akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define si(a) scanf("%d",&a)
#define sll(a) scanf("%lld",&a)
#define sl(a) scanf("%ld",&a)
#define pll(a) printf("%lld\n",a) 
#define sc(a) scanf("%c",&a)a
#define pc(a) printf("%c",a)
#define ll long long
#define mod 1000000007
#define w while
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF INT_MAX
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll>
long double PI=acos(-1);
//////////////////////////////////////////////////////////////
const ll N=1e5+5;
ll Ans=1;
bool done[1000009];
vector < ll > primes;

void FindPrime(ll N)
{
    done[1] = 1;
    for(int i=2;i<=N;i++)
	{
        if(done[i]) continue;
        for(int j=i*2;j<=N;j+=i)
		{
            done[j] = 1;
        }
        primes.push_back(i);
    }
}

ll solve(ll Num)
{
    for(int i=0;i<primes.size();i++)
	{
    	int p=primes[i];
        if(p*p*p > Num) break;
        ll Count = 1;
        while(Num%p == 0)
		{
            Num /= p,Count++;
        }
        Ans *= Count;
    }
    ll sq = (ll)sqrt(Num);
    if(!done[Num]) 
	Ans *= 2;
    else if(sq*sq == Num && !done[sq]) 
	Ans *= 3;
    else if(Num != 1) 
	Ans *= 4;
    return Ans;
}


ll fact[N], invfact[N];



ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

ll modinv(ll k)
{
	return pow(k, mod-2, mod);
}


ll nCr(ll x, ll y)
{
	if(y>x)
		return 0;
	ll num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}

void initinv()
{
	fact[0]=1;
	fr(i,1,N)
	{
		fact[i]=(i*fact[i-1])%mod;
	}
	invfact[N]=modinv(fact[N]);
	for(int i=N-1;i>=1;i--)
	{
		invfact[i]=((i+1)*invfact[i+1])%mod;
	}
}
///////////////////////////////////////////////////////////////
int main()
{
	char ch;
	cin>>ch;
	if(ch>='A'&&ch<='Z')
	cout<<"A";
	else if(ch>='a'&&ch<='z')
	cout<<"a";
    return 0;
}





Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
const int N=705;
inline int gi() {
  char ch=getchar(); int q=0,x=0;
  while(ch<'0'||ch>'9') q=(ch=='-'?1:q),ch=getchar();
  while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int n,m,c[N][N],col[N],vis[N],cnt,flag;
void dfs(int x,int cl){
  vis[x]=cnt,col[x]=cl;
  for (int i=1; i<=n; ++i)
    if (!c[x][i]){
      if (!vis[i])
	dfs(i,cl^1);
      else
	if (col[i]==cl)
	  flag=1;
    }
  return;
}
bitset<N>f,g;
int main(){
  int a,b; cin>>n>>m;
  for (int i=1; i<=m; ++i)
    a=gi(),b=gi(),c[a][b]=c[b][a]=1;
  for (int i=1; i<=n; ++i)
    c[i][i]=1;
  f.set(0);
  for (int i=1; i<=n; ++i)
    if (!vis[i]){
      ++cnt,dfs(i,0);
      if (flag) break;
      int c0=0,c1=0;
      for (int x=1; x<=n; ++x)
	if (vis[x]==cnt)
	  col[x]==0?++c0:++c1;
      g=f;
      f=(g<<c0)|(g<<c1);
    }
  if (flag) return puts("-1"),0;
  int ans=m;
  for (int i=1; i<=n; ++i)
    if (f[i]==1)
      ans=min(ans,(i*(i-1)+(n-i)*(n-i-1))/2);
  cout<<ans;
  return 0;
}

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

#define Bye return 0
#define ll long long
const ll M = 1e9+7;
const ll SIZE = 2e5+1;
vector<ll> ps(SIZE, 0); 
int e, n;
ll res = 0;

int scan(){
    scanf("%d", &e);
    return e;
}

void solve(){
    cin>>n;
    for (int i=1; i<=n; i++){
        ps[i] = (ps[i-1] + scan()*1ll)%M;
        res = (res%M + (e*ps[i-1])%M)%M;
    }
    cout<<res<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 4692
#include<bits/stdc++.h>
typedef long long i64;
const int P=924844033,M=2333;
int N,K;
int pw(int a,int n){
	if(n<0)n+=P-1;
	int v=1;
	for(;n;n>>=1,a=i64(a)*a%P)if(n&1)v=i64(v)*a%P;
	return v;
}
int A[M],B[M],r[M],E[M],fac[M],fiv[M];
int fix(int x){return x+(x>>31&P);}
void ntt(int*a,int t){
	for(int i=1;i<N;++i)if(i<r[i])std::swap(a[i],a[r[i]]);
	for(int i=1;i<N;i<<=1){
		for(int j=0;j<N;j+=i<<1){
			i64 z=pw(5,(P-1)/(i<<1)*t);
			E[0]=1;
			for(int k=1;k<i;++k)E[k]=E[k-1]*z%P;
			int*b=a+j,*c=b+i;
			for(int k=0;k<i;++k){
				int x=b[k],y=c[k]*i64(E[k])%P;
				b[k]=fix(x+y-P);
				c[k]=fix(x-y);
			}
		}
	}
	if(t==-1){
		i64 I=pw(N,-1);
		for(int i=0;i<N;++i)a[i]=a[i]*I%P;
	}
}
int n,k;
int C(int n,int k){
	if(n<k)return 0;
	return fac[n]*i64(fiv[k])%P*fiv[n-k]%P;
}
int main(){
	scanf("%d%d",&n,&k);
	for(N=2,K=0;N<n+5;N<<=1,++K);
	for(int i=1;i<N;++i)r[i]=r[i>>1]>>1|(i&1)<<K;
	for(int i=fac[0]=1;i<=n;++i)fac[i]=i64(i)*fac[i-1]%P;
	fiv[n]=pw(fac[n],-1);
	for(int i=n;i;--i)fiv[i-1]=i64(i)*fiv[i]%P;
	int an=n/k,bn=n/k+1,ac=(k-n%k)*2,bc=n%k*2;
	for(int i=0;i<=n;++i)A[i]=C(an-i,i);
	for(int i=0;i<=n;++i)B[i]=C(bn-i,i);
	ntt(A,1),ntt(B,1);
	for(int i=0;i<N;++i)A[i]=i64(pw(A[i],ac))*pw(B[i],bc)%P;
	ntt(A,-1);
	int ans=0;
	for(int i=0;i<=n;++i)ans=(ans+i64(i&1?-1:1)*fac[n-i]*A[i])%P;
	printf("%d\n",fix(ans));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2147483647)
#define mod (1000000007)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)

void solve()
{
    int h,n,sum=0;cin>>h>>n;
    REP(i,n){
        int a;cin>>a;sum+=a;
    }cout<<(sum>=h?"Yes":"No")<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
using pair = pair<int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
const int INF = 100000000;
// " ", ' '

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

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

	int N; cin >> N;
	vec cnt(N+1, 0);
	for (int i=1; i<=N; i++) {
		int ii = i;
		while(true) {
			if (ii%2==0) {
				cnt.at(i) += 1;
				ii = ii/2;
			}
			else break;
		}
	}

	int max_cnt = 0;
	int max_i = 1;
	for (int i=1; i<=N; i++) {
		if (max_cnt<cnt.at(i)) {
			max_cnt = cnt.at(i);
			max_i = i;
		}
	}

	cout << max_i << endl;
	
}


Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void saiki(int now, int parent, int pcolor, vector<vector<int>> &edges, map<pii, int> &henmap, vector<int> &ans){
    int nowcol = 0;
    for(auto to: edges[now]){
        if(to == parent)
            continue;
        auto e = make_pair(min(now, to), max(now, to));
        if(nowcol == pcolor) nowcol++;
        ans[henmap[e]] = nowcol;
        saiki(to, now, nowcol, edges, henmap, ans);
        nowcol++;
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    vector<int> ans(n-1);
    map<pii, int> henmap;
    REP(i, n-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        henmap[{a, b}] = i;
    }
    int k = 0;
    REP(i, n)
        k = max(k, (int)edges[i].size());

    vector<int> parent(n);
    vector<vector<int>> children(n);
    saiki(0, -1, -1, edges, henmap, ans);

    cout << k << endl;
    REP(i, n-1){
        cout << ans[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 16256
<?php
$s = str_split(trim(fgets(STDIN)));
$n = count($s);
$m = 'No';
for($i=0; $i<$n; $i++){
if($s[$i]=='C'){
break;
}
}
if($i<($n -1)){
for($j=0; $i+$j<$n; $j++){
if($s[$i+$j]=='F'){
$m = 'Yes';
break;
}
}
}
print $m;
?>

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

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

  double t = 0;
  for (int i=0;i<n-1;i++){
    t = (v[i] + v[i+1]) / 2;
    v[i+1] = t;
  }
  cout << v[n-1];
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int a = 0, b = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == ')') {
			if(!a) b++;
			else a--;
		}
		if(s[i] == '(') {
			a++;
		}
	}
	for(int i = 0; i < b; i++) {
		cout << "(";
	}
	cout << s;
	for(int i = 0; i < a; i++) {
		cout << ")";
	}
	cout << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<unordered_map>
#define ll long long
using namespace std;
int main(){
  ll n;
  cin>>n;
  ll sum=0;
  unordered_map<int,int>mp;
  for(ll i=0;i<n;i++)
  {
      ll t;
      cin>>t;
      mp[t]++;
      sum+=t;
  }
  ll q;
  cin>>q;
  while(q--)
  {
      ll b,c;
      cin>>b>>c;
      if(mp.find(b)==mp.end())
      {
          cout<<sum<<endl;
          continue;
      }
      ll count=mp[b];
      sum=sum-count*b;
      mp.erase(b);
      sum+=count*c;
     mp[c]=mp[c]+count;
     // sum-=b;
     // sum+=c;
      cout<<sum<<endl;
  }
   return 0;
    
}


Measured memory_bytes: 6700
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int N;
    cin >> N;
    set<string> st;
    rep(_, N) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19224
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int h, w, ans = inf, tmp;
int a[26][26];

int main() {

	cin >> h >> w;
	rep(i, h) rep(j, w)cin >> a[i][j];

	rep(i, h) {
		rep(j, w) {
			rep(k, h) {
				rep(l, w) {
					tmp += a[k][l] * min(abs(i - k), abs(j - l));
				}
			}
			ans = min(ans, tmp);
			tmp = 0;
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  int x, y; cin >> x >> y;
  int sx = 0;
  vi vx, vy;
  bool disx = true;
  bool init = true;

  REP(i, SZ(s)) {
    if(s[i] == 'T') {
      init = false;
      disx = !disx;
      if(disx) {
        vx.pb(0);
      } else {
        vy.pb(0);
      }
    } else {
      if(init) sx++;
      else if(disx) vx[SZ(vx)-1]++;
      else vy[SZ(vy)-1]++;
    }
  }

  x -= sx;

  if(SZ(vx)) {
    vector<map<int, bool>> mx(SZ(vx));
    mx[0][vx[0]] = true;
    mx[0][-vx[0]] = true;
    REP(i, SZ(vx)-1) {
      MFOR(j, mx[i]) {
        if(j->first+vx[i+1] <= 8000) mx[i+1][j->first+vx[i+1]] = true;
        if(j->first-vx[i+1] >= -8000) mx[i+1][j->first-vx[i+1]] = true;
      }
    }

  

    bool okx = false;

    MFOR(i, mx[SZ(vx)-1]) if(i->first == x) okx = true;
    if(!okx) {
      cout << "No" << endl;
      return 0;
    }
  } else if(x != 0) {
    cout << "No" << endl;
    return 0;
  }

  if(SZ(vy)) {
    vector<map<int, bool>> my(SZ(vy));
    my[0][vy[0]] = true;
    my[0][-vy[0]] = true;
    REP(i, SZ(vy)-1) {
      MFOR(j, my[i]) {
        if(j->first+vy[i+1] <= 8000) my[i+1][j->first+vy[i+1]] = true;
        if(j->first-vy[i+1] >= -8000) my[i+1][j->first-vy[i+1]] = true;
      }
    }

    bool oky = false;

    MFOR(i, my[SZ(vy)-1]) if(i->first == y) oky = true;
    if(!oky) {
      cout << "No" << endl;
      return 0;
    }
  } else if(y != 0) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 190720
#include <iostream>
#include <vector>
#include <map>
#include <functional>

using namespace std;

int main() {
  int n,cap; cin >> n >> cap;
  vector<int>w(n), v(n);
  for (int i = 0; i < n; ++i) {
    cin >> w[i] >> v[i];
  }
  function<long long()>big_dp = [&]() -> long long {
     map<pair<int, long long>, long long>dp;
    function<long long(int, long long)>solve = [&](int i, long long j) -> long long{
      if (i == n) {
        return 0;
      }
      if (dp.find(make_pair(i,j)) != dp.end()) {
        return dp[make_pair(i,j)];
      }
      long long without = solve(i + 1, j);
      long long with = 0;
      if (j - w[i] >= 0)
        with = solve(i + 1, j - w[i]) + v[i];
      dp[make_pair(i, j)] = max(with, without);
      return max(with, without);
    };
    return solve(0, cap);
  };
  const int max_val = 1e3 * 1e2;
  int ans = 0;
  // vector<long long>dp(max_val + 1, 1e9 + 1);
  // dp[0] = 0;
  // for (int i = 0; i < n; i++) {
  //   for (int j = max_val; j >= v[i]; j--) {
  //     dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
  //     if (dp[j] <= cap) {
  //       ans = max(ans, j);
  //     }
  //   }
  // }
  vector<vector<long long>> dp(n + 1, vector<long long>(max_val + 1, 1e9 + 1));
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 0;
  }
  // for (int i = 0; i <= max_val; i++) {
  //   dp[0][i] = 0;
  // }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= max_val; j++) {
      dp[i][j] = dp[i-1][j];
      if (j - v[i-1] >= 0)
        dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1]);
      if (dp[i][j] <= cap) {
        ans = max(ans, j);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 80256
#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++)
typedef long long ll;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n, x;
  cin >> n >> x;
  vector<int> l(n);
  rep(i, n) {
    cin >> l[i];
  }
  int ans = 1;
  int pos = 0;
  rep(i, n) {
    pos += l[i];
    if (pos > x) break;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 200005;

int n, a[N];

long long myabs(long long a) {
	return a > 0 ? a : -a;
}

int main() {
	read(n);
	long long sum = 0, pre = 0;
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		sum += a[i];
	}
	long long ans = 1e18;
	for (int i = 1; i < n; ++i) {
		pre += a[i];
		ans = std::min(ans, myabs(sum - pre - pre));
	}
	print(ans);
}


Measured memory_bytes: 6432
#include <iostream>

using namespace std;

int main () {
	char b;
	cin >> b;
	switch (b) {
	case 'A': b='T'; break;
	case 'C': b='G'; break;
	case 'G': b='C'; break;
	case 'T': b='A'; break;
	}
	cout << b << endl;	
	return 0;
}


Measured memory_bytes: 256
<?php


$count = trim(fgets(STDIN));

$start = 0;
$max = 0;

$values = trim(fgets(STDIN));



for ($i =0; $i < strlen($values);$i++)
{
	$char = substr($values, $i,1);
	
	if ($char == 'D')
	{
		$start--;
	}
	if ($char == 'I')
	{
		$start++;
	}
	
	if ($start > $max)
	{
		$max = $start;
	}
}

echo $max . "\n";

Measured memory_bytes: 3828
a, *D, = [list(map(int, s.split())) for s in open(0)] 
D = D[0]
flag = 0
for d in D:
    if d % 2 == 0:
        if d % 3 == 0 or d % 5 == 0:
            pass
        else:
            flag +=1 
            break
if not flag:
    print("APPROVED")
else:
    print("DENIED")

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

int main() {
    int64_t N;
    cin >> N;
    if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
        cout << "hon" << endl;
    }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
}


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

#define ll long long

using namespace std;

int
main(void){
	ll a, b; cin >> a >> b;
	int n = 1;
	while(a <= b){
		if(a * 2 <= b){
			n++;
			a *= 2;
		}
		else break;
	}
	cout << n;
}


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

int main() {
  int n;
  cin >> n;
  int l, r;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import numpy as np

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

A = sorted(A, reverse=True)
A = np.array(A)

if N % 2 == 0:
  # # 偶数の場合
  end = (N - 2) // 2
  answer = A[0] + (A[1:end+1] * 2).sum()
else:
  # 奇数の場合
  end = (N - 2) // 2
  answer = A[0] + (A[1:end+1] * 2).sum() + A[end+1]

print(answer)


Measured memory_bytes: 49844
#include <iostream>

int main(int argc, char** argv) {
    char input;

    long long int num_of_W = 0;
    long long int sum_of_W = 0;
    int cnt = 0;
    while((input = getchar()) != EOF){
        if(input == '\n') break;

        if(input == 'W'){
            num_of_W++;
            sum_of_W += cnt;
        }

        cnt++;
    }

    std::cout << sum_of_W - (num_of_W-1)*num_of_W/2;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> dp(100005);
bool vis[100005];
int dfs(vector<vector<int>>& adj, int &i){
  if(vis[i]){
    return dp[i];
  }
  int ans = 0;
  vis[i] = 1;
  for(int j = 0; j < adj[i].size(); j++){
    ans = max(ans, 1+dfs(adj, adj[i][j]));
  }
  return dp[i] = ans;
}
int main(){
  int n, m;
  cin >> n >> m;
  memset(vis, 0, sizeof(dp));
  fill(dp.begin(), dp.end(), 0);
  vector<vector<int>> adj(n+1);
  for(int i = 0; i < m; i++){
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    
  }
  //dfs(adj, 1);
  for(int i = 1; i < n+1; i++){
    if(!vis[i]){
      dfs(adj, i);
    }
  }
  cout << *max_element(dp.begin(), dp.end()) << "\n";

}


Measured memory_bytes: 11252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 40
struct stage{
  char st[MAX][2][2];
  stage(){}
};
struct block{
  char st[2][2][2];
  block(){}
};
int h,n,ans;
int ax[]={-1,0,1,-1,0,1,-1,0,1};
int ay[]={-1,-1,-1,0,0,0,1,1,1};
vector<block> v;
bool out(int x,int y){
  return (x<0||1<x||y<0||1<y);
}
bool check(int d,int k){
  bool f=0;
  for(int l=0;l<2;l++)
    for(int i=0;i<2;i++)
      for(int j=0;j<2;j++)
	f|=(v[d].st[l][i][j]=='#'&&out(i+ax[k],j+ay[k]));
  return f;
}
bool check2(int d,int k,int z,stage s){
  bool f=0;
  for(int l=0;l<2;l++)
    for(int i=0;i<2;i++)
      for(int j=0;j<2;j++)
	f|=(v[d].st[l][i][j]=='#'&&(z+l==0||s.st[z+l-1][i+ax[k]][j+ay[k]]=='#'));
  return f;
}
void dfs(int d,int c,stage s){
  if(d==n){
    ans=max(ans,c);
    return;
  }
  //cout<<d<<"/"<<c<<endl;
  for(int k=0;k<9;k++){
    if(check(d,k)) continue;
    stage b=s;
    int z=MAX-2,o=0;
    while(!check2(d,k,z,b)) z--;
    //cout<<k<<":"<<z<<endl;
    for(int l=0;l<2;l++)
      for(int i=0;i<2;i++)
	for(int j=0;j<2;j++)
	  if(v[d].st[l][i][j]=='#')
	    b.st[z+l][i+ax[k]][j+ay[k]]='#';
    
    for(int l=0;l<MAX;l++){
      bool f=1;
      for(int i=0;i<2;i++)
	for(int j=0;j<2;j++)
	  f&=b.st[l][i][j]=='#';
      
      if(f){
	o++;
	for(int m=l;m<MAX-2;m++)
	  for(int i=0;i<2;i++)
	    for(int j=0;j<2;j++)
	      b.st[m][i][j]=b.st[m+1][i][j];
	l--;
      }
    }
    dfs(d+1,c+o,b);
  }
}
int main(){
  while(cin>>h>>n,h||n){
    stage s;
    memset(s.st,'.',sizeof(s.st));
    for(int k=0;k<h;k++)
      for(int i=0;i<2;i++)
	for(int j=0;j<2;j++)
	  cin>>s.st[k][i][j];
    v.clear();
    block b;
    for(int k=0;k<n;k++){
      for(int i=0;i<2;i++)
	for(int j=0;j<2;j++)
	  for(int l=0;l<2;l++)
	    cin>>b.st[i][j][l];
      v.push_back(b);
    }
    ans=0;
    dfs(0,0,s);
    cout<<ans<<endl;
  }
  return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N)
    {
        cin >> A[i];
        A[i]--;
    }
    vector<bool> isVisited(N, false);
    vector<ll> route;
    isVisited[0] = false;
    route.push_back(0);
    ll now = 0;
    ll repFirst;

    REP(i, N)
    {
        ll next = A[now];
        route.push_back(next);
        if (!isVisited[next])
        {
            isVisited[next] = true;
        }
        else
        {
            repFirst = next;
            break;
        }
        now = next;
    }

    ll loop;
    vector<ll> loopS;
    bool isLoop = false;
    REP(i, route.size() - 1)
    {
        if (route[i] == repFirst)
        {
            loop = route.size() - 1 - i;
            isLoop = true;
        }

        if (isLoop)
        {
            loopS.push_back(route[i]);
        }
    }

    ll ans;
    if (route.size() >= K + 1)
    {
        ans = route[K] + 1;
    }
    else
    {
        ll p = K - (route.size() - 1);
        ll res = p % loop;
        ans = loopS[res] + 1;
    }

    cout << ans << endl;
}


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

const int dx[] = {0,  -1, 0, 1, 0,  -1, 1, 1, -1,  -2, 0, 2, 0};
const int dy[] = {0,  0, -1, 0, 1,  -1, -1, 1, 1,  0, -2, 0, 2};
const int sz[] = {5, 9, 13};

struct Ink {
	int x, y, val;
	Ink(int x = 0, int y = 0, int val = 0) : x(x), y(y), val(val) {}
	bool operator < (const Ink &t) const {
		if (x != t.x) return x < t.x;
		if (y != t.y) return y < t.y;
		return val < t.val;
	}
};

set<int> done;
int grid[10][10];

inline int hash_(vector<Ink> &c, int n, int nx, int ny)
{
	typedef unsigned int uint;
	uint p = 1e9 + 7;
	uint mod = 1e9 + 9;
	uint h = 0;
	for (int i = 0; i < c.size(); i++){
		h = (h * p + c[i].x) % mod;
		h = (h * p + c[i].y) % mod;
		h = (h * p + c[i].val) % mod;
	}
	h = (h * p + n) % mod;
	h = (h * p + nx) % mod;
	h = (h * p + ny) % mod;
	return h;
}

inline bool ingrid(int x, int y)
{
	return x >= 0 && y >= 0 && x < 10 && y < 10;
}

vector<Ink> search(int n, vector<Ink> c, int nx, int ny)
{
	if (n == 0){
		if (c.size() == 0) return vector<Ink>(1);
		else return vector<Ink>(0);
	}
	if (c.size() == 0) return vector<Ink>(0);
	
	
	for (int i = 0; i < c.size(); i++){
		if (nx - 2 > c[i].x) return vector<Ink>(0);
		else if (nx - 2 == c[i].x){
			if (ny > c[i].y) return vector<Ink>(0);
		}
	}
	
	
	memset(grid, 0, sizeof(grid));
	for (int i = 0; i < c.size(); i++){
		grid[c[i].x][c[i].y] = c[i].val;
	}
	
	for (; nx < 10; nx++){
		for (; ny < 10; ny++){
			for (int s = 0; s < 3; s++){
				bool f = true;
				for (int dir = 0; dir < sz[s]; dir++){
					int tx = nx + dx[dir];
					int ty = ny + dy[dir];
					//if (!ingrid(tx, ty)) continue;
					if (!ingrid(tx, ty) || grid[tx][ty] == 0){
						for (int dir2 = 0; dir2 < dir; dir2++){
							int tx2 = nx + dx[dir2];
							int ty2 = ny + dy[dir2];
							grid[tx2][ty2]++;
						}
						f = false;
						break;
					}
					grid[tx][ty]--;
				}
				if (!f) continue;
				vector<Ink> v;
				for (int i = 0; i < c.size(); i++){
					if (grid[c[i].x][c[i].y]){
						v.push_back(Ink(c[i].x, c[i].y, grid[c[i].x][c[i].y]));
					}
				}
				vector<Ink> t = search(n - 1, v, nx, ny);
				if (t.size()){
					t.push_back(Ink(nx, ny, s));
					return t;
				}
				for (int dir = 0; dir < sz[s]; dir++){
					int tx = nx + dx[dir];
					int ty = ny + dy[dir];
					//if (!ingrid(tx, ty)) continue;
					grid[tx][ty]++;
				}
			}
		}
		ny = 0;
	}
	/*
	int h = hash_(c, n, nx, ny);
	if (done.count(h)) return vector<Ink>(0);
	done.insert(h);
	*/
	return vector<Ink>(0);
}

int main()
{
	int n;
	scanf("%d", &n);
	vector<Ink> c;
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			int x;
			scanf("%d", &x);
			if (x) c.push_back(Ink(i, j, x));
		}
	}
	
	vector<Ink> res = search(n, c, 0, 0);
	for (int i = 1; i < res.size(); i++){
		printf("%d %d %d\n", res[i].y, res[i].x, ++res[i].val);
	}
}

Measured memory_bytes: 1212
from itertools import combinations

N = int(input())
S = [input() for i in range(N)]

m = []
a = []
r = []
c = []
h = []
for i in range(N):
    if S[i][0] == 'M':
        m.append(S[i])
    elif S[i][0] == 'A':
        a.append(S[i])
    elif S[i][0] == 'R':
        r.append(S[i])
    elif S[i][0] == 'C':
        c.append(S[i])
    elif S[i][0] == 'H':
        h.append(S[i])

cnt = []
cnt.append(len(m))
cnt.append(len(a))
cnt.append(len(r))
cnt.append(len(c))
cnt.append(len(h))

com = list(combinations(range(5), 3))

ans = 0
for i in com:
    ans += cnt[i[0]]*cnt[i[1]]*cnt[i[2]]
print(ans) 

Measured memory_bytes: 60760
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

lli n,m;
vll ans;
lli a,b;

int main(){
    cin >> n >> m;
    ans = vll(n+1);
    for(lli i = 0;i < m;i++){
        cin >> a >> b;
        ans[a]++;
        ans[b]--;
    }
    for(lli i = 1;i <= n;i++){
        ans[i] += ans[i-1];
    }
    for(lli i = 1;i < n;i++){
        if(ans[i] % 2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
    
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 998244353
int pow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (int64_t) res * a % MOD;
		a = (int64_t) a * a % MOD;
	}
	return res;
}

int main() {
	static int fact[10000001];
	static int inv[10000001];
	fact[0] = 1;
	for (int i = 1; i <= 10000000; i++) fact[i] = (int64_t) fact[i - 1] * i % MOD;
	inv[10000000] = pow(fact[10000000], MOD - 2);
	for (int i = 10000000; i; i--) inv[i - 1] = (int64_t) inv[i] * i % MOD;
	
	int n;
	scanf("%d", &n);
	int res = pow(3, n);
	for (int i = n / 2 + 1; i <= n; i++) {
		res -= (int64_t) pow(2, n - i) * fact[n] % MOD * inv[i] % MOD * inv[n - i] * 2 % MOD;
		if (res < 0) res += MOD;
	}
	std::cout << res << std::endl;
	return 0;
}



Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[100010],cnt;
map<int,int>mp;
int main(){
	cin>> n;
	rep(i,n){
		cin>>a[i];
		mp[a[i]]=i;
	}
	sort(a,a+n);
	rep(i,n)cnt+=abs(mp[a[i]]-i)%2;
	cout<<cnt/2<<endl;
	return 0;
}

Measured memory_bytes: 5376
#include <cstdio>

int A[2000000];
int B[2000000];

void countingSort(int n) {
	int C[10001];

	//初期化
	for (int i = 0;i < 10001; i++){
		C[i] = 0;
	}

	//カウントしてCに格納していく
	for (int i = 0; i < n; i++) {
		C[A[i]]++;
	}

	for (int i = 1; i < 10001; i++) {
		C[i] = C[i] + C[i-1];
	}

	for (int i = n-1; i >= 0; i--) {
		B[C[A[i]] - 1] = A[i];
		C[A[i]]--;
	}

}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	
	countingSort(n);

	for (int i = 0; i < n - 1; i++) {
		printf("%d ", B[i]);
	}

	printf("%d\n", B[n-1]);
	return 0;
}


Measured memory_bytes: 18360
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
string s;
cin>>s;
int lo=s.size();
string a;
for(int i=0;i<lo;i++){
if(s[i]=='1')a+='1';
else if(s[i]=='0')a+='0';
else if(s[i]=='B'&& a.empty()!=1)a.erase(a.size()-1);
}
cout<<a<<endl;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
	"math"
)
var v [][]float64

func factorial(n int)int {
	ret := 1
	for i :=2;i<=n;i++{
		ret *=i
	}
	return ret

}
func calc(nums []int)float64 {
	ret := 0.0
	n := len(nums)
	for i:=1; i<n; i++{
		ret += v[nums[i]][nums[i-1]]
	}
	return ret
}
func perm(nums []int) float64{
	ret := 0.0
	ret += calc(nums)
	n := len(nums)
	p := make([]int,n+1)
	for i := 0; i<=n; i++{
		p[i]=i
	}
	for i :=1; i<n;{
		p[i]--
		j := 0
		if i%2 == 1{
			j = p[i]
		}
		nums[i],nums[j] = nums[j],nums[i]
		ret += calc(nums)
		for i=1; p[i]==0; i++{
			p[i] = i
		}
	}
	return ret
}
func main(){
	var N int
	fmt.Scanf("%d",&N)
	p := make([][]int,N,N)
	v = make([][]float64,N,N)
	l := make([]int,N,N)
	for i := range p{
		p[i] = make([]int,2,2)
		v[i] = make([]float64,N,N)
		l[i] = i
		fmt.Scanf("%d %d",&(p[i][0]),&(p[i][1]))
		for j:=0;j<i;j++ {
			v[j][i] = math.Pow(math.Pow(float64(p[i][0]-p[j][0]),2) + math.Pow(float64(p[i][1]-p[j][1]),2),0.5)
v[i][j] = v[j][i]
		}
	}
	fmt.Println(float64(perm(l))/ float64(factorial(N)))
}


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

int main(){
  int n;
  string s;
  cin >> n;
  if (n >= 1000) cout << "ABD" << endl;
  else cout << "ABC" << endl; 

  
  return 0; 
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    int n,l;
    cin>>n>>l;
    vector<string> s(n);
    REP(i,n) cin>>s[i];
    sort(s.begin(),s.end());
    REP(i,n){
        cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  if(n < 1200)System.out.println("ABC");
  else if(n < 2800)System.out.println("ARC");
  else System.out.println("AGC");
}}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
bool koma[2005];
vector<int> G[2005];
int dist[2005];
int cnt[2005];

int dfs(int v,int p=-1){
	int val=0;
	if(koma[v])val++;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]!=p){
			val+=dfs(G[v][i],v);
		}
	}
	return (cnt[v]=val);
}

P dfs2(int v,int p=-1){
	P rec=P(0,0);
	for(int i=0;i<G[v].size();i++){
		int nv=G[v][i];
		if(nv!=p){
			P p=dfs2(nv,v);
			p.first+=cnt[nv];
			p.second+=cnt[nv];
			if(p.first>rec.first){
				swap(p,rec);
			}
			P np;
			np.second=rec.second+p.second;
			if(p.second<rec.first){
				np.first=rec.first-p.second;
			}else{
				if((p.first+rec.first)%2==0)np.first=0;
				else np.first=1;
			}
			rec=np;
		}
	}
	return rec;
}

int solve(int s){
	memset(dist,-1,sizeof(dist));
	dist[s]=0;
	queue<int> que;
	que.push(s);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			int nv=G[v][i];
			if(dist[nv]==-1){
				dist[nv]=dist[v]+1;
				que.push(nv);
			}
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(koma[i]){
			ans+=dist[i];
		}
	}
	dfs(s);
	P p=dfs2(s);
	if(p.first==0)return ans/2;
	return INF;
}

int main(void){
	scanf("%d",&n);
	string s;
	cin >> s;
	for(int i=0;i<n;i++){
		if(s[i]=='1'){
			koma[i]=true;
		}
	}
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int ans=INF;
	for(int i=0;i<n;i++){
		ans=min(ans,solve(i));
	}
	if(ans==INF)ans=-1;
	printf("%d\n",ans);
	return 0;
}


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

C = [0] * N
A = [[] for _ in range(N)]

for i in range(N):
    C[i], *A[i] = list(map(int, input().split()))

ans = float("inf")
for i in range(1<<N):
    S = []
    for j in range(N):
        if i & (1<<j):
            S.append(j)
    
    W = [0] * M
    for s in S:
        for j in range(M):
            W[j] += A[s][j]
    
    flag = True
    for j in range(M):
        if W[j] < X:
            flag = False
            break

    if flag:
        res = 0
        for s in S:
            res += C[s]
        ans = min(ans, res)

if ans == float("inf"):
    print(-1)
else:
    print(ans)


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

int main(){
  
  int n, m, days = 0;
  cin >> n >> m;
  
  vector<int> a(m);  
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
    days += a.at(i);
  }
  
  if(n >= days){
    cout << n - days << endl;
  }else{
    cout << -1 << endl;
  }
 
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector<pair<int,int>> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(), A.end());

    vector<int> ans(N);
    for (int i = 0; i < N; i++) {
        auto &a = i < N/2 ? A[N/2] : A[N/2-1];
        ans[A[i].second] = a.first;
    }

    for (auto x: ans) {
        cout << x << endl;
    }

    return 0;
}


Measured memory_bytes: 4480
import numpy as np
n,m,c = map(int, input().split())
b = np.array(list(map(int, input().split())))
res = 0
for i in range(n):
  a = np.array(list(map(int, input().split())))
  if sum(a * b) + c > 0:
    res += 1
print(res)


Measured memory_bytes: 20668
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if (a < b) a = b;}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e18 + 1;

using arr3 = array<int, 3>;
map<arr3, int>mp;
int f(int x, int y, int z) {
	if (x == 0 && y == 0 && z == 0)return mp[{x, y, z}] = 0;
	if (mp.count({ x,y,z }))return mp[{x, y, z}];
	if (((x & 1) ^ (y & 1)) == (z & 1)) {
		int res1 = 2 * f(x >> 1, y >> 1, z >> 1);
		int res2 = INF;
		if (x > 0)res2 = 1 + 2 * f((x - 1) >> 1, (y + 1) >> 1, z >> 1);
		int res = min(res1, res2);
		if (res >= INF)return mp[{x,y,z}] = INF;
		else return mp[{x, y, z}] = res;
	}
	else {
		return mp[{x, y, z}] = INF;
	}
}

void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
	}
	int x = A[0], y = A[1];
	int z = 0;
	FOR(i, 2, N)z ^= A[i];
	ll ans = f(x, y, z);
	if (ans >= INF || ans == x)print(-1);
	else print(ans);
}


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//while (test());
	 //int q;
	 //cin >> q;
	 //while (q--)
	solve();
}


Measured memory_bytes: 3684
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

ans = 0
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
p = p[:x]
q = q[:y]

P = sum(i for i in p)
Q = sum(j for j in q)
ans = P+Q
apples = p+q
apples.sort()
for i in range(len(r)):
  if apples[i] < r[0]:
    ans = ans-apples[i] + r[0]
    del r[0]
  else:
    break
print(ans)

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

int main (){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << a[n-1];
	for(int j = n-2; j >= 0; j--){
		cout << " " << a[j];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int getLongestIndex(int length[3]);

 int main(void){
   int num;
   int length[3];

   fscanf(stdin,"%d",&num);
   for(int i = 0;i < num;i++){
     fscanf(stdin,"%d %d %d",&length[0],&length[1],&length[2]);
     if(length[0] != length[1] && length[1] != length[2] && length[0] != length[2]){
       int longest = length[getLongestIndex(length)];
       longest *= longest;

       int other = 0;
       for(int n = 0;n < 3;n++){
         if(n == getLongestIndex(length)){
           continue;
         }
         other += length[n] * length[n];
       }

       if(longest == other){
         printf("YES\n");
       }
       else{
         printf("NO\n");
       }
     }
     else{
       printf("NO\n");
     }
   }

   return 0;
 }

 int getLongestIndex(int length[3]){
   int longerIndex = -1;
   int longer = -1;
   for(int i = 0;i < 3;i++){
     if(longer < length[i]){
       longer = length[i];
       longerIndex = i;
     }
   }
   return longerIndex;
 }

Measured memory_bytes: 1012
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <chrono>
#include <random>
#include <bits/stdc++.h>
 
using namespace std;
template <typename T> T max(T a, T b) {return a>b?a:b;}
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
#define ll long long
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))

const double eps = (double)1e-6;
const int maxn = 2e5+5;
const ll mod = 1e9+7;



    

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

    int n, t; cin >> n;
    vector<int> a,b;
    for (int i = 0; i < n; i++) {
        cin >> t; a.push_back(t);
    }
    for (int i = 0; i < n; i++) {
        cin >> t; b.push_back(t);
    }

    for (int i = 0; i < n; i++) {
        if (a[i] < b[i]) break;
        else if (a[i] > b[i]) {
            swap(a,b);
            break;
        }
    }
    int cnt = 0;
    while (a != b) {
        next_permutation(a.begin(),a.end());
        cnt++;
    }
    cout << cnt << endl;

}

Measured memory_bytes: 256
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#include <initializer_list>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int a,b,c;
  cin>>a>>b>>c;
  if(a*c<b){cout<<c<<endl;}
  else{cout<<b/a<<endl;}
    
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<int> ans(100005,-1);
const int INF=10e9+10;
vector<int> dist(100005,INF);
void bfs(int s)
{
queue<int>q;
q.push(s);
dist[s]=0;
while(!q.empty())
{
int node=q.front();
q.pop();
for(auto i:adj[node])
{
if(dist[i]>dist[node]+1)
{
dist[i]=dist[node]+1;
ans[i]=node;
q.push(i);
}
}
}
}
int main()
{
int n,m;
cin>>n>>m;
adj.assign(n+1,vector<int>());
for(int i=0; i<m; ++i)
{
int a,b;
cin>>a>>b;
--a;
--b;
adj[a].push_back(b);
adj[b].push_back(a);
}
bfs(0);
int fn(0);
for(int i=0; i<n; ++i)
{
if(ans[i]==-1)
fn=1;
}
if(fn)
{
cout<<"Yes\n";
for(int i=1; i<n; ++i)
cout<<ans[i]+1<<"\n";
}
else
cout<<"No";
}


Measured memory_bytes: 10632
package main

import "fmt"

func main() {
	var h, w, n, sr, sc int
	var s, t string
	fmt.Scan(&h, &w, &n, &sr, &sc, &s, &t)

	L, R, T, B := 1, w, 1, h
	for i := 0; i < n; i++ {
		switch t[n-i-1] {
		case 'L':
			R = min(w, R+1)
		case 'R':
			L = max(1, L-1)
		case 'U':
			B = min(h, B+1)
		case 'D':
			T = max(1, T-1)
		}

		switch s[n-i-1] {
		case 'L':
			L++
		case 'R':
			R--
		case 'U':
			T++
		case 'D':
			B--
		}

		if L > R || T > B {
			break
		}
	}

	if (L <= sc && sc <= R) && (T <= sr && sr <= B) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 2176
//35
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<utility>

using namespace std;

char g[20][20];
int h,w;
int t[20][20];

struct S{
  int t,x,y;
};

int main(){
  while(cin>>h>>w,h|w){
    int ax,ay,bx,by;
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	cin>>g[y][x];
	if(g[y][x]=='A'){
	  ax=x;
	  ay=y;
	}else if(g[y][x]=='B'){
	  bx=x;
	  by=y;
	}
      }
    }
    fill(t[0],t[20],1<<30);
    queue<S> que;
    S is={0,ax,ay};
    que.push(is);
    while(!que.empty()){
      int x=que.front().x;
      int y=que.front().y;
      int ct=que.front().t;
      que.pop();
      if(t[y][x]<=ct)continue;
      t[y][x]=ct;
      for(int i=0;i<4;i++){
	int d[]={0,1,0,-1,0};
	int nx=x+d[i];
	int ny=y+d[i+1];
	if(nx<0||w<=nx||ny<0||h<=ny||t[ny][nx]<=ct+1||g[ny][nx]=='#')continue;
	S ns={ct+1,nx,ny};
	que.push(ns);
      }
    }
    string p;
    cin>>p;
    int e;
    for(e=0;e<10000;e++){
      if(t[by][bx]<=e)break;
      char o=p[e%p.size()];
      int ny=by+(o=='2')-(o=='8');
      int nx=bx+(o=='6')-(o=='4');
      if(0<=ny&&ny<h&&0<=nx&&nx<w){
	by=ny;
	bx=nx;
      }
    }
    if(e<10000){
      cout<<e<<' '<<by<<' '<<bx<<endl;
    }else{
      cout<<"impossible"<<endl;
    }
  }
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 300030
#define rep(i,n) for(ll i=0;i<n;++i) 

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

int main() {
    priority_queue<ll> pq;
    vector<vector <ll> > G(MAXN);
    ll n, m, tmp, ans;

    cin >> n;

    rep(i,n) {
        cin >> m;
        rep(k, m) {
            cin >> tmp;
            //cout << tmp;
            G[i].push_back(tmp);
        }
    }
    ans = 0;
    for(int i=n-1; i>=0; i--) {
        for(int k=0; k< G[i].size(); k++) {
            pq.push(G[i][k]);
        }
        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}



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

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

using namespace std;

const int LEN = 8;
const string correctWord = "AIZUNYAN";

int main(){
  set<string> S;
  string wrongWord = "AIDUNYAN";
  sort(wrongWord.begin(),wrongWord.end());
  do {
    S.insert(wrongWord);
  } while( next_permutation(wrongWord.begin(),wrongWord.end()) );

  string text;
  cin >> text;
  rep(i,text.size()){
    if( i + LEN - 1 < text.size() ) {
      if( S.count(text.substr(i,LEN)) ) {
	cout << correctWord;
	i += ( LEN - 1 );
      } else cout << text[i];
    } else cout << text[i];
  } puts("");
  return 0;
}

Measured memory_bytes: 2128