codeparrot/codecomplex huggingface dataset:
// Problem: 1005_E1. Median on Segments (Permutations Edition)
// Time complexity: nlogn
//package fourninetysixDiv3;
import java.util.HashMap;
import java.util.Scanner;
public class Median_Segments_general {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = s.nextInt();
		}
		System.out.println(func(n, m, arr)-func(n, m+1, arr));
	}
	public static long func(int n,int m,int[] arr) {
		HashMap<Long, Integer> map = new HashMap<>();
		map.put((long) 0, 1);
		long sum = 0;
		long res = 0;
		long add=0;
		for(int i=0;i<n;i++) {
			if(arr[i]<m) {
				sum--;
				if(map.containsKey(sum)) {
					add-=map.get(sum);
				}
			}
			else {
				if(map.containsKey(sum)) {
					add+=map.get(sum);
				}
				sum++;
			}
			res+=add;
			if(map.containsKey(sum)) {
				map.put(sum, map.get(sum)+1);
			}
			else {
				map.put(sum,1);
			}
		}
		return res;
	}
}
// Problem: 903_F. Clear The Matrix
// Time complexity: linear
// practice with rainboy
import java.io.*;
import java.util.*;

public class CF903F {
	static final int INF = 0x3f3f3f3f;
	static void fill(int[][][][] aa, int a) {
		for (int h0 = 0; h0 <= 4; h0++)
			for (int h1 = 0; h1 <= 4; h1++)
				for (int h2 = 0; h2 <= 4; h2++)
					for (int h3 = 0; h3 <= 4; h3++)
						aa[h0][h1][h2][h3] = a;
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a1 = Integer.parseInt(st.nextToken());
		int a2 = Integer.parseInt(st.nextToken());
		int a3 = Integer.parseInt(st.nextToken());
		int a4 = Integer.parseInt(st.nextToken());
		int[] aa = new int[10];
		aa[0] = aa[1] = aa[2] = aa[3] = a1;
		aa[4] = aa[5] = aa[6] = a2;
		aa[7] = aa[8] = a3;
		aa[9] = a4;
		int[][] ww = new int[10][4];
		ww[0][0] = 1;
		ww[1][1] = 1;
		ww[2][2] = 1;
		ww[3][3] = 1;
		ww[4][0] = ww[4][1] = 2;
		ww[5][1] = ww[5][2] = 2;
		ww[6][2] = ww[6][3] = 2;
		ww[7][0] = ww[7][1] = ww[7][2] = 3;
		ww[8][1] = ww[8][2] = ww[8][3] = 3;
		ww[9][0] = ww[9][1] = ww[9][2] = ww[9][3] = 4;
		char[][] cc = new char[4][n + 8];
		for (int k = 0; k < 4; k++) {
			char[] c_ = cc[k];
			br.readLine().getChars(0, n, c_, 4);
			c_[0] = c_[1] = c_[2] = c_[3]
				= c_[n + 4] = c_[n + 5] = c_[n + 6] = c_[n + 7] = '.';
		}
		int[][][][] dp = new int[5][5][5][5];
		int[][][][] dq = new int[5][5][5][5];
		fill(dp, INF);
		dp[4][4][4][4] = 0;
		int[] hh = new int[4];
		for (int i = 0; i < n + 4; i++) {
			for (int h0 = 0; h0 <= 4; h0++)
				for (int h1 = 0; h1 <= 4; h1++)
					for (int h2 = 0; h2 <= 4; h2++)
						for (int h3 = 0; h3 <= 4; h3++)
							for (int s = 0; s < 10; s++) {
								hh[0] = h0;
								hh[1] = h1;
								hh[2] = h2;
								hh[3] = h3;
								for (int k = 0; k < 4; k++) {
									int h = ww[s][k];
									if (hh[k] < h) {
										while (h < 4 && cc[k][i + h] == '.')
											h++;
										hh[k] = h;
									}
								}
								int x = dp[h0][h1][h2][h3] + aa[s];
								if (dp[hh[0]][hh[1]][hh[2]][hh[3]] > x)
									dp[hh[0]][hh[1]][hh[2]][hh[3]] = x;
							}
			fill(dq, INF);
			for (int h0 = 1; h0 <= 4; h0++) {
				hh[0] = h0 < 4 || cc[0][i + 4] == '*' ? h0 - 1 : 4;
				for (int h1 = 1; h1 <= 4; h1++) {
					hh[1] = h1 < 4 || cc[1][i + 4] == '*' ? h1 - 1 : 4;
					for (int h2 = 1; h2 <= 4; h2++) {
						hh[2] = h2 < 4 || cc[2][i + 4] == '*' ? h2 - 1 : 4;
						for (int h3 = 1; h3 <= 4; h3++) {
							hh[3] = h3 < 4 || cc[3][i + 4] == '*' ? h3 - 1 : 4;
							int x = dp[h0][h1][h2][h3];
							if (dq[hh[0]][hh[1]][hh[2]][hh[3]] > x)
								dq[hh[0]][hh[1]][hh[2]][hh[3]] = x;
						}
					}
				}
			}
			int[][][][] tmp = dp; dp = dq; dq = tmp;
		}
		System.out.println(dp[4][4][4][4]);
	}
}
// Problem: 1010_A. Fly
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SFly {

	public static void main(String[] args) throws IOException {
		
		BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
		int planet = Integer.parseInt(lector.readLine());
		int ini = Integer.parseInt(lector.readLine());
		double peso = ini;
		int[] desp = new int[planet];
		int[] ater = new int[planet];
		String[] temp = lector.readLine().split(" ");		
		for(int i=0; i<planet; i++) {
			desp[i] = Integer.parseInt(temp[i]);
			if(desp[i] == 1) {
				System.out.println(-1);
				lector.close();
				return;
			}
		}
		temp = lector.readLine().split(" ");		
		for(int i=0; i<planet; i++) {
			ater[i] = Integer.parseInt(temp[i]);
			if(ater[i] == 1) {
				System.out.println(-1);
				lector.close();
				return;
			}
		}
		temp = null;
		int i=planet-1;
		peso = (peso*ater[0])/(ater[0]-1);
		while(i>0) {
			peso = (peso*desp[i])/(desp[i]-1);
			peso = (peso*ater[i])/(ater[i]-1);
			i--;
		}
		peso = (peso*desp[0])/(desp[0]-1);
		peso = peso - ini;
		System.out.println(peso);
		lector.close();
	}
}
// Problem: 1180_A. Alex and a Rhombus
// Time complexity: linear
import java.io.*;
import java.lang.*;
import java.util.*;
public class alex
{
    public static void main(String[] args)throws IOException
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();int sum=1;
        for(int i=1;i<=n;i++)
        {
            sum=sum+(4*(i-1));
        }
        System.out.println(sum);
    }
}
// Problem: 1028_B. Unnatural Conditions
// Time complexity: constant
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class AAA {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());	
		int n=Integer.parseInt(st.nextToken());
		int m=Integer.parseInt(st.nextToken());
		String a="";
		String b="";
		for(int i=0;i<1129;i++) {
			a+="1";
			b+="8";
		}
		a+="9";
		b+="1";
		
		System.out.println(a);
		System.out.println(b);
	}
		
}
// Problem: 1190_B. Tokitsukaze, CSL and Stone Game
// Time complexity: linear
    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.math.*;
    public class B {
        public static void main(String[] args) throws Exception {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
            int n = Integer.parseInt(bf.readLine());
            StringTokenizer st = new StringTokenizer(bf.readLine());
            Integer[] a = new Integer[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
            Arrays.sort(a);
            int[] b = new int[n];
            for(int i=0; i<n; i++) b[i] = a[i].intValue();
            boolean diff = false;
            boolean diff2 = false;
            Set<Integer> vals = new HashSet<Integer>();
            vals.add(b[0]);
            int valval = 0;
            for(int i=1; i<n; i++) {
                vals.add(b[i]);
                if(b[i] == b[i-1]) {
                    if(!diff) {
                        diff = true;
                        valval = b[i];
                    }
                    else diff2 = true;
                }
            } 
            long sum = 0;
            for(int i : b) sum += i;
            sum -= 1L*n*(n-1)/2;

            if(diff && !diff2) {
                if(!vals.contains((valval-1)) && (valval > 0)) {
                    if(sum%2 == 0) out.println("cslnb"); else out.println("sjfnb");
                }
                else out.println("cslnb");
            }
            else if(diff2) out.println("cslnb");
            else if(sum%2 == 0) out.println("cslnb"); else out.println("sjfnb");
            // int n = Integer.parseInt(st.nextToken());
     
            
            out.close(); System.exit(0);
        }
    }
// Problem: 1197_D. Yet Another Subarray Problem
// Time complexity: quadratic
//package ContestEd69;

import java.io.*;
import java.util.StringTokenizer;

public class mainD {
    public static PrintWriter out = new PrintWriter(System.out);
    public static FastScanner enter = new FastScanner(System.in);
    public static long[] arr;
    public static void main(String[] args) throws IOException {
        int n=enter.nextInt();
        int m=enter.nextInt();
        long k=enter.nextLong();
        arr=new long[n+1];
        for (int i = 1; i <n+1 ; i++) {
            arr[i]=enter.nextLong();
        }
        long[] summ=new long[n+1];
        for (int i = 1; i <n+1 ; i++) {
            summ[i]+=arr[i]+summ[i-1];
        }

        long[] best=new long[n+1];

        for (int i = 1; i <n+1 ; i++) {
            best[i]=Math.max(0, ((i-m>=0) ? best[i-m]+summ[i]-summ[i-m]-k:0));
        }
        long ans=best[1];

        for (int i = 1; i <n+1 ; i++) {
            ans=Math.max(ans,best[i]);
            for (int j = 1; j <m ; j++) {
                ans=Math.max(ans, ((i-j>=0) ? best[i-j] -k +summ[i]-summ[i-j]:0));
            }
        }
        System.out.println(ans);
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer stok;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() throws IOException {
            while (stok == null || !stok.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return null;
                }
                stok = new StringTokenizer(s);
            }
            return stok.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        char nextChar() throws IOException {
            return (char) (br.read());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }
    }
}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
import java.util.*;
import java.lang.*;
public class Main {
    static long m = 1000000007;
    static long powmod(long x, long y, long p)
    {
        // Initialize result
        long res = 1;

        // Update x if it is more
        // than or equal to p
        x = x % p;

        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;

            // y must be even now
            // y = y / 2
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    static long mulmod(long a, long b, long mod){
        long res=0;
        a = a % mod;
        while (b > 0)
        {
            // If b is odd, add 'a' to result
            if (b % 2 == 1)
                res = (res + a) % mod;

            // Multiply 'a' with 2
            a = (a * 2) % mod;

            // Divide b by 2
            b /= 2;
        }

        // Return result
        return res % mod;
    }

    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long k = sc.nextLong();
        if(x>0) {
            long d= powmod(2,k,m);
            long ans= mulmod(d,2,m)%m;
            ans= mulmod(ans,x,m)%m;
            ans++;
            ans%=m;
            ans= (ans-d+m)%m;
            System.out.println(ans);
        }
        else
            System.out.println(0);
    }
}
// Problem: 994_B. Knights of a Polygonal Table
// Time complexity: nlogn
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
import java.util.Map.*;
public class codeforces {
     static int count =0;
     static boolean f=false;
     static int [] arr;
	static 	PrintWriter pw=new PrintWriter(System.out);
	static void solve(int index , int mask) {
		if(index==arr.length) {
			int sum1=0; int sum2=0;
			for(int i=0;i<arr.length;i++) {
				if((mask & 1<<i)!=0) sum1+=arr[i];
				
			}
			return;
		}
		solve(index+1, mask | 1<<index);
		solve(index+1, mask);
	}
	public static void main(String [] args) throws IOException, InterruptedException {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int y=sc.nextInt();
		pair [] arr=new pair[x];
		for(int i=0;i<x;i++) arr[i]=new pair(i, sc.nextInt(),0);
		for(int i=0;i<x;i++) arr[i].y=sc.nextInt();
		Arrays.sort(arr);
		PriorityQueue<Integer> qq=new PriorityQueue<>();
		//pw.println(Arrays.toString(arr));
		Long [] list=new Long [x];
		long sum=0; 
		for(int i=0;i<x;i++) {
			pair w=arr[i];
			if(qq.size()<y) {
				qq.add(w.y);
				sum+=w.y;
				list[w.i]=sum;

			}else if(!qq.isEmpty()) {
				sum+=w.y;
				list[w.i]=sum;
				int first=qq.poll();
				if(w.y>first) {
					sum-=first;
					qq.add(w.y);
				}else {
					qq.add(first);
					sum-=w.y;
				}
			} else list[w.i]=(long) w.y;
			//pw.println(qq);
		}
		for(Long w:list) pw.print(w+" "); 
		pw.flush();
		pw.close();
	}
	
	
	static class pair implements Comparable<pair>{
		String  name; int x,y,i ;
		public pair(String name , int x) {
			this.name=name; this.x=x;
		}
		
		public pair (int i,int x,int y) {
			this.i=i; this.x=x; this.y=y; 
		}
		public int compareTo(pair o) {
			return x-o.x;
		}
		public int compareTo1(pair o) {
			if(!name.equals(o.name))
				return name.compareTo(o.name);
			return x-o.x;
		}
		public String toString() {
			return i+" "+x+" "+y;
		}
	}

   static class Scanner {
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	}
// Problem: 913_F. Strongly Connected Tournament
// Time complexity: quadratic
import java.io.*;
import java.util.*;

public class Codeforces913F {
	public static void main(String[] args) throws IOException {
		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int a = input.nextInt();
		int b = input.nextInt();
		input.close();
		final int mod = 998244353;
		
		int frac = multiply(a, inverse(b, mod), mod);
		int reverse = (mod+1-frac)%mod;
		
		int[] fracpower = new int[n+1];
		int[] reversepower = new int[n+1];
		fracpower[0] = 1;
		reversepower[0] = 1;
		for (int i = 1; i <= n; i++) {
			fracpower[i] = multiply(fracpower[i-1], frac, mod);
			reversepower[i] = multiply(reversepower[i-1], reverse, mod);
		}
		
		int[][] dp1 = new int[n+1][n+1];
		dp1[2][1] = 1;
		for (int i = 3; i <= n; i++) {
			for (int j = 1; j < i; j++) {
				if (j == 1) {
					dp1[i][j] = fracpower[i-1];
				}
				else {
					dp1[i][j] = multiply(dp1[i-1][j-1], fracpower[i-j], mod);
				}
				if (j == i-1) {
					dp1[i][j] += reversepower[i-1];
					dp1[i][j] %= mod;
				}
				else {
					dp1[i][j] += multiply(dp1[i-1][j], reversepower[j], mod);
					dp1[i][j] %= mod;
				}
			}
		}
		
		int[][] dp2 = new int[n+1][n+1];
		dp2[1][1] = 1;
		dp2[2][1] = 1;
		dp2[2][2] = 0;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				dp2[i][j] = multiply(dp2[j][j], dp1[i][j], mod);
				val += dp2[i][j];
				val %= mod;
			}
			dp2[i][i] = (mod+1-val)%mod;
		}
		
		/*for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				System.out.print(dp2[i][j] + " ");
			}
			System.out.println();
		}*/
		
		int[] EV = new int[n+1];
		EV[1] = 0;
		EV[2] = 1;
		for (int i = 3; i <= n; i++) {
			int val = 0;
			for (int j = 1; j < i; j++) {
				int r = j*(i-j) + (j*(j-1))/2 + EV[i-j] + EV[j];
				r %= mod;
				val += multiply(dp2[i][j], r, mod);
				val %= mod;
			}
			val += multiply((i*(i-1))/2, dp2[i][i], mod);
			val %= mod;
			
			int s = (mod+1-dp2[i][i])%mod;
			EV[i] = multiply(val, inverse(s, mod), mod);
		}
		
		System.out.println(EV[n]);
	}
	
	public static int multiply(int a, int b, int mod) {
		long x = (long)a*(long)b;
		return (int) (x%mod);
	}
	
	public static int inverse (int a, int n) {
		int m = n;
		int r1 = 1;
		int r2 = 0;
		int r3 = 0;
		int r4 = 1;
		while ((a > 0) && (n > 0)) {
			if (n >= a) {
				r3 -= r1*(n/a);
				r4 -= r2*(n/a);
				n = n%a;
			}
			else {
				int tmp = a;
				a = n;
				n = tmp;
				tmp = r1;
				r1 = r3;
				r3 = tmp;
				tmp = r2;
				r2 = r4;
				r4 = tmp;
			}
		}
		if (a == 0) {
			if (r3 >= 0)
				return (r3%m);
			else
				return (m+(r3%m));
		}
		else {
			if (r1 >= 0)
				return (r1%m);
			else
				return (m+(r1%m));
		}

	}
}
// Problem: 1197_B. Pillars
// Time complexity: linear
import java.util.*;
import java.io.*;
import java.math.*;
public class Solution{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = Integer.parseInt(st.nextToken());
        int ind = 0;
        for(int i=0;i<n;i++){
            if(a[i]==n){
                ind = i;
                break;
            }
        }
        boolean ok = true;
        for(int i=ind+1;i<n;i++) if(a[i]>a[i-1]) ok = false;
        for(int i=ind-1;i>=0;i--) if(a[i]>a[i+1]) ok = false;
        if(ok) System.out.println("YES");
        else System.out.println("NO");
        
    }
}
// Problem: 1054_A. Elevator or Stairs?
// Time complexity: constant
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Solve4 {

    public static void main(String[] args) throws IOException {
      FastReader sc = new FastReader();
      int x= sc.nextInt();
      int y= sc.nextInt();
      int z= sc.nextInt();
      int t1= sc.nextInt();
      int t2= sc.nextInt();
      int t3= sc.nextInt();
      if(Math.abs(x-y)*t1 < (Math.abs(x-z)+Math.abs(x-y))*t2+3*t3 ) System.out.println("NO");
      else System.out.println("YES");
    }

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException ex) {
            }
            return s;
        }
    }

}
// Problem: 608_C. Chain Reaction
// Time complexity: linear
import java.util.Scanner;

public class codef8 {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int beacon[] = new int[1000001];
		int pos[] = new int[num];
		for (int i = 0; i < num; i++) {
			int position = sc.nextInt();
			beacon[position] = sc.nextInt();
			pos[i] = position;
		}
		int dp[] = new int[1000001];
		int max = 0;
		if (beacon[0] != 0)
			dp[0] = 1;
		
		for (int i = 1; i <= 1000000; i++) {
			if (beacon[i] == 0) {
				dp[i] = dp[i-1];
			} 
			else {
				int j = i - beacon[i] - 1;
				if (j < 0) {
					dp[i] = 1;
				}
				else {
					dp[i] = dp[j] + 1;
				}
			}
			max = Math.max(max, dp[i]);
		}		
		System.out.println(num-max);
	}

}
// Problem: 1061_A. Coins
// Time complexity: constant
import java.io.*;
public class coins
{
 public static void main(String args[])throws IOException
 {
  InputStreamReader read=new InputStreamReader(System.in);
  BufferedReader in=new BufferedReader(read);
  int i,k,n,v;
  String a;
  a=in.readLine();
  for(i=0;i<a.length();i++)
  {
   if(a.charAt(i)==' ')
   break;
  }
  n=Integer.parseInt(a.substring(0,i));
  v=Integer.parseInt(a.substring(i+1));
  k=v%n;
  v=v/n;
  if(k>0)
  v++;
  System.out.println(v);
 }
}
// Problem: 1054_D. Changing Array
// Time complexity: nlogn
import java.io.*; 
import java.util.*; 


public class p7{
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

		int nextInt() 
		{ 
			return Integer.parseInt(next()); 
		} 

		long nextLong() 
		{ 
			return Long.parseLong(next()); 
		} 

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 
        int n = sc.nextInt();
		int k = sc.nextInt();
		long one = (long)Math.pow(2, k) - 1;
		
		long[] arr = new long[n+1];
		
		arr[0] = 0;
		for(int i=1;i<=n;i++){
			arr[i] = sc.nextLong();
			arr[i] ^= arr[i-1];
		}

		Map<Long, Long> count = new HashMap<>();

		for(int i=0;i<=n;i++){
			Long key = Math.min(arr[i], (arr[i]^one));
			Long val = count.get(key);
			if(val==null) val = 0L;
			count.put(key, val+1);
		}

		long num = n;
		long ans = num*(num+1)/2;
		
		for(Map.Entry<Long, Long> ent: count.entrySet()){
			
			Long cnt = ent.getValue();
			
			long num1 = cnt/2;
			long num2 = (cnt+1)/2;
			
			ans -= ( (num1*(num1-1))/2 );
			ans -= ( (num2*(num2-1))/2 );
		}

		System.out.println(ans);
	}
}
// Problem: 1029_A. Many Equal Substrings
// Time complexity: quadratic
import java.util.Scanner;


public class FUck {

		public static void main(String args[])
		{
			Scanner scan=new Scanner(System.in);
			int n=scan.nextInt();
			int k=scan.nextInt();
			String t=scan.next();
			int mx=0;
			for(int i=1;i<n;i++)
			{
				int gd=1;
				for(int j=0;j<i;j++)
				{
					
					if(t.charAt(j)!=t.charAt((n-i)+j))
					{
						
						gd=0;
						// i think i can break here
					}
					}
				if(gd==1){
					mx=i;
					
				}
			}
			System.out.print(t);
			for(int i=2;i<=k;i++)
			{
				for(int j=mx;j<n;j++)
				{
					System.out.print(t.charAt(j));
				}
			}
		}
}
// Problem: 1197_C. Array Splitting
// Time complexity: nlogn
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = in.nextInt();
		for(int i = n-1; i > 0; i--)
			arr[i] -= arr[i-1];
		arr[0] = 0;
		Arrays.sort(arr);
		long sum = 0;
		for(int i = n-k; i >= 0; i--)
			sum += arr[i];
		System.out.println(sum);
	}
}