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

typedef long long ll;

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    //  --------------------------------------
    
    int N, Q;
    cin >> N >> Q;
    
    string S;
    cin >> S;
    
    int AC[N]; AC[0] = 0;
    int ac_counter = 0;
    for (int i = 1; i < N; i++) {
        AC[i] = AC[i-1];
        if (S[i-1] == 'A' && S[i] == 'C') {
            AC[i] += 1;
        }
    }
    
    int l, r;
    for (int i = 0; i < Q; i++) {
        cin >> l >> r;
        cout << AC[r-1] - AC[l-1] << "\n";
    }

//    for (int i = 0; i < N; i++) {
//        cout << AC[i];
//    }
    
    
}




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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++)
    cin>>vec.at(i);
  int count=0;
  for(int i=1;i<N;i++){
  	for(int j=0;j<i;j++)
      count+=vec.at(i)*vec.at(j);
  }
  cout<<count<<endl;
}

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

namespace ABC
{
    class ProgramD
    {
        struct Bridge
        {
            public int a;
            public int b;
        }
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var n = int.Parse(inputs[0]);
            var m = int.Parse(inputs[1]);

            var list = new Bridge[m];
            for (var i = 0; i < m; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var a = int.Parse(inputs1[0]) - 1;
                var b = int.Parse(inputs1[1]) - 1;
                list[i] = new Bridge() { a = a, b = b };
            }

            var rList = Enumerable.Range(0, n - 1).Select(x => true).ToArray();
            list = list.OrderBy(x => x.b).ToArray();

            var result = 0;
            foreach (var b in list)
            {
                var isPath = true;
                for (var i = b.a; i < b.b; i++)
                {
                    if (!rList[i])
                    {
                        isPath = false;
                        break;
                    }
                }

                if (isPath)
                {
                    rList[b.b - 1] = false;
                    result++;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 46944
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    A = [0]+list(map(int, input().split()))
    B = [0]+list(map(int, input().split()))
    C = [0]+list(map(int, input().split()))
    ans = 0
    prev = -1
    for i in range(1, N+1):
        dish = A[i]
        point = B[dish]
        ans += point
        if prev+1==dish:
            ans += C[prev]
        prev = dish
    print(ans)

Measured memory_bytes: 10540
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int s,t,u;
	cin>>s;
	t=s/100;
	u=s%100;
	if(1<=t&&t<13 && 0<u&&u<13){
		cout<<"AMBIGUOUS";
	}
	else if(1<=t&&t<13){
		cout<<"MMYY";
	}
	else if( 0<u&&u<13){
		cout<<"YYMM";
	}
	else {
		cout<<"NA";
	}
}

Measured memory_bytes: 256
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
LL n, m;
struct node {
	LL a, b; 
	bool operator < (const node &rhs) const {
		return b < rhs.b;
	};
}gg[100000 + 6];
bool cmp(node a, node b) {
	return a.a < b.a;
}
priority_queue<node > q;
int main() {
	cin >> n >> m;
	for (LL i = 1; i <= n; ++i) scanf("%lld%lld", &gg[i].a, &gg[i].b);
	sort(gg + 1, gg + 1 + n, cmp);
	LL j = 1, ans = 0;
	for (LL i = 1; i <= m; ++i) {
		while (j <= n && gg[j].a <= i) q.push(gg[j]), ++j;
		if (!q.empty()) ans += q.top().b, q.pop();
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, D; cin >> N >> D;
  vector<vector<ll>> X(N, vector<ll> (D));
  for(ll i = 0; i < N; i++) {
    for(ll j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }
  ll cnt = 0;
  for(ll i = 0; i < N; i++) {
    for(ll j = i + 1; j < N; j++) {
      ll dis = 0;
      for(ll k = 0; k < D; k++) {
        dis += (X.at(i).at(k) - X.at(j).at(k)) * (X.at(i).at(k) - X.at(j).at(k));
      }
      for(ll n = 0; n < 10000; n++) {
        if(n * n == dis) cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3608
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    K = int(input())
    S = input()

    mod = 10 ** 9 + 7
    n = len(S)
    ans = 0

    fact =[1]*(K+n)
    factinv = [1]*(K+n)
    inv = [0,1]


    for i in range(2,K+n):
        fact[i] = (fact[i-1] * i) % mod
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv[i] = (factinv[i-1] * inv[i]) % mod

    def nCr(n,r):
        r = min(r,n-r)
        return (fact[n] * factinv[r] * factinv[n-r]) % mod

    for i in range(K+1):
        tmp = pow(25,i,mod)
        tmp *= nCr(i+n-1,n-1)
        tmp *= pow(26,K-i,mod)
        ans += tmp
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 214680
#include <stdio.h>
int main(void){
    int a,b,w,n,i,t[31];
    for(i=1;i<=30;i++){
        t[i]=i;
    }
    scanf("%d%d",&w,&n);
    for(i=0;i<n;i++){
        scanf("%d,%d",&a,&b);
        t[a]^=t[b]^=t[a]^=t[b];
    }
    for(i=1;i<=w;i++){
        printf("%d\n",t[i]);
    }
}

Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main() {
    int n = 0;  //カードの枚数
    vector<int>card;    //カードの配列
    int apoint = 0; //アリスの点数
    int bpoint = 0; //ボブの点数
    bool ab = false;    //どちらがうけとるか

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int buff = 0;
        cin >> buff;
        card.push_back(buff);
    }

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

    for (int j = n -1; j >=0 ; --j) {
        if (ab == false){
            apoint += card[j];
            card.pop_back();
            ab = true;
        } else{
            bpoint += card[j];
            card.pop_back();
            ab = false;
        }
    }

    int ans = apoint - bpoint;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  string s;
  cin >> s;
  ll ans=0;
  rep(i,s.size()-1){
    if(s.at(i)!=s.at(i+1)){
      ans++;
    }
  }
  cout << ans;

}

Measured memory_bytes: 3724
#include <iostream>

using namespace std;

int main()
{
string s;
cin>>s;
int cnt1=0,cnt2=0;
int j=0;
int indi=0;
int flag=0;
for (int i=0;i<s.size();i++){
    if(s[i]!=s[0])
        indi=i;}
for (int i=0;i<s.size();i++){
    if(s[i]==s[0])
        cnt1++;
    else if (s[indi]==s[i])
        cnt2++;
}
if(cnt1==2 && cnt2==2)
    cout<<"Yes";
else
    cout<<"No";

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
 int a,b;
 scanf("%d %d",&a,&b);

 if(a<b){
   printf("a < b\n");
 }
 else if(a>b){
   printf("a > b\n");
 }
 else {
   printf("a == b\n");
 }
return 0;
}


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

int main(){

    int a, b, c, temp;
    cin >> a >> b >> c;

    if(a > b){
        temp = a;
        a = b;
        b = temp;
    }

    if(b > c){
        temp = b;
        b = c;
        c = temp;
    }

    if(a > b){
        temp = a;
        a = b;
        b = temp;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}


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

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

template <class Head>
void dbgLog(Head&& head) {
  cerr << head << endl;
}

template <class Head, class... Tail>
void dbgLog(Head&& head, Tail&&... tail)
{
  cerr << head << " ";
  dbgLog(forward<Tail>(tail)...);
}

#if DEBUG
  #define DLOG(...)        dbgLog(__VA_ARGS__)
  #define DFMT(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFMT(...)
  #define DCALL(func, ...)
#endif

// operator<< definitions for some classes

template <typename T1, typename T2>
ostream& operator<< (ostream& os, const pair<T1,T2>& p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& v) {
  os << '[';
  for (auto it = v.begin(); it != v.end(); it++) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  os << ']';

  return os;
}

template <typename T, typename T2, typename T3>
ostream& operator<< (ostream& os, const priority_queue<T, T2, T3>& orig) {
  priority_queue<T, T2, T3> pq(orig);
  bool first = true;
  os << '[';
  while (!pq.empty()) {
    T x = pq.top(); pq.pop();
    if (!first) os << ", ";
    os << x;
    first = false;
  }
  return os << ']';
}

template<typename F>
class FixPoint : private F {
public:
  explicit constexpr FixPoint(F&& f) noexcept : F(forward<F>(f)) {}

  template<typename... Args>
  constexpr decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, forward<Args>(args)...);
  }
};

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return FixPoint<F>{forward<F>(f)};
}

int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S; cin >> S;
  int K; cin >> K;

  int N = S.size();
  vector<vector<vector<int>>>
    dp(N+2, vector<vector<int>>(N+2, vector<int>(K+1, -1)));
  for (int j = 0; j < N+1; j++) {
    for (int k = 0; k < K+1; k++) {
      dp.at(0).at(j).at(k) = dp.at(j).at(N+1).at(k) = 0;
    }
  }
  auto f = fix([&](auto recF, int i, int j, int k) -> int {
      int& ref = dp.at(i).at(j).at(k);
      if (ref < 0) {
	if (S.at(i-1) == S.at(j-1)) {
	  ref = 1 + recF(i-1, j+1, k);
	}else {
	  int t = max(recF(i-1, j, k), recF(i, j+1, k));
	  if (k > 0) ref = max(t, 1 + recF(i-1, j+1, k-1));
	  else       ref = t;
	}
	DLOG("f: ", i, j, k, " -> ", ref);
      }
      return ref;
    });
  int ans = 0;
  for (int i = 1; i <= N; i++) ans = max(ans, 2 * f(i, i, K) - 1);
  for (int i = 1; i <  N; i++) ans = max(ans, 2 * f(i, i+1, K));
  cout << ans << endl;

  return 0;
}



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

bool comp(const pair<int,int> a, const pair<int,int> b) {

    return a.second < b.second;
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){
  int n;
  vector<int> list;
  int ans=0;
  cin >>n;
  for(int i = 0;i<n;i++){
    int x;
    cin >>x;
    list.push_back(x);
  }

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

  cout <<list[(int)n/2] - list[(int)n/2 - 1]<<endl;
  return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    ll answer=0;
    int l=0;
    int r=0;
    while(n-->0){
        cin>>l>>r;
        answer+=r-l+1;
    }
    cout<<answer;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from scipy.sparse.csgraph import floyd_warshall
import itertools

from pprint import pprint as pp
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
ABC = [list(map(int, input().split())) for _ in range(M)]

graph = [[float('inf') for _ in range(N)] for _ in range(N)]
for i in range(M):
    x, y, c = ABC[i]
    x -= 1
    y -= 1
    graph[x][y] = c
    graph[y][x] = c

dist = floyd_warshall(graph, directed=False)

ans = []
for rlist in itertools.permutations(r, len(r)):
    tmp = 0
    for r,n in zip(rlist,rlist[1:]):
        tmp += dist[r-1,n-1]
    ans.append(tmp)

print(int(min(ans)))


Measured memory_bytes: 33540
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

ll cal(string s, vector<ll> v){
    if(accumulate(all(v),0LL) == 0){
        return stol(s);
    }
    ll sum = 0;
    string t;
    t += s[0];
    for(int i = 1; i < s.size(); i++){
        if(v[i-1]){
            sum += stol(t);
            t.erase();
            t.push_back(s[i]);
        }else{
            t.push_back(s[i]);
        }
    }
    sum += stol(t);
    return sum;
}

ll dfs(string s, ll d, vector<ll> v){
    if(d >= s.size()-1){
        ll cnt = 0;
        //for(auto x:v) cout << x << " "; cout << endl;

        return cal(s,v);
    }
    vector<ll> z = v;
    z[d] = 1;
    return dfs(s,d+1,v) + dfs(s, d+1,z);
}

int main(){
    string s; cin >> s;
    vector<ll> v(s.size()-1,0);
    put(dfs(s, 0,v));
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define f(a,b,c) for(int i=a;i<=b;i+=c)
#define d(a,b,c) for(int i=a;i>=b;i-=c)  
using namespace std;
int n,m,x,y,a[1000],b[1000];
int main(){
	cin>>n>>m>>x>>y;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=m;i++)cin>>b[i];
	sort(a+1,a+1+n);sort(b+1,b+1+m);
	for(int i=x+1;i<=y;i++){
		if(i>a[n]&&i<=b[1]){
			cout<<"No War"<<endl;
			return 0;
		}
	}
	cout<<"War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long a[100000];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  int i=0;
  while(a[i]<=a[n-1]/2) i++;
  if(i==0) cout<<a[n-1]<<' '<<a[i]<<endl;
  else{
    if(a[n-1]%2==0){
      if(a[n-1]/2-a[i-1]<=a[i]-a[n-1]/2) cout<<a[n-1]<<' '<<a[i-1]<<endl;
      else cout<<a[n-1]<<' '<<a[i]<<endl;
    }
    else{
      if(a[n-1]/2-a[i-1]<=a[i]-a[n-1]/2-1) cout<<a[n-1]<<' '<<a[i-1]<<endl;
      else cout<<a[n-1]<<' '<<a[i]<<endl;
    }
  }
  
  return 0;
}

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

typedef vector<vector<int> > Matrix;

const int MAX_M = 10; // 町の数
const int INF = 100000000;
Matrix d; // グラフの距離を格納した2次元配列（隣接行列）
          // d[u][v]は辺e=(u,v)のコスト（辺が存在しない場合はINF、ただしd[i][i]=0）

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

int main() {
  int n, m;
  while(cin >> n, n != 0) {
    m = 0;
    d = Matrix(MAX_M, vector<int>(MAX_M, INF));
    for (int i = 0; i < MAX_M; i++) d[i][i] = 0;

    for (int i = 0; i < n; i++) {
      int from, to, dist;
      cin >> from >> to >> dist;
      d[from][to] = dist;
      d[to][from] = dist;
      
      // 初期状態では町の数がわからないので、道情報を読み込みながら調べる
      m = max(m, from+1);
      m = max(m, to+1);
    }
    warshall_floyd(m);
    int min_m = -1, min_dist = INF;

    for (int i = 0; i < m; i++) {
      int sum = 0;
      for (int j = 0; j < m; j++) {
        sum += d[i][j];
      }
      if (sum < min_dist) {
        min_dist = sum;
        min_m = i;
      }
    }
    cout << min_m << " " << min_dist << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	/** ケースごとの数値の種類 */
	private static final int N = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			long[] x = new long[n], y = new long[n], z = new long[n];
			IntStream.range(0, n).forEach(i -> {
				x[i] = scanner.nextLong();
				y[i] = scanner.nextLong();
				z[i] = scanner.nextLong();
			});
			System.out.println(IntStream.range(0, 1 << N)
					.mapToLong(i -> IntStream.range(0, n)
							.mapToLong(j -> (((i & 1) > 0) ? -1 : 1) * x[j] + ((((i >> 1) & 1) > 0) ? -1 : 1) * y[j]
									+ ((((i >> 2) & 1) > 0) ? -1 : 1) * z[j])
							.sorted().skip(n - m).sum())
					.max().getAsLong());
		}
	}
}


Measured memory_bytes: 41844
#include <stdio.h>
int main(){
	unsigned n;
	scanf("%u", &n);
	char w[2] = {0, 0};
	int a[12];
	unsigned wmin[2];
	for(unsigned i = 0; i < n; ++i) scanf("%d", a + i);
	for(unsigned i = 0; i < n; ++i){
		unsigned tmp;
		scanf("%u", &tmp);
		if(!w[a[i]] || wmin[a[i]] > tmp){
			w[a[i]] = 1;
			wmin[a[i]] = tmp;
		}
	}
	unsigned ans;
	printf("%u\n", w[0] && w[1] ? wmin[0] + wmin[1] : 0u);
}



Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int ca(int c){
  int x = 0;
  for(int i=1; i<=c; i++){
    if(c<i) break;
    c-=i;
    x++;
  }
  return x;
}

int main(void){

  long long N;
  int c, ans = 0;

  cin >> N;

  for(long long z=2; z*z<=N; z++){
    c = 0;
    while(true){
      if(N%z==0){
        N = N / z;
        c++;
      }
      else{
        ans += ca(c);
        break;
      }
    }
  }
  if(N!=1) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3652
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n, k;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto ar = readln().strip().split().map!(to!int).array();
		n = ar[0].to!int;
		k = ar[1].to!int;
	}
}

auto main2(Input* input)
{
	with (input)
	{
        auto keta = 1;
        auto temp = n;
        while (temp >= k)
        {
            temp /= k;
            keta++;
        }
        return keta;
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`11 2`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 4);
	}

	unittest // example2
	{
		string example =
`1010101 10`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 7);
	}

	unittest // example3
	{
		string example =
`314159265 3`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == 18);
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M;
int A[200010],B[200010];

struct UnionFind {
	vector<int> data;
 	UnionFind(int size):data(size, -1) {}
	bool unite(int x,int y){
		x=root(x);
		y=root(y);
 	   if(x!=y){
			if (data[y]<data[x]){
				swap(x, y);
			}
			data[x]+=data[y];
			data[y]=x;
		}
		return x!=y;
	}
	bool same(int x, int y){
		return root(x)==root(y);
	}
	int root(int x){
		return data[x]<0? x:data[x]=root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

signed main(){
	cin>>N>>M;
	UnionFind UF(N+10);
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		UF.unite(A[i],B[i]);
	}
	int ans=0;
	REP(i,N){
		ans=max(ans,UF.size(i));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8008
import java.io.*;
public class Main{

    public static void main(String[] args)throws IOException{

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    String[] arr = str.split(" ");
    int a = Integer.parseInt(arr[0]);
    int b = Integer.parseInt(arr[1]);
    int c = Integer.parseInt(arr[2]);

    int count = 0;

    for(int i = a; i <= b; i++){
        if(c % i == 0){
        count++;
        }
    }

    System.out.println(count);

    }
  }

Measured memory_bytes: 24304
#include <iostream>

using namespace std;

const int maxn = 100 + 10;
const int maxnn = 1e5 + 10;

int n , W;
long long dp[maxnn];
int v[maxn] , w[maxnn];

int main() {
    cin >> n >> W;
    for (int i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    
    for (int i = 1; i <= n; i++){
        for (int j = W; j >= 0; j--){
            if (j - w[i] < 0){
                dp[j] = dp[j];
                continue;
            }
            dp[j] = max(dp[j] , dp[j-w[i]] + v[i]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int dp[maxn];
int height[maxn];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>height[i];
	height[0]=-1000000;
	//每一个状态都可以由前一个或者是隔着两个的状态转移而来  
	dp[0]=dp[1]=0; 
	for(int i=2;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
	}
	cout<<dp[n];
	return 0;
} 

Measured memory_bytes: 1024
#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)

n = gets.to_i
gets.to_i.times do |i|
  j,i = gets.chomp.split(' ').map { |x| x.to_i }
  i = [i, j, n-i+1, n-j+1].min
  mod = (i+2) % 3
  puts(mod + 1)
end

Measured memory_bytes: 6136
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int[][] a = new int[H][W];
		for(int i = 0;i < H;++i)
			for(int j = 0;j < W;++j)
				a[i][j] = sc.nextInt();
		sc.close();
		
		ArrayList<String> ans = new ArrayList<>();
		for(int i = 0;i < H;++i) {
			for(int j = 0;j < W-1;++j) {
				if(a[i][j] != 0 && a[i][j] % 2 != 0) {
					a[i][j]--;
					a[i][j+1]++;
					ans.add((i+1) + " " + (j+1) + " " + (i+1) + " " + (j+2));
				}
			}
		}
		
		for(int i = 0;i < H-1;++i) {
			if(a[i][W-1] != 0 && a[i][W-1] % 2 != 0) {
				a[i][W-1]--;
				a[i+1][W-1]++;
				ans.add((i+1) + " " + (W) + " " + (i+2) + " " + (W));
			}
		}
		
		System.out.println(ans.size());
		for(int i = 0;i < ans.size();++i)
			System.out.println(ans.get(i));
	}
}


Measured memory_bytes: 97868
#include <iostream>

#include <vector>
#include <string>


using namespace std;

int main()
{
	int t[2], a[2];

	cin >> t[0] >> t[1] >> a[0] >> a[1];

	while (true)
	{
		a[0] -= t[1];
		if (a[0] <= 0)
		{
			cout << "Yes\n";
			return 0;
		}

		t[0] -= a[1];
		if (t[0] <= 0)
		{
			cout << "No\n";
			return 0;
		}
	}

	return 0;

}

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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int x;cin>>x;
  string str;cin>>str;
  string s1,s2;
  int n = str.size() /2;
  s1 = str.substr(0,n);
  s2 = str.substr(n,n);
  map<pair<string,string>,int> mp,mp2;
  for (int b = 0; b < (1<<n); b++)
  {
      vector<int> bit;
      for (int i = 0; i < n; i++)
      {
          bit.push_back((b>>i)&1);
      }
      string rs = "";
      string ls = "";
      for (int i = 0; i < n; i++)
      {
        if(bit[i] == 1)rs.push_back(s1[i]);
        else ls.push_back(s1[i]);
      }
      mp[make_pair(rs,ls)]++;
  }
  // DEBUG(s1,s2);
  reverse(ALL(s2));
  for (int b = 0; b < (1<<n); b++)
  {
      vector<int> bit;
      for (int i = 0; i < n; i++)
      {
          bit.push_back((b>>i)&1);
      }
      string rs = "";
      string ls = "";
      for (int i = 0; i < n; i++)
      {
        if(bit[i] == 1)rs.push_back(s2[i]);
        else ls.push_back(s2[i]);
      }
      mp2[make_pair(rs,ls)]++;
  }
  int res = 0;
  for (auto &&i : mp)
  {
    // if(i.first.first == "" || i.first.second == "")continue;
    
    res += i.second*mp2[i.first];
  }
  cout<<res<<endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 89556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int h,w,k;
string ch[305];
int pre[305][305];
vector<int> tmp[305];
int vis[305];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin>>h>>w>>k)
    {
        for(int i=0; i<h; i++)
        {
            vis[i]=0;
            tmp[i].clear();
            cin>>ch[i];
        }
        for(int i=0; i<h; i++)
        {
            for(int j=0; j<w; j++)
            {
                if(ch[i][j]=='#')
                {
                    tmp[i].push_back(j);
                }
            }
        }
        int cnt=1;
        vector<int> ase;
        for(int i=0; i<h; i++)
        {
            int sz=tmp[i].size();
            int l=0;
            int r=w-1;
            if(sz!=0)
            {
                vis[i]=1;
                //ase.clear();
                for(int j=0; j<sz; j++)
                {
                    if((j==sz-1) && j==0)
                    {
                        l=0;
                        r=w-1;
                    }
                    else if(j==0)
                    {
                        l=0;
                        r=tmp[i][j];
                    }
                    else if(j==(sz-1))
                    {
                        l=tmp[i][j-1]+1;
                        r=w-1;
                    }
                    else
                    {
                        l=tmp[i][j-1]+1;
                        r=tmp[i][j];
                    }
                    for(int pq=l; pq<=r; pq++)
                    {
                        pre[i][pq]=cnt;
                    }
                    cnt++;
                }
                int koto=ase.size();
                if(koto==0)
                {

                }
                else
                {
                    int last=ase.back();
                    ase.clear();
                    for(int j=last;j>=0;j--)
                    {
                        if(vis[j]==1)
                        {
                            break;
                        }
                        vis[j]=1;
                        for(int pq=0;pq<w;pq++)
                        {
                            pre[j][pq]=pre[i][pq];
                        }
                    }
                }
            }
            else
            {
                ase.push_back(i);
            }
        }
        for(int i=0;i<h;i++)
        {
            if(vis[i]==0)
            {
                vis[i]=1;
                for(int j=0;j<w;j++)
                {
                    pre[i][j]=pre[i-1][j];
                }
            }
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
            {
                cout<<pre[i][j]<<" ";
            }
            cout<<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>

#define MAX_V 100
#define INF 1000000
using namespace std;

struct edge{
    int to, cap, rev;
};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int i=0; i<G[v].size(); i++){
            edge e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f){
    if(v == t){
        return f;
    }
    for(int &i=iter[v]; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0){
            return flow;
        }
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, INF)) > 0){
            flow += f;
        }
        //cout<<flow<<endl;
    }
}

int main(){
    int n, m, u, v, c;
    cin>>n>>m;
    for(int i=0; i<m; ++i){
        cin>>u>>v>>c;
        add_edge(u, v, c);        
    }

    cout<<max_flow(0, n-1)<<endl;

    return 0;
}


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

void solve(int n, int Y)
{
    for(int x=0; x<=n; x++)
    {
        for(int y=0; y<=n-x; y++)
        {
            int z = n - x - y;
            if(10000*x + 5000*y + 1000*z == Y && z >= 0)
            {
                cout << x << " " << y << " " << z << endl;
                return;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return;
}

int main()
{
    int n, Y;
    cin >> n >> Y;

    solve(n, Y);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <string>
#include <unordered_map>
using namespace std;
long long ans;
long long N;
bool number(int n){
    int count3=0,count5=0,count7=0;
    while(n > 0){
        int r = n % 10;
        if(r == 3)count3++;
        else if(r == 5)count5++;
        else if(r == 7)count7++;
        else return false;
        n /= 10;
    }
    return count3 && count5 && count7;
}
void solve(long long s){
    if(s > N){
        return;
    }
    if(number(s)){
        ans++;
    }
    for(int i=3;i<=7;i+=2){
        solve(s * 10 + i);
    }
    return;
}
int main(void){

    cin >> N;
    solve(0);
    cout << ans;
}


Measured memory_bytes: 3156
S = input()
c1 = c2 = 0
 
N = len(S)
c1 = N - len([s for s in S[0::2] if s == "0"]) - len([s for s in S[1::2] if s == "1"])
c2 = N - len([s for s in S[0::2] if s == "1"]) - len([s for s in S[1::2] if s == "0"])
 
print(min(c1, c2))

Measured memory_bytes: 3636
import math
import collections

N, M = [int(s) for s in input().split()]
graph = {i:[] for i in range(1, N+1)}
for _ in range(M):
    v1, v2 = [int(s) for s in input().split()]
    graph[v1].append(v2)
    graph[v2].append(v1)

queue = collections.deque([1])
visited = set([1])
pre = dict()
while queue:
    v = queue.popleft()
    for w in graph[v]:
        if w not in visited:
            queue.append(w)
            visited.add(w)
            pre[w] = v
if len(visited) != N:
    print("No")
else:
    print("Yes")
    for i in range(2, N+1):
        print(pre[i])

Measured memory_bytes: 57440
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

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



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<climits>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }
using namespace std;

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

	vector<long long> h(N);
	rep(i, N) cin >> h[i];

	vector<long long> dp(N, LLONG_MAX);
	dp[0] = 0;
	REP(i, 1, N)
	{
		chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
		if (i > 1) 
		{
			chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
		}
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e3 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, have[maxn];
vector<int>adj[maxn];
string s;
int sum = 0;
void dfs(int v, int p, int d)
{
	if(have[v])
		sum += d;
	for(int to : adj[v])
		if(to != p)
			dfs(to, v, d + 1);
}
pii dfs2(int v, int p)
{
	int tot = 0, mx = 0, cnt = have[v];
	for(int to : adj[v])
	{
		if(to != p)
		{
			pii a = dfs2(to, v);
			tot += a.x;
			cnt += a.y;
			mx = max(mx, a.x);
		}
	}
	if(mx * 2 <= tot)
		tot %= 2;
	else
		tot = mx * 2 - tot;
	return {tot + cnt, cnt};
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	cin >> s;
	for(int i = 0; i < n; i++)
		have[i + 1] = s[i] == '1';
	for(int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int ans = mod;
	for(int v = 1; v <= n; v++)
	{
		//cout << "cur : " << v << endl;
		int tot = 0;
		pii mx = {0, 0};
		for(int to : adj[v])
		{
			sum = 0;
			dfs(to, v, 1);
			mx = max(mx, pii(sum, to));
			tot += sum;
		}
		if(tot % 2 == 0 && mx.x * 2 <= tot)
			ans = min(ans, tot / 2);
		else
		{
			for(int to : adj[v])
			{
				if(to == mx.y)
				{
					int mn = dfs2(to, v).x;
					//cout << "aa " << mn << " " << mx.x << endl;
					if(tot % 2 == 0 && mn * 2 <= tot - mx.x + mn)
						ans = min(ans, tot / 2);
				}					
			}
		}
	}
	cout << (ans == mod ? -1 : ans) << "\n";
	return 0;
}

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

int main() {
    int n; cin >> n;
    int ans = 1;
    for (int i=0; i<n; ++i) {
        int a; cin >> a;
        if (a%2) ans = 1 - ans;
    }
    cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 void getrank(int x[10],int y[3]){
     int i,j,swp;
     for(i=0;i<10;i++){
         for(j=i+1;j<10;j++){
             if(x[i]>x[j]){
                 swp = x[i];
                 x[i] = x[j];
                 x[j] = swp;
             }
         }
     }
     for(i=0;i<3;i++)
         y[i] = x[9-i];
 }
 int main(void){
     int n[10];
     int rank[3];
     int i;

     for(i=0;i<10;i++){
         scanf("%d",&n[i]);
     }
     getrank(n,rank);
     printf("%d ",rank[0]+rank[1]+rank[2]);
     for(i=0;i<10;i++){
         scanf("%d",&n[i]);
     }
     getrank(n,rank);
     printf("%d",rank[0]+rank[1]+rank[2]);
     puts("");

     return 0;
 }


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

const int INF = 100;
const int alpha_size = 26;

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

  vector<vector<int>> v(n, vector<int>(alpha_size));
  rep(i, n) {
    string s;
    cin >> s;
    rep(j, s.size()) v[i][s[j] - 'a']++;
  }

  vector<int> a(alpha_size, INF);
  rep(j, alpha_size) rep(i, n) a[j] = min(a[j], v[i][j]);

  rep(i, alpha_size) {
    cout << string(a[i], i + 'a');
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

char s[100010];
int vl[100010], vr[100010];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    scanf("%s", &s);

    int cntl = 0;
    int cntr = 0;
    for (int i = -1; i < n + 1; i++) {
        if (i == -1) {
            vl[cntl] = -1;
            cntl++;
            if (s[0] == '0') {
                vr[cntr] = -1;
                cntr++;
            }
            continue;
        }
        if (i == n) {
            vr[cntr] = i;
            cntr++;
            if (s[i - 1] == '0') {
                vl[cntl] = i;
                cntl++;
            }
            continue;
        }
        if (s[i] == '1' && i < n - 1 ? (s[i + 1] == '0') : false) {
            vr[cntr] = i;
            cntr++;
        }
        if (s[i] == '1' && i > 0 ? (s[i - 1] == '0') : false) {
            vl[cntl] = i;
            cntl++;
        }
    }
    int vs = cntl;

    if (vs - k <= 1) {
        printf("%d\n", n);
        return 0;
    }
    int ret = 0;
    rep(i, vs - k) {
        if (i == 0) {
            ret = max(ret, vr[i + k] - vl[i]);
        } else if (i == vs - k - 1) {
            ret = max(ret, vr[i + k] - vl[i]);
        } else {
            ret = max(ret, vr[i + k] - vl[i] + 1);
        }
    }

    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 768
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        a: [usize;n]
    }

    let mut buy_day = vec![MAX; n];

    for i in 0..n {
        let mut now = a[i];
        for j in i + 1..n {
            if a[j] >= now {
                now = a[j];
                buy_day[i] = j;
            } else {
                break;
            }
        }
    }

    //println!("{:?}", buy_day);

    let mut money = 1000;
    let mut stock = 0;

    for i in 0..n {
        if buy_day[i] != MAX {
            let buy_num = money / a[i];
            money = money - buy_num * a[i];
            stock += buy_num;
        } else {
            money += stock * a[i];
            stock = 0;
        }
    }

    println!("{}", money);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2240
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
    
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int c=0;
    for(int i=n;i<=100003;i++)
    {
       
        for(int j=1;j*j<=i;j++)
        {
            if(i%j==0)
            {c++;}
        }
        //cout<<" "<<c<<" "<<i<<endl;
        if(c==1 && i>=n)
        {
            cout<<i<<endl;
            break;
        }
        c=0;
           
    }
    return 0;
   
  
}
    

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var x int
var ans int

func main() {
	fmt.Scan(&x)
	if x < 1200 {
		fmt.Println("ABC")
	} else {
		fmt.Println("ARC")
	}
}

/*  ----------------------------------------  */
func lcm(x, y uint64) uint64 {
	return (x / gcd(x, y)) * y
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 512