akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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


	vector<int> east(n, 0), west(n, 0);
	int x = 0;
	for (int i = 0; i < n; i++) {
		west[i] = x;
		if (s[i] == 'W') {
			x++;
		}
	}
	x = 0;
	for (int i = n-1; i >= 0; i--) {
		east[i] = x;
		if (s[i] == 'E') {
			x++;
		}
	}

	int ans = 1e9;
	for (int i = 0; i < n; i++) {
		// printf("%2d %c: %d %d\n", i, s[i], west[i], east[i]);
		ans = min(ans, west[i] + east[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
struct edge{int to,cap,rev;};
vector<edge> G[4000010];
bool used[4000010];
void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,(int)G[to].size()});
    G[to].push_back((edge){from,0,(int)G[from].size()-1});
}
int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    rep(i,0,G[v].size()){
        edge &e=G[v][i];
        if(used[e.to]==false&&e.cap>0){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int f=0;
    for(;;){
        memset(used,0,sizeof used);
        int g=dfs(s,t,1000000000);
        if(g==0)return f;
        f+=g;
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int h,w;cin>>h>>w;
    string s[h];
    rep(i,0,h)cin>>s[i];
    rep(i,0,h){
        rep(j,0,s[i].size()){
            if(s[i][j]=='.')continue;
            if(s[i][j]=='S'){
                add_edge(200,i,1000000000);
                add_edge(i,j+100,1000000000);
            }
            else if(s[i][j]=='T'){
                add_edge(i,201,1000000000);
                add_edge(i,j+100,1000000000);
            }
            else add_edge(i,j+100,1);
        }
    }
    rep(i,0,w){
        rep(j,0,h){
            if(s[j][i]=='.')continue;
            
            if(s[j][i]=='S'){
                add_edge(200,i+100,1000000000);
                add_edge(i+100,j,1000000000);
            }
            else if(s[j][i]=='T'){
                add_edge(i+100,201,1000000000);
                add_edge(i+100,j,1000000000);
            }
            else add_edge(i+100,j,1);
        }
    }
    int ans=max_flow(200,201);
    if(ans>=1000000)cout<<-1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 98560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    long int mod = 1000000007;
    long int n, k;
    cin >> n >> k;
    long int ans = 0;
    long int mn = 0;
    long int mx = 0;
    for (long int i = 0; i < k; i++){
        mn += i;
    }
    for (long int i = n - k + 1; i <= n; i++){
        mx += i;
    }
    ans += (mx - mn + 1) % mod;
    for (int i = k + 1; i <= n + 1; i++){
        mn += i - 1;
        mx += n - i + 1;
        ans += (mx - mn + 1) % mod;
        ans %= mod;
    }
    

    // cout << mn << " " << mx << endl;
    cout << ans << endl;

    

}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   string s,t,sd;
   cin >> s >> t;
   for (int i= 0;i < s.size();i++){
      s = s[s.size()-1] + s;
      s.erase(s.size()-1);
      if (s == t){
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
   return 0; 

}


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

typedef long long int ll;

ll n;
ll dp[2+ll(1e5)][15];
ll bigmod = 1e9+7;
vector <ll> vec;

ll power(ll a,ll b,ll md)
{
    ll r = 1;
    while(b>0){
        if(b%2==1){
            r = (r*a)%md;
        }
        a = (a*a)%md;
        b = b/2;
    }
    return r;
}

ll solve(ll idx,ll mod)
{
    //cout<<idx<<" "<<mod<<endl;
    if(idx==n)
    {
        if(mod==5)return 1;
        return 0;
    }

    if(dp[idx][mod]==-1)
    {
        ll val = 0;
        for(ll i=0;i<10;i++)
        {
            val = (val+solve(idx+1,(mod+i*power(10,vec[idx],13))%13)+bigmod)%bigmod;
        }
        dp[idx][mod] = val;
    }
    return dp[idx][mod];

}

int main()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    string s;
    cin>>s;
    n = 0;
    ll sum = 0;
    ll j =s.size();

    for(ll i=0;i<s.size();++i){
        j--;
        if(s[i]=='?'){
            vec.push_back(j);
            sum = (sum*10)%13;
        }
        else
        sum = (sum*10+(s[i]-'0'))%13;
    }
    n = vec.size();
    //cout<<sum<<endl;
    cout<<solve(0,sum);



}


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

int main() {
  int n;
  cin >> n;
  
  int n1 = n / 1000;
  int n2 = n / 100 % 10;
  int n3 = n / 10 % 10;
  int n4 = n % 10;
  
  if (n1 == n2 && n2 == n3
      || n2 == n3 && n3 == n4) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3568
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 998244353;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long modMult(long long a, long long b, long long m) {
  long long res = 0;
  long long exp = a % m;
  while (b) {
    if (b & 1) {
      res += exp;
      if (res > m) res -= m;
    }
    exp <<= 1;
    if (exp > m) exp -= m;
    b >>= 1;
  }
  return res;
}
long long powMod(long long a, long long b, long long m) {
  long long res = 1;
  long long exp = a % m;
  while (b) {
    if (b & 1) res = modMult(res, exp, m);
    exp = modMult(exp, exp, m);
    b >>= 1;
  }
  return res;
}
const int MAX = 1e7;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long COM_smallK(ll n, ll k)
{
    ll res = 1;
    rep3(i, n - k + 1, n + 1)
    {
        res *= i;
        res %= MOD;
    }
    return res * finv[k] % MOD;
}
//powMod(a,b,MOD)
//O(log(b))?
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,m,k;
    cin>>n>>m>>k;
    COMinit();
    ll res=0;
    rep(i,k+1){
        ll temp=COM(n-1,i)*m;
        temp%=MOD;
        temp*=powMod(m-1,n-i-1,MOD);
        temp%=MOD;
        res+=temp;
        res%=MOD;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 238028
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1LL<<60;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}


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


///////////////////////////////////////////////////////////////////////////////////

int main(){
    int x;
    cin >> x;
    if (x == 0){
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cctype>
using namespace std;
const int N=2e5;
int n,k,hea,tai;
bool arr[N*6+1],rev;
int main()
{
	scanf("%d%d",&n,&k);
	hea=n,tai=1;
	for(int i=1;i<=n;++i) {
		char c=getchar();
		while(!isalpha(c)) {
			c=getchar();
		}
		arr[i]=c=='A';
	}
	for(int i=1;(i<=n*5)&&(i<=k);++i) {
		if(arr[tai]^rev) {
			arr[tai]^=1;
		} else {
			arr[++hea]=arr[tai++];
			rev^=1;
		}
	}
	if(k>n*5) {
		k-=n*5;
		if(arr[tai]^rev) {
			putchar(k&1?'B':'A');
			for(int i=2;i<=n;++i) {
				putchar(i&1?'A':'B');
			}
		} else {
			for(int i=1;i<=n;++i) {
				putchar(i&1?'B':'A');
			}
		}
	} else {
		for(int i=tai;i<=hea;++i) {
			putchar(arr[i]^rev?'A':'B');
		}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2736
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int _=2005;
const int mod=1e9+7;
inline int read()
{
	char ch='!';int z=1,num=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')z=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=(num<<3)+(num<<1)+ch-'0',ch=getchar();
	return z*num;
}
int n,k,f[_][_];
void add(int &a,int b){a+=b;if(a>=mod)a-=mod;}
const int N=2000*2000;
int jc[N+5],inv[N+5];
int ksm(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)r=1ll*r*a%mod;return r;}
void Pre(){inv[0]=jc[0]=1;for(int i=1;i<=N;++i)jc[i]=1ll*jc[i-1]*i%mod,inv[i]=ksm(jc[i],mod-2);}
int C(int A,int B)
{
	if(A<B)return 0;
	return 1ll*jc[A]*inv[B]%mod*inv[A-B]%mod;
}
int main()
{
	Pre();
	n=read(),k=read();
	if(k==1)return puts("1"),0;
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
		{
			add(f[i][j],f[i-1][j]);
			if(j)add(f[i][j],1ll*f[i][j-1]*C(n-i+(n-j+1)*(k-1)-1,k-2)%mod*(n-j+1)%mod);
		}
	printf("%d\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 47104
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>a>>b>>c;
    if(a==b)printa(c);
    else if(a==c)printa(b);
    else if(b==c)printa(a);
    return 0;
}

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

int main(){
  int A,B;
  cin >> A >> B;
  int p,q,r=-1;
  long long out;
  if(A>B){
    p=A; q=B;
  }else{
    p=B; q=A;
  }
  while(r!=0){
    r = p%q;
    p = q;
    q = r;
  }
  out = A/p;
  out *= B;
  cout << out << endl;
  
  return 0;
}

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

int a[200010],b[200010],n,val[200010],l,r,mid,ans,fp,nwp;
long long nw,sum[200010],nww,fa,fb,nwa,nwb;

long long gcd(long long a,long long b) {return (!b)?a:gcd(b,a%b);}

int main()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d%d",&a[i],&b[i]),val[i]=max(a[i],b[i]),nw+=min(a[i]-b[i],0);
	sort(val+1,val+1+n),sum[0]=0,fp=0,fa=0,fb=1;
	for (int i=1; i<=n; i++) sum[i]=sum[i-1]+val[i];
	for (int i=1; i<=n; i++)
	{
		l=1,r=n,ans=0,nww=(a[i]<b[i]?nw:nw+a[i]-b[i]);
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (sum[mid]-(max(a[i],b[i])<=val[mid]?max(a[i],b[i]):0)+nww<=0) ans=mid,l=mid+1; else r=mid-1;
		}
		nww=nww-(a[i]-b[i])+sum[ans]-(max(a[i],b[i])<=val[ans]?max(a[i],b[i]):0);
		nwp=ans-(max(a[i],b[i])<=val[ans]);
		nwa=b[i]-(a[i]+nww),nwb=b[i];
		if (nwp>fp||nwp==fp&&nwa*fb>nwb*fa) fp=nwp,fa=nwa,fb=nwb;
	}
	fa+=fp*fb,fb*=n;
	long long g=gcd(fa,fb);
	printf("%lld %lld\n",fa/g,fb/g);
	return 0;
}

Measured memory_bytes: 2176
/*
[tenka1-2018] F - Circular
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 300000;
const ll MOD = 998244353;

int N;
int A[MAX_N * 2];
int b[MAX_N * 2];

ll solve() {
    if (count(A, A + N, 0) == 0) {
        return 0;
    }
    if (count(A, A + N, 0) == N) {
        ll ans = 1;
        for (int i = 1; i <= N; i++) {
            (ans *= i) %= MOD;
        }
        return ans;
    }

    vector<int> pos[MAX_N];
    for (int j = 0; j < N; j++) {
        if (A[j] == 0 && A[(j + N - 1) % N] > 0) {
            for (int i = 0; i < 2 * N; i++) {
                b[i] = A[(i + j) % N];
            }
            for (int i = 0; i < 2 * N; i++) {
                A[i] = b[i];
            }
            for (int i = 0; i < N; i++) {
                pos[A[i]].push_back(i);
            }
            break;
        }
    }

    ll ans = 1;
    set<int> empty, unused;
    ll rem = 0;
    for (int i = 0; i < N; i++) {
        empty.insert(i);
        empty.insert(i + N);
    }
    empty.insert(3 * N);

    int K = pos[0].size();
    for (int i = 0; i < N; i++) {
        int size = pos[i].size();
        if (size > K) {
            return 0;
        }
        if (size == 0) {
            (ans *= rem) %= MOD;
        } else {
            int l = pos[i][0], r = pos[i].back() + 1;
            if (size != r - l) {
                return 0;
            }
            for (int p : pos[i]) {
                empty.erase(p);
                empty.erase(p + N);
                unused.insert(p);
            }
            if (A[l + N - 1] > i && A[r] > i && size < K) {
                return 0;
            }
            if (A[l + N - 1] < i && A[r] < i) {
                (ans *= K - size + 1) %= MOD;
            }

            auto itr = unused.lower_bound(l - K + 1);
            while (itr != unused.end() && *itr < r) {
                auto itr2 = empty.lower_bound(*itr);
                if (*itr2 - *itr < K) {
                    itr = unused.lower_bound(*itr2);
                } else {
                    rem++;
                    itr = unused.erase(itr);
                }
            }
        }
        rem--;
    }

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 51456
def f(ans, c_num, h, w):
    s1, s2 = divide(h, w - c_num)
    # print("ss")
    # print(s1, s2)
    return min(ans, max([c_num * h, s1, s2]) - min([c_num * h, s1, s2]))


def divide(h, w):
    if (h % 2 == 0) or (w % 2 ==0):
        return h * w // 2, h * w // 2

    else:
        return min(w, h) * (max(w, h) // 2), min(w, h) * (max(w, h) // 2 + 1)


h, w = map(int, input().split())
ideal_s = h * w // 3

ans = float("inf")
c_num = 0
count = 0

while True:
    c_num += 1
    count += h

    if count >= ideal_s:
        break

c_num_1 = c_num - 1
c_num_2 = c_num

# print(c_num_1, c_num_2)

ans = f(ans, c_num_1, h, w)
ans = f(ans, c_num_2, h, w)

hh = h
h = w
w = hh

c_num = 0
count = 0

while True:
    c_num += 1
    count += h

    if count >= ideal_s:
        break

c_num_1 = c_num - 1
c_num_2 = c_num

# print(c_num_1, c_num_2)

ans = f(ans, c_num_1, h, w)
ans = f(ans, c_num_2, h, w)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const ll N = 105, MOD = 1e9 + 7;

ll n, m;

ll a[N], b[N];

ll dp[N][2][2][2];

ll ans;


main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    ll L, R;
    cin >> L >> R;
    ll x = L;
    while (x){
        a[++n] = x % 2;
        x /= 2;
    }
    x = R;
    while (x){
        b[++m] = x % 2;
        x /= 2;
    }
    n = max (n, m);
    m = n;
    reverse (a + 1, a + n + 1);
    reverse (b + 1, b + n + 1);
    for (ll I = 1; a[I - 1] == 0; I++){
        for (ll i = 1; i <= n; i++)
        for (ll a1 = 0; a1 < 2; a1++)
        for (ll a2 = 0; a2 < 2; a2++)
        for (ll a3 = 0; a3 < 2; a3++)
        dp[i][a1][a2][a3] = 0;
        int a1 = 0, a2 = 0, a3 = 0;
        if (a[I] == 0)
            a2 = 1;
        if (I > 1)
            a3 = 1;
        dp[I][a1][a2][a3] = 1;
        for (int i = I; i < n; i++)
        for (ll a1 = 0; a1 < 2; a1++)
        for (ll a2 = 0; a2 < 2; a2++)
        for (ll a3 = 0; a3 < 2; a3++){
            int b1 = 0, b2 = 0, b3 = 0;
            int j = i + 1;
            for (int x = 0; x < 2; x++)
                for (int y = x; y < 2; y++){
                    int b1 = a1, b2 = a2, b3 = a3;
                    if (a2 == 0 && x < a[j])
                        continue;
                    if (a3 == 0 && y > b[j])
                        continue;
                    if (a1 == 0 && x < y)
                        b1 = 1;
                    if (a2 == 0 && x > a[j])
                        b2 = 1;
                    if (a3 == 0 && y < b[j])
                        b3 = 1;
                    dp[j][b1][b2][b3] += dp[i][a1][a2][a3];
                    dp[j][b1][b2][b3] %= MOD;
                }
        }
        for (ll i = n; i <= n; i++)
        for (ll a1 = 0; a1 < 2; a1++)
        for (ll a2 = 0; a2 < 2; a2++)
        for (ll a3 = 0; a3 < 2; a3++)
            ans = (ans + dp[i][a1][a2][a3]) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;

const ll MOD = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m+2);
    for(int i=1; i<=m; i++) cin >> a[i];
    a[0] = -1;
    a[m+1] = n+1;
    vector<ll> mfib(100001);
    mfib[0] = 1;
    mfib[1] = 1;
    for(int i=2; i<=100000; i++){
        mfib[i] = ((mfib[i-1]%MOD) + (mfib[i-2]%MOD))%MOD;
    }
    ll ans = 1;
    for(int i=0; i<=m; i++){
        int dif = a[i+1]-a[i]-2;
        if(dif==-1) {
            cout << 0 << endl;
            return 0;
        }
        ans *= mfib[dif];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
vector<i64> s;
i64 X;

i64 dp[202][101010];

const i64 M = 1e9 + 7;

int main() {
  cin >> N;
  cin >> X;
  s.resize(N);
  rep(i,0,N - 1) cin >> s[i]; 

  sort(all(s));
  dp[N][X] = 1;
  for(int i = N - 1;i >= 1;i--) {
    for(i64 x = 0;x < 101010;x++) {
      //use
      (dp[i][x % s[i]] += dp[i + 1][x]) %= M;
      //not use
      (dp[i][x] += dp[i + 1][x] * i % M) %= M;
    }
  }

  i64 ans = 0;

  for(i64 x = 0;x < 101010;x++) {
    (ans += (dp[1][x] * (x % s[0])) % M) %= M;
  }
  cout << ans << endl;
}


Measured memory_bytes: 157312
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
  string s;
  cin >> s;
  cout << (char)s[0] << s.size() - 2 << (char)s[s.size() - 1] << endl;
}


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

using namespace std;
vector<int> primes;

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

void prime_list(){
  primes.push_back(2);
  for(int i=3;i<=1000009;i+=2){
    int tmp = primes.size();
    for(int j=0;primes[j]*primes[j]<=i;j++){
      if(i%primes[j]==0)break;
      if(j==tmp-1)primes.push_back(i);
    }
  }
}

int main(){
  long long a, b, lgcd, cnt=0;
  cin >> a >> b;
  lgcd = gcd(a, b);
  for(long long i=2;i*i<=lgcd;i++){
    if(lgcd%i==0)cnt++;
    while(lgcd%i==0)lgcd/=i;
  }
  if(lgcd!=1)cnt++;
  cout << cnt+1 << endl;
}

Measured memory_bytes: 256
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
function be_able_to_reach($from, $to)
{
  $time = $to[0] - $from[0];
  $distance = abs($to[1] - $from[1]) + abs($to[2] - $from[2]);
  #var_dump($time,$distance);
  if($distance > $time) return false;
  if($distance % 2 == 0 && $time % 2 == 0) return true;
  if($distance % 2 == 1 && $time % 2 == 1) return true;
  return false;
}

$scan = new Scanner();
$r = $scan->nextInt();
$D = $scan->nextInt();
$x = $scan->nextInt();
for($n = 0; $n < 10; $n++)
{
  $x = $x * $r - $D;
  printf("%d\n", $x);
}


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

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N+1, 0);
    //iの書かれた箱に入れるボールの個数（0 or 1）
    vector<int> b(N+1, 0);
    for(int i = 1; i < N+1; i++) cin >> a[i];

    for(int i = N; i >= 1; i--){
        //iの倍数の箱に入っているボールの総数
        int sum = 0;
        //自分(i)より大きなiの倍数が存在するならば、それらの箱に入っているボールの総数を見る
        for(int j = i+i; j <= N; j+=i){
            sum ^= b[j];
        }
        //sum = 0, a[i] = 1の場合にb[i] = 1が格納される。
        //sum = 1, a[i] = 0の場合は問題設定的に考えられない
        //sum = 1 && a[i] = 1 または、sum = 0, a[i] = 0の時にb[i] = 0が格納される
        b[i] = sum ^ a[i];
    }
    vector<int> ans;
    //b[i]に1が入っている場合は、その箱の番号(i)を答えを出力するための配列ansに格納
    for(int i = 1; i < N+1; i++){
        if(b[i]) ans.push_back(i);
    }
    //答えを出力
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 5328
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    if(X >= 30)cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int a, b, c, d;cin>>a>>b>>c>>d;
  cout<<(( abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d) )?"Yes":"No")<<endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

void solve(){
    int N;
    cin >> N;

    vi nums(N, 0);
    int A;
    for (int i = 0; i < N; i++) {
        cin >> A;
        nums[A]++;

        if (nums[A] > 2) {
            cout << 0 << endl;
            return;
        }
    }

    ll ans = 1;
    for (int i = 1; i < N; i++) {
        if (nums[i] == 2) {
            ans = ans * 2 % 1000000007;
        }else if (nums[i] == 1) {
            cout << 0 << endl;
            return;
        }
    }


    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

void solve() {
  int x;
  cin>>x;
  if(x>=400 && x<=599)
    cout<<8;
  else if(x>=600 && x<=799)
    cout<<7;
  else if(x>=800 && x<=999)
    cout<<6;
  else if(x>=1000 && x<=1199)
    cout<<5;
  else if(x>=1200 && x<=1399)
    cout<<4;
  else if(x>=1400 && x<=1599)
    cout<<3;
  else if(x>=1600 && x<=1799)
    cout<<2;
  else
    cout<<1;
}

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


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int A,B;
	cin >> A >> B;

	int ans = 0;
	if (A <= 5){
		ans = 0;
	} else if (A <= 12) {
		ans = B / 2;
	} else {
		ans = B;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n; cin >> n;
    map<string,int>m;
    rep(i,n){
        string s; cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3632
def main():
    import math
    s = int(input())
    mod = 10**9+7
    c = s//3
    ans = 0
    for i in range(1,c+1):
        l = s - i*3
        ans += (math.factorial(l+i-1)//math.factorial(l)//math.factorial(i-1)) % mod
    print(ans%mod)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9052
#include <bits/stdc++.h> 
using namespace std; 
int main(){
  string s,a;
  cin>>s>>a;
  int count=0;
  for(int i=0;i<a.size();i++){
  if(s[i]!=a[i]){
    count++;
  }
  }
  cout<<count<<"\n";
  return 0;


}

Measured memory_bytes: 3912
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const LL LLINF = 1LL << 60;

int main(void) {
	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 <vector>
using namespace std;
typedef long long ll;

ll inf = 1e9+7;
class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,M;
int main(){
	while(cin >> N >> M && N>0){
		vector<ll> p2(N+1,1);
		vector<int> checked(N+1,0);
		for(int i=1;i<=N;i++) p2[i] = 2*p2[i-1]%inf;
		int a,b;
		UnionFind uf(N);
		for(int i=0;i<M;i++){
			cin >> a >> b;
			uf.unite(a,b);
		}
		ll ans = 1,num = 0;
		for(int i=1;i<=N;i++){
			if(!checked[uf.find(i)]){
				checked[uf.find(i)] = 1;
				if(uf.size(i)>=2) num++;
			}
		}
		int s = uf.compnents_number();
		if(s==1) cout << (N==1? 2:3) << endl;
		else if(s==N) cout << p2[N] << endl;
		else cout << (p2[s]+1)%inf << endl;
	}
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll r;
    cin >> r;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  float i,n,b,t,a,h,k,r=1e9;
  scanf("%f%f%f",&n,&t,&a);
  for(i=0;i<n;i++){
    scanf("%f",&h);
    k=fabsf(t-h*0.006-a);
    if(r>k){
      r=k;
      b=i;
    }
  }
  printf("%d",(int)(b+1));
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python
def modpow(x, y, mod):
    ret = 1
    z = x
    n = len(bin(y)) - 2
    for i in range(n):
        if ((y >> i) & 1):
            ret = ret * z % mod
        z = z * z % mod
    return ret

def modinv(x, mod):
    return modpow(x, mod-2, mod)

def main():
    n, m, k = map(int, input().split())
    mod = 998244353

    c1 = 1
    c2 = 1
    for i in range(1, n):
        c1 = c1 * i % mod
        if i == k:
            c2 = modinv(c1, mod)
    c3 = modinv(c1, mod)
    c3_list = [0] * (k+1)
    c3_list[k] = c3
    for i in range(k-1, -1, -1):
        c3 = c3 * (n-(k-i)) % mod
        c3_list[i] = c3
    comb = (c1 * c2 % mod) * c3_list[0] % mod

    x = m * modpow(m-1, n-k-1, mod) % mod

    ret = x * comb % mod

    for i in range(1, k+1):
        c2 =c2 * (k-i+1) % mod
        comb = (c1 * c2 % mod) * c3_list[i] % mod
        x = x * (m-1) % mod

        ret += x * comb % mod
        ret %= mod

    print(ret)


if __name__ == '__main__':
    main()


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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            List<char> input = Console.ReadLine().ToCharArray().ToList();
            int q = int.Parse(Console.ReadLine());

            for (int i = 0; i < q; i++)
            {
                string[] command = Console.ReadLine().Split(' ');
                int a = int.Parse(command[1]);
                int b = int.Parse(command[2]);

                switch (command[0])
                {
                    case "replace":
                        input.RemoveRange(a, b - a + 1);
                        input.InsertRange(a, command[3].ToCharArray());
                        break;
                    case "reverse":
                        input.Reverse(a, b - a + 1);
                        break;
                    case "print":
                        for (; a <= b; a++)
                        {
                            Console.Write(input[a]);
                        }
                        Console.WriteLine();
                        break;
                    default:
                        break;
                }
            }
        }
    }
}

Measured memory_bytes: 9492
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll W, H, x, y;

int main(){
  cin >> W >> H >> x >> y;
  int flag = 0;
  if(double(x) == W / 2.0 && double(y) == H / 2.0) flag = 1;
  cout << W * H / 2.0 << " " << flag << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
K = int(input())
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
    num = que.popleft()
    if i == K-1:
        print(num)
        break
    if num%10 == 0:
        que.append(num*10 + num%10)
        que.append(num*10 + num%10 + 1)
    elif num%10 == 9:
        que.append(num*10 + num%10 - 1)
        que.append(num*10 + num%10)
    else:
        que.append(num*10 + num%10 - 1)
        que.append(num*10 + num%10)
        que.append(num*10 + num%10 + 1)


Measured memory_bytes: 74784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[200001];
ll ans=2e14,sum[200001],INF=2e14;
int search(int l,int r,int nl,int nr)
{
    if(l==r)
        return l;
    int mid=l+r>>1;
    if(sum[nr]-sum[mid]>sum[mid]-sum[nl-1])
    {
        if(mid+1<=r&&abs(sum[nr]-sum[mid+1]-sum[mid+1]+sum[nl-1])<abs(sum[nr]-sum[mid]-sum[mid]+sum[nl-1]))
            return search(mid+1,r,nl,nr);
        else
            return mid;
    }
    else
    {
        if(mid-1>=l&&abs(sum[nr]-sum[mid-1]-sum[mid-1]+sum[nl-1])<abs(sum[nr]-sum[mid]-sum[mid]+sum[nl-1]))
            return search(l,mid-1,nl,nr);
        else
            return mid;
    }
}
ll solve(int x)
{
    ll MAX=0,MIN=INF;
    int sv1=search(1,x-1,1,x),sv2=search(x+1,n,x+1,n);
    MAX=max(max(sum[sv1],sum[x]-sum[sv1]),max(sum[sv2]-sum[x],sum[n]-sum[sv2]));
    MIN=min(min(sum[sv1],sum[x]-sum[sv1]),min(sum[sv2]-sum[x],sum[n]-sum[sv2]));
    return MAX-MIN;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    for(int i=2;i<n-1;i++)
        ans=min(ans,solve(i));
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> A(n), B(n), C(n - 1);
    for (auto &a : A) {
        cin >> a;
    }
    for (auto &b : B) {
        cin >> b;
    }
    for (auto &c : C) {
        cin >> c;
    }
    int res = 0;
    for (int i = 0; i < n-1; i++) {
        res = res + B[i];
        if ((A[i] + 1) == (A[i + 1])) {
            res = res + C[A[i] - 1];
        }
    }
    res = res + B.back();
    cout << res;
    
	return 0;
}


Measured memory_bytes: 3576
n,m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]

b = [[] for i in range(8)]

for i in range(n):
    b[0].append(a[i][0] + a[i][1] + a[i][2])
    b[1].append(a[i][0] + a[i][1] - a[i][2])
    b[2].append(a[i][0] - a[i][1] + a[i][2])
    b[3].append(a[i][0] - a[i][1] - a[i][2])
    b[4].append(-a[i][0] + a[i][1] + a[i][2])
    b[5].append(-a[i][0] + a[i][1] - a[i][2])
    b[6].append(-a[i][0] - a[i][1] + a[i][2])
    b[7].append(-a[i][0] - a[i][1] - a[i][2])

ans = 0
for i in range(8):
    b[i].sort()
    b[i].reverse()
    ans = max(ans, sum(b[i][:m]))
print(ans)






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

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

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

  vector<vector<long long>> num(4,vector<long long>(N));
  num[0][0] = 8;
  num[1][0] = 1;
  num[2][0] = 1;

  for(int i = 0;i < N-1;i++) {
    num[3][i+1] += num[1][i] + num[2][i] + num[3][i]*10;
    num[2][i+1] += num[0][i] + num[2][i]*9;
    num[1][i+1] += num[0][i] + num[1][i]*9;
    num[0][i+1] += num[0][i]*8;

    for(int j = 0;j < 4;j++) num[j][i+1] %= MOD;
    
  }

  cout << num[3][N-1] << endl;
  
}


Measured memory_bytes: 42328
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) for(auto &i:vec)fprintf(stderr,"%ld ",i);puts("");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, d;
	scanf("%d %d", &n, &d);
	std::vector<P> ab(n);
	REP(i, 0, n) scanf("%ld %ld", &ab[i].se, &ab[i].fi);
	std::sort(ALL(ab), [](P x, P y){return x.se<y.se;});
	
	ll ans = 0,  pos = 0;
	pq<P> que;
	REP(i, 0, d){
		while(pos<n and ab[pos].se<=i+1){
			que.push(ab[pos]);
			pos++;
		}
		if(que.empty()) continue;
		ans += que.top().fi;
		que.pop();
	}
	printf("%ld\n", ans);
	return 0;
}


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

int n , m;
const int N = 55;
set<int> g[N];
vector<pair<int,int>> edges;
int ans = 0;

bool vis[N];

void dfs(int node){
      vis[node] = 1;

      for(auto ch : g[node]){
            if(!vis[ch]){
                  dfs(ch);
            }
      }
}

int32_t main(){

     cin >> n >> m;

     for(int x=1;x<=m;x++){
           int u ,v;    cin >> u >> v;
           g[u].insert(v) , g[v].insert(u);
           edges.push_back({u , v});
     }

      for(auto ed : edges){
            int u = ed.first , v = ed.second;

            g[u].erase(v) , g[v].erase(u);

            int comp = 0;
            memset(vis , false , sizeof(vis));

            for(int x=1;x<=n;x++){
                  if(!vis[x]){
                        comp++;;
                        dfs(x);
                  }
            }

            ans += comp == 2;

            g[u].insert(v) , g[v].insert(u);
      }

      cout << ans << endl;

     
     return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> p(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
        p[i] = (p[i] + 1) / 2;
    }

    for (int i = 1; i <= N; i++) {
        p[i] += p[i - 1];
    }

    double ans = 0;
    for (int i = K; i <= N; i++) {
        ans = max(ans, p[i] - p[i - K]);
    }
    cout << setprecision(7) << ans << endl;
}


Measured memory_bytes: 1792
import java.util.*;
import java.util.concurrent.ThreadLocalRandom; 
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		long n=in.nextLong();
		long ans=0;
		int [] prime = new int[1000001];
		for(int i=2;i<1000001;i++)
		{
			if(prime[i]==0)
			{
				for(int j=2;i*j<1000001;j++)
				{
					prime[i*j]=1;
				}
			}
		}
		long t=n;
		for(long i=2;i*i<n;i++)
		{
			if(prime[(int)i]==0&&n%i==0)
			{
				int q=0;				
				while(t%i==0)
				{
					t=t/i;
					q++;
				}
				int j=0;
				while(j*(j+1)/2<=q)
				{
					j++;
				}
				ans=ans+j-1;
			}
		}
		if(t!=1)
		{
			ans++;
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 40576
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 305;
double dp[N][N][N];
int arr[N];

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,cnt1=0,cnt2=0,cnt3=0; cin>>n; 
    FOR(i, 0, n) {
    	cin>>arr[i];
    	if(arr[i] == 1) cnt1++;
    	else if(arr[i] == 2) cnt2++;
    	else cnt3++;
    }
    memset(dp, 0, sizeof(dp));
    FOR(k, 0, N) {
    	FOR(j, 0, N) {
    		FOR(i, 0, N) {
    			if(i + j + k == 0) continue;
    			if(i + j + k >= N) continue;

    			int l = i + j + k;
    			double wait = 1.0 * n / l;
    			double p_a = 1.0 * i / l;
    			double p_b = 1.0 * j / l;
    			double p_c = 1.0 * k / l;

    			if (i)
    			{
    				dp[i][j][k] += p_a * dp[i-1][j][k];
    			}

    			if(j) {
    				dp[i][j][k] += p_b * dp[i+1][j-1][k];
    			}

    			if(k) {
    				dp[i][j][k] += p_c * dp[i][j+1][k-1];
    			}

    			dp[i][j][k] += wait;
    		}
    	}
    }

    coud(dp[cnt1][cnt2][cnt3], 10);
    return 0;
}

Measured memory_bytes: 221952