akhauriyash/Code-Regression huggingface dataset:
/** omgursocute **/
#include <bits/stdc++.h>

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	int n;
	cin >> n;
	map<string, int> mp;
	
	while(n--) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		++mp[s];
	}

	ll res = 0;
	for(auto p: mp) {
		int app = p.second;
		res += 1ll*app*(app-1) >> 1;
	}

	cout << res;

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

	ll n,m; cin >> n >> m;

	vector<string> s(n); rep(i,n) cin >> s[i];

	mf_graph<ll> graph(n*m+2);
	ll _s = n * m, _t = n * m + 1;
	rep(i, n) rep(j, m) {
	  if (s[i][j] == '#') continue;
		if ((i+j) % 2 == 0) { 
		  graph.add_edge(_s, i * m + j, 1);
			if (j + 1 < m && s[i][j + 1] == '.') graph.add_edge(i * m + j, i * m + (j + 1), 1);
			if (i + 1 < n && s[i + 1][j] == '.') graph.add_edge(i * m + j, (i + 1) * m + j, 1);
			if (j - 1 >= 0 && s[i][j - 1] == '.') graph.add_edge(i * m + j, i * m + (j - 1), 1);
			if (i - 1 >= 0 && s[i - 1][j] == '.') graph.add_edge(i * m + j, (i - 1) * m + j, 1);
		}
		else graph.add_edge(i * m + j, _t, 1);
	}

	ll ans = graph.flow(_s,_t);

	for (auto e : graph.edges()) {
    //cerr << e.from << " " << e.to << " " << e.cap << " " << e.flow << endl;
	  if (e.from == _s || e.to == _t || e.flow == 0) continue;
		if (e.to - e.from == m) {
			s[e.from / m][e.from % m] = 'v';
			s[e.to / m][e.to % m] = '^';
		}
		else if (e.to - e.from == -m) {
			s[e.from / m][e.from % m] = '^';
			s[e.to / m][e.to % m] = 'v';
		}
		else if (e.to - e.from == 1) { 
		  s[e.from/m][e.from%m] = '>';
			s[e.to/m][e.to%m] = '<';
		}
  	else if (e.to - e.from == -1) {
			s[e.from / m][e.from % m] = '<';
			s[e.to / m][e.to % m] = '>';
		}
	}

	cout << ans << endl;
	rep(i, n) { rep(j, m) {
		cout << s[i][j];
	} cout << endl; }


}



Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll sum = -n*(n+1)/2;
  rep(i, n) {
    sum += a[i];
  }
  cout << sum << endl;
}



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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a));

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const long double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;


const int MAX = 100005;

priority_queue<int> toR;
int c;

int a[MAX];
VI p;
int n;
LL ans[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);cin.tie(0);

	cin>>n;

	FOR(i,0,n)
	{
		cin>>a[i];
	}

	int mx = 0;
	FOR(i,0,n)
	{
		if(a[i]>mx)
		{
			mx = a[i];
			p.PB(i);
		}
	}


	int ptr = n-1;
	RFOR(i,SZ(p),0)
	{
		while(ptr>=p[i])toR.push(a[ptr--]);

		int x = a[p[i]];
		int pr = 0;
		if(i)pr = a[p[i-1]];
		LL cnt = c*1ll*(x-pr);

//		cerr<<i<<" "<<p[i]<<" "<<cnt<<endl;

		while(toR.size() && toR.top()>pr)
		{
			cnt += toR.top()-pr;
			toR.pop();
			c++;
		}

		ans[p[i]] = cnt;
	}


	FOR(i,0,n)cout<<ans[i]<<"\n";
}



Measured memory_bytes: 2808
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      x: u64,
      y: u64,
    }
    let mut i = x;
    let mut ans = 0;
    loop {
        ans += 1;
        if i > y/2 {
            break;
        }
        i = i * 2;
    }
    println!("{}", ans);
}


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

int main() {
  string  S;
  
  cin >> S ;
  int N = S.size();
  if(N == 3){
    if(S.at(0) == S.at(2)){
      cout<<"Yes"<<endl;
    }
    else {
      cout<<"No"<<endl;
    }
  }
  else{
  for (int i=0; i<N/2; i++){
    char A = S.at(i);
    char B = S.at(N-1-i);
    if(A != B){
      cout << "No"<<endl;
      break;
    }
    char C = S.at(N/2-i-1);

    if(A != C){
      cout <<"No"<<endl;
      break;
    }
    char D = S.at(N/2+1+i);
    char E = S.at(N-i-1);
    if(D != E){
      cout <<"No"<<endl;
      break;
    }
    if(i == (N/2)-1){
    cout <<"Yes"<<endl;
    }
  }
  }
}


Measured memory_bytes: 256
///******* In the name of Allah *******///

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a;
    double aa,bb;
    scanf("%d",&a);
    aa = a;
    bb = 2 * 3.1416 * aa;
    printf("%0.2lf",bb);

    return 0;
}


Measured memory_bytes: 3776
#include<stdio.h>
#include<algorithm>
using namespace std;
   int n;
   int a[100005];
   int main()
   {
   while(scanf("%d",&n)!=EOF)
      {
      for(int i=0;i<n;i++)
	     {
	     scanf("%d",&a[i]);
	     }	
	  sort(a,a+n);
	  int sum=a[n/2]-a[n/2-1];
	  printf("%d\n",sum);   
      }	
   return 0;   
   }

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

long long int sum=0;
string s;

long long int s_to_i(string s){
    long long int res=0;
    for(int i=0; i<s.size(); i++){
        res+=(s[i]-'0')*pow(10,(int)s.size()-i-1);
    }
    return res;
}

void dfs(int i,int j){
    if(j==s.size()){
        sum+=s_to_i(s.substr(i,j-i));
        //cout<<i<<' '<<j<<' '<<stoi(s.substr(i,j-i))<<endl;
        return;
    }
    sum+=s_to_i(s.substr(i,j-i))*pow(2,(int)s.size()-j-1);
    dfs(i,j+1);
    dfs(j,j+1);
    //cout<<i<<' '<<j<<' '<<stoi(s.substr(i,j-i))<<endl;
}

int main(){
    cin>>s;
    dfs(0,1);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
 
int par[100001];
int sib[100001];
int deg[100001];
int n;
 
int depth(int);
int height(int);
 
int main(int argc,char *argv[]) {
  int i,j;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    par[i] = -1;
    sib[i] = -1;
    deg[i] = 0;
  }
  for(i = 0; i < n; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      par[left] = id;
      sib[left] = right;
      deg[id]++;
    }
    if(right != -1) {
      par[right] = id;
      sib[right] = left;
      deg[id]++;
    }
  }
 
  for(i = 0; i < n; ++i) {
    int dep = depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, par[i], sib[i], deg[i], dep, height(i));
    if(dep == 0) {
      printf("root\n");
    } else if(deg[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}

int depth(int i) {
  if(par[i] == -1) return 0;
  return depth(par[i]) + 1;
}
 
int height(int i) {
  int j, h = 0;;

  for(j = 0; j < n; ++j) {
    if(par[j] == i) {
      int tmp = height(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}
 

Measured memory_bytes: 620
n = int(input())
s = list(str(input()))
alf = [chr(i) for i in range(65, 65+26)]*2

for k in range(len(s)):
    for l in range(26):
        if s[k] == alf[l]:
            s[k] = alf[l + n]
            break
s = "".join(s)
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        string cur = to_string(i);
        int sum = 0;
        for (auto x : cur) sum += x - '0';
        if (sum >= a && sum <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';

export function Main(input: string) {
    const [s, w] = input.split(' ').map(int => parseInt(int));  // ?

    let result = w >= s ? 'unsafe' : 'safe';

    //output

    console.log(result);
    return result;
}

// Don't edit this line!
Main(fs.readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29628
N = int(input())

lst  = []
l_append = lst.append
ans = 0
for i in range(N):
    A, B = map(int, input().split())
    l_append(A + B)
    ans -= B

lst.sort(reverse = True)

for i in range(N):
    if i % 2 == 0:
        ans += lst[i]
    else:
        pass

print (ans)


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

  
int main(){
  double l;
  cin >> l;
  double s;
  s=l/3.000000;
  cout << fixed <<setprecision(8);
   cout << s*s*s << endl;
}
 

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

int main() {
  long long n;
  string ans;

  cin >> n;

  long long r;
  while(n) {
    r=n%26;
    if(r==0) {
      ans+='z';
      n--;
    } else
      ans+=(char)('a'+n%26-1);
    n/=26;
  }

  reverse(ans.begin(),ans.end());

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3620
// ABC047B - すぬけ君の塗り絵 2 イージー

#include <bits/stdc++.h>
using namespace std;

int main() {
	int W, H, N;
	cin >> W >> H >> N;

	int minX = 0;
	int maxX = W;
	int minY = 0;
	int maxY = H;

	for (int i = 0; i < N; i++) {
		int x, y, a;
		cin >> x >> y >> a;
		switch (a) {
		case 1:
			minX = max(minX, x);
			break;
		case 2:
			maxX = min(maxX, x);
			break;
		case 3:
			minY = max(minY, y);
			break;
		case 4:
			maxY = min(maxY, y);
			break;
		default:
			break;
		}
	}

	int ans;
	if ((maxY <= minY)||(maxX <= minX)) {
		ans = 0;
	} else {
		ans = (maxY - minY)*(maxX - minX);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	final int INF = Integer.MAX_VALUE;

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();

		boolean[][] g = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			int u = scan.nextInt();
			int k = scan.nextInt();
			for (int j = 0; j < k; j++) {
				int v = scan.nextInt();
				g[u - 1][v - 1] = true;
			}
		}

		int time = 0;
		int[] d = new int[n];
		boolean[] isSearched = new boolean[n];
		Queue<Integer> que = new LinkedList<Integer>();

		for (int i = 0; i < n; i++)
			d[i] = INF;
		que.add(0);
		while (!que.isEmpty()) {
			int length = que.size();
			for (int i = 0; i < length; i++) {
				int id = que.poll();
				if (isSearched[id])
					continue;
				d[id] = Math.min(d[id], time);
				for (int j = 0; j < n; j++)
					if (g[id][j])
						que.add(j);
				isSearched[id] = true;
			}
			time++;
		}
		for (int i = 0; i < n; i++)
			System.out.println((i + 1) + " " + (isSearched[i] ? d[i] : -1));
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 28012
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	string str; cin >> str;
	if (str.length() == 2)
		cout << str;
	else
	{
		reverse(str.begin(), str.end());
		cout << str << endl;
	}

	return 0;
}

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
        for (int i = Math.min(a, b);; i--) if (a % i == 0 && b % i == 0) {
            k--;
            if (k == 0) {
                System.out.println(i);
                break;
            }

        }
    }

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

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23764
#include <stdio.h>

int main(void)
{
    int H;     /*???????????????*/
	int W;     /*?¨??????????*/
	int a;     /*??°???????????¨?????°*/
	int b;     /*??°???????????¨?????°*/
	int c;     /*??°???????????¨?????°*/
	int d;     /*??°???????????¨?????°*/
	int e;     /*??°???????????¨?????°*/
	int f;     /*??°???????????¨?????°*/
	int g;     /*??°???????????¨?????°*/
	int h;     /*??°???????????¨?????°*/
	int i;     /*??°???????????¨?????°*/
	int j;     /*??°???????????¨?????°*/
	int k;     /*??°???????????¨?????°*/
	int l;     /*??°???????????¨?????°*/
	int m;     /*??°???????????¨?????°*/
	int n;     /*??°???????????¨?????°*/
	int o;     /*??°???????????¨?????°*/
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			break;
		}
		else if((H % 2) == 1 && (W % 2) == 1){
			for (a = 1; a <= (H / 2); a++){
				for (b = 1; b <= (W / 2); b++){
					printf("#.");
					}
					
				printf("#");
				printf("\n");
				for (c = 1; c <= (W / 2); c++){
					printf(".#");
				}
				printf(".");
				printf("\n");
		}
				
				for (d = 1; d <= (W / 2); d++){
					printf("#.");
				}
				printf("#");
				printf("\n");
				printf("\n");
			}
	   
	   else if((H % 2) == 0 && (W % 2) == 1){
			for (h = 1; h <= (H / 2); h++){
				for (e = 1; e <= (W / 2); e++){
				printf("#.");
			}
			printf("#");
			printf("\n");
			for (f = 1; f <= (W / 2); f++){
				printf(".#");
				
			}
			printf(".");
			printf("\n");
			
			}
			
			printf("\n");
			
	   }
	else if((H % 2) == 1 && (W % 2) == 0){
		for(k = 1; k <= (H / 2); k++){
			for (g = 1; g <= (W/ 2); g++){
			printf("#.");
		}
		printf("\n");
		for (i = 1; i <= (W / 2); i++){
			printf(".#");
		  }
		  printf("\n");
		}
		
		for (j = 1; j <= (W / 2); j++){
			printf("#.");
			}
			printf("\n");
			printf("\n");
			
			
	
	}
		
    else if((H % 2) == 0 && (W % 2) == 0){
		for (n = 1; n <= (H / 2); n++){
			for (l = 1; l <= (W / 2); l++){
			printf("#.");
		}
		printf("\n");
		for (m = 1; m <= (W / 2); m++){
			printf(".#");
		}
		printf("\n");
		
		}
		printf("\n");
	
      }
	}
	
	
	
	return (0);
}

Measured memory_bytes: 588
fun main(args: Array<String>) {
    var (count) = readLine()!!.split(" ").map { it.toInt() }
    val values = readLine()!!.split(" ").map { it.toInt() }
    val costs = readLine()!!.split(" ").map { it.toInt() }

    val diffs: MutableList<Int> = java.util.ArrayList()

    for (index in 0 until count) {
        diffs.add(values[index] - costs[index])
    }

    diffs.sort()
    val diffMax = diffs.filter { it > 0 }.asReversed()

    if (diffMax.size < count) count = diffMax.size

    val res = diffMax.subList(0, count).sum()

    print(res)
}


Measured memory_bytes: 36136
#include <stdio.h>

int main() {
    int n, k;
    scanf("%d%d", &n,&k);
    int ans = 1;
    for (int i=0; i<n; i++){
        if (ans*2 < ans+k){
            ans*=2;
        }
        else{
            ans+=k;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
vector<char> v;
int main() {
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin>>n;
	while(n) {
	    v.push_back((n-1)%26+'a');
		n=(n-1)/26;	
	}
	reverse(v.begin(),v.end());
	for(int i=0; i<v.size(); i++)
		cout<<v[i];
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9

int a[100000];
int b[100000];
p num[100000];
int N;

void input() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
		num[i].first = a[i] + b[i];
		num[i].second = i; // k番目に取るべき料理の番号
	}
}

void solve() {
	sort(num, num + N, greater<pair<int, int>>());
	ll sum1,sum2;
	sum1 = 0;
	sum2 = 0;
	for (int i = 0; i < N; i += 2) {
		sum1 += a[num[i].second];
	}
	for (int i = 1; i < N; i += 2) {
		sum2 += b[num[i].second];
	}
	cout << sum1 - sum2 << endl;
}

int main() {
	input();
	solve();

	return 0;
}

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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
template<class T> void out(T a){cout<<a<<'\n';}

int main(){
  int n,q;
  cin>>n>>q;
  dsu d(n);
  rep(i,q){
  	int k,u,v;
  	cin>>k>>u>>v;
  	if(k==0) d.merge(u,v);
  	else out(d.same(u,v));
  }
}


Measured memory_bytes: 3856
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 2e5+5


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

        int n,k;
        cin >> n >> k;
        int i,a[n];
        for(i=0; i<n; i++) cin >> a[i];
        sort(a,a+n);
        int s=0;
        for(i=0; i<(n-k); i++){
            s=s+a[i];
        }
        cout << s << '\n';
        
        

}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	int a,b;
	cin >> a >> b;
	if(a==b) cout << "a == b" << endl;
	else if (a<b) cout << "a < b" << endl;
	else cout << "a > b" << endl;
}

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

int main() {
 int a, b;
  cin >> a >> b;
  if (a%2 == 0 || b%2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
 
    
 return 0;
}


Measured memory_bytes: 3636
N=int(input())
A=list(map(int,input().split()))

SUM=[0]
for a in A:
    SUM.append(SUM[-1]+a)
    
i=1
j=2
k=3
P=SUM[i]
Q=SUM[j]-SUM[i]
R=SUM[k]-SUM[j]
S=SUM[N]-SUM[k]
ANS=10**10
check=1

while j<N-1:
    check=1
    while check==1:
        check=0
        if i<j-1:
            if abs(P-Q)>abs(P+A[i]-Q+A[i]):
                P+=A[i]
                Q-=A[i]
                i+=1
                check=1
        if k<N-1:

            if abs(R-S)>abs(R+A[k]-S+A[k]):
                R+=A[k]
                S-=A[k]
                k+=1
                check=1

    #print(P,Q,R,S,i,j,k)
    
    if ANS>max([P,Q,R,S])-min([P,Q,R,S]):
        ANS=max([P,Q,R,S])-min([P,Q,R,S])

    
    Q+=A[j]
    R-=A[j]
    j+=1

print(ANS)

Measured memory_bytes: 25672
#ifndef KHOKHO
//#pragma GCC optimize("O3")
#endif
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define ARRS int(1e6+500)
#define MAX ((long long)(1e18+1))
#define EP ((double)(1e-12))
#define HS1 ((ll)(1000001329))
#define HS2 ((ll)(1000001531))
#define MOD ((long long)1000000007ll)
#define AT9 ((long long)1000000000ll)
#define PI 3.14159265358979323846264338327950288419716939937510
#define LG 20

ll a[2];

int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w+",stdout);
	#endif //KHOKHO
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	n--;
	ll x;
	x=abs(a-b);
    ll l,r;
    for(int i=0; i<=n; i++){
		l=i*c-(n-i)*d;
		r=i*d-(n-i)*c;
		if(l<=x&&x<=r){
			cout<<"YES";
			return 0;
		}
    }
    cout<<"NO";

	return 0;
}


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

map<pair<int,int>,int> mp;
vector<pair<int,int> > v[4];
stack<pair<int,int> > st;

void solve(int j,int l,int r,int t){
	if(t==1){
		for(int i=l;i<=r;i++){
			if(!st.empty()){
				pair<int,int> x = st.top();
				if(mp[x] == mp[v[j][i]]){st.pop();}
				else{st.push(v[j][i]);}
			}else{
				st.push(v[j][i]);
			}
		}
	}else{
		for(int i=l;i>=r;i--){
			if(!st.empty()){
				pair<int,int> x = st.top();
				if(mp[x] == mp[v[j][i]]){st.pop();}
				else{st.push(v[j][i]);}
			}else{
				st.push(v[j][i]);
			}
		}
	}
}

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

	int r,c,n;
	cin>>r>>c>>n;	
	int val=0;

	for(int i=0;i<n;i++){
		int x,y;cin>>x>>y;
		int a,b;cin>>a>>b;

		if(((x==0)||(x==r)||(y==0)||(y==c))&&((a==0)||(a==r)||(b==0)||(b==c))){
			val++;
			if(x==0){v[0].push_back(make_pair(x,y));}
			else if(y==c){v[1].push_back(make_pair(x,y));}
			else if(x==r){v[2].push_back(make_pair(x,y));}
			else{v[3].push_back(make_pair(x,y));}

			if(a==0){v[0].push_back(make_pair(a,b));}
			else if(b==c){v[1].push_back(make_pair(a,b));}
			else if(a==r){v[2].push_back(make_pair(a,b));}
			else{v[3].push_back(make_pair(a,b));}
			mp[make_pair(x,y)] = mp[make_pair(a,b)] = val;
		}
	}

	for(int i=0;i<4;i++){
		sort(v[i].begin(),v[i].end());
	}

	solve(0,0,(int)v[0].size()-1,1);
	solve(1,0,(int)v[1].size()-1,1);
	solve(2,(int)v[2].size()-1,0,-1);
	solve(3,(int)v[3].size()-1,0,-1);

	if(!st.empty()){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
}

Measured memory_bytes: 15080
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            if (a % 2 == 0 || b % 2 == 0) out.println("No");
            else out.println("Yes");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        private int pread() {
            if (pnumChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= pnumChars) {
                curChar = 0;
                try {
                    pnumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (pnumChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = pread();
            while (isSpaceChar(c))
                c = pread();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = pread();
            }
            int res = 0;
            do {
                if (c == ',') {
                    c = pread();
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = pread();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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

int main() {
  ll m,n;
  cin >> m >> n;
  if(2*m>=n) {
    cout << n/2 << endl;
  }
  else {
    n=n-2*m;
    cout << n/4+m << endl;
  }
}

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

int main() {
	int n,k,x,i,j,ans=0,cur=0,res=0;
	cin >> k >> x;
	for(i=-k+1; i<0; i++){
		cout << x+i << ' ';
	}
	cout << x << ' ';
	for(i=1; i<k; i++){
		cout << x+i << ' ';
	}
	return 0;
}

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

int main(){
    int ans=0;
    int n;
    cin >> n;

    int p=(n/2)-1,q=(n/2);

    int data[n];
    
    for (int i = 0; i < n; i++){
        cin >> data[i];
    }
    
    sort(data,data+n);

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << data[q]-data[p] << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

const int MAXN = 50;
typedef long long LL;
char buf[MAXN];
int A[MAXN][MAXN];
LL f[MAXN][MAXN][MAXN];
int n;
LL calc(int l, int r, int s) {
	if (l >= s && r <= s) return 1;
	LL & dp = f[l][r][s];
	if (dp != -1) return dp;
	dp = 0;
	for (int p = l; p < s; ++p)
		for (int q = s + 1; q <= r; ++q) if (A[p][q])
			for (int j = p; j < s; ++j)
				for (int k = s + 1; k <= q; ++k)
					dp += calc(l, j, p) * calc(j + 1, k - 1, s) * calc(k, r, q);
	return dp;
}
int main() {
	memset(f, -1, sizeof f);
	std::cin >> n; int m = n * 2;
	for (int i = 1; i <= m; ++i) {
		std::cin >> buf + 1;
		for (int j = 1; j <= m; ++j)
			A[i][j] = buf[j] & 1;
	}
	LL ans = 0;
	for (int i = 1; i <= m; ++i) if (A[1][i])
		ans += calc(2, m, i);
	std::cout << ans << std::endl;
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int a; cin >> a;
	string s; cin >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
	return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1), visited(N);
  vector<vector<int>> edge(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    edge[A].push_back(B);
    edge[B].push_back(A);
  }

  queue<int> que;
  que.push(0);
  ans[0] = 0;
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (int u : edge[now]) {
      if (ans[u] >= 0) continue;
      ans[u] = now;
      que.push(u);
    }
  }
  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
}

Measured memory_bytes: 10544
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_A
 */
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

using namespace std;

char
SwapCase(const char c)
{
  if (isupper(c)) {
    return tolower(c);
  } else if (islower(c)) {
    return toupper(c);
  }
  return c;
}

int
main()
{
  ios::sync_with_stdio(false);

  string str;
  getline(cin, str);
  transform(str.begin(), str.end(), str.begin(), SwapCase);
  cout << str << endl;

  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long

const int MOD = 1e9 + 7;
const int N = 3e5 + 7;
int cnt[70][2];
ll A[N];

int main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%lld", A + i);
		for (int j = 0; j <= 60; j++) {
			int id = A[i] >> j & 1;
			id ^= 1;
			(ans += (1LL << j) % MOD * cnt[j][id] % MOD) %= MOD;
			cnt[j][A[i] >> j & 1]++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2560
a, b = map(int, input().split())

total = [(n * (n+1)) // 2 for n in range(1, 1000)]

pos = 0
found = False
while not found:
    if total[pos] > a and total[pos] - a == total[pos+1] - b:
        found = True
    else:
        pos += 1

print(total[pos] - a)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <functional>

using namespace std;

#define tp template
#define tn typename
#define cl class
#define us using

us str=string;
us ll=long long;
us ul=unsigned long long;
us sz=size_t;
tp<cl T,sz N>us ary=array<T,N>;
tp<sz N>using ari=array<ll,N>;

#define rep(i, n) for(ll i = 0,i##_len=(n); i < i##_len; i++)
#define loop(i, n, m) for(ll i = (n),i##_len<=(m); i < i##_len; i++)
#define all(x) (x).begin(),(x).end()

tp<tn a,tn f>void setary(a b,a e,f l){ll c=0;for(a i=b;i!=e;i++){*i=l(c);c++;}}

int main(){
	int k,n[3];
	cin >> n[0] >> n[1] >> n[2] >> k;
	sort(n,n+3);
	cout << n[0]+n[1]+n[2]*pow(2,k) << endl;
}

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

int main(){
  vector<int> N(4);
  cin >> N.at(0) >> N.at(1) >> N.at(2) >> N.at(3);
  sort(N.begin(), N.end());
  if(N.at(0)==1 && N.at(1)==4 && N.at(2)==7 && N.at(3)==9) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

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

  int maxx=-100;
  rep(i,n){
    int t;cin>>t;
    maxx=max(maxx,t);
  }

  int miny=100;
  rep(i,m){
    int t;cin>>t;
    miny=min(miny, t);
  }

//cout<<maxx<<' '<<miny<<' '<<x<<' '<<y;
  if(maxx<miny && x<miny && maxx<y){
    cout<<"No War";
  }else{
    cout<<"War";
  }
  
  return 0;
}

Measured memory_bytes: 256
//よるかつ
//前に解説ACしたから今度は自力で
//尺取り解法

#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n);
  vector<ll> b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  //全てaを読む
  ll t=0;
  rep(i,n) t+=a[i];
  int j=n;
  int ans = 0;
  rep(i,m+1){
    //読めるところまで減らす
    while(j>0&&t>k){
      --j;
      t-=a[j];
    }
    //0まで減らしても無理だったらあきらめる
    if(t>k) break;
    //最大値を更新
    ans = max(ans,i+j);
    if(i==m) break;
    //b[i]を足す
    t+=b[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cfloat>
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<string> f(n);
        vector<int> w(n), s(n), a(n);
        double wsum = 0;
        for(int i = 0; i < n; i++){
            cin >> f[i] >> w[i] >> s[i];
            a[i] = i;
            wsum += w[i];
        }
        vector<int> ans(n);
        double g = DBL_MAX;
        do{
            double accw = 0, tmpg = 0;
            bool valid = true;
            for(int i = 0; i < n; i++){
                if(s[a[i]] < accw){
                    valid = false;
                    break;
                }
                accw += w[a[i]];
                tmpg += (n-i)*w[a[i]];
            }
            if(valid && tmpg/wsum < g){
                g = tmpg/wsum;
                ans = a;
            }
        }while(next_permutation(a.begin(), a.end()));
        for(int i = n-1; i >= 0; i--){
            cout << f[ans[i]] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    ll m = 1;
    bool zero = false;
    bool overflow = false;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        if(a[i] == 0) zero = true;
        else if(1000000000000000000LL / a[i] < m) {
            overflow = true;
        }
        if(!overflow) m *= a[i];
    }

    if(zero) {
        cout << 0 << endl;
        return 0;
    }

    if(overflow) {
        cout << -1 << endl;
        return 0;
    }

    cout << m << endl;
}


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

int main(){
    string s; cin >> s;
    string t[16] = {"AKIHABARA", "KIHABARA", "AKIHBARA", "AKIHABRA",
                  "AKIHABAR", "KIHBARA", "KIHABRA", "KIHABAR",
                  "AKIHBRA", "AKIHBAR", "AKIHABR", "KIHBRA",
                  "KIHBAR", "KIHABR", "AKIHBR", "KIHBR"};
    for(int i = 0; i < 16; i++){
        if(t[i] == s){
            cout << "YES" << endl; return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int last = 1;
		for(int j = 19;j >= 0; j--){
			if((1<<j) <= L){
				last = j;
				break;
			}
		}
		int N = last + 1;
		
		List<Pair>[] E = new List<Pair>[N];
		for(int i=0;i<N;i++) E[i] = new List<Pair>();
		for(int i=1;i<=last;i++){
			int bc = 1 << (i - 1);
			E[i].Add(new Pair(i - 1, 0));
			E[i].Add(new Pair(i - 1, bc));
		}
		
		int rest = L - (1 << last);
		for(int i = last - 1; i >= 0; i--){
			int bc = 1 << i;
			for(int j=0;j<4;j++){
				if(rest < bc) break;
				E[last].Add(new Pair(i, L - rest));
				rest -= bc;
			}
		}
		
		int M = 0;
		for(int i=0;i<N;i++) M += E[i].Count;
		
		Console.WriteLine("{0} {1}",N, M);
		for(int i=0;i<N;i++){
			foreach(var e in E[i]){
				Console.WriteLine("{0} {1} {2}", (N - 1 - i) + 1, (N - 1 - e.V) + 1, e.Cost);
			}
		}
		
		
		
		
	}
	
	class Pair{
		public int V, Cost;
		public Pair(int v, int c){
			V = v; Cost = c;
		}
	}
	
	
	int L;
	public Sol(){
		L = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<long> as(N);
	for (int i = 0; i < N; i++) cin >> as[i];
	long ans = 0, r = 0, x = 0, s = 0;
	for (int l = 0; l < N; l++)
	{
		while(x == s)
		{
			if (r < N)
			{
				r++;
				x ^= as[r-1];
				s += as[r-1];
			}
			else break;
		}
		ans += r-l-(x!=s);
		x ^= as[l];
		s -= as[l];
	}

	cout << ans << endl;

}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1792
/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
   string s ;
   cin >> s ;
   for(int i = 0 ; i < s.length()-1 ; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" ; 
            return 0 ; 
        }
   }
   cout << "Good" ; 

























return 0 ;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;using vll = vector<ll>;
ll mod = 1e9+7, INF = 1e18;
int main(){
  ll n, d;
  cin >> n >> d;
  vector<vll> v(n, vll(d));
  for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < d; j++) {
      cin >> v[i][j];
    }
  }
  ll cnt=0;
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      ll sum = 0;
      for (ll k = 0; k < d; k++) {
        sum += (v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
      }
      ll x = sqrt(sum);
      if (sum == x*x) cnt++;
    }
  }
  
  cout << cnt << endl;
      
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a;
bool b=true;
string A;
int main(){
  cin>>A;
  a=A.size();
  for(int i=0;i<a;i++)if(A.at(i)!=A.at(a-i-1))b=false;
  for(int i=0;i<(a-1)/2;i++)if(A.at(i)!=A.at((a-1)/2-i-1))b=false;
  for(int i=0;i<a+1-(a+3)/2;i++)if(A.at((a+3)/2+i-1)!=A.at(a-i-1))b=false;
  if(b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
R, C = map(int, input().split())
 
c = []
black = 0

for _ in range(R):
    tmp = input()
    c.append(tmp)
    black += list(tmp).count("#")

INF = R * C
 
def steppable(h, w):
    if not (h in range(R) and w in range(C)):
        return False
    if c[h][w] == '#':
        return False
    else:
        return True
 
num_step = [[INF for w in range(C)] for h in range(R)]
num_step[0][0] = 1
 
queue = [(0, 0)]
counter = 0

while not queue == []:

    if counter >= 10000:
        print(-1)
        exit()

    h = queue.pop(0) # here
    next_  = [
        (h[0] + 1, h[1]),
        (h[0] - 1, h[1]),
        (h[0], h[1] + 1),
        (h[0], h[1] - 1),]
        
    for n in next_:
        if steppable(n[0], n[1]) and num_step[n[0]][n[1]] == INF:
            queue.append(n)
            num_step[n[0]][n[1]] = num_step[h[0]][h[1]] + 1
 
if num_step[R-1][C-1] != INF:
    ans = R*C - black - num_step[R-1][C-1]
    print(ans)
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
ll d[305][305] ;
ll a[610][305] ;
ll b[610][305] ;

 int main(){
  ll h, w ; cin>>h>>w ;
 rep(i,610){
   rep(j,305){
     a[i][j]=0 ;
     b[i][j]=0 ;
   }
 }
  rep(i,h){
    rep(j,w){
    char ww ; cin>>ww ;
     if(ww=='#'){
        d[i][j]=1 ;
       ll ee= j-i+305 ;
       ll ff= i+j ;
       rep2(v,i,303) {
         a[ee][v+1]++ ; //vika
         
       }
       rep2(v,i,303) {
         b[ff][v+1]++ ;
         
       }
     } 
     else d[i][j]=0  ;
    }
  }
  
  ll ans=0 ;
  rep(i,h){
    rep(j,w){
      if(d[i][j]==1){
        ll now= j-i ;
        ll mow= i+j ;
        rep(r,i){
          // r min i max
          if(r+now>=0&& r+now< w &&d[r][r+now]==1){ 
            ll x= now+2*i-2*r+305 ;
            ll y= now-2*i+2*r+305 ;
            
           if(0<=x && x< 610) ans+= a[x][r+1]-a[x][max(0ll,2*r-i)] ;
           if(0<=y && y<610) ans+= a[y][min(303ll,2*i-r+1)] -a[y][i];
          }
          //cout<<i<<" "<<j<<" "<<ans<<endl ;
          if(0<=mow-r && mow-r <w &&d[r][mow-r]==1){
          ll z= mow+2*i-2*r ;
          ll w= mow-2*i+2*r ;
          if(0<=z && z<610) ans+=b[z][min(303ll,2*i-r+1)] -b[z][i];
          if(0<=w && w<610) ans+=b[w][r+1]-b[w][max(0ll,2*r-i)] ;
          }
          
        }
        //cout<<i<<" "<<j<<" "<<ans<<endl ;
      }
    }
  }
  
  ///
  ll rest = 0 ;
  rep(i,h){
   rep(j,w){
     if(d[i][j]==0 ) continue ;
     rep2(u,j+1,w-1){
       if(d[i][u]==0) continue;
       ll g= (u-j)/2 ;
       if((u-j)%2==0 ){
         if(i-g>=0&& d[i-g][(j+u)/2]==1) rest++ ;
         if(i+g<h&& d[i+g][(j+u)/2]==1) rest++ ;
       }
     }
   //////
    rep2(u,i+1,h-1){
      if(d[u][j]==0) continue ;
      ll g= (u-i)/2 ;
      if((u-i)%2==0){
        if(j-g>=0 && d[(u+i)/2][j-g]==1) rest++ ;
        if(j+g<w && d[(u+i)/2][j+g]==1) rest++  ;
      }
    }
    //
   }
  }
  //cout<< ans<<endl ;
  cout<<ans-rest<<endl ;

  return 0 ;
}


/*
4 4
####
####
####
####
*/

Measured memory_bytes: 7272
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] ns = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long n = 1;
        for (int i = 1; i <= ns[0]; i++) n = (n * i) % 1000000007;
        long s = 1;
        for (int i = 1; i <= ns[1]; i++) s = (s * i) % 1000000007;
        long res = 0;
        if (ns[0] == ns[1]) res = (n * s * 2) % 1000000007;
        else if (Math.Abs(ns[0] - ns[1]) == 1) res = (n * s) % 1000000007;
        Console.WriteLine(res);
    }
}

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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    ios::sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();

    string s;   cin >> s;

    for(int i = 0;i < s.size() - 1;i++){
        if(s[i] == s[i + 1])
            return cout << i + 1 << " " << i + 2, 0;
        else if(i + 2 < s.size() && s[i] == s[i + 2])
            return cout << i + 1 << " " << i + 3, 0;
    }

    cout << -1 << " " << -1;
}

Measured memory_bytes: 512