akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = list(input())

species_S_list = set(S)
ans = 0
for num in range(0, 1000):
    cnt = 0
    num_str = str(num).zfill(3)
    n0, n1, n2 = list(num_str)
    if n0 in species_S_list and n1 in species_S_list and n2 in species_S_list:
        index0 = S.index(n0)
        index2 = N - S[::-1].index(n2) - 1
        if index0 < index2:
            if n1 in S[index0 + 1: index2]:
                ans += 1
print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    cin >> N;
    if(N % 2 == 0) cout << 1.0 / 2.0 << endl;
    else cout << (N / 2 + 1) / (double)N << endl;
}

Measured memory_bytes: 256
import math

A,B,H,M = map(int,input().split())

HH = H * 5

angle = (HH - M) * 6 + (M / 60) * 30

ans = math.sqrt((A ** 2 + B ** 2) - (2 * A * B * (math.cos(math.radians(angle)))))
  
print(ans)

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans = 0;
    if(a > b){
        ans += b;
    }else{
        ans += a;
    }

    if(c > d){
        ans += d;
    }else{
        ans += c;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def left(text, n):
  return text[:n]

def right(text, n):
  return text[-n:]

def mid(text, n, m):
  return text[n-1:n+m-1]
  
n = int(input())

rangeSet = [[0]*10 for i in range(10)]

# [1,9][9,1]など先頭＋最終の組み合わせを設定
for i in range(1,n+1):
	first = int(left(str(i),1))
	end = int(right(str(i),1))
	rangeSet[first][end] += 1

kumiawase = 0
for k in range(1,10):
	for l in range(1,10):
		tmp = rangeSet[k][l] * rangeSet[l][k]
		kumiawase += tmp	
print(kumiawase)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y, z, p = 1;
    cin >> x >> y >> z;
    x = x - y - 2*z;
    while(x >= (y+z)){
        x -= (y+z);
        p++;
    }
    cout << p << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;


int main() {
	char s;
	cin >> s;
	if (isupper(s)) {
		cout << "A";

	}
	else {
		cout << "a";
	}
}




Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000010;
const ll MOD = 1000000007;

int main() {FIN
    
    ll n, t, a, i, x = 0, y = 0, dt, da;
    cin >> n;
    for (i = 0; i < n; i++) {
		cin >> t >> a;
		if (i == 0)
			x = t, y = a;
		else {
			dt = (x / t) + (x % t > 0 ? 1 : 0);
			da = (y / a) + (y % a > 0 ? 1 : 0);
			x = t * max(dt, da);
			y = a * max(dt, da);
		}
	}
	
	cout << x + y << "\n";
	
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k;
  cin >> k;
  int ans = 1;
  vector<int> a(1000005);
  a[0] = 7%k;
  for(int i = 0; i < 1000005; i++){
    if(a[0] == 0) break;
    a[i+1] = (a[i]*10+7)%k;
    ans++;
    if(a[i+1] == 0) break;
  }
  if(ans == 1000006) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 7208
#include <bits/stdc++.h>
using namespace std;
#define N_MAX 40
#define w_MAX 10
#define INF 100000

int dp[N_MAX + 1][w_MAX * (N_MAX + 10) + 1][w_MAX * (N_MAX + 10) + 1];
int a[N_MAX], b[N_MAX], c[N_MAX];

void solve(int N){
  // 初期化
  for (int i = 0; i < N_MAX + 1; i++) {
    for (int j = 0; j < w_MAX * (N_MAX + 10) + 1; j++) {
      for (int k = 0; k < w_MAX * (N_MAX + 10) + 1; k++) {
        dp[i][j][k] = INF;
      }
    }
  }
  dp[0][0][0] = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < w_MAX * N_MAX + 1; j++) {
      for (int k = 0; k < w_MAX * N_MAX + 1; k++) {
        dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
        dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
      }
    }
  }

}

int main(){
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i] >> c[i];
  solve(N);
  int ans = INF;
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < w_MAX * N_MAX + 1; j++) {
      for (int k = 1; k < w_MAX * N_MAX + 1; k++) {
        if(j * Mb == k * Ma) ans = min(ans, dp[i][j][k]);
      }
    }
  }
  
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

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

int main() {

  int N, M;
  cin >> N >> M;

  priority_queue<pair<int, int>> v;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    v.push({a, 1});    
  }

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    v.push({b, a});
  }

  long count = 0;

  for (int i = 0; i < N; i++) {

    pair<int, int> p = v.top();
    v.pop();
    count += p.first;

    if (1 < p.second) {
      p.second--;
      v.push(p);
    }
    
  }
  
  cout << count << endl;

}

Measured memory_bytes: 2420
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,y[200010];
vi x;

int main(){
    I(n);
    x.resize(n);
    REP(i,n) { I(x[i]); y[i] = x[i]; }
    sort(x.begin(),x.end());
    int xlow = x[n/2-1];
    int xhigh = x[n/2];
    REP(i,n){
        if (y[i] > xlow){
            printf("%d\n",xlow);
        } else {
            printf("%d\n",xhigh);
        }
    }
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N, X[101];

signed main(){
    cin >> N;
    REP(i, N) cin >> X[i];
    ll ans = LONG_LONG_MAX / 2;
    FOR(P, 1, 101){
        ll dist = 0;
        REP(i, N) dist += (X[i] - P) * (X[i] - P);
        ans = min(ans, dist);
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 3552
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for a in range(0, A+1):
    for b in range(0, B+1):
        for c in range(0, C+1):
            if 500*a+100*b+50*c == X:
                ans += 1
print(ans)

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

using namespace std;

#define llong long long
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++ i < n; )
#define rep1(i,n) for (int i = 0; i ++ < n; )
#define len(x) ((int)x.size())

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  string s; cin >> s;
  s.resize(4);
  if (s == "YAKI") cout << "Yes";
  else cout << "No";

  return 0;
}


Measured memory_bytes: 256
def doit(s):
    r = s.count('R')
    l = s.count('L')
    return [0] * (r - 1) + [r - r // 2 + l // 2, l - l // 2 + r // 2] + [0] * (l - 1)

s = input()
ret = []
p = 0
for i in range(1, len(s)):
    if s[i - 1] == 'L' and s[i] == 'R':
        ret += doit(s[p:i])
        p = i
ret += doit(s[p:])

print(' '.join(map(str, ret)))

Measured memory_bytes: 10964
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	cout<< string(tx - sx, 'R');
	cout<< string(ty - sy, 'U');
	cout << string(tx - sx, 'L');
	cout<< string(ty - sy, 'D');
	cout << "D" <<  string(tx - sx+1, 'R') << string(ty - sy+1, 'U')<<"L";
	cout << "U" << string(tx - sx + 1, 'L') << string(ty - sy + 1, 'D') << "R";
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O2")
#include <bits/stdc++.h>

#define int long long
#define double long double 

using namespace std;

const int INF = 1e+18;
const int MAXN = 100000;
const int LOGN = 20;
const int mod = 1e9+7;

signed main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    double a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    double dp[n][n + 1];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) dp[i][j] = 0.0;
    }

    dp[0][0] = 1 - a[0];
    dp[0][1] = a[0];

    for (int i = 1; i < n; i++) {
        dp[i][0] = dp[i - 1][0]*(1 - a[i]);
        for (int j = 1; j <= n; j++) {
            dp[i][j] += dp[i - 1][j] * (1 - a[i]);
            dp[i][j] += dp[i - 1][j - 1] * a[i];
        }
    }

    double ans = 0.0;
    for (int i = (n + 1) / 2; i <= n; i++) {
        ans += dp[n - 1][i];
    }
    
    cout.precision(17);
    cout << ans;
}

Measured memory_bytes: 140928
import sys

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret


import math

def get_primenumber(number):#エラトステネスの篩
    prime_list = []
    search_list = list(range(2,number+1))
    #search_listの先頭の値が√nの値を超えたら終了
    while search_list[0] <= math.sqrt(number):
      #search_listの先頭の値が√nの値を超えたら終了
      #search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        #head_numの倍数を除去
        search_list = [num for num in search_list if num % head_num != 0]
    #prime_listにsearch_listを結合
    prime_list.extend(search_list)
    return prime_list

p=get_primenumber(79000)

n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)
amax=max(ap)

if amax==1:
    print("pairwise coprime")
    sys.exit()

if amin!=1:
    bp=enum_div(amin)+[amin]
    bp=bp[1:]
    for bpi in bp:
        yn=""
        for ai in ap:
            if ai%bpi!=0:
                yn="coprime"
                break
        if yn=="":
            print("not coprime")
            sys.exit()

if n>=78500 :
    print("setwise coprime")
    sys.exit()

aa=[0]*(amax+1)
for ai in ap:
    aa[ai]+=1
    
for pp in range(2,amax+1):
#for pp in p:
    psum=0
#    for pi in range(pp,amax+1,pp):
#    for pi in range(pp,amax+pp-1,pp):
#        psum+=aa[pi]
    psum=sum(aa[pp: :pp])
#    print("pp:",pp,psum)
    if psum>=2:
            print("setwise coprime")
            sys.exit()
## max_13.txt ... max_16.txt : "setwise coprime"
print("pairwise coprime")
   


Measured memory_bytes: 201720
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
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;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}


void solve(){
	ll n,d;
	cin>>n>>d;
	vector<vector<ll>> x(n,vector<ll> (d,0));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<d;j++){
			cin>>x[i][j];
		}
	}

	ll ans=0;

	for(ll i=0;i<n;i++){
		for(ll j=i+1;j<n;j++){
			ll sum=0;
			for(ll k=0;k<d;k++){
				sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			if(pow((int)sqrt(sum),2)==sum){
				ans++;
			}
		}
	}

	cout<<ans<<endl;
}

int main(){
	
	solve();
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;
ld p=1.0/(ld)1e9;


int main()
{
    FAST
    ld n,d;cin>>n>>d;
    ll ans=0;
    f(i,0,(int)n)
    {
        ld x,y;cin>>x>>y;
        ld val = sqrt(x*x+y*y);
        if(val<d+p) ans++;
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

typedef pair<ll, pll> para;
const ll inf = 1e18 + 7;
const int maxN = 1e5 + 5;

int n, x, y, a, b;
int dist1[maxN], dist2[maxN];
vi graph[maxN];

void DFS(int start, int dist[]) {
	for (auto x: graph[start]) {
		if (dist[x] == -1) {
			dist[x] = dist[start] + 1;
			DFS(x, dist);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> x >> y;
	REP(i, n - 1) {
		cin >> a >> b;
		graph[a].pb(b);
		graph[b].pb(a);
	}
	RI(i, n) dist1[i] = dist2[i] = -1;
	dist1[x] = 0;
	dist2[y] = 0;
	DFS(x, dist1);
	DFS(y, dist2);
	int ans = 0;
	RI(i, n) if (dist1[i] < dist2[i]) ans = max(ans, dist2[i] - 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10368
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()

fun main(args: Array<String>) {
    val dic = mutableSetOf<String>()
    repeat(N) {
        dic.add(sc.next())
    }
    println(if (dic.count() == 3) "Three" else "Four")
}


Measured memory_bytes: 35916
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll fact[200001];
ll inv[200001];
ll power(ll val, ll exp)
{
    if(exp == 1)
        return val;
    ll res = power(val, exp/2);
    return (exp & 1) ? ((val*res)%mod*res)%mod : (res*res)%mod;  
}

ll inverse(ll val)
{
    return power(val, mod - 2);
}

ll nCrMod(int n, int r)
{
    return (fact[n] * inv[r] % mod * inv[n - r] % mod) % mod;
}

bool comp(pair<int,int>& p1, pair<int,int>& p2)
{
    return (p1.first + p1.second) < (p2.first + p2.second);
}

ll pathsBetweenPts(pair<int,int> p1, pair<int,int> p2)
{
    if(p1.first <= p2.first && p1.second <= p2.second)
    {
        int down = p2.first - p1.first;
        int right = p2.second - p1.second;
        return nCrMod(down + right, down);
    }
    return 0;
}

void preprocess()
{
    fact[0] = 1;
    inv[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
        inv[i] = inverse(fact[i]);
    }
}

ll solve(int H, int W, vector<pair<int,int>> obs)
{
    ll ways = nCrMod(H+W-2, H-1);
    sort(obs.begin(), obs.end(), comp);
    vector<ll> pathsToObs;
    pathsToObs.push_back(pathsBetweenPts({1,1}, obs[0]));
    for(int i = 1; i < obs.size(); i++)
    {
        ll paths = pathsBetweenPts({1,1}, obs[i]);
        for(int j = i - 1; j >= 0; j--)
        {
             paths = (mod + paths - (pathsToObs[j]*pathsBetweenPts(obs[j], obs[i]))%mod)%mod;
        }
        pathsToObs.push_back(paths);
    }
    for(int i = 0; i < obs.size(); i++)
    {
        ways = (mod + ways - (pathsToObs[i]*pathsBetweenPts(obs[i],{H,W})%mod))%mod;
    }
    return ways;
}

int main() {
   int H,W,n; 
   preprocess();
   cin >> H >> W >> n;
   vector<pair<int,int>> obs(n);
   for(int i = 0; i < n; i++)
        cin >> obs[i].first >> obs[i].second;
   cout << solve(H,W,obs);
   return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>
#include<vector>
#include<stdbool.h>
using namespace std;

int main() {
	int A, B;
	string S;
	cin >> A >> B;
	cin >> S;
	while (S[A] == '-') {
		int num1 = 0, num2 = 0;
		for (int i = 0;i < A;i++) {
			if (S[i] == '-') {
				cout << "No\n";
				return 0;
			}
			else {
				num1++;
			}
		}
		for (int i = A + 1;i < S.size();i++) {
			if (S[i] == '-') {
				cout << "No\n";
				return 0;
			}
			else {
				num2++;
			}
		}
		if ((num1 == A) && (num2 == B)) {
			cout << "Yes\n";
			return 0;
		}
		else {
			cout << "No\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;

}

Measured memory_bytes: 256
fun is_inside(l: Int, c: Int, r: Int): Boolean {
    return (0 <= c - r) && (c + r <= l)
}

fun main(args : Array<String>) {
    val (w, h, a, b, r) = readLine()!!.split(" ").map(String::toInt)
    if (is_inside(w, a, r) && is_inside(h, b, r)) {
        println("Yes")
    } else {
        println("No")
    }
}



Measured memory_bytes: 33812
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
	int  a, b, x;
	cin >> a >> b >> x;
	if (a <= x &&(a + b) >= x) cout << "YES" << endl;
	else cout << "NO" << endl;

    return 0;
}




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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

string S;

// [l, r] を除いた S と "keyence" を比較
static inline bool func(int l, int r) {
    string s_tmp = S.substr(0, l + 1) + S.substr(r);
    return (s_tmp == "keyence");
}

signed main()
{
    cin >> S;
    REP(l, S.length()-1) {
        for(int r = l + 1; r < S.length(); ++r) {
            if(func(l, r)) {
                printf("YES\n");
                return 0;
            }
        }
    }

    printf("NO\n");
    return 0;
}


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

int main(){
  int N,X,Y;  
  cin >> N >> X >> Y;

  vector<int> vec(N);
  int res;
  for (int i = 1; i < N; i++) {
    for (int j = i+1; j < N+1; j++) {
       if (i<=X&&j>=Y) res=(X-i)+1+(j-Y);
       else if (i<=X&&X<=j&&j<=Y) res=(X-i)+min(j-X,Y-j+1);
       else if (X<=i&&j<=Y) res=min(j-i,i-X+Y-j+1);
       else if (X<=i&&i<=Y&&j>=Y) res=(j-Y)+min(Y-i,i-X+1);
       else res=j-i; 
       vec.at(res)+=1;
    }
  }

  for (int i = 1; i < N; i++) {
      cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

const assert = require('assert');

line = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);
n = Number(line.shift());
V = {};
w = {};
function add(obj, u, v, c) {
  if (!obj.hasOwnProperty(u)) obj[u] = {};
  obj[u][v] = c;
}
for (i in line) {
  ary = line[i].split(' ').map(Number);
  u = ary[0];
  V[u] = {'id': u, 'd': Number.POSITIVE_INFINITY,
          'pi': null, 'heapindex': null};
  for (j = 2; j < ary.length; j += 2)
    add(w, u, ary[j], ary[j+1]);
}
for (i in V) {
  if (V[i].id === 0) {
    V[i].d = 0;
    break;
  }
}

// heap tree

heap = new Array(n+1);
heapsize = 0;
for (i = 0; i <= n; i++) heap[i] = null; // heap stores node objects
function minHeapify(A, i) {
  var l, r, smallest, tmp;
  l = 2 * i;
  r = 2 * i + 1;
  if (l <= heapsize && A[l].d < A[i].d) smallest = l;
  else smallest = i;
  if (r <= heapsize && A[r].d < A[smallest].d) smallest = r;
  if (smallest !== i) {
    tmp = A[i];
    A[i] = A[smallest];
    A[i].heapindex = i;
    A[smallest] = tmp;
    A[smallest].heapindex = smallest;
    minHeapify(A, smallest);
  }
}
function heapExtractMin(A) {
  var min;
  assert(heapsize >= 1, 'heap underflow');
  min = A[1];
  min.heapindex = null;
  A[1] = A[heapsize];
  A[1].heapindex = 1;
  A[heapsize] = null;
  heapsize--;
  minHeapify(A, 1);
  return min;
}
function heapDecreaseKey(A, i, key) {
  var parent, tmp;
  assert(key.d <= A[i].d, 'new key is larger than current key');
  A[i] = key;
  A[i].heapindex = i;
  while (i > 1) {
    parent = Math.floor(i / 2);
    if (A[parent].d <= A[i].d) break;
    tmp = A[i];
    A[i] = A[parent];
    A[i].heapindex = i;
    A[parent] = tmp;
    A[parent].heapindex = parent;
    i = parent;
  }
}
const POSITIVE_INFINITY_NODE =
  {'id': null, 'd': Number.POSITIVE_INFINITY, 'pi': null, 'heapindex': null};
function minHeapInsert(A, key) {
  heapsize++;
  A[heapsize] = POSITIVE_INFINITY_NODE;
  heapDecreaseKey(A, heapsize, key);
}

// Dijkstra algorithm

function relax(u, v, w) {
  if (v.d > u.d + w[u.id][v.id]) {
    v.d = u.d + w[u.id][v.id];
    v.pi = u;
    if (v.heapindex !== null) heapDecreaseKey(heap, v.heapindex, v);
  }
}

function dijkstra(w) {
  var S = [], i, Q = heap, u;
  for (i in V) minHeapInsert(Q, V[i]);
  while (heapsize !== 0) {
    u = heapExtractMin(Q);
    S.push(u);
    for (j in w[u.id]) {
      v = V[j];
      relax(u, v, w);
    }
  }
}

dijkstra(w);
for (i in V) console.log("%s %d", i, V[i].d);

Measured memory_bytes: 72636
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	int n;
	long long u[110000], v[110000], w[110000];
	cin >> n;
	bool isw[110000][3];
	bool f = false;
	long count = 0;
	for (int i = 0; i < 10050; i++)//初期化
	{
		isw[i][0] = false;
		isw[i][1] = false;
	}
	isw[1][0] = true;
	isw[1][1] = true;//1の色を決めておく
	for (int i = 1; i < n; i++)
	{
		cin >> u[i] >> v[i] >> w[i];
	}
	while (!f)
	{
		for (int i = 1; i < n; i++)
		{
			if (isw[u[i]][1] == true)//u[i]の色が確定してるとき
			{
				isw[v[i]][0] = isw[u[i]][0];//v[i]の色を決める
				//cout << v[i] << " paint " << isw[v[i]][0] << " because of " << u[i] << endl;;
				if (w[i] % 2 == 1)//距離が奇数のとき
				{
					isw[v[i]][0] = !isw[v[i]][0];//色を反転
				}
				//cout << isw[v[i]][1] << endl;
				if (isw[v[i]][1] == false)//色を決めたとき
				{
					count++;
					//cout << "count++" << endl;
				}
				isw[v[i]][1] = true;//確定フラグ
			}

			if (isw[v[i]][1] == true)//v[i]の色が確定してるとき
			{
				isw[u[i]][0] = isw[v[i]][0];//u[i]の色を決める
				//cout << u[i] << " paint " << isw[u[i]][0] << " because of " << v[i] << endl;;
				if (w[i] % 2 == 1)
				{
					isw[u[i]][0] = !isw[u[i]][0];
				}
				//cout << isw[v[i]][1] << endl;
				if (isw[u[i]][1] == false)
				{
					count++;
					//cout << "count++" << endl;
				}
				isw[u[i]][1] = true;//確定フラグ
			}

			if (count == n - 1)f = true;
		}
		for (int i = n; i >1; i--)
		{
			if (isw[u[i]][1] == true)//u[i]の色が確定してるとき
			{
				isw[v[i]][0] = isw[u[i]][0];//v[i]の色を決める
				//cout << v[i] << " paint " << isw[v[i]][0] << " because of " << u[i] << endl;;
				if (w[i] % 2 == 1)//距離が奇数のとき
				{
					isw[v[i]][0] = !isw[v[i]][0];//色を反転
				}
				//cout << isw[v[i]][1] << endl;
				if (isw[v[i]][1] == false)//色を決めたとき
				{
					count++;
					//cout << "count++" << endl;
				}
				isw[v[i]][1] = true;//確定フラグ
			}

			if (isw[v[i]][1] == true)//v[i]の色が確定してるとき
			{
				isw[u[i]][0] = isw[v[i]][0];//u[i]の色を決める
				//cout << u[i] << " paint " << isw[u[i]][0] << " because of " << v[i] << endl;;
				if (w[i] % 2 == 1)
				{
					isw[u[i]][0] = !isw[u[i]][0];
				}
				//cout << isw[v[i]][1] << endl;
				if (isw[u[i]][1] == false)
				{
					count++;
					//cout << "count++" << endl;
				}
				isw[u[i]][1] = true;//確定フラグ
			}

			if (count == n - 1)f = true;
		}

	}
	for (int i = 1; i <= n; i++)
	{
		if (isw[i][0] == 1)cout << 1 << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 3200
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    K, T = map(int, input().split())
    A = list(map(int, input().split()))

    que = queue.PriorityQueue()
    for a in A:
        que.put(-a)

    que2 = queue.Queue()

    ans = 0
    while not que.empty():
        n = -que.get()
        if not que2.empty():
            que.put(que2.get())
        if que.empty():
            ans += 1
            if n - 1 > 0:
                n -= 1
                que.put(-n)
                continue
            else:
                break
        if n - 1 > 0:
            n -= 1
            que2.put(-n)

    print(ans - 1)


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

int main() {
  string s, t; cin >> s >> t;
  int length = t.length();
  int res = 0;
  
  for (int i = 0; i < s.length() - length + 1; i++) {
    string str = s.substr(i, length);
    int cnt = 0;

    for (int j = 0; j < str.length(); j++) {
      if (str[j] == t[j]) { 
        cnt = cnt + 1;
      }
    }

    if (cnt > res) {
      res = cnt;
    }

  }

  cout << length - res << endl;
}

Measured memory_bytes: 3140
//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

int main() {
    fastIO;
    ll n; cin>>n;
    string ans="";

    while (n>0) {
        int x= n%26-1;
        if(x<0) x=25;
        ans+= x + 'a';
        n-=x; n/=26;
    } reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

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

int main() {
char c;
cin >> c;

 if (c =='a'|| c == 'i' || c == 'u' || c == 'e' || c == 'o' ){
    cout << "vowel" << endl;
 }

 else{
    cout << "consonant"  << endl;
 }

}

Measured memory_bytes: 256
from bisect import bisect_left
INF = 10**11

a,b,q = map(int,input().split())
ss = [int(input()) for _ in range(a)] 
tt = [int(input()) for _ in range(b)] 
xx = [int(input()) for _ in range(q)] 

ss = sorted(ss)
tt = sorted(tt)

for x in xx:
  left,middle,right = INF,INF,INF
  sp = bisect_left(ss,x)
  tp = bisect_left(tt,x)
  
  l_sp, r_sp = INF, INF
  l_tp, r_tp = INF, INF
      
  if 0 < sp:
    l_sp = sp - 1
  if 0 < tp:
    l_tp = tp - 1
  if sp < a:
    r_sp = sp
  if tp < b:
    r_tp = tp
    
  
  
  left,right,middle_ts, middle_st = INF,INF,INF,INF
  
  if (l_sp != INF) and (l_tp != INF):
    left = abs(x - min(ss[l_sp],tt[l_tp]))    

  if (r_sp != INF) and (r_tp != INF):
    right = abs(max(ss[r_sp],tt[r_tp]) - x)      

  if (l_tp != INF) and (r_sp != INF):
    middle_ts = min(abs(tt[l_tp] - x), abs(ss[r_sp] - x)) + ss[r_sp] - tt[l_tp]
  
  if (l_sp != INF) and (r_tp != INF):
    middle_st = min(abs(ss[l_sp] - x), abs(tt[r_tp] - x)) + tt[r_tp] - ss[l_sp]
    
  print(min(left,right,middle_ts,middle_st))
  

Measured memory_bytes: 16148
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int a, b, ans = -1;
    cin >> a >> b;
    for(int i=0;i<=10000;i++){
        int x = i*8/100;
        int y = i*10/100;
        if(x == a && y == b){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c||a+c==b||b+c==a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    int map[2][n];
    for(int i = 0; i<2; ++i)for(int j = 0; j<n; ++j)cin >> map[i][j];
    int ans = 0;
    for(int i = 1; i<=n; ++i){
        int pos = 1, tmp_ans = map[0][0];
        while(pos<i){
            tmp_ans += map[0][pos];
            ++pos;
        }
        --pos;
        while(pos<n){
            tmp_ans += map[1][pos];
            ++pos;
        }
        if(ans < tmp_ans)ans = tmp_ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left

N, Q, *AX = map(int, open(0).read().split())
A, X = AX[:N], AX[N:]

if N % 2 == 1:
    A = [0] + A

M = len(A) // 2
B = []
S = [sum(A[M:])]
for i in range(M - 1):
    l, r = A[2 * i + 1], A[i + M]
    B.append((l + r) // 2)
    S.append(S[-1] + l - r)

for x in X:
    print(S[bisect_left(B, x)])

Measured memory_bytes: 31484
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	string s, t;
	cin >> N >> s >> t;
	for (int i = N; i >= 0; -- i) {
		if (s.substr(N-i, i) == t.substr(0, i)) {
			cout << N*2-i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
import java.util.*;


public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long n = scan.nextLong();
        StringBuilder out = new StringBuilder();
        while(n > 26){
            if(n % 26 != 0){
                out.append(name(n % 26));
                n /= 26;
            }else{
                out.append(name(26));
                n = n / 26 - 1;
            }
        }
        out.append(name(n));
        for(int i = out.length() - 1; i >= 0 ; i--) System.out.print(out.charAt(i));
        scan.close();
    }
    
    public static String name(long n){
        
            byte[] b = {(byte) (n + 96)};
            if(n % 26 == 0) b[0] = 122;
            return new String(b);
       
            
    }
}

Measured memory_bytes: 27000
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

template<int Mod>
struct MintBase {
  int64_t x; // typedef long long int64_t;
  MintBase(int64_t x=0):x((x%Mod+Mod)%Mod){}
  MintBase operator-() const { return MintBase(-x);}
  MintBase& operator+=(const MintBase a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator-=(const MintBase a) {
    if ((x += Mod-a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator*=(const MintBase a) { (x *= a.x) %= Mod; return *this;}
  MintBase operator+(const MintBase a) const { return MintBase(*this) += a;}
  MintBase operator-(const MintBase a) const { return MintBase(*this) -= a;}
  MintBase operator*(const MintBase a) const { return MintBase(*this) *= a;}
  MintBase pow(int64_t t) const {
    if (!t) return 1;
    MintBase a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime Mod
  MintBase inv() const { return pow(Mod-2);}
  MintBase& operator/=(const MintBase a) { return *this *= a.inv();}
  MintBase operator/(const MintBase a) const { return MintBase(*this) /= a;}
};

//const int Mod = 1000000007;
//const int Mod = 998244353;

using mint = MintBase<1000000007>;

int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    vector<mint> min(n + 2), max(n + 2), ans(n + 2);
    min[0] = 0;
    max[0] = 0;
    rep(i, n + 1)
    {
        min[i + 1] = min[i] + i;
        max[i + 1] = max[i] + (n - i);
        ans[i + 1] = max[i + 1] - min[i + 1] + 1;
    }
    mint an(0);
    rep(i, n - k + 2)
    {
        auto index = i + k;
        an += ans[index];
    }
    cout << an.x << endl;
    return 0;
}


Measured memory_bytes: 7992
S = input()
ex1 = ''
while len(ex1) < len(S):
    ex1 += '1'
    if len(ex1) < len(S):
  	    ex1 += '0'
ex2 = ''
while len(ex2) < len(S):
    ex2 += '0'
    if len(ex2) < len(S):
        ex2 += '1'
ans1 = 0
ans2 = 0
for i in range(len(S)):
    if ex1[i] == S[i]:
        ans2 += 1
    else:
        ans1 += 1
print(min(ans1,ans2)) 

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>0 && a<=9 &&  b>0 && b<=9)
    {
        printf("%d\n",a*b);
    }
    else
        printf("-1");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	int cnt1 = 0, cnt2 = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			cnt1 += a[i];
		} else {
			cnt2 += a[i];
		}
	}
	cout << abs(cnt1 - cnt2) << endl;
	return 0;
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int x = a * b;
  int y = x % 2;
  if (y == 0){
  	cout << "Even" << endl;
  }
  else {
  	cout << "Odd" << endl;
  }
}


Measured memory_bytes: 3632
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    string r,ans="No";
    cin>>r;
    if(r[1]=='9')ans="Yes";
    if(r[0]=='9')ans="Yes";
    cout<<ans<<endl;

}


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

int main(){
	int n;

	while(1){
		int ans =0, p = 0;
		cin >> n;

		if(n == 0) break;

		for(int i=1; i < n; i++){
			p = 0;
			for(int j = i; j < n; j++){
				p += j;

				if(p == n) ans++;
			}
		}

		cout << ans << endl;
	}
}

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

bool check(string S, int first, int last)
{
  bool result = true;
  while (first < last)
  {
    if (S[first] != S[last])
    {
      return false;
    }
    first++;
    last--;
  }
  return result;
}

int main(void)
{
  string S;
  cin >> S;

  // 全体が回文か
  if (!check(S, 0, S.size() - 1))
  {
    cout << "No" << endl;
    return 0;
  }

  //前半と後半
  if (!check(S, 0, (S.size() - 1) / 2 - 1))
  {
    cout << "No" << endl;
    return 0;
  }
  if (!check(S, (S.size() + 3) / 2 - 1, S.size() - 1))
  {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


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;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	int a = 0, b = 0;
	rep(i, n) {
		if ((i + 1) % k == 0)a++;
		else if (k % 2 == 0 && (i + 1) % k == k / 2)b++;
	}
	cout << a * a*a + b * b*b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  ll a[X], b[Y], c[Z];
  rep(i, X){
    cin >> a[i];
  }
  rep(i, Y){
    cin >> b[i];
  }
  rep(i, Z){
    cin >> c[i];
  }
  sort(a, a+X, greater<ll>());
  sort(b, b+Y, greater<ll>());
  sort(c, c+Z, greater<ll>());
  vector<ll> ans;
  rep(i, X){
    rep(j, Y){
      rep(l, Z){
        if(i*j*l>K) break;
        ans.push_back(a[i]+b[j]+c[l]);
      }
    }
  }
  sort(ans.begin(), ans.end(),greater<ll>());
  rep(i, K){
    cout << ans[i] << endl;
  }
  
}

Measured memory_bytes: 35172
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = (int)1e5 + 10;
// make sure N size is correctttt!!!!!!!!!

int n, d[N], t[N], k;
vector<P> v;

int32_t main(){_

   cin>>n>>k;
   v.resize(n);
   
   for (int i = 0; i < n; ++i)
   {
      cin>>v[i].S>>v[i].F;
   }

   sort(v.rbegin(), v.rend());

   set<int> first_time;//stores T
   multiset<int> data;//stores delicious
   int sum = 0;

   for (int i = 0; i < k; ++i)
   {
      int T = v[i].S, D = v[i].F;
      sum += D;
      if(first_time.count(T) == 0){
         first_time.insert(T);
      }
      else{
         data.insert(D);
      }
   }

   int ans = sum + sz(first_time) * sz(first_time);

   for (int i = k; i < n; ++i)
   {
      if(data.empty())break;
      int T = v[i].S, D = v[i].F;
      if(first_time.count(T) == 0){
         first_time.insert(T);
         sum -= *data.begin();
         sum += D;
         data.erase(data.begin());
         smax(ans, sum + sz(first_time) * sz(first_time));
      }
   }

   cout<<ans;
   //make sure N size is correct!!!!!!!!!
   return 0;
}

Measured memory_bytes: 6272
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	// "sort"
)

var stdin = initStdin()
 
func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func scanInt() int {
	stdin.Scan()
	i, _ := strconv.Atoi(stdin.Text())
	return i
}

func scanStr() string {
	stdin.Scan()
	return stdin.Text()
}

type ia []int

func (ia ia)Len() int {
	return len(ia)
}
func (ia ia)Swap(i, j int) {
	ia[i], ia[j] = ia[j], ia[i]
}
func (ia ia)Less(i, j int) bool {
	return ia[i] < ia[j]
}

const inf = 1000000000 + 7

var fib = []int {1, 1, 2, 3, 5, 8}
var fibCount = 6

func mFib(req int) int {
	if req <= fibCount {
	} else {
		lo := req - fibCount
		for i := 0; i < lo; i++ {
			fib = append(fib, (fib[fibCount-2]+fib[fibCount-1])%inf )
			fibCount++
		}
	}
	return fib[req-1]
}


func main() {
	n := scanInt()
	m := scanInt()
	bef := -1
	ans := 1
	a := 1
	for i := 0; i < m; i++ {
		a = scanInt()
		diff := a - bef
		if diff < 2 {
			ans = 0
			break
		}
		ans *= mFib(diff-1)
		ans %= inf
		bef = a
	}
	ans *= mFib(n - bef)
	ans %= inf
	fmt.Println(ans)
}

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

int main() {
  int N, A = 1;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++)
    cin >> d.at(i);
  sort(d.begin(), d.end());
  for (int i = 0; i < N - 1; i++) {
    if (d.at(i) < d.at(i + 1))
      A++;
  }
  cout << A;
}


Measured memory_bytes: 256
n,m,l = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
b = [list(map(int,input().split())) for i in range(m)]
for i in range(n):
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += a[i][k]*b[k][j]
        if j==l-1:print(sum)
        else:print(sum,end=" ")



Measured memory_bytes: 6576
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <map>

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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;
}
template <typename T>
T GCD(T x, T y)
{
    return (y ? GCD<T>(y, x % y) : x);
}



int main() {
    string S;
    cin>>S;
    int answer=0;
    map<char, char> mp;
    mp['0']='1';
    mp['1']='0';
    for(int i=0; i<S.size()-1; i++){
        if(S[i]!=S[i+1])
            continue;
        S[i+1]=mp[S[i]];
        answer++;
    }

    cout<<answer<<endl;


    return 0;
}



Measured memory_bytes: 512