akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init();
void printList();
void deleteNode(NodePointer);
void deleteFirst();
void deleteLast();
void delete(int);
void insert(int);

main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


NodePointer listSearch(int key){
  NodePointer x;
  x=nil->next;
  while(x!=nil && x->key!=key){
    x=x->next; 
 }
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
    NodePointer x;
    x=listSearch(key);
    if ( x == nil ) return;
    deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  //追加したいnodeのnextをリストの先頭のnodeにする
  x->next=nil->next;
  //リストの先頭のprevを追加したいnodeにする
  nil->next->prev=x;
  //リストの先頭を追加したいnodeにする
  nil->next=x;
  //追加したいnodeのprevをnilにする
  x->prev=nil;
}

Measured memory_bytes: 31788
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program
{
    static char[] alp = "abcdefghijklmnopqrstuvwxyz".ToCharArray();

    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        char[] alp = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
        long[] c = new long[alp.Length];

        long ans = 1;
        for (int i = 0; i < N; i++)
        {
            c[Inv(s[i])]++;
        }

        for (int i = 0; i < alp.Length; i++)
        {
            ans *= c[i] + 1;
            ans %= (long)1e9 + 7;
        }

        Console.WriteLine((ans + (long)1e9 + 6) % ((long)1e9 + 7));
    }

    static int Inv(char c)
    {
        for (int i = 0; i < alp.Length; i++)
            if (c == alp[i]) return i;
        return -1;
    }
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll H, N;
  cin >> H >> N;
  for(int i = 0; i < N; i++){
    ll A;
    cin >> A;
    H -= A;
  }
  cout << (H<=0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;

class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long K;
        K = sc.nextLong();
        long[] a = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                a[i] = sc.nextLong();
        }
        solve(N, K, a);
    }

    static void solve(long N, long K, long[] a){
        boolean[] dp = new boolean[(int)(K+1)];

        for (int i = 1; i <= K; i++){
            for (int j = 0; j < N; j++){
                if (i - (int)a[j] < 0){
                    break;
                }
                if (!dp[i-(int)a[j]]){
                    dp[i] = true;
                    break;
                }
            }
        }
        if (dp[(int)K]){
            System.out.print("First");
        }else{
            System.out.print("Second");
        }

    }
}


Measured memory_bytes: 23380
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

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

int main() {
  string s, c, tmp;
  string front = "", back = "";
  bool flag = true; // trueならそのまま、backなら反転
  int N, q, f;
  cin >> s >> N;
  rep(i, N){
    cin >> q;
    if (q==1) {
      if (flag) flag = false;
      else flag = true;
      // 入れかえを行う
      tmp = front;
      front = back;
      back = tmp;
    }
    else if (q == 2){
      cin >> f >> c;
      if (f==1){ // 先頭につける
        front += c;
      } else { // 後ろにつける
        back += c;
      }
    }
    // cout << front << s << back << endl;
  }

  reverse(front.begin(), front.end());
  if (!flag) reverse(s.begin(), s.end());
  cout << front << s << back << endl;
  
}



Measured memory_bytes: 1376
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n);
	int mx = 0;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		mx = max(mx, A[i]);
	}
	int closeHalf = MOD, sec = -1;
	for (int i = 0; i < n;  i++) {
		if(A[i] != mx) {
			if(abs(A[i] - mx / 2) < closeHalf) {
				sec = A[i];
				closeHalf = abs(A[i] - mx / 2);
			}
		}
	}
	cout << mx << " " << sec;  
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int A[100], n, i, j, t, sw = 0;

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

  for ( i = 0; i < n; i++ ){
    for ( j = n-1; j >= i+1; j-- ){
      if ( A[j] < A[j-1] ){
	t = A[j]; A[j] = A[j-1]; A[j-1] = t;
	sw++;
      }
    }
  }

  for ( i = 0; i < n; i++ ){
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}



Measured memory_bytes: 2708
S=input()
 
if S[0]==S[1] and S[1]==S[2]:
  print("No")
elif S[0]==S[1] and S[2]==S[3]:
  print("Yes")
elif S[0]==S[2] and S[1]==S[3]:
  print("Yes")
elif S[0]==S[3] and S[1]==S[2]:
  print("Yes")
else:
  print("No")

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class S> vector<int> build_sa(const S& s) {
  int n = s.size();
  vector<int> sa(n), id(begin(s), end(s)), buf(n);
  iota(rbegin(sa), rend(sa), 0);
  stable_sort(begin(sa), end(sa), [&](int i, int j) { return s[i] < s[j]; });
  for (int m = 1; m < n; m *= 2) {
    for (int k = 0; k < n; ++k) {
      int i = sa[k], p = k ? sa[k - 1] : n, j = i + m / 2, q = p + m / 2;
      buf[i] = p + m < n and id[i] == id[p] and id[j] == id[q] ? buf[p] : k;
    }
    swap(id, buf);
    iota(begin(buf), end(buf), 0);
    auto nsa = sa;
    for (int k = 0, i; k < n; ++k)
      if ((i = sa[k] - m) >= 0) nsa[buf[id[i]]++] = i;
    swap(sa, nsa);
  }
  return sa;
}

template <class T> struct sparse_table {
  vector<vector<T>> t;
  sparse_table(const vector<T>& v = {}) : t{v} {
    for (int k = 1, n = v.size(); 1 << k <= n; ++k) {
      t.emplace_back(n - (1 << k) + 1);
      for (int i = 0; i + (1 << k) <= n; ++i)
        t[k][i] = min(t[k - 1][i], t[k - 1][i + (1 << (k - 1))]);
    }
  }
  T fold(int l, int r) const {
    assert(l < r);
    int k = __lg(r - l);
    return min(t[k][l], t[k][r - (1 << k)]);
  }
};

template <class S> struct suffix_array {
  S s;
  int n;
  vector<int> sa, rank, h;
  sparse_table<int> st;
  suffix_array(const S& _s = S()) : s(_s), n(s.size()), rank(n), h(n) {
    sa = build_sa(s);
    for (int k = 0; k < n; ++k) rank[sa[k]] = k;
    for (int i = 0, m = 0; i < n; ++i, m = max(m - 1, 0)) {
      int j = rank[i] + 1 < n ? sa[rank[i] + 1] : n;
      while (max(i, j) + m < n and s[i + m] == s[j + m]) ++m;
      h[rank[i]] = m;
    }
    st = {h};
  }
  int lcp(int i, int j) const {
    if (i == j) return n - i;
    if (rank[i] > rank[j]) swap(i, j);
    return st.fold(rank[i], rank[j]);
  }
  int cmp(int i, int j, int len) const {
    int m = lcp(i, j);
    return m < len ? s[i + m] - s[j + m] : 0;
  }
};

#define size(v) v.size()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int n = size(s), m = size(t);
  suffix_array<string> sa(s + "$" + t);
  vector<int> a(n - m + 1), b(n - m + 1);
  for (int l = 0; l + m <= n; ++l) {
    a[l] = sa.lcp(l, n + 1);
  }
  suffix_array<string> rsa({rbegin(sa.s), rend(sa.s)});
  for (int l = 0; l + m <= n; ++l) {
    b[l] = rsa.lcp(n - l + 1, 0);
  }
  int res = 0;
  for (int l = 0; l + m <= n; ++l) {
    res += a[l] + b[l] == m - 1;
  }
  cout << res << '\n';
}



Measured memory_bytes: 79296
//https://atcoder.jp/contests/abc141/tasks/abc141_a
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    if(s == "Sunny")cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else if(s == "Rainy") cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int N;
    cin >> N;
    vi L(N);
    in(N,L);
    
    sor(L);
    int ans = 0;
    rep(i,N) reps(j,i+1,N){
        auto aa = lower_bound(all(L), L[i]+L[j]) - L.begin()-1;
        auto bb = upper_bound(all(L), abs(L[i]-L[j])) - L.begin();
        //cout << aa << " " << bb << endl;
        bb = max(int(bb), j);
        if(bb < aa) ans += int(aa-bb);
        
        //cout << aa << " " << bb <<"  "<< aa-bb<<  endl;
    }

    out(ans);
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define NIL -1
 
typedef struct{
  int oya, left, right;
}Node;
 
Node Tree[MAX];
int n, Depth[MAX];
 
int getDepth(int);
void print(int);
 
int child[MAX];
 
int main(void){
  int i, j;
  int d, v;
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    Tree[i].oya = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &child[j]);
 
      Tree[child[j]].oya = v;
       
      
      if(j == 0)
    Tree[v].left = child[0];
       
      else
    Tree[child[j - 1]].right = child[j];
    }
  }
   
  for ( i = 0; i < n; i++ )
    Depth[i] = getDepth(i);
   
  for ( i = 0; i < n; i++ )
    print(i);
   
  return 0;
}
 
int getDepth(int u){
  int d = 0;
 
  while(Tree[u].oya >= 0){
    u = Tree[u].oya;
    d++;
  }
 
  return d;
}
 
void print(int u){
 
  int i, cnt = 0;
 
  printf("node %d: parent = %d, depth = %d, ",u,Tree[u].oya,Depth[u]);
 
  if(Tree[u].oya == NIL)
    printf("root, [");
 
  else if(Tree[u].left == NIL)
    printf("leaf, [");
 
  else
    printf("internal node, [");
 
  u = Tree[u].left;
  while(u != NIL){
    if(cnt == 0)
      printf("%d",u); 
 
    else
      printf(", %d",u);
   
    u = Tree[u].right;
    cnt++;
 
     
  
 }
 
 
    printf("]\n");
 
}

Measured memory_bytes: 2564
#include <stdio.h>
int main(){
  int a,b;
  
  scanf("%d %d",&a,&b);
  
  if(a==b){
    printf("Draw");
    return 0;
  } else if(a==1){
    printf("Alice");
    return 0;
  } else if(b==1){
    printf("Bob");
    return 0;
  }
  
  if(a<b){
    printf("Bob");
  } else {
    printf("Alice");
  }
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
using namespace std;

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

	return gcd(b, a % b);
}

int main()
{
	int N;
	cin >> N;
	vector<unsigned long long> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	vector<unsigned long long> res(N + 1);
	res[2] = A[0];

	for (auto i = 1; i < N - 1; ++i)
	{
		auto a = A[i];
		auto b = res[i + 1];
		if (a < b)
		{
			swap(a, b);
		}
		res[i + 2] = gcd(a, b);
	}

	vector<unsigned long long> res2(N + 1);
	res2[N] = res[N];
	res2[N - 1] = A[N - 1];
	for (auto i = N - 2; i >= 0; --i)
	{
		auto a = A[i];
		auto b = res2[i + 1];
		if (a < b)
		{
			swap(a, b);
		}
		res2[i] = gcd(a, b);
	}
	res[0] = res2[0];
	res[1] = res2[1];

	auto result = 0ull;
	for (auto i = 0; i < N + 1; ++i)
	{
		auto a = res[i];
		auto b = res2[i];
		if (a < b)
		{
			swap(a, b);
		}
		result = max(result, gcd(a, b));
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<utility>
#include<algorithm>
using namespace std;

vector < vector<pair<int, int>>> g;
vector<int> ans;

void dfs(int node, int from = -1, int fromColor = -1) {
    int color = 1;
    for (int i = 0; i < (int)g[node].size(); i++) {
        int to = g[node][i].first;
        int id = g[node][i].second;

        if (to == from)
            continue;

        if (color == fromColor)
            color++;

        ans[id] = color;
        dfs(to, node, color);
        color++;
    }
}

int main(void)
{
    int N;
    cin >> N;

    vector<int> a(N - 1), b(N - 1);
    for (int i = 0; i < N-1; i++)
        cin >> a[i] >> b[i];

    g.resize(N);
    for (int i = 0; i < N-1; i++) {
        a[i]--;
        b[i]--;

        g[a[i]].push_back(make_pair(b[i], i));
        g[b[i]].push_back(make_pair(a[i], i));
    }

    ans.resize(N - 1);
    dfs(0);

    cout << *max_element(ans.begin(), ans.end()) << endl;
    for (int i = 0; i < (int)ans.size(); i++)
        cout << ans[i] << endl;


    return 0;
}


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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  const int M = 1<<15;
  int dp[M + 1][5] = {};
  dp[0][0] = 1;
  for(int i = 1; i * i <= M; i++){
    int s = i * i;
    for(int j = s; j <= M; j++){
      for(int k = 0; k <= 3; k++){
        dp[j][k+1] += dp[j-s][k];
      }
    }
  }
  int n;
  while(cin>>n && n){
    int ans = 0;
    REP(i,5)ans += dp[n][i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>

using namespace std;

bool is_msn(int n) {
    return n % 7 == 1 || n % 7 == 6;
}

bool is_prime(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (is_msn(i) && n % i == 0) {
            return false;
        }
    }
    return true;
}

vector<int> solve(int n) {
    vector<int> retval;
    set<int> divs;
    for (int i = 2; i <= n; ++i) {
        if (is_msn(i) && n % i == 0 && is_prime(i)) {
            divs.insert(i);
        }
    }
    for (set<int>::iterator iter = divs.begin(); iter != divs.end(); ++iter) {
        retval.push_back(*iter);
    }
    return retval;
}

int main() {
    int n;
    vector<int> answer;
    while (true) {
        cin >> n;
        if (n == 1) {
            return 0;
        }
        answer = solve(n);
        cout << n << ": ";
        for (int i = 0; i < (int)answer.size(); ++i) {
            cout << answer[i];
            if (i < (int)answer.size() - 1) {
                cout << ' ';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1216
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	C := make([]int, N)
	S := make([]int, N)
	F := make([]int, N)

	for i := 0; i < N-1; i++ {
		fmt.Scanf("%d %d %d", &C[i], &S[i], &F[i])
	}
	C[N-1], S[N-1], F[N-1] = 0, 0, 0

	for i := 0; i < N; i++ {
		time := S[i]+C[i]
		for j := i+1; j < N-1; j++ {
			if time < S[j] {
				time = S[j] + C[j]
			} else if time % F[j] == 0 {
				time += C[j]
			} else if time % F[j] != 0 {
				time += (F[j] - time % F[j])  + C[j]
			}
		}
		fmt.Println(time)
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define N 10000

int LCSLength(char *, char *);

char X[N + 1], Y[N + 1];
int c[N + 1][N + 1];

int main()
{

    int q;
    int i;
    scanf("%d", &q);

    for (i = 0; i < q; i++)
    {
        X[0] = ' ';
        Y[0] = ' ';
        scanf(" %s %s", &X[1], &Y[1]);

        // printf("%s\n%s\n",X,Y);

        printf("%d\n", LCSLength(X, Y));
    }

    return 0;
}

int LCSLength(char *X, char *Y)
{
    int i, j;
    int m, n;
    m = strlen(X);
    n = strlen(Y);

    for (i = 1; i <= m; i++)
    {
        c[i][0] = 0;
    }

    for (j = 0; j <= n; j++)
    {
        c[0][j] = 0;
    }

    for (i = 1; i <= m; i++)
    {
        for (j = 1; j <= n; j++)
        {
            if (X[i] == Y[j])
            {
                c[i][j] = c[i - 1][j - 1] + 1;
            }
            else if (c[i - 1][j] >= c[i][j - 1])
            {
                c[i][j] = c[i - 1][j];
            }
            else
                c[i][j] = c[i][j - 1];
        }
    }

    return c[m][n] - 1;
}



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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;


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

    int T, P, R;
    while (cin >> T >> P >> R, T) {
        VV v(T, V(3, 0));   // AC, pena, id(0-index)
        rep(i, T) v[i][2] = i;

        VV wa(T, V(P, 0));
        while (R--) {
            int tid, pid, t;
            string m;
            cin >> tid >> pid >> t >> m;
            tid--; pid--;
            if (m[0] == 'C') {
                v[tid][0]++;
                v[tid][1] += wa[tid][pid] * 1200 + t;
            } else {
                wa[tid][pid]++;
            }
        }

        rep(i, T) v[i][0] *= -1;
        sort(all(v));
        rep(i, T) v[i][0] *= -1;

        for (auto u : v) {
            cout << u[2] + 1 << " " << u[0] << " " << u[1] << endl;
        }

    }
}

Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,n,k,r[3],dp[100001][3],mx,x[3],m;
	char s[100001],b[4]="spr";
	scanf("%d %d",&n,&k);
	scanf("%d %d %d",&r[0],&r[1],&r[2]);
	scanf("%s",s);
	for(i=0;i<k;i++)	{
		for(j=0;j<3;j++)	x[j]=0;
		if(s[i]=='r')	x[2]=r[2];
		if(s[i]=='s')	x[0]=r[0];
		if(s[i]=='p')	x[1]=r[1];
		for(j=0;j<3;j++)	dp[i][j]=x[j];
	}
	for(i=k;i<n;i++)	{
		for(j=0;j<3;j++)	x[j]=0;
		if(s[i]=='r')	x[2]=r[2];
		if(s[i]=='s')	x[0]=r[0];
		if(s[i]=='p')	x[1]=r[1];
		m=max(dp[i-k][1],dp[i-k][2]);
		dp[i][0]=m+x[0];
		m=max(dp[i-k][0],dp[i-k][2]);
		dp[i][1]=m+x[1];		
		m=max(dp[i-k][0],dp[i-k][1]);
		dp[i][2]=m+x[2];
	}
	mx=0;
	for(i=n-k;i<n;i++)	{
		m=0;
		for(j=0;j<3;j++)	{
			m=max(dp[i][j],m);
		}
		mx+=m;
	}
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;

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

    int n = sc.nextInt();
    int ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  }
}


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

#define ll long long
#define UN unsigned
#define pb push_back
#define mod 1000000007
#define mt make_tuple
typedef tuple<int, int> tii;
typedef pair<int, int> pii;

void solve(){
    int k, n;
    cin >> k >> n;

    vector<ll> a(n);
    for(auto& x: a){
        cin >> x;
    }

    int ans = INT_MAX;
    for(int i=0; i<n; i++){
        int d1, d2;
        if(i == 0)
            d1 = a[0] + abs(k-a[n-1]);
        else
            d1 = abs(a[i] - a[i-1]);

        if(i == n-1) 
            d2 = a[0] + abs(k-a[n-1]);
        else
            d2 = abs(a[i+1]-a[i]);

        ans = min(ans, min(k-d1, k-d2));
    }

    cout << ans;
}

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 1792
n=50
table=[2**i for i in range(n+1)]
A,B=map(int,input().split())
st=0
for i in range(n+1):
    if table[i]>B:
        st=i
        break
ans=0
for i in range(1,st+1):
    x=0
    if B%(2**i)>=2**(i-1):
        x=B%(2**i)-2**(i-1)+1
    b=((B-B%(2**i))//(2**i))*(2**(i-1))+x
    y=0
    if (A-1)%(2**i)>=2**(i-1):
        y=(A-1)%(2**i)-2**(i-1)+1
    a=(((A-1)-(A-1)%(2**i))//(2**i))*(2**(i-1))+y
    if (b-a)%2==1:
        ans+=1<<(i-1)
print(ans)
    
    



Measured memory_bytes: 3064
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long INF = 1L<<59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto D = s[1].to!long;
    auto A = readln.split.map!(to!long).array;

    auto B = N.iota.map!(i => tuple(A[i], i)).array;
    B.sort!"a[0] > b[0]";

    auto st1 = new SegmentTree!(Tuple!(long, int), min, tuple(1L<<59, 1<<29))(N);
    auto st2 = new SegmentTree!(Tuple!(long, int), min, tuple(1L<<59, 1<<29))(N);
    foreach (i; 0..N) st1.assign(i, tuple(A[i]+D*i, i));
    foreach (i; 0..N) st2.assign(i, tuple(A[i]-D*i, i));

    Tuple!(int, int, long)[] E;

    foreach (b; B) {
        int i = b[1];
        if (i > 0) {
            int j = st2.query(0, i-1)[1];
            if (j >= N) continue;
            E ~= tuple(i, j, abs(i - j) * D + A[i] + A[j]);
        }
        if (i < N - 1) {
            int j = st1.query(i+1, N-1)[1];
            if (j >= N) continue;
            E ~= tuple(i, j, abs(i - j) * D + A[i] + A[j]);
        }
        st1.assign(i, tuple(1L<<59, 1<<29));
        st2.assign(i, tuple(1L<<59, 1<<29));
    }


    E.sort!"a[2] < b[2]";
    auto uf = new UnionFind(N);
    long ans = 0;

    foreach (e; E) {
        if (uf.find(e[0]) == uf.find(e[1])) continue;
        ans += e[2];
        uf.unite(e[0], e[1]);
    }

    ans.writeln;
}


class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}


class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}


Measured memory_bytes: 43996
import math
import collections
#import sys
#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

    
a,b=MI()
g=gcd(a,b)
pg=list(set(prime_factorize(g)))
print(len(pg)+1)





Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e6;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
   
     void solve(){
          
     
        int a,b;
        cin>>a>>b;
        int mx=max({a-b,a+b,a*b});
        cout<<mx<<endl;    
     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


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

int main(void) {
    string S;
    cin>>S;
    int a_index = -1, z_index = -1;
    for (int i = 0; i < S.size(); i++) {
        char s = S[i];
        if (s == 'A' && a_index == -1) a_index = i;
        if (s == 'Z') z_index = i;
    }
    cout << z_index - a_index + 1 << endl;
    return 0;
}

Measured memory_bytes: 832
# input
N = int(input())
K = int(input())

# defnition
N_bin = str(N)
bit_len_N = len(N_bin)
DP = [[[0]*(K+2) for _ in range(2)] for _ in range(bit_len_N+1)]
# Kは0でない数の数
# smaller=0はboarder

DP[0][0][0] = 1

# solve with けたDP
for bit in range(bit_len_N):
    max_digit = int(N_bin[bit])
    for smaller in range(2):
        for k in range(K+1):
            cand_digits = max_digit+1 if smaller == 0 else 10
            for next in range(cand_digits):
                if next == max_digit and smaller == 0:
                    if next == 0:
                        DP[bit+1][0][k] += DP[bit][0][k]
                    else:
                        DP[bit+1][0][k+1] += DP[bit][0][k]
                else:
                    if next == 0:
                        DP[bit+1][1][k] += DP[bit][smaller][k]
                    else:
                        DP[bit+1][1][k+1] += DP[bit][smaller][k]
print(DP[-1][0][K]+DP[-1][1][K])


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

void f(string s) {

    for (int i = 0; i < 5; i++) {
        cout << s[i];
    }
    cout << " ";
    for (int i = 6; i < 13; i++) {
        cout << s[i];
    }
    cout << " ";
    for (int i = 14; i < 19; i++) {
        cout << s[i];
    }
    cout << endl;
}

int main() {

    string s;
    cin >> s;

    f(s);

    return 0;
}


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

int main() {
  int A[100];
  int N, M;
  int a, b;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    A[i] = 0;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[a-1] += 1;
    A[b-1] += 1;
  }
  for (int i = 0; i < N; i++)
    cout << A[i] << endl;

  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 //Compiler version g++ 6.3.0
 
 signed main()
 {
 	int N, a[100000], b[100000];
 	cin >> N;
 	int x = 0, ans = 0;
 	for(int i = 0; i < N; i++){
 		cin >> a[i];
 		x ^= a[i];
 		b[i] = a[i]^(a[i]-1);
 	}
 	for(int k = 30; k >= 1; k--){
 		bool bit, find = 0;
 		int tmp = x;
 		for(int i = 0; i < k; i++){
 			bit = tmp % 2;
 			tmp /= 2;
 		}
 		int num;
 		for(int i = 0; i < N; i++){
 			if(b[i] == pow(2ll, k)-1){
 				find = 1;
 				num = b[i];
 				break;
 			}
 		}
 		if(bit && find){
 			x ^= num; ans++;
 		}
 		if(bit && !find){
 			cout << -1 << endl;
 			return 0;
 		}
 	}
 	cout << ans << endl;
 }

Measured memory_bytes: 1792
#include <stdio.h>

int main (void)
{
	int N,M;
	scanf("%d",&N);
	if(!(N%2)){
		M = (N/2) * (N+1);
	}
	else{
		M = ((N+1)/2) * N;
	}
	printf("%d \n",M);
	
	return 0;
}

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

int main() {
  int N;
  cin >> N ;
  
  vector<int> R(N);
  for ( int i = 0 ; i < N ; i++ )
    cin >> R.at(i);
  
  int maxv = -2000000000;
  int minv = R.at(0);
  for ( int i = 1 ; i < N ; i++ ){
	maxv = max(maxv,R.at(i) - minv) ;
    minv = min(minv,R.at(i));
  }  
  cout << maxv << endl;
}


Measured memory_bytes: 3560
#include <iostream>

using namespace std;

int main() {
  long int n, tmp;
  cin >> n;

  tmp = 0;
  for(int i=1;  i<=n; i++){
    if(i % 15 == 0){
      continue;
    }else if(i % 3 ==0 && i % 5 != 0){
      continue;
    }else if(i % 3 !=0 && i % 5 == 0){
      continue;
    }else{
      tmp += i;
    } 
  }

  cout <<  tmp << endl;

  return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
import string

def main():
    n = int(input().strip())
    v = input().strip()
    newv = [0] * (len(v))
    al = string.ascii_uppercase
    for i, c in enumerate(v):
        newv[i] = al[(al.index(c) + n) % len(al)]
    print("".join(newv))

if __name__ == '__main__':
    main()


Measured memory_bytes: 40432
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if((a==7&&b==5&&c==5)||(a==5&&b==7&&c==5)||(c==7&&a==5&&b==5))
    cout<<"YES";
  else
    cout<<"NO";
  return 0;
}


Measured memory_bytes: 3028
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

a,b,c=map(int,input().split())
print("Yes" if a<=c<=b else "No")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;

int main(){
  ll N;  cin >> N;
  VL a(N+2, 0); rep(i,1,N+1) cin >> a[i];
  
  VL suma(N+2, 0);
  ll cnt = 0;
  rep(i,1,N+1){
    cnt += abs(a[i] - a[i-1]);
    suma[i] = cnt;
  }
  suma[N+1] = cnt + abs(a[N] - 0);
  
  rep(i,1,N+1){
    cout << suma[N+1] - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n;
     cin >> n;
     vector<int> a(n);
     for(int i = 0; i < n; ++i) cin >> a[i];

    int tallest = a[0];
    ll ans = 0;
     for(int i = 1; i < n; ++i){
         if(a[i] > tallest) tallest = a[i];
         else{
             ans += tallest-a[i];
         }
     }

     cout << ans << '\n';
}

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

Measured memory_bytes: 3984
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

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

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

  int a;
  cin >> a;

  cout << 3 * a * a << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(llong i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(llong i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
llong mod = 1000000007;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  llong N;cin>>N;
  llong cross =0;
  vector<llong> a(N);REP(i,N){
    cin>>a[i];
    cross = cross ^ a[i];
  }

if(cross == 0){
  cout <<"Yes"<<endl;
}else{
  cout << "No"<<endl;
}
}


Measured memory_bytes: 1024
import itertools
import numpy as np

N, M, X = map(int, input().split())
books = list()
for _ in range(N):
    books.append(list(map(int, input().split())))
    
A = [False, True]
combinations = list(itertools.product(A, repeat=N))
books_array = np.array(books)
amount = float('inf')
check = False
for comb in combinations:
    array = books_array[np.array(comb).T]
    amo = array[:, 0].sum()
    if np.all(array[:, 1:].sum(axis=0) >= X) and amo < amount:
        amount = amo
        check = True

if check:
    print(amount)
else:
    print(-1)

Measured memory_bytes: 27772
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

int main(){
	ll n,p;
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}
	vector<ll> v;
	for(ll i=2;i*i<=p;i++){
		bool sosuu=true;
		for(ll j=2;j*j<=i;j++){
			if(i%j==0){
				sosuu=false;
				break;
			}
		}
		if(sosuu==false)continue;
		else{
			ll cnt=0;
		while(p%i==0){
				p/=i;
				cnt++;
			}
			if(cnt>=n){
				ll x=cnt/n;
				rep(k,0,x)v.push_back(i);
			}
		}
	}
	ll ans=1;
	rep(i,0,v.size()){
		ans*=v[i];
	}
	cout<<ans<<endl;
}

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

using namespace std;

string s[10];
int h, w, k;

int sum[15][1005];

bool check(vector<int> &v, int js, int jt) {
  for (int i = 0; i < v.size() - 1; i++) {
    int t = v[i];
    int l = js;
    int b = v[i + 1];
    int r = jt;

    int sum_ = sum[b][r] - sum[b][l] - sum[t][r] + sum[t][l];
    if (sum_ > k) {
      return false;
    }
  }
  return true;
}

int solve(vector<int> &v) {
  int ans = 0;
  int js = 0;
  for (int jt = 1; jt <= w; jt++) {
    if (check(v, js, jt)) {
      continue;
    } else {
      if (jt - js == 1) {
        return -1;
      }
      jt--;
      js = jt;
      ans++;
    }
  }
  return ans + v.size() - 2;
}

int dfs(int i, vector<int> v) {
  if (i == h) {
    v.push_back(h);
    int ans = solve(v);
    if (ans < 0) {
      return 10 * 1000 + 1;
    } else {
      return ans;
    }
  }
  int res = 10 * 1000 + 1;
  res = min(res, dfs(i + 1, v));
  v.push_back(i);
  res = min(res, dfs(i + 1, v));
  return res;
}

int main() {
  cin >> h >> w >> k;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
  }

  // sum
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (s[i - 1][j - 1] == '1') {
        sum[i][j] += 1;
      }
      // cout << sum[i][j] << " ";
    }
    // cout << endl;
  }

  cout << dfs(1, {0}) << endl;
  return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll a, b, k; cin >> a >> b >> k;
	if (a <= k) {
		if (b - (k - a) >= 0) cout << 0 << " " << b - (k - a);
		else cout << 0 << " " << 0;
	}
	else cout << a - k << " " << b;
}



Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main(){
    int N,r,l;
    scanf("%d",&N);
    int A[N],sum_l=0,xor_l=0;
    long long int res=0;
    for(int i=0;i<N;i++){scanf("%d",A+i);}
    r=0;
    for(l=0;l<N;l++){
        while(r<N && (sum_l+A[r])==(xor_l^A[r])){
            sum_l+=A[r];
            xor_l^=A[r];
            r++;
        }
        res+=(r-l);
        sum_l-=A[l];
        xor_l^=A[l];
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 896
import sys
from collections import defaultdict
from collections import deque
import numpy as np
import heapq
from heapq import heappush, heappop


#read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [[0 for _ in range(10)] for _ in range(10)]

'''
while(True):
    Nstr = str(N)
    l = len(Nstr) - 1

    if Nstr[0] == Nstr[l]:
        break

    N -= 1
'''

# print(N)


for i in range(N+1):
    s = str(i)
    l = len(s) - 1

    if s[l] == '0':
        continue
    A[int(s[0])][int(s[l])] += 1


ans = 0
for j in range(1, 10):
    for k in range(1, 10):
        ans += A[j][k] * A[k][j]

# print(A)
print(ans)


Measured memory_bytes: 12488
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        for(int i=1;i<=n;i++){
            int x = i;
            if(x%3==0){
                System.out.printf(" %d",i);
            }else{
                while(x!=0){
                    if(x%10==3){
                        System.out.printf(" %d",i);
                        break;
                    }
                    x/=10;
                }
            }
        }
        System.out.printf("\n");
    }
}


Measured memory_bytes: 40496
N, M = gets.split.map(&:to_i)

edges = []

while line = gets
  edges << line.split.map(&:to_i)
end

count = 0

(2..N).to_a.permutation.each do |tuple|
  order = [1] + tuple
  ok = order.each_cons(2).all? do |edge|
    edges.include?(edge) or edges.include?(edge.reverse)
  end
  count += 1 if ok
end

puts count
  

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 5 * 10000 + 1
#define INF 10000000000

int h, w;
const int MOD = int(1e9)+7;

int wall(char c)
{
    return c == '#' ? 1:0;
}

int main()
{
    cin >> h >> w;
    char mat[h][w];
    ll dp[h][w];
    memset(dp, 0LL, sizeof(dp));

    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            cin >> mat[i][j];
    
    dp[1][0] = !wall(mat[1][0]);
    dp[0][1] = !wall(mat[0][1]);


    
    for (int r = 0; r < h; ++r)
    {
        for (int c = 0; c < w; ++c)
        {
            if (wall(mat[r][c]))
                continue;
            if (r - 1 >= 0)
                dp[r][c] += dp[r-1][c];
            if (c - 1 >= 0)
                dp[r][c] += dp[r][c-1];
            dp[r][c] %= MOD;
        }
    }

   /*  for (int r = 0; r < h; ++r)
    {    
        for (int c = 0; c < w; ++c)
            cout << dp[r][c] << " ";
        cout << endl;
    } */
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <stdio.h>

int main(){
   int d,c[26],s[365][26],last[26],i,j,ms,mi,t;
   long sum;

   scanf("%d",&d);
   for (i=0;i<26;i++) {
      scanf("%d",&c[i]);
      last[i]=-1;
   }
   for (j=0;j<d;j++)
      for (i=0;i<26;i++) scanf("%d",&s[j][i]);
   for (i=0;i<d;i++) {
      mi=0;
      ms=s[i][0]+(c[0]*(d-last[0]))*(d-i);
      for (j=1;j<26;j++) {
         t=s[i][j]+(c[j]*(d-last[j]))*(d-i);
         if (t>ms) {
            ms=t;
            mi=j;
         }
      }
      printf("%d\n",mi+1);
      last[mi]=i;
   }
   return 0;
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
long long n, m;

int gcm(int a, int b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
    }if (!(a % b))return b;
  return gcm(a % b, b);
}
long long gcm(long long a, long long b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
  }if (!(a % b))return b;
  return gcm(a % b, b);
}


int main()
{
  cin >> m >> n;
  cout << m / gcm(n, m) * n << endl;
}


Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto a = readAs!(int[]);
	ulong cnt;
	ulong rate;
	while(rate < 3200) {
		if(a.any!(i => rate <= i && i < rate+400)) cnt++;
		rate += 400;
	}
	writefln("%d %d", cnt==0 ? 1 : cnt, cnt+a.count!(i => i >= 3200));
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
chk = [False for i in range(n)]

c = 0
d = 0
while True:
	if chk[c]:
		print (-1)
		exit()
	else:
		chk[c] = True
		if c == 1:
			print (d)
			exit()
	c = a[c]-1
	d += 1

Measured memory_bytes: 7884