akhauriyash/Code-Regression huggingface dataset:
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n,m,k;cin>>n>>m>>k;
	vi a(n),b(m);cin>>a>>b;
	for(int i=1;i<n;i++)
	a[i]+=a[i-1];
	for(int i=1;i<m;i++)
	b[i]+=b[i-1];
	int ans=lower_bound(all(b),k)-b.begin();
	if(ans<m)
	{
		if(b[ans]==k)
		ans++;
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]<=k){
		int x=lower_bound(all(b),k-a[i])-b.begin();
		if(x<m)
		{
			if(b[x]==k-a[i])
			x++;
		}
		ans=max2(ans,i+1+x);
		}
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 6364
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    vector<vector<bool>>is_filled(H, vector<bool>(W));

    for (int i=0; i<N; i++){
        int xi, yi, ai;
        cin >> xi >> yi >> ai;
        if (ai == 1){
            for (int x=0; x<xi; x++){
                for (int y=0; y<H; y++){
                    is_filled[y][x] = true;
                }
            }
        }
        else if (ai == 2){
            for (int x=xi; x<W; x++){
                for (int y=0; y<H; y++)is_filled[y][x] = true;
            }
        }
        else if (ai == 3){
            for (int x=0; x<W; x++){
                for (int y=0; y<yi; y++)is_filled[y][x] = true;
            }
        }
        else {
            for (int x=0; x<W; x++){
                for (int y=yi; y<H; y++)is_filled[y][x] = true;
            }
        }
    }
    int ans = 0;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            if (!is_filled[i][j])ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int compute(string s) {
    int begin;
    int nest = 0;
    int n = 0;
    vector<int> children, children2;
    vector<char> operators, operators2;

    for (int i=0; i<(int)s.length(); i++) {
        if (s[i] == '(') {
            nest++;
            if (nest == 1) {
                begin = i+1;
            }
        }
        else if (s[i] == ')') {
            if (nest == 1) {
                string substr = s.substr(begin, i-begin);
                n = compute(substr);
            }
            nest--;
        }
        else if (nest == 0) {
            if ('0' <= s[i] && s[i] <= '9') {
                n *= 10;
                n += s[i]-'0';
            }
            else {
                children.push_back(n);
                operators.push_back(s[i]);
                n = 0;
            }
        }
    }
    children.push_back(n);
    children2.push_back(children[0]);
    for (int i=0; i<(int)operators.size(); i++) {
        if (operators[i] == '*') {
            children2[children2.size()-1] *= children[i+1];
        }
        else if (operators[i] == '/') {
            children2[children2.size()-1] /= children[i+1];
        }
        else {
            children2.push_back(children[i+1]);
            operators2.push_back(operators[i]);
        }
    }
    n = children2[0];
    for (int i=0; i<(int)operators2.size(); i++) {
        if (operators2[i] == '+') {
            n += children2[i+1];
        }
        else {
            n -= children2[i+1];
        }
    }
    return n;
}

int main() {
    int n;
    string s;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> s;
        cout << compute(s.substr(0, s.length()-1)) << endl;
    }
    return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

void Swap(int *a, int *b, int *c)
{
    int temp;
    temp = *b;
    *b = *a;
    *a = *c;
    *c = temp;
}


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int>v(n);
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
        sum += v[i];
    }
    int count = 0;
    for(int i = 0; i < n; i++)
    {
        if(v[i]*4*m >= sum)
        {
            count++;
        }

    }
    if(count >= m)
        cout << "Yes" << endl;
    else
       cout << "No" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, E, M;
  cin >> A >> B;
  M = A + B;
  C = A - B;
  if(M < C) M = C;
  C = A * B;
  if(M < C) M = C;
  cout << M << endl; 
}

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

using namespace std;

bool flip = false;

void query(int F, char C, deque<char>& D) {
	if (flip)
		F = (F == 1) ? 2 : 1;
	if (F == 1)
		D.push_front(C);
	else
		D.push_back(C);
}

int main() {
	int Q;
	string S;
	cin >> S >> Q;
	deque<char> D(S.begin(), S.end());

	while (Q--) {
		char C;
		int q, F;
		cin >> q;
		if (q == 1)
			flip = !flip;
		else {
			cin >> F >> C;
			query(F, C, D);
		}
	}
	if (flip)
		reverse(D.begin(), D.end());
	S = string(D.begin(), D.end());
	cout << S;
	
	return 0;
}

Measured memory_bytes: 1280
from math import ceil,floor
n=int(input())
a=list(map(int,input().split()))
ave_h=ceil(sum(a)/n)
ave_l=floor(sum(a)/n)
ans1,ans2=0,0
for aa in a:
    ans1+=(aa-ave_h)**2
for aa in a:
    ans2+=(aa-ave_l)**2
print(min(ans1,ans2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e7+5;
const long long inf=0x3f3f3f3f;
const long long mod=1e9+7;
long long n,m,a[maxn],b[maxn],cx[maxn],cy[maxn],px[maxn],py[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	memset(px,-1,sizeof(px));
	memset(py,-1,sizeof(py));
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		cx[a[i]]++;
		px[a[i]]=i;
	}
	for(long long i=1;i<=m;i++)
	{
		cin>>b[i];
		cy[b[i]]++;
		py[b[i]]=i;
	}
	for(long long i=1;i<=n*m;i++)
	{
		if(cx[i]>2||cy[i]>2)
		{
			cout<<"0"<<endl;
			return 0;
		}
	}
	long long nn=0,mm=0,ans=1,cnt=0;
	for(long long i=n;i>0;i--)
	{
		for(long long j=m;j>0;j--)
		{
			long long x=(i-1)*m+j;
			if(px[x]!=-1&&py[x]!=-1)
			{
				nn++;
				mm++;
				cnt++;
			}
			else if(px[x]!=-1)
			{
				if(!mm)
				{
					cout<<"0"<<endl;
					return 0;
				}
				nn++;
				cnt++;
				ans=ans*mm%mod;
			}
			else if(py[x]!=-1)
			{
				if(!nn)
				{
					cout<<"0"<<endl;
					return 0;
				}
				mm++;
				cnt++;
				ans=ans*nn%mod;
			}
			else
			{
				if(nn*mm-cnt==0)
				{
					cout<<"0"<<endl;
					return 0;
				}
				ans=ans*(nn*mm-cnt)%mod;
				cnt++;
			}
			if(mm>m||nn>n)
			{
				cout<<"0"<<endl;
				return 0;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

/*
2 2
4 3
3 4
*/


Measured memory_bytes: 166144
import bisect

N = int(input())
numbers = []
for i in range(N):
    numbers.append(int(input()))

lis = [numbers[0]]
for last in numbers[1:]:
    if lis[-1] < last:
        lis.append(last)
    else:
        pos = bisect.bisect_left(lis, last)
        lis[pos] = last

print(len(lis))

Measured memory_bytes: 13136
from functools import reduce

n = int(input())
s = input().strip()

MOD = 998244353

R = 1
G = 2
B = 4
RG = R + G
RB = R + B
GB = G + B
RGB = R + G + B
table = {'R': R, 'G': G, 'B': B}
counts = {
    0: 0,
    R: 0, G: 0, B: 0,
    RG: 0, RB: 0, GB: 0,
}
patterns = 1
for cv in [table[c] for c in s]:
    rest = RGB - cv
    if counts[rest] > 0:
        patterns = (patterns * counts[rest]) % MOD
        counts[rest] -= 1
    elif R != cv and counts[R] > 0:
        patterns = (patterns * counts[R]) % MOD
        counts[R] -= 1
        counts[R + cv] += 1
    elif G != cv and counts[G] > 0:
        patterns = (patterns * counts[G]) % MOD
        counts[G] -= 1
        counts[G + cv] += 1
    elif B != cv and counts[B] > 0:
        patterns = (patterns * counts[B]) % MOD
        counts[B] -= 1
        counts[B + cv] += 1
    else:
        counts[cv] += 1

print((patterns * reduce(lambda o, v: (o * v) % MOD, range(1, n + 1), 1)) % MOD)


Measured memory_bytes: 62684
n, m = map(int,input().split())
ans = 1
if abs(n-m) == 0:
    for i in range(1,n+1):
       ans *= i
       ans = ans%(10**9+7)
    ans = 2*(ans**2)
    print(ans%(10**9+7))
    


elif abs(n-m) == 1:
    for i in range(1,min(n+1,m+1)):
        ans *= i
        ans = ans%(10**9+7)
    ans = max(n,m)*(ans**2)
    print(ans%(10**9+7))


else:
    print(0)

Measured memory_bytes: 9220
inf = 1000000007
 
a = 0
ab = 0
abc = 0
r = 1
 
s = input()
 
for c in s:
    if c == "A":
        a += r
    elif c == "B":
        ab += a
    elif c == "C":
        abc += ab
    else:
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + r
        r *= 3
        
    a %= inf
    ab %= inf
    abc %= inf
    r %= inf

print(abc)

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<stack>
using namespace std;
typedef long long llong;
static const int MAX = 10;

int n, m;
int ans;
vector< vector<int> > M(MAX + 1);
int d[MAX + 1];

void dfs(int x){
    int check = 0;
    for (int i = 1; i <= n; i++){
        if (d[i] < 0) check++;
    }
    if (check == n) ans++;
    for (int i = 0; i < M[x].size(); i++){
        if (d[M[x][i]] > 0){
            d[M[x][i]] = -1;
            dfs(M[x][i]);
            d[M[x][i]] = 1;
        }
    }
    return;
}

int main(){
    cin >> n >> m;
    int x, y;

    for (int i = 1; i <= n; i++) d[i] = 1;

    for (int i = 0; i < m; i++){
        cin >> x >> y;
        M[x].push_back(y);
        M[y].push_back(x);
    }
    ans = 0;
    d[1] = -1;
    dfs(1);
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  rep(i, S.size()) {
    int next = ((S[i] - 'A') + N) % 26;
    S[i] = 'A' + next;
  }
  cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	ll T;
	cin >> N >> T;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	ll maxNow = 0;
	vector<ll> maxVal(N, 0);
	for (int i = N - 1; i >= 0; i--) {
		maxVal[i] = maxNow = max(maxNow, A[i]);
	}

	vector<ll> vDiff;
	REP(i, N) {
		ll diff1 = maxVal[i] - A[i];
		vDiff.emplace_back(diff1);
	}
	
	T /= 2;
	ll ans = 0;
	sort(vDiff.rbegin(), vDiff.rend());
	REP(i, vDiff.size()) {
		if (vDiff[0] == vDiff[i]) {
			ans++;
		} else {
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2936
import itertools
 
n,m = map(int,input().split())
 
path = [[False] * n for i in range(n)]
 
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  path[a][b] = True
  path[b][a] = True
  
ans = 0
 
#頂点を並び替える順列を生成してループ
for i in itertools.permutations(range(n),n):
  #頂点1が始点
  if i[0] == 0:
    #生成した順列の中をさらにループ
    for j in range(n):
      # n-1まで続いたら条件を満たすパスが存在する
      if j == n-1:
        ans += 1
        break
      #i[j]からi[j+1]に行くパスがなければ終了
      if not path[i[j]][i[j+1]]:
        break
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char map[505][505];
int def[505][505];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
vector<int>to[200005];
int price[15];
int main() {
	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<ll>>a(n);
	for (int i = 0; i < n; i++) {
		cin >> price[i];
		a[i].resize(m);
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}

	ll ans = inf;
	for (int bit = 0; bit < (1 << n); bit++) {
		vector<ll>t(m, 0);
		bool ok = true;
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				for (int j = 0; j < m; j++) {
					t[j] += a[i][j];
				}
				sum += price[i];
			}
		}
		
		for (int k = 0; k < m; k++) {
			if (t[k] < x) {
				ok = false;
			}
		}

		if (ok) {
			ans = min(ans, sum);
		}

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

Measured memory_bytes: 8324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;;
#define f(i,a,b) for(int i=a;i<=b;i++)
const int M=1e6;
int arr[M];
int main(){
    int n;
    cin>>n;
    f(i,0,n-1)cin>>arr[i];
    ll r=0;
    f(i,1,n-1){
        if(arr[i]<arr[i-1]) r+=arr[i-1]-arr[i],arr[i]=arr[i-1];
    }
    cout<<r;
}


Measured memory_bytes: 4392
#include <iostream>
#include <algorithm>
#include <string.h>
#define int long long
using namespace std;
int arr[300030];
signed main()
{
	int N;
	cin >> N;
	int i;
	for (i = 0; i < N; i++)
	{
		cin >> arr[i];
	}
	int ans = 0;
	for (i = 0; i < 60; i++)
	{
		int t = (1LL << i) % 1000000007;
		int j;
		int h = 0;
		for (j = 0; j < N; j++)
		{
			if ((1LL << i) & arr[j])
				h++;
		}
		t *= h;
		t %= 1000000007;
		t = (t * (N - h)) % 1000000007;
		ans += t;
		ans %= 1000000007;
	}
	cout << ans;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    string s;
    int n;
    cin >> n >> s;
    int r = 0; int b = 0;
    rep(i,n) {
        if (s[i]=='R') r++;
        else b++;
    }
    if (r>b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import groupby

class Osa_k:
    def __init__(self, n_max):
        self.min_factor = min_factor = list(range(n_max+1))
        for i in range(2, int(n_max**0.5)+1):
            if min_factor[i] == i:
                for j in range(i*i, n_max+1, i):
                    if min_factor[j] == j:
                        min_factor[j] = i

    def __call__(self, n):
        min_factor = self.min_factor
        n_twoes = (n & -n).bit_length() - 1  # 最悪ケースでは速くなる
        res = [2] * n_twoes
        n >>= n_twoes
        while n > 1:
            p = min_factor[n]
            res.append(p)
            n //= p
        return res

def main():
    N = int(input())
    A = list(map(int, input().split()))
    osa_k = Osa_k(1010101)
    Factors = [osa_k(a) for a in A]
    factors = Factors[0]
    st0 = set(factors)  # 0 になれば setwize
    st1 = set(factors)  # 重複しなければ pairwise
    pairwise = True
    for factors in Factors[1:]:
        st = []
        for f, _ in groupby(factors):
            if f in st1:
                pairwise = False
            else:
                st1.add(f)
            st.append(f)
        st0 &= set(st)
    if pairwise:
        print("pairwise coprime")
    elif not st0:
        print("setwise coprime")
    else:
        print("not coprime")

main()


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);

    swap(a, c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
#include <iomanip>
#include <bitset>


using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> h(n);
	rep(i,n)cin>>h[i];
	int ans = 0;
	rep(i,n)if(h[i]>=k)ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
A = []
for _ in range(N):
    a = int(input())
    A.append(a)
A.sort()

ans = 0
for v in Counter(A).values():
    if v%2: ans += 1

print(ans)

Measured memory_bytes: 25260
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    int H, W, count = 0;
    string tmp;
    cin >> H >> W;
    vector<string> masu(H);
    vector<string> table(H);
    for(int i = 0; i < H; i++){
       cin >> tmp;
       masu[i] = tmp;
       masu[i] += "\n";
       table[i] = string(W+1,'T');
    }


    for(int i = 0; i < H; i++){
        bool flag = true;
        for(int j = 0; j < W; j++){
            if(masu[i][j] == '#'){
                flag = false;
            }
        }
        if(flag == true){
            for(int k = 0; k < W+1; k++){
                table[i][k] = 'F';
            }
        }
    }

    for(int i = 0; i < W; i++){
        bool flag = true;
        for(int j = 0; j < H; j++){
            if(masu[j][i] == '#'){
                flag = false;
            }
        }
        if(flag == true){
            for(int k = 0; k < H; k++){
                for(int k = 0; k < H; k++){
                    table[k][i] = 'F';
                }
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W+1; j++){
            if(table[i][j] == 'T'){
                cout << masu[i][j];
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    ll count = 0;
    if(A%2==B%2&&B%2==C%2){

    }else{
        count++;
        if(A%2==B%2){
            A++;B++;
        }else if(A%2==C%2){
            A++;C++;
        }else if(B%2==C%2){
            B++;C++;
        }
    }

    ll M = max(A,max(B,C));
    cout << (3*M-A-B-C)/2+count << endl;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
S = [list(input()) for i in range(H)]

non_placed_h = set()
for h in range(H):
    if S[h].count('#') == 0:
        non_placed_h.add(h)

ans = [[0] * W for i in range(H)]
x = 0

for h in range(H):
    if h in non_placed_h:
        continue

    else:
        x_cnt = 0
        x += 1

        for w in range(W):
            if S[h][w] == '#':
                x_cnt += 1
                if x_cnt >= 2:
                    x += 1
            ans[h][w] = x

for h in range(H - 2, -1, -1):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h + 1][w]

for h in range(1, H):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h - 1][w]

for h in range(H - 2, -1, -1):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h + 1][w]

for h in range(1, H):
    for w in range(W):
        if ans[h][w] == 0:
            ans[h][w] = ans[h - 1][w]

m = float('inf')
for a in ans:
    m = min(m, min(a))

d = m - 1

for i in range(H):
    for j in range(W):
        ans[i][j] -= d

for a in ans:
    print(' '.join(map(str, a)))



Measured memory_bytes: 48108
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    S = Scanner.string()
    e, w = 0, 0
    e = S.count("E")
    ans = int(1e09)
    for i in range(N):
        if S[i] == "E":
            e -= 1
        ans = min(ans, e+w)
        if S[i] == "W":
            w += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41588
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,cur;
string s;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	n=s.size();
	s="$"+s;
	if(s[n]=='1' || s[1]=='0'){
		cout<<"-1\n";
		return 0;
	}
	for(int i=1;i<=n/2;i++){
		if(s[i]!=s[n-i]){
			cout<<"-1\n";
			return 0;
		}
	}
	cur=n;
	for(int i=n-1;i;i--){
		cout<<cur<<' '<<i<<endl;
		if(s[i]=='1')cur=i;
	}
	return 0;
}

Measured memory_bytes: 1664
import sys
N = int(input())

s = ['' for i in range(N)]
for i in range(N):
    s[i] = str(input())

for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            print('No')
            sys.exit()

for i in range(1, N):
    str1 = list(s[i - 1])
    str2 = list(s[i])
    if str1[-1] != str2[0]:
        print('No')
        sys.exit()

print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h+1);
    vector<vector<int>>dp(h+1,vector<int>(w+1));
    rep(i,h){cin>>s[i]; s[i]+='a';}
    rep(i,w+1)s[h]+='a';
    rep(i,h+1){
        rep(j,w+1){
            dp[i][j]=1e9;
        }
    }
    dp[0][0]=(s[0][0]=='#');
    rep(i,h){
        rep(j,w){
            dp[i][j+1]=min(dp[i][j+1],dp[i][j]+(s[i][j]!=s[i][j+1]));
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]+(s[i][j]!=s[i+1][j]));
        }
    }
    cout<<(dp[h-1][w-1]+1)/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int x;
int main(void){
    for(int i = 1; i<1000 ; i++){
        while(true){
            cin >> x;
            if(x == 0){
                break;
            }
            if(x > 0){
                cout << "Case";
                cout << " ";
                cout << i++;
                cout << ": ";
                cout << x << endl;
            }
            else {
                cout << endl;
            }
        }
    }
}




Measured memory_bytes: 2980
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    vector<double> a(n,0);
    vector<double> b(n,0);
    for(int i = 0;i < n; i++){
        cin>>a[i]>>b[i];
    }
    double p=1;;
    for(int i = 1;i <= n; i++){
        p*=i;
    }
    vector<int> v(n,0);
    for(int i = 0;i < n; i++){
        v[i]=i;
    }
    double sum=0;
    do{
        for(int i = 0;i < n-1; i++){
            sum+=sqrt((a[v[i]]-a[v[i+1]])*(a[v[i]]-a[v[i+1]])+(b[v[i]]-b[v[i+1]])*(b[v[i]]-b[v[i+1]]));
        }
    }while(next_permutation(v.begin(),v.end()));
    double ans=sum/p;
    cout<<fixed<<setprecision(10)<<ans<<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)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

lint dp[MAX];
lint dq[MAX][3];

int main(){
    int n; cin >> n;
    vector<lint> a(n);
    rep(i, n) cin >> a[i];

    lint ans;
    if(n % 2 == 0){
        dp[0] = a[0]; dp[1] = a[1];
        for(int i = 2; i < n; i++){
            if(i % 2 == 1) dp[i] = max(dp[i-2]+a[i], dp[i-3]+a[i]);
            else dp[i] = dp[i-2]+a[i];
        }
        ans = max(dp[n-1], dp[n-2]);
    }
    else{
        if(n == 3){
            out(max(a[0], max(a[1], a[2]))); return 0;
        }
        dq[0][0] = a[0]; dq[1][1] = a[1];
        dq[2][2] = a[2]; dq[2][0] = a[0] + a[2];
        for(int i = 3; i < n; i++){
            dq[i][0] = dq[i-2][0] + a[i];
            dq[i][1] = max(dq[i-2][1], dq[i-3][0]) + a[i];
            dq[i][2] = max(dq[i-2][2], dq[i-3][1]) + a[i];
            if(i > 3) dq[i][2] = max(dq[i][2], dq[i-4][0] + a[i]);
        }
        ans = max(dq[n-1][2], max(dq[n-2][1], dq[n-3][0]));
    }

    out(ans);
}

Measured memory_bytes: 9548
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    println!("{}", (100 * (v[0] - v[1]) + 1900 * v[1]) << v[1]);
}



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

int main() {

  string s;
  cin >> s;
  bool flg = true;

  if(s[2] != s[3]) {
    flg = false;
  }

  if(s[4] != s[5]) {
    flg = false;
  }

  if (flg == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){ 
		Scanner sc = new Scanner(System.in);
      	//N個の都市
		int N = sc.nextInt();
      	//M本の道路
        int M = sc.nextInt();
      	//数字の組み合わせ入力
      	int Road[] = new int[N];
      	for(int i = 0;i < M * 2;i++){
		  Road[sc.nextInt()-1] += 1;
        }
      	for(int i = 0;i < N; i++){
          System.out.println(Road[i]); 
        }
    }
}

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

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    int ans = 0;
    rep(i,n){
        int sum = 0;
        rep(j,m){
            int a;
            cin >> a; 
            sum += a*b[j];
        }
        sum += c;
        if(sum > 0) ans++;
    }
    cout << ans <<endl;
    return 0;
}

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

// dp[i] - 1 if first player can win with i stones, 0 otherwise
int N, K, a[105];
bool dp[100005];

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  dp[0] = 0;
  for(int i = 1; i <= K; i++){
    bool find = false;
    for (int j=0; j<N; j++) {
      if (i - a[j] < 0) continue;
      if(dp[i - a[j]] == 0){
        find = true;
      }
    }
    if(find){
      dp[i] = 1;
    }else{
      dp[i] = 0;
    }
  }
  if(dp[K]){
    cout << "First" << endl;
  }else{
    cout << "Second" << endl;
  }
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    a = k;

    /*r = n % k;
    c = n;
    d = k;
    while(r!=0){
        c = d;
        d = r;
        r = c % d;
    }

    cout << d << endl;*/

    /*
    if (n % k == 0) {
        cout << 0 << endl;
        return 0;
    }*/
    
    n %= k;


    while (1) {
        if (aabs(aabs(n - k) - k) == n || n == 0) {
            n = (aabs(n - k) > aabs(aabs(n - k) - k))?aabs(aabs(n - k) - k):aabs(n - k);
            break;
        }
        n = aabs(n - k);
    }
    
    cout << n << endl;


    
    return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import io, os
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    n, m = map(int, input().decode().rstrip("\n\r").split())
    h = list(map(int, input().decode().rstrip("\n\r").split()))

    is_good = [True] * n

    for _ in range(m):
        a, b = map(int, input().decode().rstrip("\n\r").split())
        h_a, h_b = h[a - 1], h[b - 1]
        if h_a >= h_b:
            is_good[b - 1] = False
        if h_b >= h_a:
            is_good[a - 1] = False

    print(sum(is_good))


if __name__ == '__main__':
    main()


Measured memory_bytes: 86536
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        s: Chars, 
        t: Chars
    }

    let ans = {
        let mut ans = std::usize::MAX;
        for i in 0..=s.len()-t.len() {
            let mut count = 0;
            for j in 0..t.len() {
                if t[j] != s[j+i] {
                    count += 1;
                }
            }
            if ans > count {
                ans = count
            }
        }
        ans
    };

    println!("{}",ans)
}

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

using namespace std;
typedef long long ll;
double N;
ll M;
string s;
vector<ll > input1;  
vector<vector <ll > > input2;

int main(){

    vector<pair<int, int > > v;
    for(int i = 0; i < 100; i++){
        v.push_back(make_pair(0, i+1));
    }

    while(1){
        int x;
        cin >> x;
        if(cin.eof()) break;
        //if(x == -1) break;
        v[x-1].first++;
    }

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

    vector<int > result;
    int temp = v[0].first;
    for(int i = 0; i < 100; i++){
        //cout << v[i].second << endl;
        result.push_back(v[i].second);
        if(v[i].first != v[i + 1].first){
            break;
        }
    }

    sort(result.begin(),result.end());
    for(int i = 0; i < result.size(); i++){
        cout << result[i] << endl;
    }
} 


Measured memory_bytes: 3164
#include<stdio.h>

int main(void){
	int m,d,w;
	char week[7][10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	
	
	while(1){
		scanf("%d %d",&m,&d);
		if(m==0 && d==0)break;
		
		if(m>1)d+=31;
		if(m>2)d+=29;
		if(m>3)d+=31;
		if(m>4)d+=30;
		if(m>5)d+=31;
		if(m>6)d+=30;
		if(m>7)d+=31;
		if(m>8)d+=31;
		if(m>9)d+=30;
		if(m>10)d+=31;
		if(m>11)d+=30;
		
		d+=2;
		w=d%7;
		printf("%s\n",week[w]);
		
	}
	
	return 0;
}

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

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    string s;
    int k;
    cin >> s >> k;
    int len = (int)s.length();

    for (int i = 0 ; i < len; i++) {
        if (s[i] != 'a' && (int)('z' - s[i] + 1 <= k)) {
            k = k - ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }

    if (k != 0) {
        s[len - 1] = 'a' + ((s[len - 1] - 'a' + k) % 26);
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 200000;
int n;
ll a[MAX_N];

int b[20];

int maxb() {
  int res = 0;
  REP(i, 20) res = max(res, b[i]);
  return res;
}

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

  int s = 0, t = 0;
  ll ans = 0;

  while(s < n) {
    while(maxb() < 2 && t != n) {

      // cout << "t: " << t << ", s: " << s << endl;
      // REP(i, 3) cout << b[i] << ", ";
      // cout << endl;
      // cout << "maxb: " <<  maxb() << endl;

      REP(i, 20) {
        b[i] += (a[t] >> i) & 1;
      }
      t++;
    }

    while((maxb() == 2 || t == n ) && s < n) {
      if(maxb() == 2) ans += (t - s - 1);
      else ans += (t - s);

      // cout << "t: " << t << ", s: " << s << endl;
      // REP(i, 3) cout << b[i] << ", ";
      // cout << endl;
      // cout << "maxb: " <<  maxb() << endl;

      REP(i, 20) {
        b[i] -= (a[s] >> i) & 1;
      }
      s++;
    }
  }


  cout << ans << endl;

  return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main ()
{
    fastio
    int x ; cin >> x ;
    cout << 1000 - (x % 1000 == 0 ? 1000 : x % 1000)  ;
    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 3640
#include <iostream>

int main(int argc, char **argv)
{
	int h, w;
	int x = 0, y = 0;
	char tiles[100][100];
	bool throughed[100][100] = {};
	bool loop = false;
	bool end = false;
	while(std::cin >> h >> w, h+w != 0){
		x = 0;
		y = 0;
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 100; j++){
				throughed[j][i] = false;
			}
		}
		loop = false;
		end = false;
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				std::cin >> tiles[j][i];
			}
		}
		while(true){
			if(throughed[x][y]){
				loop = true;
				break;
			}
			throughed[x][y] = true;
			switch(tiles[x][y]){
				case '.':
					end = true;
					break;
				case '^':
					y--;
					break;
				case 'v':
					y++;
					break;
				case '<':
					x--;
					break;
				case '>':
					x++;
					break;
			}
			if(end){
				break;
			}
		}
		if(loop){
			std::cout << "LOOP" << std::endl;
		}else{
			std::cout << x << " " << y << std::endl;
		}
	}
	return 0;
}

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

int main()
{
	vector<vector<long long int> >v(3,vector<long long int>(3));
	for(long long int i=0;i<3;i++)
	{
		for(long long int j=0;j<3;j++)
		{
			cin>>v[i][j];
		}
	}
	long long int n;
	bool flag =false;
	cin>>n;
	
	for(long long int k=0;k<n;k++)
	{
		long long int b;
		cin>>b;
		for(long long int i=0;i<3;i++)
		{
			for(long long int j=0;j<3;j++)
			{
				if(b==v[i][j])
				{
					v[i][j]=0;
				}
			}
		}
	}
	
	for(long long int i=0;i<3;i++)
	{
		if(v[i][0]==v[i][1] && v[i][2]==0 && v[i][1]==v[i][2])
		{
			flag=true;
			break;
		}
		if(v[0][i]==v[1][i] && v[2][i]==0 && v[1][i]==v[2][i])
		{
			flag=true;
			break;
		}	
	}
	if(v[0][0]==v[1][1] && v[1][1]==v[2][2])
	{
		flag=true;
	}
	if(v[0][2]==v[1][1] && v[1][1]==v[2][0])
	{
		flag=true;
	}
	
	if(flag)
	{
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	
	return 0;
	
}

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

int main()
{
  char A;
  cin >> A ;
  
  if(A == 'A' || A == 'B' || A == 'C' || A == 'D' || A == 'E' || A == 'F' || A == 'G' || A == 'H'|| A == 'I'|| A == 'J'|| A == 'K'|| A == 'L'|| A == 'M'|| A == 'N'|| A == 'O'|| A == 'P'|| A == 'Q'|| A == 'R'|| A == 'S'|| A == 'U' || A == 'V' || A == 'W' || A == 'X' || A == 'Y' || A == 'Z')
  {cout << "A" << endl;
}else{
 cout << "a" << endl;
}
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using namespace std;

int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1; i<=n; i++){
        if(i%2){
            int cnt=1;
            for(int j=1; j<i; j++){
                if(i%j==0){
                    cnt++;
                }
            }
            if(cnt==8){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];
bool use[100010];
int arr[256];
void Sequence() {
	int w, a, b;
	cin >> w >> a >> b;
	if (a + w < b) {
		cout << b - (a + w) << endl;
	}
	else if (b + w < a) {
		cout << a - (b + w) << endl;
	}
	else {
		cout << 0 << endl;
	}

}
int main() {
	Sequence();
	return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

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

    // 0-indexed
    bool expo[999];

    ALL(fill, expo, false);

    FOR (b, 2, X) FOR (p, 2, X)
    {
        int bp = (int)pow(b, p);
        if (X < bp) break;
        expo[bp - 1] = true;
    }

    bool flg = false;
    for (int i = X - 1; 0 <= i; i--)
    {
        if (expo[i])
        {
            cout << i + 1 << endl;
            flg = true;
            break;
        }
    }

    if (!flg) cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 512