akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
int dp[100100];
void init() {
  memset(dp, 0x8f, sizeof dp);
  dp[0] = 1;
  for(int i = 0;i <= 5; i++) {
    for(int j = 100 + i; j <= 100000; j++) {
      dp[j] = max(dp[j], dp[j-100-i]);
    }
  }
}
int main() {
  init();
  int n;
  cin >> n;
  if(dp[n] == 1) cout << 1 << endl;
  else cout << 0 << endl;
}

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


void solve(std::vector<long long> M, std::vector<long long> D){
    if(M[0]+1==M[1]) cout<<1<<endl;
    else cout<<0<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::cout<<std::fixed<<std::setprecision(10);//誤差小数10桁まで
    std::vector<long long> M(2);
    std::vector<long long> D(2);
    for(int i = 0 ; i < 2 ; i++){
        scanf("%lld",&M[i]);
        scanf("%lld",&D[i]);
    }
    solve(std::move(M), std::move(D));
    return 0;
}


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


int main() {
    string A,B;
    cin >> A >> B;
    if (A.size() == B.size() + 1) {
        rep(i,B.size()) {
            cout << A[i] << B[i];
        }
        cout << A[A.size() - 1] << endl;
    }
    else {
        rep(i,A.size()) {
            cout << A[i] << B[i];
        }
        cout << endl;
    }
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5 + 10; int n, k, c;
char s[maxN + 1];

int memo[maxN + 1], options[2][maxN];
int acc[maxN + 1];
int solve(int i = 0)
{
  if (i >= n) return 0;
  if (memo[i] != -1) return memo[i];

  int ans = 0;
  if (s[i] == 'x') ans = max(ans, solve(i + 1));
  else
  {
    int working = 1 + solve(i + c + 1), notWorking = solve(i + 1);
    ans = max({ans, working, notWorking});
    options[0][i] = working, options[1][i] = notWorking;
  }
  return memo[i] = ans;
}

int main()
{
  int t = 0;
  while (scanf("%d %d %d", &n, &k, &c) != EOF)
  {
    if (t++) printf("---------\n");

    scanf(" %s", s);
    memset(memo, -1, sizeof(memo));
    solve();
    for (int i = n - 2; i >= 0; i--)
      memo[i] = max(memo[i], memo[i + 1]);
    for (int i = 0, cc = 0; i < n; i++)
    {
      acc[i + 1] = acc[i] + (s[i] == 'o' && i >= cc);
      if (s[i] == 'o' && i >= cc)
        cc = i + c + 1;
    }
    DEBUG
    for (int i = 0; i < n; i++)
      printf("%d%c", acc[i], i < n - 1 ? ' ' : '\n');

    vector<int> ans;
    for (int i = 0; i < n; i++)
    {
      if (s[i] == 'x') continue;
      DEBUG printf("\t%d %d %d %d\n", i + 1, k, options[0][i], options[1][i]);
      int total = memo[0];
      DEBUG printf("\t\t%d %d %d %d\n", total, memo[i], memo[i + 1], acc[i]);
      if (acc[i] + options[1][i] < k)
        ans.push_back(i);
    }
    for (int i: ans)
      printf("%d\n", i + 1);
  }
  return 0;
}
// ooxxoxoxxxoxoxxo
//       ^

Measured memory_bytes: 12020
//Discounts of Buckwheat
#include<bits/stdc++.h>
using namespace std;
#define INF 10000

int dp[7][51]={0};
int p[6][2]={{2, 380}, {3, 550}, {5, 850}, {10, 1520}, {12, 1870}, {15, 2244}};

void print(){
  for(int i=0; i<7; i++){
    for(int j=0; j<20; j++)
      printf("%6d", dp[i][j]);
    cout<<endl;
  }
}

int main(){
  memset(dp, 0, sizeof(dp));
  for(int i=0; i<51; i++)dp[0][i]=0;

  for(int i=0; i<6; i++){
    for(int j=0; j<51; j++){
      int min_v=INF;
      for(int n=1; ; n++){
        if(j-p[i][0]*n<0)break;
        if(j-p[i][0]*n!=0 && dp[i][j-p[i][0]*n]==0)continue;
        if(min_v>dp[i][j-p[i][0]*n]+p[i][1]*n)
          min_v=dp[i][j-p[i][0]*n]+p[i][1]*n;
      }
      if(dp[i][j]!=0)min_v=min(min_v, dp[i][j]);
      else if(min_v==INF)min_v=0;
      dp[i+1][j]=min_v;
    }
  }
  //print();
  int n;
  while(true){
    cin>>n;
    if(n==0)break;
    cout<<dp[6][n/100]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N,total;
  bool ans=true;
  cin>>N;
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
    total=4*i+7*j;
    if(N==total){
      cout<<"Yes"<<endl;
      ans=false;
      break;
    }
    }
    if(!ans)break;
  }
  if(ans)cout<<"No"<<endl;
}

Measured memory_bytes: 256
import math
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
limit = sum(B) - sum(A)
cnt_A = 0
cnt_B = 0
for i in range(N):
  if A[i] > B[i]:
    cnt_B += A[i] - B[i]
  elif A[i] < B[i]:
    cnt_A += math.ceil((B[i] - A[i]) / 2)
if cnt_A <= limit and cnt_B <= limit:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int W, n, a, b;
long long dp[100010];
int main()
{
	cin>>n>>W;
	for (int i = 1; i <= n; ++i){
		scanf("%d%d",&a, &b);
		for (int j = W - a; j >= 0; --j){
			dp[j + a] = max(dp[j + a], dp[j] + b);
		}
	}
	cout<<dp[W]<<endl;
	return 0;
} 

Measured memory_bytes: 1024
n = int(input())
l = [[0 for _ in range(10)] for __ in range(10)]

for i in range(1, n+1):
    l[int(str(i)[0])][int(str(i)[-1])] += 1

ans = 0

for i in range(1, 10):
    for j in range(1, 10):
        ans += l[i][j] * l[j][i]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    ll r, D, x2000, x;
    cin >> r >> D >> x2000;

    x = x2000;
    REP(i, 10){
        x = r*x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <map>
const int MAXN = 2e5+5;
const int MAXQ = 2e5+5;
int pos[MAXQ], R[MAXN];
int S[MAXN], T[MAXN], X[MAXN];  // Roadblocks
std::map<int,int> D;
int N, Q;

// R^2 with roadblocks = vertical lines
// People all have unit slope: y = x + D[i]

int main() {
    scanf(" %d%d", &N, &Q);
    for (int i = 0; i < N; ++i) {
        scanf(" %d%d%d", &S[i], &T[i], &X[i]);
        R[i] = i;
    }
    std::sort(R, R + N, [](int l, int r) {
        return X[l] != X[r] ? X[l] < X[r] : S[l] < S[r];
    });
    for (int i = 0; i < Q; ++i) {
        int d;
        scanf("%d", &d);
        D[d] = i;
        pos[i] = -1;
    }
    for (int i = 0; i < N; ++i) {
        auto lo = D.lower_bound(S[R[i]] - X[R[i]]);
        auto hi = D.lower_bound(T[R[i]] - X[R[i]]);
        for (auto jtr = lo; jtr != hi;) {
            pos[jtr->second] = X[R[i]];
            jtr = D.erase(jtr);
        }
    }
    for (int i = 0; i < Q; ++i) {
        printf("%d\n", pos[i]);
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

ll nPr(ll n, ll r){
  ll ret = 1;
  while(r--){
    ret *= n;
    ret %= MOD;
    n--;
  }
  return ret;
}

int main(){
  cout << setprecision(10);
  int N;
  ll K;
  cin >> N >> K;

  vector<vector<int>> v(N);
  for(int i = 0; i < N-1; i++){
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    tmp1--; tmp2--;
    v[tmp2].push_back(tmp1);
    v[tmp1].push_back(tmp2);
  }

  ll ans = K;
  queue<int> q;
  q.push(0);
  vector<int> flg(N, 0);
  flg[0] = 1;

  while(!q.empty()){
    int now = q.front();
    q.pop();
    int degree = 0;
    for(auto next: v[now]){
      if(flg[next] == 0){
        degree++;
        flg[next] = 1;
        q.push(next);
      }
    }
    if(now == 0){
      ans *= nPr(K-1, degree);
    } else {
      ans *= nPr(K-2, degree);
    }
    ans %= MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 6904
n, m = map(int, input().split())
x = []
for _ in range(n):
    a, b = map(int, input().split())
    x.append([a, b])
x.sort()
ans = 0
for a, b in x:
    while m > 0 and b > 0:
        ans += a
        m -= 1
        b -= 1
    if m == 0:
        print(ans)
        exit(0)


Measured memory_bytes: 20048
#include<bits/stdc++.h>
using namespace std;
int main()
{
 string str;
 cin>>str;
 int ans=0;
 int j=0;
 for(int i=0;i<str.length();i++)
 {
 if(str[i]=='R')
  j++;
 else
  j=0;
 ans=max(ans,j);
 }
 cout<<ans;
 return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
 
#define MAX 36
 
int main(){
  char a[MAX][3],b[MAX][3],str[3];
  int n,i,j,c[MAX],d[MAX],tmp,mini,ok = 1;
 
  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s" ,a[i]);
    strcpy(b[i],a[i]);
    c[i] = d[i] = a[i][1]-'0';
  }
 
  for(i = 0 ; i < n ; i++){
    for(j = n-1 ; j > i ; j--){
      if(c[j] < c[j-1]){
    tmp = c[j];
    c[j] = c[j-1];
    c[j-1] = tmp;
 
    strcpy(str,a[j]);
    strcpy(a[j],a[j-1]);
    strcpy(a[j-1],str);
      }
    }
  }  
 
  for(i = 0 ; i < n ; i++){
    if(i != n-1){
      printf("%s " ,a[i]);
    }else{
      printf("%s\n" ,a[i]);
      puts("Stable");
    }
  }
 
  for(i = 0 ; i < n-1 ; i++){
    mini = i;
    for(j = i+1 ; j < n ; j++){
      if(d[j] < d[mini]){
    mini = j;
      }
    }
     
    if(mini != i){
      tmp = d[i];
      d[i] = d[mini];
      d[mini] = tmp;
 
      strcpy(str,b[i]);
      strcpy(b[i],b[mini]);
      strcpy(b[mini],str);
    }
  }
 
  for(i = 0 ; i < n ; i++){
    if(strcmp(a[i],b[i])){
      ok = 0;
    }
    if(i != n-1){
      printf("%s " ,b[i]);
    }else{
      printf("%s\n" ,b[i]);
    }
  }
 
  if(ok){
    puts("Stable");
  }else{
    puts("Not stable");
  }
 
  return 0;
}


Measured memory_bytes: 2072
n, k = map(int, input().split())
c = [0] * n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        c[a[j]-1] += 1
ans = 0

for i in range(n):
    if c[i] == 0:
        ans += 1
print(ans)


Measured memory_bytes: 9124
#include<stdio.h>
#include<stdlib.h>
int main(){
  int x,y,i,m=0,j,c=0,*d[3],dp[3][40010]={};
  char s[100010];//printf("\n");
  for(i=0;i<3;i++)d[i]=&dp[i][20000];
  scanf("%s",s);//printf("aa\n");
  for(i=0;s[i]&&s[i]-'T';i++);
  d[0][i]=d[1][0]=1;
  //printf("a\n");
  for(c=m=0;s[i];i++){
    if(s[i]=='F')c++;
    else{//printf("%d\n",c);
      for(j=-8010;j<8010;j++)d[2][j]|=d[m][j-c]|d[m][j+c];
      for(j=-8010;j<8010;j++)d[m][j]=d[2][j];
      for(j=0;j<40000;j++)dp[2][j]=0;
      m=1-m;
      c=0;
    }
  }//printf("\n");
  for(j=-8010;j<8010;j++)d[2][j]|=d[m][j-c]|d[m][j+c];
  for(j=-8010;j<8010;j++)d[m][j]=d[2][j];//printf("aa\n");
  scanf("%d %d",&x,&y);//printf("%d %d\n",d[0][x],d[1][y]);
  //for(j=-10;j<10;j++)printf("%d %d\n",j,d[0][j]);
  printf("%s\n",d[0][x]*d[1][y]?"Yes":"No");
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int h[100005];
int k;
vector<int> mem(100005,-1);
int fanc(int n);
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    cout<<fanc(n)<<"\n";
    return 0;
}
int fanc(int n){
    if(n==1){
        mem[n]=0;
    }
    if(n==2){
        mem[n]=abs(h[1]-h[2]);
    }
    if(mem[n]<0){
        mem[n]=fanc(n-1)+abs(h[n-1]-h[n]);
        for(int i=0;i<k+1&&n-i>0;i++){
            mem[n]=min(mem[n],abs(h[n]-h[n-i])+fanc(n-i));
        }
    }
    return mem[n];
}

Measured memory_bytes: 10324
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
struct node{
  int x,k,id;
  bool operator<(node u) const{
    return x<u.x;
  }
};
int a[maxn];
node b[2*maxn];
int main()
{
   int n,m,i,j;
   LL ans,ret,li,co;
   int x,out;
   while (scanf("%d %d",&n,&m)!=-1){
     for (i=0;i<n;i++) {
        scanf("%d",&a[i]);
        if (i){
          if (a[i-1]<a[i]) {
            b[2*i-1]=(node){a[i-1]+1,1,i};
            b[2*i]=(node){a[i]+1,-1,i};
          }  else {
            b[2*i-1]=(node){a[i]+1,1,i};
            b[2*i]=(node){a[i-1]+1,-1,i};
          }
        }
     }
     sort(b+1,b+2*n-2+1);
     ans=0;out=x=1;
     li=0;co=0;
     for (i=1;i<n;i++){
       if (a[i-1]<a[i]){
          if (a[i-1]<x && x<=a[i]) {ans+=1+a[i]-x;li--;co+=1+a[i];}
          else {ans+=a[i]-a[i-1];co+=a[i]-a[i-1];}
       } else {
          if (a[i]<x && x<=a[i-1]) {ans+=m+a[i]-a[i-1];co+=m+a[i]-a[i-1];}
          if (x>a[i-1]) {ans+=1+m+a[i]-x;co+=1+m+a[i];li--;}
          if (x<=a[i]) {ans+=1+a[i]-x;li--;co+=1+a[i];}
       }
     }
     ret=ans;
     for (j=1;j<=2*n-2;){
       if (co+li*(b[j].x-1)<ans) ans=co+li*(b[j].x-1);
       do{
         i=b[j].id;
         if (a[i-1]<a[i]){
          if (a[i-1]<x && x<=a[i]) {ret-=1+a[i]-x;li++;co-=1+a[i];}
          else {ret-=a[i]-a[i-1];co-=a[i]-a[i-1];}
         } else {
          if (a[i]<x && x<=a[i-1]) {ret-=m+a[i]-a[i-1];co-=m+a[i]-a[i-1];}
          if (x>a[i-1]) {ret-=1+m+a[i]-x;co-=1+m+a[i];li++;}
          if (x<=a[i]) {ret-=1+a[i]-x;li++;co-=1+a[i];}
         }

         if (a[i-1]<a[i]){
          if (a[i-1]<b[j].x && b[j].x<=a[i]) {ret+=1+a[i]-b[j].x;co+=1+a[i];li--;}
          else {ret+=a[i]-a[i-1];co+=a[i]-a[i-1];}
         } else {
          if (a[i]<b[j].x && b[j].x<=a[i-1]) {ret+=m+a[i]-a[i-1];co+=m+a[i]-a[i-1];}
          if (b[j].x>a[i-1]) {ret+=1+m+a[i]-b[j].x;co+=1+m+a[i];li--;}
          if (b[j].x<=a[i]) {ret+=1+a[i]-b[j].x;co+=1+a[i];li--;}
         }
         j++;
       } while (j<=2*n && b[j].x==b[j-1].x);
       x=b[j-1].x;
       if (ret<ans) {ans=ret;}

     }
     printf("%lld\n",ans);
   }
}


Measured memory_bytes: 2944
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
 
    def root(self, i):
        if self.parent[i] == i:
            return i
        else:
            self.parent[i] = self.root(self.parent[i])
            return self.parent[i]
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if j >= i:
            self.parent[j] = i
        else:
            self.parent[i] = j
N, K, L = map(int, input().split())
road = UnionFind(N)
train = UnionFind(N)
for _ in range(K):
    p, q = map(int, input().split())
    road.union(p-1, q-1)
for _ in range(L):
    r, s = map(int, input().split())
    train.union(r-1, s-1)
for i in range(N):
    road.root(i)
    train.root(i)
lst = []
for i in range(N):
    lst.append((road.parent[i], train.parent[i]))
c = collections.Counter(lst)
ans = []
for i in range(N):
    ans.append(c[lst[i]])
print(*ans)

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


int main()
{
	
		int n;
		cin>>n;
		vector<long double>a;
		for(int i=0;i<n;i++)
		{
			long double x;
			cin>>x;
			a.push_back(x);
		}
		vector<vector<long double>>dp(n+2,vector<long double>(n+4));
		dp[0][0]=1-a[0];
		dp[0][1]=a[0];
		long double ans=0;
		// cout<<endl;
		// cout<<dp[0][0]<<" "<<dp[0][1]<<endl;
		for(int i=1;i<n;i++)
		{
			for(int j=0;j<=i+1;j++)
			{
				if(j==0)
					dp[i][j]=dp[i-1][j]*(1-a[i]);
				else
					dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
				if(i==n-1 && j>n/2)
					ans+=dp[i][j];

				// cout<<dp[i][j]<<" ";
			}
			// cout<<endl;
		}
		if(n<2)
			cout<<a[0];
		else
		    cout << fixed << setprecision(10) <<ans << endl;

	
}

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

using namespace std;

long long dp[105][500][105];

int main() {
	int N,W; cin >> N >> W;
	vector<int> w(N),v(N);
	for(int i=0;i<N;++i) cin >> w[i] >> v[i];
	long long w0=w[0];
	for(int i=0;i<N;++i) w[i]-=w0;
	for(int i=0;i<N;++i) {
	    for(int j=0;j<500;++j) {
			for(int k=0;k<=i;++k) {
				dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
				if(j>=w[i])
					dp[i+1][j][k+1]=max(dp[i+1][j][k+1],dp[i][j-w[i]][k]+v[i]);
			}
		}
	}
	long long ans=0;
	for(int i=0;i<500;++i)
		for(int j=0;j<=N;++j)
			if(i+j*w0<=W) ans=max(ans,dp[N][i][j]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 42880
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll H(int n, int r){
    ll a = n+r-1;
    ll b = r-1;
    return COM(a,b);
}
int main(){
    COMinit();
    int S;
    cin >> S;
    int leng = S/3;
    ll ans = 0;
    for(int i = 1; i <= leng; ++i){
        ll n = S - 3*i;
        ll r = i;
        ans += H(n,r);
        ans %= MOD;
    }
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 15584
X,K,D=map(int,input().split())

N=abs(X)//D
if N>=K:
    ans=abs(X)-D*K
    print(ans)
else:
    M=K-N
    if M%2==0:
        ans=abs(X)-D*N
    else:
        ans=D*(N+1)-abs(X)
    print(ans)

Measured memory_bytes: 9176
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
#define p push
const int MAX=2e5+5;
const int MAX2=1e6;
const int MAAX=2e18;
const int MOD=1e9+7;
in main()
{
    string s;
    cin>>s;
    string ans="";
    int idx=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
            ans+='0';
        if(s[i]=='1')
            ans+='1';
        if(s[i]=='B')
            if(ans.size())
            ans.erase(ans.end()-1);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    bricks = string_to_int(input)
    count = 1
    broken = 0
    for b in bricks:
        if b == count:
            count += 1
            continue
        broken += 1

    return -1 if broken == len(bricks) else broken


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(input())
    print(ret)


Measured memory_bytes: 78212
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
struct  Dice{
	int left;
	int right;
	int top;
	int bottom;
	int front;
	int behind;
	void e()
	{
		int t=this->front;
		this->front=this->left;
		this->left=this->behind;
		this->behind=this->right;
		this->right=t;
	}
	void w()
	{
		int t=this->front;
		this->front=this->right;
		this->right=this->behind;
		this->behind=this->left;
		this->left=t;
	}
	void s()
	{
		int t=this->front;
		this->front=this->top;
		this->top=this->behind;
		this->behind=this->bottom;
		this->bottom=t;
	}
	void n()
	{
		int t=this->front;
		this->front=this->bottom;
		this->bottom=this->behind;
		this->behind=this->top;
		this->top=t; 
	}
};
using namespace std;
int main() {
	Dice dice;
	string s;
	cin>>dice.front>>dice.bottom>>dice.right>>dice.left>>dice.top>>dice.behind; 
	cin>>s;
	for(int i=0; i<s.length(); i++) {
		if(s[i]=='W') {
			dice.w();
		} else if(s[i]=='S') {
			dice.s();
		} else if(s[i]=='N') {
			dice.n();
		} else if(s[i]=='E') {
			dice.e();
		}
	}
	cout<<dice.front<<endl;
	return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int X,Y;
    cin >> X >> Y;
    if(Y%2==1 || 2*X>Y || Y>4*X) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    vector<ll> X(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> X[i];
    }
    vector<ll> sortX = X;
    sort(sortX.begin(), sortX.end());
    //cerr << sortX[N/2] << endl;
    //cerr << sortX[(N-1)/2] << endl;
    // 中央値に選ばれる数は２択
    for(size_t i=0;i<N; i++)
    {
        if(X[i] <sortX[N/2]) cout << sortX[N/2] << endl;
        else cout << sortX[(N-1)/2] << endl;
    }
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		
		if(a.equals("H")&&b.equals("D")){
			System.out.print("D");
		}
		else if(a.equals("H")&&b.equals("H")){
			System.out.print("H");
		}
		else if(a.equals("D")&&b.equals("D")){
			System.out.print("H");
		}
		else if(a.equals("D")&&b.equals("H")){
			System.out.print("D");
		}
	}
}


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)

ll modulo(ll x,ll y)
{
    ll ans=1;
    x=x%mod;
    while (y>0)
    {
        if (y&1) ans=(ans*x)%mod;
        y=y>>1;
        x=(x*x)%mod;
    }
    return ans;
}

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<62)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
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;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k,count=1;
    cin>>n>>k;
    
    while(n/k>0){
        n/=k;
        count++;
    }
    
    puta(count);
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		sc.close();
		int ans = Math.min(K, N) * X + Math.max(0, N - K) * Y;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
	int N;
	cin >> N;
	int tmp;
	cin >> tmp;
	int cnt = 0;
	int ans = 0;
	for (int i = 1; i < N; i++)
	{
		int s;
		
		cin >> s;
		if (tmp >= s) {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			
			cnt = 0;
		}
		tmp = s;
	}
	
	cout << ans << endl;
	
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;

  priority_queue<ll> q;
  vll A(N);
  for (auto& a: A) {
    cin >> a;
    q.push(a);
  }

  for (int i=0; i<M; i++) {
    ll x = q.top(); q.pop();
    q.push(x/2);
  }

  ll ret = 0;
  while (!q.empty()) {
    ret += q.top(); q.pop();
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 2168
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans=max({a*c,a*d,b*c,b*d});

	printf("%lld\n",ans);
}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	int T=1;
	// cin >> T;
	while (T--){
		solve();
	}
}


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


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    H, W = map(int, input().split())
    S = []
    for h in range(H):
        S.append(input().strip())

    uf = UnionFind(H*W)
    for i in range(H):
        for j in range(W):
            if i < H-1 and S[i][j] != S[i+1][j]:
                uf.union(i*W+j, (i+1)*W+j)
            if j < W-1 and S[i][j] != S[i][j+1]:
                uf.union(i*W+j, i*W+(j+1))
    D = {}
    for i in range(H):
        for j in range(W):
            r = uf.find(i*W+j)
            if r not in D:
                D[r] = [0, 0]
            if S[i][j] == "#":
                D[r][0] += 1
            else:
                D[r][1] += 1
    ans = 0
    for d in D.values():
        ans += d[0]*d[1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,W;
	cin>>n>>W;int temp=n;
	ll wi,vi;
	ll dp[W+1];
	fill(dp, dp+W+1, 0);
	
	while(temp--)
	{
		cin>>wi>>vi;
		for(int w=W;w>=wi;w--)
		dp[w]=max(dp[w-wi]+vi, dp[w]);	
	}
	ll ans=0;
	for(int i=0;i<=W;i++)ans=max(ans, dp[W]);
	cout<<ans<<"\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);

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

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
struct edge { int to, cost; };
std::vector<edge>v[100];
bool used[210];
bool graph[100][100];
bool visited[100];

int n, m;

void dfs(int v) {
	visited[v] = true;
	for (int v2 = 0;v2 < n;v2++) {
		if (graph[v][v2] == false)continue;
		if (visited[v2] == true)continue;
		dfs(v2);
	}
}

int main() {
	std::cin >> n >> m;
	int a[100], b[100];
	for (int i = 0;i < m;i++) {
		std::cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	int ans = 0;
	for (int i = 0;i < m;i++) {
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
		for (int j = 0;j < n;j++)visited[j] = false;
		dfs(0);
		bool bridge = false;
		for (int j = 0;j < n;j++) if (visited[j] == false)bridge = true;
		if (bridge)ans++;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for (v = 0; v < n; v++) {
		if (M[u][v] == 0)continue;
		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}


int main() {
	int u, v, k, i, j,m;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++)M[i][j] = 0;
	}

	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		u--;
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			v--;
			M[u][v] = 1;
		}
	}

	for (m = 0;  m< n; m++)color[m] = WHITE;
	tt = 0;

	for (m = 0; m < n; m++) {
		if (color[m] == WHITE)dfs_visit(m);
	}
	for (m = 0; m < n; m++) {
		printf("%d %d %d\n", m + 1, d[m], f[m]);
	}

	return 0;
}



Measured memory_bytes: 2044
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			long m = sc.nextLong();
			long n = sc.nextLong();
			
			System.out.println(gcd(m, n)+" "+lcm(m, n));
		}
	}
	
	public static long gcd(long a, long b){
		
		if(b == 0)	return a;
		else return gcd(b, a % b);
	}
	
	public static long lcm(long a, long b){
		return a * b / gcd(a, b);
	}
}

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

int main(void){
    
    int a,b;
    cin >> a >> b;
    
    if(a <= 8 && b <= 8){
        cout << "Yay!" <<endl;    
    }
    else{
        cout << ":(" <<endl;
    }
    
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int m;

signed main() {
	cin >> m;
	cout << m * m*m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <cmath>

using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> v;
  for(int i=1;i<=sqrt(M);i++){
    if(M%i==0){
      v.push_back(i);
      v.push_back(M/i);
    }
  }
  int ans=0;
  for(auto it=v.begin();it!=v.end();it++){
    if((*it)>ans&&(*it)<=(M/N)){
      ans=(*it);
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int N, Q;
char S[100001];

int sum[100001];
int main(){
	scanf("%d%d",&N, &Q);
	scanf("%s",S);

	for(int i = 0; i < N; i++){
		if(S[i] == 'A' and S[i + 1] == 'C'){
			sum[i + 1] += 1 + sum[i];
		}
		else{
			sum[i + 1] = sum[i];
		}
	}
	for(int i = 0; i < Q; i++){
		int l, r;
		scanf("%d%d",&l, &r);
		printf("%d\n", sum[r - 1] - sum[l - 1]);
	}
	return 0;
}

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;ver<(n);ver++)
#define loop while(true)
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(v) (v).begin(), (v).end()
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

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

int main(){
  int n, a[200010] = {};
  
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  
  ll r = 0, l = 0;
  int rp = n - 1, lp = 0;
  
  while(rp != lp){
    if(r >= l){
      l += a[lp];
      lp++;
    }
    else{
      r += a[rp];
      rp--;
    }
  }
  
  cout << min(abs(r + a[rp] - l), abs(l + a[lp] - r));
  
  
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
ans = 112345
for i in range(N + 1):
    a = i
    b = N - i
    c = 0
    while a:
        c += a % 6
        a //= 6
    while b:
        c += b % 9
        b //= 9
    ans = min(ans, c)
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(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 (int i = 0; i < n; ++i)
#define int long long

typedef long long ll;
typedef pair<int, int> Pair;

const int kMaxN = 2*100000;

int N, A[kMaxN];
int ans = 0;

int l, r;
int sum, xor_;

signed main() {
  cin >> N;
  REP(i, N) { cin >> A[i]; }

  r = 0;
  REP(i, N) {
    l = i;
    while ((r < N) && (sum+A[r] == (xor_^A[r]))) {
      sum += A[r];
      xor_ ^= A[r];
      ++r;
    }
    ans += r-l;
    sum -= A[l];
    xor_ ^= A[l];
  }

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


Measured memory_bytes: 1792
import java.io.*;

public class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
		String line = reader.readLine();
        	String[] num = line.split(" ", -1);
        	
        	int W = Integer.parseInt(num[0]);
        	int H = Integer.parseInt(num[1]);
        	int x = Integer.parseInt(num[2]);
      		int y = Integer.parseInt(num[3]);
      		int r = Integer.parseInt(num[4]);
      		if(x >= r && x <= (W - r) && y >= r && y <= (H - r)) {
      			System.out.println("Yes");
      		} else {
      			System.out.println("No");
      		}
 		} catch (IOException e) {
          System.out.println(e);
        } catch (NumberFormatException e) {
          System.out.println("error");
        }
    }
}

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

#define M 1000005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> PII;
typedef pair<lli,lli> PLL;

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

	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
		
	int k;
	cin>>k;

	string s;
	cin>>s;

	int n = (int)s.size();
	if(n<=k)
		cout<<s<<"\n";
	else
	{
		for(int i=0;i<k;i++)
			cout<<s[i];
		cout<<"...\n";
	}
	
}

Measured memory_bytes: 3648
// https://atcoder.jp/contests/abc133/tasks/abc133_d
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize,
        a: [i64; n]
    };

    let pl = a[0]*2;
    let mut mi = 0;

    {
        let mut i = 0;
        let mut j = 1;
        loop {
            mi += (a[i]-a[j])*2;
            if j == 0 {
                break;
            }
            i = (i+2)%n;
            j = (j+2)%n;
        }
    }

    let mut ans = vec![0; n];
    ans[0] = (pl+mi)/2;

    for i in 1..n {
        ans[i] = (a[i-1] - ans[i-1]/2) * 2;
    }

    for i in 0..n {
        if i >= 1 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}


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

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

    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    vector<pair<int,int>> v;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='B') {
                v.push_back(make_pair(i,j));
            }
        }
    }
    int ans=0;
    int n=v.size();
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans=max(ans,abs(v[i].first - v[j].first)+abs(v[i].second-v[j].second));
        }
        
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3268
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)


def main():
    N, *XY = map(int, read().split())
    X = list(zip(XY[::2], range(N)))
    Y = list(zip(XY[1::2], range(N)))

    X.sort()
    Y.sort()

    edge = []
    for i in range(N - 1):
        edge.append((X[i + 1][0] - X[i][0], X[i][1], X[i + 1][1]))
        edge.append((Y[i + 1][0] - Y[i][0], Y[i][1], Y[i + 1][1]))

    edge.sort()

    uf = UnionFind(N)
    ans = 0
    for d, s, t in edge:
        if not uf.same(s, t):
            uf.union(s, t)
            ans += d

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 130924
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;

vector<vector<ll>> dp_arr;

int main()
{
	int n;
	cin >> n;
	vector<ll> arr(n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	vector<ll> cum_sum(n+1,0);
	for(int i = 1; i <= n; i++)
	{
		cum_sum[i] = arr[i-1] + cum_sum[i-1];
	}	
	dp_arr.resize(n+1, vector<ll>(n+1,0));
	// for(int i = 1; i <= n; i++)
	// {
	// 	dp_arr[i][i] = arr[i-1];
	// }
	for(int l = 2; l <= n ; l++)
	{
		for(int i = 1; i + l - 1 <= n; i++)
		{
			ll min_ = LONG_MAX;
			for(int j = i; j < i+l-1; j++)
			{
				// if(l == 2)
				// {	
				// 	min_ = min(min_, dp_arr[i][j] + dp_arr[j+1][i+l-1] + cum_sum[i+l-1] - cum_sum[i-1]);
				// }
				min_ = min(min_, dp_arr[i][j] + dp_arr[j+1][i+l-1] + cum_sum[i+l-1] - cum_sum[i-1]);
			}
			dp_arr[i][i+l-1] = min_;
			// cout << "i: " << i << " j: " << i+l-1 << " dp: " << dp_arr[i][i+l-1] << endl;
		}
	}
	cout << dp_arr[1][n] << endl;
	return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
using namespace std;

int n;
char s[105], t[105];

void init() {
	scanf("%d%s%s", &n, s+1, t+1);
	return ;
}

void solve() {
	for(register int i = 1; i <= n; i++) {
		printf("%c%c", s[i], t[i]);
	}
	return ;
}

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

Measured memory_bytes: 128
# a,b,n=map(int,input().split())
# max=0
# for i in range(1,n+1):
#     if a%b*i%b<i%b:
#         ans=a*i//b -a*(i//b)
#         if max<ans:
#             max=ans

# print(max)

a,b,n=map(int,input().split())
max=0

if b>n:
    x=n
    ans=(a*x)//b -a*(x//b)

else:
    x=b-1
    ans=(a*x)//b -a*(x//b)

print(ans)
    

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	ld a, b, h, m;
	cin >> a >> b >> h >> m;
	complex<ld>  l, s;
	ld pi = acos(-1.0);
	s = polar(a, (h * 30.0 + m / 2.0) * pi / 180.0);
	l = polar(b, m * 6.0 * pi / 180.0);
	cout << fixed << setprecision(10) <<  abs(s - l) << endl;
}


Measured memory_bytes: 4192
package main

import "fmt"

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

func max(n []int) int {
	max := n[0]
	for _, v := range n {
		if v > max {
			max = v
		}
	}
	return max
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	l := make([]int, n+1)
	l[0] = 0
	r := make([]int, n+1)
	r[n] = 0

	for i := 0; i < n; i++ {
		l[i+1] = gcd(l[i], a[i])
		r[n-i-1] = gcd(r[n-i], a[n-i-1])
	}
	m := make([]int, n)
	for i := 0; i < n; i++ {
		m[i] = gcd(l[i], r[i+1])
	}
	fmt.Println(max(m))
}


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

using namespace std;

struct expand_type {
    template <typename... T>
    expand_type (T&&...) {}
};
template <typename... ArgTypes>
void print (ArgTypes... args) {
    expand_type {0, (cerr << args << ", ", 0)...};
    cerr << "\b\b \n";
}
#define printv(x) cerr << "["; for(auto i : (x)) cerr << i << ", "; cerr << "\b\b]\n";

typedef unsigned long long ull;
typedef long double ld;



int main () {
    std::ios::sync_with_stdio (false);
    cin.tie (nullptr);
    cout.tie (nullptr);
    int s, w;
    cin >> s >> w;
    if (w >= s) {
        puts ("unsafe");
    } else {
        puts ("safe");
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int p[50];
  for (int i = 0; i < N; i++) cin >> p[i];

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (p[i] != i + 1) count++;
  }
  if (count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
t = 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = [a, b, c, d, e]
for i in f:
    t += ((i - 1) // 10 + 1) * 10
g = [(f[i] - 1) % 10 + 1 for i in range(5)]
t = t - 10 + min(g)
print(t)

Measured memory_bytes: 3064