akhauriyash/Code-Regression huggingface dataset:
/*
ID:xmydada1
LANG:C++
TASK:
*/
#include<bits/stdc++.h>
using namespace std;
int a[3001][3001],b[3001][3001],m,n,ans=0,sum=0,p;
char s[2001][2001];
#define reg register
inline int read() {
reg int s = 0, t = 0; reg char ch = getchar();
while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
return t ? -s : s;
}

inline void print(reg long long x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + 48);
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();m=read();
	for(int i=1;i<=n;i++)
	scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='#')continue;
			if(s[i][j-1]=='.')a[i][j]=a[i][j-1];
			if(s[i][j-1]!='.')
			{
				for(int k=j;;k++)
				{
					if(s[i][k]=='.')a[i][j]++;
					else break;
				}
			}
			if(s[i-1][j]=='.')b[i][j]=b[i-1][j];
			if(s[i-1][j]!='.')
			{
				for(int k=i;;k++)
				{
					if(s[k][j]=='.')b[i][j]++;
					else break;
				}
			}
		}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=m;j++)
			{
				ans=max(ans,a[i][j]+b[i][j]);
			}
cout<<ans-1;
	
	return 0;
}


Measured memory_bytes: 53504
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

int main()
{
	lint A,B,Q;
	vector<lint> s;
	vector<lint> t;
	vector<lint> x;
	
	cin >> A >> B >> Q;
	s.push_back(-1e18);
	for(lint i=0;i<A;i++)
	{
		lint tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	s.push_back(1e18);
	t.push_back(-1e18);
	for(lint i=0;i<B;i++)
	{
		lint tmp;
		cin >> tmp;
		t.push_back(tmp);
	}
	t.push_back(1e18);
	for(lint i=0;i<Q;i++)
	{
		lint tmp;
		cin >> tmp;
		x.push_back(tmp);
	}
	
	for(lint i=0;i<Q;i++)
	{
		lint dist=1e18;
		
		auto it1=lower_bound(s.begin(),s.end(),x[i]);
		auto it2=lower_bound(s.begin(),s.end(),x[i]);
		--it2;
		auto it3=lower_bound(t.begin(),t.end(),x[i]);
		auto it4=lower_bound(t.begin(),t.end(),x[i]);
		--it4;
		
		dist=min(dist,abs(x[i]-*it1)+abs(*it1-*it3));
		dist=min(dist,abs(x[i]-*it1)+abs(*it1-*it4));
		dist=min(dist,abs(x[i]-*it2)+abs(*it2-*it3));
		dist=min(dist,abs(x[i]-*it2)+abs(*it2-*it4));
		dist=min(dist,abs(x[i]-*it3)+abs(*it3-*it1));
		dist=min(dist,abs(x[i]-*it3)+abs(*it3-*it2));
		dist=min(dist,abs(x[i]-*it4)+abs(*it4-*it1));
		dist=min(dist,abs(x[i]-*it4)+abs(*it4-*it2));
		
		cout << dist << endl;
	}
	return 0;
}



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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int w, h;
    cin>>h>>w;
    ll arr[h][w];
    for(int i=0; i<h; i++) for (int j=0; j<w; j++) arr[i][j]=0;
    arr[0][0]=1;
    string c[h];
	for(int i=0; i<h; i++) cin>>c[i];
	for(int i=0; i<h; i++)
	{
		for(int j=0; j<w; j++)
		{
			if(c[i][j]=='.') 
			{
				if(i-1>=0) arr[i][j]+=arr[i-1][j];
				if(j-1>=0) arr[i][j]+=arr[i][j-1];
				arr[i][j]%=M;
			}
		}
	}
	cout<<arr[h-1][w-1];

    return 0;
}
 

Measured memory_bytes: 9088
n,m,d=map(int, input().split())
ans=0
if n-2*d>0:
    b=n-2*d
    a=2*d
else:
    a=(n-d)*2
    b=0
x1=(2*b+a)/(n**2)
if d!=0:
    ans=x1*(m-1)
else:
    ans=x1*(m-1)/2
print(ans)

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

int m,n;
int p[1001][2];

bool searchP(int x,int y){
	for(int i=0;i<n;i++){
		if(p[i][0]==x && p[i][1]==y) return true;
	}
	return false;
}

int main(void){
	int m;

	while(cin>>m && m){
		int i,j;
		int x,y,dx,dy;
		int dist[m-1][2];
		cin>>dx>>dy;
		for(int i=0;i<m-1;i++){
			cin>>x>>y;
			dist[i][0] = x - dx;
			dist[i][1] = y - dy;
		}

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

		for(i=0;i<n;i++){
			for(j=0;j<m-1;j++){
				if(!searchP(p[i][0]+dist[j][0],p[i][1]+dist[j][1])) break;
			}
			if(j == m-1) break;
		}

		cout<<p[i][0]-dx<<" "<<p[i][1]-dy<<endl;
	}

	return 0;
}

Measured memory_bytes: 876
#include<iostream>

using namespace std;

int main(){
  int n,N[200000]={0},T;
  cin >> n >> T;
  for (int i=0;i<n;i++){
    cin >> N[i];
  }
  int oyu=0;
  for(int i=0;i<n-1;i++){
    if ((N[i+1]-N[i])>=T) oyu += T;
    else oyu += (N[i+1]-N[i]);
    //cout << oyu << endl;
  }
  oyu += T;
  cout << oyu << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  int n, k;
  cin>>n>>k;
  string s;
  cin>>s;
  s = '$' + s + '$';
  deque<int> p, q;
  REP(i,n+1) {
    if (s[i] != s[i+1]) {
      if (s[i] == '1' || s[i+1] == '0') {
        p.push_back(i);
      } else {
        q.push_back(i);
      }
    }
  }
  if (p.size() <= k) {
    cout << n << endl;
  } else {
    int mx = 0;
    if (p[0] < q[0]) {
      q.push_front(0);
    }
    p.push_back(n);
    REP(i,p.size()) {
      if (i+k < p.size()) {
        mx = max(mx, p[i+k] - q[i]);
      }
    }
    cout << mx << endl;
  }
  return 0;
}


Measured memory_bytes: 764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N;
        int[] A;
        int[] maxL, maxR;

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            A = in.nextIntArray(N);
            maxL = new int[N];
            maxR = new int[N];

            int tmp = -1;
            for (int i = 0; i < N; ++i) {
                tmp = Math.max(tmp, A[i]);
                maxL[i] = tmp;
            }

            tmp = -1;
            for (int i = N - 1; i >= 0; --i) {
                tmp = Math.max(tmp, A[i]);
                maxR[i] = tmp;
            }

            for (int i = 0; i < N; ++i) {
                int ans;
                if (i == 0) {
                    ans = maxR[i + 1];
                } else if (i == N - 1) {
                    ans = maxL[i - 1];
                } else {
                    ans = Math.max(maxL[i - 1], maxR[i + 1]);
                }
                out.println(ans);
            }
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 47624
# python3

#===============================================================================
from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout

def ilist():
    return [int(x) for x in stdin.readline().strip().split(" ")]
def iint():
    return int(stdin.readline().strip())
def istr():
    return stdin.readline().strip()
##==============================================================================


def solve():
    pass


if __name__ == '__main__':
    s = istr()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")


Measured memory_bytes: 67540
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define fr(i,b,e) for(int i=(b); i<(e); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long int li;
typedef long long ll;
const int INF=1000000;


int main(void){
    string s;
    cin >> s;
    string t=s;
    reverse(all(t));
    bool check=false;
    if(s==t){
        string l;
        string r;
    
        int n=s.length();
        l=s.substr(0,(n-1)/2);
        r=s.substr((n+1)/2);
        if(l==r) check=true;
    }
    
    if(check==true){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


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

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;
const dd PI = 3.1415926435;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

ll pow_fast(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    if (k == 1)
    {
        return n;
    }

    if (k % 2 == 0)
    {
        ll tmp = pow_fast(n, k / 2LL);
        return tmp * tmp % MOD;
    }
    else
    {
        ll tmp = pow_fast(n, k / 2LL);
        tmp *= tmp;
        tmp %= MOD;
        return tmp * n % MOD;
    }
}

map<ll, ll> sosuu(ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            res[i] += 1;
            n /= i;
        }
    }
    if (n != 1)
    {
        res[n] += 1;
    }
    return res;
}

int main()
{
    string X;
    cin >> X;
    ll cur = 0;
    ll sum = 0;
    stack<char> stk;
    while (cur < X.size())
    {
        while (cur < X.size() && X[cur] == 'S')
        {
            stk.push('S');
            cur += 1;
        }
        while (cur < X.size() && X[cur] == 'T')
        {
            if (!stk.empty())
            {
                sum += 2;
                stk.pop();
            }
            cur += 1;
        }
    }

    cout << X.size() - sum << endl;
}

Measured memory_bytes: 640
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,k,fr,ba,po,t,frl,bal;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>t;
		if(t==1){
			po=i;
		}
	}
	k--;
	frl=po-1;
	fr=(frl+k-1)/k;
	bal=n-po;
	ba=(bal+k-1)/k;
	if((n-1+k-1)/k<fr+ba){
		cout<<(n-1+k-1)/k;
	}else{
		cout<<fr+ba<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
ll dfs(ll n) {
	if (n <= 0)return 0;
	if ((n+1) % 4 == 0) {
		return 0;
	}
	else if ((n+1) % 4 == 1) {
		return n;
	}
	else if ((n+1) % 4 == 2) {
		return (n - 1) ^ n;
	}
	else if ((n+1) % 4 == 3) {
		return n + 1;
	}
}

int main() {
	ll A, B;
	cin >> A >> B;
	ll ans = dfs(A-1) ^ dfs(B);
	cout <<ans<<endl;
	return 0;
}



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

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

using namespace std;

int64_t ans;

void dfs(string const s, int k, int64_t sum) {
  if (s.empty()) {
    if (k > 0) { return; }
    ans += sum;
    return;
  }
  int N = s.size();
  if (k + 1 <= N) {
    int64_t plus = stoll(s.substr(0, k + 1));
    dfs(s.substr(k + 1), 0, sum + plus);
  }
  if (k + 1 < N) {
    dfs(s, k + 1, sum);
  }
}

int main() {
  string s; cin >> s;
  dfs(s, 0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {

    const int INF = INT_MAX / 3;

    string S;
    cin >> S;
    reverse(all(S));
    S.push_back('0');
    int N = sz(S);
    vi cur{ 0, INF }, nex(2);
    rep(i, N) {
        rep(j, 2) {
            nex[j] = INF;
        }
        const int D = S[i] - '0';
        rep(j, 2) {
            int need = D + j;
            // 今払う
            if (need <= 9) {
                smin(nex[0], cur[j] + need);
            }
            // 後で払う
            smin(nex[1], cur[j] + 10 - need);
        }
        swap(cur, nex);
    }
    cout << cur[0] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 1948
#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 n,k;
  cin >> n >> k;
  vector <int> ans(n,0);
  rep(i,k){
    int d;
    cin >> d;
    rep(i,d){
      int a;
      cin >> a;
      ans[a-1]++;
    }
  }
  int cnt=0;
  rep(i,n)if(ans[i]==0)cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
using namespace std;
int main(){
	string z;
	int b,c;
	for(int i=0;i<9;i++){
		cin>>z>>b>>c;
		cout<<z<<" "<<b+c<<" "<<b*200+c*300<<endl;
	}
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<cctype>
#include<cstdio>
#include<string>
using namespace std;
int main(){
string num;
while(true){
cin>>num;int sum=0;

for(int i=0;i<num.size();i++){
	sum+=num[i]-'0';
}
if(sum==0)break;
cout<<sum<<endl;
}
 return 0;
}

Measured memory_bytes: 1184
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
bool used[4001];
ll fact[4001], inv_fact[4001];
ll comb(ll n, ll k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
int main() {
	int K, N;
	cin >> K >> N;
	fact[0] = 1;
	inv_fact[0] = 1;
	for (int i = 1; i <= 4000; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
	for (int i = 2; i <= 2 * K; i++) {
		memset(used, 0, sizeof(used));
		int x = 0, y = 0;
		for (int j = 1; j <= K; j++) {
			if (used[j]) continue;
			used[j] = 1;
			if (1 <= i - j && i - j <= K) {
				if (!used[i - j]) {
					used[i - j] = 1;
					y++;
				}
			}
			else {
				x++;
			}
		}
		ll ans = 0;
		for (int j = 0; j <= min(N, y); j++) {
			ll t = comb(y, j);
			(t *= mod_pow(2, j)) %= MOD;
			(t *= comb(N + x - 1, N - j)) %= MOD;
			(ans += t) %= MOD;
		}
		if (i % 2 == 0) {
			for (int j = 0; j <= min(N - 1, y); j++) {
				ll t = comb(y, j);
				(t *= mod_pow(2, j)) %= MOD;
				(t *= comb(N + x - 2, N - 1 - j)) %= MOD;
				(ans += t) %= MOD;
			}
		}
		cout << ans << endl;
	}
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;

vi g[maxn];
int deg[maxn];
bool us[maxn];

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

	rep(i, N-1) {
		int a, b;
		cin >> a >> b; --a; --b;
		g[a].pb(b); g[b].pb(a);
		++deg[a]; ++deg[b];
	}

	vi c(N);
	rep(i, N) cin >> c[i];
	sort(ALL(c));

	queue<int> que;
	rep(i, N) if (deg[i] == 1) {
		que.push(i);
	}

	vi ans(N, -1);
	int now = 0;

	while (!que.empty()) {
		int v = que.front(); que.pop();
		if (us[v]) continue;
		us[v] = 1;
		ans[v] = c[now++];
		for (int to : g[v]) {
			if (--deg[to] == 1) {
				que.push(to);
			}
		}
	}

	int M = 0;
	rep(i, N) {
		for (int to : g[i]) {
			M += min(ans[i], ans[to]);
		}
	}
	M /= 2;
	cout << M << endl;
	rep(i, N) printf("%d%c", ans[i], i == N-1 ? '\n' : ' ');

	return 0;
}

Measured memory_bytes: 3200
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
string S;
ll r,g,b;

int main() {
  INCANT;
  cin >> N;
  cin >> S;
  rep(i, N) {
    if (S[i]=='R') r++;
    if (S[i]=='G') g++;
    if (S[i]=='B') b++;
  }
  ll ans = r*g*b;
  rep(i, N-2) {
    for (int j=i+1; j<N-1; j++) {
      if (S[i]==S[j]) continue;
      int ng = 2*j-i;
      if (ng>=N) continue;
      if (S[ng]!=S[i] && S[ng]!=S[j]) ans--;
    }
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int main() {
	string s;
	cin >> s;
	
	int cnt[26] = {};
	REP(i, s.size()) cnt[s[i]-'a']++;
	
	REP(i, 26) if (cnt[i] == 0) {
		printf("%c\n", i + 'a');
		return 0;
	}
	puts("None");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9;

int a, b, c, N;
string s;

int main() {
    cin>>s;
    string ch = "KIHBRxx";
    int idx = 0;
    bool flag=true;
    REP(i,0,s.size()){
        if(s[i]==ch[idx]){
            idx++;
        }else if(s[i]=='A'){
            if(i==0||s[i-1]=='H'||s[i-1]=='B'||s[i-1]=='R'){
                continue;
            }
            flag=false;
        }else{
            flag=false;
        }
    }
    if(flag&&idx==5) p("YES");
    else p("NO");
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

char s[101010];

int main() {
    scanf("%s", s);
    int n = (int)strlen(s);
    int l = (n - 1) / 2, r = n / 2;
    int i;
    for (i=0; i <= l && s[l-i] == s[r+i] && s[l] == s[l-i]; ++i);
    printf("%d\n", n - 1 - l + i);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef struct Card {
  char suit;
  int value;
} card;

void print(card A[],int n);
void BubbleSort(card C[],int n);
void SelectionSort(card C[],int n);
int isStable(card in[],card out[],int n);


int main(void)
{
  int n,i;
  card c1[100],c2[100];

  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf(" %c %d",&c1[i].suit,&c1[i].value);
  }

  for(i = 0;i < n;i++){
    c2[i] = c1[i];
  }

  BubbleSort(c1,n);
  
  SelectionSort(c2,n);

  print(c1,n);
  puts("Stable");
  
  print(c2,n);
  
  if(isStable(c1,c2,n) == 1){
    puts("Stable");
  } else {
    puts("Not stable");
  }

  return 0;
}






void print(card A[],int n){
  int i;
  
  for(i = 0;i < n;i++){
    if(0 < i){
      printf(" ");
    }
    
    printf("%c%d",A[i].suit,A[i].value);
  }
  
  puts("");
}



void BubbleSort(card C[], int n){
  int i,j;
  card temp;
  
  for(i = 0;i < n;i++){
    for(j = n-1;j >= i+1;j--){
      if(C[j].value < C[j-1].value){
	temp =
	  C[j-1];
	C[j-1] = C[j];
	C[j] = temp;
      }
    }
  }
  
}



void SelectionSort(card C[],int n){
  int i,j;
  card temp;
  int minj;
  
  for(i = 0;i < n;i++){
    minj = i;
    
    for(j = i ;j < n;j++){
      if(C[j].value < C[minj].value){
	minj = j;
      }
    }
    
    temp = C[i];
    C[i] = C[minj];
    C[minj] = temp;
  }
  
}



int isStable(card in[],card out[],int n){  
  int i;
 
  for(i = 0;i < n;i++){
    if(in[i].suit != out[i].suit){
      return 0;
    }
  }
  
  return 1;
}



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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  REP(i, N) cin >> m[i];
  sort(m.begin(), m.end());
  int ans = 0;
  X -= accumulate(m.begin(), m.end(), 0);
  ans += N;
  ans += X / m[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,d;
	int x[11][11];

	cin>>n>>d;

	rep(i,n){
		rep(j,d){
			cin>>x[j][i];
		}
	}
	int t=0;
	int total=0;
	rep(i,n-1){
		for(int j=i+1; j<n; j++){
			t=0;
			rep(k,d){
				t+=abs((x[k][j]-x[k][i])*(x[k][j]-x[k][i]));
			}
			for(int l=1; l<4001; l++){
				if(l*l==t){
					total++;
					break;
				}
			}
		}
	}
	cout<<total<<endl;
	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
const ll mod=10e9+7;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N;
    cin>>N;
    ll ans=0;
    if(N>=10000)ans+=N-9999;
    if(N==100000)ans--;
    if(N>=1000)ans+=900;
    else if(N>=100)ans+=N-99;
    if(N>=10)ans+=9;
    else ans=N;
    cout<<ans<<endl;
    return 0;
    
}

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



int main(){
	int w,n,i;
	int a,b;
	cin>>w>>n;
	vector<int>num(w+5);
	for(i=1;i<=w;i++){
		num[i]=i;
	}
	for(i=1;i<=n;i++){
		char ch;
		cin>>a>>ch>>b;
		swap(num[a],num[b]);
	}
	for(i=1;i<=w;i++){
		cout<<num[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ll n;
vl as;
vvl dp;

ll dfso(ll m, ll d) {
    if (m == n / 2) return 0;
    if (dp[m][d] != -LINF) return dp[m][d];
    ll res = -LINF;
    chmax(res, as[m * 2 + d] + dfso(m + 1, d));
    if (d <= 1) chmax(res, as[m * 2 + d + 1] + dfso(m + 1, d + 1));
    if (d == 0) chmax(res, as[m * 2 + d + 2] + dfso(m + 1, d + 2));
    return dp[m][d] = res;
}

ll dfse(ll m, ll d) {
    if (m == n / 2) return 0;
    if (dp[m][d] != -LINF) return dp[m][d];
    ll res = -LINF;
    chmax(res, as[m * 2 + d] + dfse(m + 1, d));
    if (d == 0) chmax(res, as[m * 2 + d + 1] + dfse(m + 1, d + 1));
    return dp[m][d] = res;
}


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

    cin>>n;
    as = vl(n);
    cin>>as;
    dp = vvl(n / 2, vl(3, -LINF));
    if (n % 2) {
        cout<<dfso(0, 0)<<endl;
    }
    else {
        cout<<dfse(0, 0)<<endl;
    }
}

Measured memory_bytes: 16396
n = int(input())
cp = 26
pcp = 0
cl = 1
while n > cp:
    pcp = cp
    cl += 1
    cp += 26**cl

n -= pcp + 1
cp = 1
ans = ''
for i in range(cl):
    t = (n % (cp * 26) - n % cp) // cp
    t = max(t, 0)
    ans = chr(t + 97) + ans
    n -= t*cp
    cp *= 26
print(ans)


Measured memory_bytes: 61668
k = gets.to_i

@memo = Array.new(k + 1).map{Array.new(k + 1, 0)}
def gcdmemo(i, j)
  return @memo[i][j] if @memo[i][j] > 0
  u, v = i, j
  while (j > 0) do
    r =  i % j
    i = j
    j = r
  end
  @memo[u][v] = i
end
1.upto(k) do |i|
  1.upto(k) do |j|
    gcdmemo(i, j)
  end
end
ans = 0
1.upto(k) do |i|
  1.upto(k) do |j|
    c = @memo[i][j]
    1.upto(k) do |l|
      ans += @memo[c][l]
    end
  end
end
puts ans

Measured memory_bytes: 14424
n = int(input())
sequence = input().split(' ')
sequence = [int(x) for x in sequence]
for h in range(n - 1):
    print(format(sequence[h]) + ' ', end='')
print(sequence[n - 1])

for i in range(1, n):
    v = sequence[i]
    j = i - 1
    while j >= 0 and sequence[j] > v:
        sequence[j+1] = sequence[j]
        j -= 1
    sequence[j+1] = v
    for k in range(n-1):
        print(format(sequence[k]) + ' ', end='')
    print(sequence[n-1])

Measured memory_bytes: 8040
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000;
const char ENDL = '\n';
vector<ll> bit(5, 0);

void makebit(ll x, ll n) {
	rep(i, n) {
		if (x >= pow(2, n - 1 - i)) {
			bit[i] = 1;
			x -= pow(2, n - 1 - i);
		}
		else
			bit[i] = 0;
	}
}

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

	ll N, ini, Ans = 0;
	vector<ll> judge(5);
	judge[0] = 'M' - 'A';
	judge[1] = 'A' - 'A';
	judge[2] = 'R' - 'A';
	judge[3] = 'C' - 'A';
	judge[4] = 'H' - 'A';

	vector<ll> sub(5, 0);
	cin >> N;
	rep(i, N) {
		string S;
		cin >> S;
		ini = S[0] - 'A';
		rep(j, 5) {
			if (ini == judge[j])
				sub[j] += 1;
		}
	}

	rep(i, pow(2, 5)) {
		makebit(i, 5);
		ll er = 0, plas = 1;
		for (auto x : bit) {
			if (x == 1) er++;
		}
		if (er != 3) continue;

		rep(j, 5) {
			if (bit[j] == 1)
				plas *= sub[j];
		}
		Ans += plas;
	}
	cout << Ans << ENDL;
	return 0;
}


Measured memory_bytes: 256
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod
 
s=int(input())
mod=10**9+7

g1=[1,1]
g2=[1,1]
inverse=[0,1]
 
for i in range(2,s+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

ans=0
for i in range(1,s//3+2):
  ans+=cmb(s-2*i-1,i-1,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 65408
#include<iostream>

using namespace std;

int main(){

    int N,K,t,y;

    cin >> N >> K;

    int A[K];

    for(int i=0;i<K;i++){
        cin >> t >> y;
        if((N/2+1)<t)t=N+1-t;
        if((N/2+1)<y)y=N+1-y;
        if(t>y)t=y;
        A[i]=t%3;
        if(A[i]==0)A[i]=3;
    }
    for(int j=0;j<K;j++){
        cout << A[j] << endl;
    }


return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    string S;
    cin >> S;
    ll cnt = 0;
    if(S.size() == 1)cout << 0 << endl;
    else{
    while(S.size()){
        ll s = S.size();
        if(S[0] == S[s - 1]){
            S.erase(S.begin() + s - 1);
            S.erase(S.begin());
        }
        else if(S[0] == 'x'){
            S.erase(S.begin());
            cnt++;
        }
        else if(S[s - 1] == 'x'){
            S.erase(S.begin() + s - 1);
            cnt++;
        }
        else {
            cnt = -1;
            break;
        }
        if(S.size() == 1){
            break;
        }
    }
    cout << cnt << endl;
/*    S.erase(S.begin() + S.size() - 1);
    cout << S << endl << S.size() << endl;*/
    }
}

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

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

using namespace std;

class mint{
	static const int MOD=1e9+7; // 998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=m.inverse(); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	mint inverse()const{
		int a=x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint f(const vector<mint>& x){
	int n=x.size();
	vector<mint> sum(n+1);
	rep(i,n) sum[i+1]=sum[i]+x[i];

	mint res=0;
	rep(i,n) res+=sum[n]-sum[i+1]-mint(n-i-1)*x[i];
	return res;
}

int main(){
	int n,m; cin>>n>>m;
	vector<mint> x(n),y(m);
	rep(i,n) cin>>x[i];
	rep(i,m) cin>>y[i];

	cout<<f(x)*f(y)<<endl;

	return 0;
}


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


// int gcd(int a,int b){
//   int x = max(a,b);
//   int y = min(a,b);

//   int r;
//   do{
//     r = x % y;
//     x = y;
//     y = r;
//   }while(r!= 0);

//   return x;
// }

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

  vector<int> a(N);
  rep(i,N) cin >> a[i];


  int ans = a[0];
  for(int i=1;i<N;i++){
    ans = __gcd(ans,a[i]);
  }
  
  cout << ans << endl;
}

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

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if( (x|y) == 0 ) break;
			
			System.out.println( (1.0*x*x + 2.0*x*sqrt(1.0*y*y+1.0*x*x/4) ) );
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.buffer.readline
from math import gcd

N = int(input())
A = list(map(int, input().split()))

# Mまでの素数全列挙(エラトステネスの篩)
def primes(M):
    B = set(A)
    if (1 in B and len(A) != len(B) + A.count(1)-1) or (not 1 in B and len(A) != len(B)):
        return False
    ok = True
    is_prime = [-1 for _ in range(M+1)]
    for m in range(2, M+1):
        if is_prime[m] == -1:
            is_prime[m] = 1
            cnt = 0
            if m in B: cnt += 1
            l = 2
            while m*l <= M:
                if m*l in B:
                    cnt += 1
                is_prime[m*l] = 0
                l += 1
            if cnt > 1:
                ok = False
                break
    return ok

def check():
    k = A[0]
    for a in A:
        k = gcd(a, k)
    return k == 1

if primes(10**6):
    ans = "pairwise coprime"
elif check():
    ans = "setwise coprime"
else:
    ans = "not coprime"
print(ans)

Measured memory_bytes: 254260
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  scanf("%d",&n);
  if(n%2==0){
    vector<int> a,b;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	if(i+j!=n+1){
	  a.push_back(i);
	  b.push_back(j);
	}
      }
    }
    printf("%d\n",a.size());
    for(int i=0;i<a.size();i++){
      printf("%d %d\n",a[i],b[i]);
    }
  }
  else{
    vector<int> a,b;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	if(i+j!=n){
	  a.push_back(i);
	  b.push_back(j);
	}
      }
    }
    printf("%d\n",a.size());
    for(int i=0;i<a.size();i++){
      printf("%d %d\n",a[i],b[i]);
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

void solve(){
	/*int n;
	cin>>n;
	int ans=1;
	int res=1e18;
	int flag=0;
	for(int i=0;i<n;i++){
		int x; cin>>x;
		if(x==0){ans=0;flag=1;}
		if(x>res&&!flag){ans=-1;flag=1;}
		if(!flag){
			ans*=x;
			res=1e18/ans;
		}
	}
	cout<<ans<<endl;*/
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	if(a[0]==0) cout<<0<<endl;
	else{
		int mx=1e18;
		int ans=1;
		int flag=0;
		for(int i=0;i<n&&!flag;i++){
			if(mx/ans<a[i]){
				cout<<-1<<endl;
				return;
			}
			else{
				ans*=a[i];
			}
		}
		cout<<ans<<endl;
	}
}

int32_t main(){
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 4432
N,Q=map(int,input().split())
S=input()
TD=[tuple(input().split()) for _ in range(Q)]

def go(x):
    pos=x
    for t,d in TD:
        if pos==N: return N
        if pos==-1: return -1
        if t==S[pos]:
            if d=='L': pos-=1
            else: pos+=1
    return pos

U=N
L=-1
while U-L>1:
    x=(U+L)//2
    if go(x)==-1: L=x
    else: U=x
left=L

U=N
L=-1
while U-L>1:
    x=(U+L)//2
    if go(x)==N: U=x
    else: L=x
right=U

print(right-left-1)

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

ll n, x;
/*FUNCs=================================================*/
ll dp[51];
ll dp2[51];
ll rec_calc_range(ll n) {
    if(dp[n]!=0) return dp[n];
    if(n==1) return 5;
    ll ret = 1 + rec_calc_range(n-1) + 1 + rec_calc_range(n-1) + 1;
    return dp[n] = ret;
}
ll rec(ll n) {
    if(dp2[n]!=0) return dp2[n];
    if(n==0) return dp2[n] = 1;
    return dp2[n] = rec(n-1) + 1 + rec(n-1);
}
ll recursive(ll n, ll L, ll R) {
    if(x<L) return 0;
    else if(L<=x && x<=R) return recursive(n-1, L+1, (R+L)/2-1) + ((L+R)/2<=x?1:0) + recursive(n-1, (R+L)/2+1, R-1);
    else if(R<x) return dp2[n];
}

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    cin >> n >> x;
    ll range = rec_calc_range(n);
    ignore = rec(n);
    ll ans = recursive(n, 1, range);

//    for(int i = 0; i < 51; ++i) debug(dp2[i]);

    cout << ans << '\n';
//    debug(range);

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;
using std::string;

int digitSum(string str)
{
	int i, sum = 0, length = str.length();
	for (i = 0; i < length; i++)
		sum += atoi(str.substr(i, 1).c_str());
	return sum;
}

int main()
{
	string num;
	int sum;
	while (true)
	{
		cin >> num;
		if (num == "0") break;
		sum = digitSum(num);
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <math.h>
int hantei(int);
int main(void){
  int N,s[10000],i,count=0;
  
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&s[i]);
  }

  for(i = 0 ; i < N ; i++){
    if(hantei(s[i]) == 1) count++;
  }
  printf("%d\n",count);
  return 0;
}

int hantei(int s){
  int j;
  for(j =2 ; j <= sqrt(s) ; j++){
    if(s%j == 0) return 0;
  }
  return 1;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int a,b;
    std::deque<long long int> A;
    std::deque<long long int> B;
    for (int i=0;i<n+1;i++) {
        cin>>a;
        A.emplace_back(a);
    }
    for (int j=0;j<n;j++) {
        cin>>b;
        B.emplace_back(b);
    }
    long long int sum=0;
    long long int one=A[0],another;
    for (int k=0;k<n;k++) {
        another=A[k+1];
        if (one<=B[k]) {
            sum+=one;
            B[k]-=one;
        } else {
            sum+=B[k];
            one-=B[k];
            B[k]=0;
        }
        if (another<=B[k]) {
            sum+=another;
            another=0;
            B[k]-=another;
        } else {
            sum+=B[k];
            another-=B[k];
            B[k]=0;
        }
        one=another;
    }
    cout<<sum<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 40);

int main() {
  ll N;
  cin >> N;

  vi A(N);
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
    A[i] *= 2;
  }

  vi v1(N + 1);
  for (ll i = 0; i < N; i++) {
    v1[i + 1] = v1[i] + A[i];
  }

  vi v2(N + 1);
  for (ll i = 0; i < N; i++) {
    v2[i + 1] = v2[i] + A[N - 1 - i];
  }

  ll ans = INF;

  for (ll j = 2; (N - j) >= 2; j++) {
    // 左半分の個数がj
    // 左半分の和はv1[j]

    ll l_min = INF, l_max = 0;
    ll r_min = INF, r_max = 0;

    {
      ll k = distance(v1.begin(), lower_bound(v1.begin(), v1.end(), v1[j] / 2));

      ll tmp = INF;
      for (ll l = k - 1; l <= k + 1; l++) {
        if (l >= 1 && l < j) {
          if (abs(v1[j] - v1[l] * 2) < tmp) {
            l_min = min(v1[j] - v1[l], v1[l]);
            l_max = max(v1[j] - v1[l], v1[l]);
            tmp = abs(v1[j] - v1[l] * 2);
          }
        }
      }
    }

    {
      // 右半分の個数がN-j
      ll k = distance(v2.begin(), lower_bound(v2.begin(), v2.end(), v2[N - j] / 2));

      ll tmp = INF;
      for (ll l = k - 1; l <= k + 1; l++) {
        if (l >= 1 && l < N - j) {
          if (abs(v2[N - j] - v2[l] * 2) < tmp) {
            r_min = min(v2[N - j] - v2[l], v2[l]);
            r_max = max(v2[N - j] - v2[l], v2[l]);
            tmp = abs(v2[N - j] - v2[l] * 2);
          }
        }
      }
    }

    ans = min(ans, max(r_max, l_max) - min(l_min, r_min));
  }

  cout << ans / 2 << endl;
}

Measured memory_bytes: 4992
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

int i,j,k,n;string s;
cin>>s;n=s.length();
if(s[0]!='A') cout<<"WA";
else
{
	int f=1,c=0;
	for(i=1;i<n;i++)
	{
		if(i>=2 && i<=n-2)
		{
			if(s[i]=='C') c++;
			}
		if(int(s[i])<97 && s[i]!='C') f=0;	
	}
	if(c!=1 || s[1]=='C' || s[n-1]=='C') f=0;
	cout<<(f ? "AC" : "WA");
}




return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
typedef long long ll;

using namespace std;
int main(){
	ll n; cin >> n;
	vector<ll> A(n);
	vector<ll> B(n);
	for (ll i = 0; i < n; i++){
		cin >> A[i] >> B[i];	
	}
	ll ans = 0;
	ll tmp = 0;
	for (ll i = n-1; i >= 0; i--){
		A[i] += ans;
		tmp = B[i] -A[i] % B[i];
		ans += tmp; 
		//for (ll j = 0; j <= i; j++){
		//	A[j] += tmp;
		//}
		if (A[i] % B[i] == 0) ans -= B[i];
 
	}
 
	cout << ans << endl;
 
	
return 0;
}


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

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

  long long ans = 0;
  for(long long r = 1; r * r <= N; r++){
    if(N % r != 0){
      continue;
    }
    long long m = N / r - 1;
    if(r >= m || m <= 0){
      continue;
    }

    ans += m;
  }
  cout << ans << endl;
}


Measured memory_bytes: 888
n, m = map(int, input().split())
q = [list(map(int, input().split())) for _ in range(m)]

ans = ['0']*n
judge = [0]*n

for i in range(m):
    a_list = q[i]
    rank = a_list[0] - 1
    num = str(a_list[1])

    if judge[rank] == 0:
        judge[rank] = 1
        ans[rank] = num
    else:
        if ans[rank] == num:
            continue
        else:
            print(-1)
            exit()


if ans[0] == '0' and judge[0] == 1 and n != 1:
    print(-1)
elif ans[0] == '0' and n != 1:
    ans[0] = '1'
    print(int(''.join(ans)))
else:
    print(int(''.join(ans)))


Measured memory_bytes: 3064
MASK = (1 << 64) - 1

x = 0
def c_test(i):
    return+(x & (1 << i) > 0)
def c_set(m):
    global x
    x |= M[m]
def c_clear(m):
    global x
    m = M[m]
    x = (x | m) ^ m
def c_flip(m):
    global x
    x ^= M[m]
def c_all(m):
    m = M[m]
    return+(x & m == m)
def c_any(m):
    m = M[m]
    return+(x & m > 0)
def c_none(m):
    m = M[m]
    return+(x & m == 0)
def c_count(m):
    m = M[m]
    return bin(x & m).count('1')
def c_val(m):
    m = M[m]
    return x & m


fmap = [
    c_test,
    c_set,
    c_clear,
    c_flip,
    c_all,
    c_any,
    c_none,
    c_count,
    c_val,
]

def query(Q):
    for q in range(Q):
        t, *cmd = map(int, input().split())
        res = fmap[t](*cmd)
        if res is not None:
            yield res


M = []
N = int(input())
for i in range(N):
    k, *B = map(int, input().split())
    M.append(sum(1 << b for b in B))

Q = int(input())

print(*query(Q), sep='\n')



Measured memory_bytes: 7828