akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: Make a Rectangle
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", &as[i]);
  sort(as, as + n);

  int k = 0, pa = -1;
  int bs[2];

  for (int i = n - 1; k < 2 && i >= 0; i--) {
    if (pa == as[i]) {
      bs[k++] = pa;
      pa = -1;
    }
    else pa = as[i];
  }

  if (k < 2) puts("0");
  else printf("%lld\n", (ll)bs[0] * bs[1]);

  return 0;
}


Measured memory_bytes: 640
def judge(x: int):
    if x > 0:
        return True
    else:
        return False


if __name__ == "__main__":
    n, k, q = list(map(int, input().split(" ")))
    a = [int(input()) - 1 for i in range(q)]

    participant = [k - q for i in range(n)]

    for i in range(q):
        participant[a[i]] += 1

    participant = list(map(judge, participant))

    for i in range(n):
        if participant[i]:
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 11828
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  vector<int> a(n, -1);
  rep (i, m) {
    int p, q;
    cin >> p >> q;
    --p;
    if (a[p] != -1 && a[p] != q || p == 0 && q == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    a[p] = q;
  }

  for (int i = 0; i < n; i++) {
    if (i == 0 && a[i] == -1 && n != 1) {
      a[i] = 1;
    }
    if (a[i] == -1) {
      a[i] = 0;
    }
  }

  for (auto v : a) cout << v;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3600
A,B,N = list(map(int , input().split()))

if N>B:
    x = B -1
else:
    x = N
D = []

if N > 20:
    w = N % 15 + 5
elif N > 4:
    w = N-1
else:
    w = N
for i in range(w):
    F1 = (A*(x-i))//B
    F2 = A * ((x-i)//B)
    S = F1 - F2
    D.append(S)

ans = max(D)
print(ans)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;



int main(){

    int N;
    cin >> N;

    vector <int> X(N), Y(N);
    for (int i = 0; i < N; i++){
        cin >> X[i];
        Y[i] = X[i];
    }

    sort(Y.begin(), Y.end());
    int a = Y[N / 2 - 1];
    int b = Y[N / 2];

    for (int i = 0; i < N; i++){
        if (X[i] <= a){
            cout << b << endl;
        }else{
            cout << a << endl;
        }
    }
    
    return 0;
}

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

int howmany(int n){
  int count = 0;
  for(int i = 1; i <= n; i++){
    if(n % i == 0) count++;
  }
  return count;
}

int main() {
  int n, ans = 0;
  cin >> n;
  
  for(int i = 1; i <= n; i += 2){
    if(howmany(i) == 8) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    int n; cin >> n;
    ll a[3*n];
    ll l[n+1],r[n+1];
    rep(i,3*n) cin >> a[i];
    priority_queue<ll> pq;
    priority_queue<ll,vector<ll>,greater<ll>> pq2;
    ll sum=0;
    rep(i,n){
        pq2.push(a[i]);
        sum+=a[i];
    }
    l[0]=sum;
    rep(i,n){
        pq2.push(a[n+i]);
        sum+=a[n+i];
        sum-=pq2.top(); pq2.pop();
        l[i+1]=sum;
    }
    sum=0;
    rep(i,n){
        pq.push(a[3*n-1-i]);
        sum+=a[3*n-1-i];
    }
    r[0]=sum;
    rep(i,n){
        pq.push(a[2*n-1-i]);
        sum+=a[2*n-1-i];
        sum-=pq.top(); pq.pop();
        r[i+1]=sum;
    }
    ll ans=l[0]-r[n];
    //rep(i,n) cout << l[i] << " " << r[n-i] << endl;
    for(int i=1;i<=n;i++){
        chmax(ans,l[i]-r[n-i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6388
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let mut ans = 0;
    for _i in 0..n {
        let l: i32 = sc.read();
        let r: i32 = sc.read();
        ans += r - l + 1;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void) {
	int a, b, d;
	while (scanf("%d %d", &a, &b) != EOF) {
		d = 1;
		a += b;
		while ((a /= 10) > 0) d++;
		printf("%d\n", d);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
template<typename T> class Dijkstra {
public:
	struct edge{
		int to; T cost;
	};
	int V;
	vector<vector<edge> > G;
	vector<T> d;
	using pti = pair<T,int>;
	Dijkstra(int node_size) : V(node_size), G(V), d(V, numeric_limits<T>::max()){}
	//無向グラフの場合
	void add_edge(int u,int v,T cost){
		G[u].push_back((edge){v,cost}),G[v].push_back((edge){u,cost});
	}
	void solve(int s){
		priority_queue<pti,vector<pti>,greater<pti> > que;
		d[s] = 0;
		que.push(pti(0,s));
		while(!que.empty()){
			pti p = que.top();
			que.pop();
			int v = p.second;
			if(d[v] < p.first) continue;
			for(auto& w : G[v]){
				if(d[w.to] > d[v] + w.cost){
					d[w.to] = d[v] + w.cost;
					que.push(pti(d[w.to],w.to));
				}
			}
		}
	}
};

int main(){
    int n,m;
    int s,t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    Dijkstra<ll> d1(n),d2(n);
    for(int i=0;i<m;i++){
        ll u,v,a,b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        d1.add_edge(u,v,a);
        d2.add_edge(u,v,b);
    }
    d1.solve(s);
    d2.solve(t);
    vector<ll> p(n);
    for(int i=0;i<n;i++){
        p[i] = d1.d[i] + d2.d[i];
    }
    for(int i=n-2;i>=0;i--){
        p[i] = min(p[i],p[i+1]);
    }
    ll ans = (ll)1000000000000000;
    for(int i=0;i<n;i++){
        cout << ans-p[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19012
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	
	string s;
	cin >> s;
	int cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1')cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int divide(int a){
    vector<int> ans;
    for(int j=1; j*j<=a; j++){
        if(a%j==0) {ans.emplace_back(j);
        if((j*j)!=a) {
            ans.emplace_back(a/j);
        } 
        }
    }
    return ans.size();
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int ans=0;
    for(int i=1; i<=n; i=i+2){
        if(divide(i)==8) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int c;
	scanf("%d",&c);
	int a[c];
	int number=0;
 	for(int i=0; i<c; i++)	
	 	scanf("%d",&a[i]);
	for(int k=1; k+1<c; k++)
	{
		if((a[k-1]<a[k]&&a[k]<a[k+1]) or (a[k-1]>a[k]&&a[k]>a[k+1]))
			number++;
	}
	printf("%d\n",number);
	system("pause");
	return 0;
}

Measured memory_bytes: 376
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 14, 2020 09:24:45 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = sorted(list(map(int, input().split())))

  div = 1
  ans = 0
  for i in range(N-1, 0, -1):
    div *= 2
    ans += (A[i] / div)
  ans += (A[0] / div)
  print(ans)


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


Measured memory_bytes: 64968
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    ll cnt = 0;
    for (int r = 0; r <= N; r++) {
        for (int g = 0; g <= N; g++) {
            if ((N - r * R - g * G) % B == 0) {
                int b = (N - r * R - g * G) / B;
                if (b >= 0 && b <= N)
                    cnt++;
            }
        }
    }

    cout << cnt << endl;
}

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

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;

int main() {
    std::ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;

    std::cout << (S.size()>=4 && S.substr(0,4)=="YAKI" ?"Yes":"No") << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n,m;
  cin>>n>>m;
  npairs(long,int,a,n);
  sort(all(a));
  long cost=0;
  int k=0;
  FOR(i,n){
    k+=a[i].second;
    cost+=a[i].first*a[i].second;
    if(k>=m){
      cost-=a[i].first*(k-m);
      break;
    }
  }
  cout<<cost;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
  int n, k, p, r;
  cin >> n >> k;
  ll ans = 0;
  for (int b = 1; b <= n; b++) {
    p = n / b; r = n % b;
    ans += p * max(0, b-k);
    ans += max(0,r-k+1);
  }
  if (k == 0) ans -= n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RANGE(i, x, n) for(ll i = x; i < n; ++i)

using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 50;
ll C[MAXN+1][MAXN+1];
void Initial()
{
    int i,j;
    for(i=0; i<=MAXN; ++i)
    {
        C[0][i] = 0;
        C[i][0] = 1;
    }
    for(i=1; i<=MAXN; ++i)
    {
        for(j=1; j<=MAXN; ++j)
            C[i][j] = (C[i-1][j] + C[i-1][j-1]);
    }
}

ll Cm(ll n, ll k)
{
    if(n < k) {
        return 0;
    }else {
        return C[n][k];
    }
}

int main()
{
    Initial();
    int N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N, 0);
    map<ll, ll> nv;
    REP(i, N) {
        cin >> v[i];
        ++nv[v[i]];
    }
    sort(v.begin(), v.end(), greater<ll>());
    double ans;
    ll sum = 0, res = 0;
    ll maxv = v[0];
    ll minv = v[A - 1];
    REP(i, A) {
        sum += v[i];
    }
    if(maxv == minv) {
        ans = (sum + 0.0) / (A + 0.0);
        RANGE(i, A, B + 1) {
            res += Cm(nv[maxv], i);
        }
        printf("%.7lf\n", ans);
        printf("%lld\n", res);
    }else {
        ll p = 0;
        REP(i, A) {
            if(v[i] == minv) {
                ++p;
            }
        }
        ans = (sum + 0.0) / (A + 0.0);
        res = Cm(nv[minv], p);
        printf("%.7lf\n", ans);
        printf("%lld\n", res);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    string s;

    cin>>s;
    int n=s.length();
    if(n&1)
    {
        cout<<"No";return;
    }
    for(int i=0;i<n;i+=2)
    {
       
            if(s[i]!='h'||s[i+1]!='i')
            {
                cout<<"No";return;
            }
        
    }
    cout<<"Yes";
   // cout<<s<<endl;
}

signed main()
{
        noob
         
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1);
    map<int, int> mp;
    priority_queue<pair<int, int>> pq;
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        A[i] = a-1;
        mp[a-1] = i;
        for (int j = 0; j < i-1; j++) {
            pq.push({-a, i});
        }
    }
    vector<int> ans;
    for (int i = 0; i < N*N; i++) {
        if (mp[i] > 0) {
            int t = mp[i];
            ans.push_back(t);
            for (int j = 0; j < N-t; j++) pq.push({-N*N*2, t});
        }else{
            if (pq.empty()) {
                cout << "No" << endl;
                return 0;
            }
            int t = pq.top().second;
            pq.pop();
            ans.push_back(t);
        }
    }
    for (int i = 1; i <= N; i++){
        auto it = ans.begin()+A[i];
        if (count(ans.begin(), it, i) != i-1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (int i = 0; i < N*N; i++) {
        cout << ans[i];
        cout << ((i == N*N-1) ? "\n" : " ");
    }
    return 0;
}


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

//最大公約数を求める

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

int main(){

    int n, x; cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = (int)abs(x - a[0]);
    for(int i = 1; i < n; i++) ans = gcd(ans, (int)abs(x - a[i]));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long V[1 << 18];
long long W[1 << 18];
pair <long long, long long> wv[1 << 9];
int v[100000];
int L[100000];
long long dp[1 << 10][100001];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> V[i] >> W[i];
  }

  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++){
    cin >> v[i] >> L[i];
  }
  int max_L = *max_element(L, L + Q);

  if(W[0] <= max_L){
    for(int i = W[0]; i <= max_L; i++){
      dp[0][i] = V[0];
    }
  }

  for(int i = 1; i < min((1 << 10), N); i++){
    int prev = (i + 1) / 2 - 1;
    for(int j = 0; j <= max_L; j++){
      dp[i][j] = max(dp[i][j], dp[prev][j]);
      if(j >= W[i]){
        dp[i][j] = max(dp[i][j], V[i] + dp[prev][j - W[i]]);
      }
    }
  }

  for(int i = 0; i < Q; i++){
    int cur_v = v[i];
    long long cur_L = L[i];
    if(cur_v <= (1 << 10)){
      cout << dp[cur_v - 1][cur_L] << endl;
    } else {
      int wv_size = 0;
      while(true){
        wv[wv_size] = make_pair(W[cur_v - 1], V[cur_v - 1]);
        wv_size ++;
        cur_v /= 2;
        if(cur_v <= (1 << 10)){
          break;
        } 
      }

      long long res = 0;
      for(int bit_set = 0; bit_set < (1 << wv_size); bit_set++){
        long long sw = 0;
        long long sv = 0;
        for(int j = 0; j < wv_size; j++){
          if(((bit_set >> j) & 1) == 1){
            sw += wv[j].first;
            sv += wv[j].second;
          }
        }
        if(sw <= cur_L){
          res = max(res, sv + dp[cur_v - 1][cur_L - sw]);
        }
      }
      cout << res << endl;
    }
  }
  
  return 0;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

int main(void)
{
	li n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<li> zero_one;
	zero_one.push_back(0);
	zero_one.push_back(0);
	li now = 1;
	li now_num = 0;
	rep(i, n) {
		if (s[i] - '0' == now) {
			now_num++;
		} else {
			zero_one.push_back(now_num);
			now_num = 1;
			now = 1 - now;
		}
	}
	zero_one.push_back(now_num);
	if (k == 0) {
		li res = 0;
		for (li i = 0; i < zero_one.size(); i += 2) {
			res = max(res, zero_one[i]);
		}
		cout << res << endl;
		return 0;
	}
	if (zero_one.size() - 2 < k * 2) {
		cout << n << endl;
		return 0;
	}
	li tres = 0;
	rep(i, k * 2 + 1) {
		tres += zero_one[i];
	}

	//for (auto item : zero_one)cout << item << " "; cout << endl;

	li res = tres;
	for (li i = k * 2 + 2; i < zero_one.size(); i += 2) {
		tres -= zero_one[i - k * 2 - 1];
		tres -= zero_one[i - k * 2 - 2];
		tres += zero_one[i - 1];
		tres += zero_one[i];
		/*
		cout << i << " "
		     << zero_one[i - k * 2 - 2] << " "
		     << zero_one[i - k * 2 - 1] << " "
		     << zero_one[i - 1] << " "
		     << zero_one[i ] << " "
		     << res << endl;
		     */
		res = max(res, tres);
		if (i == zero_one.size() - 2) {
			tres -= zero_one[i - k * 2];
			tres -= zero_one[i - k * 2 + 1];
			tres += zero_one[i + 1];
			res = max(res, tres);
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1528
#include<stdio.h>
#define N 500000
int temp[N],c=0;
int main();
void MergeSort(int x[],int left,int right){
  int mid,i,j,k;
  if(left<right){
      mid=(left+right)/2;
      MergeSort(x,left,mid);
      MergeSort(x,mid+1,right);

      for(i=mid;i>=left;i--){
	temp[i]=x[i];
      }
      for(j=mid;j<=right;j++){
	temp[right-(j-(mid+1))]=x[j];}
      i=left;j=right;
      for(k=left;k<=right;k++){
	if(temp[i]<=temp[j])
	  x[k]=temp[i++];
	else x[k]=temp[j--];
c++;
}
}
}
int main(){
  int i,k,x[N];
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&x[i]);}
    MergeSort(x,0,k-1);
    for(i=0;i<k;i++){
if(i>0)printf(" ");      
 printf("%d",x[i]);

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

      



Measured memory_bytes: 5608
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for L in range(min(N, K+1)):
    for R in range(min(N-L, K-L)+1):
        js = V[:L] + V[-R:] if R > 0 else V[:L]
        t = K - L - R
        s = 0
        for i in sorted(js):
            if i < 0 and t > 0:
                s += -i
                t -= 1
        ans = max(ans, sum(js) + s)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int photo[100][100];
int pict[50][50];

int n, m;

void rot() {
  int tmp[50][50];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      tmp[i][j] = pict[i][j];
    }
  }

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      //printf("%d", tmp[m - j -1][i]);
      pict[i][j] = tmp[m - j - 1][i];
    }
    //printf("\n");
  }
}

bool ans(int I, int J)
{
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (pict[i][j] != -1 && photo[I + i][J + j] != pict[i][j]) {return false;}
    }
  }
  return true;
}

void printans(int I, int J)
{
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (pict[i][j] != -1) {
	printf("%d %d\n", j + J + 1, i + I + 1);
	return;
      }
    }
  }
}

int main()
{
  while (scanf("%d %d ", &n, &m) == 2) {
    if (n == 0 && m == 0) {
      break;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
	scanf("%d ", &photo[i][j]);
      }
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
	scanf("%d ", &pict[i][j]);
      }
    }
    
    /*    for (int i = 0; i < n; i++) {
	  for (int j = 0; j < n; j++) {
	  printf("%d", photo[i][j]);
	  }
	  printf("\n");
	  }*/
    /*    for (int i = 0; i < m; i++) {
	  for (int j = 0; j < m; j++) {
	  printf("%d", pict[i][j]);
	  }
	  printf("\n");
	  }
	  rot();
	  for (int i = 0; i < m; i++) {
	  for (int j = 0; j < m; j++) {
	  printf("%d", pict[i][j]);
	  }
	  printf("\n");
	  }*/
    
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
	if (i + m - 1 < n && j + m - 1 < n) {
	    for (int k = 0; k < 4; k++) {
	      if (ans(i, j)) {
		printans(i, j);
		goto next;
	      }
	      rot();
	    }
	  }
      }
    }  
    printf("NA\n");
    next:;
    }
  }

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string ans;
  int Q;
  cin >> ans >> Q;
  bool rev = false;
  int cnt = 0;
  int L = ans.length();

  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      rev ^= 1;
      cnt++;
      continue;
    }

    if (t == 2) {
      if (ans.length() == L && rev == 1) {
        reverse(ans.begin(), ans.end());
        rev = 0;
      }
      int f;
      string c;
      cin >> f >> c;

      if (f == 1) {
        if (rev == false) {
          ans.insert(0, c);
        } else {
          ans += c;
        }
      } else if (f == 2) {
        if (rev == false) {
          ans += c;
        } else {
          ans.insert(0, c);
        }
      }
    }
  }

  if (ans.length() == L && rev == 1) {
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
  }

  if (!rev) {
    cout << ans << endl;
  } else if (rev == 1) {
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 912
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> a(N);
	vector<Int> b(N);
	vector<Int> c(N);

	Int temp;
	for (Int i = 0; i < N; i++) {
		cin >> temp;
		temp--;//0-indexed
		a[i] = temp;
	}
	for (Int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (Int i = 0; i < N-1; i++) {
		cin >> c[i];
	}

	Int ans = 0;
	for (Int i = 0; i < N; i++) {
		temp = a[i];
		ans += b[temp];
		if (i + 1 < N && a[i + 1] == temp + 1) {
			ans += c[temp];
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 610000;
const int K = 19;
const int mod = 1e9 + 7;
int f[N], invf[N], inv2, inv3, a[N], b[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int s1 = 0;
    int s2 = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        s1 += a[i];
    }
    for (int i = 1; i <= n; i++){
        cin >> b[i];
        s2 += b[i];
    }
    if (s1 < s2){
        cout << -1;
        return 0;
    }
    multiset < int > s;
    for (int i = 1; i <= n; i++){
        if (a[i] > b[i]) s.insert(-a[i] + b[i]);
    }
    int x = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        if (a[i] < b[i]){
            ans++;
            int d = b[i] - a[i];
            while(d > x){
                d -= x;
                ans++;
                x = -*s.begin();
                s.erase(s.begin());
            }
            x -= d;
        }
    }
    cout << ans;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	REP(i,k){
		VI s(n,0);
		REP(j,n){
			int l=j-a[j], r=j+a[j]+1;
			s[max(l,0)]++;
			if(r<=n-1)
				s[r]--;
		}
		int p=0;
		bool f=1;
		REP(j,n){
			p+=s[j];
			a[j]=p;
			if(p!=n)
				f=0;
		}
		if(f)
			break;
	}
	REP(i,n)
		cout << a[i] << ' ';
	cout << endl;
	return 0;
}

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

#define MOD 1000000007

int main(){
  int n,count,maxi = 1;
  cin >> n;
  vector<int> da(n),db(n);
  for(int i = 0;i < n;i++){
    cin >> da[i];
    cin >> db[i];
  }
  count = 0;
  for(int i = 0;i < n;i++){
    if(da[i] == db[i])count++;
    else count = 0;
    maxi = max(maxi,count);
  }
  if(3 <= maxi)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int c0=0 ,c1=0,c2=0,c3=0 ,n ;
    cin >> n ;
    string arr[n] ;
    for(int i=0 ; i<n ; i++){
        cin>> arr[i] ;
        if (arr[i]=="AC")
           c0=c0+1 ;
        else if(arr[i]=="WA")
            c1=c1+1 ;
        else if (arr[i]=="TLE")
            c2=c2+1 ;
        else if (arr[i]== "RE")
            c3=c3+1 ;

    }
    cout<< "AC x "<< c0 << endl ;
    cout << "WA x "<< c1 << endl ;
    cout << "TLE x "<< c2 << endl ;
    cout << "RE x "<< c3 << endl ;
    return 0;
}


Measured memory_bytes: 6724
#include<cstdio>
#include<algorithm>
#define MN 1111
using namespace std;

int mmh=1e9;
char s[MN];
int main(){
	scanf("%s",s);
	for (int i='a';i<='z';i++){
		int la=-1,ans=0,j;
		for (j=0;s[j];j++)
		if (s[j]==i){
			if (ans<j-la-1) ans=j-la-1;
			la=j;
		}
		if (ans<j-la-1) ans=j-la-1;
		if (mmh>ans) mmh=ans;
	}
	printf("%d\n",mmh);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
struct drink
{
	long long sl,dj;
};
bool cmp(drink x,drink y)
{
	return x.dj<y.dj;
}
int main()
{
long long n,m,ans=0;
cin>>n>>m;
drink drinks[n+2];
for(int i=0;i<n;i++)
{
	cin>>drinks[i].dj>>drinks[i].sl;
}
sort(drinks,drinks+n,cmp);
for(int i=0;m>=0;i++)
{
	if(m>=drinks[i].sl)
	{
		ans+=drinks[i].dj*drinks[i].sl;
		m-=drinks[i].sl;
	}
	else
	{
		ans+=drinks[i].dj*m;
        m=0;
		cout<<ans<<endl; 
		return 0;
	}
}
cout<<ans<<endl;
}

Measured memory_bytes: 1792
import itertools
import math

k = int(input())
l = []
for i in range(1,k+1):
    l.append(i)
    
    
a = list(itertools.combinations(l, 3))
ans = 0
for i in range(len(a)):
    b = math.gcd( math.gcd(a[i][0],a[i][1]), a[i][2])
    ans += b
c = list(itertools.combinations(l, 2))

for i in range(len(c)):
    d = math.gcd(c[i][0], c[i][1])
    ans += d
ans = ans * 6
e = sum(l)
print(ans+e)

Measured memory_bytes: 103960
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int T;
    cin >> n >> T;
    
    int t[n];
    rep(i, n)   cin >> t[i];
    
    int dp[n - 1];
    rep(i, n - 1){
        dp[i] = t[i + 1] - t[i];
    }
    ll sum = 0;
    rep(i, n - 1){
        if(dp[i] < T){
            sum += dp[i];
        }else{
            sum += T;
        }
    }
    sum += T;
    cout << sum << endl;
}

Measured memory_bytes: 1792
import numpy as np
N = int(input())
opengrid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    opengrid.append(array)
benefit = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    benefit.append(array)
i = 1
st = []
while i <= 1023:
  x = bin(i)[2:]
  y = '0'*(10-len(x))+x
  z = []
  for chara in y:
    z.append(int(chara))
  st.append(z)
  i += 1
maxx = -99999999999
for pat in st:
  j = 0
  ans = 0
  while j < N:
    v1 = np.array(pat)
    v2 = np.array(opengrid[j])
    x = np.dot(v1,v2)
    ans += benefit[j][x]
    j += 1
  maxx = max(maxx,ans)
print(maxx)

Measured memory_bytes: 13788
import math
n = int(input())


cnt=0
for i in range(2,int(math.sqrt(n))+1):
    
    if (n-1)%i==0:
       
        
        cnt=cnt+2
    if (n)%i==0:
        s=n
        while s%i==0:
            s=s//i
        if s%i==1:
            
            cnt=cnt+1
if int(math.sqrt(n-1)) == math.sqrt(n-1):
    
    cnt=cnt-1

if n==2:
    print(1)
else:
    print(cnt+2)
        

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

int main(){

int N, M;
cin >> N >> M;
vector<int>X(M);

	if(M == 1){
      	cout << 0 << endl;
    	return 0;
  }
  
int ma = -20000;
int mi = 20000;
for(int i = 0; i < M; i++){ 
      cin >> X.at(i);
      ma = max(ma, X.at(i));
      mi = min(mi, X.at(i));
}

 
sort(X.begin(), X.end());


vector<int>de(M - 1);

for(int i = 0; i < M - 1; i++){

      de.at(i) =abs(X.at(i + 1) - X.at(i)); 

}

sort(de.begin(), de.end());
reverse(de.begin(), de.end());

int sum = 0;

for(int i = 0; i < min(N - 1, M - 1); i++){ 
      sum += de.at(i);
 
}

 
int ans = abs(ma - mi) - sum;

cout << ans << endl; 
}

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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;
#define sorti(x) sort(x.begin(), x.end())

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  vector<ll> p(n);

  ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
  rep(i,n) {
    cin >> p[i];
    if (p[i] > b) {
      cnt1++;
    } else if (p[i] > a and p[i] <= b) {
      cnt2++;
    } else {
      cnt3++;
    }
  }

  cout << min(min(cnt1,cnt2), cnt3) << endl;
}

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

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n;

int main() {
	cin >> n;
	cont (i, n) {
		cout << "ACL";
	}
	cout << ln;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int L;
int main()
{
	L=gi();
	double a=L*1./3;
	printf("%.10lf\n",a*a*a);
	return 0;
}


Measured memory_bytes: 256
import sys 
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 10 ** 9 +7
N, K = map(int, readline().split())
# s = [0] * (N+1)
# g = [0] * (N+1)
# g[0] = N % mod
# for i in range(1,N+1):
#     s[i] += (s[i-1] + i ) % mod
#     g[i] += (g[i-1] + N - i) % mod
# ans = (sum(g[K-1:]) % mod  - sum(s[K-1:]) % mod + N-K+2) % mod
# print(ans)
k = np.arange(K,N+2,dtype = np.int64)
low = k*(k-1)//2
high = k*(2*N - k + 1) //2
cnt = high-low+1
print(sum(cnt)%mod)

Measured memory_bytes: 33280
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 10000

int main()
{
  int i, j;
  int n, q;
  int nl[N], s;
  int count = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      scanf("%d", &nl[i]);
    }

  scanf("%d", &q);
  for(i = 0; i < q; i++)
    {
      scanf("%d", &s);
      for(j = 0; j < n; j++)
	{
	  if(s == nl[j]) 
	    {
	      count++;
	      break;
	    }
	}
    }
  printf("%d\n", count);

  return 0;
}

Measured memory_bytes: 636
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
long long w[N_], K, m, T[N_], U[N_];
int n, P;
bool OK(int pv) {
	int i, cnt = 0;
	for (i = 1; i <= n; i++) {
		if (i != pv)T[++cnt] = w[i];
	}
	long long z = w[pv] + m;
	long long rem = (K - 1)*m;
	for (i = 1; i <= cnt; i++) {
		long long t;
		if (z >= T[i]) {
			t = min(min(rem, z - T[i]), m);
		}
		else {
			t = min(rem, m);
		}
		rem -= t;
		U[i] = t;
		T[i] += t;
	}
	for (i = cnt; i >= 1 && rem; i--) {
		long long t;
		if (z >= T[i]) {
			t = min(rem, m - U[i]);
			T[i] += t;
			U[i] += t;
			rem -= t;
		}
	}
	int r = 1;
	for (i = 1; i <= cnt; i++) {
		if (T[i] > z)r++;
	}
	return r <= P;

}
int main() {
	int i;
	scanf("%d%lld%lld%d", &n, &m, &K, &P);
	for (i = 1; i <= n; i++) {
		scanf("%lld", &w[i]);
	}
	sort(w + 1, w + n + 1);
	int b = 1, e = n, mid, r=0;
	while (b <= e) {
		mid = (b + e) >> 1;
		if (OK(mid)) {
			r = mid;
			e = mid - 1;
		}
		else b = mid + 1;
	}
	printf("%d\n", n - r + 1);
}

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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int n,r;
	cin>>n>>r;
	cout << r + (100 * max(0,10 - n)) << '\n';
}


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

int need(char c){
	if(c == 'a'){
		return 0;
	}
	else{
		return 'a' + 26 - c;
	}
}

int main(){
	int i, K;
	string s;
	cin >> s;
	scanf("%d", &K);
	for(i = 0; i < s.size(); i++){
		if(need(s[i]) <= K){
			K -= need(s[i]);
			s[i] = 'a';
		}
	}
	K %= 26;
	while(K > 0){
		K--;
		s[s.size() - 1]++;
		if(s[s.size() - 1] > 'z'){
			s[s.size() - 1] = 'a';
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define INF (1e17)
#define N 100005
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll n,m,x,h[N];
vector<P> G[N];
priority_queue<P,vector<P>,greater<P> > q;
ll d[N];

ll dijkstra(){

  for(int i=0;i<n;i++)d[i]=INF;
  q.push(P(0,0));
  d[0]=0;
  
  while(!q.empty()){
    P t=q.top(); q.pop();
    ll cost=t.first,node=t.second;

    if(node==n-1)return cost+max(cost-x+h[n-1],0LL);
    if(d[node]<cost)continue;
    
    for(int i=0;i<G[node].size();i++){
      ll nnode=G[node][i].first;
      ll ncost=cost+G[node][i].second;
      
      if(x-ncost>=h[nnode])
	ncost+=x-ncost-h[nnode];
      if(d[nnode]>ncost){
	d[nnode]=ncost;
	q.push(P(ncost,nnode));
      }
    }
  }
  
  return INF;
}

int main(){
  
  cin>>n>>m>>x;
  
  for(int i=0;i<n;i++)scanf("%lld",&h[i]);

  ll a,b,c;
  for(int i=0;i<m;i++){
    scanf("%lld%lld%lld",&a,&b,&c);
    a--,b--;
    if(h[a]-c>=0)G[a].push_back(P(b,c));
    if(h[b]-c>=0)G[b].push_back(P(a,c));
  }

  ll ans=dijkstra();
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}

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

vector<pair<int,int>> query[200002];

const int n = 1<<18;
ll ma[n*2], lazy[n*2];
void add(int i, ll v) {
  for (i += n; i > 1; i >>= 1) {
    if (i&1)
      lazy[i-1] += v;
    ma[i>>1] = max(ma[i]+lazy[i],ma[i^1]+lazy[i^1]);
  }
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int l, r, a;
    cin >> l >> r >> a;
    r++;
    query[l].emplace_back(l,a);
    query[r].emplace_back(l,-a);
  }
  ll off = 1e15;
  ll ans = 0;
  add(1,off);
  for (int i = 1; i <= n; i++) {
    for (auto p : query[i])
      add(p.first, p.second);
    ll score = ma[1];
    ans = max(ans, score-off);
    add(i+1, score);
    add(i  ,-score);
  }
  cout << ans << endl;
}


Measured memory_bytes: 17664
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var people = ToInt32(ReadLine());
        var input = ReadLine().Split(' ');
        var day = ToInt32(input[0]);
        var result = ToInt32(input[1]);
        for(var i = 0; i < people; i++)
        {
            var bet = ToInt32(ReadLine());
            result += 1 + (day-1) / bet;
        }
        WriteLine(result);
    }
}



Measured memory_bytes: 11220
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
#define int long long
int flag[100010];
signed main(){
    ll n,x,m;
    cin >> n >> x >> m;
    vector<ll>a;
    a.push_back(x);
    flag[x] = 1;
    ll res = 0;
    res += x;
    bool fff = 0;
    ll S = -1;
    rep(i,200000){
        ll p = a[i]*a[i]%m;
        if(p==0)fff = 1;
        if(flag[p]!=0){
            S = flag[p];
            break;
        }
        a.push_back(p);
        flag[p] = i+2;
        res += p;
    }
    int mm = a.size();
    if(!fff){
        ll ans = 0;
        vector<ll> b;
        ll sm = 0;
        ll c = 0;
        for(int i=S-1;i<mm;i++){
            b.push_back(a[i]);
            sm += a[i];
            c++;
            // cerr << b.back()<< " ";
        }
        // cerr << endl;
        for(int i=0;i<min(n,S-1);i++){
            ans += a[i];
        }
        n -= min(n,S-1);
        // cerr << S << endl;
        // cerr << n << " "<< ans << endl;
        ans += sm * (n/c);
        // cerr << n/c << " " << n%c << endl;
        rep(i,n%c){
            ans += b[i];
        }
        cout << ans << endl;
    }else{
        ll ans = 0;
        if(n < mm){
            for(int i=0;i<n;i++){
                ans += a[i];
            }
        }else{
            ans = res;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5012
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, K = MI()
    original = input()
    num_happy = 0

    for i in range(N - 1):
        if original[i] == original[i+1]:
            num_happy += 1

    print(min(N-1, num_happy + 2 * K))


main()


Measured memory_bytes: 71404
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=2e5+100;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
int A[maxn];
int T,n,m,k;
 
int main()
{
    cin>>n>>k;
    LL res=1,sign=1;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    sort(A+1,A+1+n);
    int l=1,r=n;
    if(k&1)
    {
        res*=A[r--];
        k--;
        if(res<0) sign=-1;
    }
    while(k>0)
    {
        if(1LL*A[l]*A[l+1]*sign>1LL*sign*A[r]*A[r-1])
        {
            res=1LL*A[l]*A[l+1]%mod*res%mod;
            l+=2;
        }
        else
        {
            res=1LL*A[r]*A[r-1]%mod*res%mod;
            r-=2;
        }
        k-=2;
    }
    cout<<(res+mod)%mod<<endl;
}

Measured memory_bytes: 4328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		int len = s.length();
		int pos = 0;
		boolean y = false;
		
		for(int i=0; i<len; i++){
			if(s.charAt(i) == 'C'){
				pos = i;
				y = true;
				break;
			}
		}
		
		if(y){
			y = false;
			for(int i= pos; i<len; i++){
				if(s.charAt(i) == 'F'){
					y = true;
					break;
				}
			}
		}
		if(y){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 10064
#include<stdio.h>
int main(){
  int n,m,i,max,k,j,z;
  char p,w;
  while(1){
    scanf("%d %d%c",&n,&m,&w);
    if(n==0&&m==0)break;
    char c[101]={0};
    for(i=0;i<m;i++){
      scanf("%c%c",&p,&w);//printf("%c",p);
      if(p=='A'){
	for(j=0;j<n;j++){
	  if(c[j]==0){
	    c[j]='A';
	    break;
	  }
	}
      }
      if(p=='B'){
	for(j=n-1;j>-1;j--){
	  if(c[j]==0&&c[j+1]!='A'&&c[j-1]!='A'){
	    c[j]='B';
	    break;  
	  }
	}
	if(j==-1){
	  for(j=0;j<n;j++){
	    if(c[j]==0){
	      c[j]='B';
	      break;
	    }
	  }
	}
      }
      if(p=='C'){
	if(i==0){
	  c[(n-(n%2))/2]='C';
	}
	else{
	  j=0;
	  while(1){
	    for(;c[j]==0;j++);
	    if(c[j+1]==0&&j+1<n){
	      c[j+1]='C';
	      break;
	    }
	    if(c[j-1]==0&&j>0){//printf("%d",j);
	      c[j-1]='C';
	      break;
	    }
	    j++;
	  }
	}
      }
      if(p=='D'){
	if(i==0)c[0]='D';
	else{
	  z=0;
	  max=0;
	  for(j=0;j<n;j++){
	    if(c[j]!=0)continue;
	    for(k=1;k<n;k++){
	      if(j-k>-1){
		if(c[j-k]!=0)break;
	      }
	      if(j+k<n){
		if(c[j+k]!=0)break;
	      }
	    }
	    if(max<k){
	      max=k;
	      z=j;
	    }
	  }
	  c[z]='D';
	}
      }
    }
    for(i=0;i<n;i++){
      if(c[i]==0)printf("#");
      else       printf("%c",c[i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572