akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

string s;

void solve() {
    cin >> s;
    int n = s.size();
	int ans = 0;
	int j = 0;
	char t = '?';
	while(j < n) {
		if(j == n - 1) {
			if(t != s[j]) {
				ans ++; j++;
			} else {
				j ++;
			}
		}
		else if(j == n - 2) {
			if(s[j] != t && s[j] != s[j + 1]) {
				ans += 2; j += 2;
			} else {
				ans += 1; j += 2;
			}
		}
		else if(s[j] != t) {
			ans ++;
			t = s[j];
			j ++;
		}
		else if(s[j] == t) {
			ans += 2;
			t = s[j + 2];
			j += 3;
		}
	}
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

using namespace std;

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

#define pb push_back
#define endl '\n'

///(Moan) ey (hoe) pakhi jeno (Oral) dibe <3

void fuck()
{
    string s;
    int i, flag=1;
    cin>>s;
    for(i=0; i<=2; i++){
        if(s[i]==s[i+1]){
            flag=0;
            break;
        }
    }
    if(flag==1)
        cout<<"Good"<<endl;
    else
        cout<<"Bad"<<endl;
}

int main()

{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    fuck();

    return 0;
}


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

int main(void){
	char w[101][11], dummy[11];
	int n, i, j;

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

	for(i = 0; i<n; i++){
		strcpy(dummy, w[i]);
		for(j = i+1; j<n; j++){
			// printf("%s : %s : %d : %d\n", dummy, w[j], i, j);
			if(strcmp(dummy, w[j]) == 0){
				printf("No\n");
				exit(0);
			}
		}
	}

	for(i = 0; i<n-1; i++){
		for(j = 0; j<11; j++){
			if(w[i][j] == '\0'){
				// printf("find : %d\n", j);
				dummy[0] = w[i][j-1];
				break;
			}
		}
		if(dummy[0] != w[i+1][0]){
			// printf("%c : %c\n", dummy[0], w[i+1][0]);
			printf("No\n");
			exit(0);
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double
#define mid (l+r)/2
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int maxn=100005;
double dis(pdd a,pdd b)
{
    return sqrt((a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se));
}
pdd add(pdd a,pdd b)
{
    a.fi+=b.fi;
    a.se+=b.se;
    return a;
}
pdd sub(pdd a,pdd b)
{
    a.fi-=b.fi;
    a.se-=b.se;
    return a;
}
pdd fix(pdd X,double d)
{
    double tp=dis(X,pdd(0,0));
    X.fi=X.fi*d/tp;
    X.se=X.se*d/tp;
    return X;
}
int main()
{
    #ifdef local
    freopen("in.txt","r",stdin);
    #endif // local
    pdd a,b;
    cin>>a.fi>>a.se>>b.fi>>b.se;
    pdd A=sub(b,a);
    pdd C=sub(a,b);
    pdd B=pdd(-A.se,A.fi);
    B=fix(B,dis(a,b));
    pdd c=add(b,B);
    pdd d=add(c,C);
    cout<<c.fi<<' '<<c.se<<' '<<d.fi<<' '<<d.se<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int N;
	bool f=false;
	cin >> N;
	rep(i, N){
		cin >> s;
		if (s=="Y")
			f = true;
	}
	cout << (f?"Four":"Three") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<cstdio>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,m;
 cin>>n>>m;
 priority_queue<ll> vec;
 ll a,sum=0,tmp;
 rep(i,0,n){
  cin>>a;
  vec.emplace(a);
 }
 ans=0;
 ll mx;
 while(m>0){
  mx=vec.top();
  vec.pop();
  mx/=2;
  vec.emplace(mx);
  m--;
  //cout<<vec[n-1]<<" "<<m<<endl;
 }
 rep(i,0,n){
  ans+=vec.top();
  vec.pop();
 }
 pr(ans);
return 0;}


Measured memory_bytes: 4292
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numberA = sc.nextInt();
        int numberB = sc.nextInt();
        int numberC = sc.nextInt();

        if(numberA+numberB+numberC >= 22)
          System.out.println("bust");
        else
          System.out.println("win");
    }
}

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

int main(int argc, char const *argv[]) {
  int x1,x2,y1,y2;
  int x3,y3,x4,y4;
  double mx,my;
  cin >> x1 >> y1 >> x2 >> y2;
  mx = x2 - x1;
  my = y2 - y1;
  double nx ,ny;
  nx = -my;
  ny = mx;


  x4 = x1 + nx;
  y4 = y1 + ny ;
  x3 = x2 + nx;
  y3 = y2 + ny ;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


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

using namespace std;

int main()
{
  int A[2][100];

  int N;

  cin >> N;

  for (int ii=0; ii<2; ++ii)
    for (int jj=0; jj<N; ++jj)
      cin >> A[ii][jj];


  A[1][0] += A[0][0];
    
  for (int jj=1; jj<N; ++jj)
    A[0][jj] += A[0][jj-1];

  for (int jj=1; jj<N; ++jj)
    A[1][jj] += max(A[0][jj],A[1][jj-1]);

  std::cout << A[1][N-1] << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int[] nml = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int[,] matrixA = new int[nml[0], nml[1]];
        int[,] matrixB = new int[nml[1], nml[2]];
        for (int i = 0; i < nml[0]; i++)
        {
            int[] inputMatrixA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 0; j < nml[1]; j++)
            {
                matrixA[i, j] = inputMatrixA[j];
            }
        }
        for (int i = 0; i < nml[1]; i++)
        {
            int[] inputMatrixB = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (int j = 0; j < nml[2]; j++)
            {
                matrixB[i, j] = inputMatrixB[j];
            }
        }

        StringBuilder stringBuilder = new StringBuilder("");
        for (int i = 0; i < nml[0]; i++)
        {
            for (int j = 0; j < nml[2]; j++)
            {
                long subA = 0;
                for (int k = 0; k < nml[1]; k++)
                {
                    subA += matrixA[i, k] * matrixB[k, j];
                }
                stringBuilder.Append(subA + " ");
            }
            stringBuilder.Remove(stringBuilder.Length - 1, 1);
            stringBuilder.AppendLine();
        }

        Console.Write(stringBuilder);
    }
}



Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, ans;
    cin >> A >> B;
    if (A >= 13)
    {
        ans = B;
    }
    else
    {
        if (A >= 6)
        {
            ans = B / 2;
        }
        else
        {
            ans = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

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



int main() {
  int h, n;

  cin >> h >> n;

  int _sum = 0;
  rep(i, n) {
    int a;
    cin >> a;
    _sum += a;
  }

  if (h <= _sum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(void){
    int ans=1;
    int x; cin >> x;

    for(int i=2; i<33; i++){
        int j=2;
        while(pow(i,j)<=x){
            if(pow(i,j)>ans) ans=pow(i,j);
            j++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x;
    a[--x]++;
  }
  for (int i = 0; i < n; i++) {
    //cerr << a[i] << endl;
    if (k - (q - a[i]) > 0) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cstdint>
#include <istream>
#include <sstream>
#include <cctype>
#include <functional>
#define fore(i,x,y) for(ll i=(x);i<(y);i++)
#define disp(a) cout << a << endl;
typedef long long ll;
using namespace std;
int main()
{
	int N,K,ANS=0;
	vector<int>V;
	cin>>N>>K;
	fore(i,0,N){
		int t;
		cin >> t;
		V.push_back(t);
	}
	sort(V.begin(),V.end());
	reverse(V.begin(),V.end());
	fore(i,0,K){
		ANS=ANS+V[i];
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;
const ll MOD=1000000007;
int n;
ll k;
vector<int> es[100010];

ll dfs(int index, int parent){
  ll usable=k-2;
  if(parent==-1)usable++;

  ll result=1;
  if (k<(int)es[index].size()) {
    return 0;
  }
  for(auto e:es[index]){
    if(e!=parent){
      result*=dfs(e,index);
      result%=MOD;
      result*=usable;
      usable--;
      result%=MOD;
    }
  }
  //  cout<<"["<<index<<"] "<<result<<endl;
  return result;
}

void solve(){
  cout<<dfs(0,-1)*k%MOD<<endl;
}

int main(){_;
  cin>>n>>k;
  int a,b;
  REP(i,n-1){
    cin>>a>>b;
    a--;
    b--;
    es[a].push_back(b);
    es[b].push_back(a);
  }
  if(k==1){
    if(n==1)cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
  }
  if (k==2){
    if(n<=2)cout<<2<<endl;
    else cout<<0<<endl;
    return 0;
  }
  solve();
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    string s; cin >> s;
    bool flag1, flag2, flag3;
    int ans = 0;
    char c1, c2, c3;


    for(int j = 0; j <= 9; j++){
        for(int k = 0; k <= 9; k++){
            for(int l = 0; l <= 9; l++){
                c1 = j + '0', c2 = k + '0', c3 = l + '0';
                flag1 = false, flag2 = false, flag3 = false;
                rep(i, n){
                    if(!flag1){
                        if(s[i] == c1) flag1 = true;
                    }else if(!flag2){
                        if(s[i] == c2) flag2 = true;
                    }else if(!flag3){
                        if(s[i] == c3) flag3 = true;
                    }
                }
                if(flag3) ans++;
            }
        }
    }
    cout << ans << endl;    
}

Measured memory_bytes: 3712
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = list(input())
    k = int(input())

    for i in range(n):
        if s[i] != s[k - 1]:
            s[i] = "*"

    print("".join(s))


if __name__ == '__main__':
    resolve()


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

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 1e6 + 2, inf = 1e18;

long long gcd(long long a, long long b) { 
    if(a == 0 && b == 0) return 0;
    return b == 0 ? a : gcd(b, a % b); 
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int spf[N+10];    //Can go upto N = 1e7
int cnt[N + 5];

bool one = true;
 
void SPF(){
 
    spf[1] = 1; 

    for (int i = 2; i <= N; i++) 
        if (spf[i] == 0) { 
            spf[i] = i; 
            for (int j = 2*i; j <= N; j += i) 
                if (spf[j] == 0) 
                    spf[j] = i; 
    } 
}
    

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    SPF();

    int n;
    cin >> n;

    int g = 0;

    FOR(i,1,n) {
        int u;  cin >> u;
        g = gcd(g, u);

        while (u > 1) {
            int p = spf[u];
            cnt[p]++;
            while (u % p == 0) u /= p;
        }
    }

    FOR(i,2,N) if (cnt[i] > 1) one = false;

    if(one) {
        cout << "pairwise coprime";
        return 0;
    }

    if(g == 1) {
        cout << "setwise coprime";
        return 0;
    }
    cout << "not coprime";
}


Measured memory_bytes: 19272
S = input()
cand1 = 0
cand2 = 0
for i in range(len(S)):
    if i%2==0:
        if S[i]!='0':
            cand1 += 1
        if S[i]!='1':
            cand2 += 1
    else:
        if S[i]!='1':
            cand1 += 1
        if S[i]!='0':
            cand2 += 1
print(min(cand1, cand2))

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

  deque<int> b;
  rep(i,n){
    int a;
    cin >> a;
    if (i % 2 == 0) b.push_front(a);
    else b.push_back(a);
  }


  if (n % 2 == 1){
    rep(i,n){
      printf("%d ", b.front());
      b.pop_front();
    }
  }
  else {
    rep(i,n){
      printf("%d ", b.back());
      b.pop_back();
    }
  }
  printf("\n");
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in();
    for (ll i = (ll)sqrt(n) + 1; i >= 1; --i)
    {
        if (n % i == 0)
        {
            cout << max(to_string(i).length(), to_string(n / i).length()) << endl;
            return;
        }
    }
}

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
import static java.lang.Math.pow;
import static java.lang.System.out;
import java.io.File;
import java.util.Scanner;


public class Main extends BaseExe {

    public static void main(String[] args) {
        new Main().exeSysIn();
    }

    @Override
    protected void execute() throws Exception {
        out.println((int) pow(Double.parseDouble(nextLine()), 3));
    }
}


abstract class BaseExe {

    private Scanner scan;

    private String inData;

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeCtrl(Scanner scan) throws Exception {
        this.scan = scan;
        execute();
    }

    protected abstract void execute() throws Exception;

    protected String nextLine() {
        return scan.nextLine();
    }

    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    protected boolean isNotEmptyInData() {
        inData = nextLine();
        return !inData.isEmpty();
    }

    protected String getInData() throws Exception {
        if (inData.isEmpty())
            throw new Exception("inData is Empty.");
        return inData;
    }
}

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

static class EnglishSentence
{
    static void Main()
    {
        var q = Console.In.ReadToEnd()
            .Split( ' ' )
            .GroupBy( x => x )
            .Select( x => new { w = x.Key, c = x.Count() } )
            .ToArray();
        var most = q.Single( x => x.c == q.Max( y => y.c ) ).w;
        var longest = q.Single( x => x.w.Length == q.Max( y => y.w.Length ) ).w;
        Console.WriteLine( most + " " + longest );
    }
}

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

using P = pair<char, int>;

int root(int x, vector<int>& par, vector<int> const& cnt) {
    if(cnt[x] > 0) {
        return x;
    }
    return par[x] = root(par[x], par, cnt);
}

int main() {
    int N, Q;
    while(cin >> N >> Q, N) {
        vector<int> parent(N);
        for(int i=1; i<N; ++i) {
            int p;
            cin >> p;
            p--;
            parent[i] = p;
        }
        vector<P> query(Q);
        vector<int> m_cnt(N);  
        m_cnt[0] = 1;
        for(int i=0; i<Q; ++i) {
            cin >> query[i].first >> query[i].second;
            query[i].second--;
            if(query[i].first == 'M') {
                m_cnt[query[i].second]++;
            }
        }
        reverse(query.begin(), query.end());
        long long res = 0;
        for(auto& q : query) {
            if(q.first == 'Q') {
                res += root(q.second, parent, m_cnt) + 1;
            } else {
                m_cnt[q.second]--;
            }
        }
        cout << res << endl;
    }
}



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

min_num = 10**9
for a in range(1,n):
    b = n-a
    a_s = sum(list(map(lambda x: int(x), str(a))))
    b_s = sum(list(map(lambda x: int(x), str(b))))
    num = a_s+b_s
    min_num = min(num, min_num)

print(min_num)


Measured memory_bytes: 42728
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  lint n, k;
  cin >> n >> k;

  lint x = n%k;
  while(x > abs(x-k)){
    x = abs(x-k);
  }

  cout << x << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-48);
}
int n, m; char s[5005];
string rs[5], ss;
int main() {
	scanf("%s", s+1), n = (int)strlen(s+1);
	for (int i = 0; i < 5; i++) rs[i] = "{{{{{";
	for (int l = 1; l <= n; l++) {
		ss.clear();
		for (int r = l; r <= n; r++) {
			ss.push_back(s[r]); bool f = false;
			for (int i = 0; !f && i < 5; i++)
				if (ss == rs[i]) f = true;
			if (f) continue;
			if (ss >= rs[4]) break; rs[4] = ss;
			for (int i = 4; i; i--)
				if (rs[i] < rs[i-1])
					swap(rs[i-1], rs[i]);
		}
	}
	return read(m), cout << rs[m-1] << endl, 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int MOD = 1e9 + 7;

inline int add(int x, int y){
	int res = x + y;	
	while(res >= MOD)res-=MOD;
	return res;
}

inline int mul(int x,int y){
	return (1LL * x * y) % MOD;
}

int modpow(int x,int p){
	int res = 1;
	while(p){
		if(p&1)gmul(res,x);
		gmul(x,x);
		p/=2;
	}
	return res;
}

inline int invert(int x){
	return modpow(x,MOD - 2);
}

const int N = 2e6 + 10;

int fac[N], inv[N];

void init(int n){
	fac[0] = inv[0] = 1;
	for(int i = 1;i < n; ++i){
		fac[i] = mul(fac[i-1], i);	
		inv[i] = invert(fac[i]); 
	}
}

int comb(int n,int k){
	if(k > n)return 0;
	return mul(fac[n],mul(inv[k], inv[n-k]));	
}


int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	init(N);
	int r1,r2,c1,c2;
	cin >> r1 >> c1 >> r2 >> c2;
	if(r1 > c1){
		swap(r1,c1);
		swap(r2,c2);
	}
	int ans = 0;
	rep(r,r1,r2+1){
		gadd(ans, add(comb(r+c2+1,r+1), MOD - comb(r+c1,r+1)));
	}
	cout << ans << '\n';
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int MAX = 1e4;

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

  vector<ll> dp(h + MAX + 1, INF);
  dp[0] = 0;
  rep(i, n) {
    rep(j, h) {
      dp[j + p[i].first] = min(dp[j + p[i].first], dp[j] + p[i].second);
    }
  }

  ll ans = INF;
  FORR(i, h + MAX, h) ans = min(ans, dp[i]);
  cout << ans << endl;





  
  return 0;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  SCIN(s);
  int cnt = 0;
  REP(si, s.size() - 1) {
    if (s[si] != s[si + 1]) cnt++;
  }

  cout << cnt << endl;
  

  return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
char a[110][110];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)cin>>a[i][j];
	}
	for(int i=1;i<=n+n;i++)
	{
		for(int j=1;j<=m;j++)printf("%c",a[(i+1)/2][j]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
def I():
    return stdin.readline().rstrip()
def MI():
    return map(int,stdin.readline().rstrip().split())
def LI():
    return list(map(int,stdin.readline().rstrip().split()))
#main part
n=int(I())
cnt=0
for a in range(1,n):
    for b in range(1,n):
        if a*b>=n:
            break
        cnt+=1
print(cnt)

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

int main()
{
	ll n, a[200010];
	cin >> n;
	rep(i, n)
	{
		cin >> a[i];
	}
	ll sum[200010];
	sum[0]=0;
	rep(i, n) sum[i+1]=sum[i]+a[i];
	rep(i, n)
	{
		if(a[i]%2==0 && a[i]>=2) a[i]=2;
		else a[i]%=2;
	}
	ll le[200010], re[200010];
	le[0]=0; re[n]=0;
	rep(i, n)
	{
		le[i+1]=min((2-a[i])+le[i], sum[i+1]);
		re[n-(i+1)]=min((2-a[n-(i+1)])+re[n-i], sum[n]-sum[n-(i+1)]);
	}
	ll dp[200010];
	dp[0]=0;
	rep(i, n)
	{
		if(a[i]<2)
		{
			dp[i+1]=min((1-a[i])+dp[i], le[i+1]);
		}
		else
		{
			dp[i+1]=min(dp[i]+1, le[i+1]);
		}
	}
	ll ans=2*n;
	rep(i, n+1) ans=min(ans, dp[i]+re[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8064
#!/usr/bin/env pypy3

import array
import collections
import heapq
import itertools


AdjacentVertex = collections.namedtuple("AdjacentVertex", "vertex cost")
Town = collections.namedtuple("Town", "idx x y")
INF = 2 ** 31 - 1
NO_VERTEX = -1


# Prim法で頂点0からの最小全域木を求める
def compute_mst_prim(max_v, adj_list):
    # pred[u]は頂点uの「ひとつ前」の頂点を表す
    pred = [NO_VERTEX for _ in range(max_v)]
    # uとpred[u]を結ぶ辺の重みがkey[u]に入る
    key = [INF for _ in range(max_v)]
    key[0] = 0
    # 二分ヒープを優先度付きキューとして用いる
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    # 優先度付きキューに頂点が入っているかを示す配列
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)


def solve(n, towns):
    txs = sorted(towns, key=lambda t: t.x)
    tys = sorted(towns, key=lambda t: t.y)
    adj_list = [set() for _ in range(n)]
    g = itertools.chain(zip(txs[:-1], txs[1:]), zip(tys[:-1], tys[1:]))
    for t1, t2 in g:
        cost = min(abs(t1.x - t2.x), abs(t1.y - t2.y))
        adj_list[t1.idx].add(AdjacentVertex(t2.idx, cost))
        adj_list[t2.idx].add(AdjacentVertex(t1.idx, cost))
    (_, key) = compute_mst_prim(n, adj_list)
    return sum(key)


def main():
    n = int(input())
    towns = [Town(idx, *(int(z) for z in input().split())) for idx in range(n)]
    res = solve(n, towns)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 145240
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
fac = []
fac = factorization(N)

#print(fac)

def sankaku(x):
    ans = 0
    for i in range(int(2*math.sqrt(x))):
        if i*(i+1)//2 < x:
            ans += 1
        else:
            pass
    return ans

def truesan(x):
    return sankaku(x+1)-1

#print(truesan(N))

a = 0
for i in range(len(fac)):
    a += truesan(fac[i][1])

print(a if N != 1 else 0)

Measured memory_bytes: 9512
#include <stdio.h>
#include <string.h>
char s[200001];
int main(void){
    scanf("%s",s);
    int a=0;
    while(true){
        if(s[a]=='A')break;
        a += 1;
    }
    int z=strlen(s)-1;
    while(true){
        if(s[z]=='Z')break;
        z -= 1;
    }
    printf("%d\n",z-a+1);
    return 0;
}


Measured memory_bytes: 384
h, w = gets.split.map(&:to_i)
hs = []
h.times{ hs << gets.chomp.split("") }
def del_same_line(target_ary)
  target_ary.reject!{|e| !e.include?('#') }
end
del_same_line(hs)
hs = hs.transpose
del_same_line(hs)
hs = hs.transpose
hs.each{|e| puts e.inject(:+)}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

// 1 2 3
// 1
// 1 2 3 4
// 2

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

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

  int ans_n = *(a.end()-1);
  int ans_r = 0;
  int mindis = 1<<30; 
  rep(i, n-1) {
    if (mindis > abs(a[i] - (ans_n+1)/2)) {
        ans_r = a[i];
        mindis = abs(a[i] - (ans_n+1)/2);
    }
  }
  cout << ans_n << " " << ans_r << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

#include<vector>
using namespace std;
bool flag=false;
vector<int> v[233333];
vector<int> way;
bool vis[233333];
bool visited[233333];
int n;
int m;
int l,r;
bool dfs_find_way(int a){
	vis[a]=true;
	way.push_back(a);
	if(a==n){
		return true;
	}
	for(int i=0;i<v[a].size();i++){
		if(!vis[v[a][i]]){
			if(dfs_find_way(v[a][i])){
				return true;
			}
		}
	}
	way.pop_back();
	return false;
}
int dfs_get_ans(int a,int num=0){
	visited[a]=true;
	for(int i=0;i<v[a].size();i++){
		if(!visited[v[a][i]]){
			num=dfs_get_ans(v[a][i],num+1);
		}
	}
	return num;
}
int main(){
	cin>>n;
	m=n-1;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs_find_way(1);
///*
	for(int i=0;i<way.size();i++){
		visited[way[i]]=true;
//	cout<<way[i]<<" ";
	}
//*/
//puts("1");
	for(int i=0;i<(way.size()+1)/2;i++){
		l+=dfs_get_ans(way[i],0);
	}
	for(int i=(way.size()+1)/2;i<way.size();i++){
		r+=dfs_get_ans(way[i],0);
	}
	if(l>r){
		puts("Fennec");
		return 0;
	}
	else if(l<r){
		puts("Snuke");
		return 0;
	}
	else{
		if(way.size()%2==0){
			puts("Snuke");
			return 0;
		}
		else{
			puts("Fennec");
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 12664
# coding: utf-8
import sys
input = sys.stdin.readline

n = int(input())

monster = list(map(int,input().split()))
yusha = list(map(int,input().split()))
kill = 0
overkill = 0
for i in range(len(yusha)):
    #i番目の町、モンスターの方が多いなら勇者の数だけ倒す
    if monster[i] >= yusha[i]:
        kill += yusha[i]
    else:
        kill += monster[i]
        overkill = yusha[i] - monster[i]
        if monster[i+1] >= overkill:
            kill += overkill
            monster[i+1] -= overkill
        else:
            kill += monster[i+1]
            monster[i+1] = 0
    #print(kill)
            
print(kill)

Measured memory_bytes: 19376
#include<iostream>
#include <vector>
#include <cstdlib>
using namespace std;

const long long INF = 1LL << 60;

int min_arr(long long cost[], int K){
    int a = cost[0];
    for (int i = 1; i < K; ++i){
        if (a > cost[i]) {
            a = cost[i];
        }
    }
    return a;
}

int main()
{    
    int N,K;
    cin >> N >> K;
    long long h[N];
    long long dp[N];
    long long cost[K];

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

    for (int i = 0; i < N; ++i) {
        dp[i]=0;
    }

    for (int i = 0; i < K; ++i) {
        cost[i]=INF;
    }
    
    for (int i = 1; i < N; ++i){
        for (int j = 0; j < K; ++j){
            if (i-j-1 < 0){
                break;
            }
            cost[j] = abs(h[i]-h[i-j-1])+dp[i-j-1];
        }
        dp[i]=min_arr(cost,K);
    }

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args> void dbg(Args &&... args) {
  using expander = int[];
  (void)expander{
      0,
      (static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() {
  exit(0);
}

const ll N = 1e5;
ll n;
ll a[N + 5], b[N + 5];
ll sum[N + 5], num[2 * N + 5];

void input() {
  scanf("%lld", &n);
  forn(i, 1, n + 1) {
    scanf(" %lld", &a[i]);
    b[i] = a[i];
  }
}

ll calc(ll in) {
  ll res = 0;
  memset(sum, 0, sizeof sum);
  memset(num, 0, sizeof num);
  for (int i = 1; i <= n; i++) {
    if (a[i] >= in)
      sum[i] = sum[i - 1] + 1;
    else
      sum[i] = sum[i - 1] - 1;
  }
  ll pre = 0;
  num[N] = 1;
  for (int i = 1; i <= n; i++) {
    if (sum[i] > sum[i - 1])
      pre += num[sum[i] + N] + 1;
    else
      pre -= num[sum[i - 1] + N] - 1;
    num[sum[i] + N]++;
    res += pre;
  }
  return res;
}

void solve() {
  sort(b + 1, b + n + 1);
  ll l = 1;
  ll r = unique(b + 1, b + n + 1) - b - 1;
  ll med = n * (n + 1) / 2 - n * (n + 1) / 2 / 2;
  // ll med = n * n / 2 + ((n * n) % 2 != 0);
  ll ans;
  while (l <= r) {
    ll mid = (l + r) / 2;
    ll count = calc(b[mid]);
    if (count >= med) {
      ans = b[mid];
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  printf("%lld\n", ans);
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  // freopen("output", "w", stdout);
  // gen();
  while (!feof(stdin)) {
    input();
    solve();
    scanf(" ");
  }
#else
  input();
  solve();
#endif
  return 0;
}


Measured memory_bytes: 4096
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		sc.close();
		sc = null;
		int[] zero = new int[n+2];
		int[] one = new int[n];
		boolean f;
		int j=0;
		int l=0;
		if(s.charAt(0)=='0') {f=true;one[l++]=0;}
		else{f=false;}
		//zero[0]=0;
		for(i=0; i < n; i++) {
			if(!f && s.charAt(i) == '1') {one[l++] = i; f=true;}
			else if(f && s.charAt(i) == '0')  {zero[j++] = i; f=false;}
		}
		zero[j++] = n;
		int max = 0;
		if(j-1 < k) {max=n;}else {
		for(i=k;i<j;i++) {
			if((zero[i] - one[i-k]) > max) max = zero[i] - one[i-k];
		}
		}
		System.out.println(max);
	}
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    map<int, pair<int, int>> idx;
    vector<vector<bool>> c(3, vector<bool>(3));
    int n, a;

    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < 3; ++j) {
            cin >> a;
            idx[a] = make_pair(i, j);
        }
    }
    cin >> n;

    int b;

    for(int i = 0; i < n; ++i) {
        cin >> b;
        if(idx.count(b)) c.at(idx[b].first).at(idx[b].second) = true;
    }

    for(int i = 0; i < 3; ++i) {
        if(c.at(i).at(0) && c.at(i).at(1) && c.at(i).at(2)) {
            printf("Yes\n");
            return 0;
        }
        if(c.at(0).at(i) && c.at(1).at(i) && c.at(2).at(i)) {
            printf("Yes\n");
            return 0;
        }
    }
    if(c.at(0).at(0) && c.at(1).at(1) && c.at(2).at(2)) {
            printf("Yes\n");
            return 0;
    }
    if(c.at(0).at(2) && c.at(1).at(1) && c.at(2).at(0)) {
            printf("Yes\n");
            return 0;
    }

    printf("No\n");

    return 0;
}

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

using namespace std;
int main(int argc, char const *argv[]) {

        int midterm_exam_score; //　中間試験の点数
        int final_exam_score; //　期末試験の点数
        int re_exam_score; //　再試験の点数
        int data;         //　データの数
        while(data <= 50 && cin >> midterm_exam_score >> final_exam_score >> re_exam_score) {

                if(midterm_exam_score == -1 && final_exam_score == -1 && re_exam_score == -1) break;

                int sum_score = midterm_exam_score + final_exam_score;   //中間と期末試験の合計

                if(midterm_exam_score == -1 || final_exam_score == -1) cout << "F\n";
                else if(80 <= sum_score ) cout << "A\n";
                else if(65 <= sum_score && sum_score < 80) cout << "B\n";
                else if(50 <= sum_score && sum_score < 65) cout << "C\n";
                else if(30 <= sum_score && sum_score < 50) {
                        if(50 <= re_exam_score) cout << "C\n"; // 再テストが50以上なら
                        else cout << "D\n";
                }
                else if(sum_score < 30) cout << "F\n";
        }

        return 0;
}



Measured memory_bytes: 3072
#define rep(i,n) for (int i=0;i<(n);i++)
#include<iostream>
using namespace std;

void input_txt(char (*a)[51],int n){
	rep(i,n){
		rep(j,n)cin >> a[i][j];
	}
}

bool turn(int n,int m,char (*a)[51],char (*b)[51]){
	bool exist = false;
	rep(i,n){
		rep(j,n){
				bool match = true;
				if(i+m-1>n or j+m-1>n) continue;//超えたら止まる
				for(int y=0;y<m;y++){
					for(int x=0;x<m;x++){
						if(a[i+y][j+x]!=b[y][x]) match=false;
						continue;
					}
				}
				if(match) exist=true;
		}
	}
	return exist;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	//入力
	int m,n;
	char a[51][51],b[51][51];
	cin >> n >> m;
	input_txt(a,n);
	input_txt(b,m);

	cout << ((turn(n,m,a,b)) ? "Yes":"No") <<endl;
	return 0;
}

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

#define DEF_ELM_MAX 100005

typedef struct _PROCESS
{
	char name[100];
	int time;
} PROCESS;

static int head;
static int tail;
static PROCESS Queue[DEF_ELM_MAX];

void enque(PROCESS x)
{
	Queue[tail++] = x;
	tail %= DEF_ELM_MAX;
}

PROCESS deque( void )
{
	PROCESS x = Queue[head++];
	head %= DEF_ELM_MAX;
	return x;
}

////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
int main(void)
{
	int i;
	int N;
	int q;
	PROCESS p;
	int elaps = 0;
//
	scanf("%d %d", &N, &q);
	for ( i = 0 ; i < N ; i++ ) {
		scanf("%s %d", Queue[i].name, &Queue[i].time);
	}
	head = 0;
	tail = N;

	while (head != tail) {
		p = deque();
		if (p.time <= q) {
			elaps += p.time;
			printf("%s %d\n", p.name, elaps);
		} else {
			p.time -= q;
			elaps += q;
			enque(p);
		}

	}
	
	return 0;
}

Measured memory_bytes: 10756
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



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

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


vector<ll> S;
vector<ll> P;

ll solve(ll i, ll k){
//    cout << i << " " << k << endl;
    if(k==1){
        if(i==0) return 1;
        else return 0;
    }
    else if(k<S[i-1]+2) return solve(i-1, k-1);
    else if(k==S[i-1]+2) return solve(i-1, S[i-1]) + 1;
    else if(k<=2 * S[i-1]+2) return solve(i-1, S[i-1]) + 1 + solve(i-1, k - S[i-1] - 2);
    return 2 * solve(i-1, S[i-1]) + 1;
}


int main() {
    ll N, K; cin >> N >> K;
    S.resize(N+1);
    P.resize(N+1);
    S[0] = 1;
    P[0] = 1;
    for(int i=0; i<N; i++){
        S[i+1] = 2 * S[i] + 3;
    }
    
    for(int i=0; i<N; i++){
        P[i+1] = 2 * P[i] + 1;
    }

    
    cout << solve(N, K) << endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc145/tasks/abc145_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

const int MOD = 1e9 + 7;

template <int N, typename T, T M> struct factorial_mod {
    T mod[N + 1];
    T inv_mod[N + 1];

    constexpr factorial_mod() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    constexpr T power(T a, T b) {
        T r = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    constexpr T comb(T n, T r) {
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }
};
factorial_mod<1000001, long long, MOD> facmod;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y;
    cin >> X >> Y;
    if (X > Y) {
        swap(X, Y);
    }
    // 今後X < Yとする
    if ((X + Y) % 3 != 0) {
        cout << "0\n";
        return 0;
    }
    // 移動回数は(n + m) = (X + Y) / 3;
    // X座標は n + 2m = X;
    // Y座標は 2n + m = Y;
    // 以上から
    // m = X - (X + Y)/3;
    // n = Y - (X + Y)/3;
    int m = X - (X + Y) / 3;
    int n = Y - (X + Y) / 3;
    if (m < 0 || n < 0) {
        cout << "0\n";
        return 0;
    }
    cout << facmod.comb(m + n, m) << endl;

    return 0;
}


Measured memory_bytes: 19248