akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define pb emplace_back
#define mp make_pair

using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<ll, ll> P;

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;
}

ll R, C, N, M, K, Q;

vector<ll> v[200005];
vector<ll> res;

void dfs(ll node, ll p = 0){
    PRINT(node)
    PRINT(res[node])
    irep(itr,v[node]){
        if(*itr == p) continue;
        res[*itr] += res[node];
        dfs(*itr, node);
    }
    return;
}

signed main() {
    //cout << fixed << setprecision(10);
    cin >> N >> Q;

    rep(i, N-1){
        ll from,to; cin >> from >> to;
        from --;
        to --;
        v[from].pb(to);
        v[to].pb(from);
    }
    res.assign(N,0); 
    rep(i,Q){
        ll node, val; cin >> node >> val;
        res[--node] += val;
    }
    dfs(0);

    rep(i, N){
        cout << res[i] << endl;
    }

    //cout << max << endl;
}


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

int main(){
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if(w >= x + r && 0 <= x - r && h >= y + r && 0 <= y - r) cout << "Yes";
  else cout << "No";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 1000000007 
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
struct bit {
	int d[maxn];
	void init() {
		memset(d, 0, sizeof(d));
	}
	int lb(int a) {
		return a & -a;
	}
	void pls(int pl, int num) {
		while (pl < maxn) {
			d[pl] = (d[pl] + num) % mod;
			pl += lb(pl);
		} 
	}
	int q(int pl) {
		int ans = 0;
		while (pl) 
			ans = (ans + d[pl]) % mod, pl -= lb(pl);
		return ans;
	}
	int q(int l, int r) {
		return (q(r) - q(l - 1)) % mod;
	}
}x;
int n;
int a[maxn], s[maxn], nx[maxn];
ll mt[maxn];
ll re[maxn], br[maxn];
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		s[a[i]]++;
	}
	for (int i = n; i >= 1; i--)
		s[i] += s[i + 1];
	ll tot = 1;
	for (int i = 1; i <= n; i++) {
		s[i] -= (n - i);
		if (s[i] < 0) {
			cout << 0 << endl;
			return 0;
		}
		tot = tot * s[i] % mod;
		mt[i] = (s[i] - 1) * ksm(s[i], mod - 2) % mod;
	}
	re[0] = 1;
	for (int i = 1; i <= n; i++) {
		re[i] = re[i - 1];
		if (mt[i]) re[i] = re[i] * mt[i] % mod;
		br[i] = ksm(re[i], mod - 2);
	}
	nx[0] = 1;
	for (int i = 1; i <= n; i++)
		if (s[i] == 1) nx[i] = i;
		else nx[i] = nx[i - 1];
	// >= nx[i]
	ll ans = 0;
	for (int i = n; i >= 1; i--)
		ans += x.q(a[i] - 1) * tot, 
		ans %= mod, 
		x.pls(a[i], 1);
	for (int tp = 0; tp < 2; tp++) {
		ll nans = 0;
		x.init();
		for (int i = 1; i <= n; i++) {
			int ns = a[i];
			nans += re[ns] * x.q(nx[ns], ns - tp), nans %= mod;
			x.pls(ns, br[ns]);
		}
		nans = nans * tot % mod;
		nans = nans * (mod + 1) / 2 % mod;
		if (tp == 0) ans += nans;
		else ans -= nans;
		reverse(a + 1, a + n + 1);
	}
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8064
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
cal=lambda x:(1+x)/2
a=list(map(cal,a))
#print(a)
now=sum(a[:k])
ans=now
#print(now)
d=a[0]
for i in range(1,n-k+1):
    #print(i)
    tmp=now-d+a[i+k-1]
    ans=max(ans,tmp)
    d=a[i]
    now=tmp
    #print(now)
    #print()
print(ans)

Measured memory_bytes: 25060
n = input()
Nr = list(map(int,list(reversed(n))))
Nr.append(0)

ans = 0 
for i in range(len(Nr)):
    if Nr[i] > 5:
        Nr[i+1] += 1
        ans += (10 - Nr[i])
    elif Nr[i]==5:
        if Nr[i+1]>=5:
            Nr[i+1] += 1
            ans += (10 - Nr[i])
        else:
            ans += Nr[i]
    else:
        ans += Nr[i]

print(ans)

Measured memory_bytes: 129456
n, l = map(int, input().split())

list_t = list(range(l, l+n))

#絶対値が最小のList indexを抽出する

index = 0

comp = abs(list_t[0])
for n, i in enumerate(list_t):
    if comp > abs(i):
        comp = abs(i)
        index = n

print(sum(list_t[:index] + list_t[index+1:]))

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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int A, B;
    cin >> A >> B;

    cout << max(A+B, max(A-B, A*B)) << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

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

int main() {
  int N,a;
  cin >> N;
  for ( int i = 0; i < N; i++){
    int l,r;
    cin >> l >> r;
    a = a + r - l + 1;
    if ( i == N - 1 ){
      cout << a;
    }
  }
}

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

int main() {
  int a, b, c, d;
  cin >> a;
  b = a / 100;
  c = (a - 100*b) / 10;
  d = a - 100*b - 10*c;
  cout << b + c + d << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
int B[200005];
vector <int> V[200005];
int DP[200005], Q;
int Partial[200005];
int Arb[4 * 200005], Lazy[4 * 200005];
void Update(int K, int L, int R, int pos, int val)
{
    if(Lazy[K] != 0)
    {
        Arb[K] += Lazy[K];
        if(L != R)
        {
            Lazy[K * 2] += Lazy[K];
            Lazy[K * 2 + 1] += Lazy[K];
        }
        Lazy[K] = 0;
    }
    if(L > R || L > pos || R < pos)
        return;
    if(L == R)
    {
        Arb[K] = val;
        return;
    }
    //if(pos > (L + R) / 2)
    Update(K * 2 + 1, (L + R) / 2 + 1, R, pos, val);
    //else
    Update(K * 2, L, (L + R) / 2, pos, val);
    Arb[K] = min(Arb[K * 2], Arb[K * 2 + 1]);
}

int Query(int K, int L, int R, int x, int y)
{
    if(Lazy[K] != 0)
    {
        Arb[K] += Lazy[K];
        if(L != R)
        {
            Lazy[K * 2] += Lazy[K];
            Lazy[K * 2 + 1] += Lazy[K];
        }
        Lazy[K] = 0;
    }
    if(L > R || L > y || R < x)
        return 2000005;
    if(L >= x && R <= y)
        return Arb[K];
    int a = Query(K * 2, L, (L + R) / 2, x, y);
    int b = Query(K * 2 + 1, (L + R) / 2 + 1, R, x, y);
    return min(a, b);
}
void Read()
{
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> B[i], Partial[i] = Partial[i - 1] + B[i];
    cin >> Q;
    for(int j = 1; j <= Q; j++)
    {
        int l, r;
        cin >> l >> r;
        V[l].push_back(r);
    }
    for(int  i = 1; i <= N; i++)
    {
        sort(V[i].begin(), V[i].end());
        reverse(V[i].begin(), V[i].end());
    }

}
void Update2(int K, int L, int R, int x, int y, int val)
{
    if(Lazy[K] != 0)
    {
        Arb[K] += Lazy[K];
        if(L != R)
        {
            Lazy[K * 2] += Lazy[K];
            Lazy[K * 2 + 1] += Lazy[K];
        }
        Lazy[K] = 0;
    }
    if(L > R || L > y || R < x)
        return;
    if(L >= x && R <= y)
    {
        Arb[K] += val;
        if(L != R)
        {
            Lazy[K * 2] += val;
            Lazy[K * 2 + 1] += val;
        }
        return;
    }
    Update2(K * 2, L ,(L + R) / 2, x, y, val);
    Update2(K * 2 + 1, (L + R) / 2 + 1, R, x, y, val);
    Arb[K] = min(Arb[K * 2], Arb[K * 2 + 1]);
}
void Solve()
{
    for(int i = 0; i <= N; i++)
    {
        if(i > 0)
        {
            int val = B[i];
            Update2(1, 1, N + 1, 1, i, val);
            Update2(1, 1, N + 1, i + 1, N + 1, 1 - val);
        }

        for(int j = 0; j < V[i + 1].size(); j++)
        {
            int r = V[i + 1][j];
            int x = Query(1, 1, N + 1, 1, r + 1);
            Update(1, 1, N + 1, r + 1, x);
        }

    }
    cout << Arb[1] << "\n";
}
int main()
{

    Read();
    for(int i = 1; i <= 4 * (N + 1); i++)
        Arb[i] = 200005;
    Update(1, 1, N + 1, 1, 0);
    Solve();
    return 0;
}


Measured memory_bytes: 17536
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

ll dp[MAX][13];

vector<pair<ll,ll> > ans;
ll K;
ll X,Y;
ll dx,dy;
pair<ll,ll> modify;
ll nx,ny;

pair<ll,ll> strategy(ll x,ll y,ll K){
  //x,yは残りの距離、Kは移動可能距離
  // cout<<"remain "<<x<<" "<<y<<endl;
  if(x<0){
    modify = strategy(-x,y,K);
    return mp(-modify.first,modify.second);
  }
  if(y<0){
    modify = strategy(x,-y,K);
    return mp(modify.first,-modify.second);
  }
  if(x>y){
    modify = strategy(y,x,K);
    return mp(modify.second,modify.first);
  }
  //ここでは0<=x<=yであるはず
  ll L = x+y;
  //まだまだだからとりあえず近ずく
  if(L>2*K){
    dx = min(x,K);
    dy = K - dx;
    return mp(dx,dy);
  }
  //lastの移動
  if(L==K){
    return mp(x,y);
  }
  if((x+y)%2==0){
    //2回でいける
    ll t = (y-x)/2;
    dx = K-t;
    dy = t;
    return mp(dx,dy);
  }
  //3回でいける
  dx = min(K,x);
  dy = K-dx;
  return mp(dx,dy);
}

int main(){
  cin>>K;
  cin>>X>>Y;
  ll x=0,y=0;
  ll a,b;

  if(K%2==0 and (X+Y)%2!=0){
    cout<<-1<<endl;
    return 0;
  }

  else{
    while(x!=X or y!=Y){
      pair<ll,ll> move = strategy(X-x,Y-y,K);
      x += move.first;
      y += move.second;
      ans.pb(mp(x,y));
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()) cout<<ans[i].first<<" "<<ans[i].second<<endl;
  }

}


Measured memory_bytes: 5484
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits.h>

#define INF LLONG_MAX

using namespace std;

int main()
{
    int i, j;
    int x;
    int n;
    vector<int> x_vec;
    long long min_val = INF;
    long long sum;
    int max_x = 0;
    int min_x = INF;

    cin >> n;
    for (i = 0; i < n; i++) {
        int x_tmp;
        cin >> x_tmp;
        x_vec.push_back(x_tmp);
        max_x = max(max_x, x_tmp);
        min_x = min(min_x, x_tmp);
    }

    for (x = min_x; x <= max_x; x++) {
        sum = 0;
        for (i = 0; i < n; i++) {
            sum += (x - x_vec[i]) * (x - x_vec[i]);
        }
        min_val = min(sum, min_val);
    }

    cout << min_val << endl;

    return 0;
}


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

int main() {
  int x1,x2,x3,x4,y1,y2,y3,y4;
  cin>>x1>>y1>>x2>>y2;
  x3=x2+y1-y2;
  y3=y2+x2-x1;
  x4=x3+y2-y3;
  y4=y3+x3-x2;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mode 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
bool comparion(pll a,pll b)
{
    if(a.ff==b.ff)
        return(a.ss>b.ss);
    return (a.ff>b.ff);
}
int main()
{  
    FAST
    ll n,m;
    cin>>n>>m;
    vpl ms;
    ll a;
    for(ll i=0;i<n;i++)
    {
        cin>>a;
        ms.pb(mp(a,1));
    }
    ll x;
    for(ll i=0;i<m;i++)
    {
        cin>>a>>x;
        ms.pb(mp(x,a));
    }
    sort(ms.begin(),ms.end(),comparion);
    ll q=n;
    ll ans=0;
    for(auto i:ms)
    {
        a=i.ff;
        x=i.ss;
        if(x>q)
        {
            ans+=(q*a);
            q=0;
        }
        else
        {
            ans+=(x*a);
            q-=x;
        }
        if(q==0)
            break;
    }
    cout<<ans;
}

Measured memory_bytes: 6512
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	string s;
	string s1 = "apple";
	string s2 = "peach";
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s.substr(i,5)==s1)
		s.replace(i,5,s2);
		else if(s.substr(i,5)==s2)
		s.replace(i,5,s1);
	}
	printf("%s\n",s.c_str());
}

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

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

typedef long long ll;

int n;
vector<ll> accum_add, accum_xor;

bool solve(int left, int mid){
  if(accum_add[mid] - accum_add[left] == (accum_xor[mid] ^ accum_xor[left])) return true;
  else return false;
}

int binary_search(int left){
  int ok = left;
  int ng = n + 1;

  while(abs(ok - ng) > 1){
    int mid = (ok + ng) / 2;
    if(solve(left, mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }

  return ok;
}

int main(){
  /* input */
  cin >> n;
  accum_add.resize(n+1);
  accum_xor.resize(n+1);
  REP(i, 0, n){
    cin >> accum_add[i+1];
    accum_xor[i+1] = accum_add[i+1];
  }

  /* 累積を計算 */
  REP(i, 0, n){
    accum_add[i+1] += accum_add[i];
    accum_xor[i+1] ^= accum_xor[i];
  }
  
  ll res = 0;
  REP(left, 0, n){ // 左端を固定
    int right = binary_search(left); // 右端を二分探索
    //cout << "[" << left << ", " << right  << ")" << endl;
    res += ll(right - left);
  }
  cout << res << endl;
}

Measured memory_bytes: 3328
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n, m = map(int, input().split())
    cards = [0] * (n + 2)
    for i in range(m):
        l, r = map(int, input().split())
        cards[l] += 1
        cards[r + 1] -= 1

    cnt, res = 0, 0
    for i in range(n + 2):
        cnt += cards[i]
        if cnt == m:
            res += 1

    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 37996
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i, j, k, N, Y, ii=-1, jj=-1, kk=-1, ans;
    cin >> N >> Y;
    for (i = 0; i <= N; i++)
    {
        for (j = 0; j <= N-i; j++)
        {
            k = N - i - j ; 
            ans = 10000*i + 5000*j + 1000*k;
            if(ans == Y)
            {
                ii = i;
                jj = j;
                kk = k;
            }
        }
    }
    cout << ii << " " << jj << " "<< kk << "\n";
    return 0;
}


Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

a_list = sorted(a_list)[-1 * X:]
b_list = sorted(b_list)[-1 * Y:]
#print(a_list)
#print(b_list)

all_list = sorted(a_list + b_list + c_list)

print(sum(all_list[-1 * (X + Y):]))

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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; }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<int> range(101, 0);
    for(int i=a; i <= b; i++) range[i]++;
    for(int i=c; i <= d; i++) range[i]++;
    int cnt = 0;
    rep(i, 101) if(range[i]==2) cnt++;
    cout << (cnt ? cnt-1 : cnt) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
  public static void main(String args[])throws IOException
  {
    InputStreamReader read = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(read);
    double r=Double.parseDouble(in.readLine());
    double circum=(double)(2*(Math.PI)*r);
    System.out.println(circum);
  }
}

Measured memory_bytes: 33176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

using tup = tuple<ll, int, int>;
vector<tuple<int, int, int>> G[110]; // G[i] := i->j dist enemy
//dist[i][j] := ??????0????????????i??? ????????????L??§????????¨????????????????¨????????°????
int dist[110][110];

int N, M, L;

void dijkstra(int start){
	rep(i, 110)rep(j, 110) dist[i][j] = INF;
    priority_queue<tup, vector<tup>, greater<tup>> que; // ????????? ?????? ??????
    dist[start][L] = 0;
    que.push(make_tuple(0, start, L));
    while(!que.empty()){
        int cost, u, money;
        tie(cost, u, money) = que.top(); que.pop();
        // printf("cost %d u %d moeny %d\n", cost, u, money);
        // if(dist[u][money] < cost) continue;
        if(u == N - 1) break;
        for(auto tm : G[u]){
            int v, len, enemy;
            tie(v, len, enemy) = tm;
            // printf("v %d len %d enemy %d\n", v, len, enemy);
            if(len > money){
            	if(cost + enemy < dist[v][money]){
            		dist[v][money] = cost + enemy;
            		que.push(make_tuple(dist[v][money], v, money));
            	}
            }else{ //?????????
            	if(cost < dist[v][money - len]){
            		// printf("k\n");
            		dist[v][money - len] = cost;
            		que.push(make_tuple(dist[v][money - len], v, money - len));
            	}
            	if(cost + enemy < dist[v][money]){
            		dist[v][money] = cost + enemy;
            		que.push(make_tuple(dist[v][money], v, money));
            	}
            }
        }
    }
}

int main(void){
	while(1){
		scanf("%d %d %d", &N, &M, &L);
		if(N == 0) return 0;
		rep(i, 110) G[i].clear();

		rep(i, M){
			int a, b, d, e; scanf("%d %d %d %d", &a, &b, &d, &e);
			a--, b--;
			G[a].pb(make_tuple(b, d, e)), G[b].pb(make_tuple(a, d, e));
		}
		// printf("dis\n");
		dijkstra(0);
		int ans = INF;
		rep(i, L + 1) chmin(ans, dist[N - 1][i]);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3396
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, A, B = MAP()
print(min(A*N, B))


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

using namespace std;

#define int long long
#define  IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int INF = 1e9;

const int N = 2e3 + 10;
vector<int> adj[N];

int dis[N][N], vis[N][N];

void bfs(int u) {
    queue<int> q;
    q.push(u);
    dis[u][u] = 0;
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        for (auto it:adj[x]) {
            if (!vis[u][it]) {
                vis[u][it] = 1;
                dis[u][it] = dis[u][x] + 1;
                q.push(it);
            }
        }
    }
}

signed main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    for (int i = 1; i <= n; i++) {
        bfs(i);
    }
    vector<int> ans(n);
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            ans[dis[i][j]]++;
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}

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

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

  int a[n];

  int bit;
  int a1;
  cin >> a1;
  bit=a1;
  a[0]=a1;

  rep(i,n-1){
      int aa;
      cin >> aa;
      a[i+1]=aa;
    bit = bit ^ aa;
  }

  rep(i,n){
      int ans = bit ^ a[i];
      cout << ans << " " ;
  }
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b >= c) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
int N, M;
int A[333][333];
bool flg[333];
int num[333];
int main()
{
  cin >> N >> M;  
  FOR(i,0,N) FOR(j,0,M) {
    cin >> A[i][j];
    A[i][j]--;
  }
  FOR(i,0,M) flg[i] = true;
  int ans = 1000;
  FOR(i,0,M) {
    FOR(j,0,M) num[j] = 0;
    FOR(j,0,N) {
      int k = 0;
      FOR(k,0,M) {
        if(flg[A[j][k]]) {
          num[A[j][k]]++;
          break;
        }
      }  
    }
    int cnt = 0;
    int mxm = 0;
    FOR(j,0,M) {
      if(cnt < num[j]) {
        mxm = j;
        cnt = num[j];
      }
    }
    ans = min(ans, cnt);
    flg[mxm] = false;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

const int inf = 1e8, Nmax = 303;

int n, m, i, j, ans;
char a[Nmax][Nmax], ch[Nmax];

int solve(char a[], char b[])
{
    int i, j, cost[Nmax][Nmax], dp[Nmax][Nmax];

    for(i=0; i<=n; ++i) dp[i][n+1] = dp[n+1][i] = inf, cost[i][0] = cost[0][i] = 0;

    for(i=1; i<=n; ++i)
    for(j=1; j<=n; ++j)
        cost[i][j] = cost[i-1][j-1] + (a[i]==b[j]);

    for(i=n; i>=0; --i)
    for(j=n; j>=0; --j)
    {
        if(i==n && j==n) dp[n][n] = 0;
        else dp[i][j] = min(dp[i][j+1] + cost[i][j+1], dp[i+1][j] + cost[i+1][j]);
    }

    return dp[0][0];
}

int main()
{
    scanf("%d %d\n", &n, &m);

    for(i=1; i<=n; ++i)
    {
        scanf("%s\n", ch+1);
        for(j=1; j<=m; ++j)
            a[j][i] = ch[j];
    }

    for(i=1; i<m; ++i)
        ans += solve(a[i], a[i+1]);

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

    return 0;
}


Measured memory_bytes: 1152
n = int(input())
maxnum_4 = n // 4
maxnum_7 = n // 7
ans = 'No'
for i in range(maxnum_7 + 1):
  for j in range(maxnum_4 + 1):
    total = i * 7 + j * 4
    if total == n:
      ans = 'Yes'
      break
  if ans == 'Yes':
    break
print(ans)

Measured memory_bytes: 61664
n, a, b = map(int, input().split(' '))

if n > 100 or a > n or b > n:
    raise ValueError

ret_max = min(a, b)

if n > a + b:
    ret_min = 0
else:
    ret_min = (max(a, b) + min(a, b)) - n

print(ret_max, ret_min)


Measured memory_bytes: 2940
h, w = map(int, input().split())
table = [[x for x in input()] for _ in range(h)]
ans_table = [[0 for _ in range(w)] for _ in range(2*h)]

for y in range(h):
  ans_y = 2 * y
  ans_table[ans_y] = table[y]
  ans_table[ans_y + 1] = table[y]

for y in range(2*h):
  print("".join(ans_table[y]))

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

int main() { 
    int f = 0;
    string s;
    cin >> s;
    if(s[0] == 'A' && s[1] == 'A' && s[2] == 'A') f = 1;
    if(s[0] == 'B' && s[1] == 'B' && s[2] == 'B') f = 1;

    if(!f) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e6+10;


int main(){
    ll x=7;
    ll k;
    in>>k;
    int ans=1;

    while(x%k){
        x=x*10+7;
        x%=k;
        ++ans;
        if(ans==2000000)break;
        
    }
    if(ans==2000000)ans=-1;
    out<<ans;
    return 0;
}


Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main {
    static Character[] toCharacterArray(String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        Character[] array = new Character[len];
        for (int i = 0; i < len; i++) {
            array[i] = new Character(s.charAt(i));
        }
        return array;
    }

    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String arr = reader.readLine();

        Set<Character> S = new HashSet<Character>(Arrays.asList(toCharacterArray(arr)));
        System.out.println(1 < S.size() ? "Yes" : "No");
    }
}

Measured memory_bytes: 23124
def main():
    N, T = map(int, input().split())
    t = tuple(map(int, input().split()))

    i = 0
    x = 0
    while i < N - 1:
        t2 = t[i+1] - t[i]
        if t2 < T:
            x += t2
        else:
            x += T
        i += 1
    print(x + T)

main()


Measured memory_bytes: 26964
from itertools import permutations
from math import factorial
from scipy.spatial import distance_matrix
import numpy as np

n = int(input())
x = []
for i in range(n):
    x.append(list(map(int, input().split())))
x = np.array(x)
d = distance_matrix(x, x)

res = 0
for path in permutations(range(n)):
    path = list(path)
    res += np.sum(d[path[:-1], path[1:]])
print(res/factorial(n))


Measured memory_bytes: 29944
#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 n,m,x;
  cin >>n >>m >>x;
  int a[12][12];
  vector<int> c(n);
  rep(i,n){
    cin >>c[i];
    rep(j,m) cin >>a[i][j];
  }
  int ans = 1001001001;
  rep(s,1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n){
      if(s>>i&1){
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if(d[j]<x) ok =false;
    if(ok) ans = min(ans, cost);
  }
  if(ans==1001001001) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll a,b,c,tk=0,dif,i;
    cin>>a>>b>>c;
    vector<ll>v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(),v.end());
    for(i=1;i<3;i++)
    {
        tk+=(v[i]-v[i-1]);
    }
    cout<<tk<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
broken_steps = set([int(input()) for _ in range(m)])
#print(broken_steps)

def ptn_num(x): # 'x'stepまでのパターン数
    if x == 1:
        print(1)
    else:
        dp = [0] * (x+1) # DP枠_including step'0'
        cnt = 0
        if 1 in broken_steps: # in case, step'1' broken 
            dp[:2] = 1, 0
        else:
            dp[:2] = 1, 1 # Usually

        for i in range(2, x+1):
            if i in broken_steps: # 階段が壊れている場合...
                cnt += 1
                if cnt == 2:
                    print(0)
                    exit()
            else: # 階段が壊れてない場合...
                dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
                cnt = 0
        
        print(dp[-1])

ptn_num(n)


Measured memory_bytes: 50140
a,b,c,d = input()

for i in range(2**3):
    op = ["+","+","+"]
    for j in range(3):
        if ((i>>j)&1) == 1:
            op[j] = "-"
    ans = eval(a + op[0] + b + op[1] + c + op[2] +d)
    if ans == 7 :
        print("{}{}{}{}{}{}{}={}".format(a,op[0],b,op[1],c,op[2],d,ans))
        break

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

using namespace std;

int main() {
    int a , b , c , d , atb , atc , btc ;
    cin >> a >> b >>c >> d;
    atb = abs (a - b);
    atc = abs (a - c);
    btc = abs (b - c);
    if(atc <= d )
        cout << "Yes" << endl;
    else if(atb <= d && btc <= d)
        cout << "Yes" << endl;
    else
        cout << "No"<<endl;
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
bool is_pall(string s)
{
   
   for(int i=0;i<s.size();i++)
   {
       if(s[i]!=s[s.size()-i-1])
       {
           return false;
       }
   }
    return true;
}
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);

 string s;
 cin>>s;
 ll n=s.size();
 if(is_pall(s.substr(0,(n-1)/2))&&is_pall(s.substr((n+3)/2-1,n-(n+3)/2+1))&&is_pall(s))
 {
     cout<<"Yes"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
int n,m,k;
const int mxn=3010;
int gh[mxn][mxn];
ll dp[mxn][mxn][4];
ll dfs(int i,int j,int k){
	if(i>n)return 0;
	if(j>m)return 0;
	ll ans=0;
	if(dp[i][j][k]!=-1)return dp[i][j][k];
	if(k>0){
		ans=max(ans,gh[i][j]+dfs(i,j+1,k-1));
		ans=max(ans,gh[i][j]+dfs(i+1,j,3));
	}
	ans=max(ans,dfs(i+1,j,3));
	ans=max(ans,dfs(i,j+1,k));
	return dp[i][j][k]=ans;
}
void solve(){
int x=0,y=0,z=0;
cin>>n>>m>>k;
mex(dp),mez(gh);
while(k--){
	cin>>x>>y>>z;
	gh[x][y]=z;
}
ll ans=dfs(1,1,3);
cout<<ans;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
   //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}

Measured memory_bytes: 322824
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    int m, d, M, D;
    cin >> m >> d >> M >> D;
    if(d+1 == D) cout << 0 << endl;
    else cout << 1 << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#define CL(a) memset(a,0,sizeof(a))
#define cl(a,b) memset(a,(b),sizeof(a))
#define For(i,a,b) for(i=a;i<b;i++)
#define LL long long 
using namespace std;
const int maxn = 5e6 + 100;
char a[maxn];
int main()
{
	scanf("%s",a);
	int i,j;
	int len = strlen(a);
	int ans = len;
	for(i=1;i<len;i++)
	{
		if(a[i]!=a[i-1]) ans = min(ans,(max(i,len-i)));
		
	} 
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mod 998244353
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define adb2(a) for(auto i:a) cout << i.first << " " << i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define N 500010
using namespace std;

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

    set<string> st;
    string s;
    for(int i=0; i<n; i++)
    {
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
}

Measured memory_bytes: 19284
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for(auto& x: H) cin >> x;

    sort(H.begin(), H.end());
    ll ans = 0;
    for(int i=0; i<N-K; i++) ans += H[i];
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

bool valid(ll a, ll b, ll k) {
    if (a < 0 || b < 0) return false;
    if (a > k*(b+1) || b > k*(a+1)) return false;
    return true;
}


char query(ll A, ll B, ll i) {
    ll k = max((B+A)/(A+1), (B+A)/(B+1));
    
    ll low = 0;
    ll high = B+1;

    while (high - low > 1) {
        ll mid = (high + low) / 2;
        ll ma = A - mid*k;
        ll mb = B - mid;
        if (valid(ma, mb, k) && valid(ma, mb + 1, k)) {
            // cout << mid << " " << ma << " " << mb << " valid" << endl;
            low = mid;
        } else {
            // cout << mid << " " << ma << " " << mb << " invalid" << endl;
            high = mid;
        }
    }

    ll cx = low;

    if (i <= cx*(k+1)) {
        if (i % (k+1) == 0) return 'B';
        else return 'A'; 
    }

    A -= cx*k;
    B -= cx;
    i -= cx*(k+1);
    // cout << "%% k, cx: " << k << " " << cx << endl;
    // cout << "%% new A, B: " << A << ", " << B << endl;

    if (A > 0 && B > 0) {
        // how many steps to the left can we take without violating
        // b - ka <= k
        // ka >= b - k
        // a >= (b - k)/k
        // 

        if (B - k*A <= 0) {
            ll na = A - (B - k + (k-1))/k;
            // cout << "%%%" << A << " " << B << " " << B - k*A << " " << na << endl;
            if (i <= na) return 'A';
            i -= na;
            A -= na;
        }

        ll nb = B - k*A;
        // cout << "%%%" << A << " " << B << " " << nb << endl;
        if (i <= nb) return 'B';

        i -= nb;
        B -= nb;

        // cout << "%% num Bs: " << nb << endl;

        if (i % (k+1) == 1) return 'A';
        else return 'B';
    } else {
        if (A == 0) return 'B';
        if (B == 0) return 'A';
    }



}

void solve() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    for (ll i=C; i<=D; i++) cout << query(A, B, i);
    cout << "\n";
}

int main(){
    int Q;
    cin >> Q;
    for (int q=0;q<Q;q++) solve();
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int n,x;
    cin>>n>>x;
    vi a(n);
    REP(i,n){
        cin>>a[i];
    }
    ll ans=0;
    if (a[0] > x) {
       ans += a[0] - x;
       a[0] = x;
    }

    REP(i,n-1){
        if(a[i]+a[i+1]>x){
            ans+=(a[i]+a[i+1]-x);
            a[i+1]=x-a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.

int _find(ll a,ll b){
    if(a<=0 && b>=0){
        return 0;
    }
    // a,b
    if(a>0){
        return 1;
    }
    
    return (b-a+1)%2==0 ? 1:-1;
    
}

void solve(){
    ll a,b;
    cin>>a>>b;
    int ans=_find(a,b);
    if(ans>0){
        cout<<"Positive\n";
    }
    else if(ans==0){
        cout<<"Zero\n";
    }
    else{
        cout<<"Negative\n";
    }
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

string s;

bool check(string t) {
    int index = 0;
    rep (i, s.size()) {
        if (s[i] == t[index]) index++;
    }
    return index > 2;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n >> s;
    int res = 0;
    rep (i, 1000) {
        string t = "";
        if (i < 100) t += '0';
        if (i < 10) t += '0';
        t += to_string(i);
        if (check(t)) res++;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 384
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var ans = "";

        while (n != 0)
        {
            if (n % 2 != 0)
            {
                n--;
                ans = "1" + ans;
            }
            else
            {
                ans = "0" + ans;
            }
            n /= -2;
        }

        if (ans == "") ans = "0";

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<long long int> data(n);
	data[0] = 0;
	for (int i = 1; i < n; i++) {
		cin >> data[i];
		data[i] += data[i-1];
	}
	int counter = 0;
	long long int kyo = 0;
	int a;
	for (int i = 0; i < m; i++) {
		cin >> a;
		kyo += abs(data[a+counter]-data[counter]);
		counter += a;
	}
	cout << kyo%100000 << endl;
	return 0;
}

Measured memory_bytes: 1796
#include <iostream>

using namespace std;

int main(){
    int n;
    int d;
    int x;
    cin >> n;
    cin >> d >> x;
    int a;
  	int result = x;
    for(int i = 0; i < n; i++){
        cin >> a;
        result += d / a;
        if(d % a != 0){
            result += 1;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256