akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long dp[100005][2];
vector<int>v[100005];
long long md = 1e9+7;
long long rec(int x, int col, int par){
	if(v[x].size() == 1 && v[x][0] == par){
		return 1;
	}
	if(dp[x][col] != -1)return dp[x][col];
	long long ret = 1;
	for(int i = 0 ; i < v[x].size(); i++){
		long long sum0 = 1, sum1 = 1;
		if(col == 1)sum1 = 0;
		int y = v[x][i];
		if(y == par)continue;
		if(col == 0){
			sum1 = rec(y, 1, x)%md;
		}
		sum0 = rec(y, 0, x)%md;
		ret *=(sum1+sum0)%md;
		ret %= md;
	}
	return dp[x][col] = ret;
}
int main(){
	int n;
	cin >> n;
	for(int i = 0; i <= 100000; i++)
		dp[i][0] = -1, dp[i][1] = -1;
	for(int i = 1; i < n; i++){
		int x, y;
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	cout <<  (rec(1, 1, 0) + rec(1, 0, 0))%md;
}

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

int main() {
  string s;
  cin>>s;
  if(s.at(0)!=s.at(1)&&s.at(1)!=s.at(2)&&s.at(0)!=s.at(2)) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
	long long n,T,t[200000];
	long long sum=0;
	cin>>n>>T;
	for(long long i=1;i<=n;i++)
		cin>>t[i];
	for(long long i=2;i<=n;i++){
		if(t[i]-t[i-1]>=T)
			sum+=T;
		else
			sum+=t[i]-t[i-1];
	}
	sum+=T;
	cout<<sum<<endl;
}





Measured memory_bytes: 1792
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let n = read!(usize);
    let s = read!(String; n);

    let mut map = HashSet::new();
    for e in &s {
        map.insert(e);
    }
    println!("{}", map.len());
}


Measured memory_bytes: 16404
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, a[100009];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int l = *min_element(a, a + n), r = *max_element(a, a + n);
	if (r - l >= 2) printf("No\n");
	else if (r - l == 0) printf(l + 1 == n || l * 2 <= n ? "Yes\n" : "No\n");
	else {
		int cnt = 0;
		for (int i = 0; i < n; i++) if (a[i] == l) cnt++;
		printf(cnt <= l && n - cnt >= 2 * (l + 1 - cnt) ? "Yes\n" : "No\n");
	}
	return 0;
}

Measured memory_bytes: 512
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int R;
  ci(R);
  if(R < 1200){
    co("ABC");
  }
  else if(R < 2800){
    co("ARC");
  }
  else{
    co("AGC");
  }
}

Measured memory_bytes: 256
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 100100
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    ll s,w;cin>>s>>w;
    if(w>=s)
        cout<<"unsafe\n";
    else
        cout<<"safe\n";
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
string S;
int main()
{
	file();
	cin>>S;
	if(S.find("AC")<S.length())puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 20;
int n,data[maxn],tmp[maxn];
int main(){
	cin >> n;
	for(int i = 1;i <= n;++i)scanf("%d",&data[i]);
	memcpy(tmp,data,sizeof(data));
	stable_sort(tmp + 1,tmp + n + 1);
	int mid = tmp[n/2 + 1],mid_p = tmp[n/2];
	for(int i = 1;i <= n;++i)
		if(data[i] < mid)printf("%d\n",mid);
		else printf("%d\n",mid_p);
	return 0;
}


Measured memory_bytes: 3716
#include <iostream>

using namespace std;

int main(void) {
	int num, i = 0, a, b;
	long long asum = 0, bsum = 0, anx, bnx;
	cin >> num;
	for (; i < num; i++) {
		scanf("%d%d", &a, &b);
		anx = a;
		bnx = b;
		if (asum > anx) {
			anx = (asum / a)*a;
			if (asum > anx)
				anx += a;
			bnx = (anx / a)*b;
		}
		if (bsum > bnx) {
			bnx = (bsum / b)*b;
			if (bsum > bnx)
				bnx += b;
			anx = (bnx / b)*a;
		}
		asum = anx;
		bsum = bnx;
	}
	cout << asum + bsum << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,e;
    //int f=0;
    string st,tt,nt;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    //a=0;
    cin>>a;
    b=a;
    while(a){
    d = a % 10;
    c = c + d;
    a = a / 10;
  }
  if(b%c==0)printa("Yes");
  else printa("No");
    return 0;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

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

    vector<string> r = {"AC", "WA", "TLE", "RE"};

    map<string, int> ans;
    for (auto x : r) {
        ans[x] = 0;
    }

    rep(i, N) {
        string S ;
        cin >> S;

        ans[S]++;
    }

    for(auto x:r){
        cout << x << " x " << ans[x] << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
using namespace std;
template<class T>inline void read(T &res)
{
    char c;
    T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
    res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';
    res*=flag;
}
int main()
{
    ll a,b,v,w,t;
    read(a);
    read(v);
    read(b);
    read(w);
    read(t);
    if(a>b)
        swap(a,b);
    if(a+v*t>=b+w*t)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
    char name[1000];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){return a < b ? a : b;}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    for(i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while(head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

//-----------------------------------------------------------------------------

int n;
ll h,w;
map<P,ll> mp;
ll cnt[10];

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

	cin>>h>>w>>n;
	REP(i,n) {
		ll a,b; cin>>a>>b; a--,b--;
		FOR(j,-2,1) {
			FOR(k,-2,1) {
				int nx=b+j,ny=a+k;
				if(nx<0||nx>=w-2||ny<0||ny>=h-2) continue;
				mp[P(nx,ny)]++;
			}
		}
	}
	ll sum=0;
	for(auto x:mp) {
		cnt[x.se]++;
		sum++;
	}
	cnt[0]=(h-2)*(w-2)-sum;

	REP(i,10) cout<<cnt[i]<<endl;


	return 0;
}


Measured memory_bytes: 56576
# D - Banned K
N = int(input())
A = list(map(int,input().split()))
lis = [0]*(N+1)
for x in A:
    lis[x] += 1
ans = 0
for x in lis:
    ans += x*(x-1)//2
for k in range(N):
    print(ans-lis[A[k]]+1)

Measured memory_bytes: 32304
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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; }

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

    int h, w;
    cin>>h>>w;
    vector<string> grid(h);
    rep(i, h) cin>>grid[i];

    vector<vector<int>> dp(h, vector<int>(w));  // count(h, w)
    rep(i, h) {
        int j = 0;
        int cnt = 0;
        while (j < w) {
            if (j + cnt == w || grid[i][j + cnt] == '#') {
                rep(k, cnt) dp[i][j + k] += cnt;
                j += cnt + 1;
                cnt = 0;
                continue;
            }
            cnt++;
        }
    }
    rep(j, w) {
        int i = 0;
        int cnt = 0;
        while (i < h) {
            if (i + cnt == h || grid[i + cnt][j] == '#') {
                rep(k, cnt) dp[i + k][j] += cnt;
                i += cnt + 1;
                cnt = 0;
                continue;
            }
            cnt++;
        }
    }
    int m = 0;
    rep(i, h) {
        rep(j, w) {
            chmax(m, dp[i][j] - 1);
        }
    }
    cout<<m<<endl;
}

Measured memory_bytes: 20224
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int i = 0; i < 7; i++)
	{
		int a = 0,b = 0;

		cin >> a >> b;

		cout << a - b << endl;
	}
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        ArrayList<Character> ss = new ArrayList<>();
        ss.add(s[0]);
        for (int i = 1; i < s.length; i++) {
            if(s[i - 1] != s[i]) {
                ss.add(s[i]);
            }
        }
        System.out.println(ss.size() - 1);
    }
}

Measured memory_bytes: 40684
#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>

using namespace std;


int main(){

    long long a, b, c;

    cin >> a >> b >> c;
    if((a < c && c < b) || (b < c && c < a)){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}


Measured memory_bytes: 256
from collections import deque
a = deque([])
for i in range(int(input())):
    c = input().split()
    if c[0] == "insert":
        a.appendleft(c[1])
    elif c[0] == "delete":
        try:
            a.remove(c[1])
        except ValueError:
            pass
    elif c[0] == "deleteFirst":
        a.popleft()
    else:
        a.pop()
for i,e in enumerate(a):
    if i == len(a) - 1:
        print(e)
    else:
        print(e, end=" ")



Measured memory_bytes: 69740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  int X;
  cin >> X;
  
  if (X >= 400 && X < 600) {
    cout << 8 << endl;
  } else if (X >= 600 && X < 800) {
    cout << 7 << endl;
  } else if (X >= 800 && X < 1000) {
    cout << 6 << endl;
  } else if (X >= 1000 && X < 1200) {
    cout << 5 << endl;
  } else if (X >= 1200 && X < 1400) {
    cout << 4 << endl;
  } else if (X >= 1400 && X < 1600) {
    cout << 3 << endl;
  } else if (X >= 1600 && X < 1800) {
    cout << 2 << endl;
  } else if (X >= 1800 && X < 2000) {
    cout << 1 << endl;
  }
}


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

int main(void)
{
	int n;
	int a[100][100];
	int S[100][100];
	int S2[101][101]; //S[100][100]???????????????S2[i][j]=S[i-1][j-1](i*j!=0),S2[i][j]=0(i*j==0)
	int T[100][100]; //T[i][j]???a[i][0]??????a[i][j]?????§??????
	cin>>n;
 
	//??\???
	for(int i=0;i<n;++i){
		int tmp=0;
		for(int j=0;j<n;++j){
			cin>>a[i][j];
			tmp+=a[i][j];
			T[i][j]=tmp;
		}
	}

	/*
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cout<<T[i][j]<<" ";
		}
		cout<<endl;
	}*/

	//S[i][j]????¨????
	for(int j=0;j<n;++j){
		int tmp=0;
		for(int i=0;i<n;++i){
			tmp+=T[i][j];
			S[i][j]=tmp;
		}
	}

	/* checked
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cout<<S[i][j]<<" ";
		}
		cout<<endl;
	}*/

	//S[i][j]??????S2[i][j]?????????
	for(int i=0;i<n+1;++i){
		for(int j=0;j<n+1;++j){
			if(i==0||j==0){
				S2[i][j]=0;
			} else {
				S2[i][j]=S[i-1][j-1];
			}
		}
	}

	/* checked
	for(int i=0;i<n+1;++i){
		for(int j=0;j<n+1;++j){
			cout<<S2[i][j]<<" ";
		}
		cout<<endl;
	}*/

	long max=S2[1][1];

	for(int i=1;i<n+1;++i){
		for(int j=1;j<n+1;++j){
			for(int k=0;k<i;++k){
				for(int l=0;l<j;++l){
					long square=S2[i][j]-S2[i][l]-S2[k][j]+S2[k][l]; //??????????????????????????¢?????¢???
					if(square>max) max=square;
				}
			}
		}
	}

	cout<<max<<endl;

	return 0;
}

Measured memory_bytes: 3232
#include<stdio.h>
 
int main(){
  int i, j, n, q, c=0;
  int S[10001], T[501];
   
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=1; i<=q; i++){
    scanf("%d",&T[i]);
  }
  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      if(i != j && S[i] == S[j]) S[j]=0;
    }
  }
 
  for(i=1; i<=n; i++){
    if(i>1 && S[i]==0)continue;
    for(j=1; j<=q; j++){
      if(S[i] == T[j]) c++;
    }
  }
  printf("%d\n",c);
  return 0;
}

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

t = []
if s[0] == '0':
    t.append(0)

c0 = 0
c1 = 0
for ss in s:
    if ss == '0':
        if c1 > 0:
            t.append(c1)
            c1 = 0
        c0 += 1
    else:
        if c0 > 0:
            t.append(c0)
            c0 = 0
        c1 += 1

if c1 > 0:
    t.append(c1)
if c0 > 0:
    t.append(c0)

if s[-1] == '0':
    t.append(0)

c_t = [0]
for tt in t:
    c_t.append(c_t[-1] + tt)

k2 = min(k, len(t) // 2)
ans = 0
for i in range(1, len(c_t), 2):
    j = i - k2 * 2 - 1
    if j < 0:
        continue
    ans = max(ans, c_t[i] - c_t[j])

# print(c_t)
print(ans)


Measured memory_bytes: 7932
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N;
ll T[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i, N) cin >> T[i];

  if (N == 1) {
    cout << T[0] << endl;
    return 0;
  }

  ll t = lcm(T[0], T[1]);
  for (int i = 2; i < N; i++) {
    t = lcm(t, T[i]);
  }
  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    int x,y;
    cin>>x>>y;
    if(y%2==1||y/2-x<0||2*x-y/2<0){
        cout<<"No";
        }else{
        cout<<"Yes";
    }

    return 0;
}


Measured memory_bytes: 3620
import java.util.*;
public class Main{
  public static void main(String args[])
  {
    Scanner in = new Scanner(System.in); 
    String s = in.nextLine();
    if(s.substring(s.length() - 1, s.length()).equals("3"))
    {
      System.out.println("bon");
    }
    else if(s.substring(s.length() - 1, s.length()).equals("0") || s.substring(s.length() - 1, s.length()).equals("1") || s.substring(s.length() - 1, s.length()).equals("6") || s.substring(s.length() - 1, s.length()).equals("8"))
    {
      System.out.println("pon");
    }
    else
    {
      System.out.println("hon");
    }
  }
}

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

int X;

signed main()
{
	X=read();
	for ( int i=-500;i<=500;i++ ) 
		for ( int j=-500;j<=500;j++ ) 
		{
			int A=i*i*i*i*i;
			int B=j*j*j*j*j;
			if(A-B==X) 
				return printf("%lld %lld\n",i,j),0;
		}
	return 0;
}
			 

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

using namespace std;

const int M = 500005;
const int mod = 998244353;

int A[M], B[4 * M], C[4 * M], S[4 * M], len[4 * M];
int n, q;

void push_up(int p) {
    S[p] = (S[p << 1] + S[p << 1 | 1]) % mod;
}

void push_down(int p) {
    if (B[p] != 1) {
        B[p << 1] = (long long) B[p << 1] * B[p] % mod;
        C[p << 1] = (long long) C[p << 1] * B[p] % mod;
        S[p << 1] = (long long) S[p << 1] * B[p] % mod;
        B[p << 1 | 1] = (long long) B[p << 1 | 1] * B[p] % mod;
        C[p << 1 | 1] = (long long) C[p << 1 | 1] * B[p] % mod;
        S[p << 1 | 1] = (long long) S[p << 1 | 1] * B[p] % mod;
        B[p] = 1;
    }
    if (C[p] != 0) {
        C[p << 1] = (C[p << 1] + C[p]) % mod;
        S[p << 1] = (S[p << 1] + (long long) C[p] * len[p << 1]) % mod;
        C[p << 1 | 1] = (C[p << 1 | 1] + C[p]) % mod;
        S[p << 1 | 1] = (S[p << 1 | 1] + (long long) C[p] * len[p << 1 | 1]) % mod;
        C[p] = 0;
    }
}

void build(int p, int l, int r) {
    len[p] = r - l + 1;
    B[p] = 1;
    if (l == r) {
        S[p] = A[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);
    push_up(p);
}

void modify(int p, int l, int r, int a, int b, int x, int y) {
    if (l == a && r == b) {
        B[p] = (long long) B[p] * x % mod;
        C[p] = ((long long) C[p] * x + y) % mod;
        S[p] = ((long long) S[p] * x + (long long) y * len[p]) % mod;
        return;
    }
    push_down(p);
    int mid = (l + r) >> 1;
    if (mid < a)
        modify(p << 1 | 1, mid + 1, r, a, b, x, y);
    else if (b <= mid)
        modify(p << 1, l, mid, a, b, x, y);
    else {
        modify(p << 1, l, mid, a, mid, x, y) ;
        modify(p << 1 | 1, mid + 1, r, mid + 1, b, x, y);
    }
    push_up(p);
}

int query(int p, int l, int r, int a, int b) {
    if (l == a && r == b)
        return S[p];
    push_down(p);
    int mid = (l + r) >> 1;
    if (mid < a)
        return query(p << 1 | 1, mid + 1, r, a, b);
    if (b <= mid)
        return query(p << 1, l, mid, a, b);
    return (query(p << 1, l, mid, a, mid) + query(p << 1 | 1, mid + 1, r, mid + 1, b)) % mod;
}

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; ++i)
        scanf("%d", &A[i]);
    build(1, 0, n - 1);
    while (q-- != 0) {
        int op, l, r, b, c;
        scanf("%d", &op);
        if (op == 0) {
            scanf("%d%d%d%d", &l, &r, &b, &c);
            modify(1, 0, n - 1, l, r - 1, b, c);
        }
        if (op == 1) {
            scanf("%d%d", &l, &r);
            printf("%d\n", query(1, 0, n - 1, l, r - 1));
        }
    }
    return 0;
}

Measured memory_bytes: 22068
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
#ifndef ONLINE_JUDGE
    scanf("%lld", &a);
#else
    scanf("%I64d", &a);
#endif
    return a;
}

char s[100004];
int c[100004]; int cn = 0;

int main() {
    scanf("%s", s);
    int n = strlen(s);

    if (s[0] == '0' || s[n-1] == '1') {
        printf("-1\n");
        return 0;
    }

    for (int i = 0; i < n-1; i++) {
        if (s[i] != s[n-2-i]) {
            printf("-1\n");
            return 0;
        }
        if (s[i] == '1')
            c[cn++] = i+1;
    }

    for (int i = cn-1; i > 0; i--)
        c[i] -= c[i-1];

    for (int i = 0; i < cn; i++)
        printf("%d %d\n", i+1, i+2);

    int p = cn+2;
    for (int i = 1; i < cn; i++)
        for (int j = 1; j < c[i]; j++)
            printf("%d %d\n", i+1, p++);

    return 0;
}


Measured memory_bytes: 1920
// 　　＿＿
// 　／　<＠ﾌ
//  ｜(ﾉﾉハ))
//  ﾉ从ﾟヮﾟ从
// 　ﾉ｜ｿﾉГ|つ author:hotarunx
// 〈_ﾉ^^^ヽ|
// 　~~tｧtｧ~
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long
constexpr int INF = 1000000000 + 8;
constexpr array<int, 4> DY = {0, 1, 0, -1}, DX = {1, 0, -1, 0};

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

    int h, w;
    cin >> h >> w;
    int ch, cw;
    cin >> ch >> cw;
    ch--, cw--;
    int dh, dw;
    cin >> dh >> dw;
    dh--, dw--;

    vector<string> grid(h);
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }

    vector<vector<int>> cost(h, vector<int>(w, INF));
    cost[ch][cw] = 0;

    deque<pair<int, int>> q;
    q.push_back({ch, cw});

    while (!q.empty()) {
        const int y = q.front().first;
        const int x = q.front().second;
        q.pop_front();

        for (int dy = -2; dy <= 2; dy++) {
            for (int dx = -2; dx <= 2; dx++) {
                const int ny = y + dy, nx = x + dx;
                int ncost = cost[y][x];
                if (abs(dy) + abs(dx) > 1) ncost++;

                if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                if (grid[ny][nx] == '#') continue;
                if (ncost >= cost[ny][nx]) continue;

                if (abs(dy) + abs(dx) > 1) q.push_back({ny, nx});
                else q.push_front({ny, nx});
                cost[ny][nx] = ncost;
            }
        }
    }

    const int ans = (cost[dh][dw] != INF ? cost[dh][dw] : -1);
    cout << ans << endl;
}


Measured memory_bytes: 12656
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    a_s = list(map(int, input().split()))

    # sums = [i+1 - a_s[i] for i in range(len(a_s))]
    #
    # # ans = [sums[sums[i]-1:-1].count(sums[i]) for i in range(len(a_s))]
    #
    # ans = 0
    # for i in range(len(a_s)):
    #     ans += sums[a_s[i]-i-1:-1].count(a_s[i]+i+1)
    #
    # # print(sum(ans))
    # print(ans)

    # 「番号+身長」「番号-身長」の計算結果をまとめたリストを作成(dict型のイメージ。結果が1になるデータが2個ある,2になるデータが4個ある・・等)
    # a_plus_list = [0 for i in range(len(a_s)+1)]
    # a_minus_list = [0 for i in range(len(a_s)+1)]
    # for i in range(len(a_s)+1):
    #     a_plus_list[i+1 + a_s[i]] += 1
    #     # a_minus_list[i+1 - a_s[i]] += 1

    a_plus_dict = {}
    a_minus_dict = {}
    for i in range(len(a_s)):
        plus = a_plus_dict.get(i+1 + a_s[i], 0)
        a_plus_dict[i+1 + a_s[i]] = plus + 1

        if i+1 <= a_s[i]:
            continue

        minus = a_minus_dict.get(i+1 - a_s[i], 0)
        a_minus_dict[i+1 - a_s[i]] = minus + 1

    ans = 0
    for key, val in a_plus_dict.items():

        target = a_minus_dict.get(key, 0)
        ans += target * val

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
2 3 3 1 3 1"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6
5 2 4 2 8 8"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5"""
        output = """22"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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


int main() {
    std::string pass;
    std::cin >> pass;
    for (int i = 0; i < 3; i++) {
        if (pass[i] == pass[i + 1]) {
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }
    std::cout << "Good" << std::endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int A(int sum);
int B(int sum);

int main(void)
{
	int sum1, sum2;
	
	sum1 = A(0);
	sum2 = B(0);
	
	if (sum1 >= sum2){
		printf("%d\n", sum1);
	}
	else {
		printf("%d\n", sum2);
	}
	
	return (0);
}

int A(int sum)
{
	int jo, su, ri, ei;
	
	scanf("%d %d %d %d", &jo, &su, &ri, &ei);
	
	sum = jo + su + ri + ei;
	
	return (sum);
}

int B(int sum)
{
	int jo, su, ri, ei;
	
	scanf("%d %d %d %d", &jo, &su, &ri, &ei);
	
	sum = jo + su + ri + ei;
	
	return (sum);
}

Measured memory_bytes: 592
#include<stdio.h>
int N[50][50];

void visit(int i,int j,int w,int h){
  N[i][j]=0;

  if(N[i][j+1]==1 && j+1<w) visit(i,j+1,w,h);
  if(N[i+1][j+1]==1 && i+1<h  && j+1<w) visit(i+1,j+1,w,h);
  if(N[i+1][j]==1 && i+1<h) visit(i+1,j,w,h);
  if(N[i+1][j-1]==1 && i+1<h  && 0<=j-1 ) visit(i+1,j-1,w,h);
  if(N[i][j-1]==1 && 0<=j-1) visit(i,j-1,w,h);
  if(N[i-1][j-1]==1 && 0<=i-1  && 0<=j-1) visit(i-1,j-1,w,h);
  if(N[i-1][j]==1 && 0<=i-1) visit(i-1,j,w,h);
  if(N[i-1][j+1]==1 && 0<=i-1 && j+1<w) visit(i-1,j+1,w,h);
  
  
}

int main(){
  int count,w,h,i,j;


  while(1){
    
    count=0;
    
    scanf("%d%d",&w,&h);
    
    if(w==0 && h==0)break;
    
    for(i=0;i<h;i++)
      {
	for(j=0;j<w;j++)
	  {
	    scanf("%d",&N[i][j]);
	  }
      }
    
    /*ツ暗按湘」ツづ債地ツ図ツづ可海ツづ「ツ督づ個値ツづーツ妥」ツ禿シツつオツづつ「ツつュ*/

    for(i=0;i<h;i++)
      {
	for(j=0;j<w;j++)
	  {
	    
	  
	    
	    if(N[i][j]==1)
	      {
		
		visit(i,j,w,h);
		count++;
	      }
	  }
      }
    
   
  
 
printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        int D = cin.nextint;
        int X = cin.nextint;
        for (int i = 0; i < N; i++)
        {
            int d = cin.nextint;
            for (int j = 1; j <= D; j += d)
            {
                X++;
            }
        }
        WriteLine(X);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int n,k,a,ak,h;
int main(){
    cin>>n>>k>>a;
    h=a;
    for(int i=2;i<=n;i++){
        cin>>ak;
        a=__gcd(a,ak);       
        h=max(ak,h);
    }
    if(k%a==0&&k<=h)        
        cout<<"POSSIBLE"<<endl;
    else
        cout<<"IMPOSSIBLE"<<endl;
}

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

int main(){
  int A, B, C; cin >> A >> B >> C;
  if((A-B) > C){
    cout << 0;
  }
  else{
    cout << C-(A-B);
  }
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

#define pint pair<int,int>

bool cmp(pint x, pint y){
  return x.first>y.first;
}

signed main(void){
  int n,m;cin >> n >> m;
  vint a(n);vin(a);
  vector<pair<int,int>> p(m);
  vsort(a);
  rep(i,m)cin >> p[i].second >> p[i].first;
  sort(all(p),cmp);
  
  int t=0;
  rep(i,m){
    int b=p[i].second, c=p[i].first;
    while(a[t]<c && b>0){
      a[t++]=c;
      b--;
    }
  }

  cout << accumulate(all(a),0LL) << endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    rep(i, 0, N) cin >> a[i];
    rep(i, 0, N) cin >> b[i];
    int res = 0;
    rrep(digit, 29, 0)
    {
        int bekihigh = 1 << (digit + 1), bekilow = 1 << digit;
        rep(i, 0, N) a[i] %= bekihigh, b[i] %= bekihigh;
        sort(b.begin(), b.end());
        ll num = 0;
        rep(i, 0, N)
        {
            int add = 0;
            if (bekilow - a[i] >= 0)
            {
                add += lower_bound(b.begin(), b.end(), bekihigh - a[i])
                - lower_bound(b.begin(), b.end(), bekilow - a[i]);
            }
            else
            {
                add += lower_bound(b.begin(), b.end(), bekihigh - a[i]) - b.begin();
                add += lower_bound(b.begin(), b.end(), bekihigh)
                - lower_bound(b.begin(), b.end(), bekihigh + bekilow - a[i]);
            }
            num += add;
        }
        if (num & 1) res += bekilow;
    }
    cout << res << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define rep(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

ll h,w,k,dp[109][10],fib[100];

ll fibo(ll x){
    if(x<=2)return 1;
    if(fib[x])return fib[x];
    return fib[x]=fibo(x-2)+fibo(x-1);
}

int main(){
    cin>>h>>w>>k;
    dp[0][1]=1;
    rep(i,h){
        FOR(j,1,w+1){
            (dp[i+1][j-1]+=dp[i][j]*fibo(j-1)*fibo(w-j+1))%=mod;
            (dp[i+1][j]+=dp[i][j]*fibo(j)*fibo(w-j+1))%=mod;
            (dp[i+1][j+1]+=dp[i][j]*fibo(j)*fibo(w-j))%=mod;
        }
    }
    cout<<dp[h][k]<<endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
two=0
four=0
for a in A:
    if a%2==0 and a%4!=0:
        two+=1
    elif a%4==0:
        four+=1
if (len(A)-two+1)//2<=four and two!=0:
    print("Yes")
elif len(A)//2<=four and two==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <map>
#include <string>
using namespace std;
map<string,int>mp;
int n,ans;
string s;
int main(void)
{
    cin>>n;
    while(n--)
    {
        cin>>s;
        if(!mp[s])
        {
            ans++;
            mp[s]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

constexpr int N = 100, P = 1000000007;

int n, k;
int dp[N + 1][N * N + 1];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    std::cin >> n >> k;
    
    dp[n][0] = 1;
    for (int i = n; i > 0; --i) {
        for (int j = 0; j <= n * n; ++j) {
            for (int v = 0; v <= k; ++v) {
                if (dp[i][j] == 0)
                    continue;
                int t = v <= i ? (v + j) / i : 0;
                dp[i - 1][j + t] = (dp[i - 1][j + t] + dp[i][j]) % P;
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= n * n; ++i)
        ans = (ans + 1ll * i * dp[0][i]) % P;
    int tot = 1ll * k * n * (P + 1) / 2 % P;
    for (int i = 0; i < n; ++i)
        tot = 1ll * tot * (k + 1) % P;
    ans = (tot - ans + P) % P;
    std::cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 4108
#include "bits/stdc++.h"
using namespace std;

// #define int long long

signed main(void)
{
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  int M;

  cin >> N;
  cout << "Christmas";
  for (int i = 0; i < 25 - N; i++)
    cout << " Eve";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
num_list = [ int(v) for v in input().split() ]

sign = len([ v for v in num_list if v < 0 ])
mini = min([ abs(v) for v in num_list ])
total = sum([ abs(v) for v in num_list ])

if sign % 2 == 0:
    ans = total
else:
    ans = total - (2*mini)
print(ans)

Measured memory_bytes: 66920
ans = []
for i in range(int(input())):
    a, b, c = map(int, input().split())
    lst = [a, b, c]
    lst.sort()
    if lst[2]**2 == lst[0]**2 + lst[1]**2:
        ans.append("YES")
    else:
        ans.append("NO")
for i in ans:
    print(i)

Measured memory_bytes: 7664
n = int(input())
P = list(map(int, input().split()))

count = 0
for i in range(n - 1):
    if P[i] == i + 1:
        P[i], P[i + 1] = P[i + 1], P[i]
        count += 1
if P[-1] == n:
    count += 1

print(count)

Measured memory_bytes: 14008
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    int k;
    cin >> k >> s;
    if(s.length() <= k)cout << s << endl;
    else{
        cout << s.substr(0,k) << "..." << endl;
    }
    return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


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

    REP(i,1,N+1)
    {
        if( i * i > N )
        {
            cout << (i-1)*(i-1) << endl;
            return 0;
        }
    }
    cout << N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int n;
    ll k;
    cin >> n >> k;
    int a[n];
    rep(i, n){
        cin >> a[i];
        a[i]--;
    }

    int l[n];
    rep(i, n) l[i] = INF;

    int j = 0;
    ll cnt = 0;
    l[0] =  0;
    while(true){
        j = a[j];
        cnt++;
        if(l[j]!=INF){
            int u = cnt - l[j];
            rep(ui, (k-cnt)%u){
                j = a[j];
            }
            cout << ++j << endl;
            return 0;
        }

        l[j] = cnt;
        if(cnt==k){
            cout << ++j << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 5156
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

int solve()
{
	ll n ;
	cin >> n ;
	rep(i,1,10)
	{
		if(n%i==0)
		{
			ll a = i , b = n/i ;
				if(a < 10 && b < 10) return cout << "Yes",0;
		}
	}
	cout << "No";


}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}

	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 256
N = int(input())
S = input()

ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  a = S[i]
  for j in range(i+2,N,2):
    b = S[j]
    k = (i+j)//2
    if sorted([a,S[k],b]) == ['B','G','R']:
      ans -= 1
      
print(ans)

Measured memory_bytes: 9168
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll R;
    cin >> R;
    if(R < 1200)cout << "ABC" << endl;
    else if(R < 2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int A[15][15];
main()
{
	int N;
	while(scanf("%d",&N),N)
	{
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)A[i][j]=0;
		int x=N/2+1,y=N/2;
		for(int i=1;i<=N*N;i++)
		{
			while(A[x][y]!=0)
			{
				x=(x+1)%N,y=(y-1+N)%N;
			}
			A[x][y]=i;
			x=(x+1)%N,y=(y+1)%N;
		}
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<N;j++)printf("%4d",A[i][j]);
			puts("");
		}
	}
}



Measured memory_bytes: 2564
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // before C++14
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
#pragma endregion library

int main(){
    int n; cin >> n;
    ll ans = 1;
    rep(i,n){
        ll t; cin >> t;
        ans = lcm(t,ans);
    }
    cout << ans << '\n';
    
}

Measured memory_bytes: 256
#include<iostream>

int count;
int a,b,c;

void sort(void){
    if(a>b)std::swap(a,b);
    if(a>c)std::swap(a,c);
    if(b>c)std::swap(b,c);
}

int solve(void){
    sort();
    if(a==c){
        return count;
    }
    if(a==b){
        count += c-a;
        return count;
    }
    if(b==c){
        for(int i=0; i < (c+1-a)/2; i++){
            a += 2;
            count++;
        }
        return solve();
    }
    count += (b+1-a)/2;
    a += 2*((b+1-a)/2);
    return solve();
}


int main(void){
    std::cin >> a >> b >> c;
    std::cout << solve() << std::endl;
    return 0;
}

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

int n;
string alpha="abcdefghijklmn";

void dfs(string s,int a){
  if(s.size()==n){
    cout<<s<<endl;
    return;
  }
  else if(s==""){
    string p="a";
    dfs(p,1);
  }
  else{
    string p;
    for(int i=0;i<=a;i++){
      p=s+alpha[i];
      dfs(p,max(a,i+1));
      p=s;
    }
  }
}

int main(){
  cin>>n;
  dfs("",0);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define lli int
int const maxlen = 2e5 +7;
vector<int> adjlist[maxlen];
bool visited[maxlen];
int req = 0;
void dfs(int u){
  visited[u] =1 ;
  req++;
  for(int v: adjlist[u]){
    if(visited[v])
      continue;
    dfs(v);
  }
}
void solve(){

  int N;
  cin>>N;
  int M;
  cin>>M;
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    adjlist[a].push_back(b);
    adjlist[b].push_back(a);
  }

  int cnt = 0;
  for(int i=1;i<=N;i++){
    if(visited[i])
      continue;
    dfs(i);
    cnt = max(cnt, req);
    req = 0;
  }
  cout<<cnt<<endl;
}
signed main(){
  // int t;
  // cin>>t;
  // while(t--)
  solve();
}


Measured memory_bytes: 20976