akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<ios>
using namespace std;
template<int N>
struct ans{
	bool a[N];
	constexpr ans():a(){
		for(int i=0;i<N;i++){
			a[i]=i%10==i/10000+1&&i/1000%10==i/10%10;
		}
	}
};
constexpr auto a=ans<90000>();
int N,M,s;
main(){
	scanf("%d%d",&N,&M);
	N-=10000;
	M-=10000;
	for(;N<=M;N++)s+=a.a[N];
	printf("%d",s);
}


Measured memory_bytes: 256
s = gets.chomp.chars
alphabet = ('a'..'z').to_a
n = s.size

if n < 26
  c = alphabet.find { |x| !s.include?(x) }
  puts s.join + c
  exit
end

arr = []
id = -1
(n - 1).downto(1) do |i|
  arr << s[i]
  if s[i - 1] < s[i]
    id = i - 1
    break
  end
end

if id == -1
  puts '-1'
else
  c = arr.select { |x| x > s[id] }.min
  if id == 0
    puts c
  else
    puts s[0..id - 1].join + c
  end
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, int> mp;
  int mn=N, mx=0;
  rep(i, N) {
    cin >> A[i];
    mp[A[i]]++;
    mn = min(A[i], mn);
    mx = max(A[i], mx);
  }
  switch(mx-mn) {
    case 0:
      if(mp[mn] == mn+1) cout << "Yes" << endl;
      else if(mp[mn] >= mn*2) cout << "Yes" << endl;
      else cout << "No" << endl;
      break;
    case 1:
      if(mp[mn] < mx && 2*(mx-mp[mn]) <= mp[mx]) cout << "Yes" << endl;
      else cout << "No" << endl;
      break;
    default:
      cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <math.h>

using namespace std;


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

	for (long long unsigned int i = (long long unsigned int)sqrt(N) + 1; i >= 1; i--)
	{
		if (N % i == 0)
		{
			cout << (i - 1) + (N / i - 1) << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
    char w[11],t[1001];
    int i,n=0;

    gets(w);

    while(1){
        gets(t);
        if(!strcmp(t,"END_OF_TEXT")) break;

        char* pt=strtok(t," /\".,@#");
        i=0;
        while(pt[i]!='\0'){
            pt[i]=tolower(pt[i]);
            i++;
        }
        if(!strcmp(pt,w)) n++;

        while(1){
            pt=strtok(NULL," /\".,@#");
            if(pt==NULL) break;
            i=0;
            while(pt[i]!='\0'){
                pt[i]=tolower(pt[i]);
                i++;
            }
            if(!strcmp(pt,w)) n++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 528
#include <iostream>
#include <vector>

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

  std::vector<long long> A(N);
  std::vector<long long> S(N + 1, 0);

  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }

  for (int i = 1; i <= N; i++) {
    S[i] = S[i - 1] + A[i - 1];
  }

  long long ans = 0;
  int mod = 1000000007;

  for (int i = 0; i < N; i++) {
    ans += A[i] * ((S[N] - S[i + 1]) % mod);
    ans %= mod;
  }

  std::cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 6348
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let a: Vec<u64> = get!(u64;n);

    let mut set = HashSet::new();

    for &x in &a {
        if !set.remove(&x) {
            set.insert(x);
        }
    }

    println!("{}", set.len());
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int n,m,a[5555];
LL ans;
int main(){
	cin>>n>>m;
	FOR(i,1,n) getint(a[i]);
	FOR(i,1,n)
		FOR(j,1,n)
			if (a[i]>a[j]){
				if (i<j) (ans+=1ll*m*(m+1)/2)%=MO;
				else (ans+=1ll*m*(m-1)/2)%=MO;
			}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m,n,aa[110000][10],cnt=0;
pair<int,int> p[220000];
string s,ss[220000],x;
char c;
signed main(){
    rep(i,3){
        rep(j,3){
            cin>>aa[i][j];
        }
    }
    cin>>n;
    rep(i,n){
        cin>>m;
        rep(j,3){
            rep(k,3){
                if(aa[j][k]==m){
                    aa[j][k]=0;
                }
            }
        }
    }
    rep(i,3){
        if(aa[i][0]==0&&aa[i][1]==0&&aa[i][2]==0){
            cout<<"Yes";
            return 0;
        }
    }
    rep(i,3){
        if(aa[0][i]==0&&aa[1][i]==0&&aa[2][i]==0){
            cout<<"Yes";
            return 0;
        }
    }
    if((aa[0][0]==0&&aa[1][1]==0&&aa[2][2]==0)||(aa[2][0]==0&&aa[1][1]==0&&aa[0][2]==0)){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
}

Measured memory_bytes: 3968
X = int(input())

x = 0

L = [0]

if X == 1:
  print(X)

else:
  for i in range(2,int(X ** 0.5) + 1):
    n = 1
    a = i
    while n < X :
      n *= a
      L.append(n)
    if n // a > x:
      x = (n // a)
  
  print(max(i for i in L if i <= X))

Measured memory_bytes: 3060
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

i = 0
j = 0
count = 0
a = [0]*N
b = [0]*M
ans = 0

sum = 0
for i in range(N):
    sum += A[i]
    a[i] = sum
sum = 0
for j in range(M):
    sum += B[j]
    b[j] = sum

ind = bisect.bisect_right(b, K)
ans = ind

for i in range(N):
    if a[i] <= K:
        ind = bisect.bisect_right(b, K-a[i])
        ans = max(ans, ind+i+1)
    else:
        break

print(ans)


Measured memory_bytes: 47312
#include <iostream>

 

using namespace std;

 

int main()
{
   int i, h, m, s;     
   cin >> i;
   h = i / 3600;
   m = i / 60 % 60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;
   
   return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;

struct edge { int to, cost; };

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
//const ll INF = 1e18;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

ll dp[110][100010];

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

Measured memory_bytes: 79360
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	
	cin>>N;
	
	for(int i = 1; i <=9; i++){
		for(int j = 1; j <= 9; j++){
			if(i*j == N){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define N 101

int main(void){
	int i=0,j=0,k=0;
	char S[N];
	do{
		scanf("%c",&S[j]);
		j++;
	}while(S[j-1]!='\n');
	while(i<=j-2-i){
		if(S[i]!=S[j-2-i]){
			k++;
		}
		i++;
	}
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr int INF = 1e7;
constexpr ll MOD = 1e9 + 7;

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

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

    int n = 0;

    while (true)
    {
        if (n == INF)
        {
            cout << -1 << endl;
            return 0;
        }

        if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
            break;

        int a_ = a, b_ = b, c_ = c;

        a = (c_ + b_) / 2;
        b = (c_ + a_) / 2;
        c = (a_ + b_) / 2;

        n++;
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

LL path[305][305];
LL ans[305][305];
LL INF = 9999999999999999;

int main() {
    LL n, m, l;
    cin >> n >> m >> l;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            path[i][j] = INF;
            ans[i][j] = INF;
        }
        path[i][i] = 0;
    }

    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (c <= l) {
            path[a][b] = c;
            path[b][a] = c;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                path[j][k] = min(path[j][k], path[j][i] + path[i][k]);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (path[i][j] <= l) {
                ans[i][j] = 1;
            }
        }
        ans[i][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans[j][k] = min(ans[j][k], ans[j][i] + ans[i][k]);
            }
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s, t;
        cin >> s >> t;
        if (ans[s][t] == INF) {
            printf("-1\n");
        } else {
            printf("%lld\n", ans[s][t] - 1);
        }
    }

}


Measured memory_bytes: 5132
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';
#define MOD 1000000007

using namespace std;
static ll dp[3000][3000];
int main(void){
    
    ll N, M, S[3000], T[3000];
    cin>>N>>M;
    rep(i, N) cin>>S[i];
    rep(j, M) cin>>T[j];
    MEMSET(dp, 0);
    dp[0][0]=0;
    rep(i, N+1) rep(j, M+1){
        if(i==0 || j==0) dp[i][j]=0;
        else{
        dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+MOD)%MOD;
        if(S[i-1]==T[j-1]) dp[i][j]+=(dp[i-1][j-1]+1)%MOD;
        dp[i][j]%=MOD;
            //cout<<i<<sp<<j<<sp<<dp[i][j]<<endl;
        }
    }
    cout<<(dp[N][M]+1)%MOD<<endl;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(void){
    ll N=5;
    ll A=0;
    
    for(ll i=0; i<5;i++){
        cin>>A;
        if(A==0){
            cout << i+1 << endl;
        }
    }
        
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;

int main()
{
	int a,b,c,d;
	scanf("%d%d",&a,&b);
	c=b*(b-1); 
	c+=a*(a-1);
	printf("%d\n",c/2);
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 61;

int MOD = 1000000007;


int main(){
    std::ios_base::sync_with_stdio(false);

    ll n; cin >> n;
    ll x[5]; rep(i,5) cin >> x[i];

    //cout << INF << endl;

    ll mi = INF;
    rep(i,5) mi = min(mi, x[i]);

    if(n<=mi) cout << 5 << endl;
    else if (mi<n && n%mi==0) cout << n/mi + 4 << endl;
    else cout << n/mi + 5 << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

def main():
    bCardNum = int(input())
    bCard = [input() for s in range(bCardNum)]
    
    rCardNum = int(input())
    rCard = [input() for s in range(rCardNum)]
    
#    print(bCard)
#    print(rCard)
    
    uniq_bCard = list(set(bCard))
#    print(uniq_bCard)
    
    result = 0
    
    count_bCard = Counter(bCard)
    count_rCard = Counter(rCard)
    
    for string in uniq_bCard:
        tmp = count_bCard[string] - count_rCard[string]
        if(tmp > result):
            result = tmp
    
    print(result)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define int long long
using namespace std;
typedef pair<int,int> pii;
static const int inf = 1ll<<60;
static const int MAX_N = 100000;

int N,T,Q;
vector<pii> A;
int flg[MAX_N+5];
int table[MAX_N+5];
int next[MAX_N+5];

signed main(){
    for(int i=0;i<100000;++i){
        next[i]=inf;
    }
    cin>>N>>T>>Q;
    for(int i=0;i<N;++i){
        int a,d;
        cin>>a>>d;
        if(d!=1)d=-1;
        A.PB(pii(a,d));
    }
    int maxd=0;
    int t=0;
    for(int i=0;i<N;++i){
        if(flg[i]==1)continue;
        if(A[i].SE!=1||A[i+1].SE!=-1){
            if(A[i].SE==1)table[i]=t;
            else table[i]=t-1;
            continue;
        }
        int D=abs(A[i].FI-A[i+1].FI)/2;
        if(D<=T){
            maxd=max(D,maxd);
            A[i].FI+=A[i].SE*D;
            A[i+1].FI=A[i].FI;
            flg[i]=1;
            flg[i+1]=1;
            next[t]=A[i].FI;
            t++;
        }
    }
    for(int i=0;i<N;++i){
        if(flg[i]==1)continue;
        if(A[i].SE==1){
            int k=table[i];
            int d=abs(A[i].FI-next[k]);
            if(d>=maxd)A[i].FI+=maxd;
            else {
                A[i].FI=next[k];
                flg[i]=1;
            }
        }
        else {
            int k=table[i];
            int d=abs(A[i].FI-next[k]);
            if(d>=maxd)A[i].FI-=maxd;
            else {
                A[i].FI=next[k];
                flg[i]=1;
            }
        }
    }
    T-=maxd;
    for(int i=0;i<N;++i){
        if(flg[i]==1)continue;
        if(A[i].SE==1&&A[i+1].SE==-1){
            A[i].FI+=T;
            A[i+1].FI-=T;
            flg[i]=1;
            flg[i+1]=1;
            continue;
        }
        if(A[i].SE==1){
            int k=table[i];
            if(next[k]==inf){
                A[i].FI+=T;
            }
            else{
                int d=abs(A[i].FI-next[k]);
                if(d<=T)A[i].FI=next[k];
                else A[i].FI+=T;
            }
        }
        else{
            int k=table[i];
            if(next[k]==inf)A[i].FI-=T;
            else{
                int d=abs(A[i].FI-next[k]);
                if(d<=T)A[i].FI=next[k];
                else A[i].FI-=T;
            }
        }
    }
    for(int i=0;i<Q;++i){
        int q;
        cin>>q;
        q--;
        cout<<A[q].FI<<endl;
    }
}

Measured memory_bytes: 5124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;
typedef pair<ll, string> PLS;

ll n, color;

int main(){
	while (cin >> n&&n){
		V vi;
		REP(i, n){
			ll ncolor;
			if (i % 2 == 0){
				cin >> ncolor;
				if (i == 0){
					color = ncolor;
					vi.push_back(1);
				}
				else{
					if (color == ncolor)vi[vi.size() - 1]++;
					else {
						color = ncolor;
						vi.push_back(1);
					}
				}
			}
			else{
				cin >> ncolor;
				if (ncolor != color){
					color = ncolor;
					ll num = vi[vi.size() - 1] + 1;
					vi.pop_back();
					if (vi.empty())vi.push_back(num);
					else vi[vi.size() - 1] += num;
				}
				else{
					vi[vi.size() - 1]++;
				}
			}
			//REP(i, vi.size()){
			//	cout << vi[i] << " ";
			//}
			//cout << endl;
		}
		//cout << color;
		ll ans = 0, size = vi.size();
		for (int i = size - 1; i >= 0; i--){
			if (color == 0){
				if ((size - 1 - i) % 2 == 0)ans += vi[i];
			}
			else {
				if ((size - 1 - i) % 2 == 1)ans += vi[i];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3080
n,a,b=map(int,input().split())
# x=n//(a+b)
# y=n%(a+b)
# print(a*x+min(y,a))
if a==0:
    print(0)
else:
    x=n//(a+b)
    y=n%(a+b)
    print(a*x+min(y,a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110000;
bool vis[MAXN];
int val[MAXN];
list<int> grafo[MAXN];
void bfs(){
  deque<pair<int, int>> Q;
  vis[0] = true;
  Q.push_back({0,-1});
  while(!Q.empty()){
    auto el = Q.front();
    int node = el.first;
    Q.pop_front();
    for(auto adj : grafo[node])
      if(!vis[adj]){
        vis[adj] = true;

        val[adj] = node;
        Q.push_back({adj, node});
      }
  }
}

int main(){
  int N, M, da, a;
  cin>>N>>M;

  for(int i = 0; i < M; i++){
    cin>>da>>a;
    da--;
    a--;
    grafo[da].push_back(a);
    grafo[a].push_back(da);
  }
  bfs();
  bool notOk = false;
  for(int i = 0; i < N; i++){
    if(!vis[i])
      notOk = true;
  }
  if(notOk)
    cout<<"No\n";
  else{
    cout<<"Yes\n";
    for(int i = 1; i < N; i++)
      cout<<val[i]+1<<'\n';
  }
}


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

int main()
{
    double a,b,c;
    cin>>a>>b>>c;
    c+=0.5;
    double sum=0;
    while(c>=a)
    {
       sum+=b;
       c-=a;
    }
    cout<<sum<<endl;
}


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

using namespace std;

int main() {
   int N, tmp;
   cin >> N;
   int P[N];
   for (int i = 0; i < N; i++) {
      cin >> tmp;
      P[tmp - 1] = i;
   }
   int ans = 0, cnt = 0;
   for (int i = 1; i < N; i++) {
      if (P[i] > P[i - 1]) cnt++;
      else cnt = 0;
      ans = max(cnt, ans);
   }
   cout << N - (ans + 1) << endl;
   return 0;
}


Measured memory_bytes: 1024
import random
 
def quick_sort(array):
    low_array = []
    high_array = []
    if len(array) <= 1:
        return array
    pivot = random.choice(array)[0]
    pivot_count = 0
    for a in range(len(array)):
        if pivot > array[a][0]:
            low_array.append(array[a])
        elif pivot < array[a][0]:
            high_array.append(array[a])
        else:
            pivot_count += 1
    print(pivot, low_array, high_array, pivot_count)
    low_array = quick_sort(low_array)
    high_array = quick_sort(high_array)
    return low_array + [pivot, ] * pivot_count + high_array
    #return low_array + high_array
 
def main():
    list1=input().split(' ')
    n=int(list1[0])
    m=int(list1[1])
    biglist=[]
    for i in range(n):
        list=input().split(' ')
        biglist.append([int(list[0]), int(list[1])])
    #array = [3, 4, 2, 6, 8, 1, 7]
    array=[[5,1], [2,3], [3,4], [7,2], [6,6]]
    #new_array=quick_sort(array)
    #print(new_array)
    newlist=sorted(biglist)
    #print(sorted(biglist))
    #print(newlist, m, n)
    money=0
    jun=0
    while m>0:
        if newlist[jun][1]>=m:
            money+=m*newlist[jun][0]
            print(money)
            return
        else:
            money+=newlist[jun][0]*newlist[jun][1]
            #print(money)
            m-=newlist[jun][1]
        jun+=1

main()

Measured memory_bytes: 21292
n = int(input())
t, a = map(int, input().split())
h = [int(i) for i in input().split()]

for i in range(len(h)):
    temp = t-h[i]*0.006
    if i == 0:
        min_dist = abs(temp-a)
        ans = i
    elif min_dist > abs(temp-a):
        min_dist = abs(temp-a)
        ans = i
print(ans+1)

Measured memory_bytes: 3060
N, C, K = map(int, input().split())
T = []
for _ in range(N):
    T.append(int(input()))
T.sort()

ans = 1
temp = [T[0], 0]
for t in T:
    if temp[0] + K < t or temp[1] + 1 > C:
        ans += 1
        temp = [t, 0]
    temp[1] += 1
print(ans)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vl;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define ln "\n"
#define forn(i,e) for(ll i=0; i<e; i++)
#define forsn(i,s,e) for(ll i=s; i<e; i++)
#define rforn(i,e) for(ll i=e; i>=0; i--)
#define rforsn(i,s,e) for(ll i=e; i>=s; i--)
#define vasort(v) sort(v.begin(), v.end())
#define vdsort(v) sort(v.begin(), v.end(),greater<int>())
#define F first
#define S second

#define out1(x1) cout << x1 << ln
#define out2(x1,x2) cout << x1 << " " << x2 << ln
#define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
#define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
#define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
#define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

#define in1(x1) cin >> x1
#define in2(x1,x2) cin >> x1 >> x2
#define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
#define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
#define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
#define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

#define arrin(a,n) forn(i,n) cin >> a[i];
#define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main(){
    ll n,W;
    in2(n,W);
    vl w,v;
    w.PB(0);
    v.PB(0);
    forn(i,n){
        ll a,b;
        in2(a,b);
        w.PB(a);
        v.PB(b);
    }
    vl value(W+1,0);
    vector<bool> possible(W+1);
    possible[0]=true;
    for(ll k=1;k<=n;k++){
        for(ll x=W;x>=0;x--){
            if (possible[x] && x+w[k]<=W){
                possible[x+w[k]]=true;
                value[x+w[k]]=max(value[x+w[k]],value[x]+v[k]);
            }
        }
    }
    ll c=0;
    forn(i,W+1){
        c=max(c,value[i]);
    }
    out1(c);
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(m);
    ll ans=1;
    ll mod = 1e9+7;
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        a[i]=n*m-a[i];
    }
    for(int i = 0; i < m; i++)
    {
        cin>>b[i];
        b[i]=n*m-b[i];
    }
    sort(all(a));
    sort(all(b));
    
    for(int i = 0; i < n-1; i++)
    {
        if(a[i]==a[i+1])
        {
            ans=0;
            break;
        }
    }
    
    for(int i = 0; i < m; i++)
    {
        if(b[i]==b[i+1])
        {
            ans=0;
            break;
        }
    }
    
    
    ll acnt=0;
    ll bcnt=0;
    
    for(int now = 0; now < n*m; now++)
    {
        if(ans==0)
        {
            break;
        }
        if(acnt<n && a[acnt]==now)
        {
            if(bcnt<m && b[bcnt]==now)
            {
                acnt++;
                bcnt++;
            }
            else
            {
                acnt++;
                ans*=bcnt;
                ans%=mod;
            }
        }
        else if(bcnt<m && b[bcnt]==now)
        {
            bcnt++;
            ans*=acnt;
            ans%=mod;
        }
        else
        {
            ll kouho = acnt*bcnt - now;
            if(kouho>0)
            {
                ans*=kouho;
                ans%=mod;
            }
            else
            {
                ans=0;
            }
        }

        //test
        //cout<<now<<"\t"<<ans<<endl;
    }
    


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

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations
from itertools import accumulate
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

s=input()
# lst=[0,0]
ans=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="g":
            continue
        else:
            ans-=1
    else:
        if s[i]=="g":
            ans+=1
        else:
            continue
print(ans)

Measured memory_bytes: 65132
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
//	ios::sync_with_stdio(false);
//	cin.tie(0);
const int maxx = 2e5+7;
const int maxn = 1e9+7;
typedef long long ll;
using namespace std;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll t,n,m;
ll a[maxx],sum;
priority_queue <ll,vector<ll>,less<ll> >q[100005];
int main(){
		ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	rept(i,1,n)cin>>a[i];
	rept(i,1,m){
		int op,op1;
		cin>>op>>op1;
		q[op].push(a[op1]);
		q[op1].push(a[op]);
	}
	rept(i,1,n){
		q[i].push(a[i]);
		ll op=q[i].top();
	//	cout<<op<<endl;
		if(q[i].size()==1)sum++;
		else{
			if(a[i]==op){
				q[i].pop();
				if(a[i]>q[i].top())sum++;
			}
		}	
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 12464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#define lp(i, l, r) for (int i = l; i <= r; ++i)
#define rp(i, r, l) for (int i = r; i >= l; --i)
#define ls(i, s) for (int i = 0; s[i]; ++i)
#define rs(i, s) for (int i = strlen(s) - 1; i >= 0; --i)
#define lv(i, a) for (int i = 0; i < a.size(); ++i)
#define rv(i, a) for (int i = (int)a.size() - 1; i >= 0; --i)
#define in(a) int a = (cin >> a, a)
#define ou(a) cout << a << endl
#define fast ios::sync_with_stdio(0), cin.tie(0)
#define prec(a) cout << setprecision(a) << fixed
#define appl(f, a) for (auto i = begin(a); i != end(a); f, ++i)
#define many for (int T = -1; T < 0 && cin >> T, T--;)
#define rang(a) begin(a), end(a)
#define gene template <class T>
#define endl '\n'
#define asse assert
using namespace std;
using namespace __gnu_pbds;
gene void sort(T &a) { sort(rang(a)); }
gene void reve(T &a) { reverse(rang(a)); }
gene void uniq(T &a) { sort(a), a.erase(unique(rang(a)), end(a)); }
gene void shuf(T &a) { random_shuffle(rang(a)); }
gene void merg(T l, T m, T r) { inplace_merge(l, m, r); }
gene auto gath(const T &a, const vector<int> &b) {
    vector<typename T::value_type> r;
    for (auto i : b)
        r.push_back(a[i]);
    return r;
}
gene auto min(const T &a) { return *min_element(rang(a)); }
gene auto max(const T &a) { return *max_element(rang(a)); }
gene auto sum(const T &a) { return accumulate(rang(a), 0); }
gene T inf() { return numeric_limits<T>::max(); }
gene int tmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
gene int tmax(T &a, T b) { return b > a ? a = b, 1 : 0; }
gene using bbst =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
gene using heap = __gnu_pbds::priority_queue<T, greater<T>, pairing_heap_tag>;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
template <class F, class S> auto &operator>>(istream &s, pair<F, S> &a) {
    return s >> a.first >> a.second;
}
gene auto &operator>>(istream &s, vector<T> &a) {
    for (int i = -1; i < 0 && (!a.size() && (cin >> i, a.resize(i), 0), i = 0),
             i < a.size();)
        s >> a[i++];
    return s;
}
template <class F, class S> auto &operator<<(ostream &s, const pair<F, S> &a) {
    return s << '(' << a.first << ", " << a.second << ')';
}
gene auto &operator<<(ostream &s, const vector<T> &a) {
    lv(i, a) cout << a[i] << (i + 1 == a.size() ? "" : " ");
    return s;
}
int main() {
    fast, prec(12);
    int n, k, s;
    cin >> n >> k >> s;
    if (s != int(1e9)) {
        lp(i, 1, k) cout << s << " ";
        lp(i, 1, n - k) cout << s + 1 << " ";
    } else {
        lp(i, 1, k) cout << s << " ";
        lp(i, 1, n - k) cout << 1 << " ";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;
int main(){
  int H,W; cin >> H >> W;
  vector<vector<ll>> to(10, vector<ll> (10,INF));
  for(int i = 0; i < 10; i++){
    for(int j  = 0; j < 10; j++){ cin >> to[i][j];}}
    
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < 10; j++){
        for(int k = 0; k < 10; k++){
          to[j][k] = min( to[j][k], to[j][i] + to[i][k]);}}}
                       // Warshall - Floyd method
    
     ll ans = 0;
    
    vector<vector<int>> A( H, vector<int> (W));
    
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> A[i][j];
        if( A[i][j] == 1 || A[i][j] == -1){ continue;}
        else{  ans += to[A[i][j]][1];} }}
    
    cout << ans << endl; return 0;}
          

Measured memory_bytes: 384
use std::io::stdin;
use std::collections::VecDeque;

fn read_line() -> Vec<i64> {
    let mut a_str = String::new();
    stdin().read_line(&mut a_str).expect("read error");
    a_str.split_whitespace()
        .map(|x| x.parse::<i64>().expect("parse error"))
        .collect::<Vec<i64>>()
}

fn main() {
    let v = read_line();
    let n = v[0] as usize;
    let d = v[1] as usize;
    let a = v[2];

    let mut m = Vec::<(i64, i64)>::new();
    for _i in 0..n as usize {
        let v = read_line();
        m.push((v[0], v[1]));
    }

    m.sort_by(|x, y| x.0.cmp(&y.0));

    let mut ret = 0;
    let mut total = 0;
    let mut queue = VecDeque::<(i64, i64)>::new();

    for i in 0..n {
        while queue.len() > 0 {
            let x = queue[0];
            if x.0 < m[i].0 {
                total -= queue[0].1;
                queue.pop_front();
            } else {
                break;
            }
        }

        m[i].1 -= total;

        if m[i].1 > 0 {
            let c = (m[i].1 + a - 1) / a;
            ret += c;
            total += c * a;
            queue.push_back((m[i].0 + 2 * d as i64, c * a));
        }
    }
    
    println!("{}", ret);
}

Measured memory_bytes: 11332
#include<stdio.h>
int main()
{
    char a[6],b,c,d,e;
    int i;
    scanf("%s",a);

    for(i=2; i<=5; i++)
    {
        if(a[i]>=97 && a[i]<=122)
        {
            if(i==2)
                b=a[i];
            else if(i==3)
                c=a[i];
            else if(i==4)
                d=a[i];
            else if(i==5)
                e=a[i];
        }
    }

    if(b==c && d==e)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int inf=(1<<20);


int main(void){
    int n,m;

 int c[inf];
 int t[inf];

    cin>>n>>m;
  for(int i=0;i<m;i++){
      int k;
      cin>>k;
      c[i]=k;
  }
  for(int j=0;j<=n;j++){
      t[j]=inf;
  }
  
  t[0]=0;
  for(int i=0;i<m;i++){
      for(int j=c[i];j<=n;j++){
          t[j]=min(t[j],t[j-c[i]]+1);
      }
  }
  cout<<t[n]<<endl;
    return 0;
}



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

int main()
{
	int n, m;
	while (scanf("%d %d", &n, &m), n + m){
		string str;
		str += "*";
		for (int i = 0; i < n; i++){
			str += "#";
		}
		for (int i = 0; i < m; i++){
			string t;
			cin >> t;
			if (t == "A"){
				int j = 1;
				while (str[j] != '#'){
					j++;
				}
				str[j] = 'A';
			}
			else if (t == "B"){
				bool f = false;
				for (int j = str.size(); j >= 0; j--){
					if (str[j] == '#' && str[j - 1] != 'A' && str[j + 1] != 'A'){
						str[j] = 'B';
						f = true;
						break;
					}
				}
				if (!f){
					int j = 1;
					while (str[j] != '#'){
						j++;
					}
					str[j] = 'B';
				}
			}
			else if (t == "C"){
				if (i == 0){
					if (n % 2 == 1){
						str[(n + 1) / 2] = 'C';
					}
					else {
						str[n / 2 + 1] = 'C';
					}
				}
				else {
					for (int j = 1; j < str.size(); j++){
						if (str[j] != '#'){
							if (str[j + 1] == '#'){
								str[j + 1] = 'C';
								break;
							}
							else if (str[j - 1] == '#'){
								str[j - 1] = 'C';
								break;
							}
						}
					}
				}
			}
			else if (t == "D"){
				if (i == 0){
					str[1] = 'D';
					continue;
				}
				
				int maxd = -1, maxp;
				for (int j = 1; j < str.size(); j++){
					if (str[j] != '#') continue;
					bool f = false, ff = false;
					for (int k = 1; k <= 100 && !f; k++){
						if (j - k > 0){
							if (str[j - k] != '#'){
								if (maxd < k){
									maxd = k;
									maxp = j;
								}
								f = true;
								continue;
							}
						}
						if (j + k < str.size()){
							if (str[j + k] != '#'){
								if (maxd < k){
									maxd = k;
									maxp = j;
								}
								f = true;
								continue;
							}
						}
					}
				}
				str[maxp] = 'D';
			}
		}
		
		string res = str.substr(1);
		cout << res << endl;
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll n, t;
    cin >> n >> t;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;

    sort(all(ab), [](auto lhs, auto rhs){
        if(lhs.first<rhs.first) return true;
        else if(lhs.first==rhs.first) return lhs.second<rhs.second;
        else return false;
    });

    vll a(n), b(n);
    rep(i, n) a[i] = ab[i].first;
    rep(i, n) b[i] = ab[i].second;

    vvll dp(n, vll(t, 0));
    ll res = 0;
    rep(i, n){
        rep(j, t){
            if(i==0) dp[i][j] = j==a[i]? b[i] : 0;
            else if(j-a[i]>=0) dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i]]+b[i]);
            else dp[i][j] = dp[i-1][j];
        }
        rep(j, t){
            res = max(res, dp[i][j]);
            if(i>0) res = max(res, dp[i-1][j]+b[i]);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 70784
use proconio::input;

fn main() {
    input! {
        s: usize
    }

    let n = {
        let n = (s as f64).sqrt().round() as usize;
        if n*n > s {n-1} else {n}
    };

    if n*n == s {
        println!("{} 0 0 {} 0 0",n,n)
    } else if n*(n+1) == s {
        println!("{} 0 0 {} 0 0",n,n+1)
    } else if n*(n+1) > s {
        println!("{} {} 1 {} 0 0",n,n*(n+1)-s,n+1)
    } else {
        println!("{} {} 1 {} 0 0",n+1,(n+1)*(n+1)-s,n+1)
    }
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

string s;
lli k;

int main(){
  cin >> s;
  k = s.size();
  for(lli i = 0;i < s.size()-1;i++){
    if(s[i] != s[i+1]) k = min(k,max(i+1,(lli)s.size()-i-1));
  }
  cout << k << endl;
  return 0;
}


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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

ofstream outfile;
ifstream infile;
int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	lli n, t, gc, arr[200];
	cin >> n;

	for(lli i = 1; i <= n; ++i){
		cin >> arr[i];
	}

	gc = arr[1];

	for(lli i = 2; i <= n; ++i){
		t = __gcd(arr[i], gc);
		gc = gc/t;
		gc *= arr[i];
	}

	cout << gc << "\n";
}

Measured memory_bytes: 256
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
    var n = o.a();
    var k = o.a();
    var s = o.a(1);
    var a = [];
    var x = s[0], y = 1;
    if(x == 0)a.push(0);
    for(var i = 1; i < s.length; i++){
        if(x === s[i])y++;
        else{
            a.push(y);
            y = 1;
            x = s[i];
        }
    }
    a.push(y);
    if(a.length % 2 === 0)a.push(0);
    var z = k*2+1;
    if(a.length <= z)return n;
    var ans = 0;
    for(i = 0; i < z; i++)ans += a[i];
    var mx = ans;
    for(i = z+1; i < a.length; i += 2){
        mx += a[i]+a[i-1]-a[i-z]-a[i-z-1];
        if(ans < mx)ans = mx;
    }
    return ans;
}

Measured memory_bytes: 9676
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); 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 repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<int>cnt(n); rep(i, n)cnt[i] = 1;
	vector<bool>red(n); red[0] = true;
	vector<int>x(m), y(m);
	rep(i, m) {
		cin >> x[i] >> y[i]; x[i]--; y[i]--;
		if (red[x[i]])red[y[i]] = true;
		cnt[x[i]]--; cnt[y[i]]++;
		if (cnt[x[i]] == 0) red[x[i]] = false;
	}
	int ans = 0;
	rep(i, n) {
		if (red[i] && cnt[i] != 0) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2688
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int days = sc.nextInt();
        int n = sc.nextInt();
        
        for (int i = 0; i < n; i++) {
            days -= sc.nextInt();
            if (days < 0) {
                days = -1;
                break;
            }
        }
        
        System.out.println(days);
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1000000000 + 7;
const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

vector<vector<int>> ans;

void dfs(int nokori, int h, vector<int> &num) {
    if (nokori == 0) {
        ans.push_back(num);
        return;
    }
    rrep2(i, h, 0) {
        if (nokori < i) continue;
        num.push_back(i);
        dfs(nokori - i, i, num);
        num.pop_back();
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<int> num;
        ans.clear();
        dfs(n, n, num);
        rep(i, ans.size()) {
            rep(j, ans[i].size()) {
                if (ans[i].size() - 1 == j) cout << ans[i][j] << endl;
                else cout << ans[i][j] << " ";
            }
        }
    }

}

Measured memory_bytes: 3456
#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()
{
    string s;
    cin >> s;
    if (s[1] == 'B') s[1] = 'R';
    else s[1] = 'B';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;

int l[8];
int n,a,b,c;

int commin(int m,int k[8]){
    //cout<<m<<" ";
    //for(int i=0;i<m;i++)cout<<k[i]<<" ";
    //cout<<endl;
    int rec=INF;
    for(int s=0;s<m;s++){
        for(int t=0;t<m;t++){
            if(s==t)continue;
            for(int v=0;v<m;v++){
                if(v==t||v==s)continue;
                rec=min(rec,(n-m)*10+abs(k[s]-a)+abs(k[t]-b)+abs(k[v]-c));
            }
        }
    }
    if(m>3){
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){
                k[i]+=k[j];
                int memo=k[j];
                k[j]=k[m-1];
                rec=min(rec,commin(m-1,k));
                k[i]-=memo;
                k[j]=memo;
            }
        }
    }
    return rec;
}
signed main(){
    cin>>n>>a>>b>>c;
    for(int i=0;i<n;i++)cin>>l[i];
    cout<<commin(n,l)<<endl;
    return 0;
}
        


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

#define ll long long int
const int N=1e5+5;
#define pi pair<int,int>

vector<vector<pi> > graph;
vector<int> vis,col;
int n,m,diff=0;

void dfs(int node,int par=0){
    vis[node] = 1;
    for(auto it:graph[node]){
        if(it.first == par)
            continue;
        else if(vis[it.first]==0)
            dfs(it.first,node);
    }
}

int main(){
    cin >> n >> m;
    graph.resize(n+1);
    vis.resize(n+1);
    fill(vis.begin(),vis.end(),0);
    for(int i=0;i<m;i++){
        int x,y,z;
        cin >> x >> y >> z;
        graph[x].push_back(make_pair(y,z));
        graph[y].push_back(make_pair(x,z));
    }

    for(int i=1;i<=n;i++){
        if(vis[i] == 0){
            dfs(i);
            diff += 1;    
        }
    }
    cout << diff << '\n';

    return 0;
}

Measured memory_bytes: 10752