akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int q,w=1000000000;
  for(int i=-100;i<101;i++){
    q=0;
    for(int j=0;j<n;j++){
      q+=(a[j]-i)*(a[j]-i);
    }
    w=min(w,q);
  }
  cout << w;
}


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

int main(){
	int N,Y;
	cin>>N>>Y;
	int truth=0;
	for(int x=0;x<=N;++x){
		if(truth==1) break;
		for(int y=0;y<=N;++y){
			if(truth==1) break;
			int z=N-x-y;
			if((1000*x+5000*y+10000*z==Y) && (z>=0)){
				cout<<z<<" "<<y<<" "<<x<<endl;
				truth=1;
				break;
			}
		}
	}
	if(truth==0) cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！

int main() {
    vector<int> vec(3);
    rep(i, 3) cin >> vec.at(i);
    sort(vec.begin(), vec.end());
    if (vec.at(0) == 5 and vec.at(1) == 5) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

ts=[]

for i in range(n):
  x,l=map(int,input().split())
  ts.append((x+l,x-l))
  
ts.sort()

#print(ts)
ans=0
old=-10**10
for i,j in ts:
  
  if j>=old:
    old=i
  else:
    ans+=1

print(n-ans)

Measured memory_bytes: 16984
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
#include<cmath>
#define ll long long
#define pb(c, n) c.push_back(n);
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s, t, w;
    cin>>s>>t;
    for(int i = 0; i < n; i++)
    {
        w+=s[i];
        w+=t[i];
    }
    cout<<w;
}


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

#define gif(a,b) ((a)/(b)+((a)%(b)?1:0))
#define float long double
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define w(x) cout<<(#x)<<" is "<<(x)<<"\n";
using namespace std;

int32_t main()
{ 
    IOS
    int T; 
    T=1; 
    for (int t = 0; t < T; ++t)
    {
        int x, y;
       cin >> x >> y;
       int a, b;
       b = y - 2*x; 
       a = 4*x - y;
       //cout << a << " l"<< b;
        if((b%2 ==0  && b/2 >= 0 && a%2 == 0 && a/2 >= 0))
        	{
        		cout << "Yes"<< endl;
        	
        	}
        else
        	cout << "No";
    }

    return 0;
}


Measured memory_bytes: 3636
def resolve():
    '''
    code here
    '''
    N = int(input())
    As = [int(item) for item in input().split()]

    res = 0
    if N >= 2:
        prev = As[0]
        for item in As[1:]:
            if item < prev:
                res += prev - item
            else:
                prev = item

    else:
        res = 0

    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 32184
#include <iostream>

int main()
{
    int64_t x, y;
    std::cin >> x >> y;
    if (x + y <= 1)
    {
        std::cout << "Brown";
    }
    else if (abs(x - y) > 1)
    {
        std::cout << "Alice";
    }
    else
    {
        std::cout << "Brown";
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) scanf("%lld", &A[i]);
	
	ll ans = 0;
	REP(i, 60) {
		ll cnt[2] {};
		REP(j, N) ++cnt[A[j] >> i & 1];
		ans += (1ll<<i) % MOD * cnt[0] % MOD * cnt[1] % MOD;
		ans %= MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct NODE{
  int parent,left,right;
};
struct NODE T[MAX];
int n,D[MAX];

int getDepth(int u){
  int d = 0;
  while(T[u].parent != NIL){
    u = T[u].parent;
    d++;
  }
  return d;
}

void printChildren(int u){
  int c;
  c = T[u].left;
  printf("[");
  while(c != NIL){
    printf("%d",c);
    c = T[c].right;
    if(c != NIL)printf(", ");
  }
  printf("]\n");
}

int main(){
  int i,j,d,v,c,l,r;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  
  for(i = 0 ; i < n ; i++){
    scanf("%d",&v);
    scanf("%d",&d);
    for(j = 0 ; j < d ; j++){
      scanf("%d",&c);
      if(j == 0)T[v].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = v;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    if(T[i].parent == NIL)r = i;
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].parent);
    printf("depth = %d, ",getDepth(i));
    if(T[i].parent == NIL)printf("root, ");
    else if(T[i].left == NIL)printf("leaf, ");
    else printf("internal node, ");
    printChildren(i);    
  }
  
  return 0;
}



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

int n,m;
vector<int> adj[15];
int nyala[15];

bool cek(int x){
	for(int i=1;i<=m;i++){
    	int tmp = 0;
        for(int j=0;j<adj[i].size();j++){
        	int cur = adj[i][j]-1;
            if((1<<cur) & x) tmp++;
        }
        if(nyala[i] != tmp%2) return 0;
    }
    return 1;
}

int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++){
    int x;
    scanf("%d",&x);
    for(int j=1;j<=x;j++){
      int y;
      scanf("%d",&y);
      adj[i].push_back(y);
    }
  }
  for(int i=1;i<=m;i++){
  	scanf("%d",&nyala[i]);
  }
  int ans = 0;
  for(int i=0;i<(1<<n);i++){
  	if(cek(i)) ans++;
  }
  printf("%d\n",ans);
  return 0;
}


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

int main() {
  int X, N, p, ans;
  cin >> X >> N;
  set<int> S;
  while (cin >> p) S.insert(p);
  for (int i = 0, mi = 101; i <= 101; i++) {
    if (S.count(i)) continue;
    int tmp = abs(X - i);
    if (tmp < mi) mi = tmp, ans = i;
  }
  cout << ans << "\n";
}

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

const long long INF = 1LL << 60;
int MOD = 1000000007;
double PI = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define For(i,s,n) for (int i=s;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define vs vector<string>
#define All(c) (c).begin(), (c).end()
#define Print(x) cout<<(x)<<"\n"


int main() {
	int X, Y; cin >> X >> Y;
	int ans = 0;

	if (X == 1) ans += 300000;
	else if (X == 2) ans += 200000;
	else if (X == 3) ans += 100000;

	if (Y == 1) ans += 300000;
	else if (Y == 2) ans += 200000;
	else if (Y == 3) ans += 100000;

	if (X * Y == 1) ans = 1000000;

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

typedef long long ll;

ll gcd(ll a,ll b){ // 高速ユークリッド互除法
    if(a<0) a = -1*a;
    if(b<0) b = -1*b;
    if(a==0) return b;
    if(b==0) return a;
    if(a==b) return a;
    ll c;
    if(a<b){
        c = b-(b/a)*a;
        if(c<a/2) return gcd(a,c);
        else return gcd(a,c-a);
    } else{
        c = a-(a/b)*b;
        if(c<b/2) return gcd(c,b);
        else return gcd(c-b,b);
    }
}

ll binary_method(ll a,ll b,ll m){
    // a^b mod m
    if(b==0) return 1;
    ll ans=1;
    ll ori_b = b;
    ll b_length = 0;
    while(b!=0){
        b = b/2;
        b_length++;
    }

    for(int i=b_length-1;i>-1;i--){
        if((ori_b>>i)&1) ans = (((ans * a) % m) * ans)%m;
        else ans = (ans * ans) % m;
        // cout<<ans<<endl;
    }
    return ans;
}

ll inv(ll a, ll m){
    // a^{-1} mod m, m : 素数
    // cout<<a<<" "<<binary_method(a, m-1, m)<<endl;
    return binary_method(a, m-2, m);
}

ll factorial(ll a, ll m){
    // a! mod m
    if(a<0){
        std::cout<<"factorial error. negative input"<<std::endl;
        return 0;
    }
    ll ans=1;
    for(int i=1;i<a+1;i++){
        ans = (ans * i) % m;
    }
    return ans;
}

ll comb(ll a,ll b,ll m){
    // aCb mod m 
    if(a<0 || b<0 || a<b){
        std::cout<<"combination error."<<std::endl;
    }

    ll A = factorial(a,m);
    ll B = inv(factorial(b,m),m);
    ll C = inv(factorial(a-b,m),m);
    return (((A * B) % m) * C) % m;
}

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<n+1;i++)
int main(){
    int r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;
    ll a,b,c,d;
    a = comb(r2+c2+2,c2+1,mod);
    b = comb(r2+c1+1,c1,mod);
    c = comb(r1+c2+1,r1,mod);
    d = comb(r1+c1,r1,mod);
    // cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    ll ans;
    ans = (a+(mod-b)+(mod-c)+d)%mod;
    cout<<ans<<endl;
    // binary_method(3,mod-1,mod);
    return 0;
}

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

using namespace std;

#define X   first
#define Y   second

const int   N   = 2e5 + 1;

typedef pair<int,int>   ii;

vector<int> g[N];
int n, m, s[N];
set<ii> S[2];
int c[N][2];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;

    for(int i = 1 ; i <= n ; ++i)   {
        char c; cin >> c;
        s[i] = c - 'A';
    }

    while(m--)  {
        int x, y;   cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
        c[x][s[y]]++;
        c[y][s[x]]++;
    }

    for(int i = 1 ; i <= n ; ++i)   {
        S[0].insert(ii(c[i][0],i));
        S[1].insert(ii(c[i][1],i));
    }

    while(1)    {
        if(S[0].empty())
            return 0 * puts("No");
        if ((*S[0].begin()).X && (*S[1].begin()).X)
            return 0 * puts("Yes");
        int u = (*S[0].begin()).Y;
        if(c[u][0])
            u = (*S[1].begin()).Y;
        S[0].erase(ii(c[u][0],u));
        S[1].erase(ii(c[u][1],u));
        for(int v : g[u])   {
            if(S[0].find(ii(c[v][0],v)) == S[0].end())
                continue;
            S[0].erase(ii(c[v][0],v));
            S[1].erase(ii(c[v][1],v));
            c[v][s[u]]--;
            S[0].insert(ii(c[v][0],v));
            S[1].insert(ii(c[v][1],v));
        }
    }
}


Measured memory_bytes: 30336
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

const ll INF=1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    rep(i,n){
        cin >> p[i];
    }
    ll ans=0;
    sort(p.begin(),p.end());
    rep(i,k){
        ans+=p[i];
    }
    cout << ans << endl;
} 


Measured memory_bytes: 3636
#include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)goto L;
using namespace std;main(){for(int n,v[50],s,p,c;cin>>n,n;){string t;for(s=0;s<n;)cin>>t,v[++s]=t.size();s=0;L:p=++s;f(5)f(7)f(5)f(7)f(7)cout<<s<<endl;}}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
 
int J[1001][1001]{},O[1001][1001]{}, I[1001][1001]{}; 
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int d=0;d<a;d++){
	char e[1000];
	scanf("%s",e);
	unordered_map<char,int>f;
	for(int g=0;g<b;g++){
	    f[e[g]]++;
	    J[d+1][g+1]=f['J'];
	    O[d+1][g+1]=f['O'];
	    I[d+1][g+1]=f['I'];
	    }
	}
	for(int h=2;h<=a;h++){
	    for(int i=1;i<=b;i++){
		J[h][i]+=J[h-1][i];
		O[h][i]+=O[h-1][i];
		I[h][i]+=I[h-1][i];
		}
	    }
	for(int i=0;i<c;i++){
	    int w,x,y,z;
	    scanf("%d%d%d%d",&w,&x,&y,&z);
	    w--;x--;
	    printf("%d %d %d\n",J[y][z]+J[w][x]-J[y][x]-J[w][z],O[y][z]+O[w][x]-O[y][x]-O[w][z],I[y][z]+I[w][x]-I[y][x]-I[w][z]);
	    }
    }

Measured memory_bytes: 14828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

class Program
{
    private static long Solve(long A, long B, long C)
    {
        long min = long.MaxValue;
        min = Math.Min(((A + 1) / 2) * B * C - (A / 2) * B * C, min);
        min = Math.Min(((B + 1) / 2) * C * A - (B / 2) * C * A, min);
        min = Math.Min(((C + 1) / 2) * A * B - (C / 2) * A * B, min);
        return min;
    }
    static void Main(string[] args)
    {
        int[] values = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        Console.WriteLine(Solve(values[0], values[1], values[2]));
    }
}


Measured memory_bytes: 2776
public class Main {

	public void run(java.io.InputStream in, java.io.PrintStream out) {
		final java.util.Scanner sc = new java.util.Scanner(in);
		final RankInADynamicSubset lis = new RankInADynamicSubset(sc.nextInt());
		final int q = sc.nextInt();
		
		for (int i = 0; i < q; ++i) {
			final int com = sc.nextInt();
			final int x = sc.nextInt();
			final int y = sc.nextInt();
			
			if (com == 0) {
				lis.add(x - 1, y);
			} else if (com == 1) {
				out.println(lis.currentRankOf(x - 1, y - 1));
			}
		}
		
		sc.close();
	}
	
	public static void main(String[] args) {
		(new Main()).run(System.in, System.out);
	}

	private static class RankInADynamicSubset {
		private int[] d;
		private int   n;
		
		public RankInADynamicSubset(int n) {
			this.n = 1;
			while (this.n < n) {
				this.n *= 2;
			}
			d = new int[this.n * 2];
			java.util.Arrays.fill(d, 0);
		}
		
		public void add(int i, int x) {
			i = n + i;
			d[i] += x;
			while (i != 1) {
				i /= 2;
				d[i] = d[i * 2] + d[i * 2 + 1];
			}
		}
		
		public int currentRankOf(int s, int t) {
			return currentRankOf(s, t, 0, n - 1, 1);
		}
		
		private int currentRankOf(int s, int t, int lb, int ub, int i) {
			final int m = (lb + ub) / 2;
			int res;
			
			if (s <= lb && ub <= t) {
				return (d[i]);
			}
			
			res = 0;
			if (s <= m) {
				res += currentRankOf(s, t, lb, m, i * 2);
			}
			if (m + 1 <= t) {
				res += currentRankOf(s, t, m + 1, ub, i * 2 + 1);
			}
			
			return (res);
		}
	}
	
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> ab(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ab.at(i) = make_pair(a, b);
  }
  vector<int> res(n, 0);
  rep(i, m) {
    int a = ab.at(i).first;
    int b = ab.at(i).second;
    res.at(a)++;
    res.at(b)++;
  }
  rep(i, n) {
    cout << res.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 3604
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	if (S[0] == '9' || S[1] == '9') cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto s = readln.chomp;
  
  auto d = s.length - 7;
  auto f = false;
  foreach (i; 0..s.length - d) {
    if (s[0..i] ~ s[i+d..$] == "keyence") {
      f = true;
      break;
    }
  }

  if (f) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
map<string,int> DP;
int move[4]={1,-1,4,-4};
void BFS()
{
	queue<string> que;
	que.push("01234567");
	DP["01234567"]=0;
	while(!que.empty())
	{
		string now=que.front();
		que.pop();
		int p=0;
		for(int i=0;i<8;i++)
		{
			if(now[i]=='0')
			{
				p=i;
				break;
			}
		}
		for(int i=0;i<4;i++) 
		{
			int n=p+move[i];
			if(n>=0 && n<8 && !(p==3&&i==0) && !(p==4&&i==1))
			{
				string next=now;
				swap(next[p],next[n]);
				if(DP.find(next)==DP.end())
				{
					DP[next]=DP[now]+1;
					que.push(next);
				}
			}
		}
		
	}
	
}
int main()
{
	BFS();
	string aa;
	while(getline(cin,aa))
	{
		aa.erase(remove(aa.begin(),aa.end(),' '),aa.end());
		cout<<DP[aa]<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 3436
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val list = readLine()!!.split(" ").map { it.toLong() }
    val desc = list.sortedDescending()
    var count = 0

    if (desc.size <= k) {
        println(count)
        return
    }
    val remaining  = desc.drop(k)
    println(remaining.sum())
}

Measured memory_bytes: 83480
import re
m = re.match(r'^keyence$|^(\D+)keyence$|^k(\D+)eyence$|^ke(\D+)yence$|^key(\D+)ence$|^keye(\D+)nce$|^keyen(\D+)ce$|^keyenc(\D)+e$|^keyence(\D+)$',input())
print('YES' if m else 'NO')

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

int main() {
    int64_t q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    int64_t ans = n / 2 * min(8 * q, min(4 * h, min(2 * s, d)));
    if (n & 1) ans += min(4 * q, min(2 * h, s));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import math
n,k=map(int,input().split())
l=list(map(int,input().split()))
count=0
num=1000000
mi=min(l[0:k])
if(mi<num):
    num=mi
for i in range(0,len(l),k-1):
    count+=1
    if(i<len(l)-1 and i+k-1>=len(l)):
        count+=1
        break
print(count-1)

Measured memory_bytes: 13812
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K;
  string S;
  cin >> N >> K >> S;
  vector<int64_t> A(N);
  vector<int64_t> counts;
  int64_t count = 0;
  int64_t pval = 1;
  for (int64_t i = 0; i < N; ++i) {
    const int64_t cval = static_cast<int64_t>(S[i] - '0');
    if (cval == pval) {
      ++count;
    } else {
      counts.emplace_back(count);
      // cerr << " " << count << endl;
      count = 1;
      pval = cval;
    }
  }
  if (count > 0) {
    counts.emplace_back(count);
  }
  if (S[N - 1] == '0') {
    counts.emplace_back(0);
  }
  vector<int64_t> count_sum(counts.size() + 1, 0);
  for (int64_t i = 0; i < static_cast<int64_t>(counts.size()); ++i) {
    count_sum[i + 1] = count_sum[i] + counts[i];
  }
  int64_t result = 0;
  for (int64_t i = 0; i < static_cast<int64_t>(counts.size()); i += 2) {
    const int64_t sum = count_sum[min(i + K * 2 + 1, static_cast<int64_t>(count_sum.size()) - 1)] - count_sum[i];
    result = max(result, sum);
    // cerr << " " << sum << endl;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 6040
#include <iostream>
#include <cstdint>

using namespace std;

int main(void)
{
	int_least32_t a, b;

	cin >> a >> b;

	int_least32_t plus, minus, multi;
	plus = a + b;
	minus = a - b;
	multi = a * b;

	if (plus > minus) {
		if(plus < multi) {
			cout << multi;
		}
		else {
			cout << plus;
		}
	}
	else {
		if(minus < multi) {
			cout << multi;
		}
		else {
			cout << minus;
		}
	}
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll n,l,ans=0;  cin>>n>>l;
    if(l>=0)    rep(i,2,n+1) ans+=(l+i-1); 
    else
    {
        ll x;
        if(1-l>n) x=n;
        else x=1-l;
        rep(i,1,n+1) if(i!=x) ans+=(l+i-1);
    }cout<<ans;
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	map<string,int> m;
	string str;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		m[str]++;
	}
	map<string,int>::iterator it;
	vector<pair<int,string>> v;
	int maxi=0;
	for(it=m.begin();it!=m.end();it++)
	{
	    maxi=max(maxi,it->second);
		v.push_back(make_pair(it->second,it->first));
	}
	sort(v.begin(),v.end());
	int l=v.size();
	for(int i=0-1;i<l;i++)
	{
	    if(v[i].first==maxi)
	    {
		    cout<<v[i].second<<"\n";
	    }
	    
	}
	return 0;
}

Measured memory_bytes: 29684
#include <bits/stdc++.h>
using namespace std;
 
 
long long int fn[200001];
int n;
 
 
void insert(int i,long long int v){
	for(int x=i;x<=n;x+=x&-x){
		fn[x]=max(fn[x],v);
	}
}
 
long long int query(int i){
	long long int ans=0;
	for(int x=i;x>0;x-=x&-x){
		ans=max(ans,fn[x]);
	}
	return ans;
}
 
int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); 
	cin >> n;
	long long int a[n],h[n],dp[n];
	for(int i=0;i<n;i++) cin >> h[i];
	for(int i=0;i<n;i++) cin >> a[i];
	long long int ans=0;
	for(int i=0;i<n;i++){
		long long int temp = query(h[i]-1);
		dp[i] = temp+a[i];
		insert(h[i],dp[i]);
		ans=max(ans,dp[i]);
	}
	cout << ans;
 
 
 
	

 
}

Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] params;
      Dice dice2 = new Dice(br.readLine().split(" "));
      int upper,front;
      int q = Integer.parseInt( br.readLine() );
      for ( ; q > 0; q--) {

        params = br.readLine().split(" ");

        upper = Integer.parseInt(params[0]);
        front = Integer.parseInt(params[1]);

        while(true){
          if( dice2.getFrontSide() == front){
            for (int i=0; i<3; i++)
              if(dice2.getUpperSide() == upper) break;
              dice2.rotate("W");
          }
          else {
            for(int i=0; i < 3; i++)
              if(dice2.getUpperSide() != front) dice2.rotate("N");
            for(int i=0; i < 3; i++)
              if(dice2.getUpperSide() != front) dice2.rotate("W");
            dice2.rotate("S");
          }
          if( (dice2.getUpperSide()==upper) && (dice2.getFrontSide()==front)) break;
        }
        System.out.println(dice2.getRightSide());
      }
    }
  }
}

class Dice {
  private int[] side;

  public Dice( int[] ia ) {
    side = Arrays.copyOf(ia, ia.length);
  }
  public Dice( String[] s ) {
    side = new int[s.length];
    for ( int i=0; i < 6; i++)
      side[i] = Integer.parseInt(s[i]);
  }

  public int getUpperSide() {
    return side[0];
  }
  public int getFrontSide() {
    return side[1];
  }
  public int getRightSide() {
    return side[2];
  }

  public int doRotate(String s) {
    for ( int i=0; i < s.length(); i++ ) {
      rotate(s.substring(i, i+1));
    }
    return side[0];
  }

  public void rotate(String o) {
    switch(o) {
      case "N" :
        rotateN();
        break;
      case "S" :
        rotateS();
        break;
      case "W" :
        rotateW();
        break;
      case "E":
        rotateE();
        break;
      default :
    }
  }

  private void rotateN() {
    int tmp = side[0];
    side[0] = side[1]; side[1] = side[5]; side[5] = side[4];
    side[4] = tmp;
  }
  private void rotateS() {
    int tmp = side[0];
    side[0] = side[4]; side[4] = side[5]; side[5] = side[1];
    side[1] = tmp;
  }
  private void rotateW() {
    int tmp = side[0];
    side[0] = side[2]; side[2] = side[5]; side[5] = side[3];
    side[3] = tmp;
  }
  private void rotateE() {
    int tmp = side[0];
    side[0] = side[3]; side[3] = side[5]; side[5] = side[2];
    side[2] = tmp;
  }
}


Measured memory_bytes: 24468
<?php
fscanf(STDIN, "%d", $a);
$input = trim(fgets(STDIN));
while($input){
    $array[] = $input;
    $input = trim(fgets(STDIN));
}

rsort($array);
$sum = 0;
foreach($array as $k => $v) {
  if($k == 0) {
    $sum += $v / 2;
  } else {
    $sum += $v;
  }
}  
echo $sum;

Measured memory_bytes: 4604
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
vector<int> e[100000];
ll m[100000][2];

void init()
{
}

ll rec(int v, int prev, int c)
{
    if((e[v].size() == 0)
       || (e[v].size() == 1 && prev != -1)){
        return 1;
    }
    if(prev != -1 && m[v][c] != -1) return m[v][c];
    ll ret = 1;
    for(auto next: e[v]){
        if(next == prev) continue;
        ll s = 0;
        s += rec(next, v, 0);
        s %= MOD;
        if(c == 0) s += rec(next, v, 1);
        s %= MOD;
        ret *= s;
        ret %= MOD;
    }
    m[v][c] = ret;
    return ret;
}

void solve()
{
    REP(i, N) REP(j, 2) m[i][j] = -1;
    cout << (rec(0, -1, 0) + rec(0, -1, 1)) % MOD << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i, N-1){
        int v1, v2;
        cin >> v1 >> v2;
        v1--; v2--;
        e[v1].pb(v2);
        e[v2].pb(v1);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 15616
//============================================================================
// Name        : f.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n;cin>>n;
	ll d,a;cin>>d>>a;
	vector<ll> x(n),h(n);
	vector<pair<ll,ll>> p(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>h[i];
		p[i].first=x[i];
		p[i].second=h[i];
	}
	sort(p.begin(),p.end());
	for(int i=0;i<n;i++){
		x[i]=p[i].first;
		h[i]=p[i].second;
	}
	queue<pair<ll,ll>> q;
	ll sum=0;
	ll ans=0;
	for(int i=0;i<n;i++){
		while(1){
			if(q.size()==0)break;
			if(x[i]-q.front().first<=(2*d))break;
			sum-=q.front().second*a;
			q.pop();
		}
//		cout<<i<<' '<<sum<<endl;
		ll b=0;
		if(h[i]-sum>0){
			b=(h[i]-sum-1)/a+1;
		}
		sum+=b*a;
		ans+=b;
		q.push(make_pair(x[i],b));
//		cout<<i<<' '<<b<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

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

int64_t pattern_x_from_n(int x, int n);
int64_t sum_from1_to_x(int x);

int main()
{
	int n,k;
	int64_t sum=0;

	cin >> n >> k;
	for (int i=k;i<=n+1;++i)
	{
		sum+=pattern_x_from_n(i,n);
		sum%=1000000007;
	}

	cout << sum << endl;
	return 0;

}

int64_t pattern_x_from_n(int x, int n)
{
	int64_t from, to;
	
	from=sum_from1_to_x(x-1);
	to=sum_from1_to_x(n)-sum_from1_to_x(n-x);
	//fprintf(stderr,"n: %d, x: %d -> from: %lld, to: %lld\n",n,x,from,to);

	return to-from+1;
}

int64_t sum_from1_to_x(int x)
{
	return ((int64_t)x*(x+1))/2;
}



Measured memory_bytes: 3608
#include<algorithm>
#include<bitset>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<unordered_map>
#include<utility>
#include<vector>

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;

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

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

class UnionFind{
    using Weight = long long;

    int n;
    std::vector<int> par;
    std::vector<Weight> weight;
    int siz;

public:
    UnionFind(int n_ = 0){
        init(n_);
    }

    void init(int n_ = 0){
        n = n_;
        par.assign(n, -1);
        weight.assign(n, 0);
        siz = n;
        return;
    }

    int find(int x){
        if(par[x] < 0){
            return x;
        }
        int root = find(par[x]);
        weight[x] += weight[par[x]];
        return par[x] = root;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    Weight get_weight(int x){
        find(x);
        return weight[x];
    }

    bool unite(int x, int y, Weight w = 0){
        w += get_weight(x) - get_weight(y);

        x = find(x);
        y = find(y);

        if(x == y){
            return false;
        }

        if(par[x] < par[y]){
            std::swap(x, y);
            w = -w;
        }

        par[x] += par[y];
        par[y] = x;
        weight[y] = w;
        --siz;

        return true;
    }

    Weight diff(int x, int y){
        return get_weight(y) - get_weight(x);
    }

    int size_of_set(int x){
        return -par[find(x)];
    }

    int count_set(void){
        return siz;
    }
};

int main(){
    int n, m;
    std::cin >> n >> m;

    std::vector<int> a(m), b(m);
    for(int i = 0 ; i < m ; ++i){
        std::cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }

    UnionFind uf(n);
    std::vector<long long> ans(m);
    ans[m - 1] = (long long)n * (n - 1) / 2;

    for(int i = m - 1 ; i > 0 ; --i){
        int sa = uf.size_of_set(a[i]);
        int sb = uf.size_of_set(b[i]);

        ans[i - 1] = ans[i];

        if(uf.unite(a[i], b[i])){
            ans[i - 1] -= (long long)sa * sb;
        }
    }

    for(int i = 0 ; i < m ; ++i){
        std::cout << ans[i] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 6776
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

//* calculate primes using sieve
ll sieve(ll n, vll &prime, vector<bool> &isprime){
    //* return the number of primes <= n
    //* prime[0]~ prime[p-1] record the primes
    //* isprime[0] ~ isprime[n] records the sieve
    ll p = 0;
    rep(i, n+1)
        isprime[i] = true;
    isprime[0] = isprime[1] = false;
    for(ll i=2; i <= n; i++){
        if(isprime[i]){
            prime[p++] = i; 
            for(ll j= 2*i; j <= n; j+= i)
                isprime[j] = false;
        }
    }
    return p;
}
void solve(long long N){
    vll prime(55555); vb isprime(55555+1, false);
    ll p = sieve(55555, prime, isprime);
    vll rec;
    REP(i, p){
        if(prime[i] % 5 == 1)
            rec.push_back(prime[i]);
    }
    REP(i, N){
        cout << rec[i] << " ";
    }
    cout << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  if (N > M) swap(N, M);
  if (M == 1)
    cout << 1 << '\n';
  else if (N == 1)
    cout << M - 2 << '\n';
  else
    cout << (N - 2) * (M - 2) << '\n';
  return 0;
}


Measured memory_bytes: 3620
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

pair <int, int> arr[maxx];

bool cmp(pair <int, int> x, pair <int, int> y) {
    if (x.S == y.S) return x.F < y.F;
    return x.S < y.S;
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> arr[i].F >> arr[i].S;
    }
    sort (arr + 1, arr + m + 1, cmp);
    int last = 0, res = 0;
    for (int i = 1; i <= m; i++) {
        if (arr[i].F < last) {
            continue;
        }
        last = arr[i].S;
        res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0077
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                string res = "";

                int i = 0;
                while (i < line.Length)
                {
                    if (line[i] == '@')
                    {
                        int n = int.Parse(line[i + 1].ToString());
                        char r = line[i + 2];
                        res += new string(r, n);
                        i += 3;
                    }
                    else
                    {
                        res += line[i];
                        i++;
                    }
                }

                Console.WriteLine(res);
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 15680
d = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

n=int(input())
for i in range(n):
    k = input()
    if k == "AC":
        d['AC'] += 1
    elif k == "WA":
        d['WA'] += 1
    elif k == "TLE":
        d['TLE'] += 1
    elif k == "RE":
        d['RE'] += 1
    
print("AC x", d['AC'])
print("WA x", d['WA'])
print("TLE x", d['TLE'])
print("RE x", d['RE'])

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  sort(vec.begin(),vec.end());
  int64_t ans = 0;
  int drink = 0;
  bool flag = true;
  
  for(int i=0; i<N; i++){
    int cnt = 0;
   if(flag){
     while(cnt < vec.at(i).at(1)){
      drink++;
      ans += vec.at(i).at(0);
      cnt++;
      if(drink == M){
        flag = false;
        break;
      }
     }
   }
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
import sys

input = sys.stdin.readline

MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))

ans2 = (sum(a) % MOD) ** 2 - sum(ai ** 2 for ai in a)

if ans2 % 2 != 0:
    ans2 += MOD
ans = (ans2 // 2) % MOD
print(ans)


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

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            //int ans = 0;
            var ans = Enumerable.Range(1, n).Sum();
            /*
            for (int i = 1; i <= n; i++)
            {
                ans += i;
            }
            */
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

typedef long long ll;

ll dp[2002][2002];

#define MOD 1000000007

int main(void) {
  int n, m; cin >> n >> m;
  vector<int> ss;
  vector<int> ts;
  for (int i = 0; i < n; i++) {
    int st; cin >> st; ss.push_back(st); 
  }
  for (int i = 0; i < m; i++) {
    int tt; cin >> tt; ts.push_back(tt);
  }
  for (int i = 0; i <= n; i++) // 空列は必ず一致するためそれを考慮した値で初期化
    dp[i][0] = 1;
  for (int i = 0; i <= m; i++)
    dp[0][i] = 1;

  // Sとi、Tをjまで考慮した値で更新していく
  for (int i = 1; i <= n; i++)  
    for (int j = 1; j <= m; j++) {
      // まだカウントされてない要素を加算
      // 共通部分を除外するが、((i - 1, j - 1)にあるものがいままでの共通要素)
      // 現在の文字が一致した場合、共通部分が増えるので条件分岐
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
      if (ss[i - 1] != ts[j - 1]) {
        dp[i][j] = (dp[i][j] + MOD - dp[i - 1][j - 1]) % MOD; 
      }
    }

  // n, mまで考慮した値ということは文字列全体をみた値であるため、これを出力
  cout << dp[n][m] << endl;

  return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <cmath>
using namespace std;
 
bool isPrime(int n){
     
    if(n == 2) return true;
    else if(n%2 == 0) return false;
     
    int i = 3;
    while(i <= sqrt(n)){
        if(n%i==0){
            return false;
        }
        else{
            i = i + 2;
        }
    }
    return true;
}
 
 
int main() {
    int N, element, count = 0;
     
    cin >> N;
     
    for(int i = 0; i<N ;i++){
        cin >> element;
        if(isPrime(element) == true) {
            count++;
            //cout << element << endl;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3028
def num(N, M):
    return min(N, M//2)

N, M = map(int, input().split())
if 2*N >= M:
    print(M//2)
else:
    a = (M - 2*N) // 4
    cand = []
    for i in range(a, a+1):
        cand.append(num(N+i, M-2*i))
    print(max(cand))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#define _USE_MATH_DEFINES
using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<string, map<string, int> > Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;

double getb[200000];
double dp[100001][30];

int main(){
	int n;
	fill(&dp[0][0], &dp[100000][29] + 1, 0.0);
	dp[1][1] = 1.0;
	for(int i = 1; i < 100000; i++){
		for(int j = 0; j < 29; j++){
			dp[i+1][j+1] += dp[i][j] * pow(0.5, j);
			dp[i+1][0] += dp[i][j] * (1 - pow(0.5, j));
		}
	}
	getb[0] = 0;
	for(int i = 1; i <= 100000; i++){
		getb[i] = 0.0;
		for(int j = 1; j < 30; j++){
			getb[i] += dp[i][j];
		}
		getb[i] += getb[i-1];
	}
	while(cin >> n && n){
		cout << fixed << setprecision(9) << getb[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 24000
#include<iostream>
#include<vector>
using namespace std;typedef pair<int,int>P;typedef vector<P>V;typedef V::iterator I;void D(V&v,int x,I&i){int c=0;for(i=v.begin();c<x;++i)c+=i->second-i->first;int&s=i[-1].second;i=v.insert(i,P(s-c+x,s));s-=c-x;}void S(V&v,int x,int y){I i,j;v.reserve(v.size()+2);D(v,x,i);D(v,y,j);V v1(j,v.end());v1.insert(v1.end(),i,j);v1.insert(v1.end(),v.begin(),i);v=v1;}int main(){int n,m,p,q,r,x,y,c;for(;cin>>n>>m>>p>>q>>r,n;){V v(1,P(0,n));for(;m--;){cin>>x>>y;S(v,x,y);}v.reserve(v.size()+2);I i,e;D(v,p-1,i);D(v,q,e);for(c=0;i!=e;++i)c+=i->second<=r?i->second-i->first:i->first<r?r-i->first:0;cout<<c<<endl;}}

Measured memory_bytes: 1284
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
a = input().split()
li = []
s = 1
for i in range(1,N):
    if a[i] != a[i-1]:
        li.append(s)
        s = 1
        continue
    if a[i] == a[i-1]:
        s +=1
if s != '':
    li.append(s)
n = len(li)
ans = 0
for i in range(n):
    l = li[i]
    ans += l//2
print(ans)

Measured memory_bytes: 3064
inputs = raw_input().replace("\n", "").split(" ")
x1, y1, x2, y2 = map(int, inputs)

w = x2 - x1
h = y2 - y1
x3, y3 = x2 - h, y2 + w
x4, y4 = x3 - w , y3 - h

print("%d %d %d %d" % (x3, y3, x4, y4))

Measured memory_bytes: 2568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        int A = 0;
        
        for(int i = 0; i < N; i++){
            A += sc.nextInt();
        }
        
        System.out.println(H > A ? "No" : "Yes");
    }
}

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

int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    s += s;
    int i = 0, cnt = 1;
    ll ans1 = 0;
    while(i<n-1){
        if(s[i]==s[i+1])cnt++;
        else{
            ans1 += cnt/2;
            cnt=1;
        }
        i++;
    }
    if(cnt==n){
        ll ans = (ll)n*k/2;
        cout << ans << endl;
        return 0;
    }
    ll ans2=ans1;
    ans1 += cnt/2;
    while(i<2*n-1){
        if(s[i]==s[i+1]) cnt++;
        else{
            ans2+=cnt/2;
            cnt=1;
        }
        i++;
    }
    ans2+=cnt/2;
    ll ans =ans1 + (ans2-ans1)*(k-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define int long long
#define INF 1<<40
#define N 100
using namespace std;
signed main() {
	int n; cin >> n;
	int a[200000];
	for (int i = 0; i < n; ++i) cin >> a[i];
	sort(a, a + n);
	bool flag = true;
	for (int i = 0; i < n - 1; ++i)
		if (a[i] == a[i + 1]) flag = false;
	cout << (flag ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1792
from functools import reduce
N = int(input())
g = 10 ** 9 + 7


def mul(a, b):
  return (a * b) % g

def adda(a, p1, p2):
    for x in range(len(a)):
        a[x] = p1[x] + p2[x]

d = []
DP = [[0 for _ in range(N+1)] for _ in range(N+1)]
ans = [0 for _ in range(N+1)]
for i in range(2, N+1):
  for j in (x for x in d if x * x <= N):
    if i % j == 0:
      adda(DP[i], DP[j], DP[i//j])
      break
  else:
    d.append(i)
    DP[i][i] = 1
  adda(ans, ans, DP[i])

print(reduce(mul, [x + 1 for x in ans[1:N+1]]))


Measured memory_bytes: 12388
#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main(void) {
    cin >> n >> m;
    if (n >= m / 2) {
        cout << m / 2 << endl;
    } else {
        cout << (2 * n + m) / 4 << endl;
    }
    return 0;
}

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

int main(){
  int H,W,K,a=0;
  cin>>H>>W>>K;
  vector<string> B(H),b(H);
  REP1(i,0,H){
    cin>>B[i];
    B[i]='#'+B[i]+'#';
  }
  REP1(i,1,H) REP1(j,1,W+1){
    REP1(k,0,H) b[k]=B[k];
    REP2(k,i,0) b[k][j]=b[k-1][j];
    b[0][j]='s';
    int p=0,x=0,f=1,z;
    while(f){
      f=0;
      char c1,c2;
      REP1(i1,0,H) REP1(j1,1,W+2){
        if(j1==1) z=0;
        c1=b[i1][j1-1];
        c2=b[i1][j1];
        if(c2==c1&&c1!='s'){
          z++;
          continue;
        }
        if(z>=K){
          p+=(c1-'0')*z*pow(2,x);
          REP2(i2,i1,0)
            b[i2].replace(j1-z,z,b[i2-1].substr(j1-z,z));
          b[0].replace(j1-z,z,z,'s');
          f=1;
        }
        z=1;
      }
      x++;
    }
    a=max(a,p);     
  }
  cout<<a<<endl;
}

Measured memory_bytes: 3920