akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

long long MOD = 10000000000 + 7;
vector<ll> v;
int N;

ll f(ll X, ll A){
  ll ret = X / A;
  return ret * A;
}

ll g(ll X){
  for(int i = 0; i < v.size(); i++){
    X = f(X, v[i]);
  }

  return X;
}

int main(){
  cout << setprecision(10);

  cin >> N;
  v.assign(N,0);
  
  for(int i = 0; i < N; i++){
    cin >> v[i];
  }

  // 最小をもとめる
  // 2以上で最小
  ll right, left,mid;

  right = 100000000000000000;
  left = 1;
  while(right - left > 1){
    // cerr << left << " " << right << endl;
    mid = (right + left) / 2;
    ll ret = g(mid);
    if(ret >= 2){
      right = mid;
    } else {
      left = mid; 
    }
  }
  ll min_ans = right;

  // 最大を求める
  // 3以上で最小 - 1
  right = 100000000000000000;
  left = 1;
  while(right - left > 1){
    // cerr << left << " " << right << endl;
    mid = (right + left) / 2;
    ll ret = g(mid);
    if(ret >= 3){
      right = mid;
    } else {
      left = mid; 
    }
  }
  ll max_ans = left;

  // cerr << min_ans << " " << max_ans << endl;
  if(min_ans >= max_ans || max_ans < 2 || min_ans < 2){
    cout << -1 << endl;
    return 0;
  }
  cout << min_ans << " " << max_ans << endl;
}


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

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

int main() {

    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> T(N);

    rep(i, N)
            cin >>
        S[i] >> T[i];

    string X;
    cin >> X;

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == X)
            for (int j = i + 1; j < N; j++)
                ans += T[j];
    }

    cout << ans << endl;

    return 0;
}

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

pair<ll,ll> mid(ll sx, ll sy, ll tx, ll ty){
    rep(i,2)rep(j,2){
        ll nx = sx+(2*i-1)*k, ny = ty + (2*j-1)*k;
        if(max(abs(nx-sx),abs(ny-sy))==k&&max(abs(nx-tx),abs(ny-ty))==k){
            return {nx,ny};
        }
    }
    rep(i,2)rep(j,2){
        ll nx = tx+(2*i-1)*k, ny = sy + (2*j-1)*k;
        if(max(abs(nx-sx),abs(ny-sy))==k&&max(abs(nx-tx),abs(ny-ty))==k){
            return {nx,ny};
        }
    }
    assert(false);
}

vector<pair<ll,ll>> ans;
void dfs(ll sx,ll sy,ll gx,ll gy){
    if(sx==gx&&sy==gy)return;
    ll d=abs(sx-gx)+abs(sy-gy);
    if(d==k){
        ans.emplace_back(gx,gy);
        return;
    }
    if(2*k<d){
        ll dx = gx-sx, dy = gy-sy;
        if(abs(dx)>=k){
            if(dx>0)sx+=k;
            else sx-=k;
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
        else if(abs(dy)>=k){
            if(dy>0)sy+=k;
            else sy-=k;
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
        else {
            sx=gx;
            if(dy<0)sy+=k-abs(dx);
            else sy-=k-abs(dx);
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
    }

    else if(d%2){
        ll dx = gx-sx, dy = gy-sy;
        if(abs(dx)>=k){
            if(dx>0)sx+=k;
            else sx-=k;
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
        else if(abs(dy)>=k){
            if(dy>0)sy+=k;
            else sy-=k;
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
        else {
            sx=gx;
            if(dy<0)sy+=k-abs(dx);
            else sy-=k-abs(dx);
            ans.emplace_back(sx,sy);
            dfs(sx,sy,gx,gy);
        }
    }

    else {
        auto p = mid(sx+sy,sx-sy,gx+gy,gx-gy);
        ans.emplace_back((p.first+p.second)/2,(p.first-p.second)/2);
        ans.emplace_back(gx,gy);
    }
}

int main(){
    ll x,y;
    cin>>k>>x>>y;
    if((x+y)%2&&k%2==0){
        cout<<-1<<endl;
        return 0;
    }
    dfs(0,0,x,y);
    cout<<ans.size()<<endl;
    for(auto p : ans){
        cout<<p.first<<" "<<p.second<<endl;
    }
    return 0;
}

Measured memory_bytes: 19692
from subprocess import call
call(('pypy3','-c',"""

from collections import deque

def main():
  h,w=map(int,input().split())
  #global mp
  mp=[list(input()) for _ in range(h)]
  #global dist
  dist=[[-1]*w for i in range(h)]
  q=deque([])
  
  for i in range(h):
    for j in range(w):
      if mp[i][j]=="#":
        dist[i][j]=0
        q.append([i,j])
      else:
        dist[i][j]=-1
  
  while q:
    x,y=q.popleft()
    for i,j in ((1,0),(0,1),(-1,0),(0,-1)):
      xx,yy=x+i,y+j
      if (0<=xx<h and 0<=yy<w and dist[xx][yy]==-1):
        dist[xx][yy]=dist[x][y]+1
        q.append([xx,yy])
  
  ret=0
  for i in range(h):
    for j in range(w):
      ret=max(ret,dist[i][j])
      
  print(ret)
  return

main()


"""))





Measured memory_bytes: 180680
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
    string s;
    cin >> s;
    int ans;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else ans = 1;
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  vector<int> card(100);
  cin >> N;
  
  for(int i=0; i<N; i++) cin >> card.at(i);

  sort(card.begin(), card.end());
  reverse(card.begin(),card.end());
  
  int A=0;
  int B=0;
  for(int i=0; i<N; i++) {
    if(i % 2 == 0) A += card.at(i);
    else B += card.at(i);
  }
  cout << A - B << endl;
}

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

int fff(int a){
	int rt;
	if(a % 2 == 1)
	{
		rt = 3 * a + 1;
	}
	else
	{
		rt = a / 2;
	}
	return rt;
}

int main() {
	int s;
	cin >> s;
	int bb = 0;
	vector<int> m(10000,0);
	m.at(0) = s;
	for(int i = 1;i < 10001;i++)
	{
		m.at(i) = fff(m.at(i-1));
		for(int j = 0;j < i;j++)
		{
			if(m.at(i) == m.at(j))
			{
				cout << i+1 << 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 h,w;
 cin>>h>>w;
 vector<vector<char>> data(h,vector<char>(w));
 rep(i,h){
     rep(j,w){
        cin>>data.at(i).at(j);
     }
 }
 vector<int> a(0),b(0);
 rep(i,h){
     int check=0;
     rep(j,w){    
         if(data.at(i).at(j)=='#') check++;
      }
    if(check>0) a.push_back(i);
 }
 rep(i,w){
     int check=0;
     rep(j,h){   
         if(data.at(j).at(i)=='#') check++;
     }
    if(check>0) b.push_back(i);
 }
 int n = a.size();
 int m = b.size();
 rep(i,n){
     rep(j,m){
         cout<<data.at(a.at(i)).at(b.at(j));
     }
     cout<<""<<endl;
 }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    char c; cin >> c;
    c++;
    cout << (char)c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;

  // 宣言と同時に Parent を初期化
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};


int H,W;
vector<string> s;
bool seen[400][400];

void dfs(int h, int w, int &white, int &black){
  seen[h][w] = true;
  if(s[h][w] == '.') white++;
  else black++;

  rep(dir,4) {
    int nh = h + dh[dir];
    int nw = w + dw[dir];
    if(nh < 0 || nh == H || nw < 0 || nw == W) continue;
    if(seen[nh][nw]) continue;
    if(s[h][w] == s[nh][nw]) continue;
    dfs(nh, nw, white, black);
  }
}

int main(){
  cin >> H >> W;
  s.resize(H);
  rep(h,H) cin >> s[h];

  ll ans = 0;
  rep(h,H) rep(w,W) {
    if(seen[h][w]) continue;
    int white = 0, black = 0;
    dfs(h, w, white, black);
    ans += (ll)white*black;
  }
  cout << ans << endl;
}

Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;

signed main() {
    int n;
    cin >> n;
    int ans= 0;
    rep(i, n){
        ans += i;
    }
    cout << ans << endl;;
    return 0;
}

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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 3000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int M = S.size();
  N += M;
  long ans = 0;
  for (int i = M; i <= N; i++) {
    long tmp = com(i - 1, M - 1);
    (tmp *= mpow(25, i - M)) %= MOD;
    (tmp *= mpow(26, N - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 74584
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int a[][] = new int[2][n];
        int candies = 0;

        for (int i = 0; i < n; i++) {
            a[0][i] = sc.nextInt();
        }
        candies += a[0][0];     // 0番目で曲がった時の計算用

        for (int i = 0; i < n; i++) {
            a[1][i] = sc.nextInt();
            candies += a[1][i];     // 0番目で曲がった時の計算用
        }

//        int best_n = 0;
        int best_score = candies;     // 0番目で曲がった時のカウント
        for (int i = 1; i < n; i++) {        // n番目で曲がる
            candies += a[0][i];
            candies -= a[1][i-1];
            if (candies > best_score) {
//                best_n = n;
                best_score = candies;
            }
        }
        System.out.println(best_score);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int a(int n) {
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n;
    cin >> n;
    if(n % a(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3524
#include<iostream>
#include<vector>
using namespace std;
#define ll long long int 
ll b[100005], c[100005];
int main(){
  ll i,j,k,n,m,t;
  cin>>n;
  for(i=1;i<=n+1;i++) cin>>b[i];
  for(i=1;i<=n;i++) cin>>c[i];
  vector<ll>a;
  a.push_back(0);
  for(i=1;i<=n;i++){
      a.push_back(b[i]);
      a.push_back(c[i]);
  }
  a.push_back(b[i]);
  ll ans=0;
  for(i=2;i<=2*n+1;i+=2){
    ll cur=a[i];
    if(a[i-1]>=cur){
     ans+=cur;
      continue;
    }
    ans+=(a[i-1]);
    cur-=a[i-1];
    if(a[i+1]>=cur){
      ans+=cur;
      a[i+1]-=cur;
      continue;
    }
    ans+=a[i+1];
    a[i+1]=0;
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 3956
loop do
  m, f, r = gets.split.map(&:to_i).map {|i| i < 0 ? nil : i }
  break unless m || f || r
  case
  when !m || !f
    puts ?F
  when m + f >= 80
    puts ?A
  when m + f >= 65
    puts ?B
  when m + f >= 50 || m + f >= 30 && r && r >= 50
    puts ?C
  when m + f >= 30
    puts ?D
  else
    puts ?F
  end
end

Measured memory_bytes: 8648
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const Int MAX = 55;
Int dp[MAX][MAX][MAX];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m;
  cin>>n>>m;
  vector<Int> a(n),b(n),c(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];

  const Int INF = 1e9;
  for(Int i=0;i<MAX;i++)
    for(Int j=0;j<MAX;j++)
      for(Int k=0;k<MAX;k++)
	dp[i][j][k]=-INF;

  dp[0][m][0]=0;
  for(Int i=0;i<n;i++){
    for(Int j=0;j<=m;j++){
      for(Int k=0;k<10;k++){
	for(Int x=0;x<10;x++){
	  if(j-x<0) continue;
	  Int res=c[i];
	  if(k) chmax(res,b[i]);
	  if(x) chmax(res,a[i]);

	  if(a[i]>=0&&x){
	    Int cnt=8;
	    Int tmp=a[i]*min(cnt,x);
	    cnt-=min(cnt,x);
	    tmp+=max((Int)0,b[i])*min(cnt,k);
	    chmax(res,tmp);
	  }
	  if(b[i]>=0&&k){
	    Int cnt=8;
	    Int tmp=b[i]*min(cnt,k);
	    cnt-=min(cnt,k);
	    tmp+=max((Int)0,a[i])*min(cnt,x);
	    chmax(res,tmp);
	  }
	  chmax(dp[i+1][j-x][x],dp[i][j][k]+res);
	}
      }
    }
  }

  Int ans=-INF;
  for(Int j=0;j<=m;j++)
    for(Int k=0;k<10;k++)
      chmax(ans,dp[n][j][k]);

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




Measured memory_bytes: 4496
#include <iostream>

using namespace std;

int main() {
 int s;

 cin >> s;

 int h = s / 3600;
 s -= h * 3600;
 int m = s / 60;
 s -= m * 60;

 cout << h << ":" << m << ":" << s << endl;

 return 0;
}

Measured memory_bytes: 3080
#include<iostream>

#include <cstdio>
#include <algorithm>
using namespace std;

const int maxn = 1e5+10;
const int INF = 0x7fffffff;

long long sum = 0;
long long op;
int num[maxn];
int dis[maxn];
long long n;
int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&num[i]);
        sum+=num[i];
    }
    if(2*sum%((n+1)*n)){
        printf("NO\n");
        return 0;
    }
    op = 2*sum/((n+1)*n);
    for(int i=0;i<n;i++){
        if(i==n-1){
            dis[i] = num[0] - num[i];
        }else{
            dis[i] = num[i+1] - num[i];
        }
    }
    for(int i=0;i<n;i++){
        if(op-dis[i]<0||(op-dis[i])%n){
            printf("NO\n");
            return 0;
        }
    }
     printf("YES\n");
    return 0;
}

Measured memory_bytes: 1024
s = input()
cen = -(-len(s)//2)-1
ans = 'Yes'
if s != s[::-1]:
    ans = 'No'
mae = s[:cen]
if mae != mae[::-1]:
    ans = 'No'

ato = s[cen+1:]
if ato != ato[::-1]:
    ans = 'No'
print(ans)

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 n, m;
  cin >> n >> m;
  vector<pair<int, int>> s(n);
  for (auto& x : s) cin >> x.first >> x.second;
  sort(s.begin(), s.end(), [](auto& x, auto& y) { return x.first < y.first; });
  ll ans = 0;
  for (auto& x : s) {
    int p = min(m, x.second);
    ans += (ll)p * x.first;
    m -= p;
    if (m <= 0) break;
  }
  cout << ans << endl;
}


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

// main.cpp

int main() {
  std::int_fast64_t N;
  std::cin >> N;
  std::vector<std::int_fast64_t> A;
  A.reserve(N);
  std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), N, std::back_inserter(A));

  std::sort(A.begin(), A.end());
  std::int_fast64_t sum = 0;
  std::int_fast64_t answer = 0;
  for (const std::int_fast64_t& A_i : A) {
    if (A_i <= sum * 2) ++answer;
    else answer = 1;
    sum += A_i;
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
using namespace std;
int sun[1000000];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&sun[i]);
	}int maxv=-2000000000;
	 int minv=sun[0];
	for(int i=1;i<n;i++)
	{
		maxv=max(maxv,sun[i]-minv);
		minv=min(minv,sun[i]);
	}
	printf("%d\n",maxv);
	return 0;
}

Measured memory_bytes: 3980
#include<cstdio>
using namespace std;
int a[310][310];
int ilem[310];
int n,m;
int cnt[310];
int ban[310];
int main()
{
//	freopen("B.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
		ilem[i]=1;
		cnt[a[i][1]]++;
	}
	int ans=n;
	int mx=0,p;
	for(int i=1;i<=m;i++)
		if(cnt[i]>mx)
			mx=cnt[i];
	if(mx<ans) ans=mx;
	for(int zt=1;zt<m;zt++)
	{
		mx=0,p=0;
		for(int i=1;i<=m;i++)
		{
			if(ban[i]) continue;
			if(cnt[i]>mx)
			{
				mx=cnt[i];
				p=i;
			}
		}
		if(!p) break;
		ban[p]=1;
		for(int i=1;i<=n;i++)
		{
			cnt[a[i][ilem[i]]]--;
			while(ban[a[i][ilem[i]]]&&ilem[i]<=m)
				ilem[i]++;
			cnt[a[i][ilem[i]]]++;
		}
		mx=0;
		for(int i=1;i<=m;i++)
		{
			if(ban[i]) continue;
			if(cnt[i]>mx)
				mx=cnt[i];
		}
		if(mx<ans) ans=mx;
	}
	printf("%d\n",ans);
	return 0;
}


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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, x;

	cin >> n >> x;
	if (n == x) {
		puts("Yes");
		REPU(i, 1, n + n) printf("%d\n", i);
	}
	else if (x >= 3 && x <= n + n - 3) {
		puts("Yes");
		vector<int> ans(n + n);
		ans[n] = x;
		ans[n - 1] = x - 1, ans[n + 1] = x + 1;
		ans[n - 2] = x + 2, ans[n + 2] = x - 2;
		int cur = 1;
		REPU(i, 1, n - 2) {
			while (cur >= x - 2 && cur <= x + 2) cur++;
			ans[i] = cur++;
		}
		REPU(i, n + 3, n + n) {
			while (cur >= x - 2 && cur <= x + 2) cur++;
			ans[i] = cur++;
		}
		REPU(i, 1, n + n) printf("%d\n", ans[i]);
	}
	else if (x == 2 && n >= 3) {
		puts("Yes");
		vector<int> ans(n + n);
		ans[n] = 2, ans[n - 1] = 1, ans[n + 1] = 3;
		int cur = 4;
		REPU(i, 0, n - 2) {
			ans[n + 2 + i] = cur++;
			ans[n - 2 - i] = cur++;
		}
		REPU(i, 1, n + n) printf("%d\n", ans[i]);
	}
	else if (x == n + n - 2 && n >= 3) {
		puts("Yes");
		vector<int> ans(n + n);
		ans[n] = n + n - 2, ans[n - 1] = n + n - 3, ans[n + 1] = n + n - 1;
		int cur = n + n - 4;
		REPU(i, 0, n - 2) {
			ans[n + 2 + i] = cur--;
			ans[n - 2 - i] = cur--;
		}
		REPU(i, 1, n + n) printf("%d\n", ans[i]);
	}
	else puts("No");

	return 0;
}


Measured memory_bytes: 2304
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> mp(n+1);
    rep(i,n){
        mp[a[i]]++;
    }
    vector<int> cnt(n + 1, 0);
    for(auto x : mp){
        cnt[x]++;
    }
    show(cnt);
    int all = n;
    for(int k = 1; k <= n; k++){
        int x = all / k;
        //x枚以上あるやつは無駄
        show(k, x, all, cnt.size());
        while((int) cnt.size() - 1 > all / k){
            if(cnt.back() == 0){
                cnt.pop_back();
                continue;
            }
            all--;
            cnt.back()--;
            cnt[cnt.size() - 2]++;
            if(cnt.back() == 0)cnt.pop_back();
        }
        show(all);
        show(cnt);
        cout << all / k << "\n";
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int solve(int *a, int n, int s, vector<vector<int>> &v)
{
    if (s==0)
    {
        return v[n][s]=1;
    }
    if (n==0)
    {
        return v[n][s]=0;
    }
    if (v[n][s]!=-1)
    {
        return v[n][s];
    }
    if (a[n-1]<=s)
    {
        return v[n][s]=solve(a, n, s-a[n-1], v)||solve(a, n-1, s, v);
    }
    return v[n][s]=solve(a, n-1, s, v);
}
int main()
{
    start();
    int x;
    cin>>x;
    int a[]={ 100, 101, 102, 103, 104, 105 };
    int n=6;
    vector<vector<int>> v(n+1, vector<int>(x+1, -1));
    if (solve(a, n, x, v))
    {
        cout<<1;
    }
    else
    {
        cout<<0;
    }

    return 0;
}

Measured memory_bytes: 6324
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int hcf(long long int a,long long int b){
	return b > 0 ? hcf(b, a % b) : a;
}

int main() {
	// your code goes here
	long long int num1,num2,ans=0;
	cin>>num1>>num2;
	long long int hcf12=__gcd(num1,num2);
	set<long long int>s;
	for(long long int i=1;i<=sqrt(hcf12);i++){
		if((hcf12)%i==0){
			long long int a=(hcf12)/i,b=i;
			if(num1%a==0 && num2%a==0){
				s.insert(a);
			}
			if(num1%b==0 && num2%b==0){
				s.insert(b);
			}
		}
	}
	vector<long long int>arr;
	for(auto it=s.begin();it!=s.end();it++){
		arr.push_back(*it);
	}
	for(long long int i=1;i<arr.size();i++){
		if(arr[i]==-1){
			continue;
		}
		ans++;
		for(int j=i+1;j<arr.size();j++){
			if(arr[j]%arr[i]==0){
				arr[j]=-1;
			}
		}
	}
	cout<<ans+1;
	return 0;
}


Measured memory_bytes: 3896
from collections import defaultdict,deque
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
N,M=map(int,input().split())
if M==0:
  print(-1)
  exit()
G=defaultdict(set)
for i in range(M):
  a,b,c=map(int,input().split())
  G[a+(c<<30)].add(b+(c<<30))
  G[b+(c<<30)].add(a+(c<<30))
  G[a].add(a+(c<<30))
  G[b].add(b+(c<<30))
  G[a+(c<<30)].add(a)
  G[b+(c<<30)].add(b)
def BFS(x):
  d={}
  for k in G.keys():
    d[k]=float("inf")
  stack=deque([(x,0)])
  if x not in d:
    return -1
  while stack:
    s,m=stack.popleft()
    if s==N:
      return m
    if d[s]>m:
      d[s]=m
      if s>=(1<<30):
        for i in G[s]:
          if d[i]>10**30:
            stack.appendleft((i,m))
      else: 
        for i in G[s]:
          if d[i]>10**30:
            stack.append((i,m+1))
  return -1

print(BFS(1))



      
    


Measured memory_bytes: 232564
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include<algorithm>
#include <functional>
#include <queue>
#include <unordered_map>
using namespace std;
 
void func_C() {
	int N;
	unsigned long long res = 0;
 
	map<string, int> dict;
	string s;
 
	cin >> N;
 
	for (int i = 0; i < N; i++) {
		cin >> s;
		sort(s.begin(), s.end());
		if (dict.find(s) != dict.end())
			res += ++dict[s];
		else
			dict[s] = 0;
 
	}
	cout << res << endl;
}
 
int main()
{
	func_C();
	return 0;
}

Measured memory_bytes: 11136
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(void){
	int i=0, n=0, c=0;
	string w;
	vector<string> t;
	cin>>w;
	transform(w.begin(), w.end(), w.begin(), ::toupper);
	do{
		if(!(n%1024)){ t.resize(1024); }
		cin>>t[n];
	}while(t[n++]!="END_OF_TEXT");--n;
	for(i=0; i<n; ++i){
		transform(t[i].begin(), t[i].end(), t[i].begin(), ::toupper);
		if(w==t[i]){ ++c; } 
	}
	cout<<c<<"\n";
	return(0);
}


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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s<t) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
int i;
#define rep2(i, a, b) for(i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
using namespace std;
// _________コーディングはここから！！___________
template <const int sz = 5 * 10000000, typename T = long long> struct IO {
    char reader[sz], writer[sz];
    char *now, *now2 = writer;
    IO() {
        reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
        now = reader;
    }
    inline T read() {
        while(*now && *now <= 32) now++;
        if(*now == '-') {
            now++;
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return -res;
        } else {
            T res = 0;
            while('0' <= *now and *now <= '9') { res = res * 10 + *now++ - '0'; }
            return res;
        }
    }
    inline string read_str() {
        string res;
        while(*now and *now != '\n' and *now != ' ') res += *now++;
        now++;
        return res;
    }
    inline void write(T x, char margin = ' ') {
        if(x == 0) {
            putchar('0');
            putchar(margin);
            return;
        }
        if(x < 0) {
            putchar('-');
            x = -x;
        }
        while(x) {
            *now2 = '0' + x % 10;
            now2++;
            x /= 10;
        }
        do {
            now2--;
            putchar(*now2);
        } while(now2 != writer);
        putchar(margin);
    }
    inline void write_str(string s, char margin = ' ') {
        for(auto c : s) putchar(c);
        putchar(margin);
    }
};
IO io;
inline int read() { return io.read(); }
inline void write(int x) { io.write(x); }
inline void write(int x, char c) { io.write(x, c); }
constexpr int N = 500003;
int c[N];
struct T {
    int l, r, idx;
    constexpr bool operator<(const T &rhs) const noexcept { return r < rhs.r; }
} q[N];
int ans[N], last[N], dat[N];

inline void dec(int k) {
    for(++k; k < N; k += k & -k) --dat[k];
}
inline int sum(int k) {
    int res = 0;
    for(++k; k > 0; k -= k & -k) res += dat[k];
    return res;
}
int n, Q, now = 1;

// 頑張れ！！
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
// 頑張れ！！

// vector<int> l[N], idx[N];
vector<pair<int, int>> v[N];
int L, R;
main() {
    n = read(), Q = read();
    rep2(i, 1, n) c[i] = read();
    rep(i, Q) {
        L = read();
        v[read()].emplace_back(L, i);
    }
    rep2(i, 1, n) {
        if(last[c[i]]) dec(last[c[i]]);
        last[c[i]] = i;
        for(auto [l, idx] : v[i]) ans[idx] = sum(i) - sum(l - 1) + i - l + 1;
    }
    // rep(i, Q) {
    //     for(; now < q[i].r; ++now) {
    //         if(last[c[now]]) dec(last[c[now]]);
    //         last[c[now]] = now;
    //     }
    //     ans[q[i].idx] = sum(q[i].r - 1) - sum(q[i].l - 1) + q[i].r - q[i].l;
    // }
    rep(i, Q) write(ans[i], '\n');
}


Measured memory_bytes: 42324
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <cstdlib>
 
auto& in = std::cin;
auto& out = std::cout;
 
int32_t H,W,K;
char map[1000][1000];
bool ok[1000][1000];
int sx, sy;
void func(int h, int w, int k)
{
	if (h < 0 || H <= h || w < 0 || W <= w) { return; }
	if (k < 0) { return; }
	if (ok[h][w]) { return; }
	if (map[h][w] == '#') { return; }
	ok[h][w] = true;
	int dist = K - (std::abs(w - sx) + std::abs(h - sy)) - 1;
	func(h - 1, w, dist);
	func(h + 1, w, dist);
	func(h, w - 1, dist);
	func(h, w + 1, dist);
}
 
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
 
	in >> H>>W>>K;
	for (size_t i = 0; i < H; i++)
	{
		in >> map[i];
	}
	for (size_t i = 0; i < H; i++)
	{
		for (size_t w = 0; w < W; w++)
		{
			if (map[i][w] == 'S') {
				sx = w; sy = i; map[i][w] = '.';
			}
		}
	}
	func(sy, sx, K);
 
	int res = H*W;
	for (int i = 0; i < H; i++)
	{
		for (int w = 0; w < W; w++)
		{
			if (map[i][w] != '#' && ok[i][w]) {
				res = std::min(res, 1 + (std::min({ i,H - i - 1,w,W - w - 1 })+K-1)/K);
			}
		}
	}
	std::cout << res << std::endl;
 
	return 0;
}
#endif

Measured memory_bytes: 33024
#include <stdio.h>

int Check(int S){
  int i, s0, s;
  s0 = S % 10;
  for(i = 1;i < 4;i++){
    S *= 0.1;
    s = S % 10;
    if(s == s0) return 1;
    s0 = s;
  }
  return 0;
}

int main(void){
  int S;
  scanf("%d", &S);
  if(Check(S) == 1) printf("Bad\n");
  else printf("Good\n");
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i=0;i<N;i++){
        cin >> P.at(i);
    }
    int ct = 0;
    int m = P.at(0);
    for(int i=0;i<N;i++){
        int x = min(m,P.at(i));
        if(P.at(i) == x){
            ct++;
            m = P.at(i);
        }
    }

    cout << ct << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
int M,T,P,R;
ll sect[100005];
ll ans=0,tmpans=0;
ll tmpmin=1e12;
typedef long long ll;
typedef vector<ll> vll;

int main(int argc,char const* argv[])
{
  while(1)
    {
      int h,w;
      cin >> h >> w;
      if(h==0) break;
      int firstaim=h*h+w*w;
      int tmpaim=1e9;
      int hcand=0,wcand=0;
      for(int i=1;i<=150;i++)
	{
	  for(int j=i+1;j<=150;j++)
	    {
	      if(i==h && j==w) continue;
	      if(i*i+j*j>=firstaim && i*i+j*j<tmpaim)
		{
		  if(i>h && i*i+j*j==firstaim) 
		    {
		      hcand=i;
		      wcand=j;
		      tmpaim=i*i+j*j;
		    }
		  else if(i*i+j*j!=firstaim) 
		    {
		      hcand=i;
		      wcand=j;
		      tmpaim=i*i+j*j;
		    }
		  if(tmpaim==firstaim && hcand>h) break;
		}
	    }
	  if(tmpaim==firstaim && hcand>h) break;
	}
      cout << hcand << ' ' << wcand << endl;
    }
  return 0;
}



Measured memory_bytes: 3068
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }


    static class Pos {
        int h;
        int w;

        Pos(int h, int w) {
            this.h = h;
            this.w = w;
        }

        int diff(Pos other) {
            return Math.abs(h - other.h) + Math.abs(w - other.w);
        }
    }

    static void solve(Scanner scanner) {
        int H = scanner.nextInt(), W = scanner.nextInt(), D = scanner.nextInt();
        scanner.nextLine();
        Map<Integer, Pos> m = new HashMap<>();
        for (int h = 0; h < H; h++){
            for (int w = 0; w < W; w++) {
                int n = scanner.nextInt();
                m.put(n, new Pos(h, w));
            }
        }
        scanner.nextLine();

        int[] cSum = new int[H * W + 1];
        for (int i = 1 + D; i < H * W + 1; i++) {
            cSum[i] = cSum[i - D] + m.get(i).diff(m.get(i - D));
        }

        int Q = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < Q; i++) {
            int[] q = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            System.out.println(cSum[q[1]] - cSum[q[0]]);
        }
    }

}

Measured memory_bytes: 179776
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int dp[MAX_N];

signed main() {
  INIT;
	VAR(int,n);
	VEC(int,h,n);

	fill_n(dp,MAX_N,INF);
	dp[0] = 0;
	REP(i,n){
	  if(i-1>=0)dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
		if(i-2>=0)dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
	}
	OUT(dp[n-1])BR;
	
	
  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    string s; cin >> s;
    int n = s.size();
    int x,y; cin >> x >> y;
    deque<int> dx,dy;
    int cnt = 0;
    int str = 0;
    rep(i,n){
        if(s[i] == 'T'){
            if(cnt % 2) dy.push_back(str);
            else dx.push_back(str);
            cnt++;
            str = 0;
        }else{
            str++;
        }
    }
    if(str){
        if(cnt % 2) dy.push_back(str);
        else dx.push_back(str);
    }
    if(dy.empty()) dy.push_back(0);
    int fx = dx.front();
    x -= fx;
    dx.pop_front();
    if(dx.empty()) dx.push_back(0);
    int nx = dx.size(); int ny = dy.size();
    sort(RALL(dx)); sort(RALL(dy));

    bool okx = false, oky = false;
    int tmpx = 0, tmpy = 0;
    rep(i,nx){
        if(tmpx > x) tmpx -= dx[i];
        else tmpx += dx[i];
    }
    if(tmpx == x) okx = true;

    rep(i,ny){
        if(tmpy > y) tmpy -= dy[i];
        else tmpy += dy[i];
    }
    if(tmpy == y) oky = true;
    if(okx && oky) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
    int a, b, c, n;
    cin >> a >> b >> c >> n;
    
    int cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if ((500*i + 100*j + 50*k) == n) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	as := make([]uint64, n)
	for i := 0; i < n; i++ {
		as[i] = uint64(nextInt())
	}

	var r int
	var l int

	var sum uint64
	var count int

	for l = 0; l < n; l++ {
		for as[l]&sum != 0 {
			sum -= as[r]
			r += 1
		}
		//fmt.Printf("r: %v, l: %v\n", r, l)
		sum += as[l]
		count += l - r + 1
	}

	fmt.Println(count)
}

func check(as []uint64) bool {
	if len(as) == 0 {
		return false
	}
	xor := as[0]
	sum := as[0]
	for _, a := range as[1:] {
		xor ^= a
		sum += a
		if xor != sum {
			return false
		}
	}
	//if xor == sum {
	//	fmt.Printf("xor: %v, sum: %v\n", xor, sum)
	//}
	return xor == sum
}


Measured memory_bytes: 3840
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt

  let solve a res | a >= n = res
                  | otherwise = let nb = (n-1) `div` a
                                    res' = res + nb
                                in solve (a+1) res'

      ans = solve 1 0

  print ans


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

const ll INF = 1LL << 60;

class UnionFind {
public:
  //親の番号を格納する。親だった場合は-(その集合のサイズ)
  vector<int> Parent;

  //作るときはParentの値を全て-1にする
  //こうすると全てバラバラになる
  UnionFind(int N) {
    Parent = vector<int>(N, -1);
  }

  //Aがどのグループに属しているか調べる
  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  //自分のいるグループの頂点数を調べる
  int size(int A) {
    return -Parent[root(A)];//親をとってきたい]
  }

  //AとBをくっ付ける
  bool connect(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
    A = root(A);
    B = root(B);
    if (A == B) {
      //すでにくっついてるからくっ付けない
      return false;
    }

    //大きい方(A)に小さいほう(B)をくっ付けたい
    //大小が逆だったらひっくり返しちゃう。
    if (size(A) < size(B)) swap(A, B);

    //Aのサイズを更新する
    Parent[A] += Parent[B];
    //Bの親をAに変更する
    Parent[B] = A;

    return true;
  }
};

ll N, M;

int main() {
    cin >> N >> M;
    UnionFind uf = UnionFind(N);

    rep(i, M) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--; y--;
        uf.connect(x, y);
    }

    set<ll> st;
    rep(i, N) {
        ll par = uf.root(i);
        st.insert(par);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 8292
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin >> s;
  vector<string> w = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  for(int i=0; i<7; i++) if(s==w[i]){cout << 7-i; return 0;}
}

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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");


int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int n;
    cin>>n;
    vi vec;
    int maxi=INT_MIN;
    int maxi2=INT_MIN;
    mapii mps;
    while(n--)
    {
    	int x;
    	cin>>x;
    	vec.pb(x);
    	++mps[x];
    	if(x>maxi)
    		maxi=x;
    }
    for(auto x : vec)
    {
    	if(x>maxi2 && x<maxi)
    		maxi2=x;
    }
    for(auto x : vec)
    {
    	if(x==maxi && mps[x]==1)
    		cout<<maxi2<<"\n";
    	else
    		cout<<maxi<<"\n";
    }

}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; ++i) cin >> A[i];
    for(int i=0; i<N; ++i) cin >> B[i];
    vector<int> AC(0), WA(0);
    for(int i=0; i<N; ++i) {
        if(A[i] >= B[i]) AC.push_back(A[i]-B[i]);
        else WA.push_back(B[i]-A[i]);
    }
    sort(AC.begin(), AC.end(), greater<int>());

    if(WA.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    if(AC.size() == 0) {
        cout << -1 << endl;
        return 0;
    }
    int ans = WA.size() + 1;
    int cur = 0;
    for(int i=0; i<WA.size(); ++i) {
        while(WA[i] > 0) {
            if(WA[i] <= AC[cur]) {
                AC[cur] -= WA[i];
                break;
            } else {
                WA[i] -= AC[cur];
                if(cur == AC.size()-1) {
                    cout << -1 << endl;
                    return 0;
                } else {
                    ++cur;
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}

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

typedef long long LL;
typedef pair<int, int> II;

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    freopen("out", "w", stdout);
#endif
    LL a, b; cin >> a >> b;
    if (abs(a - b) <= 1) puts("Brown"); else puts("Alice");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int dp[3000][3000];
pair<int, int> ab[3000];

int main(){
    int n, t;
    int a, b;
    pair<int, int> c;
    cin >> n >> t;
    for (int i = 0; i < n; i++){
        cin >> a >> b;
        c = make_pair(a, b);
        ab[i] = c;
    }
    sort(ab, ab + n);
    for (int m = 1; m < n; m++){
        c = ab[m-1];
        a = c.first; b = c.second;
        for (int s = 1; s < t; s++){
            if (s < a) dp[m][s] = dp[m-1][s];
            else dp[m][s] = max(dp[m-1][s], dp[m-1][s-a] + b);
        }
    }
    int ans = 0;
    int happiness;
    for (int i = 0; i < n; i++){
        happiness = ab[i].second + dp[i][t-1];
        if (happiness > ans) ans = happiness;
    }
    cout << ans << '\n';

}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

int main(){
  ll n, m, s, c;
  cin >> n >> m;
  vector<ll> S(4,-1); 
  RAP(i,m){
      cin >> s >> c;
      if(S[s]==-1){
          S[s] = c;
      }else{
          if(S[s] != c){
              cout << -1 << endl;
              return 0;
          }
      }
  }
  for(ll i=1;i<=n;i++){
      if(S[i]==-1){
          if(i==1){
              if(n==1){
                  cout << 0;
              }else{
                  cout << 1;
              }
          }else{
              cout << 0;
          }
      }else{
          if(S[i]==0 && i==1 && n!=1){
              cout << -1 << endl;
              return 0;
          }else{
              cout << S[i];
          }
      }
  }
  cout << endl;
  return 0;
 
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<int> a(n);
  int i,j;
  rep(i,n)cin>>a[i];
  vector<bool> ok(2001,false);
  rep(i,1<<n)
  {
    int kans=0;
    rep(j,n)
    {
      if(1<<j&i)kans+=a[j];
    }
    ok[kans]=true;
  }
  int q;cin>>q;
  vector<int> m(q);
  rep(i,q)cin>>m[i];
  rep(i,q)
  {
    if(ok[m[i]])cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
}




Measured memory_bytes: 3088