akhauriyash/Code-Regression huggingface dataset:
/*
ID: wangjun30
TASK:
LANG: C++
*/
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int m,n;
	cin>>m>>n;
	int num[n];
	for(int i=0;i<n;i++)
		cin>>num[i];
	if(m>=n){
		cout<<0;
		return 0;
	}
	sort(num,num+n);
	vector<int> v;
	int ans=0;
	for(int i=1;i<n;i++)
		ans+=num[i]-num[i-1],v.push_back(num[i]-num[i-1]);
	if(m==1){
		cout<<ans;
		return 0;
	}
	sort(v.begin(),v.end());
	for(int i=1;i<m;i++)
		ans-=v[v.size()-i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

int64_t mod = 998244353 ;

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }
            
        }
        
    }
    return p ;
}

int main(){
    int64_t n,k ;
    
    cin >> n >> k ;
    vector<int64_t> p(n) ;
    vector<int64_t> c(n) ;
    for (int i = 0; i < n; i++)
    {
        cin >> p.at(i) ;
        p.at(i) -- ;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c.at(i) ;
    }
    vector<int64_t> score(n,0) ;
    for (int i = 0; i < n; i++)
    {
        int64_t nows = 0 ;
        int64_t nowi = i ;
        int64_t nowm = 0 ;
        int64_t temp = INT64_MIN ;
        while (nowm < k)
        {
            nowm ++ ;
            nowi = p.at(nowi) ;
            nows += c.at(nowi) ;
            temp = max(temp,nows) ;
            if (nowi == i)
            {
                if (nows <= 0)
                {
                    break ;
                }else
                {
                    if (k/nowm > 2)
                    {
                        nows *= k/nowm -1 ;
                        nowm = nowm * (k/nowm -1) ;
                        temp = max(temp,nows) ;
                    }
                    
                    
                }
                
                
            }
            
        }
        score.at(i) = temp ;
    }
    int64_t ans = score.at(0) ;
    for (int i = 1; i < n; i++)
    {
        ans = max(ans, score.at(i)) ;
    }
    
    
    cout << ans << endl ;
}

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

int abs(int a,int b)
{
    if(a < b)
    {
        return b - a;
    }
    else
    {
        return a - b;
    }
}

int main()
{
    int n, t, A , ans;
    cin >> n >> t >> A;
    double dif = 100000;
    for(int i = 1; i <= n; i++)
    {
        double Hi;
        cin >> Hi;
        if(dif  > abs((t - A) / 0.006, Hi))
        {
            dif = abs((t - A) / 0.006, Hi);
            ans = i;
        }
    }
    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  
  while(N > 0) {
    N = N - 1000;
  }
  if (N == 0) {
    cout << 0 << endl;
  }
  else {
    cout << - N << endl;
  }
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e18+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

const int MOD = 998244353; 

void solve(){
    int n;
    cin >> n;
    int dp[n+1][3];
    memset(dp, 0, sizeof(dp));
    for(int i = 1; i <= n; i++){
        int a, b, c;
        cin >> a >> b >> c;
        dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a;
        dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b;
        dp[i][2] = max(dp[i-1][1], dp[i-1][0])+c;
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);
    //#endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main(){
	int n,k;
    cin>>n>>k;
    int cnt=0;
    rep(i,n){
        int h;
        cin>>h;
        if(h>=k){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
  int N,i,j,sum[40];
  long K,A[100000],B[100000],ans=0;
  long long ans2=0;
  for(i=0;i<40;i++)sum[i]=0;
  scanf("%d %ld",&N,&K);
  for(i=0;i<N;i++) {
    scanf("%ld",&A[i]);
    B[i] = A[i];
  }
  for(i=0;i<N;i++)for(j=0;j<40;j++) {
    sum[j]+=A[i]%2;
    A[i] = A[i] >> 1;
  }
  for(i=39;i>-1;i--)if(sum[i]*2<N)if(pow(2.0,i)+ans<=K)ans+=(long)pow(2.0,i);
  for(i=0;i<N;i++)ans2+=ans^B[i];
  printf("%lld\n",ans2);
}


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

int main() {
    int n;
    cin>>n;
    map<int,int> mp;
    int ans = 0;
    rep(i,n){
        int a;
        cin>>a;
        mp[a]++;
    }
    for(auto x:mp){
        if(x.second % 2) ans++;
    }
    
    cout<< ans << endl;
}



Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    set<string> pq;
    for (int i = 0; i < s.size(); ++i) {
        for (int j = 1; j <= k && i + j <= s.size(); ++j) {
            pq.insert(s.substr(i,j));
            if (pq.size() > k)
                pq.erase(prev(pq.end()));
        }
    }
    cout << *prev(pq.end()) << endl;
}


Measured memory_bytes: 892
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")
def nck(n,k):
    return fact[n]*inv[k]*inv[n-k]%mod
N = 3*10**5
fact = [1]*(N+1)
for i in range(1,N+1):
    fact[i] = fact[i-1]*i%mod

inv = [None]*(N+1)
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N)[::-1]:
    inv[i] = inv[i+1]*(i+1)%mod
#solve
def solve():
    s = II()
    ans = 0
    for i in range(1, 2001):
        sb = s
        x = i * 3
        sb -= x
        if sb >= 0:
            ans += nck(sb + i - 1, i - 1)
            ans %= mod
            
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 84012
#include<bits/stdc++.h>
#define maxn 1010
using namespace std;
typedef long long ll;
ll n,m,a[maxn],b[maxn],c[maxn];
ll sm(bool f1,bool f2,bool f3)
{
	vector<ll> v;
	for(ll i=0;i<n;i++)
	{
		ll tmp=0;
		if(f1)
			tmp+=a[i];
		else
			tmp-=a[i];
		if(f2)
			tmp+=b[i];
		else
			tmp-=b[i];
		if(f3)
			tmp+=c[i];
		else
			tmp-=c[i];
		v.push_back(tmp);
	}
	sort(v.rbegin(),v.rend());
	ll sum=0;
	for(ll i=0;i<m;i++)
		sum+=v[i];
	return sum;
}
int main()
{
	cin>>n>>m;
	for(ll i=0;i<n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll res=-1;
	res=max(res,max(sm(0,0,0),max(sm(0,0,1),max(sm(0,1,0),max(sm(1,0,0),max(sm(1,1,0),max(sm(1,0,1),max(sm(0,1,1),sm(1,1,1)))))))));
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ss second
#define ff first
#define endl "\n";
int32_t main(){
	int n;
	cin>>n;
	int a[n+1],b[n];
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=min(a[i],b[i]);
		b[i]-=min(a[i],b[i]);
		ans+=min(a[i+1],b[i]);
		a[i+1]=max((long long)0,a[i+1]-b[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
x,y=map(int,input().split())
X=max(x,y)
Y=min(x,y)

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

if (X+Y)%3!=0:
    print(0)
else:
    if X>(Y*2):
        print(0)
    else:
        N=(X+Y)//3
        H=(N-(X-Y))//2
        print(cmb(N,H,10**9+7))
        #print(N,H)

Measured memory_bytes: 213084
// Sum of Three Integers
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int K, S;
    int count = 0;
    cin >> K >> S;
    for (int X = 0; X <= K; ++X) {
        for (int Y = 0; Y <= K; ++Y) {
            int Z = S - X - Y;
            if (0<= Z && Z <= K) {
                ++count;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int a;
    cin >> a;
    cout << a + a*a + a* a*a << endl;
    return 0;
}

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


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        j = 0
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


if N == 1:
    print(0)
else:
    table = prime_decomposition(N)
    temp = list(set(table))

    count = 0
    for i in range(len(temp)):
        c = table.count(temp[i])
        k = 1
        while c > 0:
            c -= k
            k += 1
            if c >= 0:
                count += 1

    print(count)


Measured memory_bytes: 9284
n,h = map(int,input().split())
a = []
b = []
ans = 0
for i in range(0,n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
a.sort(reverse = True)
b.sort(reverse = True)
while h > 0 :
    if(ans == n):
        break
    if(b[ans] < a[0]):
        break
    h -= b[ans]
    ans += 1
if h>0:
    ans += -(-h//a[0])
print(ans)


Measured memory_bytes: 11348
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using Int = unsigned int;
using llong = long long;
using Llong = unsigned long long;
using ldouble = long double;
using intV = vector<int>;
using llongV = vector<long long>;
using llongVV = vector<vector<long long>>;
using Graph = vector<vector<long long>>;
using costGraph = vector<vector<pair<long long, long long>>>;

const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0LL; i < llong(n); i++)
#define FORS(i, a, b) for (llong i = llong(a); i < llong(b); i++)

// 0-indexed, [l, r)
class SegmentTree {
    public :
        llongV __data;
        llong __size;

        SegmentTree (llong size) {
            this->init(size);
        };

        void init (llong size) {
            // 完全二分木にする
            llong binSize = 0;
            while((1 << binSize) < size) {
                binSize++;
            }
            this->__size = (1 << binSize);

            this->__data.resize(this->__size * 2);
            for(llong i = 0; i < this->__size * 2; i++) {
                this->__data[i] = INF;
            }
        };

        /* メソッド */
        void update(llong index, llong value) {
            index += this->__size - 1;
            this->__data[index] = value;
            while(index > 0) {
                index = (index - 1) / 2;
                this->__data[index] = min(this->__data[index * 2 + 1], this->__data[index * 2 + 2]);
            }
        };

        llong __query(llong qLeft, llong qRight, llong node, llong left, llong right) {
            if(right <= qLeft || qRight <= left) return INF;
            if(qLeft <= left && right <= qRight) return this->__data[node];

            llong leftVal = this->__query(qLeft, qRight, node * 2 + 1, left, (left + right) / 2);
            llong rightVal = this->__query(qLeft, qRight, node * 2 + 2, (left + right) / 2, right);
            return min(leftVal, rightVal);
        }

        // wrapper
        llong query(llong left, llong right) {
            return this->__query(left, right, 0, 0, this->__size);
        };
};

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

    llong N, M;
    cin >> N >> M;

    SegmentTree tree(N + 1);
    tree.update(1, 0);
    vector<tuple<llong, llong, llong>> edges(M);

    FOR(i, M) cin >> get<0>(edges[i]) >> get<1>(edges[i]) >> get<2>(edges[i]);
    sort(edges.begin(), edges.end());

    for(auto a : edges) {
      llong L, R, C;
      tie(L, R, C) = a;
      llong cost = tree.query(L, R + 1) + C;
      tree.update(R, min(cost, tree.query(R, R + 1)));
    }

    llong ans = tree.query(N, N + 1);
    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4608
#include<iostream>
using namespace std;
int main(){
  char c;
  cin>>c;
  if(c=='a')
    cout<<"vowel"<<endl;
  else if(c=='i')
    cout<<"vowel"<<endl;
  else if(c=='u')
    cout<<"vowel"<<endl;
  else if(c=='e')
    cout<<"vowel"<<endl;
  else if(c=='o')
    cout<<"vowel"<<endl;
  else
    cout<<"consonant"<<endl;
}


Measured memory_bytes: 256
h, w, m = map(int, input().split())
table = []
sum_rows = [0 for i in range(h)]
sum_cols = [0 for i in range(w)]
for i in range(m):
    h_, w_ = map(int, input().split())
    table.append((h_, w_))
    sum_rows[h_-1] += 1
    sum_cols[w_-1] += 1

r = max(sum_rows)
c = max(sum_cols)
ans_ = (r + c)
count = 0
for i in range(m):
    if ans_ == (sum_rows[table[i][0]-1]+sum_cols[table[i][1]-1]):
        count += 1

if count == (sum_rows.count(r) * sum_cols.count(c)):
    print(ans_-1)
else:
    print(ans_)

Measured memory_bytes: 54236
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
using namespace std;
#define maxn 1e6;
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if((b - a) == (c - b) || (c - b) == (b - a))
		printf("YES\n");
		else
			printf("NO\n");
			return 0;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Program
    {
        static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int ans = (X - A) % B;
            Console.WriteLine(ans);
        }
       
    }
}

Measured memory_bytes: 11092
import java.util.Scanner

object Main {
  def solve(N: Long, M: Long): Long = {
    if (N * 2 >= M) M / 2
    else {
      val c = M - N * 2
      N + c / 4
    }
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextLong()
    val M = sc.nextLong()
    println(solve(N, M))
  }
}


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

using namespace std;

long long int cost[1<<16];

long long int dp[1<<16];

int arr[16][16];


long long int fun(int n ){
    if(n==0)return 0;
    if(dp[n]!=-1)return dp[n];
    dp[n]=cost[n];
    for(int j=(n-1)&n;j>0;j=(j-1)&n){
        dp[n]=max(dp[n],fun(j)+fun(n^j));
    }
    return dp[n];
}

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n ;cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cin>>arr[i][j];
    }
    
    for(int i=0;i<(1<<n);i++){
        for(int j=0;j<n;j++)
            for(int k=j+1;k<n;k++){
                if((i&(1<<k)) and (i&(1<<j)))cost[i]+=arr[j][k];
            }
    }  
    cout<<fun((1<<n)-1)<<endl;
    
    return 0;
}



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

long long gcd(long long a, long long b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
int main(void){
    long long a, b;
    while(cin >> a >> b){
        long long s = gcd(a, b);
        cout << s << " " << a*b/s << endl;
    }
    return 0;
}



Measured memory_bytes: 3016
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,n;

  while(~scanf("%lld %lld %lld",&a,&b,&n)){
    ll res=0;
    a*=10;
    for(ll i=0;i<n;i++){
      int d=a/b;
      res+=(d%10);
      a=((a-(d%10)*b)*10)%1000000000;
    }
    printf("%lld\n",res);
  }
}

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

#define REP(var, i, j) for (int var=(i); var<(j); var++)

typedef pair<int, int> P;

//定数
const int MAX_H = 1000;
const int MAX_W = 1000;
const int INF = MAX_H*MAX_W;
//入力
char factory[MAX_H+5][MAX_W+5];
P list[9];

int bfs(int x1, int y1, int x2, int y2){
    int res[MAX_H][MAX_W];
    REP(i, 0, MAX_H){
        REP(j, 0, MAX_W){
            res[i][j] = INF;
        }
    }
    res[x1][y1]  = 0;
    queue<P> que;
    que.push(P(x1, y1));
    while (que.size()){
        P temp = que.front();
        que.pop();
        if (temp.first == x2 && temp.second == y2) break;
        int nx, ny;
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};

        REP(i, 0, 4){
            nx = temp.first + dx[i];  
            ny = temp.second + dy[i];
            if (factory[nx][ny] == 'X') continue;
            if (res[nx][ny] == INF){
                res[nx][ny] = res[temp.first][temp.second]+1;
                que.push(P(nx, ny));
            } 
        }
    }
    return res[x2][y2];
}

int solve(int x, int y, int N){
    int res = bfs(x, y, list[0].first, list[0].second);
    REP(i, 1, N){
        res += bfs(list[i-1].first, list[i-1].second, list[i].first, list[i].second); 
    }
    return res;
}

int main(){
    //入力
    int H, W, N;
    cin >> H;
    cin >> W;
    cin >> N;
    
    REP(i, 0, MAX_H+5){
        REP(j, 0, MAX_W+5){
            factory[i][j] = 'X';
        }
    }

    char number[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};

    P S;
    REP(i, 1, H+1){
        REP(j, 1, W+1){
            cin >> factory[i][j];
            REP(k, 0, N){
                if (factory[i][j] == number[k]) list[k] = P(i, j);
            } 
            if (factory[i][j] == 'S') S = P(i, j);
        }
    }
    int res;
    res = solve(S.first, S.second, N);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 8028
#include<stdio.h>
#include<string.h>
#include<vector>
struct S{char s[9],d[9],m[64];};
int F(char*r,char*s)
{
	for(int i=0;i<8;++i)
		if(r[i]-'?'&&r[i]-s[i])return 0;
	return 1;
}
int main()
{
	int n,m,i,f;
	S r[1024],s;
	std::vector<S>v;
	v.reserve(1024);
	while(scanf("%d%d",&n,&m),n+m)
	{
		v.clear();
		for(i=0;i<n;++i)scanf("%s%s%s",r[i].m,r[i].s,r[i].d);
		while(m--)
		{
			scanf("%s%s%s",s.s,s.d,s.m);
			for(f=1,i=n-1;i>=0;--i)
			{
				if(F(r[i].s,s.s)&&F(r[i].d,s.d))
				{
					if(*r[i].m-'d')f=0;
					break;
				}
			}
			if(!f)v.push_back(s);
		}
		printf("%u\n",v.size());
		for(i=0;i<v.size();++i)printf("%s %s %s\n",v[i].s,v[i].d,v[i].m);
	}
	return 0;
}

Measured memory_bytes: 0
//B
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);

int main() {
	int n;
	scanf("%d", &n);
	map<string, int> cnt;
	while (n--) {
		string s;
		cin >> s;
		cnt[s]++;
	}
	printf("AC x %d\n", cnt["AC"]);
	printf("WA x %d\n", cnt["WA"]);
	printf("TLE x %d\n", cnt["TLE"]);
	printf("RE x %d\n", cnt["RE"]);
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) 1e9
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n, k;
	cin>>n>>k;
	ll a[n];
	for(ll i=0 ;i<n; i++){
		cin>>a[i];
	}
	bool dp[k+1]={};
	for(ll i=0; i<=k; i++){
		for(ll j=0; j<n; j++){
			if(i >= a[j]  && !dp[i-a[j]]){
				dp[i] = true;
			}
			//cout<<dp[i]<<" ";
		}
		//cout<<"\n";
	}
	// if(dp[k]){
	// 	cout<<"First";
	// }
	// else{
	// 	cout<<"Second";
	// }
	cout<<(dp[k]==true ? "First":"Second");
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(){
	int a,b,c,count;
	while(scanf("%d %d",&a,&b)!=EOF){
		count=0;
		c=a+b;
		//printf("%d %d\n",a,b);
		while(c){
			c=c/10;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

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

int main (){
    string S;
    cin>>S;
    if(S=="abc"||S=="acb"||S=="bca"||S=="bac"||S=="cab"||S=="cba"){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] x = in.nextIntArray(n);

            int ans = Integer.MAX_VALUE;
            for (int i = 0; i + k - 1 < n; i++) {
                if (Math.abs(x[i]) < Math.abs(x[i + k - 1])) {
                    ans = Math.min(ans, Math.abs(x[i]) + Math.abs(x[i + k - 1] - x[i]));
                } else {
                    ans = Math.min(ans, Math.abs(x[i + k - 1]) + Math.abs(x[i] - x[i + k - 1]));
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

    }
}



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

int main() {
  int x;
  while(cin >> x) {
    int w[10][2]={{1},{2},{4},{8},{16},{32},{64},{128},{256},{512}};
    for(int i=9; i>=0; i--) {
      if(x-w[i][0]>=0) {
	w[i][1]=1;
	x-=w[i][0];
      }
    }
    int k=0;
    for(int i=0; i<10; i++) {
      if(w[i][1]==1) {
	if(k!=0) cout << " ";
	cout << w[i][0];
	k=1;
      }
    }
    cout << endl;
  }
  return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

vector<int> calc_z(const string &s) {
  int n = s.size();
  vector<int> z(n,0);
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) {
      int k = i-l;
      z[i] = min(z[k], r-i+1);
    }
    while (i+z[i] < n && s[z[i]] == s[i+z[i]]) z[i]++;
    if (i+z[i]-1 > r) {
      l = i; r = i+z[i]-1;
    }
  }
  return z;
}


int n;
string s;

int main()
{
  fastio();

  cin >> n >> s;

  int ans = 0;
  forn(i,n) {
    string t = s.substr(i);
    vi z = calc_z(t);
    forn(i,z.size()) {
      chmax(ans,min(i,z[i]));
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main(void)
{
    int a,b,c;
    cin >> a >> b >> c;

    if((a+b) == c | (b+c)==a | (c+a)==b )
        cout << "Yes"<<endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
// A - 居合を終え、青い絵を覆う

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main() {
	char c;
	cin >> c;

	string ans;

	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') ans = "vowel";
	else ans = "consonant";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

struct point{
	double x,y;
	point(){}
	point(double xx,double yy){
		x=xx;
		y=yy;
	}
	bool operator<(const point& p)const{
		if(x==p.x)return y<p.y;
		return x<p.x;
	}
	point operator - (point p){
		return point(x-p.x,y-p.y);
	}

	double det(point p){
		return x*p.y-y*p.x;
	}
};

int n;

point p[101];

vector<point> convex_hull(){
	int k=0;
	vector<point> qs(n*2);
	for(int i=0;i<n;i++){
		while(k>1 && (qs[k-1]-qs[k-2]).det(p[i]-qs[k-1])<=0)k--;
		qs[k++]=p[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t && (qs[k-1]-qs[k-2]).det(p[i]-qs[k-1])<=0)k--;
		qs[k++]=p[i];
	}
	qs.resize(k-1);
	return qs;
}

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf,%lf",&p[i].x,&p[i].y);
		}
		sort(p,p+n);
		printf("%d\n",n-convex_hull().size());

	}
	return 0;
}

Measured memory_bytes: 1076
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.contains("A")) {
            if(s.contains("B")) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21716
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll mod = 1e9+7;
ll power(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans = (ans*x)%mod;
		y>>=1;
		x=(x*x)%mod;
	}
	return ans;
}	
int solve()
{
	ll n;cin>>n;
	ll ans=0;
	vi a(n);
	vi J(n);
	J[0]=0;
	rep(j,1,n) J[j] = (J[j-1]+power(j,mod-2))%mod;
	rep(i,0,n) cin>>a[i];
	rep(i,1,n)
	{
		ll d = a[i]-a[i-1];
		ans = (ans+ (d*J[i])%mod)%mod;
	}
	rep(i,1,n) ans = (ans*i)%mod;
	cout<<ans<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}

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

int w, h;
int minStep;

void solve(vector<vector<int> >& board, int sy, int sx, int step)
{
	if(step + 1 >= minStep)
		return;

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

	for(int i=0; i<4; ++i){
		if(board[sy+dy[i]][sx+dx[i]] == 1)
			continue;
		int y = sy;
		int x = sx;
		while(board[y+dy[i]][x+dx[i]] == 0){
			y += dy[i];
			x += dx[i];
		}
		if(board[y+dy[i]][x+dx[i]] == 3){
			minStep = step + 1;
			break;
		}
		if(board[y+dy[i]][x+dx[i]] == 1){
			board[y+dy[i]][x+dx[i]] = 0;
			solve(board, y, x, step+1);
			board[y+dy[i]][x+dx[i]] = 1;
		}
	}
}

int main()
{
	for(;;){
		cin >> w >> h;
		if(w == 0 && h == 0)
			break;

		vector<vector<int> > board(h+2, vector<int>(w+2, -1));
		int sy, sx;
		for(int i=1; i<=h; ++i){
			for(int j=1; j<=w; ++j){
				cin >> board[i][j];
				if(board[i][j] == 2){
					sy = i;
					sx = j;
					board[i][j] = 0;
				}
			}
		}
		minStep = 11;
		solve(board, sy, sx, 0);
		if(minStep == 11)
			cout << -1 << endl;
		else
			cout << minStep << endl;
	}

	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{
    string s;
    cin >> s;
    lint ans=0, tmp;
    char x;
    x = s[0];

    REP(i,SZ(s)){
        if (s[i] != x){
            ans += 1;
        }
        x = s[i];
    }
    
    cout << ans <<"\n";

    return 0;
}

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

int main(){
	string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int n;
	cin >> n;
	string S;
	cin >> S;
	int tmp = 0;
	int move = 0;
	for(int i = 0;i < S.size();i++){
		for(int j = 0;j < alp.size();j++){
			if(S[i] == alp[j]){
				tmp = j;
				break;
			}
		}
		move = tmp + n;
		if(move >= 26){
			move -= 26;
		}
		S[i] = alp[move];
		tmp = 0;
	}
	cout << S << endl;

}



Measured memory_bytes: 256
using System;
using System.Linq;
class aoj
{
    static void Main()
    {
        int[] c = new int[8];
        c[0] = 1;c[1] = 2;c[2] = 1;c[3] = 2;c[4] = 1;c[5] = 4;c[6] = 1;c[7] = 4;
        while (true)
        {
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            int[] b = a.Split(' ').Select(int.Parse).ToArray();
            int[] f = new int[3];
            f[0] = 1000000000;
            for (int i = 0; i < 8; i++)
            {
                int e = 0;
                char[] h = new char[8];
                for (int j = 0; j < 8; j++)
                {
                    int d = j + i;
                    if (d >= 8)
                        d -= 8;
                    int g = b[j] - c[d];
                    if (g < 0)
                        g = 0;
                    e += g;
                    h[j] = (char)(c[d] + '0');
                }
                if (f[0] > e)
                {
                    f[0] = e;
                    f[1] = i;
                    string k = new string(h);
                    f[2] = int.Parse(k);
                }
                if (f[0] == e)
                {
                    string k = new string(h);
                    int l = int.Parse(k);
                    if (f[2] > l)
                    {
                        f[1] = i;
                        f[2] = l;
                    }
                }
            }
            int m = f[1];
            for (int i = 0; i < 8; i++)
            {
                int n = m + i;
                if (n >= 8)
                    n -= 8;
                if (i == 0)
                    Console.Write(c[n]);
                else
                    Console.Write(" " + c[n]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9504
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int year;
    int yen;
    cin >> year;
    cin >> yen;
    
    if(year>=13){
        cout << yen << endl;
    }else if(year<=5){
        cout << 0 << endl;
    }else{
        cout << yen/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll MOD = 1000000007ll;
ll dp[100100][13];
string s;
int main(){
	cin >> s;
	dp[0][0]=1ll;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<13;j++){
			if(s[i]=='?'){
				for(int k=0;k<10;k++){
					dp[i+1][(j*10+k)%13]+=dp[i][j];
					dp[i+1][(j*10+k)%13]%=MOD;
				}
			}else{
				int k = s[i]-'0';
				dp[i+1][(j*10+k)%13]+=dp[i][j];
				dp[i+1][(j*10+k)%13]%=MOD;
			}
		}
	}
	cout << dp[s.size()][5] << endl;
	return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
int n;
int bit[500001]={};
void add(int a,int x){
    for(int i=a;i<=n;i+=i&-i)bit[i]+=x;
    return;
}
int sum(int a){
    int s=0;
    for(int i=a;i>0;i-=i&-i)s+=bit[i];
    return s;
}
int main(){
    int q;
    cin>>n>>q;
    int c[n];
    for(int i=0;i<n;i++){
        cin>>c[i];
        c[i]--;
    }
    int l[q],r[q];
    tuple<int,int,int>query[q];
    for(int i=0;i<q;i++){
        cin>>l[i]>>r[i];
        query[i]={r[i],l[i],i};
    }
    sort(query,query+q);
    int good[n]={},ans[q];
    int R=0;
    for(int i=0;i<q;i++){
        while(R<get<0>(query[i])){
            if(good[c[R]])add(good[c[R]],-1);
            add(R+1,1);
            good[c[R]]=R+1;
            R++;
        }
        ans[get<2>(query[i])]=sum(get<0>(query[i]))-sum(get<1>(query[i])-1);
    }
    for(int i=0;i<q;i++)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 21304
import std.stdio;

int main(string[] argv)
{
	int list[30];

	foreach(n; 0..28) {
		int idx;
		readf("%d\n", &idx);
		list[idx-1]=1;
	}
	foreach(idx, n; list[0..30]) {
		if(n==0) writeln(idx+1);
	}

	return 0;
}

Measured memory_bytes: 2484
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a,b,c,d,e,f,g,h,i;
    scanf("%c%c%c",&a,&b,&c);
    getchar();
    scanf("%c%c%c",&d,&e,&f);
    getchar();
    scanf("%c%c%c",&g,&h,&i);
    getchar();
     printf("%c%c%c",a,e,i);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << '\n';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  ui N{}, K{}; cin >> N >> K;
  string S{}; std::cin >> S;

  vector<pair<ui, uc>> A;
  A.reserve(N);

  uc flag = S[0] - '0';
  A.push_back({ 0, flag });
  rep(0, N)
  {
    uc tmp = S[i] - '0';
    if (tmp != flag)
    {
      A.push_back({ i, tmp });
      flag = tmp;
    }
  }
  vector<ull> res(A.size());
  A.push_back({ N, -1 });
  rep(0, res.size())
  {
    auto cnt = K * 2;
    if (!A[i].second) --cnt;
    auto end = std::min((ui)A.size() - 1, i + cnt + 1);

    res[i] = A[end].first - A[i].first;
  }

  auto ans = *boost::max_element(res);

  using std::cout;
  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

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

    // case : 10 5 = 50
    // 1 * 49, 2 * 24, 3 * 16, 4 * 12, 5 * 9, 6 * 8, 7 * 7, 8 * 6, 9 * 5 (not), 
    // 10 * 4(not), 11 * 4, 12 * 4(not), 13 * 3, 14 * 3(not), 15 * 3(not), 16 * 3(not), 17 * 2, 18 * 2, 19 * 2, 20 * 2, 21 * 2, ..., 24 * 2, 25 * 1, ... 
    // ans : 12

    // case : 8*9 = 72
    // 1*71, 2*35, 3*23, 4*17, 5*14, 6*11, 7*10, 8*8, 
    // 高速化
    // c = a*b - 1
    // for(int i=1; i * i <= c; ++i) { long d = c / i; ans += (aが小さい場合); ans += (bが小さい場合) }
    // 可能な限り小さなa * 大きなb, 大きなa * 小さなbをcを超えないように選ぶ。
    // O(sqrt(c)) でできるが足りない。短縮する。
    // 結局 sqrt(c) * 2から、aが使われた場合、bが使われた場合、平方数が使われた場合それぞれ1を引けばいい？
    long a, b;
    while(q--) {
        cin >> a >> b;
        long c = a * b - 1;
        long l = 0, r = 1e9+100;
        while(r - l > 1) {
            long t = (l + r) / 2;
            if(t * t > c) r = t;
            else l = t;
        }

        long d = l;
        long e = d * 2;
        if(a <= d || b <= d) --e;
        // d * dはcを超えない最大の平方数か？
        long n1 = c - d * d, n2 = c - (d - 1) * d, n3 = c - (d + 1) * d;
        if(((n2 < 0) || (n1 < n2)) && ((n3 < 0) || (n1 < n3))) --e;
        cout << e << '\n';
    }
    return 0;
}

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

int main()
{
 int n; cin>>n;
 vector<ll> fib(n + 1);
 fib.at(0) = 1;
 fib.at(1) = 1;
 for (int i = 2; i <= n; i++)
 {
   fib.at(i) = fib.at(i - 1) + fib.at(i - 2);
 }
 cout << fib.at(n) << endl;

}


Measured memory_bytes: 3080
a,b=input().split()

wa = int(a) + int(b)
sa = int(a) - int(b)
seki = int(a) * int(b)

if wa >= sa and wa >= seki:
    print(str(wa))
elif sa >= wa and sa >= seki:
    print(str(sa))
else:
    print(str(seki))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define MAX INT_MAX
#define MIN INT_MIN
#define ss second
#define ff first
const int mod = 1e9+7;

int paths(vector<string> &v){
	int n = v.size();
	int m = v[0].size();
	int a[n][m];
	a[0][0] = 0;
	int num = 1;
	for(int i = 1; i < n; i++){
		if(v[i][0] == '#')
			num = 0;
		a[i][0] = num;
	}
	num = 1;
	for(int i = 1; i < m; i++){
		if(v[0][i] == '#')
			num = 0;
		a[0][i] = num;
	}
	for(int i = 1; i < n; i++){
		for(int j = 1; j < m; j++){
			if(v[i][j] == '#')
				a[i][j] = 0;
			else {
				a[i][j] = (a[i-1][j] + a[i][j-1]) % mod;
			}
		}
	}
	return a[n-1][m-1] % mod;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<string> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	cout << paths(v) << endl;
	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    int arr[n][3];
    for (int i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }int opt[n][3];
    opt[0][0]=arr[0][0];
    opt[0][1]=arr[0][1];
    opt[0][2]=arr[0][2];
    for (int i=1;i<n;i++){
        opt[i][0]=arr[i][0]+max(opt[i-1][1],opt[i-1][2]);
        opt[i][1]=arr[i][1]+max(opt[i-1][0],opt[i-1][2]);
        opt[i][2]=arr[i][2]+max(opt[i-1][0],opt[i-1][1]);
    }cout<<max(opt[n-1][0],max(opt[n-1][1],opt[n-1][2]));
    return 0;
}


Measured memory_bytes: 2560
N,M,K=map(int,input().split())
mod = 998244353

factorial=[1 for i in range(N+1)]
for i in range(1,N+1):
    if i==1:factorial[i]=1
    else:factorial[i] = factorial[i-1]*i % mod

def comb(n,k):
    return (factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod))%mod

def count(n,m,k):
  return m*comb(n-1,k)*pow(m-1,n-k-1,mod)%mod

print(sum([count(N,M,i) for i in range(K+1)]) % mod)

Measured memory_bytes: 24840
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int j=0;j<n;j++){
        cin>>b[j];
    }
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        if(a[i]>b[i])
        {
            flag=true;
            break;
        }
        else if(a[i]<b[i]){
            flag=false;
            break;
        }
    }
    if(flag)
    {
        swap(a,b);
    }
    int cnt=0;
    do{
        if(a==b)
            break;
        else
            cnt++;
    }
    while(next_permutation(a.begin(),a.end()));
    cout<<cnt<<endl;
    return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-9;
const ll MOD=1e9+7;
int main(){
    int h,w;cin>>h>>w;
    vector<vector<ll>> a(h,vector<ll>(w));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    ll ans=0;
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            ans+=a[i][j]*(i+1LL)*(j+1LL)*(h-i)*(w-j);
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4704
import math
while True:
    r0, w0, c, r = map(int, input().split())
    if (r0+w0+c+r) == 0:
        break
    else:
        tmp = math.ceil((w0*c - r0) / r)
        if tmp < 0:
            print(0)
        else:
            print(tmp)



Measured memory_bytes: 5656