akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(V) (V).begin(), (V).end() 
#define x first
#define y second

using namespace std;

typedef long long ll;
template <typename T> using V = vector <T>;
const ll mod = 1e9 + 7;
ll powmod(ll a1, ll b1, ll modx = mod) {ll res=1; a1%=modx; for(;b1;b1>>=1) {if(b1&1)res=res*a1%modx; a1=(a1*a1)%modx;}return res;}
ll inv(ll ax, ll modx = mod) { return powmod(ax,modx-2,modx); } 
int main() {fio;
	string s;
	int n;
	cin >> n;
	cin >> s;
	map <char, int> f;
	for(auto u : s) f[u]++;
	ll val = 1;
	for(auto u : f) val = (val * (u.second + 1)) % mod;
	cout << (val + mod - 1) % mod; 
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int D[2];
vector<pii> es[2];
vector<int> col[2];

pii VerToVec(int v) {
  return pii(v/(2*N), v%(2*N));
}

int VecToVer(pii p) {
  return p.X * 2*N + p.Y;
}

void Color(int v, vector<pii> &es, vector<int> &col, int c=1) {
  col[v] = c;

  auto p = VerToVec(v);
  for (auto &d : es) {
    pii q(p.X+d.X, p.Y+d.Y);
    if (q.X < 0 || q.X >= 2*N) continue;
    if (q.Y < 0 || q.Y >= 2*N) continue;
    int u = VecToVer(q);
    if (col[u]) {
      assert(col[u] == 3-c);
      continue;
    }

    Color(u, es, col, 3-c);
  }
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  rep(i, 2) {
    cin >> D[i];
    col[i].resize(4*N*N);
    reps(s, -2*N, 2*N) {
      reps(t, -2*N, 2*N) {
        if (s*s+t*t == D[i]) es[i].eb(pii(s, t));
      }
    }
  }

  rep(v, 4*N*N) {
    rep(i, 2) {
      if (col[i][v]) continue;
      Color(v, es[i], col[i]);
    }
  }

  reps(p, 1, 3) {
    reps(q, 1, 3) {
      vector<int> vs;
      rep(v, 4*N*N) {
        if (col[0][v] == p && col[1][v] == q) vs.eb(v);
      }

      if (vs.size() >= N*N) {
        vs.resize(N*N);
        for (int v : vs) {
          auto p = VerToVec(v);
          cout << p.X << " " << p.Y << "\n";
        }
        return 0;
      }
    }
  }
  assert(0);
}


Measured memory_bytes: 32628
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
long long ans=0;
int sm=INT_MAX;
int a[n];
for(int i=0;i<n;i++)
{
    int x;
    cin>>x;
    a[i]=x;
}
sort(a,a+n);
int k=n-1;
for(int i=n-1;i>=0;i--)
{
if(i==n-1)
{
    ans+=a[i];
    k--;
    if(k==0)
    break;
}
else
{
ans+=a[i];
k--;
if(k==0)
break;
ans+=a[i];
k--;
if(k==0)
break;
}
}

cout<<ans;
   return 0;
}


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

int n,m;
vector<vector<int>> g;
vector<int> seen;
int ans = 0;
void dfs(int v,int pa = 1){
  seen[v] = 1;
  for(int nv : g[v]){
    if(seen[nv]) continue;
    if(pa == n-1) ans++;
    dfs(nv,pa+1);    
  }
  seen[v] = 0;
}
int main(){
  cin>>n>>m;
  g.resize(n);
  seen.resize(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--; b--;
    g[a].pb(b); g[b].pb(a);
  }
  
  dfs(0);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int a[1000007] = {};
    int cnt[1000007] = {};
    int s; cin >> s;
    a[0] = s;
    cnt[s]++;
    int ans = -1;

    repr(i, 1, 1000001){
        if(a[i-1] % 2 == 0){
            a[i] = a[i-1] / 2;
            cnt[a[i]]++;
        }else{
            a[i] = 3*a[i-1] + 1;
            cnt[a[i]]++;
        }
        if(cnt[a[i]] == 2){
            ans = i+1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11428
fun main(args: Array<String>) {
    val (A, B, K) = readLine()!!.split(" ").map { it.toInt() }
    var a = A; var b = B
    var c = 0
    while (true) {
        a -= (a % 2)
        a /= 2
        b += a
        if (++c == K) break

        b -= (b % 2)
        b /= 2
        a += b
        if (++c == K) break
    }

    println("$a $b")
}

Measured memory_bytes: 37912
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
total = 0
previous=-1

for a in A:
    total += B[a-1]
    if previous+1 == a:
        total += C[previous-1]
    previous = a
print(total)

Measured memory_bytes: 3064
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)
#define MAXLEN 29

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;

vector <int> t[100000];
int n, ans;

int solve(int cur, int par) {
	int cnt = 0;
	bool need = false;
	bool same = false;
	for (int i = 0; i < t[cur].size(); i++) {
		if (t[cur][i] == par) continue;
		int xx = solve(t[cur][i], cur);
		if (xx == 1 || xx == 3) need = true;
		if (xx == 2 || xx == 3) cnt++;
		if (xx == 3) same = true;
	}
	bool root = (par == -1);
	//cout << cur << " " << cnt << " " << need << " " << same << endl;
	if (!root) {
		if (cnt == t[cur].size() - 1) {
			if (cnt > 0) return 2;
			else return 1;
		}	
		if (cnt < t[cur].size() - 1) {
			ans += t[cur].size() - 2 - cnt;
			if (cnt > 0 || t[cur].size() - 2 - cnt > 0) return 3;
			else return 1;
		}
	} else {
		int added = 0;
		if (t[cur].size() > cnt + 1) added = t[cur].size() - cnt - 1;
		ans += added;
		if (cnt >= 2) return 0;
		if (added) {
			return 0;
		} else {
			if (same || (need && cnt == 0)) ans++;
		}
		return 0;
	}
	assert(false);
	return 0;
}

int main() {
	//freopen("greedy.in", "r", stdin);
	//freopen("greedy.out", "w", stdout);	
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		t[a].push_back(b);
		t[b].push_back(a);
	}
	solve(0, -1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 13440
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;

int main(){
  int n;
  int x;
  cin >> n;
  map<int,int> odd;
  map<int,int> even;

  for(int i = 0; i < n; i++){
    cin >> x;
    if(i%2==0) ++even[x];
    else ++odd[x];
  }

  vector<int> Echeck;

  int Emax = 0;
  int LEmax = 0;
  int SEmax;
  int stE = 0;
  for(auto a: even){
    // 最大個数
    if(LEmax < a.second){
      stE = a.first;
      LEmax = a.second;
    }
    // 2番目以降を調べるためのvector
    Echeck.push_back(a.second);
  }

  sort(Echeck.begin(),Echeck.end(),greater<int>());
  if(Echeck.size() > 1) SEmax = Echeck[1];
  else SEmax = -1;

  vector<int> Ocheck;

  int LOmax = 0;
  int SOmax;
  int stO = 0;
  for(auto a: odd){
    if(LOmax < a.second){
      stO = a.first;
      LOmax = a.second;
    }
    Ocheck.push_back(a.second);
  }
  sort(Ocheck.begin(),Ocheck.end(),greater<int>());
  if(Ocheck.size() > 1) SOmax = Ocheck[1];
  else SOmax = -1;


  int Ans;

  if(stE != stO)  Ans = n - LEmax - LOmax;
  else{
    if(SEmax==-1&&SOmax==-1){
      Ans = n/2;
    }else if(SEmax == -1){
      Ans = min(n - LEmax - SOmax,n - (n+1)/2 - LOmax);
    }else if(SOmax == -1){
      Ans = min(n - LEmax - n/2,n - SEmax - LOmax);
    }else{
      Ans = min(n - LEmax - SOmax,n - SEmax - LOmax);
    }
  } 

  printf("%d\n",Ans );
  return 0;



}


Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC084 {
	class ABC084_A {
		static void Main(string[] args) {
			var input = int.Parse(Console.ReadLine());
			Console.WriteLine(24-input+24);
		}
	}
}


Measured memory_bytes: 11092
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<stdbool.h>
using namespace std;
typedef long long ll;
#define N (1000000000+7)

int main(void) {
	int n;
	string s;
	cin >> n >> s;
	int left = 0, right = 0;
	string t;
	for (int i = 0;i < n;i++) {
		if (s[i] == '(') {
			if (left == 0) {
				if (right == 0) {
					t += "(";
					left++;
				}
				else {
					for (int j = 0;j < right;j++)t = "(" + t;
					for (int j = 0;j < right;j++)t = t + ")";
					right = 0;
					left++;
				}
			}
			else {
				if (right == 0) {
					t += "(";
					left++;
				}
			}
		}
		else {
			if (left == 0) {
				if (right == 0) {
					t = "(" + t + ")";
				}
			}
			else {
				if (right == 0) {
					t += ")";
					left--;
				}
			}
		}
	}
	if (left != 0) {
		if (right == 0) {
			for (int i = 0;i < left;i++)t += ")";
		}
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    n, m = get_int_list()
    xs = get_int_list()

    if n >= m:
        print(0)
        return
    xs.sort()
    diffs = [a - b for a, b in zip(xs[1:], xs)]
    diffs.sort()
    print(sum(diffs[:m-n]))


if __name__ == '__main__':
    main()


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define f(i,a, b) for (ll i = a; i < b; i++)
#define ft int t; cin>>t; while(t--)
#define mp make_pair
#define pb push_back
#define ld float
#define fd(i,a, b) for (ll i = a; i >= b; i--)
#define nl "\n"
 /*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
     typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/

 ull powm(ull a,ull b){

   ull res=1;

   while(b){
     if(b%2)res=(res*a);
     a=(a*a);
     b/=2;
   }

 return res;
 }


int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
  double dd;
  cin>>dd;
  cout<<2*acos(-1)*dd;
}


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

typedef long long ll;

class UnionFind {
private:
	vector<ll> parents;
	vector<ll> ranks;

public:
	vector<ll> sizes;

	UnionFind(ll s): parents(s), ranks(s), sizes(s, 1) {
		for(ll i = 0; i < s; i++) parents[i] = i;
	}

	int find(ll x) {
		if(parents[x] == x) return x;
		else return parents[x] = find(parents[x]);
	}

	void unite(ll x, ll y) {
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(ranks[x] < ranks[y]) {
			parents[x] = y;
			sizes[y] += sizes[x];
		} else {
			parents[y] = x;
			sizes[x] += sizes[y];
			if(ranks[x] == ranks[y]) ranks[x]++;
		}
	}

	bool same(ll x, ll y) {
		return find(x) == find(y);
	}
};

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

    ll N, M;
    cin >> N >> M;

    vector<ll> A(M);
    vector<ll> B(M);

    for(int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<ll> ans(M);

    UnionFind uf(N);

    ans[M - 1] = N * (N - 1LL) / 2LL;

    for(int i = M - 1; i > 0; i--) {
        if(uf.same(A[i], B[i])) {
            ans[i - 1] = ans[i];
        } else {
            ans[i - 1] = ans[i] - (N - uf.sizes[uf.find(A[i])]) * uf.sizes[uf.find(A[i])] + (N - uf.sizes[uf.find(B[i])] - uf.sizes[uf.find(A[i])]) * uf.sizes[uf.find(A[i])];
            uf.unite(A[i], B[i]);
        }
    }

    for(int i = 0; i < M; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 7808
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class FPlayingTagOnTree {
public:
    int N, u, v;
    vc<int> dist, dist2;
    vvc<int> G;

    void dfs(int s, int p){
        for(auto& w : G[s]){
            if(w==p or dist[s]+1>=dist2[w]) continue;
            dist[w] = dist[s] + 1;
            dfs(w, s);
        }
    }

    void dfs2(int s, int p){
        for(auto& w : G[s]){
            if(w==p) continue;
            dist2[w] = dist2[s] + 1;
            dfs2(w, s);
        }
    }

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        in>>N>>u>>v, u--, v--;
        G.resize(N);
        dist.resize(N, -1);
        dist2.resize(N, -1);
        REP(i, N-1){
            int a, b;
            in>>a>>b;
            a--, b--;
            G[a].pb(b);
            G[b].pb(a);
        }
        dist[u] = dist2[v] = 0;
        dfs2(v, -1);
        dfs(u, -1);
        int ans = 0;
        REP(i, N){
            if(dist[i]==-1) continue;
            chmax(ans, dist2[i]-1);
        }
        out<<ans<<'\n';
    }
};


int main() {
	FPlayingTagOnTree solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14520
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  string res;
  if(a <= 0 && b >= 0)res = "Zero";
  else if(a > 0)res = "Positive";
  else{
    if((b - a + 1) % 2 == 1)res = "Negative";
    else res = "Positive";
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 

#define print(stuff) cout << stuff << endl
#define len length
#define ret0 return 0
#define ret return 

#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound

#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN 100005

vl adj[MAXN];
ll dp[MAXN][2];

void dfs(ll s, ll e){
    for(auto x: adj[s]){
        if(x!=e){
            dfs(x,s);
            dp[s][0] = (dp[s][0]%mod * ((dp[x][0]%mod + dp[x][1]%mod)%mod))%mod;
            dp[s][1] = (dp[s][1]%mod * dp[x][0]%mod)%mod;
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/

    ll n;
    cin>>n;
    loop(i,0,n-1){
        ll x, y;
        cin>>x>>y;
        adj[x].pb(y), adj[y].pb(x);
    }
    loop(i,1,n+1){
        dp[i][0] = dp[i][1] = 1;
    }
    dfs(1,0);
    print((dp[1][0]%mod + dp[1][1]%mod)%mod);

    /*#ifndef ONLINE_JUDGE
        end_routine();
    #endif*/
}



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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll x;cin >>x;
    ll a=360;
    ll g=__gcd(a,x);
    ll l=a*x/(g*x);
    cout <<l<<endl;
    return 0;
}

Measured memory_bytes: 3556
# -*- coding:utf-8 -*-
from collections import deque

def solve():
    d = deque(input())
    Q = int(input())

    is_reverse = False # 反転中か？

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            _, f, c = query.split()

            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    d.append(c)
                else:
                    # 先頭にcを追加
                    d.appendleft(c)
            else:
                if is_reverse:
                    # 先頭に追加
                    d.appendleft(c)
                else:
                    # 末尾に追加
                    d.append(c)

    if is_reverse:
        print("".join(reversed(list(d))))
    else:
        print("".join(d))


def solve2():
    S = list(input())
    Q = int(input())
    M = 2*10**5+10
    data = [None]*M
    data.extend(S)
    data.extend([None]*M)
    left, right = M-1, M+len(S)

    is_reverse = False

    for _ in range(Q):
        query = input()
        if query == "1":
            is_reverse = not is_reverse
        else:
            t, f, c = query.split()
            if f == "1":
                if is_reverse:
                    # 末尾にcを追加
                    data[right] = c
                    right += 1
                else:
                    # 先頭にcを追加
                    data[left] = c
                    left -= 1
            else:
                if is_reverse:
                    # 先頭に追加
                    data[left] = c
                    left -= 1
                else:
                    # 末尾に追加
                    data[right] = c
                    right += 1

    # 出力
    if is_reverse:
        print("".join(data[right-1:left:-1]))
        # for i in range(right-1, left, -1):
        #     print(data[i], end="")
    else:
        # for i in range(left+1, right):
        #     print(data[i], end="")
        print("".join(data[left+1:right]))
    # print()


if __name__ == "__main__":
    solve2()


Measured memory_bytes: 10584
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<ll> dqll;

#define MOD 1000000007

bool isPrime(ll x) {
  for (ll i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}

int main() {
  ll Q;
  cin >> Q;

  ll max = 100001;

  ll cnt = 0;

  vll lst(max);
  lst[1] = 0;
  for (ll i = 3; i <= max; i += 2) {
    if (isPrime(i) && isPrime((i + 1) / 2)) cnt++;
    lst[i] = cnt;
  }  // i

  for (int i = 0; i < Q; i++) {
    ll l, r;
    cin >> l >> r;
    ll hosei = ((isPrime(l) && isPrime((l + 1) / 2)) ? 1 : 0);
    if (l == 1) hosei = 0;
    cout << lst[r] - lst[l] + hosei << endl;
  }

  return 0;
}


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

bool isPrime(int n) {
	if (n <= 1) return 0;
	if (n == 2 || n == 3) return 1;
	if (n % 2 == 0 || n % 3 == 0) return 0;
	for (int i = 5; i * i <= n; i += 6) {
		if(n % i == 0 || n % (i + 2) == 0) return 0;
	}
	return 1;
}

signed main() {
#ifdef _DEBUG
	freopen("_in" , "r", stdin );
	freopen("_out", "w", stdout);
#endif
	int a, b; cin >> a >> b;
	int n = __gcd(a, b), c = 1, ans = 1;
	int t = n;
	while (t != 1) {
		c++; if(c * c > n) break;
		if (t % c == 0) ans++;
		while (t % c == 0) t /= c;
	}
	if (isPrime(t)) ans++;
	cout << ans << '\n';
}


Measured memory_bytes: 3596
#include<iostream>

using namespace std;


struct circle{
  double x,y,r;
};

circle c[2];


bool isIn(circle a, circle b){
  return (b.x+b.r < a.x+a.r && b.y+b.r < a.y+a.r &&
	  b.x-b.r > a.x-a.r && b.y-b.r > a.y-a.r);
}

bool cross(circle a, circle b){
  double diff = (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
  return diff <= (a.r+b.r)*(a.r+b.r);
}
int solve(){

  if(isIn(c[0],c[1])) return 2;
  else if(isIn(c[1],c[0]))return -2;
  else if(cross(c[0],c[1])) return 1;
  else return 0;
}

int main(){

  int n;
  cin >> n;
  while(n--){
    for(int i = 0; i < 2; i++)
      cin >> c[i].x >> c[i].y >> c[i].r;

    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
S = input()
T = "keyence"

ok = False
if S.startswith(T) or S.endswith(T):
    ok = True
for i in range(1, 7):
    left = T[:i]
    right = T[i:]
    a = S.startswith(left)
    b = S.endswith(right)
    if a and b:
        ok = True
if ok:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9092
#include<stdio.h>
#include<string.h>
int main()
{
    char a[3];
    scanf("%s",a);
    if(a[0]=='S'&&a[1]=='S'&&a[2]=='S')
        printf("0\n");
        else if(a[0]=='R'&&a[1]=='R'&&a[2]=='R')
            printf("3");
            else if(a[0]=='S'&&a[1]=='S'&&a[2]=='R')
                printf("1");
                else if(a[0]=='S'&&a[1]=='R'&&a[2]=='S')
                    printf("1");
                else if(a[0]=='R'&&a[1]=='S'&&a[2]=='S')
                    printf("1");
                    else if(a[0]=='R'&&a[1]=='S'&&a[2]=='R')
                    printf("1");
                    else
                        printf("2");

    return 0;
}

Measured memory_bytes: 1640
#include<iostream>
#include<string>
#include<vector>
#include<cmath>

class unionFind{
public:
	std::vector<int> tree;

	unionFind(int n){
		tree.resize(n);

		for(int i=0; i<n; i++)
			tree[i]=i;
	}

	int root(int n){
		if(tree[n]==n)
			return n;
		else
			return tree[n]= root(tree[n]);
	}

	void merge(int n, int m){
		int nRoot= root(n); 
		int mRoot= root(m);

		if(nRoot==mRoot)
			return;

			tree[mRoot]= nRoot;
	}

};

int main(){
	long long n, m;
	std::vector<long long> aList;
	std::vector<long long> bList;
	std::vector<long long> ansList;
	std::vector<long long> groupNumList;

	std::cin>>n>>m;

	unionFind *uf= new unionFind(n);
	aList.resize(m);
	bList.resize(m);	
	groupNumList.resize(n, 1);
	ansList.resize(m+1, 0);
	ansList[m]= n*(n-1)/2;

	for(int i=0; i<m; i++)
		std::cin>>aList[i]>>bList[i];

	for(int i=m-1; i>=0; i--){
		int aRoot= uf->root(aList[i]-1);
		int bRoot= uf->root(bList[i]-1);

		if(aRoot==bRoot){
			ansList[i]= ansList[i+1];		
		}else{

			long long inConv= groupNumList[aRoot]*groupNumList[bRoot];
			ansList[i]= ansList[i+1]- inConv;

			uf->merge(aList[i]-1, bList[i]-1);

			groupNumList[uf->root(aList[i]-1)]= groupNumList[aRoot]+groupNumList[bRoot];
		}
	}

	for(int i=1; i<m+1; i++)
		std::cout<<ansList[i]<<std::endl;


	return 0;
}

Measured memory_bytes: 4864
from collections import Counter

N = int(input())
dic = {}

for _ in range(N):
    s = sorted(input())
    s = str(s)
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

print(sum(d * (d-1) // 2 for d in dic.values() if d > 1))

Measured memory_bytes: 22372
#include "bits/stdc++.h"
using namespace std;

int main(){
	string z;
	cin>>z;
	
	int ans=1e9+7;
	
	for(int i=0;i<26;i++){
		int exflag=1;
		for(int j=0;j<z.size();j++)if(z[j]!=char('a'+i))exflag=0;
		if(exflag==1)ans=0;;
		string s=z;
		int ssi=s.size();
		int flag=1;
		while(1){
			string ns(ssi-1,'0');
			for(int k=0;k<ssi;k++){
				if(s[k]==char('a'+i)||s[k+1]==char('a'+i)){
					ns[k]=('a'+i);
				}else{
					ns[k]='0';
				}
			}
			ssi--;
			//cout<<char('a'+i)<<endl;
			//cout<<s<<endl;
			//cout<<ssi<<endl;
			flag=1;
			for(int j=0;j<ssi;j++)if(ns[j]!=char('a'+i))flag=0;
			if(flag==1||ssi<=1)break;
			s=ns;
		}
		int aaaa=z.size()-ssi;
		ans=min(ans,aaaa);
	}
	
	cout<<ans<<endl;
	return 0;
}

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

int main(void){
    int mx[4] = {0,1,0,-1}, my[4] = {1,0,-1,0};
    while(true){
        int N=0, gem[22][22], M=0, len=0, mov=0, cap=0;
        char dir;
        for(int i=0;i<22;++i) for(int j=0;j<22;++j) gem[i][j] = 0;
        cin >> N;
        if(N==0) break;
        for(int i=0;i<N;++i){
            int x, y;
            cin >> x >> y;
            gem[20-y][x] = 1;
        }
        cin >> M;
        int x=10, y=10;
        for(int i=0;i<M;++i){
            cin >> dir >> len;
            switch(dir){
                case 'N': mov = 0; break;
                case 'E': mov = 1; break;
                case 'S': mov = 2; break;
                case 'W': mov = 3; break;
            }
            for(int j=1;j<=len;++j){
                y += my[mov];
                x += mx[mov];
                if(gem[20-y][x]==1){
                    ++cap;
                    gem[20-y][x] = 0;
                }
            }
        }
        if(cap==N) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 3136
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count1 = 0, count2 = 0, count4 = 0;
		for(int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if(a % 4 == 0)
				count4++;
			else if(a % 2 == 0)
				count2++;
			else
				count1++;
		}
		if(count2 == 0)
			count4++;
		System.out.println(count4 >= count1 ? "Yes" : "No");
	}

}

Measured memory_bytes: 48056
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			if (H == 0) {
				sc.close();
				break;
			}
			int W = sc.nextInt();
			long L = sc.nextLong();
			int[][] dir = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };// 北、東、南、西
			char[][] maze = new char[H][];
			for (int i = 0; i < maze.length; i++) {
				maze[i] = sc.next().toCharArray();
			}

			long[][] memo = new long[10000][4];
			// <前のマス, 次のマス>
			int now = 0;
			int d = 0;// 向き N:0, E:1, S:2, W:3
			for (int i = 0; i < maze.length; i++) {
				for (int j = 0; j < maze[i].length; j++) {
					if (maze[i][j] != '#' && maze[i][j] != '.') {
						now = i * 100 + j;
						if (maze[i][j] == 'N') {
							d = 0;
						} else if (maze[i][j] == 'E') {
							d = 1;
						} else if (maze[i][j] == 'S') {
							d = 2;
						} else if (maze[i][j] == 'W') {
							d = 3;
						}
					}
				}
			}

			while (L > 0) {
				int x = now / 100;
				int y = now - x * 100;
				x += dir[d][0];
				y += dir[d][1];
				if (x < 0 || x >= H || y < 0 || y >= W || maze[x][y] == '#') {
					d = (d + 1) % 4;
					continue;
				}

				int next = x * 100 + y;
				L--;
				if (memo[next][d] == 0) {
					memo[next][d] = L;
				} else {
					long cycle = memo[next][d] - L;
					L = L % cycle;
				}

				now = next;
			}

			int x = now / 100;
			int y = now - x * 100;
			char face = '.';
			if (d == 0) {
				face = 'N';
			} else if (d == 1) {
				face = 'E';
			} else if (d == 2) {
				face = 'S';
			} else if (d == 3) {
				face = 'W';
			}

			System.out.println((x + 1) + " " + (y + 1) + " " + face);
			System.gc();
		}

	}
}

Measured memory_bytes: 33216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
class index {
        long curritems;
        long currweight;
    public index(){}
}
    class Main
    {
         static long max(long a, long b) { return (a > b)? a : b; }
        static long knapSack(int W, int wt[], long val[], int n)
        {
            int i, w;
            long K[][] = new long[n+1][W+1];

            for (i = 0; i <= n; i++)
            {
                for (w = 0; w <= W; w++)
                {
                    if (i==0 || w==0)
                        K[i][w] = 0;
                    else if (wt[i-1] <= w)
                        K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
                    else
                        K[i][w] = K[i-1][w];
                }
            }

            return K[n][W];
        }
    public static void main(String[] args)throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int number = Integer.parseInt(st.nextToken());
        long [] val = new long[number];
        int [] wts = new int[number];
        int maxweight= Integer.parseInt(st.nextToken());
        for(int i = 0;i <number;i++){
            st=new StringTokenizer(br.readLine());
            wts[i]=Integer.parseInt(st.nextToken());
            val[i]=Long.parseLong(st.nextToken());
        }

        out.println(knapSack(maxweight,wts,val,val.length));
        out.flush();
    }
}

Measured memory_bytes: 128336
#include<cstdio>
#include<algorithm>
long long a[10005];
long long b[10005];
int vis[10005];
long long ans[10005];

void preWork(int n){
    vis[1] = 1;
    for(int i = 2; i <= n; i++){
        if(!vis[i]){
            for(int j = 2*i ; j <= n; j+=i) vis[j] = 1;
        }
    }
}

int isDivide(long long p,int n){
    for(int i = n; i >= 0; i--){ 
        b[i] = a[i]%p;
    }
    //for(int i = n; i >= 0; i--) if(b[i]!=0) printf("b[%d] = %lld\n",i,b[i]);
    for(int i = n; i >= 0; i--){
        if(b[i]!=0){
            if(i<p) return 0;
            else b[i-(p-1)] = (b[i-(p-1)]+b[i])%p;
        }
    }
    return 1;
}

long long gcd(long long a,long long b){ return b?gcd(b,a%b):a; }

int main(){
    preWork(10000);
    int n;
    scanf("%d",&n);
    for(int i = n; i >= 0; i--) scanf("%lld",&a[i]);
    long long g = a[n];
    for(int i = n-1; i >= 0; i--) g = gcd(g,a[i]);
    if(g<0) g *= -1;
    int size = 0;
    for(long long i = 2; i*i <= g; i++){
        if(g==1) break;
        if(g%i==0){
            ans[++size] = i;
            while(g%i==0) g /= i;
        }
    }
    if(g!=1) ans[++size] = g;
    for(int i = 2; i <= n; i++){
        if(vis[i]) continue;
        if(isDivide(i,n)) ans[++size] = i;
        //else printf("i = %d, failed\n",i);
    }
    std::sort(ans,ans+1+size);
    int p = 1;
    while(p<=size){
        int np = p;
        while(np+1<=size && ans[np+1]==ans[p]) np++;
        printf("%lld\n",ans[p]);
        p = np+1;
    }
    return 0;
}


Measured memory_bytes: 384
#define FOR(i, a, b) for(int i=a; i<b; i++)
#include<bits/stdc++.h>
using namespace std;

bool IsPrime(int m){
    if(m<2) return false;
    if(m==2) return true;
    if(m%2==0) return false;

    double root_m = sqrt(m);

    for(int i=3; i<=root_m; i+=2){
        if(m%i==0) return false;
    }

    return true;
}

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

    int ans=0;
    FOR(i, 0, n) {
        cin >> m;
        if(IsPrime(m)) ans++;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 3136
#include <stdio.h>
main(){
  int w,n,i,x[100],a=0,b=0,tmp=0;
  scanf("%d",&w);
  for(i=0;i<w;i++){
    x[i]=i+1;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&a,&b);
    tmp=x[a-1];
    x[a-1]=x[b-1];
    x[b-1]=tmp;
  }
  for(i=0;i<w;i++){
    printf("%d\n",x[i]);
  }
  return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(Math.max(A + B, Math.max(A - B, A * B)));
    }
}


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

using namespace std;

int main()
{
 int n,coun=0,temp=0;
 cin>>n;
 int a[n];
 for(int i=0;i<n;i++)
   cin>>a[i];
sort(a,a+n);
if(n%2!=0)
    {
      cout<<0<<endl;
       return 0 ;
    }
int mid=(n-1)/2;
cout<<a[mid+1]-a[mid]<<endl;


    return 0;}

Measured memory_bytes: 640
s = input()
s_list = list(s)
# print(s_list)

sum_list = []

for i in range(len(s_list) - 2):
    sum = s[i] + s[i+1] + s[i+2]
    rnrn = abs(int(sum) - 753)
    sum_list.append(rnrn)
print(min(sum_list))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  x -= a;
  x = x % b;
  cout << x << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC006A
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b;
			string[] ss = Console.ReadLine().Split(' ');
			a = int.Parse(ss[0]);
			b = int.Parse(ss[1]);
			if (a <= b)
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
			Console.ReadKey();
		}
	}
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; 

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {

            return false;
        }
    }

    return true;
}

int main(){
    int x;
    cin >> x;
    while(1){
        if(IsPrime(x)){
            cout << x << endl;
            return 0;
        }
        x++;
    }

    return 0;
}

Measured memory_bytes: 256
import re
a = input()
a = [a[i] for i in range(len(a))]
b = "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"
b = list(b.split())
a.sort()
b.sort()
for j in range(len(b)):
    c = True
    for i in range(len(a)):
        if a[i] == b[j]:
            c = not c
            break
    if c:
        print(b[j])
        exit()
print("None")


Measured memory_bytes: 4444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <math.h>
using namespace std;

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

int main() {
	int N;
	cin >> N;
	vector<int> A;
	vector<int> sortedA;
	int tmp;
	for (int i = 0; i < N; ++i){
		cin >> tmp;
		A.push_back(tmp);
	}
	sortedA = A;
	sort(sortedA.begin(), sortedA.end(), greater<int>());
	for (int i = 0; i < N; ++i) {
		if (A.at(i) == sortedA.at(0)) {
			cout << sortedA.at(1) << endl;
		}
		else {
			cout << sortedA.at(0) << endl;
		}
	}
}

Measured memory_bytes: 3316
// ABC134-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

vector<bool> sh(200010,false);
vector<int> a(200010,0);
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    int ball=0;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=n;i>=1;i=i-1){
        int j=i;
        int baisu=0;
        while(j<=n){
            if(sh[j]) baisu++;
            j+=i;
        }
        if(baisu%2!=a[i]) sh[i]=true,ball++;
    }
    cout<<ball<<endl;
    if(ball!=0){
        for(int i=1;i<=n;i++){
            if(sh[i]) cout<<i<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define stop(n) return cout<<n,0
#define pi  acos(-1)
#define endl "\n"
#define ceil(x,y) (x+y-1)/y
//sin(x* pi / 180)
//be careful from the multiplication while using this define 
//alot of memset may couse TLE
#define TC int t;cin>>t;while(t--)
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
//</DEFINE>
ll OO = 1e18;
ll dp[3000][3000][2];
int main() {
	Fast(), File();
	int n;
	cin >> n;
	vector<int>v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	for (int i = 0; i < n; i++)dp[i][i][1] = v[i], dp[i][i][0] = -v[i];
	for (int i = 1; i < n; i++) {
		int l = 0;
		for (int r = i; r < n; r++, l++) {
			dp[l][r][0] = OO, dp[l][r][1] = -OO;
			dp[l][r][0] = min(dp[l + 1][r][1] - v[l], dp[l][r][0]);
			dp[l][r][1] = max(dp[l + 1][r][0] + v[l], dp[l][r][1]);
			dp[l][r][0] = min(dp[l][r - 1][1] - v[r], dp[l][r][0]);
			dp[l][r][1] = max(dp[l][r - 1][0] + v[r], dp[l][r][1]);
		}
	}
	cout << dp[0][n - 1][1] << endl;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }

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

int main(){
    ll n;
    cin >> n;
    ll a[n];
    rep(i,0,n) cin >> a[i];
    ll sxor[n+1] = {},ssum[n+1] = {};

    rep(i,0,n){
        sxor[i+1] = sxor[i] ^ a[i];
        ssum[i+1] = ssum[i] + a[i];
    }

    ll cnt = 0,memo = 0;
    rep(i,0,n){
        ll ok = i,ng = n;
        while(abs(ok-ng) > 1){
            ll mid = (ok+ng)/2;

            if((sxor[mid+1] ^ sxor[i]) == (ssum[mid+1] - ssum[i])){
                ok = mid;
            }
            else{
                ng = mid;
            }
        }
        cnt += ok - i + 1;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 8244
#include <bits/stdc++.h>
//abc102 B//
using namespace std;
typedef long long ll;
int main(){
    ll n,a[101];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    
    cout<<a[n-1]-a[0]<<endl;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int  a, b, c;
	cin >> a >> b >> c;
	cout << min(a + b, min(b + c, c + a))<<endl;

}


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

typedef long long ll;
typedef unsigned long long ull;

#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(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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; }

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

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  REP(i, m) cin >> a[i];
  int left = 0;
  int right = 0;
  REP(i, m){
    if (a[i] > x) right++;
    else left++;
  }
  int ans = min(left, right);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <climits>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>

using namespace std;

int main(void)
{

    int A, B;
    cin >> A >> B;

    int xmin = int(ceil(max(A / 0.08, B / 0.1)));
    double xmax = min((A + 1) / 0.08, (B + 1) / 0.1);

    int ret;
    if(xmin < xmax){
        ret = xmin;
    }else{
        ret = -1;
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var st = ReadIntArray();
            var sx = st[0];
            var sy = st[1];
            var tx = st[2];
            var ty = st[3];
            Console.WriteLine(string.Concat(new[] {
                RepeatString("U", ty - sy),
                RepeatString("R", tx - sx),
                RepeatString("D", ty - sy),
                RepeatString("L", tx - sx),
                RepeatString("L", 1),
                RepeatString("U", ty - sy + 1),
                RepeatString("R", tx - sx + 1),
                RepeatString("D", 1),
                RepeatString("R", 1),
                RepeatString("D", ty - sy + 1),
                RepeatString("L", tx - sx + 1),
                RepeatString("U", 1),
            }));
        }

        static string RepeatString(string source, int count)
        {
            return string.Concat(Enumerable.Repeat(source, count));
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define MAX_N 6500000
#define rank Asdfiasofsad
#define int long long
using namespace std;


class UF{
public:
  vector<int> par,rank;
  UF(){
    par.resize(MAX_N),rank.resize(MAX_N);
    for(int i=0;i<MAX_N;i++)par[i]=i,rank[i]=0;
  }
  UF(int n){
    par.resize(n),rank.resize(n);
    for(int i=0;i<n;i++)par[i]=i,rank[i]=0;
  }

  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

typedef pair<int,int> P;
typedef pair<int,P> PP;
vector<P> X,Y;
vector <PP> edge;
map<P,int> M;



int calc(){
  UF U;
  int res = 0;
  for(int i=0;i<edge.size();i++){
    int cost = edge[i].first;
    int a = edge[i].second.first;
    int b = edge[i].second.second;
    if(U.same(a,b)) continue;
    res += cost;
    U.unite(a,b);
  }
  return res;
}

signed main(){

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    if(M.count(P(x,y))){i--,n--;continue;}
    M[P(x,y)] = i;
    X.push_back(P(x,i));
    Y.push_back(P(y,i));
  }

  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());
  
  for(int i=0;i<n-1;i++){
    int cost = X[i+1].first - X[i].first;
    int a = X[i].second;
    int b = X[i+1].second;
    edge.push_back(PP(cost,P(a,b)));
  }


  for(int i=0;i<n-1;i++){
    int cost = Y[i+1].first - Y[i].first;
    int a = Y[i].second;
    int b = Y[i+1].second;
    edge.push_back(PP(cost,P(a,b)));
  }
  sort(edge.begin(),edge.end());
  cout<<calc()<<endl;
  return 0;
}


Measured memory_bytes: 118616