akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static Scanner in = new Scanner(System.in);
    public static int n = 0, k = 0;
    public static int[] h = new int[100001];
    public static long[] dp = new long[100001];
    public final static long oo = 10000000000l;

    public static long solve(int idx) {
        if (idx == n - 1) {
            return 0;
        } else {
            if (dp[idx] == -1) {
                long min = oo;
                for (int i = 1; i <= k; i++) {
                    if (i + idx < n) {
                        min = Math.min(min, solve(idx + i) + Math.abs(h[idx] - h[idx + i]));
                    }
                }
                return dp[idx] = min;
            } else {
                return dp[idx];
            }
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100001; i++) {
            dp[i] = -1;
        }
        n = in.nextInt();
        k = in.nextInt();
        for (int i = 0; i < n; i++) {
            h[i] = in.nextInt();
        }
        System.out.println(solve(0));
    }

}


Measured memory_bytes: 73688
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


N = ii()
P = []
for _ in range(N):
    p = ii()
    P.append(p-1)

Q = [0 for i in range(N)]
for i in range(N):
    Q[P[i]] = i

maxcnt = 1
cnt = 1
for i in range(1, N):
    if Q[i] > Q[i-1]:
        cnt += 1
    else:
        cnt = 1

    maxcnt = max(maxcnt, cnt)

print(N - maxcnt)


Measured memory_bytes: 28220
#include <stdio.h>

int combination(int n,int x){
	int i,j,k;
	int cnt = 0;

	for(i = 1;i <= n-2;i++){
		for(j = i+1;j <= n-1;j++){
			for(k = j+1;k <= n;k++){
				if(i + j + k == x){
					cnt++;
				}
			}
		}
	}

	return cnt;
}

int main(void){
	int n,x,i,j,k;
	int cnt = 0;

	while(1){
		scanf("%d %d", &n, &x);

		if((n == 0 && x == 0) || (n < 3 || n > 100)){
			return 0;
		}

		printf("%d\n", combination(n,x));
	}
	return 0;
}

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

int main() {
    int n,c,count;
    c=0;
    count=0;
    cin >> n;
    for (int i=1; i<n+1; i=i+2){
        for (int j=1; j<i+1; j=j+2){
            if (i%j==0){
                c=c+1;
            }
        }
        if (c==8){
                count=count+1;
            }
        c=0;
    }
    cout << count;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, n) {
    if (1000000000000000000 / ans >= a[i]) {
      ans *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}

/*
1101
0111101101
*/

Measured memory_bytes: 3996
N,M = map(int, input().split())
scorebook = [[] for _ in range(N)]
for i in range(M):
    p,S = input().split()
    p = int(p)-1
    scorebook[p].append(S)
maru = 0
batu = 0
for score in scorebook:
    try:
        batu += score.index("AC")
        maru += 1
    except:
        pass
print(maru, batu)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N;
ll D;
ll x[200010],y[200010];
set<tuple<ll,ll,int> > stx,sty;
bool vis[200010];

int main(){
  ll a,b;
  cin>>N>>a>>b;
  a--;b--;
  rep(i,N){
    ll sx,sy;
    cin>>sx>>sy;
    ll tx=sx-sy;
    ll ty=sx+sy;
    x[i]=tx;
    y[i]=ty;
  }
  D=max(abs(x[a]-x[b]),abs(y[a]-y[b]));
  rep(i,N){
    if(i==a||i==b)continue;
    stx.insert(make_tuple(x[i],y[i],(int)i));
    sty.insert(make_tuple(y[i],x[i],(int)i));
  }

  queue<int> que;
  que.push(a); que.push(b);
  vis[a]=vis[b]=true;
  while(que.size()){
    int v=que.front(); que.pop();
    ll xl=x[v]-D; ll xr=x[v]+D;
    ll yl=y[v]-D; ll yh=y[v]+D;

    auto it=stx.lower_bound(make_tuple(xl,yl,0));
    while(it!=stx.end()&&get<0>(*it)==xl&&get<1>(*it)<=yh){
      int idx=get<2>(*it);
      que.push(idx);
      vis[idx]=true;
      sty.erase(make_tuple(y[idx],x[idx],idx));
      stx.erase(it++); 
    }

    it=stx.lower_bound(make_tuple(xr,yl,0));
    while(it!=stx.end()&&get<0>(*it)==xr&&get<1>(*it)<=yh){
      int idx=get<2>(*it);
      que.push(idx);
      vis[idx]=true;
      sty.erase(make_tuple(y[idx],x[idx],idx));
      stx.erase(it++);
    }

    it=sty.lower_bound(make_tuple(yl,xl,0));
    while(it!=sty.end()&&get<0>(*it)==yl&&get<1>(*it)<=xr){
      int idx=get<2>(*it);
      que.push(idx);
      vis[idx]=true;
      stx.erase(make_tuple(x[idx],y[idx],idx));
      sty.erase(it++);
    }

    it=sty.lower_bound(make_tuple(yh,xl,0));
    while(it!=sty.end()&&get<0>(*it)==yh&&get<1>(*it)<=xr){
      int idx=get<2>(*it);
      que.push(idx);
      vis[idx]=true;
      stx.erase(make_tuple(x[idx],y[idx],idx));
      sty.erase(it++);
    }
  }

  vector<P> vx,vy;
  rep(i,N){
    vx.push_back(make_pair(x[i],y[i]));
    vy.push_back(make_pair(y[i],x[i]));
  }
  sort(all(vx)); sort(all(vy));

  ll res=0;
  rep(i,N){
    if(!vis[i])continue;
    ll xl=x[i]-D; ll xr=x[i]+D;
    ll yl=y[i]-D; ll yh=y[i]+D;
    res+=lower_bound(all(vx),make_pair(xl,yh))-upper_bound(all(vx),make_pair(xl,yl));
    res+=lower_bound(all(vx),make_pair(xr,yh))-upper_bound(all(vx),make_pair(xr,yl));
    res+=upper_bound(all(vy),make_pair(yl,xr))-lower_bound(all(vy),make_pair(yl,xl));
    res+=upper_bound(all(vy),make_pair(yh,xr))-lower_bound(all(vy),make_pair(yh,xl));
  }

  cout<<res/2<<endl;

  return 0;
}


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

using namespace std;
typedef         long long int   ll;

#define         input           freopen("input.txt","r",stdin)
#define         output          freopen("output.txt","w",stdout)
#define         si(a)           scanf("%d",&a)
#define         sii(a,b)        scanf("%d%d",&a,&b)
#define         siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define         pi(a)           printf("%d",a)
#define         spc             printf(" ")
#define         bl              printf("\n")
#define         here(a)         printf("#### %d ####",a)
#define         pii             pair<int,int>
#define         fr(i,n)         for(int i=0;i<n;i++)
#define         case(num)       printf("Case %d:",num)
#define         inf             1000000050
#define         MAX             10010
#define         MOD             1000000007

int flag[MAX+10];
int flag2[1000000+10];
vector<int>prime;

int main(){

    //input;
    //output;
    flag [0] = 1;
    flag [1] = 1;
    int sq = sqrt(MAX);
    for(int i=4;i<MAX; i+= 2) flag[i] = 1;
    for(int i=3;i<sq;i+=2){
        if(flag[i]==0){
            for(int j=i*i;j<MAX;j+=i){
                flag[j] = 1;
            }
        }
    }

    for(int i=0;i<MAX;i++)
        if(flag[i]==0){
            prime.push_back(i);
        }

    int n;
    cin>>n;
    vector<int>v(n);

    int pair_flag = 0;
    int set_flag = 0;
    int gcd = 0;

    for(int i=0;i<n;i++){
        cin>>v[i];
        if(i>0){
            gcd = __gcd(gcd,v[i]);
        }else gcd = v[0];
    }

    for(int i=0;i<n;i++){
        int m = v[i];

        for(int j=0;j<prime.size();j++){
            if(prime[j]>m) break;

            if(m%prime[j]==0){
                while(m%prime[j]==0){
                    m /= prime[j];
                }
                flag2[prime[j]]++;

                if(flag2[prime[j]]>1){
                    pair_flag = 1;
                    break;
                }
                if(m==1) break;
            }
        }
        if(m!=1){

            flag2[m]++;
            if(flag2[m]>1){
                pair_flag = 1;
                break;
            }
        }
        if(pair_flag) break;
    }


    if(!pair_flag){
        cout<<"pairwise coprime"<<endl;
    }else if(gcd==1){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"not coprime"<<endl;
    }


    return 0;
}
/**
*/


Measured memory_bytes: 7616
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M = map(int, input().split())
edges = [set() for _ in range(N)]
ins = [0]*N
for _ in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    ins[b] += 1
    edges[a].add(b)

dp = [-1]*N

start = []
for i in range(N):
    if ins[i] == 0:
        start.append(i)


def dfs(s):
    if dp[s] != -1:
        return dp[s]
    mx = 0
    if edges[s]:
        mx = max([dfs(dest)+1 for dest in edges[s]])
    dp[s] = mx
    return mx


ans = max(dfs(i) for i in range(N))
print(ans)


Measured memory_bytes: 125072
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main() {
    long x;
    cin >> x;

    long cnt = 2 * (x / 11);
    if(x % 11 == 0){
        cnt += 0;
    }else if(x % 11 <= 6){
        cnt += 1;
    }else{
        cnt += 2;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()


ll func1(ll x, ll val, vector <ll> &vec){
   while(x < 1e6+1){
         vec[x] = max(vec[x], val);
         x += (x&-x);
   }
}

ll func2(ll x, vector <ll> vec){
   ll ans = 0;
   while(x > 0){
         ans = max(ans, vec[x]);
         x -= (x&-x);
   }
   return ans;
}


int main()
{
   string s;
   cin >> s;
  string s1 = s.substr(0, 3);
  string s2 = s.substr(1, 3);
  int ind = 0;
  while(ind < s1.size()-1){
       if(s1[ind] == s1[ind+1]) ind++;
       else break;
  }

  if(ind == s1.size()-1){
    cout << "Yes"; return 0;
  }
  ind = 0;
  while(ind < s2.size()-1){
       if(s2[ind] == s2[ind+1]) ind++;
       else break;
  }

  if(ind == s1.size()-1){
    cout << "Yes"; return 0;
  }
  cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef long long ll;
const int maxn = 100010;

int n;
ll C, x[maxn];
int v[maxn];
ll pre[maxn], suf[maxn];
ll p_sum[maxn], s_sum[maxn];
ll val_p[maxn], val_s[maxn];

int main() {
    cin >> n >> C;
    ll ans1 = 0, ans2 = 0;
    for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
    {
        for (int i = 1; i <= n; i++) {
            p_sum[i] = p_sum[i-1]+v[i];
        }
        for (int i = n; i >= 1; i--) {
            s_sum[i] = s_sum[i+1]+v[i];
        }
        for (int i = 1; i <= n; i++) {
            val_p[i] = p_sum[i]-2*x[i];
            val_s[i] = s_sum[i]-(C-x[i]);
        }
        for (int i = 1; i <= n; i++) pre[i] = max(pre[i-1], val_p[i]);
        for (int i = n; i >= 1; i--) suf[i] = max(suf[i+1], val_s[i]);
        for (int i = 0; i <= n; i++) {
            ans1 = max(ans1, pre[i]+suf[i+1]);
        }
    }
    {
        for (int i = 1; i <= n; i++) {
            p_sum[i] = p_sum[i-1]+v[i];
        }
        for (int i = n; i >= 1; i--) {
            s_sum[i] = s_sum[i+1]+v[i];
        }
        for (int i = 1; i <= n; i++) {
            val_p[i] = p_sum[i]-x[i];
            val_s[i] = s_sum[i]-2*(C-x[i]);
        }
        for (int i = 1; i <= n; i++) pre[i] = max(pre[i-1], val_p[i]);
        for (int i = n; i >= 1; i--) suf[i] = max(suf[i+1], val_s[i]);
        for (int i = 0; i <= n; i++) {
            ans2 = max(ans2, pre[i]+suf[i+1]);
        }
    }
    cout << max(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
struct Point{
    double x,y;
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);  
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    REP(i,n){
        cout << a[i] << b[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
void main() {
    import std.stdio, std.string, std.conv, std.algorithm, std.range, std.array;
    int N, Y;
    readf("%d %d\n", &N, &Y);
    Y /= 1000;
    foreach (i; 0..min(N, Y/10) + 1) {
        foreach (j; 0..min(N-i, (Y-10*i)/5) + 1) {
            auto k = N-i-j;
            if (10*i+j*5+k == Y) {
                writefln("%d %d %d", i, j, k);
                return;
            }
        }
    }
    writeln("-1 -1 -1");
}


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

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

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

    vector<int> diff(n);
    rep (i, n)
    {
        int temp;
        cin >> temp;
        diff[i] = abs(x - temp);
    }

    int ans = diff[0];
    for (int i = 1; i < n; i++)
        ans = gcd(ans, diff[i]);

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

Measured memory_bytes: 3720
from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)
    
def bfs(u):
    queue = deque([u])
    d = [None]*n
    
    d[u] = 0
    while queue:
        v=queue.popleft()
        for i in g[v]:
            if d[i] is None:
                d[i] = d[v]+1
                p[i] = v
                queue.append(i)
    return d

p = [None]*n
d = bfs(0)
if None in p[1:]:
    print('No')
else:
    print('Yes')
        
for q in range(1,len(p)):
    print(int(p[q])+1)

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

using namespace std;

int main()
{
  int p[3], d, e;
  while(cin >> p[0] >> p[1] >> p[2] >> d >> e, p[0] || p[1] || p[2] || d || e){
    int n[3];
    for(int i = 0; i < 3; i++) cin >> n[i];
    int ans = p[0]*n[0] + p[1]*n[1] + p[2]*n[2];
    if(n[2] >= d) ans = min(ans, p[0]*n[0] + p[1]*n[1] + e*n[2]);
    else if(n[2] + n[1] >= d) ans = min(ans, p[0]*n[0] + p[1]*(n[1]-(d-n[2])) + e*d);
    else if(n[2] + n[1] + n[0] >= d) ans = min(ans, p[0]*(n[0]-(d-n[2]-n[1])) + e*d);
    else ans = min(ans, d*e);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    INT(n, m);
    ll res = 1;
    for(ll i = 1; i <= sqrt(m); i++){
        if(m % i) continue;
        if(m / i >= n) chmax(res, i);
        if(i >= n) chmax(res, m / i);
    }
    print(res);
}

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

vector<int> a;
void update(int i, pair<int, int> &p)
{
    if (i == p.first || i == -1) return;
    if (p.first == -1 || a[i] > a[p.first])
    {
        swap(p.first, p.second);
        p.first = i;
    }
    else if (p.second == -1 || a[i] > a[p.second]) p.second = i;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    int n;  cin >> n;
    a.resize(1 << n);
    for (int &i : a) cin >> i;
    vector<pair<int, int>> v(1 << n, {-1, -1});
    vector<int> ans(1 << n, 0);
    for (int i = 0; i < 1 << n; ++i)
    {
        update(i, v[i]);
        for (int j = 1; j <= n; ++j)
            if (((i >> (j - 1)) & 1) == 0)
            {
                int x = i ^ (1 << (j - 1));
                update(v[i].first, v[x]);
                update(v[i].second, v[x]);
            }
        if (i)
        {
            ans[i] = max(ans[i - 1], a[v[i].first] + a[v[i].second]);
            cout << ans[i] << '\n';
        }
    }
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

const double PI = acos(-1);

int main() {
    int N, R;
    cin >> N >> R;
    if (N >= 10) cout << R << endl;
    else cout << R+100*(10-N) << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 310
using namespace std;
namespace IO{
	const int BS=(1<<19); int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD=Buffer,*TL=Buffer,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS-1,stdin);} return *HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top; Putchar('\n');
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
int n,m,p[M][M],fd[M],cnt[M],ans;
bool vis[M];
bool del(){
	for(int i=1;i<=m;i++) if(cnt[i]>=ans) vis[i]=true;
	for(int i=1;i<=n;i++){
		while(fd[i]<=m&&vis[p[i][fd[i]]]) fd[i]++;
		if(fd[i]>m) return false;
	}
}
void calc(){
	int maxn=0; memset(cnt,0,sizeof(cnt));
	for(int i=1;i<=n;i++) cnt[p[i][fd[i]]]++;
	for(int i=1;i<=m;i++) maxn=max(maxn,cnt[i]);
	ans=min(ans,maxn);
}
int main(){
	n=read(),m=read(),memset(vis,false,sizeof(vis));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) p[i][j]=read();
		cnt[p[i][fd[i]=1]]++,ans=max(ans,cnt[p[i][1]]);
	}
	while(del()&&ans>1) calc(); printf("%d\n",ans); return 0;
}

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

const int N=1000005;
char s[N];

int main(){

	int n;

	scanf("%s%d",s,&n);

	for(int i=0;s[i];i+=n)
		putchar(s[i]);

	return !printf("\n");
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, k;
  int x[100];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] < abs(k - x[i])) {
      ans += x[i] * 2;
    } else {
      ans += abs(k - x[i]) * 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3152
#include <iostream>

std::string S, T;

int main() {
  std::cin >> S >> T;

  int ans = 1000;
  for (int i = 0; i < S.size() - T.size() + 1; ++i) {
    int cur = 0;
    for (int j = 0; j < T.size(); ++j) {
      if (S[i + j] != T[j])
        cur++;
    }
    ans = std::min(ans, cur);
  }
  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3580
#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
mx = 0
ret = 0
for i in range(n):
    if a[i] < mx:
        ret += mx-a[i]
    else:
        mx = a[i]
print(ret)


Measured memory_bytes: 32332
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int count = 0;
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'R') {
				count++;
			}
		}

		if( count > (n-count) ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> mat;
    mat.resize(H);
    REP(i, H) {
        mat[i].resize(W);
    }
    REP(i, H) {
        REP(j, W) {
            cin >> mat[i][j];
        }
    }

    vector<pair<pair<int, int>, pair<int, int>>> res;
    REP(i, H) {
        REP(j, W - 1) {
            if(mat[i][j]%2) {
                mat[i][j]--;
                mat[i][j + 1]++;
                res.push_back(make_pair(make_pair(i + 1, j + 1), make_pair(i + 1, j + 2)));
            }
        }
    }
    REP(i, H - 1) {
        if(mat[i][W - 1]%2) {
            mat[i][W - 1]--;
            mat[i + 1][W - 1]++;
                res.push_back(make_pair(make_pair(i + 1, W), make_pair(i + 2, W)));
        }
    }
    cout << res.size() << endl;
    REP(i, res.size()) {
        cout << res[i].first.first << " " << res[i].first.second << " " << res[i].second.first << " " << res[i].second.second << endl;
    }
    return 0;
}



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

#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
namespace adaptor = boost::adaptors;

// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */

using ll = long long;
using ull = unsigned long long;

/*
	int N;
	std::cin >> N;
	std::vector<int> vec(N);
	for (auto& v : vec)
	{
		std::cin >> v;
	}
*/

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

	bool f = false;
	int cnt = 0;
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		if (x == y) {
			++cnt;
			if (cnt == 3) {
				f = true;
			}
		}
		else {
			cnt = 0;
		}
	}
	if (f) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 3632
#include <iostream> 
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main () {
 long long int n,k,r,s,p,l,sum=0;cin>>n>>k>>r>>s>>p;
 string q;cin>>q;
 l=q.length();
 for (long long int i=0;i<l;i++) {
     if (q[i]=='s') {
         if (i>=k) {
             if (q[i-k]!='s') sum+=r; 
              else q[i]='R';
         }
         else {
             sum+=r;
         }
     }
      if (q[i]=='r') {
         if (i>=k) {
             if (q[i-k]!='r') sum+=p; 
             else q[i]='R';
         }
         else {
             sum+=p;
         }
     }
      if (q[i]=='p') {
         if (i>=k) {
             if (q[i-k]!='p') sum+=s; 
              else q[i]='R';
         }
         else {
             sum+=s;
         }
     }
     //cout<<q<<endl;
 }
 cout<<sum<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n);
    vector<pair<int,int>> vec(n);
    int x,y,left,right;
    rep(i,n){
        in(x,y);
        right=x+y;
        left=x-y;
        vec[i]=make_pair(right,left);
    }
    sort(all(vec));
    int end=vec[0].first,ans=1;
    for(int i=1;i<n;i++){
        if(end<=vec[i].second){
            end=vec[i].first;
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 4092
use std::cmp::Ordering;
use std::collections::BinaryHeap;

fn main() {
    solve_c();
}
#[derive(Debug)]
struct Sara {
    diff: isize,
    a: isize,
    b: isize,
    index: usize,
}
impl Eq for Sara {
}
impl PartialEq for Sara {
    fn eq(&self, other: &Self) -> bool {
        self.diff == other.diff
    }
}
impl PartialOrd for Sara {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        self.diff.partial_cmp(&other.diff)
    }
}
impl Ord for Sara {
    fn cmp(&self, other: &Self) -> Ordering {
        self.diff.cmp(&other.diff)
    }
}
fn solve_c() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let n: usize = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut saras: BinaryHeap<Sara> = BinaryHeap::with_capacity(n);
    for i in 0..n {
        handle.read_line(&mut buf).unwrap();
        let tmp: Vec<isize> = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        let sara: Sara = Sara {
            diff: tmp[0] + tmp[1],
            a: tmp[0],
            b: tmp[1],
            index: i,
        };
        saras.push(sara);
        buf.clear();
    }
    let mut takahashi = 0;
    let mut aoki = 0;
    for i in 0..n {
        if i % 2 == 0 {
            // takahashi
            let sara = saras.pop().unwrap();
            takahashi += sara.a;
        } else {
            // aoki
            let sara = saras.pop().unwrap();
            aoki += sara.b;
        }
    }
    println!("{}", takahashi-aoki);
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll K;
    vector<ll>A(3);
    cin >>A[0]>>A[1]>>A[2]>>K;
    sort(all(A));
    cout << A[0]+A[1]+A[2]*pow(2,K) << endl;


    return 0;
    

}

Measured memory_bytes: 4092
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt() + 1;
        }

        int max = 0;
        int s = 0;
        Queue<Integer> queue = new ArrayDeque<>();

        for (int i = 0; i < n; i++) {
            s += p[i];
            queue.add(p[i]);
            if (queue.size() > k) {
                s -= queue.poll();
            }
            if (queue.size() == k) {
                max = Math.max(max, s);
            }
        }

        System.out.println((double) max / 2);
    }
}

Measured memory_bytes: 78000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  unordered_set<int> S;
  for (int i=0; i<N; i++) {
    int A; cin >> A;
    if ( S.count(A) ) S.erase(A);
    else S.insert(A);
  }
  
  cout << S.size() << endl;
  
}

Measured memory_bytes: 4388
// バケット法による解
#include <iostream>
using namespace std;

int main() {
    int n;
    int d[110];
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> d[i];
  
  int a[110]= {0};
  for(int i=0;i<n;++i){
     a[d[i]]+= 1;
  }
  int res=0;
  for(int i=1;i<=100;++i){
    if(a[i])res++;
  }
  
    cout << res << endl;
}


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

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

int main(){    
    int n ;
    cin >> n ;
    n -= 200 ;
    cout << 9 - (n/200) << endl ;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<map>
#define fs first
#define sc second
using namespace std;

typedef pair<int,int> P;

int n,m;
P h[300];
int a,b,c,d[300][300],dis[300];
bool use[300],vis[300];
const int INF = (1<<25);

int main(){
  while(scanf("%d%d",&n,&m),n||m){
    for(int i=0;i<n;i++){
      scanf("%d",&h[i].fs);
      h[i].sc = i;
      for(int j=0;j<n;j++)d[i][j] = INF;
      d[i][i] = 0;
    }

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

    sort(h,h+n);
    reverse(h,h+n);

    fill(use,use+n,false);
    fill(vis,vis+n,false);
    fill(dis,dis+n,INF);
    dis[h[0].sc] = 0;

    long long ans = 0;
    for(int i=0;i<n;i++){
      use[h[i].sc] = true;
      while(i+1<n && h[i].fs == h[i+1].fs)use[h[++i].sc] = true;
      
      while(1){
	int v = -1;
	for(int u=0;u<n;u++){
	  if(use[u] && !vis[u] && (v<0 || dis[v]>dis[u]))v = u;
	}

	if(v<0)break;
	if(dis[v] == INF){
	  fill(vis,vis+n,false);
	  fill(dis,dis+n,INF);
	  ans = dis[h[0].sc] = 0;
	  break;
	}

	vis[v] = true;
	ans += dis[v];
	for(int i=0;i<n;i++)dis[i] = min(dis[i],d[v][i]);
      } 
    }
    printf("%lld\n",ans);
  }
}

Measured memory_bytes: 1276
#include <stdio.h>
#define M 100

int main(){
    int A[M][M];
    int n,i,j,u,t,x;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            A[i][j]=0;
        }
    }

    for(i=0;i<n;i++){
        scanf("%d%d",&u,&t);
        u--;
        for(j=0;j<t;j++){
            scanf("%d",&x);
            x--;
            A[u][x]=1;
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<n-1;j++){
            printf("%d ",A[i][j]);
        }
        printf("%d",A[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<int64_t> a(n+1);
    for (auto i = 0; i <= n; i++) cin >> a[i];

    vector<int64_t> tree(n+1, 0);
    tree[n] = a[n];
    for (auto i = n - 1; i >= 0; i--) tree[i] = a[i] + tree[i + 1];

    int64_t ans = 1;
    tree[0] = 1;
    if(a[0] > 1) {
        cout << -1 << endl;
        return 0;
    }
    // cout << tree[0] << endl;
    for (auto i = 1; i <= n; i++) {
        tree[i] = min(tree[i], (tree[i - 1] - a[i - 1]) * 2);
        if(tree[i] <= 0 or tree[i] < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans += tree[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4840
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

type Clue struct {
	x int
	y int
	h int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	nClues := scanInt(sc)

	clues1 := make([]Clue, 0, nClues)
	clues2 := make([]Clue, 0, nClues)
	for i := 0; i < nClues; i++ {
		x := scanInt(sc)
		y := scanInt(sc)
		h := scanInt(sc)
		if h > 0 {
			clues1 = append(clues1, Clue{x, y, h})
		} else {
			clues2 = append(clues2, Clue{x, y, h})
		}
	}

	height := -1
	centerX := -1
	centerY := -1

LOOP_X:
	for cx := 0; cx <= 100; cx++ {
		for cy := 0; cy <= 100; cy++ {
			height = -1
			ok := true

			for _, clue := range clues1 {
				sum := int(math.Abs(float64(clue.x-cx)) + math.Abs(float64(clue.y-cy)))
				if height == -1 {
					height = sum + clue.h
				} else if sum+clue.h != height {
					ok = false
					break
				}
			}

			if ok {
				if height == -1 {
					clue := clues2[0]
					height = int(math.Abs(float64(clue.x-cx)) + math.Abs(float64(clue.y-cy)))
				} else {
					for _, clue := range clues2 {
						sum := int(math.Abs(float64(clue.x-cx)) + math.Abs(float64(clue.y-cy)))
						if sum < height {
							ok = false
							break
						}
					}
				}

				if ok {
					centerX = cx
					centerY = cy
					break LOOP_X
				}
			}
		}
	}

	fmt.Println(centerX, centerY, height)
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

Measured memory_bytes: 640
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = input()

ans = 1
for x in Counter(S).values():
	ans *= x+1
	ans %= mod
print((ans-1)%mod)


Measured memory_bytes: 5972
<?php
while(fscanf(STDIN, "%d", $n) && $n) {
  $map = array(array());

  for($i = 0; $i < 21; $i++) {
    for($j = 0; $j < 21; $j++) {
      $map[$i][$j] = 0;
    }
  }

  for($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d", $x, $y);
    $map[$y][$x] = 1;
  }

  fscanf(STDIN, "%d", $m);
  
  $cnt = 0;
  $x = 10;
  $y = 10;
  $dx = array(1, 0, -1, 0);
  $dy = array(0, 1, 0, -1);
  $dir = array('E' => 0, 'N' => 1, 'W' => 2, 'S' => 3);
  
  for($i = 0; $i < $m; $i++) {
    fscanf(STDIN, "%c %d", $d, $l);
    for($j = 0; $j < $l; $j++) {
      $x += $dx[$dir[$d]];
      $y += $dy[$dir[$d]];
      if($map[$y][$x]) {
        $map[$y][$x] = 0;
        $cnt++;
      }
    }
  }

  print ($cnt == $n ? "Yes" : "No") . "\n";
}

Measured memory_bytes: 6684
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Maybe (fromJust)

solve :: Int -> Int -> Int -> Int
solve w a b
    | a <= b && b <= a + w = 0
    | b <= a && a <= b + w = 0
    | b > a = b - w - a
    | otherwise = a - b - w

main :: IO ()
main = do
    (w:a:b:_) <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    print $ solve w a b

Measured memory_bytes: 380
#include <iostream>

int main () {
  int x, y;
  while(1){
    std::cin >> x >> y;
  	if(x + y == 0)
  	  break;
  	else if(x < y) 
  	  std::cout << x << ' ' <<  y << std::endl;
  	else
  	  std::cout << y << ' ' <<  x << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3092
n, k =map(int,input().split())
s = input()

sp = "1"
count = 0
cu = []
cd = []
for i in range(n):
    if sp == s[i]:
        count += 1
    else:
        if sp == "1":
            cu.append(count)
        else:
            cd.append(count)
        count = 1
    sp = s[i]
if sp == "1":
    cu.append(count)
else:
    cd.append(count)
ans = 0
for i in range(len(cd)):
    ld = i
    rd = min(i + k - 1, len(cd)-1)
    lu = i
    ru = min(rd+1,len(cu)-1)        
    if i == 0:
        sn = 0
        sn += sum(cd[ld:rd+1])
        sn += sum(cu[lu:ru+1])
    else:
        if ldp < ld:
            sn-=cd[ldp]
        if rdp < rd:
            sn+=cd[rd]
        if lup < lu:
            sn-=cu[lup]
        if rup < ru:
            sn+=cu[ru]
    ans = max(ans,sn)
    ldp,rdp,lup,rup = ld,rd,lu,ru
if len(cd)==0:
    ans = n
print(ans)

Measured memory_bytes: 4460
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <limits>

using namespace std;

template<class T = int,T divided_by = 10>
constexpr T PINF(){ return std::numeric_limits<T>::max()/divided_by; }
template<class T = int,T divided_by = 10>
constexpr T MINF(){ return std::numeric_limits<T>::lowest()/divided_by; }

template<class T = int> T gcd(T a, T b){ return b ? gcd(b,a%b) : a; }
template<class T = int> T lcm(T a, T b){ return a / gcd(a,b) * b; }
template<class T = int> T lcm_safe(T a, T b){ T p = a/gcd(a,b); return (b <= PINF<T>()/p) ? p*b:PINF<T>(); }
//オーバーフローするとき+INFを返す
//
int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);

	long long a, b;
	cin >> a >> b;
	if (a%3 == 0 || b%3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	if (b < a) { swap(a,b); }


	long long ans_a = a;

	long long ans_b;
	{
		long long p = (b/3) * a;
		long long q = a/2 * (b-b/3);
		long long r = a%2 == 0 ? q : (a/2+1) * (b-b/3);
		ans_b = max(p,max(q,r)) - min(p,min(q,r));
	}

	long long ans_c;
	{
		long long p = (b/3 + 1) * a;
		long long q = a/2 * (b-(b/3 + 1));
		long long r = a%2 == 0 ? q : (a/2+1) * (b-(b/3 + 1));
		ans_c = max(p,max(q,r)) - min(p,min(q,r));
	}


	swap(a,b);
	long long ans_d;
	{
		long long p = (b/3) * a;
		long long q = a/2 * (b-b/3);
		long long r = a%2 == 0 ? q : (a/2+1) * (b-b/3);
		ans_d = max(p,max(q,r)) - min(p,min(q,r));
	}

	long long ans_e;
	{
		long long p = (b/3 + 1) * a;
		long long q = a/2 * (b-(b/3 + 1));
		long long r = a%2 == 0 ? q : (a/2+1) * (b-(b/3 + 1));
		ans_e = max(p,max(q,r)) - min(p,min(q,r));
	}

	cout << min(ans_a,min(ans_b,min(ans_c,min(ans_d,ans_e)))) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int m,f,r;
    while(1)
    {
        scanf("%d%d%d",&m,&f,&r);
        if(m+f+r==-3)
            break;
        if(m==-1||f==-1)
            printf("F\n");
        else if(m+f>=80)
            printf("A\n");
        else if(m+f>=65)
            printf("B\n");
        else if(m+f>=50)
            printf("C\n");
        else if(m+f>=30)
        {
            if(r>=50)
                printf("C\n");
            else
                printf("D\n");
        }
            
        else
            printf("F\n");
    }
    return 0;
}



Measured memory_bytes: 2040
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		String[] input = new String[h];
		int[][] mineCnt = new int[h][w];

		for (int i = 0; i < h; i++)
		{
			input[i] = scanner.next();
		}

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (input[i].charAt(j) == '#')
				{
					if ((i > 0) && (j > 0))		mineCnt[i-1][j-1]++;
					if (i > 0)					mineCnt[i-1][j]++;
					if ((i > 0) && (j < w-1))	mineCnt[i-1][j+1]++;
					if (j > 0)					mineCnt[i][j-1]++;
					if (j < w-1)				mineCnt[i][j+1]++;
					if ((i < h-1) && (j > 0))	mineCnt[i+1][j-1]++;
					if (i < h-1)				mineCnt[i+1][j]++;
					if ((i < h-1) && (j < w-1))	mineCnt[i+1][j+1]++;
				}
			}
		}

		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (input[i].charAt(j) == '#')
				{
					System.out.print('#');
				}
				else
				{
					System.out.print(mineCnt[i][j]);
				}
			}
			System.out.println();
		}
		scanner.close();
	}
}

Measured memory_bytes: 23252
//use std::convert::TryInto;
#![allow(dead_code)]

fn main(){
    let n: i64 = input();
    println!("{}", solve(n))
}

fn solve(mut n: i64) -> String {
    let mut res = Vec::new();
    while n>0 {
        n -= 1;
        let s = (n%26) as u8 + 'a' as u8;
        let s = s as char;
        res.push(s);
        n /= 26;
    }
    res.reverse();
    res.into_iter().collect()
}


/*
 * input function
 */
fn input<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

Measured memory_bytes: 2148
import std.stdio;
import std.conv;
import std.algorithm;
import std.array;
import std.range;
import std.string;
 
void main(){
auto ab=readln.split.map!(to!int).array;
auto sp=readln.chomp.split('-').map!(a=>a.array.length).array;
writeln(ab.equal(sp)?"Yes":"No");
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=B[A[i]-1]
    if i>=1:
        if A[i]==A[i-1]+1:
            ans+=C[A[i-1]-1]
print(ans)


Measured memory_bytes: 3064
import sys
import bisect
input = sys.stdin.readline

n = int(input())
S = list(map(lambda x: int(x), input().strip().split()))

q = int(input())

count = 0
for t in input().strip().split():
    t = int(t)
    if S[bisect.bisect_left(S, t)] == t:
        count += 1
print(count)


Measured memory_bytes: 16732
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;


#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)


#define INF 		2000000007
#define MOD			998244353

#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;




int main(){
	int R,G,B,N;	cin >> R >> G >> B>> N;
	int cnt = 0;
	int suml;
	REP(i,3001){
		if ( i * R > N ) break;
		REP(j,3001){
			suml = i* R + j * G;
			if ( suml > N ) break;
			if ( (N - suml) % B == 0 )cnt++;
		//	cout << (N-suml) << " " <<suml << " " << i << " " << j << endl;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int d; cin >> d;
    map<int, string> mp;
    mp[25] = "Christmas";
    mp[24] = "Christmas Eve";
    mp[23] = "Christmas Eve Eve";
    mp[22] = "Christmas Eve Eve Eve";
    cout << mp[d] << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll Q,H,S,D;
  cin>>Q>>H>>S>>D;
  ll N;
  cin>>N;
  H=min(2*Q,H);
  S=min(2*H,S);
  D=min(2*S,D);
  cout<<N/2*D+N%2*S<<endl;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
        return 0;
    }
    cout << "ABC" << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << A[K-1] << "\n";
  return 0;
}


Measured memory_bytes: 3600