akhauriyash/Code-Regression huggingface dataset:
s=input()
t='AKIHABARA'

res=True
si=0
for ti in range(len(t)):
    if si<len(s) and t[ti] == s[si]:
        si+=1
    elif t[ti] == 'A':
        continue
    else:
        res=False
        break

if res and si==len(s):
    print('YES')
else:
    print('NO')


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
using ll = long long;
using P = pair<ll,ll>;
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 string -> int : stoi(S);
 int -> string : to_string(N);
 Sのn文字以降をm文字取り出す : S.substr(n,m)
cout << fixed << setprecision(2) << 3.14 << endl; //3.1

 int: -2,147,483,648 ～ 2,147,483,647 (2×10^9)
 ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 (9×10^18)

*/

int main() {

  ll n, m, count=0, ans=0;
  string s;
 
  cin >> n >> m;

  if( m >= n ){ cout << "unsafe" << endl; }
  else { cout << "safe" << endl; }
  

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }
struct UnionFind {
    vector<int> par;
    vector<int> sz;
 
    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }
 
    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
 
    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }
 
    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};


int main(int argc, char const *argv[]) {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(m),b(m),c(k),d(k),ans(n);
  rep(i,m){
      cin >> a[i] >> b[i];
      a[i]--, b[i]--;
  }
  rep(i,k){
      cin >> c[i] >> d[i];
      c[i]--, d[i]--;
  }
  UnionFind uf(n);
  rep(i, m) uf.unite(a[i], b[i]);

  rep(i, n) ans[i] = uf.size(i) - 1;
  rep(i,m) {
      if(uf.same(a[i],b[i])) {
        ans[a[i]]--, ans[b[i]]--;
      }
  }
  rep(i,k) {
      if(uf.same(c[i],d[i])) {
        ans[c[i]]--, ans[d[i]]--;
      }
  }
  rep(i,n) cout << ans[i] << " \n"[i==n-1];
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 H, W, M;
	cin >> H >> W >> M;
  vector<PLL> row(H), col(W);
  REP(i, H) row[i] = {0, i};
  REP(i, W) col[i] = {0, i};
  map<PLL, int> mp;

  REP(i, M) {
    int64 hh, ww;
    cin >> hh >> ww; hh--;ww--;
    mp[{hh, ww}] = 1;
    row[hh].fs++;
    col[ww].fs++;
  }
  sort(all(row)); reverse(all(row));
  sort(all(col)); reverse(all(col));
  int64 res = 0;
  REP(i, H) {
    REP(j, W) {
      chmax(res, row[i].fs + col[j].fs - mp[{row[i].sc, col[j].sc}]);
      if (mp[{row[i].sc, col[j].sc}] == 0) break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 50176
def f(i,w):
  p = i%w
  q = i//w
  if q%2 == 1:
    p = w-1-p
  return [q,p]

h,w = map(int,input().split())
a = [[]]*h
for i in range(h):
  a[i] = list(map(int,input().split()))

k = 0
s = []
for i in range(h*w-1):
  if  a[f(i,w)[0]][f(i,w)[1]]%2 == 1:
    k = 1-k
  if k == 1:
    s += [f(i,w)[0],f(i,w)[1],f(i+1,w)[0],f(i+1,w)[1]]
m = len(s)//4
print(m)
for i in range(m):
  print(s[4*i]+1,s[4*i+1]+1,s[4*i+2]+1,s[4*i+3]+1)
    

Measured memory_bytes: 20548
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string S;
    cin>>S;
    ll mod=1e9+7;
    int n=S.size();
    vvll dp(n+1,vll (13,0));
    dp[0][0]=1;
    rep(i,0,n){
        int ni=i+1;
        if(S[i]=='?'){
            rep(d,0,10){
                rep(fd,0,13){
                    int nd=(fd*10+d)%13;
                    dp[ni][nd]+=dp[i][fd];
                    dp[ni][nd]=((dp[ni][nd]%mod)+mod)%mod;
                }
            }
        }
        else{
            int d=S[i]-'0';
            rep(fd,0,13){
                int nd=(fd*10+d)%13;
                dp[ni][nd]+=dp[i][fd];
                dp[ni][nd]=((dp[ni][nd]%mod)+mod)%mod;
            }
        }
    }
    cout<<dp[n][5]<<endl;
    return 0;
}




Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10, inf = 0x3f3f3f3f, mod = 1e9 + 7;
ll prime[maxn], mu[maxn], phi[maxn], sieve[maxn];
//线性筛
void init()
{
    prime[1] = phi[1] = mu[1] = 1;
    int cnt = 0;
    for (int i = 2; i < maxn; ++i){
        if (!prime[i]) phi[i] = i - 1, mu[i] = -1, sieve[++cnt] = i;
        for (int j = 1; j <= cnt && i * sieve[j] < maxn; ++j){
            prime[i * sieve[j]] = 1;
            if (i % sieve[j] == 0){
                phi[i * sieve[j]] = phi[i] * sieve[j];
                mu[i * sieve[j]] = 0;
                break;
            }else{
                phi[i * sieve[j]] = phi[i] * (sieve[j] - 1);
                mu[i * sieve[j]] = -mu[i];
            }
        }
    }
    return ;
}
ll a[maxn], sum[maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    string s;
    cin >> s;
    if (s.size() & 1) cout << "No" << endl;
    else{
        for (int i = 0; i < s.size(); i += 2){
            if (s[i] != 'h' || s[i + 1] != 'i'){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
//    fclose(stdin);
//    fclose(stdout);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		int[] c = new int[m];
		int[] d = new int[m];
		for (int i = 0; i < m; i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}
		
		for (int i = 0; i < n; i++) {
			int nearestPoint = -1;
			int nearestDis = Integer.MAX_VALUE;
			
			for (int j = 0; j < m; j++) {
				int dis = calcDis(a[i], b[i], c[j], d[j]);
				if (dis < nearestDis) {
					nearestDis = dis;
					nearestPoint = j + 1;
				}
			}
			System.out.println(nearestPoint);
		}
		
		sc.close();
	}
	
	static int calcDis(int a, int b, int c, int d) {
		return Math.abs(a - c) + Math.abs(b - d);
	}
}




Measured memory_bytes: 27064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define m0(x) memset(x,0,sizeof(x))
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

void print_map(map<ll, ll> mp){
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        std::cout << "key = " << itr->first           // キーを表示
                        << ", val = " << itr->second << "\n";    // 値を表示
    }
}

// Returns nCr % p
ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    vector<ll> vec;
    vec.push_back(A);
    vec.push_back(B);
    vec.push_back(C);
    sort(vec.begin(), vec.end());
    ll ans = vec.at(0) * vec.at(1) / 2;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
def main():
  h,w=map(int,input().split())
  s=["*"*(w+2)]
  for i in range(h):
    s.append("*"+input()+"*")
  s+=["*"*(w+2)]
  a=[[0]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if s[i+1][j+1]!="#":
        a[i][j]=2
      else:
        a[i][j]=(s[i][j+1]+s[i+1][j:j+3]+s[i+2][j+1]).count("#")
  for i in a:
    if i.count(1)>0:
      print("No")
      return
  print("Yes")
main()

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>

int n;
int limit;
long long int dp[101][100001] = {};
int temp;

int main() {
	std::cin >> n>>limit;
	int w, v;
	for (int i = 1; i <= n; i++) {
		std::cin >> w >> v;
		for (int j = 1; j <= limit; j++) {
			if (j-w>=0&& dp[i - 1][j - w] + v >dp[i - 1][j]) {
				dp[i][j] = dp[i - 1][j - w] + v;
			}
			else{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	std::cout << dp[n][limit] << std::endl;
}


Measured memory_bytes: 81716
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

typedef deque<int> qi;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int s[1<<n];
    for (int i = 0; i < 1 << n; i++) {
        cin >> s[i];
    }
    sort(s, s+(1<<n));
    reverse(s, s+(1<<n));

    qi q[n+1];
    q[n].push_back(s[0]);
    for (int i = 1; i < 1 << n; i++) {
        bool f = false;
        for (int j = n; j >= 1; j--) {
            if (!q[j].empty() && q[j].front() > s[i]) {
                q[j-1].push_back(s[i]);
                q[j-1].push_front(q[j].front());
                q[j].pop_front();
                f = true;
                break;
            }
        }

        if (!f) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int n;
int a[101];
int b[101];
long long s=0;
int main()
{
    cin>>n;
    for(int i=1;i<n;i++) cin>>b[i];
    a[1]=b[1];
    s+=b[1];
    b[n]=INT_MAX;
    for(int i=2;i<=n;i++)
        if(b[i]>b[i-1]) {a[i]=b[i-1];s+=b[i-1];}
        else {a[i]=b[i];s+=b[i];}
    cout<<s;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::sin;
using std::cos;
using std::fixed;
#define PI 3.141592653589793

int main(void){
  double a,b,c;
  cin >> a >> b >> c;
  double k;//??????????????????
  double S,L,h;
  double rad;
  rad = (c/180) * PI;
  S =a*b*sin(rad)/2;
  k = sqrt(a*a+b*b-2*a*b*cos(rad));

  L = a+b+k;

  h = b*sin(rad);
  cout << fixed;
  cout << setprecision(20) <<  S << endl;
  cout << setprecision(20) <<  L << endl;
  cout << setprecision(20) <<  h << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
  cin >> n;
  vector<double> v(n);
  for(int i=0 ; i<n ; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = v[0];
  for(int i=1 ; i<n ; i++){
    ans = (v[i] + ans)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    
    long[] A = new long[N+1];
    for(int i = 0; i < N+1; i++){
      A[i] = scanner.nextLong();
    }
    
    long[] B = new long[N];
    for(int i = 0; i < N; i++){
      B[i] = scanner.nextLong();
    }
    
    /*
    * 勇者はn,n+1の順に倒していくと多く倒せる
    * 次の勇者はn番目を倒すことができないから
    */
    
    long total = 0;
    
    for(int n = 0; n < N; n++){
      long amount = Math.min(A[n], B[n]);
      B[n] -= amount;
      total += amount;
      
      amount = Math.min(A[n+1], B[n]);
      A[n+1] -= amount;
      total += amount;
    }
 
    System.out.println(total);
  }
}

Measured memory_bytes: 91696
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >>n;
    vector<int> a;
    for(int i=0;i<n;i++){
        a.push_back(0);
        cin>>a[i];    
    }
    int flag = 0;
    for(int i=0;i<n;i++){
        if(a[i]%2 ==0){
            if(a[i]%3!=0 && a[i]%5!=0){
                flag =1;
            }
        }
    }
    if(flag==1){
        cout<<"DENIED";
    } else{
        cout<<"APPROVED";
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n,i,j,a[4],m[4];
	ll w,v,ans=0ll,W,c[4],wsum,vsum;
	vector<ll> g[4];
	cin >> n >> W;
	cin >> c[0] >> v;
	g[0].push_back(v);
	for(i=1; i<n; ++i){
		cin >> w >> v;
		g[w-c[0]].push_back(v);
	}
	for(i=0; i<4; ++i){
		c[i] = c[0]+i;
		m[i] = g[i].l_ength();
		if(!m[i]){
			g[i].push_back(0ll);
			continue;
		}
		sort(g[i].begin(),g[i].end(),greater<ll>());
		for(j=1; j<m[i]; ++j){
			g[i][j] += g[i][j-1];
		}
		g[i].push_back(0ll);
		for(j=m[i]; j>0; --j){
			g[i][j] = g[i][j-1];
		}
		g[i][0] = 0ll;
	}
	ans = 0ll;
	for(a[0]=0; a[0]<=m[0]; ++a[0]){
		for(a[1]=0; a[1]<=m[1]; ++a[1]){
			for(a[2]=0; a[2]<=m[2]; ++a[2]){
				for(a[3]=0; a[3]<=m[3]; ++a[3]){
					wsum = 0ll;
					for(i=0; i<4; ++i){
						wsum += c[i]*a[i];
					}
					if(wsum>W){
						continue;
					}
					vsum = 0ll;
					for(i=0; i<4; ++i){
						vsum += g[i][a[i]];
					}
					ans = max(ans,vsum);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N,P;
std::unordered_map<int64_t, int32_t> count;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> P;
	int64_t res = 1;
	for (int64_t i = 2; i*i <= P; i++)
	{
		if (P%i == 0) {
			P /= i;
			++count[i];
			if (count[i] >= N) {
				res *= i;
				count[i] %= N;
			}
			--i;
		}
	}
	++count[P];
	if (count[P] >= N) {
		res *= P;
		count[P] %= N;
	}
	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>

int main(void){
    int N, L;
    scanf("%d%d", &N, &L);
    int total=(N*(2*L+N-1))/2;
    int op=L, ed=N+L-1;
    if(op>0) printf("%d\n", total-op);
    else if(ed<0) printf("%d\n", total-ed);
    else printf("%d\n", total);
    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc135/tasks/abc135_c
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    vector<ll> an(N+2);
    FOR(i,1,N+2){
        cin>>an[i];
    }
    vector<ll> bn(N+1);
    FOR(i,1,N+1){
        cin>>bn[i];
    }
    ll ans=0;
    for(ll i=1;i<=N;++i){
        ll a=an[i]+an[i+1];
        ll b=bn[i];
        ans += min(a,b);
        an[i+1]-=max(b-an[i],(ll)0);
        an[i+1]=max(an[i+1],(ll)0);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const LL Pt = 1e9 + 7;
LL n, m;

int main()
{
	scanf("%lld %lld", &n, &m);
	LL ans = 0;
	if(2 * n <= m)
	{
		ans += n;
		ans += (m - 2 * n) / 4;
	}
	else ans += m / 2;
	printf("%lld\n", ans);
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 300500;

int n, p[N];
string s;

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> n >> s;

	s = "!" + s;

	for (int i = 1; i <= n; i++)
		p[i] = p[i - 1] + (s[i] == 'W');

	int ans = n;

	for (int i = 1; i <= n; i++)
		ans = min(ans, p[i - 1] + (n - i) - (p[n] - p[i]));

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 1900
/**
 * @Author: Mingyu Li
 * @Date:   2019-02-24T19:53:08+08:00
 * @Email:  class11limingyu@126.com
 * @Filename: task.cpp
 * @Last modified by:   Mingyu Li
 * @Last modified time: 2019-02-24T20:30:19+08:00
 */

#include <bits/stdc++.h>
#define tpname typename
#define go(i , x , y) for(__typeof(x) i = x; i <= y; i++)
#define god(i , y , x) for(__typeof(y) i = y; i >= x; i--)
#define int long long
typedef long long LL;
typedef long double ld;
typedef unsigned long long ULL;
template < tpname T > void scan(T& t) {
  char c = getchar(); T x = 1; t = 0; while(!isdigit(c)) {if(c == '-') x = -1; c = getchar();}
  while(isdigit(c)) t = t * 10 + c - '0' , c = getchar();t *= x;
}
template < tpname T , tpname... Args > void scan(T& t , Args&... args) {scan(t); scan(args...);}
template < tpname T > T mul(T x , T y , T _) {
  x %= _,y %= _;
  return ((x * y - (T)(((ld)x * y + 0.5) / _) * _) % _ + _) % _;
}
using namespace std;

const int N = 100000 + 5;
int A , B , Q;
int s[N] , t[N];
int Abs(int x) {
  return x > 0 ? x : -x;
}
int mn(int x , int y) {
  return x > y ? y : x;
}
int mx(int x , int y) {
  return x < y ? y : x;
}
signed main() {
  scan(A , B , Q);
  go(i , 1 , A) scan(s[i]);
  go(i , 1 , B) scan(t[i]);

  s[0] = -(1e18);
  s[A + 1] = (1e18);
  t[0] = -(1e18);
  t[B + 1] = (1e18);
  while(Q--) {
    int tt; scan(tt);
    int rights = upper_bound(s + 1 , s + A + 1 , tt) - s;
    int lefts = lower_bound(s + 1 , s + A + 1 , tt) - (s + 1);
    int rightt = upper_bound(t + 1 , t + B + 1 , tt) - t;
    int leftt = lower_bound(t + 1 , t + B + 1 , tt) - (t + 1);
    int ans = mn(Abs(mx(s[rights] , t[rightt]) - tt) , Abs(mn(s[lefts] , t[leftt]) - tt));
    ans = mn(ans , mn(Abs(tt - s[lefts]) + Abs(s[lefts] - t[rightt]) , Abs(tt - s[rights]) + Abs(s[rights] - t[leftt])));
    ans = mn(ans , mn(Abs(tt - t[leftt]) + Abs(t[leftt] - s[rights]) , Abs(tt - t[rightt]) + Abs(t[rightt] - s[lefts])));
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2816
N = int(input())
L = [int(i) for i in input().split()]
ans = 0
for i in range(N-2) :
    for j in range(i+1,N-1) :
        for k in range(j+1,N) :
            if L[i] != L[j] and L[j] != L[k] and L[k] != L[i] :
                if L[i]+L[j] >L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j] :
                    ans += 1
print(ans)

Measured memory_bytes: 9212
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn=  1000+10;
const int maxm = maxn*21+10;
//Pretests passed
int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}

map<int,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    int n;
    sd(n);
    int ans = 0;
    while(n--)
    {
        int x;
        sd(x);
        int idx = ma[x];
        if(idx)ma[x] = 0,ans--;
        else ma[x]=1,ans++;
    }
    ansn();
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector<int> m(n);
    for(int i=0; i<n; i++) cin>>m[i];
    sort(m.begin(), m.end());
    for(int i=1; i<=m[0]; i++) {
        bool ok = true;
        for(int j=0; j<n; j++) if(m[j]%i) ok = false;
        if(ok) cout<<i<<endl;
    }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  string s ; cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(i % 2 != 0) continue;
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <math.h>
#include <string.h>
#include <map>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#define INF 100000
#define MAX 100005

using namespace std;
#define For(i, a, b) for ( int i = (a); i < (b); i++ )
#define Fors(i, sz) for ( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset (a, s, sizeof (a))
 #define EXPLORED 2
#define VISITED 1
#define UNVISITED 0
typedef long long int ll;
 typedef pair<int,int> ii;
 typedef vector<ii> vii;
 typedef vector <int > vi;
 vector<vii> adj(MAX);
 
int main()
{
 
//   freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll a,b,c;
cin>>a>>b>>c;
if(b-a==c-b)
  cout<<"YES"<<endl;
else
  cout<<"NO"<<endl;
return 0;

}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
  ll n;
  cin>>n;
  
  string s[n];
  
  for(ll i=0;i<n;i++)
  cin>>s[i];
  
   
  
  ll ans=-1;
  
 
  
  vector<ll>adj[n+1];
  for(ll i=0;i<n;i++){
      for(ll j=0;j<n;j++)
      if(s[i][j]=='1')
      {
          adj[i].pb(j);
      }
  }
  
  function<bool(ll)>check=[&](ll s){
      ll color[n];
      for(ll i=0;i<n;i++)
      color[i]=-1;
      
      color[s]=1;
      
      queue<ll>q;
      q.push(s);
      while(!q.empty()){
          ll u=q.front();
          q.pop();
          
          
          for(auto a:adj[u]){
              if(color[a]==-1){
                  color[a]=1-color[u];
                  q.push(a);
              }
              else if(color[a]^color[u]==0)
              return true;
          }
      }
      
      return false;
  };
  
   if(check(1)){
      cout<<ans;
      return;
  }
  
  bool f=true;
  
  bool mark[n+1];
  memset(mark,false,sizeof(mark));
  
 
  ll s1=-1;
  
  for(ll i=0;i<n;i++)
  mark[i]=false;
  
  queue<ll>q;
  
  q.push(1);
  
  while(!q.empty()){
      ll x=q.front();
      q.pop();
      mark[x]=true;
      
      for(auto a:adj[x]){
          if(!mark[a]){
              mark[a]=true;
              q.push(a);
          }
      }
      
      if(q.empty())
      s1=x;
  }
  
  
  ll dis[n+1]={0};
  
  dis[s1]=1;
  
  
  while(!q.empty())
  q.pop();
  
  for(ll i=0;i<n;i++)
  mark[i]=false;
  
  q.push(s1);
  
  while(!q.empty()){
      ll x=q.front();
      q.pop();
      mark[x]=true;
      
      for(auto a:adj[x]){
          if(!mark[a]){
              mark[a]=true;
              dis[a]=1+dis[x];
              q.push(a);
          }
      }
  }
  
  ll mx=0;
  
  for(ll i=0;i<n;i++)
  mx=max(mx,dis[i]);
  
  ans=mx;
  cout<<ans<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

Measured memory_bytes: 4064
using System;
class Program{
    static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        int a,b;
        a = int.Parse(s[0]);
        b = int.Parse(s[1]);
        if(a > b)Console.WriteLine("a > b");
        if(a == b)Console.WriteLine("a == b");
        if(a < b)Console.WriteLine("a < b");
    }
}



Measured memory_bytes: 15952
s=input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)

Measured memory_bytes: 38256
exception Solved of string

module CharMap = Map.Make (Char)

let alphabet =
  [ 'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'; 'k'; 'l'; 'm';
    'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't'; 'u'; 'v'; 'w'; 'x'; 'y'; 'z']

let () =
  let a = read_line () in
  let trie = Array.make (String.length a + 1) CharMap.empty in
  for i = String.length a - 1 downto 0 do
    trie.(i) <- CharMap.add a.[i] (i + 1) trie.(i + 1)
  done;
  let dp = Array.make (String.length a + 1) (0, []) in
  for i = String.length a downto 0 do
    dp.(i) <-
      List.fold_left min (max_int, []) @@
      List.map (fun c ->
        match dp.(CharMap.find c trie.(i)) with
        | exception Not_found -> (1, [c])
        | (n, s) -> (1 + n, c :: s)) alphabet
  done;
  List.iter print_char (snd dp.(0));
  print_newline ()


Measured memory_bytes: 59388
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#define N 10005
#define LL long long
#define inf 1<<29
#define eps 1e-7
using namespace std;
vector<int>v[100005];
int get_sg(int u,int pre){
    int ret=0;
    for(int i=0;i<v[u].size();i++){
        if(v[u][i]!=pre)
            ret^=(1+get_sg(v[u][i],u));
    }
    return ret;
}
int main(){
    int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            v[i].clear();
        for(int i=1;i<n;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            v[x].push_back(y);
            v[y].push_back(x);
        }
        if(get_sg(1,-1))
            puts("Alice");
        else
            puts("Bob");
    return 0;
}


Measured memory_bytes: 11904
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  string S;
  cin >> S;
  if(S == "Sunny") cout << "Cloudy" <<endl;
  else if(S == "Cloudy") cout << "Rainy" <<endl;
  else cout << "Sunny" <<endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
         
    int main() {
      string N;
      cin >> N;
      
      int flag =0;
      for(int i=0;i<3;i++){
        if(N[i]=='7'){
          flag = 1;
        }
      }
      
      if(flag==1){
        cout << "Yes"  << endl;
      }else{
        cout << "No"  << endl;
      }
     
    }

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

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

    int n1;

    if (n < 10) {
        n1 = n;
    } else if (n < 100) {
        n1 = n % 10;
    } else if (n < 1000) {
        n1 = n % 100;
        n1 = n1 % 10;
    }

    if (n1 == 3) {
        cout << "bon" << endl;
    } else if (n1 == 0 || n1 == 1 || n1 == 6 || n1 == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;
 
int main(){
	ll a, b; cin >> a >> b;
	cout << ((!(a % 3) || !(b % 3) || !((a + b) % 3)) ? "Possible" : "Impossible" )<< endl;
	return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++) {
        if (i*2 + (x-i)*4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    i = ni()
    print(i + i ** 2 + i ** 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10788
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    string s, t;
    int a, b;
    string u;
    cin >> s >> t >> a >> b >> u;
    if(s==u){
        cout << a - 1 << " " <<b << endl;

    }
    else{
        cout << a << " " << b - 1 << endl;
    }

    return 0;
}

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

int A,B,C,D;
int main(){
	while(cin >> A >> B >> C >> D){
		if(A+B==C+D) cout << "Balanced" <<endl;
		else if(A+B<C+D) cout << "Right" << endl;
		else cout << "Left" << endl;
	}
}

Measured memory_bytes: 256
(ns Atcoder.ABC091-B)

(def N (read-string (read-line)))
(def ms (loop [m {} s [] i 0]
           (if (= i N)
             [m s]
             (do
               (def input (read-line))
               (if (nil? (get m (keyword input)))
                 (recur (conj m {(keyword input) 1}) (conj s input) (inc i))
                 (recur (update m (keyword input) + 1) s (inc i)))))))

(def M (read-string (read-line)))
(def mms (loop [m {} prem (first ms) s (second ms) i 0]
           (if (= i M)
             [prem m s]
             (do
               (def input (read-line))
               (if (nil? (get m (keyword input)))
                 (if (nil? (get prem (keyword input)))
                   (recur (conj m {(keyword input) 1}) (conj prem {(keyword input) 0}) (conj s input) (inc i))
                   (recur (conj m {(keyword input) 1}) prem s (inc i)))
                 (recur (update m (keyword input) + 1) prem s (inc i)))))))

; (println mms)
(def m1 (first mms))
(def m2 (second mms))
(def s (nth mms 2))

(println (reduce max 0 (map #(- (if (nil? (get m1 (keyword %))) 0 (get m1 (keyword %)))
                              (if (nil? (get m2 (keyword %))) 0 (get m2 (keyword %)))) s)))

Measured memory_bytes: 78156
/*
 * atcoder/abc124_3rd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 * ビット列を任意の区間K回まで反転させられる. この時最大の連続した1はいくつか.
 *
 * K個の区間は互いに重ならないものだけを考慮すればよい.
 * 重なった区間は2回以上反転されるので、
 * 結果が1度も反転させないかまたは1度のみ反転させた結果に帰着されるため.
 *
 * 区間の探索範囲を確定する
 * 連続した0と1の列をその連続した個数に置き換えた列を作る.
 * 例えば、000100の場合は3 1 2.
 * 両端を必ず1の個数とする. 両端のビットが0の場合は個数は0とすると、000100は0 3 1 2 0となる.
 * この数列は必ず1の個数 0の個数...1の個数と1の個数で終わり、1と0の個数が交互に繰り返される列となる.
 * この中から1の個数から始まるK個の区間を反転させることが出来るので1度にくり抜く連続した区間は2K+1要素を含む.
 * 0 3 1 2 0の例でみると、K=1の場合[]で囲まれた3通り.
 * [0 3 1] 2 0, 0 3 [1 2 0].
 * この和4, 3の最大値4が答えとなる.
 *
 * 区間の列挙にO(N). 各区間の和の計算は累積和でO(1).
 * 累積和の事前計算にO(N).
 */
int N, K;
string S;
template <class T, class T2>
void group(T &xs, vector<pair<T2, int> > &result) {
  int i=0, j;
  while (i<xs.size()) {
    j=i;
    while (j < xs.size() and xs[j] == xs[i]) j++;
    result.push_back({ xs[i], j-i });
    if (j==i) i++;
    i=j;
  }
}
void solve() {
  cin >> N >> K >> S;
  if (N==1) {
    cout << 1 << endl;
    return;
  }
  vector<pair<char, int> > result;
  if (S[0] == '0') result.push_back({ '1', 0 });
  group(S, result);
  if (S[N-1] == '0') result.push_back({ '1', 0 });
  vector<int> acc(result.size()+1, 0);
  loop(n,0,result.size()) acc[n+1] = acc[n] + result[n].second;
  int M = result.size();
  K = 2 * K + 1;
  int max_ = 0;
  for (int l=0; l<M; l += 2) {
    int r = min(l+K, (int)acc.size()-1);
    chmax(max_, acc[r] - acc[l]);
  }
  cout << max_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 1652
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, a[200001], b[200001], len1, len2;
long long k;
bool check(long long x)
{
    long long ans = 0;
    for (int i = 1; i <= len1; i++)
    {
        int l = i + 1, r = len1, best = len1 + 1;
        while (l <= r)
        {
            int mid = (l + r) >> 1;
            if (1LL * a[i] * a[mid] <= x)
            {
                best = mid;
                r = mid - 1;
            }
            else
            {
                l = mid + 1;
            }
        }
        ans += len1 - best + 1;
    }
    for (int i = 1; i <= len2; i++)
    {
        int l = i + 1, r = len2, best = i;
        while (l <= r)
        {
            int mid = (l + r) >> 1;
            if (1LL * b[i] * b[mid] <= x)
            {
                best = mid;
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
        ans += best - i;
    }
    for (int i = 1; i <= len1; i++)
    {
        int l = 1, r = len2, best = len2 + 1;
        while (l <= r)
        {
            int mid = (l + r) >> 1;
            if (1LL * a[i] * b[mid] <= x)
            {
                best = mid;
                r = mid - 1;
            }
            else
            {
                l = mid + 1;
            }
        }
        ans += len2 - best + 1;
    }
    return ans >= k;
}
int main(int argc, char const *argv[])
{
    scanf("%d%lld", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        int x;
        scanf("%d", &x);
        if (x < 0)
        {
            a[++len1] = x;
        }
        else
        {
            b[++len2] = x;
        }
    }
    sort(a + 1, a + len1 + 1);
    sort(b + 1, b + len2 + 1);
    long long l = -1e18, r = 1e18, best = -2e18;
    while (l <= r)
    {
        long long mid = (l + r) >> 1;
        if (check(mid))
        {
            best = mid;
            r = mid - 1;
        }
        else
        {
            l = mid + 1;
        }
    }
    printf("%lld", best);
    return 0;
}

Measured memory_bytes: 4604
sx,sy,tx,ty=map(int,input().split())
x1,y1=tx-sx,ty-sy
x2,y2=x1+2,y1+2

s="U"*y1
s+="R"*x1
s+="D"*y1
s+="L"*x1

s+="L"
s+="U"*(y2-1)
s+="R"*(x2-1)
s+="D"

s+="R"
s+="D"*(y2-1)
s+="L"*(x2-1)
s+="U"

print(s)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    int n;
    cin >> n;
    vector<lli> a(n+1, 0);
    for(int i=1; i<=n; i++){
        cin >> a[i];
        a[i] += a[i-1];
    }
    lli ans = 1e18;
    for(int i=3; i<n; i++){
        int s[2] = {1, i};
        int e[2] = {i-1, n};
        lli tmin[2][2], tmax[2][2];
        for(int d=0; d<2; d++){
            lli total = a[e[d]] -a[s[d]-1];
            lli half = a[s[d]-1] + total/2;
            int mididx = upper_bound(a.begin()+s[d], a.begin()+e[d]+1, half) -a.begin();
            for(int j=0; j<2; j++){
                if(mididx+j <= s[d] || e[d] < mididx+j){
                    tmin[d][j] = 0;
                    tmax[d][j] = 1e18;
                    continue;
                }
                lli sum1 = a[mididx+j-1] -a[s[d]-1];
                lli sum2 = a[e[d]] -a[mididx+j-1];
                if(sum1 > sum2) swap(sum1, sum2);
                tmin[d][j] = sum1;
                tmax[d][j] = sum2;
            }
        }
        for(int j=0; j<2; j++){
            for(int k=0; k<2; k++){
                ans = min(ans, max(tmax[0][j], tmax[1][k]) -min(tmin[0][j], tmin[1][k]));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*
import java.math.*

fun main(args: Array<String>) {

    var (H, W) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toLong()
//    val S = readLine()!!
//    val D = readLine()!!.split(" ").map { it.toLong() }
    val S = Array(H){readLine()!!}
    val mod = 1000000007L

    var lightH = IntArray(W)

    var ans = 0

    for ((h,s) in S.withIndex()) {
        var lightW = 0
        for ((w , c) in s.withIndex()) {
            if (c == '#') {
                lightH[w] = 0
                lightW = 0
                continue
            }
            if (lightH[w] == 0) {
                var count = 0
                for (i in h until H) {
                    if (S[i][w] == '#') break
                    count++
                }
                lightH[w] = count
            }
            if (lightW == 0) {
                var count = 0
                for (i in w until W) {
                    if (s[i] == '#') break
                    count++
                }
                lightW = count
            }
//            println ("$h $w ${lightH[w]} ${lightW}")
            ans = Math.max(ans, lightW+lightH[w]-1)
        }
    }

    println(ans)
}

Measured memory_bytes: 77972
import java.util.*;

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] S = new String[H];
        for (int i=0; i<H; i++) {
            S[i] = sc.next();
        }

        int ans = solve(H, W, S);

        System.out.println(ans);
    }

    private static int solve(int H, int W, String[] S) {
        int shortest = shortest(H, W, S);
        if (shortest == -1) return -1;

//        System.err.println(shortest);
        return H*W - countBlack(H, W, S) - shortest - 1;
    }

    private static int shortest(int H, int W, String[] S) {
        int[][] visit = new int[H][W];
        for (int i=0; i<H; i++) {
            for (int j=0; j<W; j++) {
                visit[i][j] = -1;
            }
        }
        visit[0][0] = 0;

        Queue<int[]> queue = new ArrayDeque<>();
        queue.add(new int[]{0, 0});

        int[][] move = {
                {0, 1},
                {1, 0},
                {0, -1},
                {-1, 0}
        };
        while(!queue.isEmpty()) {
            int[] pos = queue.remove();
//            System.err.println("next: " + pos[0] + ", " + pos[1] + " = " + visit[pos[0]][pos[1]]);

            for (int m=0; m<4; m++) {
                int[] nextPos = {pos[0]+ move[m][0], pos[1] + move[m][1]};
                if (isInside(H, W, nextPos) && S[nextPos[0]].charAt(nextPos[1]) == '.') {
                    if (visit[nextPos[0]][nextPos[1]] == -1) {
                        visit[nextPos[0]][nextPos[1]] = visit[pos[0]][pos[1]] + 1;
                        queue.add(nextPos);
                    } else {
                        visit[nextPos[0]][nextPos[1]] = Math.min(visit[nextPos[0]][nextPos[1]], visit[pos[0]][pos[1]] + 1);
                    }
                }
            }
        }

        return visit[H-1][W-1];
    }

    private static boolean isInside(int H, int W, int[] pos) {
        if (pos[0] < 0 || pos[1] < 0 || pos[0] >= H || pos[1] >= W) {
            return false;
        }

        return true;
    }

    private static int countBlack(int H, int W, String[] S) {
        int count = 0;

        for (int i=0; i<H; i++) {
            for (int j=0; j<W; j++) {
                if (S[i].charAt(j) == '#') count++;
            }
        }

        return count;
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second

using namespace std;
int main()
{
    double l;
    cin>>l;

    l /= 3.0;
    l = l*l*l;
    printf("%.10f", l);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int Left=a+b;
  int Right=c+d;
  if(Left<Right){
    cout<<"Right"<<endl;
  }
  else if (Left==Right){
    cout<<"Balanced"<<endl;
  }
  else{
    cout<<"Left"<<endl;
  }
}


Measured memory_bytes: 3596