akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
  int a[n]; rep(i,n) cin>>a[i];

  int r = 0;
  ll sum = 0, ans = 0;
  rep(l,n){
    while(r<n && (sum^a[r])==(sum+a[r])){
      sum += a[r]; r++;
    }
    ans += r-l;
    if(l==r) r++;
    else sum -= a[l];
  }
  cout << ans << endl;
  return 0;
}


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

#define ff 		first
#define ss 		second
#define ll 		long long
#define pb 		push_back
#define mp 		make_pair
#define pi 		pair<int,int>
#define vi 		vector<int>
#define pqb 	priority_queue<int>
#define pqs 	priority_queue<int,vi,greater<int>>
#define setbit(x) 	__builtin_popcountll(x)
#define mod 	1000000007
#define inf 	1e18
#define endl 	"\n"

int main() {
	ll t;
	cin >> t;
	if (t >= 30) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;

}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main(){
	int l,i;
	int m,n,sum,flg;
	while(1){
		cin>>l;
		sum=flg=0;
		if(l==0) break;
		for(i=1;i<=12;i++) {
			cin>>m>>n;
			sum+=m-n;
			if(sum>=l && flg==0) flg=i;
		}
		if(sum<l) cout<<"NA"<<endl;
		else if(flg!=0)cout<<flg<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;

vector < ll > fact(MAXN);

ll pwr(ll a, ll b){
  ll res = 1;
  while(b > 0){
    if(b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

ll inv(ll a){
  return pwr(a, mod - 2);
}

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

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

  ll n, k;
  cin >> n >> k;

  fact[0] = 1;
  for(int i = 1; i < MAXN; i++) fact[i] = (i * fact[i - 1]) % mod;

  ll ans = 0;
  for(int i = max(n - k, (ll)1); i <= n; i++){
    ans = (ans + ((comb(n - 1, i - 1) * comb(n, i)) % mod)) % mod;
  }

  cout << ans << '\n';
}


Measured memory_bytes: 1792
n = int(input())
ab=[]
for i in range(n-1):
    tmp = list(map(int,input().split()))
    ab.append(tmp)
link = [[] for _ in range(n)]
for tmp in ab:
    link[tmp[0]-1].append(tmp[1]-1)
    link[tmp[1]-1].append(tmp[0]-1)

cnt=0
for l in link:
    if cnt < len(l):
        cnt=len(l)
print(cnt)

from collections import deque
from collections import defaultdict
Q = deque()
Q.append([0,0]) # now, color
cs = defaultdict(lambda: -1)
while Q:
    now,now_color= Q.popleft()

    nxt_c=now_color
    for nxt in link[now]:
        if cs[str(now)+"_"+str(nxt)] !=-1:
            continue

        nxt_c = (nxt_c+1) % cnt
        cs[str(now)+"_"+str(nxt)] = nxt_c
        cs[str(nxt)+"_"+str(now)] = nxt_c
        Q.append([nxt,nxt_c])

for tmp in ab:
    print(cs[str(tmp[0]-1) + "_" + str(tmp[1]-1)]+1)

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

int main() 
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	fastio();

	string s;
	cin>>s;

	if( s.back() == 's' )
		s += "es";
	else 
		s += "s";
	cout<<s,nl;	

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define PI acos(-1LL)


#ifdef LOCAL
string to_string(const string& s){
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(T v){
    bool first = true;
    string res = "{";
    for(const auto& x: v){
        if(!first) res+=", ";
        first = false;
        res+=to_string(x);
    }
    res+="}";
    return res;
}
void bug() { cerr << endl; }
template<typename Head, typename... Tail>
void bug(Head H, Tail... T) {
    cerr << " " << to_string(H);
    bug(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__);
#else
#define debug(...) 11;
#endif


const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 2e17 + 12;


void solve() {
    int n;
    cin >> n;
    int a[n] , sum = 0;
    for(int i=0; i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    int ans = 0, pre = 0;
    for(int i=0; i<n; i++){
        pre+=a[i];
        ans = (ans%M + ((sum - pre)%M*a[i]%M)%M)%M;
    }
    cout << ans << endl;
}
signed main(){
    FAST
#ifdef TIMER
    clock_t start;
    double duration;
    start = clock();
#endif
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
#ifdef TIMER
    duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    cerr <<"\n\nTotal time elapsed: "<< duration <<"sec\n";
#endif
}


Measured memory_bytes: 5176
n = int(input())
l_v = [int(i) for i in input().split()]
l_c = [int(i) for i in input().split()]

t_v = []
t_c = []
for v, c in zip(l_v, l_c):
  if v > c:
    t_v.append(v)
    t_c.append(c)
    
print(sum(t_v) - sum(t_c))

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int a,b;
    cin>>a>>b;
    int sum=1,cnt=0;
    while(sum<b){
        cnt++;
        sum+=a-1;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

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


	int N, K;
	cin >> K;
	N = 3;

	ll kosuu[100001] = {};
	for (int i = K; i >= 1; i--) {
		int k = K / i;
		ll tmp = modpow(k, N);
		for (int j = i + i; j <= K; j += i) {
			tmp -= kosuu[j];
		}
		kosuu[i] = (tmp % mod + mod) % mod;
	}
	ll kotae = 0;
	rep1(i, K) {
		kotae += kosuu[i] * i % mod;
	}
	co(kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 4432
#include<cstdio>
#include<cstring>
#define fo(x,a,b) for(int x=(a),e_=(b);x<=e_;x++)
#define fd(x,a,b) for(int x=(a),e_=(b);x>=e_;x--)
#define two(x) (1<<(x))

const int N=2097153;
int f[21][N],vis[21][N],tot[N],lg[N],n,m,ans,mx;
char X[N],c[30];

int main(){
	int len,nxt,ful,w,go,dt;
	scanf("%d %d",&n,&m);
	memset(vis,-1,sizeof(vis));
	lg[0]=-1;fo(i,1,N-1) lg[i]=lg[i>>1]+1;
	fo(i,0,n) {
		len=two(i);
		scanf("%s",X);
		fo(j,0,len-1) if(X[j]=='1') vis[i][len+j]=i, f[i][len+j]=1;
//		printf("\nlen:%d\n",len);
		
		fd(z,i,1) {//zero is end state 
			ful=two(z)-1;
			fo(s,0,len+len-1) if(vis[z][s]==i) {
				tot[s>>z]+=f[z][s];
				nxt=s&ful;
//				printf("s:%d[%d] f:%d nxt:%d\n",s,z,f[z][s],nxt);
				if(nxt) {
					w=lg[nxt];
					go=((s>>z)<<(w+1)) | (s&(two(w+1)-1));//change together
					if(vis[w][go]!=i) vis[w][go]=i, f[w][go]=0;
//					printf("trans to %d[%d]\n",go,w);
					f[w][go]+=f[z][s];
				}
				nxt=ful-nxt;
				if(nxt) {
					w=lg[nxt];
					go=((s>>z)<<(w+1)) | (s&(two(w+1)-1));
					if(vis[w][go]!=i) vis[w][go]=i, f[w][go]=0;
//					printf("trans to %d[%d]\n",go,w);
					f[w][go]+=f[z][s];
				}
			}
		}
		fo(s,0,len+len-1) if(vis[0][s]==i) {
//			printf("s:%d[0] f:%d\n",s,f[0][s]);
			tot[s]+=f[0][s];
		}
	}
//	puts("");

	mx=ans=0;
	fd(s,two(n+1)-1,0) {
//		printf("s:%d tot:%d\n",s,tot[s]);
		if(tot[s]>=m && (lg[s]>mx || lg[s]==mx && s<ans)) mx=lg[s], ans=s; 
	}
//	printf("ans:%d\n",ans);

	for(len=0; ans>1; ans=ans>>1) c[++len]=(ans&1)+48;
	for(; len; len--) putchar(c[len]);
	return 0;
}


Measured memory_bytes: 354996
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int N,M;
V mul(const V &a, const V &b){
    V c(N*N);
    int i=0,j;
    for(;i<N;i++)for(j=0;j<N;j++)c[i*N+j]=(a[slice(i*N,N,1)]*b[slice(j,N,N)]).sum()%M;
    return c;
}
V exp(const V &a, const int n){
    if(n==1)return a;
    if(n&1)return mul(exp(a,n-1),a);
    V b=exp(a,n>>1);
    return mul(b,b);
}
V s,x;
void output(const V &r){
    int i=0;
    for(;i<N-1;i++)printf("%d ",(r[slice(i*N,N,1)]*s).sum()%M);
    printf("%d\n",(r[slice(i*N,N,1)]*s).sum()%M);
}
main(){
    int i,A,B,C,T;
    for(;scanf("%d%d%d%d%d%d",&N,&M,&A,&B,&C,&T),N;){
        s.resize(N);
        for(i=0;i<N;i++)scanf("%d",&s[i]);
        x.resize(0);
        x.resize(N*N);
        if(T){
            x[0]=B;
            x[1]=C;
            for(i=1;i<N-1;i++){
                x[i*N+i-1]=A;
                x[i*N+i]=B;
                x[i*N+i+1]=C;
            }
            x[i*N+i-1]=A;
            x[i*N+i]=B;
            output(exp(x,T));
        }else{
            for(i=0;i<N;i++)x[i*N+i]=1;
            output(x);
        }
    }
}

Measured memory_bytes: 1084
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
string st;
int dp[305][305][305],n,m,i,j,k;
int main(){
	cin>>st>>m;n=st.length();st=" "+st;
	rep(i,n) dp[i][i][0]=1;
	for(i=n;i>=1;i--){
		for(j=i+1;j<=n;j++){
			for(k=0;k<=m;k++){
				dp[i][j][k]=max(dp[i+1][j][k],dp[i][j-1][k]);
				if(st[i]==st[j]) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k]+2);
				if(k) dp[i][j][k]=max(dp[i][j][k],dp[i+1][j-1][k-1]+2);
			}
		}
	}
	int ans=0;
	for(k=0;k<=m;k++) ans=max(ans,dp[1][n][k]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 110464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    ll N, A, B;
    cin >> N >> A >> B;
    cout << A * (N / (A + B)) + min(A, N % (A + B)) << endl;

    return 0;
}

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

using namespace std;


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int t,k;cin>>t>>k;

	vector<int> h(t);
	for(int i=0;i<t;i++)
        cin>>h[i];

    vector<int> dp(t,INT_MAX);
    dp[0]=0;

    for(int i=1;i<t;i++){
        int first;
        for(int j=i-1;j>=max(i-k,0);j--){
            first = abs(h[i]-h[j])+dp[j];
            dp[i]=min(first,dp[i]);
        }
    }

    cout<<dp[t-1]<<'\n';

	return 0;
}


Measured memory_bytes: 3868
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;

int main(void) {
	int N;
	int a[101];
	scanf("%d", &N);
	

	for (int i = 0; i < 100; i++) {
		a[i] = 0;
	}
	for (int i = 0; 4*i <= 100; i++) {
		for (int j = 0; 4 * i + 7 * j <= 100; j++) {
			a[4 * i + 7 * j] = 1;
		}
	}
	if (a[N] == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

}









Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		int[] c = {15,15,7,2,3,-3};
		while(in.hasNext()){
			int[] a = new int[6];
			for(int i = 0; i < 6; i++) a[i] = in.nextInt();
			if(a[5] == 0) return;
			int ans = 100;
			for(int i = 0; i < 6; i++){
				ans += c[i] * a[i];
			}
			ans += (a[0] * 5 + a[1] * 3) * 16;
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 29112
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

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

  for (int i = 0; i < 8; i++) {
    int a = i >> 0 & 1;
    int b = i >> 1 & 1;
    int c = i >> 2 & 1;

    int ret = s[0] - '0';
    ret = a == 0 ? ret + (s[1] - '0') : ret - (s[1] - '0');
    ret = b == 0 ? ret + (s[2] - '0') : ret - (s[2] - '0');
    ret = c == 0 ? ret + (s[3] - '0') : ret - (s[3] - '0');

    if (ret == 7) {
      char aa = a == 0 ? '+' : '-';
      char bb = b == 0 ? '+' : '-';
      char cc = c == 0 ? '+' : '-';
      cout << s[0] << aa << s[1] << bb << s[2] << cc << s[3] << "=7" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int INF=1e9;
int a[100100];
int dp[100100][32];
int Max(int x,int y){
	return x>y?x:y;
}
int main(){
//	freopen("E.in","r",stdin);
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int cnt1,cnt;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=31;j++)
			dp[i][j]=INF;
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		cnt1=cnt=0;
		while(a[i]){
			if(a[i]&1) cnt1++;
			cnt++;
			a[i]>>=1;
		}
		cnt--,cnt1--;
		if(cnt1==0){
			for(int j=0;j<=cnt;j++)
				if(dp[i-1][j]+cnt-j<dp[i][cnt])
					dp[i][cnt]=dp[i-1][j]+cnt-j;
			for(int j=cnt+1;j<=31;j++)
				if(dp[i-1][j]<dp[i][cnt])
					dp[i][cnt]=dp[i-1][j];
		}
		else{
			dp[i][cnt+1]=dp[i-1][0]+cnt+1;
			for(int j=1;j<=cnt;j++)
			{
				if(dp[i-1][j]+cnt-j+1<dp[i][cnt])
					dp[i][cnt]=dp[i-1][j]+cnt-j+1;
				if(dp[i-1][j]+cnt-j+1<dp[i][cnt+1])
					dp[i][cnt+1]=dp[i-1][j]+cnt-j+1;
			}
			for(int j=cnt+1;j<=31;j++)
			{
				if(dp[i-1][j]<dp[i][cnt])
					dp[i][cnt]=dp[i-1][j];
				if(dp[i-1][j]+1<dp[i][cnt+1])
					dp[i][cnt+1]=dp[i-1][j]+1;
			}
		}
	}
	int ans=INF;
	for(int i=0;i<=31;i++)
		if(dp[n][i]<ans)
			ans=dp[n][i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 13056
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int Mod=1e9+7,N=200010;
int fac[N],inv[N],n,m,a,b;
int qpow(int a,int b){int ret=1;while(b){if(b&1)ret=1ll*ret*a%Mod;b>>=1;a=1ll*a*a%Mod;}return ret;}
int C(int p,int q){if(p<q || p<0 || q<0)return 0;return 1ll*fac[p]*inv[q]%Mod*inv[p-q]%Mod;}
int main(){
	n=gi();m=gi();
	a=gi();b=gi();int ans=0;fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=200000;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=200000;i++)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(int i=2;i<=200000;i++)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
	for(int i=1;i<=n-a;i++)
		ans=(ans+1ll*C(b+i-2,i-1)*C(n-i+m-b-1,n-i)%Mod)%Mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}

int main(void){
  ll n;cin>>n;
  string s;cin>>s;
  bool dp[11*11*11];
  rep(i,11*11*11){
    dp[i] = false;
  }
  dp[0] = true;
  rep(si, s.size()){
    int num = s[si] - '0' + 1;
    REP(j,11*11){
      if(dp[j]){
        dp[j*11 + num] = true;
      }
    }
  }
  ll ans = 0;
  rep(i, 11*11*11){
    if(i < 11*11) continue;
    if(dp[i]){
      //cout<<i/121<<i/11%11<<i%11<<endl;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#define MOD 1000000007
#define INF 1000000000000000000LL
#define MX 200

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;

ll A[MX],B[MX];
vector <P> gt[MX];
int sz;

void init()
{
	sz=0;
	A[sz]=1,B[sz]=0;
	sz++;
	A[sz]=2,B[sz]=1;
	sz++;
	while(1)
	{
		A[sz]=A[sz-1]+B[sz-1];
		B[sz]=A[sz-1];
		if(A[sz]>INF) break;
		sz++;
	}
	vector <P> vx;
	for(int i=0;i<sz;i++)
	{
		if(i==0)
		{
			vx.push_back(P(1,0));
			vx.push_back(P(2,0));
		}
		else if(i==1) 
		{
			vx.clear();
			vx.push_back(P(2,1));
			vx.push_back(P(3,1));
		}
		else
		{
			vector <P> nxt;
			for(int j=0;j<vx.size();j++)
			{
				P p=vx[j];
				ll a=p.second,b=p.first;
				for(int t=1;t<=2;t++)
				{
					a+=b;
					if(a>INF) break;
					if(i+1<sz&&a>=A[i+1]&&b>=B[i+1]) break;
					nxt.push_back(P(a,b));
				}
			}
			vx=nxt;
		}
		gt[i]=vx;
	}
}
P solve(ll X,ll Y)
{
	int mx=0;
	while(mx<sz)
	{
		if(A[mx]>X||B[mx]>Y) break;
		mx++;
	}
	if(mx==1)
	{
		return P(1,1);
	}
	ll ret=0;
	for(int i=0;i<gt[mx-2].size();i++)
	{
		P p=gt[mx-2][i];
		ll a=p.first,b=p.second;
		//printf("%lld %lld : %lld %lld\n",X,Y,a,b);
		swap(a,b);
		if(a<=X&&b<=Y)
		{
			ll nm=(X-a)/b;
			ret+=nm;
			ret%=MOD;
		}
	}
	return P(mx-1,ret);
}
int main()
{
	init();
	int Q;
	scanf("%d",&Q);
	while(Q--)
	{
		ll X,Y;
		scanf("%lld %lld",&X,&Y);
		P p=solve(X,Y);
		P q=solve(Y,X);
		if(p.first!=q.first) p=max(p,q);
		else
		{
			p.second+=q.second;
			if(p.second>=MOD) p.second-=MOD;
			//被るのは(x,x)の組、つまり、(1,1),(2,2)だけ
			if(p.first==1)
			{
				p.second--;
				if(X>=2&&Y>=2) p.second--;
				if(p.second<0) p.second+=MOD;
			}
		}
		printf("%lld %lld\n",p.first,p.second);
	}
	return 0;
}


Measured memory_bytes: 4096
n, m = list(map(int, input().split()))
ff_li = [0 for i in range(m)]
ans = 0
for i in range(n):
    ka = list(map(int, input().split()))
    for j in range(int(ka[0])):
        ff_li[ka[j+1] - 1] += 1
for i in ff_li:
    if i == n:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int a, b;
	cin >> a;
	cin >> b;
	
	if(a + b == 15){
		cout << " + " << endl;
	}else if(a * b == 15){
		cout << " * " << endl;
	}else{
		cout << " x " << endl;
	}
}

Measured memory_bytes: 384
import math

n = int(input())
D = list()
for _ in range(n):
    D.append(list(map(int,input().split())))
#全探索
sum_d = 0
cnt = 0
for i in range(n):
    for j in range(n):
        xx = math.sqrt((D[i][0]-D[j][0])**2+(D[i][1]-D[j][1])**2)
        sum_d += xx
        cnt += 1
print(sum_d/n)

    

    
    

Measured memory_bytes: 3060
from math import factorial
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

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

n, k = map(int, input().split())
a = sorted(map(int, input().split()))


mod = 10**9+7
def main():
  s = 0
  l = len(a)
  for i in range(l):
    s += a[i] * cmb(i, k - 1, mod)
    s -= a[i] * cmb(l - i -1 , k - 1, mod)

    s %= mod
  print(s)
main()

Measured memory_bytes: 26680
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int n, sum = 0, num1, num10, num100;

    cin >> n;

    // 1の位
    num1 = n % 10;
    if (num1 == 7)
    {
        sum++;
    }
    // 10の位
    num10 = n / 10;
    num10 = num10 % 10;
    if (num10 == 7)
    {
        sum++;
    }
    //100の位
    num100 = n / 100;
    num100 = num100 % 10;
    if (num100 == 7)
    {
        sum++;
    }

    if (sum > 0)
    {
        printf("Yes");
    }
    if (sum == 0)
    {
        printf("No");
    }
}


Measured memory_bytes: 3652
#include <stdio.h>

#define MAX 2000000

int N[MAX + 1];
int H = 0;

void maxHeapify(int index) {
    int l = index * 2;
    int r = l + 1;

    // find max
    int maxIndex = index;
    if (l <= H && N[index] < N[l]) maxIndex = l;
    if (r <= H && N[maxIndex] < N[r]) maxIndex = r;

    // swap
    if (maxIndex != index) {
        int temp = N[index];
        N[index] = N[maxIndex];
        N[maxIndex] = temp;
        maxHeapify(maxIndex);
    }
}

void heapIncreaseKey(int index) {
    if (index < 2) return;

    int parent = index / 2;
    if (N[index] > N[parent]) {
        int temp = N[index];
        N[index] = N[parent];
        N[parent] = temp;
        heapIncreaseKey(parent);
    }
}

int main() {
    char str[64];
    int value;

    while(1) {
        scanf("%s", str);

        if (str[0] == 'i' && str[1] == 'n') {
            // insert
            scanf("%d", &value);
            N[++H] = value;
            if (H > 1) heapIncreaseKey(H);

        } else if (str[0] == 'e' && str[1] == 'x') {
            // extract
            printf("%d\n", N[1]);
            N[1] = N[H--];
            maxHeapify(1);

        } else break;
    }

    return 0;
}



Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

signed main(){

  int n,q;

  priority_queue<P2,vector<P2>,greater<P2> >ib;

  cin>>n>>q;
  vector<int>Z;
  vector<P2>v;
  r(i,n){
    int s,t,x;
    scanf("%d%d%d",&s,&t,&x);
    s-=x;
    t-=x;
    s=max(0,s);
    if(t<0)continue;
    ib.push(P2(s,P(1,x)));
    ib.push(P2(t,P(-1,x)));
  }

  set<int>st;

  for(int i=0;i<q;i++){
    int x;
    cin>>x;
    while(!ib.empty() && ib.top().F<=x){
      P2 p=ib.top();ib.pop();
      if(p.S.F==1)st.insert(p.S.S);
      else st.erase(p.S.S);
    }
    if(st.size())cout<<*st.begin()<<endl;
    else cout<<-1<<endl;
  }


}

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

int main(void)
{
    int  n;
    cin >> n;
    vector<int> c(n);
    vector<int> v(n);
    for(int i = 0; i < n;i++) cin >> v[i];
    for(int i = 0; i < n;i++) cin >> c[i];

    int ans = 0;
    for(int i = 0; i < n; i++){
        if (c[i] < v[i]) ans += v[i] - c[i];
    }

    cout << ans << endl;
    return 0;
}

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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int W, H, N;
    cin >> W >> H >> N;
    vector<pair<int, int>> p(N);
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i].first >> p[i].second >> a[i];
    }
    int minX = 0, minY = 0, maxX = W, maxY = H;
    for (int i = 0; i < N; i++) {
        switch (a[i])
        {
        case 1: minX = max(minX,p[i].first);
            break;
        case 2: maxX = min(maxX,p[i].first);
            break;
        case 3: minY = max(minY,p[i].second);
            break;
        case 4: maxY = min(maxY, p[i].second);
            break;
        default:
            break;
        }
    }
    cout << max((maxX - minX), 0) * max((maxY - minY) , 0) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,k;
int dp[100005];
int h[100005];
int main() {
	scanf("%d%d",&n,&k);
	for(int i=0; i<n; i++) {
		scanf("%d",&h[i]); 
	} 
	for(int i=1; i<n; i++) {
		dp[i]=2000000000;
		for(int j=max(0,i-k); j<i; j++) {
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	printf("%d\n",dp[n-1]);
}

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

int main(){
    int l;
    cin >> l;
    string a,b;
    cin >> a >> b;
    string f ="";
    for(int i=0;i<l;i++){
        f+=a[i];
        f+=b[i];
    }
    cout << f;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define UMap        std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd   ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm   ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs   ( llong n )          { return ( n < 0 ) ? -n : n; }
    template<class A, class B>inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B>inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        if ( n == 3 || n == 5 || n == 7 ) echo "YES";
        else echo "NO";
        echo endl;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); echo std::fixed << std::setprecision(8); int main_result = Rlyeh::call_of_Cthulhu(114514); return main_result;}


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

signed main() {
    int A, B;
    cin >> A >> B;
    
    if (A % 2 == 0 && B % 2 == 0) {
        int C = (B - A) / 2;
        if (C % 2 == 0) cout << B << endl;
        else cout << (B ^ 1) << endl;
    }
    if (A % 2 == 0 && B % 2 == 1) {
        int C = (B - A) / 2 + 1;
        if (C % 2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
    if (A % 2 == 1 && B % 2 == 0) {
        int C = (B - A) / 2;
        if (C % 2 == 0) cout << (A ^ B) << endl;
        else cout << (A ^ B ^ 1) << endl;
    }
    if (A % 2 == 1 && B % 2 == 1) {
        int C = (B - A) / 2;
        if (C % 2 == 0) cout << A << endl;
        else cout << (A ^ 1) << endl;
    }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

AtoZ = [chr(i) for i in range(65,65+26)]
ItoC = defaultdict(str)
for i, x in enumerate(AtoZ):
    ItoC[x] = i

N = int(input())
S = input()
T = ''
for x in S:
    T += AtoZ[(ItoC[x]+N)%26]
print(T)


Measured memory_bytes: 40540
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int v = int.Parse(str[0]);
        int e = int.Parse(str[1]);
        int r = int.Parse(str[2]);
        int[] f = new int[e];
        int[] t = new int[e];
        long[] cost = new long[e];
        for(int i=0;i<e;i++){
            str = Console.ReadLine().Split(' ');
            f[i] = int.Parse(str[0]);
            t[i] = int.Parse(str[1]);
            cost[i] = int.Parse(str[2]);
        }
        BellmanFord B = new BellmanFord(f,t,cost,v,r,10000000000);
        if(B.NegativeCycle()){
            sb.Append("NEGATIVE CYCLE\n");
        }
        else{
            for(int i=0;i<v;i++){
                if(B.GetCost(i) == 10000000000){
                    sb.Append("INF\n");
                }
                else{
                    sb.Append(B.GetCost(i)+"\n");
                }
            }
        }
    }
}
class BellmanFord{
    bool NEGATIVECYCLE;
    long[] cost;
    public BellmanFord(int[] f,int[] t,long[] c,int n,int s,long INF){
        cost = new long[n];
        int e = f.Length;
        for(int i=0;i<n;i++){
            cost[i] = INF;
        }
        cost[s] = 0;
        for(int i=0;i<n-1;i++){
            for(int j=0;j<e;j++){
                if(cost[f[j]] != INF){
                    cost[t[j]] = Math.Min(cost[t[j]],cost[f[j]]+c[j]);
                }
            }
        }
        NEGATIVECYCLE = false;
        for(int i=0;i<e;i++){
            if(cost[f[i]] != INF && cost[f[i]]+c[i] < cost[t[i]]){
                NEGATIVECYCLE = true;
            }
        }
    }
    public bool NegativeCycle(){
        return NEGATIVECYCLE;
    }
    public long GetCost(int v){
        return cost[v];
    }
}

Measured memory_bytes: 9380
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

def rec(i,a,b,c):
    if i == N:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return 10**10
    # 今の竹を使わない場合
    ret0 = rec(i+1,a,b,c)
    # 今の竹をAの竹に使う
    ret1 = rec(i+1,a+L[i],b,c) + 10
    # 今の竹をBの竹に使う
    ret2 = rec(i+1,a,b+L[i],c) + 10
    #　今の竹をCの竹に使う
    ret3 = rec(i+1,a,b,c+L[i]) + 10
    return min(ret0,ret1,ret2,ret3)

print(rec(0,0,0,0))


Measured memory_bytes: 3064
N = int(input())
A =[int(x) for x in input().split()]

sum = 0
for i in range(N):
  sum+=A[i]
X =[0 for x in range(N)]
sum2=0
i=1
while i < N:
  sum2+=A[i]
  i+=2
X[0]=sum-sum2*2

for i in range(1,N):
  X[i]=2*A[i-1]-X[i-1]
for i in range(N):
  X[i]=str(X[i])
print(" ".join(X))

Measured memory_bytes: 17300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(a,a+n);
	ll num = a[n/2];
	ll sum = 0;
	for(ll i=0;i<n;i++)
	{
		sum = sum + abs(a[i]-num);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt();
        int y1 = sc.nextInt();
        int x2 = sc.nextInt();
        int y2 = sc.nextInt();

        int x = x2;
        int y = y2;
        int dx = x2 - x1;
        int dy = y2 - y1;
        int tmp = 0;

        for (int i = 0; i < 2; i++) {
            tmp = dx;
            dx = dy;
            dy = tmp;

            dx = dx * -1;
            x += dx;
            y += dy;
            System.out.print(x + " " + y);
            System.out.print(" ");
        }

        sc.close();

    }

}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if((C-(A-B))<0){
        cout << 0 <<endl;
    }else{
        cout << (C-(A-B)) <<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,d,s;
    while(~scanf("%d",&a))
    {
        scanf("%d %d %d",&b,&c,&d);
        s=0;
        if(a<b)
            s=s+a;
        else
            s=s+b;
        if(c<d)
            s=s+c;
        else
            s=s+d;
        printf("%d\n",s);
    }
    return 0;
}



Measured memory_bytes: 128
import java.util.Scanner;

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        long x = 0;
        long y = 0;

        for (int i = 1; i <= n; i++) {
            if (i%k == 0)
                x++;
        }

        if (k % 2 == 0) {
            for (int i = 1; i <= n; i++) {
                if (i%k == k/2)
                    y++;
            }
        }


        System.out.println(x*x*x + y*y*y);
    }
}


Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            Array.Sort(nums, (a, b) => b - a);

            sb.Append(nums[0]);
            for (int i = 1; i < nums.Length; i++) sb.Append(" " + nums[i]);
            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 9180
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String S = in.next();
		int a = 0;
		if(S.equals("RRR")) {
			a = 3;
		}else if(S.equals("RRS") || S.equals("SRR")) {
			a = 2;
		}else if(S.equals("RSS") || S.equals("RSR") || S.equals("SRS") || S.equals("SSR")) {
			a = 1;
		}else {
			a = 0;
		}
		System.out.println(a);
	}
}


Measured memory_bytes: 26996
from collections import deque
import sys
sys.setrecursionlimit(10**7)
#input = sys.stdin.readline
def solve():
  s = input()
  n = len(s)
  query = [0]*n
  for i in range(n-1):
    if s[i] != s[i+1]:
      query[i] = max(i+1,n-i-1)
  #print(query)
  if (s == "0"*n) or (s=="1"*n):
    print(n)
  else:
    ans = 10**12
    for i in query:
      if i!= 0:
        ans = min(ans,i)
    print(ans)
solve()

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

int V, E, src, snk;
vector<int> la, nxt, oppo, capa;
void init() {
    E = 0;
    la.clear(); nxt.clear(); oppo.clear(); capa.clear();
    la = vector<int>(V, -1);
}
void add(int u, int v, int c) {
    nxt.push_back(la[u]);
    la[u] = E++;
    oppo.push_back(v);
    capa.push_back(c);
}
vector<int> dist;
queue<int> q;
bool bfs() {
    dist = vector<int>(V, -1);
    q.push(src);
    dist[src] = 0;
    while(!q.empty()) {
        int u = q.front(); q.pop();

        for(int i = la[u]; i != -1; i = nxt[i]) {
            int v = oppo[i];
            if(capa[i] && dist[v] == -1) {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    return dist[snk] != -1;
}
vector<int> laa;
int dfs(int u, int f) {
    if(u == snk) return f;

    for(int i = laa[u]; i != -1; i = nxt[i]) {
        laa[u] = i;
        int v = oppo[i];
        if(capa[i] && dist[v] == dist[u] + 1) {
            if(int tmp = dfs(v, min(capa[i], f))) {
                capa[i] -= tmp;
                capa[i ^ 1] += tmp;
                return tmp;
            }
        }
    }
    return 0;
}
int dinic() {
    int tf = 0;
    while(bfs()) {
        laa = la;
        while(int tmp = dfs(src, 1e8)) tf += tmp;
    }
    return tf;
}

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

int H, W;
vector<string> G;

int main() {
    scanf("%d %d", &H, &W);

    G.resize(H);

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

    V = 2*H*W + 2, src = V - 2, snk = V - 1;
    init();

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            add(i*W + j, H*W + i*W + j, (G[i][j] == '.'? 1 : 1e8));
            add(H*W + i*W + j, i*W + j, 0);

            if(G[i][j] == 'X') {
                add(src, i*W + j, 1e8);
                add(i*W + j, src, 0);
            }

            bool edge = false;
            for(int k = 0; k < 4; k++) {
                int ni = i + dy[k];
                int nj = j + dx[k];
                if(ni < 0 || H <= ni || nj < 0 || W <= nj) {
                    edge = true;
                    continue;
                }
                add(H*W + i*W + j, ni*W + nj, 1e8);
                add(ni*W + nj, H*W + i*W + j, 0);
            }

            if(edge) {
                add(H*W + i*W + j, snk, 1e8);
                add(snk, H*W + i*W + j, 0);
            }

            if(edge && G[i][j] == 'X') {
                printf("-1\n");
                return 0;
            }
        }
    }

    printf("%d\n", dinic());
}


Measured memory_bytes: 1772
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n-1; i++) {
			arr[i] = sc.nextInt();
		}
		int ans = sc.nextInt();
		
		System.out.println(solve(n, arr, ans));
	}
	
	public static long solve(int n, int[] arr, int ans) {
		long[][] dp = new long[n+1][21];
		for (int i = 0; i <= n; i++) {
			Arrays.fill(dp[i], -1);
		}
		dp[0][0] = 1;
		dp[1][arr[0]] = 1;
		for (int i = 1; i < n - 1; i++) {
			for (int j = 0; j <= 20; j++) {
				if (dp[i][j] < 0) 
					continue;
				if (j + arr[i] <= 20) {
					if (dp[i+1][j+arr[i]] < 0) 
						dp[i+1][j+arr[i]] = 0;
					dp[i+1][j + arr[i]] += dp[i][j];
				}
				if (j - arr[i] >= 0) {
					if (dp[i+1][j - arr[i]] < 0)
						dp[i+1][j - arr[i]] = 0;
					dp[i+1][j - arr[i]] += dp[i][j];
				}
			}
		}
		return dp[n-1][ans];
	}
}

Measured memory_bytes: 18156
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

signed main(){
  string s;
  cin>>s;
  int a=(s[0]-'0')*10+s[1]-'0';
  int b=(s[2]-'0')*10+s[3]-'0';
  if((a>12||a==0)&&(b>12||b==0))cout<<"NA"<<endl;
  else if((a<=12&&0<a)&&(b<=12&&0<b))cout<<"AMBIGUOUS"<<endl;
  else if(a<=12&&0<a)cout<<"MMYY"<<endl;
  else cout<<"YYMM"<<endl;
  return 0;
}


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

int main()
{
    int n;
    char buf[30];

    fgets(buf, sizeof(buf),stdin);

    n = atoi(buf);

    n = n + n*n + n*n*n;

    printf("%d\n", n);

}

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


const int MAX = 2200000;
const long long MOD = 1000000007;
long long INF = 90000000001000;


int main() {

int n;cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i)
{
    cin >> a[i];
}
int q;cin >> q;
vector<int> m(q),ans(q);
for (int i = 0; i < q; ++i)
{
    cin >> m[i];
}
for (int i = 0; i < q; ++i)
{
    ans[i] = 0;
}

for (int bit = 0; bit < (1<<n); ++bit)
{
    int sum =0;
    for (int i = 0; i < n; ++i)
    {
        if(bit & (1<<i)) sum += a[i];
    }
    for (int i = 0; i < q; ++i)
    {
        if(m[i]==sum)ans[i]=1;
    }
}

for (int i = 0; i < q; ++i)
{
   if(ans[i]) cout << "yes"<< "\n";
   else cout << "no" << "\n";
}

return 0;
}





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

int64_t MOD = 1e9+7;

int main(){
  string S; cin >> S;
  int L = S.length();

  // dp[i][j] : 先頭i文字として考えられるものの内
  //   13で割った余りがjであるものの個数
  vector<vector<int64_t>> dp(100010, vector<int64_t>(13, 0));

  dp[0][0] = 1;

  for(int i=1; i<=L; i++){
    if(S[i-1] != '?'){
      int d = S[i-1] - '0';
      for(int j=0; j<13; j++){
        int nj = (j*10+d) % 13;
        dp[i][nj] += dp[i-1][j];
        dp[i][nj] %= MOD;
      }
    } else {
      for(int d=0; d<=9; d++){
        for(int j=0; j<13; j++){
          int nj = (j*10+d) % 13;
          dp[i][nj] += dp[i-1][j];
          dp[i][nj] %= MOD;
        }
      }
    }
  }

  cout << dp[L][5] << endl;

}

Measured memory_bytes: 13696
#include<stdio.h>
int main(void){
   double h[1000], Max, Min;
   int i = 1;
   scanf("%lf", &h[0]);
   Max = Min = h[0];
   while ( scanf("%lf", &h[i] ) != EOF ) {
      if ( h[i] >= Max ) Max = h[i];
      if ( h[i] <= Min ) Min = h[i];
      i++;
   }
   printf("%.1lf", Max - Min);
   return 0;
}

Measured memory_bytes: 1856
#include <cstdio>
#include <iostream>

using namespace std;
typedef pair<int, int> P;
string s[50];
int w, h;

bool judge(int nowH, int nowW) {
    P Ps[4];
    bool res = false;
    Ps[0] = P(nowH + 1, nowW);
    Ps[1] = P(nowH, nowW + 1);
    Ps[2] = P(nowH - 1, nowW);
    Ps[3] = P(nowH, nowW - 1);
    for (int i = 0; i < 4; i++) {
        if (Ps[i].first >=0 && Ps[i].first <= h && Ps[i].second >=0 && Ps[i].second <= w && s[Ps[i].first][Ps[i].second] == '#') {
            res = true;
            return true;
            break;
        } 
    }
    return res;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> s[i]; 
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                if(!judge(i, j)) {
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
#define INF 999999999
#define lint long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define P pair<lint, lint>

int memo[100001] = {};

int solve(string S, int l, int r){
    int cnt = 0;
    for(int i=l-1; i<r-1; ++i){
        cnt += memo[i];
    }
    return cnt;
}

int main(){
    int N, Q;//, memo[100001][100001];
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[100001], r[100001];
    rep(i, Q){
        cin >> l[i] >> r[i];
    }
    //
    int tmp=0;
    for(int i=1; i<N; ++i){
        if(S[i-1]=='A' && S[i]=='C'){
            ++tmp;
        }
        memo[i]=tmp;
    }
    memo[N-1]=tmp;
    //
    rep(i, Q){
        cout << memo[r[i]-1] - memo[l[i]-1] << endl;
    }
    //rep(i, N) cout << memo[i-1];
    return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
const ll mod = 1e9+7;

class union_find {
public:
vector<int> par,rank,lsize;
union_find(int n): par(n),rank(n),lsize(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
      lsize[i]=1;
   }
}

int find(int x){
   if (par[x]==x){
      return x;
   }
   else{
      return par[x] = find(par[x]); 
   }
}

void unite(int x ,int y){
   x=find(x);
   y=find(y);
   if (x==y) return;
   if (rank[x] < rank[y]){
      lsize[y] += lsize[x];
      lsize[x] = -1;
      par[x] = y;
   }else{
      lsize[x] += lsize[y];
      lsize[y] = -1;
      par[y]=x;
      if (rank[x]==rank[y]) rank[x]++;
   }   
}

bool same(int x, int y){
   return find(x) == find(y);
}

int size(int x){
   if (lsize[x] == -1){
      x=find(x);
   }
   return lsize[x];
}
};

int main(){
  int n,m;
  cin >> n >> m;
  union_find tree(n);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    tree.unite(x,y);
  }
  int ans = 0;
  for (int i = 0; i < n;i++){
    ans = max(ans,tree.size(i));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

long long int a, b, c, d;
map<long long int, long long int> memo;

long long int DFS(long long int x){
    if(memo.find(x) != memo.end()) return memo[x];

    long long int ans = INF;
    ans = min({ans, DFS(x/2) + (x%2) * d + a, DFS((x+1)/2) + (2-x%2) * d + a});
    ans = min({ans, DFS(x/3) + (x%3) * d + b, DFS((x+2)/3) + (3-x%3) * d + b});
    ans = min({ans, DFS(x/5) + (x%5) * d + c, DFS((x+4)/5) + (5-x%5) * d + c});
    if(x <= INF / d) ans = min(ans, x*d);

    return memo[x] = ans;
}

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

    for(int i=0; i<t; i++){
        long long int n;
        cin >> n >> a >> b >> c >> d;

        memo.clear();
        memo[0] = 0;
        memo[1] = d;

        cout << DFS(n) << endl;
    }
    return 0;
}

Measured memory_bytes: 4336