akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,s,l,r;
ll x[N],p[N],ans;
int main()
{
	scanf("%d%d",&n,&s);
	for (int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&p[i]);
	l=1;r=n;
	while (1==1)
	{
		if (x[r]<=s) {ans+=s-x[l];break;}
		if (x[l]>=s) {ans+=x[r]-s;break;}
		if (p[l]>=p[r])
		{
			ans+=x[r]-x[l];
			while (l<r&&p[l]>=p[r]) p[l]+=p[r--];//注意l<r,不能取等 
		}else {
			ans+=x[r]-x[l];
			while (l<r&&p[l]<p[r]) p[r]+=p[l++];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
import java.awt.geom.*;
import java.util.*;

import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	Main(){
		new AOJ1282();
	}
	
	class AOJ1282{
		ArrayList<Integer> sizes;
		ArrayList<HashMap<Integer, Integer>> arrays;
		HashMap<String, Integer> names;
		AOJ1282(){
			while(true){
				String str=sc.next();
				if(str.equals("."))	break;
				// init
				sizes = new ArrayList<Integer>();
				arrays = new ArrayList<HashMap<Integer, Integer>>();
				names = new HashMap<String, Integer>();
				int cnt=1, ans=0;
				
				while(!str.equals(".")){
					// solve
					if(ans<=0){
						if(str.contains("=")){
							if( !f1(str) )	ans=cnt;
						}else{
							f2(str);
						}
					}
					str=sc.next();
					++cnt;
				}
				System.out.println(ans);
			}
		}
		boolean f1(String str){
			int eq = str.indexOf("=");
			String left = str.substring(0, eq),
					right = str.substring(eq+1);
			String lname = left.substring(0,1),
					lb = left.substring(2,left.length()-1);
			int l = f3(lb);
			int r = f3(right);
			if(l<0 || r<0)	return false;
			if(l>=sizes.get(names.get(lname)))	return false;
			arrays.get(names.get(lname)).put(l, r);
			return true;
		}
		int f3(String str){
			int ret=-1;
//			System.out.println(str);
			try{
				ret = Integer.parseInt(str);
			}catch(NumberFormatException e){
				int idx = str.indexOf("[");
				String name = str.substring(0, idx),
						str2 = str.substring(idx+1,str.length()-1);
				int n=f3(str2);
				if(n<0)	return -1;
				int a = names.get(name);
				if(sizes.get(a) <= n)	return -1;
				if(!arrays.get(a).containsKey(n))	return -1;
				ret = arrays.get(a).get(n);
			}
			return ret;
		}
		void f2(String str){
			int idx = str.indexOf("[");
			String name = str.substring(0,idx);
			int size = Integer.parseInt(str.substring(idx+1, str.length()-1));
//			System.out.println(name+" "+size);
			
			names.put(name, arrays.size());
			sizes.add(size);
			arrays.add(new HashMap<Integer, Integer>());
			
		}
	}
}

Measured memory_bytes: 60116
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int N;
ll X[105];


int main(void) {
    
    scanf("%d", &N);
    rep(i, 0, N) cin >> X[i];

    ll ans = 1000000000000000;
    for (int p=0; p <= 100; p++) {
        ll s = 0;
        rep(i, 0, N) {
            s += (X[i]-p)*(X[i]-p);
        }
        ans = min(ans, s);
    }
   
    printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
import numpy as np
from collections import *
d=defaultdict(list)
n,m=map(int,input().split())

for s in range(m):
    a,b,c=map(int,input().split())
    d[a].append([b,c])
    d[b].append([a,c])
#print(d.keys())

#defaultdict(<class 'list'>, {1: [[2, 1], [3, 1]], 2: [[1, 1], [3, 3]], 3: [[1, 1], [2, 3]]})

def DIJKSTRA(point,d):
    cost      = {node:np.inf for node in d.keys()}
    preference= {node:  None for node in d.keys()}#最適路のこと 
    Q         = set(d.keys())  #頂点のリスト
    cost[point]=0  #開始地点のコストをゼロとする（当たり前
    while True:
        prefnd=min(Q, key=lambda c:cost[c]) #最適な点探し
        Q.remove(prefnd)  #最適だった点を削除
   #     del Q[prefnd]
        if len(Q)==0:
            break #全部の点消したら終了
        for pathcost in d[prefnd]:  #次の点とそこまでのコスト
            tempcost=cost[prefnd]+pathcost[1]  #スタートからそこまでのコストを計算
            if tempcost<cost[pathcost[0]]:   #計算してみたコストがそこに行くまでの最小値ならば
                cost[pathcost[0]]=tempcost #最小値更新
                preference[pathcost[0]]=prefnd
    return [tuple(sorted([k,v])) for k,v in preference.items() if v!=None]
path=[]
for s in range(1,n+1):
    path.extend(DIJKSTRA(s,d))
print(m-len(set(path)))

Measured memory_bytes: 12900
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

// int dx4[4]={1,0,-1,0};
// int dy4[4]={0,-1,0,1};
int dx4[4]={-1,1,0,0};
int dy4[4]={0,0,-1,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n;

int digit(int num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

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

  cin >> n;
  int ma;
  int s = sqrt(n);
  for(; s > 0; s--) {
    if(n % s == 0) {
      ma = n / s;
      break;
    }
  }

  cout << digit(ma) << endl;
}


Measured memory_bytes: 256
from fractions import gcd
mod=10**9+7
def pow_r(x, n):
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2%mod, n // 2)%mod
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2%mod, (n - 1) // 2)%mod
h,w,t=map(int,input().split())
H=gcd(h,t);W=gcd(w,t)
groups=H*W
unit=(h//H,w//W)
cnt=(2**(unit[0])+2**(unit[1])-3)%mod
unitd=gcd(unit[0],unit[1])
cnt+=pow_r(2,unitd)%mod
print(pow_r(cnt,groups))


Measured memory_bytes: 539660
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,c,i,cnt=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i = a;i <= b;i++){
		if(c % i ==0){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int A, B, C, X;
string s;
int main() {
	cin >> A >> B >> C >> X;
	int cnt = 0;
	for (int i = 0; i <= A; ++i) {
		if (500 * i > X) continue;
		for (int j = 0; j <= B; ++j) {
			if (500 * i + 100 * j > X) continue;
			if (0 <= (X - 500 * i - 100 * j) / 50 && (X - 500 * i - 100 * j) / 50 <= C) cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

struct Node {
	Node() {
		parent = -1;
		depth = 0;
		children_num = 0;
	}
	int parent;
	int children_num;
	vector<int> children;
	int depth;
};

void calc_depth(Node nodes[], int root) {
	for(int i = 0; i < nodes[root].children_num; i++) {
		nodes[nodes[root].children[i]].depth = nodes[root].depth+1;
		calc_depth(nodes, nodes[root].children[i]);
	}
}


int main() {
	int n;
	cin >> n;
	Node nodes[n];

	for(int i = 0; i < n; i++) {
		int id, k;
		cin >> id >> k;
		nodes[id].children_num = k;
		for(int j = 0; j < k; j++) {
			int child_id;
			cin >> child_id;
			nodes[id].children.push_back(child_id);
			nodes[child_id].parent = id;
		}
	}
	
	int find_par;
	for(find_par = 0; find_par < n; find_par++) {
		if(nodes[find_par].parent == -1) {
			break;
		}
	}

	calc_depth(nodes, find_par);


	for(int i = 0; i < n; i++) {
		if(nodes[i].parent == -1) {
			cout << "node " << i << ": parent = -1, depth = 0, root, ";
		}
		else if(nodes[i].children_num == 0) {
			cout << "node " << i << ": parent = " << nodes[i].parent << ", depth = " << nodes[i].depth << ", leaf, ";
		}
		else {
			cout << "node " << i << ": parent = " << nodes[i].parent << ", depth = " << nodes[i].depth << ", internal node, ";
		}
		cout << "[";
		for(int j = 0; j < nodes[i].children_num-1; j++) {
			cout << nodes[i].children[j] << ", ";
		}
		if(nodes[i].children_num > 0) {
			cout << nodes[i].children[nodes[i].children_num-1];
		}
		cout << "]";
		cout << endl;
	}
}



Measured memory_bytes: 7704
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	for (i = 0; i < S.length(); i++) {
		S[i] = 'x';
	}
	cout << S;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int main(){
    string a,b,ans="";
    int now=0,N;
    cin>>N>>a>>b;
    rep(i,a.size()){
        cout<<a[i];
        cout<<b[i];
    }
    out("");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
int N,A,B,C,D;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll mod_pow(ll x, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}
 
int mod_inv(int x)
{
	return mod_pow(x, MOD - 2);
}
 
int dp[2020][2020];
 
signed main() {
    IOS();
    COMinit();
    cin>>N>>A>>B>>C>>D;
    dp[A][0]=1;
    
    rep(i,A,B+1){
        rep(j,0,N+1){
            (dp[i+1][j]+=dp[i][j])%=MOD;
            int t=dp[i][j];
            rep(k,1,D+1){
                if(N<j+i*k)break;
                t*=COM(N-j-i*(k-1),i);
                t%=MOD;
                t*=mod_inv(k);
                t%=MOD;
                if(k>=C)(dp[i+1][j+i*k]+=t)%=MOD;
            }
        }
    }
    cout<<(dp[B+1][N])%MOD<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 29184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<functional>
#include<stack>
#include<deque>
#include<queue>
using namespace std;

int a[50];
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int MAX = 0, k = 0;
	for (int i = 0; i < n; i++) {
		if (MAX < a[i] || MAX < -a[i]) {
			MAX = abs(a[i]);
			k = i;
		}
	}
	cout << n * 2 - 1 << endl;
	for (int i = 0; i < n; i++) {
		cout << k + 1 << " " << i + 1 << endl;
		a[i + 1] += a[k + 1];
	}
	if (a[k] >= 0) {
		for (int i = 1; i < n; i++) {
			cout << i << " " << i + 1 << endl;
		}
	}
	else {
		for (int i = n - 1; i > 0; i--) {
			cout << i+1 << " " << i << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	while(true){
		int n,sum=0,mx=-1,mn=100000;
		cin >> n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			int s;
			cin >> s;
			mn=min(mn,s);
			mx=max(mx,s);
			sum+=s;
		}
		cout << (sum-mn-mx)/(n-2) << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, n, a;
	cin>>h>>w>>n;
	int x=0, y=0, ans[125][125];
	REP(i, n){
		cin>>a;
		while(a>0){
			if(y+a<w){
				FOR(j, y, y+a){
					ans[x][j]=i+1;
				}
				y+=a;
				break;
			}
			else{
				FOR(j, y, w){
					ans[x][j]=i+1;
				}
				a-=w-y;
				++x;
				y=0;
			}
		}
	}
	REP(i, h){
		if(i&1){
			FORR(j, 0, w){
				cout<<ans[i][j]<<" \n"[j==0];
			}
		}
		else{
			REP(j, w){
				cout<<ans[i][j]<<" \n"[j==w-1];
			}
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <iomanip>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int A, B, H, M;
double res;

int main()
{
    cin >> A >> B >> H >> M;

    res = sqrt(A * A + B * B - 2 * A * B * cos(abs((H * 30 + M * 0.5) - (M * 6)) * PI / 180));
    cout << fixed << setprecision(9) << res << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

string N;

// 和の計算
ll sum(string s) {
    ll res = 0;
    REP(i, s.length()) {
        res += s[i] - '0';
    }
    return res;
}

signed main()
{
    cin >> N;
    ll ans = sum(N);
    REP(i, N.length()) {
        string tmp = N;
        if(tmp[i] != '0') {
            tmp[i] -= 1;
            for(ll j = i+1; j < N.length(); ++j) {
                tmp[j] = '9';
            }
        }
        //DBG("tmp: %s\n", tmp.c_str());
        ans = max(ans, sum(tmp));
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

template <class Iit>
void vout(const Iit &begin,const Iit &end,ostream &out) {
    for(auto it = begin; it != end; it++) {
        auto tmp = it;
        if (++tmp == end) out << *it << '\n';
        else out << *it << " ";
    }
}

int main(void)
{
    IOS
    string s; cin >> s;
    int sl = s.size();
    vector<int> ans(sl);

    int x = 1;
    int prev = -1;
    FOR(i,1,sl) {
        if (s[i-1] != s[i]) {
            if (s[i-1] == 'R') {
                ans[i-1] += (x+1) /2;
                ans[i] += x / 2;
                prev = i;
            } else {
                ans[prev-1] += x /2;
                ans[prev] += (x+1) / 2;                
            }
            x = 0;
        }
        x++;
    }
    ans[prev-1] += x /2;
    ans[prev] += (x+1) / 2;                

    vout(ALL(ans),cout);

    return 0;
}

Measured memory_bytes: 1104
// Marcin Knapik
#include<bits/stdc++.h>

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

#include <ext/pb_ds/assoc_container.hpp> // order_of_key
#include <ext/pb_ds/tree_policy.hpp> // find by order
using namespace __gnu_pbds; 
#define ordered_set tree< int , null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ull>(a, b)(rng)
#define losuj_real(a, b) uniform_real_distribution<long double>(a, b)(rng)

typedef long double             ld;
typedef long long               ll;
typedef unsigned long long      ull;
typedef pair<ll, ll>            pll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vector<ii>>      vvii;
typedef vector< ll >            vll;
typedef vector< pll >           vpll;
 
#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second
#define rr "\e[31m "
#define bb "\e[m "

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}
 
template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> inline T russian(T a, T b, T mod) {ll res = 0; while(b){if(b&1) res = (res + a)%mod; a = (a+a)%mod; b>>=1;}return res;}
template <class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<typename T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return a; }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll N = 1e6+7;
const ll T = 1<<20;
const ll BIG_INF = 1e18 + 7;

ll n, m;

vvi G(N);

pair<ll, ll> dfs(int v, int pre = -1){
	ll ja_czarny = 1;
	ll ja_bialy = 1;

	for(auto&u:G[v]){
		if(u != pre){
			auto x = dfs(u, v);
			(ja_czarny *= x.s) %= INF;
			(ja_bialy *= (x.f + x.s)) %= INF; 
		}
	}

	return {ja_czarny, ja_bialy};
}

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

	FOR(i, n-1){
		int a, b;
		cin >> a >> b;
		G[a].pb(b);
		G[b].pb(a);
	}

	auto x = dfs(1);
	cout << (x.f + x.s) % INF << '\n';
}	


Measured memory_bytes: 33792
# -*- coding: utf-8 -*-


def warshall_floyd(dist):
    v_count = len(dist[0])

    for k in range(v_count):
        for i in range(v_count):
            for j in range(v_count):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    return dist


def main():
    h, w = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(10)]
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = 0

    results = warshall_floyd(c)

    for i in range(h):
        for j in range(w):
            if a[i][j] != -1:
                ai = a[i][j]
                ans += results[ai][1]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9584
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int[] a = new int[n-1];
		
		/*for(int i = 0; i < a.length; i++) {
			a[i] = stdIn.nextInt();
		}*/
		int[] b = new int[n];
		
		Map<Integer,Integer> map = new HashMap<>();
		
		
		for(int i = 0; i < n-1; i++) {
			int s = stdIn.nextInt();
			b[s-1]++;
		}
		
		for(int aa: b) {
			System.out.println(aa);
		}
		
		
	}

}


Measured memory_bytes: 62964
#include <bits/stdc++.h>
#define FOR(i, l, r) for(int i = l ; i<= r; ++i)
#define FORD(i, l, r) for(int i = l; i>= r; --i)
#define REP(i, l) for(int i = 0; i< (int)l; ++i)
#define REPD(i, l) for(int i = (int)l - 1; i>=0; --i)
#define fi first
#define se second
#define pb push_back
#define si size

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, ii> iiii;
template <class T> int getbit(T x,int y) {return x << (y-1) & 1;}
template <class T> T offbit(T x, int y) {return x | 1 <<(y-1);}
template <class T> T onbit(T x, int y) {return x & (~1<<(y-1));}
template <class T> T sqr(T x) {return x*x;}
const ll mod = 1e9 + 7;

int readint() { int res = 0; char ch = getchar(); bool minus = false; while(true) {if(ch == '-' || (ch >= '0' && ch <= '9')) break; ch = getchar();} if(ch == '-') minus = true; else res = ch -'0'; while(true) {ch = getchar(); if(ch < '0' || ch >'9') break;res = res * 10 + ch -'0';}if(minus) return -res;return res;}

ll a, b;

int main()
{
    //freopen(name".INP", "r", stdin);
    //freopen(name".OUT", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>a>>b;
    ll c = __gcd(a,b);
    ll d = b / c;
    if(a%b == 0) return cout<<-1, 0;
    if(d > 2) cout<<1LL*a*2;
    else {
        if(a%b == 0) cout<<-1;
        else cout<<1LL*a*3;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
class main
{
    static void Main(string[] args)
    {
        String a = Console.ReadLine();
        String b = Console.ReadLine();
        String c = Console.ReadLine();
        String d = Console.ReadLine();
        int i1, i2, i3, i4, res;
        i1 = Convert.ToInt32(a);
        i2 = Convert.ToInt32(b);
        i3 = Convert.ToInt32(c);
        i4 = Convert.ToInt32(d);
        res = 0;
        if (i1 > i2) res = i2; else res = i1;
        if (i3 > i4) res = res + i4; else res = res + i3;
        Console.Write(res);
    }
}


Measured memory_bytes: 11220
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n,a,b;
  cin >> n>>a>>b;
  
  if((b-a)%2==0) {
  cout << (b-a)/2 << endl;
  return 0;  
  }
  
  ll ka=a+(b-a-1)/2;
  ll ma=n-b+1+(b-a-1)/2;
  
  cout << min(ka,ma) << endl;
  
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a < b && b < c)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17164
#include<stdio.h>
#define MAX 500000
#define INFTY 1000000000

int count=0;
int L[MAX/2+2],R[MAX/2+2];

void merge(int A[], int n, int left,int mid, int right){  
  int i,k,j,n1,n2;
   n1=mid-left;
   n2=right-mid;
  
  for(i=0; i<n1; i++){L[i]=A[left+i];}
  for (i=0; i<n2; i++){R[i]=A[mid+i];}

  L[n1]=INFTY;
  R[n2]=INFTY;

  i=0; j=0;
  
  for(k=left;k<right;k++){
    count++;
    if (L[i]<=R[j]) {
      A[k]=L[i++];
    } else{
      A[k]=R[j++];
     
    }
  }}


void mergeSort(int A[], int n, int left, int right){
  if(left+1<right){
    int mid;
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A, n, left, mid, right);}
  }


int main(){
  int n, i;
  int A[MAX];

    scanf("%d", &n);
    for(i=0;i<n;i++)scanf("%d", &A[i]);

    mergeSort(A, n, 0, n);

    for(i=0;i<n;i++){
      if(i!=n-1)printf("%d ", A[i]);
      else if(i==n-1)printf("%d",A[i]) ;
    }
    printf("\n");
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 5624
#include <iostream>
#include<cstdio>
#include<vector>
#define inf 0x3f3f3f3f
using namespace std;

vector<int> sons[1010];
int w[1010],dp[1010];
int tmp[1010][5050];
bool ok=true;

void dfs(int x){
  int sum=0;
  for(int i=0;i<(int)sons[x].size();i++) dfs(sons[x][i]);
  if(!ok) return;//在ok已经是false的状态下，不要再进行tmp的计算了，否则会导致sum爆int，引起一系列问题，比如RE
  for(int i=0;i<(int)sons[x].size();i++){
    int son=sons[x][i];
    sum+=(w[son]+dp[son]);
    for(int j=0;j<=w[x];j++){
        tmp[i+1][j]=-inf;
        //tmp的状态转移方程
        if(j>=w[son]) tmp[i+1][j]=max(tmp[i+1][j],tmp[i][j-w[son]]+w[son]);
        if(j>=dp[son]) tmp[i+1][j]=max(tmp[i+1][j],tmp[i][j-dp[son]]+dp[son]);
    }
  }
  if(tmp[sons[x].size()][w[x]]<0) ok=false,dp[x]=inf;
  else dp[x]=sum-tmp[sons[x].size()][w[x]];
}

int main()
{
    int n;scanf("%d",&n);
    for(int i=2;i<=n;i++){
        int p;scanf("%d",&p);
        sons[p].push_back(i);
    }
    for(int i=1;i<=n;i++) scanf("%d",&w[i]);
    dfs(1);
    if(ok) printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 17408
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    long A = sc.nextLong();
    long B = sc.nextLong();
    long[] X = sc.nextLongList(N);
    
    long ret = 0;
    for (int i = 1; i < N; i ++) {
      long x = (X[i] - X[i - 1]) * A;
      ret += Math.min(x, B);
    }
    System.out.println(ret);
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Measured memory_bytes: 10644
n,T=map(int, input().split())
c_l =[]
t_l=[]
for i in range(n):
    c,t=map(int,input().split())
    if t<=T:
        c_l.append(c)
        t_l.append(t)

if c_l == []:
    print("TLE")
else:
    print(min(c_l))

Measured memory_bytes: 3060
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
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); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  string s;
  cin>>s;
  int n=s.size();
  for(int i=n;i > 0;){
    n-=2;
    if(s.substr(0,n/2)==s.substr(n/2,n/2)){
      cout<<n<<endl;
      return 0;
    }
  }

}


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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    void solve(){
        long long n;
        cin>>n;
        --n;
        long long ans=(n*(n+1))/2;
        cout<<ans;
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3588
fun main() {
    val (h, w, m) = readInts()

    val cols = IntArray(h + 1)
    val rows = IntArray(w + 1)
    val occurrences = mutableSetOf<Pair<Int, Int>>()
    repeat(m) {
        val (x, y) = readInts()
        cols[x]++
        rows[y]++
        occurrences.add(Pair(x, y))
    }

    val maxCol = cols.max()!!
    val maxRow = rows.max()!!

    val maxColumns = cols.mapIndexed { index, value -> Pair(index, value) }.filter { pair -> pair.second == maxCol }.map { it.first }
    val maxRows = rows.mapIndexed { index, value -> Pair(index, value) }.filter { pair -> pair.second == maxRow }.map { it.first }

    val colSet = maxColumns.toMutableSet()
    val rowSet = maxRows.toMutableSet()

    var allPairs = colSet.size * rowSet.size
    occurrences.forEach { pair ->
        if (colSet.contains(pair.first) && rowSet.contains(pair.second)) allPairs--
    }

    if (allPairs == 0) println(maxCol + maxRow - 1)
    else println(maxCol + maxRow)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 182324
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
   
#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod1 = (int)1e9 + 7;
const int mod2 = (int)1e9 + 9;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, p1 = 239, p2 = 241, h1[N], ans, H1[5005][5005], h2[N], H2[5005][5005];
char s[N];
map <pii, int> q;

inline int mult (int a, int b, int mod) {
   return 1ll * a * b % mod;
}

inline int add (int a, int b, int mod) {
   a += b;
   if (a >= mod) a -= mod;
   return a;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> s + 1;
   for (int l = 1; l <= n; l ++) {
      int pw1 = 1, pw2 = 1;
      for (int r = l; r <= n; r ++) {
         H1[l][r] = add (H1[l][r - 1], mult (s[r], pw1, mod1), mod1);
         H2[l][r] = add (H2[l][r - 1], mult (s[r], pw2, mod2), mod2);
         pw1 = mult (pw1, p1, mod1);
         pw2 = mult (pw2, p2, mod2);
      }
   }
   for (int len = 1; len <= n; len ++) {
      q.clear ();
      fill (h1 + 1, h1 + n + 1, 0);
      fill (h2 + 1, h2 + n + 1, 0);
      for (int i = 1; i + len - 1 <= n; i ++) h1[i] = H1[i][i + len - 1], h2[i] = H2[i][i + len - 1];
      for (int i = n; i >= 1; i --) {
         if (i + len + len - 1 <= n) q[{h1[i + len], h2[i + len]}] ++;
         if (q.count ({h1[i], h2[i]})) ans = len;     
      }
   }
   cout << ans;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 196992
import itertools
def main():

    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))

    a = list(itertools.permutations([i for i in range(1, N+1)]))
    k, l = 0, 0
    for i in range(len(a)):
        if list(a[i]) == P: k = i
        if list(a[i]) == Q: l = i
    return abs(k-l)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 46704
#include <stdio.h>

int main(void){
    int N,W;
    int i,j,max=0;
    int date[101][2]={};//date[N+1[2]
    int table[101][10001]={};//table[N+1][W+1]
    scanf("%d %d",&N,&W);
    for(i=1;i<N+1;i++){
        scanf("%d",&date[i][0]);
        scanf("%d",&date[i][1]);//1~N?????????????????????????´?(Vn,Wn)
    }
    
    for(i=1;i<N+1;i++){
       // use = 0;//????????????????????¨?????¢??????
        for(j=1;j<W+1;j++){
            if(date[i][1] > j){
                table[i][j] = table[i-1][j];
            }else{//?????¨????????????????????§???????????????????????¨??£??\
                if(table[i-1][j] >= table[i-1][j - date[i][1]] + date[i][0]){
                    table[i][j] = table[i-1][j];
                }else{
                    table[i][j] = table[i-1][j - date[i][1]] + date[i][0];
                }
                /*
                if(use){
                    if(table[i-1][j] >= table[i][j-1]){
                        table[i][j] = table[i-1][j];
                        use = 0;
                    }else{
                        table[i][j] = table[i-1][j-1];
                    }
                }else{
                    if(table[i][j-1] >= table[i-1][j - date[i][1]] + date[i][0]){
                        table[i][j] = table[i][j-1];
                    }else{
                        table[i][j] = table[i-1][j - date[i][1]] + date[i][0];
                        use = 1;
                    }
                }*/
                /*
                if(table[i-1][j] > table[i][j - date[i][1]] + date[i][0]){//?????¨?¨???§????????§????????¨???
                    table[i][j] = table[i-1][j];
                    use = 0;
                }else{
                    if(!(use)){
                        table[i][j] = table[i][j - date[i][1]] + date[i][0];
                        use = 1;
                    }else{
                        table[i][j] = table[i][j - date[i][1]];
                    }
                }
                 */
            }
          //  printf("%d",table[i][j]);
        }
      //  printf("\n");
        if(max < table[i][W])
            max = table[i][W];
    }
    
    printf("%d\n",max);
    return 0;
}

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

using namespace std;

class Solution {
public:
	void solve() {
		long long x;
		cin >> x;

		for (long long a = -1000; a <= 1000; a++) {
			for (long long b = -1000; b < a; b++) {
				if (a * a * a * a * a - b * b * b * b * b == x) {
					cout << a << " " << b << "\n";
					return;
				}
			}
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int x = sc.NextInt();
        int y = sc.NextInt();
        int z = sc.NextInt();

        string answer = z + " " + x + " " + y;

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const int maxn=200000+5;
long long n,a[maxn],p[maxn],sum[maxn];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	//	sum[i]=sum[i-1]+a[i];
	//	p[i]=p[i-1]^a[i];
	}
	long long opt2=0,sum1=0,sum2=0;long long ans=0;
	for(int i=1;i<=n;i++)
	{
		long long opt1=i;
		while(opt2<n&&(sum1+a[opt2+1])==(sum2^a[opt2+1]))
		{
			opt2++;
			sum1+=a[opt2];
			sum2^=a[opt2];
		}
		long long tot=opt2-opt1+1;
		sum1-=a[opt1];
		sum2^=a[opt1];
		ans+=tot;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2944
var n,m,s,t,i,j:Longint;a,b:array of string;
begin
	readln(n);
	setlength(a,n+1);
	for i:=1 to n do begin
		readln(a[i]);
	end;
	readln(m);
	SetLength(b,m+1);
	for i:=1 to m do begin
		readln(b[i]);
	end;
	s:=0;
	for i:=1 to n do begin
		t:=0;
		for j:=1 to n do begin
			if a[i]=a[j] then t:=t+1;
		end;
		for j:=1 to m do begin
			if a[i]=b[j] then t:=t-1;
		end;
		if s<t then s:=t;
	end;
	write(s)
end.


Measured memory_bytes: 128
## coding: UTF-8


N, W = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N)]

for i in range(N):
    for j in range(W+1):
        if(j >= l[i][0]):
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-l[i][0]] + l[i][1])
        else:
            dp[i][j] = dp[i-1][j]
#for k in range(N):
    #print(dp[k])
print(dp[-1][-1])

Measured memory_bytes: 120044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int N, K, x[110], ans = 0;

  cin >> N >> K;
  for(int i = 0; i < N; i++) cin >> x[i];

  for(int i = 0; i < N; i++){
    if(x[i] < K - x[i]) ans += x[i] * 2;
    else ans += (K - x[i]) * 2;
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
import math

n = int(input())
a = list(map(int, input().split()))
flg = 0
b = []
for i in range(n):
    if a[i] % 2 == 0:
        b.append(a[i])
for i in range(len(b)):
    if b[i] <= 2:
        flg = 1
    elif b[i] % 3 != 0 and b[i] % 5 != 0:
        flg = 1
if flg == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long k;
	cin>>k;
	char same='~';
	int sum=0;
	long long ans=0;
	int pd=1;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==same)
		{
			sum++;
			if(i==s.size()-1)
			{
				ans+=sum/2;
			}
			pd++;
		}
		else
		{
			ans+=sum/2;
			sum=1;
			same=s[i];
		}
	}
	if(pd==s.size())
	{
		long long h;
		h=pd*k/2;
		cout<<h;
		return 0;
	}
	same=s[0];
	int first=1;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==same)
		{
			first++;
		}
		else
		{
			break;
		}
	}
	same=s[s.size()-1];
	int last=1;
	for(int i=s.size()-2;i>=0;i--)
	{
		if(s[i]==same)
		{
			last++;
		}
		else
		{
			break;
		}
	}
	ans*=k;
	if(s[0]==s[s.size()-1]&&(first+last)%2==0&&k>1&&(first%2!=0||last%2!=0))
	{
		ans+=k-1;
	}
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    sum += a;
  }
  puts(sum < h ? "No" : "Yes");
}


Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
ans=10**18 #最小値を求めるので初期化しておく
for i in range(1,101): #1<=P<=100の範囲について消費する体力の総和を計算
 tmp=0
 for num in arr:
   tmp+=(i-num)**2
 ans=min(ans,tmp) #消費する体力の総和の最小値が答えとなる
print(ans)

Measured memory_bytes: 9008
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                sc.close();
                int[] a = new int[3];
                int pct = 100000;
                for(int i = 0 ; i < s.length() - 2 ; i++){
                        a[0] = (int)s.charAt(i) - 48;
                        a[1] = (int)s.charAt(i + 1) - 48;
                        a[2] = (int)s.charAt(i + 2) - 48;
                        int yono = 100 * a[0] + 10 * a[1] + a[2];
                        pct = Math.min(pct , Math.abs(yono - 753));
                }
                System.out.println(pct);
        }
}//0=48
//鶏になれ

Measured memory_bytes: 35224
#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;}

//BEGIN CUT HERE
template<typename T, typename F>
struct RangeSlide{
  vector<size_t> ls,rs;
  vector<T> vs;
  F cmp;
  RangeSlide(vector<T> vs,F cmp):vs(vs),cmp(cmp){}

  void add_range(size_t l,size_t r){
    ls.emplace_back(l);
    rs.emplace_back(r);
  }
  
  vector<size_t> build(){
    deque<size_t> deq;
    vector<size_t> res;
    for(size_t i=0,l=0,r=0;i<ls.size();i++){
      if(r<=ls[i]){
        deq.clear();
        l=r=ls[i];
      }
      while(r<rs[i]){
        while(!deq.empty()&&!cmp(vs[deq.back()],vs[r])) deq.pop_back();
        deq.emplace_back(r++);
      }
      while(l<ls[i]){
        if(deq.front()==l++) deq.pop_front();
      }
      res.emplace_back(deq.front());
    }
    return res;
  }
};
//END CUT HERE

template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }  
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed AOJ_0613(){
  Int n,d;
  cin>>n>>d;
  vector<Int> xs(n),ys(n);
  for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i];
  if(n==1){
    cout<<(xs[0]<=d?ys[0]:0)<<endl;
    return 0;
  }
  
  Int h=n/2;
  using P = pair<Int, Int>;
  auto calc=
    [&](Int a,Int b){
      vector<P> res;
      MFP([&](auto dfs,Int k,Int s,Int t)->void{
            if(k==b){
              res.emplace_back(s,t);
              return;
            }
            dfs(k+1,s,t);
            dfs(k+1,s+xs[k],t+ys[k]);
            dfs(k+1,s-xs[k],t-ys[k]);
          })(a,0,0);
      sort(res.begin(),res.end());
      return res;
    };  
  auto v1=calc(0,h);
  auto v2=calc(h,n);
  reverse(v2.begin(),v2.end());
  
  const Int INF = 1e17;
  vector<Int> vs;
  for(auto p:v1) vs.emplace_back(p.first);
  vs.emplace_back(-INF);
  vs.emplace_back(+INF);
  vs=compress(vs);

  vector<Int> ws(vs.size(),-INF);
  {
    Int k=0;
    for(auto p:v1){
      while(vs[k]<p.first) k++;
      chmax(ws[k],p.second);
    }
  }
  v1.clear();
  
  auto cmp=[](Int a,Int b){return a>b;};
  RangeSlide<Int, decltype(cmp)> slide(ws,cmp);  
  vector<Int> ks;

  {
    Int l=0,r=0;
    for(auto p:v2){
      Int x=p.first,k=p.second;
      while(l<(Int)vs.size()&&vs[l]< -x-d) l++;
      while(r<(Int)vs.size()&&vs[r]<=-x+d) r++;
      if(l==r) continue;
      slide.add_range(l,r);
      ks.emplace_back(k);
    }
  }
  vs.clear();
  v2.clear();
  
  auto res=slide.build();
  
  Int ans=0;
  for(Int i=0;i<(Int)res.size();i++) chmax(ans,ws[res[i]]+ks[i]);
  cout<<ans<<endl;
  return 0;
}

signed main(){
  AOJ_0613();
  return 0;
}



Measured memory_bytes: 899516