akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

template<typename T>
ostream& operator<<(ostream& os,const list<T>& a){
	os<<'[';
	foreach(i,a) os<<(i==a.begin()?"":" ")<<*i;
	return os<<']';
}

int main()
{
	for(int q;cin>>q,q;){
		list<pair<int,pii>> allocated;
		allocated.emplace_back(-1,pii(1e9,1e9+1));
		rep(_,q){
			char type; cin>>type;
			if(type=='W'){
				int label,len; cin>>label>>len;
				int pos=0;
				foreach(i,allocated){
					if(len==0) break;
					int first=i->second.first,last=i->second.second;
					if(first>pos){
						int block=min(first-pos,len);
						allocated.emplace(i,label,mp(pos,pos+block));
						len-=block;
					}
					pos=last;
				}
			}
			if(type=='D'){
				int label; cin>>label;
				for(auto i=allocated.begin();i!=allocated.end();){
					if(i->first==label)
						i=allocated.erase(i);
					else
						i++;
				}
			}
			if(type=='R'){
				int idx; cin>>idx;
				int label=-1;
				foreach(i,allocated){
					int first=i->second.first,last=i->second.second;
					if(first<=idx && idx<last){
						label=i->first;
						break;
					}
				}
				cout<<label<<endl;
			}
		}
		cout<<endl;
	}
	
	return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;





int main() {

	int n;
	ll k;
	cin >> n >> k;
	VLL a(n);
	REP(i, n)cin >> a[i];

	VI b(45, 0);
	REP(i, 45) {
		REP(j, n) {
			if (((ll)(1LL << i) & a[j]))b[i]++;
		}
	}
	VI c(45, 0);

	REP(i, 45) {
		if (((ll)((1LL << i)) & k))c[i]++;
	}

	VVLL dp(45, VLL(2, -1));
	dp[44][0] = 0;
	for (int i = 43; i >= 0; i--) {
		if (dp[i + 1][1] >= 0) {
			dp[i][1] = max(dp[i][1], dp[i + 1][1] + (1LL << i)*max(b[i], n - b[i]));
		}
		if (dp[i + 1][0] >= 0) {
			if (c[i]) {
				dp[i][1] = max(dp[i][1], dp[i + 1][0] + (1LL << i)*b[i]);
				dp[i][0] = max(dp[i][0], dp[i + 1][0] + (1LL << i)*(n - b[i]));
			}
			else {
				dp[i][0] = max(dp[i][0], dp[i + 1][0] + (1LL << i)*b[i]);
			}
		}
		
	}

	cout << max(dp[0][0], dp[0][1]) << endl;

}

Measured memory_bytes: 1024
s = input()

y1 = [0 if x % 2 ==0 else 1 for x in range(len(s))]
y2 = [0 if x % 2 !=0 else 1 for x in range(len(s))]

ans1 = sum([1 for i,j in zip(s,y1) if int(i)==j])
ans2 = sum([1 for i,j in zip(s,y2) if int(i)==j])
print(min([ans1,ans2]))

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

using ll = long long;
#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 REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

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

    vector<int> a(n);
    vector<int> b(n);
    vector<int> ac(n, 0);
    vector<int> bc(n, 0);
    REP(i, n) {
        cin >> a[i];
        if (i == 0 || a[i - 1] < a[i]) ac[i] = a[i];
    }
    REP(i, n) cin >> b[i];
    REPR(i, n) {
        if (i == n - 1 || b[i + 1] < b[i]) bc[i] = b[i];
    }

    ll ans = 1;
    REP(i, n) {
        if (ac[i] != 0 && bc[i] != 0) {
            if (ac[i] != bc[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else if (ac[i] != 0 && bc[i] == 0) {
            if (ac[i] > b[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else if (ac[i] == 0 && bc[i] != 0) {
            if (a[i] < bc[i]) {
                cout << 0 << endl;
                return 0;
            }
        } else if (ac[i] == 0 && bc[i] == 0) {
            ans *= (ll)min(a[i - 1], b[i + 1]);
            ans %= MOD;
        }
    }

    cout << ans << endl;
}


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

bool c=true;
set<int > s;
int n, a[101010];
long long ans=1;
map<int , int> m;

int main(){
cin >> n;
for(int i =1; i<=n; i++){
    cin >> a[i];
    m[a[i]]++;
    s.insert(a[i]);
    if(m[a[i]]>2)c = false;
}
if(!c) return 0*printf("%d", 0);
if(n%2==1&&m[0]>1) return 0*printf("%d", 0);
int x = s.size();
if(n%2==1)x--;
for(int i =1; i<=x;i++){
    ans = (ans*2)%mod;
}
cout << ans << endl;

return 0 ;}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    vector<int> a(2);
    cin >> a[0] >> a[1];
    int k;
    cin >> k;
    int now = 0;
    rep(i,k) {
        int n = a[now];
        if(n%2 == 1) a[now]--;
        a[1-now] += a[now]/2;
        a[now] /= 2;
        now = 1-now;
    }
    cout << a[0] << " " << a[1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x>y?x=y:0;}
	template <class T> inline void apx(T &x,const T y){x<y?x=y:0;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	int n=nxi(),q=nxi(),r_end=-1;
	lint ans=0;
	for(int i=1; i<=n; ++i){
		int p=nxi();
		ans+=(p+q-1)-std::max(p-1,r_end);
		r_end=p+q-1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b[10000],c[10000],d,e,i;
	while(1){
		d=0;
		e=0;
	scanf("%d",&a);
		if(a==0){
			return 0;
		}
	for(i=0;i<a;i++){
		scanf("%d %d",&b[i],&c[i]);
		if(b[i]>c[i]){
			d+=b[i]+c[i];
			}else if(b[i]<c[i]){
				e+=b[i]+c[i];
			}else if(b[i]==c[i]){
				d+=b[i];
				e+=c[i];
			}
	}
	printf("%d %d\n",d,e);
	}
}

Measured memory_bytes: 676
from sys import stdin
input = stdin.readline

c11,c12,c13=map(int, input().split())
c21,c22,c23=map(int, input().split())
c31,c32,c33=map(int, input().split())
# a1=0を仮定すると
# c11=b1,    c12=b2,    c13=b3
# c21=a2+b1, c22=a2+b2, c23=a2+b3
# c31=a3+b1, c32=a3+b2, c33=a3+b3

b1=c11
b2=c12
b3=c13
a2=c21-b1
a3=c31-b1

if c22==a2+b2 and c23==a2+b3 and c32==a3+b2 and c33==a3+b3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
//subset sum problem

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1=pow(10,9)+7;
int mod2=998244353;
ll inf=1e9;
ll maxxy=1e6+9;
typedef long double ld;
const double PI =  3.141592653589793238;

ll power(ll x, ll y, ll pp)
{
    ll res = 1;
    x = x % pp;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % pp;
        y = y>>1;
        x = (x*x) % pp;
    }
    return res;
}

ll modInverse(ll n, ll pp)
{
    return power(n, pp-2, pp);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<double> p(n);
    for (int i = 0; i <n ; ++i) {
        cin>>p[i];
    }
    vector<double> dp(n+1);//dp[i]==there are i heads so far;
    dp[0]=1;
    for (int coins = 0; coins <n ; ++coins) {
        for (int i = coins+1; i >=0 ; i--) {
            if(i>0){
                dp[i]=dp[i-1]*p[coins]+dp[i]*(1-p[coins]);
            }
            else
                dp[i]*=(1-p[coins]);
        }
    }
    double answer=0;
    for (int heads = 0; heads <=n ; ++heads) {
        ll tails=n-heads;
        if(heads>tails)
            answer+=dp[heads];
    }
    cout<<fixed<<setprecision(10)<<answer<<"\n";
    /*ll a[2];
    a[0]=1;
    a[1]=2*a[0]+a[1]*1;
    cout<<a[0]<<"\n";
    cout<<a[1]<<"\n";*/
    return 0;
}


Measured memory_bytes: 3824
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]
correct = 0
for i in range(N):
    ans = 0
    for j in range(M):
        ans += B[j]*A[i][j]
    ans += C
    correct += (ans > 0)

print(correct)

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

int main(void) {
	long long n, m; cin >> n >> m;
	long long correct = 0, penalty = 0;
	vector<int> WA(105000);
	vector<bool> AC(105000);

	for (int i = 1; i <= n; i++) {
		WA[i] = 0;
		AC[i] = false;
	}

	for (int i = 0; i < m; i++) {
		int p; string s;
		cin >> p >> s;
		if (AC[p]) continue;
		if (s == "AC") {
			AC[p] = true;
			correct++;
			penalty += WA[p];
		}
		else if (s == "WA") {
			WA[p]++;
		}
	}

	cout << correct << " " << penalty << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll dist(const P& p1, const P& p2) {
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h, w, D; cin >> h >> w >> D;
    const ll n = h * w;
    vector<vector<ll>> m(h, vector<ll>(w)); cin >> m;
    rep(y, h) rep(x, w) m[y][x]--;
    vector<P> v(n);
    rep(y, h) rep(x, w) {
        v[m[y][x]] = P(x, y);
    }
    vector<ll> d(n, 0);
    rep(i, D, n) {
        d[i] = d[i-D] + dist(v[i], v[i-D]);
    }
    ll Q; cin >> Q;
    rep(q, Q) {
        ll a, b; cin >> a >> b; --a, --b;
        cout << d[b] - d[a] << endl;
    }
}


Measured memory_bytes: 3968
n,y=map(int,input().split())
a,b,c=-1,-1,-1
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i+5000*j+1000*(n-i-j)==y:
            a=i
            b=j
            c=n-i-j

print(a,b,c)

Measured memory_bytes: 9144
# coding: utf-8
n = int(input())
num = list(map(int, input().split()))
for i in range(n):
    tmp = num[i]
    j = i 
    while j>0 and num[j-1] > tmp:
        num[j] = num[j-1]
        j -= 1
    num[j] = tmp
    for i in range(n):
        if i==n-1:
            print(num[i], end='')
            break
        print(num[i], end=' ')
    print()

Measured memory_bytes: 7976
s = map(int, input())
t = list(map(int, input().split()))

is_even = True
count = 0

while(is_even):
    for r in t:
        if t[0] % 2 == 0:
            t.append(t[0] // 2)
            t.pop(0)
        else:
            is_even = False
            break
    else:  
        count += 1
        
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

/*---------------------------------------------------------------------------------------------------*/

void solve()
{
    int n;
    cin >> n;
   int pre[n+1]={0};
   int a[n+1];
   fp(i,1,n)
    cin >> a[i];
   fp(i,1,n)
    pre[i]=(pre[i-1]+a[i])%mod;
   int ans=0;
   fp(i,1,n)
   {
       ans=(ans%mod + (a[i]%mod * (pre[n]-pre[i]+mod)%mod)%mod)%mod;
   }
   cout << ans << '\n';
  return;
} 

signed main()
{
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  FAST
  int T=1;
  // cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 6776
n, m = map(int, input().split())

lac = [0] * (n+1)
lwa = [0] * (n+1)

for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        lac[p] += 1
    else:
        if lac[p] == 0:
            lwa[p] += 1

ans = 0
pnl = 0

for i in range(1, n+1):
    if lac[i] > 0:
        ans += 1
        pnl += lwa[i]

print("{} {}".format(ans, pnl))


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

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

  int ans = 1024;
  for (int i = 0; i < 1 << N; i++) {
    int n = 1;
    for (int b = 0; b < N; b++) {
      n = (i & 1 << b) ? n * 2 : n + K;
    }
    ans = min(ans, n);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
 
  int longest = a.at(0) + (k - a.at(n - 1));
  rep(i, n - 1) {
    int x = a.at(i + 1) - a.at(i);
    longest = max(longest, x);
  }
 
  cout << k - longest << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<iostream>
#include<vector>
using namespace std;
const int MAX_T = 3000;
int M, start, goal, dice[6];
vector<int> N;
 
bool isPositionValid(int p){return 0<=p && p<M;}
 
vector<int> MakePath(int from){
    static vector<bool> visit(M);
	static vector<int> path(M);
    static auto checkPath = [](int moveto)->int{
        if(!isPositionValid(moveto))	return 2*MAX_T;
        else{
            int position = moveto+ N[moveto];
            if(!visit[position]) MakePath(position);
            return  path[position]+1;
        }
    };
 
    if(from == start){
		fill(path.begin(), path.end(), MAX_T+1);
    }
 
    visit[from] = true;
    int bestpath = MAX_T;
    if(from==goal)  bestpath = 0;
    else{
        for(int d : dice){
            bestpath = min(bestpath, checkPath(from + d));
            bestpath = min(bestpath, checkPath(from - d));
        }
    }
    path[from] = bestpath;
    return path;
}
 
int main(){
    // 入力
    cin >> M;
    for(int r=0; r<6; r++)   cin >> dice[r];
    cin >> start >> goal;
	start--, goal--;
	N.resize(M);
	for(int m=0; m<M; m++)   cin >> N[m];
	
	// 最短経路の探索
    auto path = MakePath(start);
     
    // 本番
    int position = start;
    for(int t=0; t<MAX_T; t++){
        if(position == goal) break;
     
        int r;
        cin >> r;
        int d = dice[r-1];
 
        static auto tryMove = [&path](int moveto, int& position)->bool{
			if(isPositionValid(moveto)){
				int new_position = moveto + N[moveto];
                if(path[position] > path[new_position]){
					position = new_position;
					return true;
				}
			}
            return false;
        };
     
		int output;
        if     (tryMove(position + d, position)) output = 1;
		else if(tryMove(position - d, position)) output = -1;
		else output = 0;
		cout << output << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1308
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

l = ins()
a = l[::-1]
n = len(l)
x = 3 if a[0]=='1' else 1
for i in range(1,n):
    if a[i]=='1':
        x = (2*x+pow(3,i,R))%R
print(x)


Measured memory_bytes: 3188
n = int(input())
a = list(map(int,input().split()))

a = sorted(a)
a = list(reversed(a))

ans = 0
index = 0

for i in range(n):
    if i == 0:
        continue
    elif i == 1:
        ans += a[0]
        index += 1
    elif i%2 == 0:
        ans += a[index]
    else:
        ans += a[index]
        index += 1

print(ans)


Measured memory_bytes: 31752
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

int n;
ll vs[200000+10];
ll nvs[200000+10];

// ll xs[200000+10]; // xs[i]: vs[i]に何回-2を掛けたらvs[i-1]以上になるか
// ll ys[200000+10]; // ys[i]: nvs[i]に何回-2を掛けたらnvs[i+1]以下になるか

ll memo1[200000+10][40];
ll memo2[200000+10][40];

ll go1(int pos, int x) {
  assert(pos > 0);
  if(x > 30) {
    ll res = go1(pos, 30);
    res += (x-30LL) * (n-pos);
    return res;
  }
  if(pos >= n) {
    return 0;
  }
  ll &res = memo1[pos][x];
  if(res < 0) {
    ll prev = vs[pos-1] << x;
    ll cur = vs[pos];
    ll cnt = 0;
    while(prev > cur) {
      cur *= 4;
      cnt += 2;
    }
    res = cnt + go1(pos+1, cnt);
    // cerr << "go1 " << pos << " " << x << " " << res << " " << cnt << endl;
  }
  return res;
}

ll go2(int pos, int x) {
  assert(pos <= n-2);
  if(x > 30) {
    ll res = go2(pos, 30);
    res += (x-30LL) * (pos+1);
    return res;
  }
  if(pos < 0) {
    return 0;
  }
  ll &res = memo2[pos][x];
  if(res < 0) {
    ll next = nvs[pos+1] * (1LL << x);
    ll cur = nvs[pos];
    ll cnt = 0;
    while(cur > next) {
      cur *= 4;
      cnt += 2;
    }
    res = cnt + go2(pos-1, cnt);
    // cerr << "go2 " << pos << " " << x << " " << res << endl;
  }
  return res;
}


int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &vs[i]);
    nvs[i] = vs[i] * -2;
  }
  memset(memo1, -1, sizeof memo1);
  memset(memo2, -1, sizeof memo2);
  
  ll res = 1000000000000000000LL;
  for(int i = 0; i <= n; ++i) {
    // i番目からを正にする
    ll cur = i; // i番目より前には軒並み-2を掛ける
    cur += go1(i+1, 0); // 正側
    cur += go2(i-2, 0); // 負側
    // cerr << i << ":" << cur << endl;
    res = min(cur, res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 147072
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
#define INF 1000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int w[300];
bool dp[300][300];
int ddp[301];

void solve(){
    memset(dp,0,sizeof(dp));
    rep(i,n) cin >> w[i];
    for(int i = 1; i < n; i+= 2){
        for(int j = 0; j < n-i; j++){
            if(abs(w[j]-w[j+i]) <= 1){
                if(i == 1 || dp[j+1][j+i-1] == true){
                    dp[j][j+i] = true;
                }
            }
            for(int k = j+1; k <= j+i-2; k += 2){
                if(dp[j][k] == true && dp[k+1][j+i] == true){
                    dp[j][j+i] = true;
                }
            }
        }
    }
    rep(i,n) ddp[i] = 0;
    for(int i = 1; i < n; i += 2) if(dp[0][i]) ddp[i] = i+1;
    for(int i = 1; i < n; i++){
        ddp[i] = max(ddp[i],ddp[i-1]);
        for(int j = 1; j < n-i; j += 2){
            if(dp[i][i+j]) ddp[i+j] = max(ddp[i+j],ddp[i-1]+j+1);
        }
    }
    cout << ddp[n-1] << endl;
}

int main(){
    while(cin >> n){
        if(n == 0) break;
        solve();
    }
}


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() { ;
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int L = sc.nextInt();


		//作る予定だったアップルパイの味
		int aji1 = 0 ;
		int eat = N + Math.abs(L) ;
		for( int i = 1 ; i <= N ; i ++) {
			int aji = 0 ;
			if(i == 0) {
				aji = L ;
			}else {
				aji = (L + i - 1);
			}
			aji1 += aji ;

			int abs = Math.abs(aji) ;
			if(abs < Math.abs(eat)) {
				eat = aji ;
			}
		}

		//出来上がるアップルパイの味
		int aji2 = aji1 - eat ;
		System.out.println(aji2);
	}

}


Measured memory_bytes: 21972
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

int main() {
  int N, M, X;
  std::vector<int> A;

  cin >> N >> M >> X;
  A.resize(N + 1, 0);
  for (int i = 0; i < M; ++i) {
    int x;
    cin >> x;
    A[x] = 1;
  }

  int ans, tmp1 = 0, tmp2 = 0;

  for (int i = X - 1; i >= 1; i--) {
    tmp1 += A[i];
  }

  for (int i = X + 1; i < N + 1; ++i) {
    tmp2 += A[i];
  }

  ans = std::min(tmp1, tmp2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int n, a;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		while (a % 2 != 1) {
			a /= 2;
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
s = input()

# 最初の2人を決めると全部決まっていく

def make_arr(first,second):
  result = [first,second]
  last,prev = second,first
  for ox in s[1:] + s[0]:
    if (ox == 'o') ^ (last == 0):
      # 両隣が異なる
      last,prev = 1-prev,last
    else:
      # 両隣が一致
      last,prev = prev,last
    result.append(last)
    continue
  bl = (result[0] == result[-2]) and (result[1] == result[-1])
  return bl,result[:-2]


answer = '-1'
for fi,se in [[0,0],[0,1],[1,0],[1,1]]:
  bl,li = make_arr(fi,se)
  if bl:
    answer = ''.join(['W' if x else 'S' for x in li])
print(answer)

Measured memory_bytes: 6372
#include <iostream>

using namespace std;

int a[100][100];
int b[100][100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, l;
    cin>>n>>m>>l;
    for(int i=0; i<n; i++) {
        for(int j=0; j<m; j++) {
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++) {
        for(int j=0; j<l; j++) {
            cin>>b[i][j];
        }
    }
    long long ans;
    for(int i=0; i<n; i++) {
        for(int j=0; j<l; j++) {
            ans=0;
            for(int k=0; k<m; k++) {
                ans+=a[i][k]*b[k][j];
            }
            if(j)cout<<' ';
            cout<<ans;
        }
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    ll N;
    cin>>N;
    cout<<((N-1)*(N))/2<<endl;
    return 0;
}

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

const ll mod=1e9+7;
ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}

int main() {
 ios::sync_with_stdio(false);
 cin.tie(0);
 int N,K;
 cin >> N >> K;
 /* int c[N+1][N+1];
 rep(i,N+1)rep(j,N+1) c[i][j] = 0;
 rep(i,N+1) c[i][0] = 1;
 rep1(j,N){
   for (int i = 1; i <= N; i++) {
     c[j][i] = mu(c[j][i - 1], mu(N - i + 1, dv(1,i)));
     //   cout << c[i] <<endl;
   }
 }
 rep(i,N+1){
   cout <<c[4][i] << endl;
   }*/
 ll cn[K];
 cn[0] = 1;
 for (int i = 1; i <= K-1; i++) {
   cn[i] = mu(cn[i - 1], mu(K- i, dv(1,i)));
   //   cout << cn[i] << endl;
 }
 ll cnk[N -K];
 cnk[0] = 1;
 for (int i = 1; i <= N-K-1; i++) {
   cnk[i] = mu(cnk[i - 1], mu(N-K-i, dv(1,i)));
   //   cout << cnk[i] << endl;
 }
 /*
   c[n+1]
 c[0] = 1;
 for (int i = 1; i <= n; i++) {
   c[i] = mu(c[i - 1], mu(n - i + 1, dv(1,i)));
   cout << c[i] <<endl;
   }*/

 rep1(i,K){
   int ans=0;
   if(i==1) ans = N-K+1;
   //   else if(i > N/2) ans =0;
   else{
     ll blue = cn[i-1];
     //       cout << blue << endl;
     if(N-K >= i-1){
       ans = mu(blue, cnk[i-2]);
       //       cout << c[N-K][i-2] << endl;
       //              cout << ans << endl;
     }
     if(N-K >= i){
       ans = ad(ans,mu(blue, cnk[i-1]*(2*1LL)));
       //       cout << ans << endl;
     }
     if(N-K >= i+1){
       ans = ad(mu(blue, cnk[i]),ans);
       //       cout << ans << endl;
     }
   }

   /*
   else if(i==N/2){
     ans = mu(c[K][i-1],c[N-K][i-2]);
   }
  else{
    ans = ad(ad(mu(c[K][i-1],c[N-K][i]),mu(c[K][i-1],1LL*2*c[N-K][i-1])),mu(c[K][i-1],c[N-K][i-2]));
    }*/
   cout << ans << endl;

 }

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long ll;

ll mod = 1e9 + 7;
ll n, k;
ll d[200001];

ll go(ll x, ll y) {
	if (y == 1)return x;
	if (y & 1) {
		return ((x * go(x, y - 1)) % mod);
	}
	else {
		ll tmp = go(x, y / 2);
		return ((tmp * tmp) % mod);
	}
}

ll go2(ll x, ll y) {
	ll s = d[x];
	ll t = d[x - y] * d[y]; t %= mod;
	ll e = go(t, mod - 2);
	ll cnt = s * e; cnt %= mod;
	return cnt;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);	
	
	cin >> n >> k;
	ll ans = 0;
	d[0] = 1;
	d[1] = 1;
	for (ll i = 2; i <= 200000; i++) {
		d[i] = d[i - 1] * i; d[i] %= mod;
	}

	for (ll i = 0; i <= min(k, n - 1); i++) {
		//nCi * (n - i)H(i);
		ll cnt = go2(n, i);
		ll cnt2 = go2(n - 1, i);
		cnt *= cnt2; cnt %= mod;
		ans += cnt; ans %= mod;
	}
	cout << ans << '\n';




}




Measured memory_bytes: 1792
N,M=map(int,input().split())
L=[]
for i in range(N):
  x,y,z=map(int,input().split())
  L.append([x,y,z])
L1=sorted(L,key=lambda x:sum(x))
L2=sorted(L,key=lambda x:x[0]-x[1]+x[2])
L3=sorted(L,key=lambda x:x[0]+x[1]-x[2])
L4=sorted(L,key=lambda x:-x[0]+x[1]+x[2])

ans=[0 for i in range(8)]
X=[0 for i in range(8)]
Y=[0 for i in range(8)]
Z=[0 for i in range(8)]
for i in range(M):
  X[0]+=L1[i][0]
  X[1]+=L1[-i-1][0]
  X[2]+=L2[i][0]
  X[3]+=L2[-i-1][0]
  X[4]+=L3[i][0]
  X[5]+=L3[-i-1][0]
  X[6]+=L4[i][0]
  X[7]+=L4[-i-1][0]
  Y[0]+=L1[i][1]
  Y[1]+=L1[-i-1][1]
  Y[2]+=L2[i][1]
  Y[3]+=L2[-i-1][1]
  Y[4]+=L3[i][1]
  Y[5]+=L3[-i-1][1]
  Y[6]+=L4[i][1]
  Y[7]+=L4[-i-1][1]
  Z[0]+=L1[i][2]
  Z[1]+=L1[-i-1][2]
  Z[2]+=L2[i][2]
  Z[3]+=L2[-i-1][2]
  Z[4]+=L3[i][2]
  Z[5]+=L3[-i-1][2]
  Z[6]+=L4[i][2]
  Z[7]+=L4[-i-1][2]
for i in range(8):
  ans[i]=abs(X[i])+abs(Y[i])+abs(Z[i])
print(max(ans))

Measured memory_bytes: 3316
N, X = map(int, input().split())

a = [1]
p = [1]
for i in range(N):
    a.append(a[-1]*2 + 3)
    p.append(p[-1]*2 + 1)
# print(a, p)

def f(lv, x):
    if lv == 0:
        return x
    c = a[lv-1] + 2
    if x == 1:
        return 0
    elif 1 < x < c:
        return f(lv-1, x-1)
    elif x == c:
        return p[lv-1] + 1
    elif c < x < a[lv]:
        return p[lv-1] + 1 + f(lv-1, x-c)
    else:
        return p[lv]

print(f(N, X))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
using ll = long long;
int main() {
	int H, W;
	int ans = 0;
	char C[55][55];
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> C[i][j];
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (C[i][j] == '#'&&C[i][j - 1] != '#'&&C[i - 1][j] != '#'
				&&C[i][j + 1] != '#'&&C[i + 1][j] != '#')
				ans++;
		}
	}
	if (ans == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

if s == 'SUN':
	print(7)
elif s == 'MON':
	print(6)
elif s == 'TUE':
	print(5)
elif s == 'WED':
	print(4)
elif s == 'THU':
	print(3)
elif s == 'FRI':
	print(2)
elif s == 'SAT':
	print(1)
else:
	print(0)



Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int N,M;
typedef pair<int,int> P;
vector<P> island_bsort;
//vector<P> island_asort;

bool compare(P a,P b){
    return a.second < b.second;
}

int main(){
    cin >> N >> M;
    int a[M], b[M];
    REP(i,M){
        cin >> a[i] >> b[i];
        island_bsort.push_back(P(a[i],b[i]));
        //island_asort.push_back(P(a[i],b[i]));
    }
    //sort(ALL(island_asort));
    sort(ALL(island_bsort),compare);
    int flag[M];
    REP(i,M){flag[i] = 1;} //i番目の橋が通れなくなったかどうかをメモ　まだ通れれば１

    int count = 0;
    int num_island = 0; //今なんばんめの島まで来てるか
    REP(i,M){
        if(num_island <= island_bsort[i].first){
            count++;
            num_island = island_bsort[i].second;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 2292
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

ans = 0
c = ['3', '5', '7']
N = 0

def check(l):
    return len(set(l)) == 3

def nummaker(k, n):
    global ans
    if k == 0:
        q = int(''.join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k-1, m)

def main():
    global N
    N = int(input().strip())
    for i in range(1, 11):
        nummaker(i, [])

if __name__ == '__main__':
    main()


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


int main(){
  int i;
  ll N,K;
  ll mind,tmp;
  cin >> N >> K;
  vector<ll> h(N);
  for(i=0;i<N;i++){
    cin >> h[i];
  }
  
  sort(h.begin(),h.end());
  
  mind = h[K-1] - h[0];
  tmp = mind;
  
  for(i=K;i<N;i++){
    tmp = h[i] - h[i-K+1];
    if(tmp < mind) mind = tmp;
  }
  cout << mind << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main() {
	string a, b;
	int flg=1;
	cin >> a >> b;
	if (a.size() != b.size()) {
		if (a.size() > b.size())flg = 0;
		else flg = 2;
	}
	else {
		for (int i = 0; i < a.size(); i++) {
			if (a[i] != b[i]) {
				if (a[i] > b[i])flg = 0;
				else flg = 2;
				break;
			}
		}
	}
	if (flg == 0)cout << "GREATER" << endl;
	else if (flg == 2)cout << "LESS" << endl;
	else cout << "EQUAL" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

bool vis[100005];
int n,x,a[1005];

int main()
{
	memset(vis,false,sizeof(vis));
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
	{
	  	x=0;
	  	for (int j=0;j<=min(4,n-i);j++)
	  	{
	  		x=x*10+a[i+j];
	  		vis[x]=true;
	  	}
	}
	for (int i=0;i<=100000;i++)
	{
		if (vis[i]==false) {
			printf("%d\n",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 2844
#include<iostream>
#include<vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
   long long int N;
   cin >>N;

   vector<long long int> a(N,0);
   for(long long int i=0;i<N;i++){
       cin >> a[i];
   }
   sort(a.begin(),a.end());

   bool b=false;

   for(long long int j=0;j<N-1;j++){
          if(a[j]==a[j+1]){
              b=true;
          }
   }
    
   if(b==true){
       cout << "NO" <<endl;
   }else{
       cout <<"YES" <<endl;
   }
   
    return 0;
}

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

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

   long long  int stools = 0;
    
    for(int i = 1; i < n; i++)
        {
            if(v[i]<v[i-1])
                {
                    stools+= (v[i-1]-v[i]);
                    v[i]=v[i-1];
                }
        }
    cout<<stools;
    
  return 0;
}


Measured memory_bytes: 4796
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//








int main(){
        int M, K;
        cin >> M >> K;

        if(M == 0){
                if(K == 0){
                        cout << "0 0" << endl;
                        return 0;
                }
                else{
                        cout << -1 << endl;
                        return 0;
                }
        }

        if(M == 1){
                if(K == 0){
                        cout << "0 0 1 1" << endl;
                        return 0;
                }
                else{
                        cout << -1 << endl;
                        return 0;
                }
        }

        if(K >= (1<<M)) {
                cout << -1 << endl;
                return 0;
        }

        vector<int> vs, ws;
        for(int i = 0; i < (1<<M); i++){
                if(i==K) continue;
                vs.emplace_back(i);
                ws.emplace_back(i);
        }

        vs.emplace_back(K);

        reverse(all(ws));
        for(int x : ws) vs.emplace_back(x);

        vs.emplace_back(K);

        for(int i = 0; i < (int)vs.size(); i++){
                if(i) cout << " ";
                cout << vs[i];
        }
        cout << endl;
        return 0;
}























Measured memory_bytes: 3568
fun main() = ABC162D.main()

object ABC162D {
    fun log(message: Any?) {
        //println(message)// TODO: ←消す
    }

    fun main() {
        val N = readInt()
        val S = readString()

        val rCount = S.filter { it == 'R' }.length
        val gCount = S.filter { it == 'G' }.length
        val bCount = S.filter { it == 'B' }.length

        val all = rCount.toLong() * gCount * bCount
        log("all=$all")

        var ignoreCount = 0L
        S.forEachIndexed { i, ic ->
            S.forEachIndexed { j, jc ->
                if (i >= j) return@forEachIndexed
                val k = j + j - i
                val kc = S.getOrNull(k)
                if (kc != null && ic != jc && jc != kc && kc != ic) {
                    ignoreCount++
                    log("ignore: $ic$jc$kc")
                }
            }
        }
        log("ignore=$ignoreCount")

        val ans = all - ignoreCount
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}

Measured memory_bytes: 55888
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n;cin >> n;
    vi v(n),s(n),t(n);
    rep(i, n) {
        cin >> v[i];
        if(i==0) s[i]=v[i];
        else s[i]=gcd(v[i],s[i-1]);
    }
    rev(i, n) {
        if(i==n-1) t[i]=v[i];
        else t[i]=gcd(v[i],t[i+1]);
    }
    int ma = -1;
    rep(i, n) {
        if(i==0) chmax(ma,t[i+1]);
        else if(i==n-1) chmax(ma,s[i-1]);
        else chmax(ma,gcd(s[i-1],t[i+1]));
    }
    cout << ma << endl;
    // for(auto p:s)cout << p << ' ';cout << endl;
    // for(auto p:t) cout << p << ' ';cout << endl;
    return 0;
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll ans = 0;
    if (n%2 == 1){

    } else {
        REP(i, 27){
            ans += n / ll(pow(5, i+1)) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
void swap(int *a, int *b)
{
  int temp;
  temp = *a;*a = *b;*b = temp;
}
//---------------------------------------------------

int main(void)
{
  LL n;
  LL c;
  LL a[200001]={0};
  scanf("%lld",&n);
  for (LL i = 0; i < n-1; i++) {
    scanf("%lld",&c );
    a[c]++;
  }
  for (LL i = 1; i <= n; i++) {
    printf("%lld\n", a[i]);
  }
  return 0;
}


Measured memory_bytes: 3296
s = input()
N = len(s)
table = {}
for i in range(N):
    table[s[i]] = table.get(s[i], [])
    table[s[i]] += [i]
ans = 100
for k, nums in table.items():
    ans = min(ans, max([nums[0], N - 1 - nums[-1]] +
                       [(nums[i + 1] - nums[i] - 1) for i in range(len(nums) - 1)]))
print(ans)


Measured memory_bytes: 3064
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b) = {
        let v: Vec<usize> = read_vec();
        (v[0], v[1])
    };
    let mut ans = if b >= a {
        a
    } else {
        a - 1
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;

ll C[55][55];

void comb_table(int n) {
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i)C[i][j] = 1LL;
			else {
				C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
			}
		}
	}
}

int main() {
	int i, n; cin >> n;
	int a, b; cin >> a >> b;

	vector <ll> v(n);
	for (i = 0; i < n; i++)cin >> v[i];

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

	double mx = 0.0;
	for (i = 0; i < a; i++) {
		mx += v[i];
	}
	mx /= a;

	int a_fpos, anum = 0;
	for (i = 0; i < n; i++) {
		if (v[i] == v[a - 1]) {
			anum++;
			if (anum == 1) {
				a_fpos = i;
			}
		}
	}

	ll ans = 0;

	if (a_fpos==0 && anum >= a) {
		for (i = a; i <= b; i++) {
			if (anum >= i) {
				ans += C[anum][i];
			}
		}
	}
	else {
		ans += C[anum][a-a_fpos];
	}
	
	printf("%.6lf\n", mx);
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}



int main() {
  int N;
  ll acnt=0,ans=0;
  string S;
  cin >> S;
  N=S.size();
  rep(i,N-1) {
    if (S[i]=='A') acnt++;
    else if (S[i]=='B') {
      if (S[i+1]=='C') {
        ans += acnt;
        i++;
      }
      else acnt=0;
    }
    else acnt=0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int n, a, b, c, tmp=0;
    scanf("%d", &n);
    
    for(int i=1; i<=n; i++){
        scanf("%d %d %d", &a, &b, &c);
     
        if(a>b){ tmp=a; a=b; b=tmp; }
        if(b>c){ tmp=b; b=c; c=tmp; }
        
        if(a*a+b*b==c*c) printf("YES\n");
        else printf("NO\n");
        
    }

    return 0;
}



Measured memory_bytes: 2040
#include <iostream>

using namespace std;

int main()
{
    int N,v[100005],x;
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>x;
        v[x]=i; //////cine are prioritatea x ;

    }
    for(int i=1;i<=N;i++){
        cout<<v[i]<<" ";
    }
    return 0;
}


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

int main(){
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1&&f==-1&&r==-1){
            break;
        }
        if(m==-1||f==-1){
            cout<<"F"<<endl;
        }else if(m+f>=80){
            cout<<"A"<<endl;
        }else if(m+f>=65){
            cout<<"B"<<endl;
        }else if(m+f>=50){
            cout<<"C"<<endl;
        }else if(m+f>=30){
            if(r>=50){
                cout<<"C"<<endl;
            }else{
                cout<<"D"<<endl;
            }
        }else{
            cout<<"F"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<set>
#include<cstring>

using namespace std;

int arr[200005];

int main()
{
    int n, a;
    while(cin >> n) {
        memset(arr, 0, sizeof(arr));
        n--;
        for(int i = 0; i < n; i++) {
            cin >> a;
            arr[a]++;
        }
        for(int i = 1; i <= n+1; i++)
            cout << arr[i] << endl;
    }
    return 0;
}


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

int main()
{
    int n,tmp;
    cin >> n;
  set<int> s;
    rep(i,n){
    cin >> tmp;
      s.insert(tmp);
    }
        if(s.size()==n)
    cout << "YES" << endl;
          else
    cout << "NO" << endl;

}



Measured memory_bytes: 9600