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

public class tr1 {
	static PrintWriter out;
	static StringBuilder sb;
	static int n;
	static long x;
	static int[] a;
	static long memo[][][];

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		n = sc.nextInt();
		x = sc.nextInt();
		a=new int [n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		memo = new long[n][3][3];
		for(long [][]h:memo)
			for(long[]a:h)
				Arrays.fill(a, -1);
		out.println(dp(0,0,0));
		out.flush();
	}

	static long dp(int i, int ma, int ml) {
		if (i == n)
			return 0;
		if (memo[i][ma][ml] != -1)
			return memo[i][ma][ml];
		long ans = -(long) 1e9;
		if(ma==0) {
			ans=Math.max(ans, dp(i+1,0,0));
			if(ml==0) {
				ans=Math.max(ans,dp(i+1,1,0)+a[i]);
				ans=Math.max(ans, dp(i+1,1,1)+a[i]*x);
				ans=Math.max(ans, dp(i+1,1,2)+a[i]);
			}
			ans=Math.max(ans, dp(i+1,2,0));
		}
		if(ma==1) {
			if(ml==0) {
			ans=Math.max(ans, dp(i+1,1,0)+a[i]);
			ans=Math.max(ans, dp(i+1,1,1)+a[i]*x);
			ans=Math.max(ans, dp(i+1,1,2)+a[i]);
	     	}
			if(ml==1) {
				ans=Math.max(ans, dp(i+1,1,1)+a[i]*x);
				ans=Math.max(ans, dp(i+1,1,2)+a[i]);
			}
			if(ml==2)
			ans=Math.max(ans, dp(i+1,1,2)+a[i]);
			ans=Math.max(ans, dp(i+1,2,0));
		}
		if(ma==2)
			ans=Math.max(ans,dp(i+1,2,0));
		return memo[i][ma][ml]=ans;
	}

	static long mod = (long) 1e9 + 7;
	static long[] fact;

	static void fac(int n) {
		fact[0] = 1;
		for (int i = 1; i <= n; i++)
			fact[i] = (1l * i * fact[i - 1]) % mod;
	}

	static int gcd(int a, int b) {

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

	static class unionfind {
		int[] p;
		int[] size;

		unionfind(int n) {
			p = new int[n];
			size = new int[n];

			for (int i = 0; i < n; i++) {
				p[i] = i;
			}
			Arrays.fill(size, 1);
		}

		int findSet(int v) {
			if (v == p[v])
				return v;
			return p[v] = findSet(p[v]);
		}

		boolean sameSet(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return true;
			return false;
		}

		int max() {
			int max = 0;
			for (int i = 0; i < size.length; i++)
				if (size[i] > max)
					max = size[i];
			return max;
		}

		void combine(int a, int b) {
			a = findSet(a);
			b = findSet(b);
			if (a == b)
				return;
			if (size[a] > size[b]) {
				p[b] = a;
				size[a] += size[b];

			} else {
				p[a] = b;
				size[b] += size[a];
			}
		}
	}

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


import java.io.BufferedReader;
// import java.io.FileInputStream;
// import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Math.max;

public class Main {
    FastScanner in;
    PrintWriter out;

    private void solve() throws IOException {
        int n = in.nextInt();
        long x = in.nextLong();
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextLong();

        long[] suffSum = new long[n + 1];
        for (int i = n - 1; i >= 0; i--)
            suffSum[i] = a[i] + max(0, suffSum[i + 1]);

        long maxSum = max(0, suffSum[0]);
        long[] curSum = {0, 0}, nextSum = {0, 0};
        for (int i = 0; i < n; i++) {
            nextSum[0] = a[i] + max(0, curSum[0]);
            nextSum[1] = x * a[i] + max(0, max(curSum[0], curSum[1]));
            curSum[0] = nextSum[0];
            curSum[1] = nextSum[1];
            maxSum = max(maxSum, max(0, max(curSum[0], curSum[1])) + max(0, suffSum[i + 1]));
        }
        out.println(maxSum);
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

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

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

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

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

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

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

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream("input.txt"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream("output.txt"));

        solve();

        out.flush();
        out.close();
    }

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


//created by Whiplash99
import java.io.*;
import java.util.*;
public class zEffi
{
    private static void calc(long[] a, long[] dp, int start, int end, int incr, int[] pos,int N)
    {
        int zero=incr==1?0:N+1;
        Arrays.fill(pos,zero);

        for(int i=start;i!=end;i+=incr)
        {
            if(0>a[i]&&0>a[i]+dp[i-incr]) pos[i]=zero;
            else if(a[i]>=a[i]+dp[i-incr]) pos[i]=i;
            else pos[i]=pos[i-incr];

            dp[i] = Math.max(Math.max(0, a[i]), a[i] + dp[i - incr]);
        }
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String[] s=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long[] a=new long[N+5];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i+1]=Integer.parseInt(s[i]);

        long[] prefMax=new long[N+5];
        long[] prefMin=new long[N+5];
        long[] sufMax=new long[N+5];
        long[] sufMin=new long[N+5];
        int[] posP=new int[N+5];
        int[] posS=new int[N+5];

        calc(a,prefMax,1,N+1,1,posP,N);
        calc(a,sufMax,N,0,-1,posS,N);

        for(i=1;i<=N;i++) a[i]=-a[i];
        calc(a,prefMin,1,N+1,1,posP,N);
        calc(a,sufMin,N,0,-1,posS,N);

        long ans=0;
        for(i=1;i<=N;i++) ans=Math.max(ans,prefMax[i]);

        ans=Math.max(ans,ans*X);

        for (i = 0; i <= N; i++)
        {
            long tmp=prefMax[i] - sufMin[i + 1] * X+sufMax[posS[i]+1];
            if(tmp>ans)
            {
                ans = tmp;
            }

            tmp=prefMax[Math.max(0,posP[i]-1)]-prefMin[i] * X + sufMax[i + 1];
            if(tmp>ans)
            {
                ans = tmp;
            }
        }
        System.out.println(ans);
    }
}


/*
    https://codeforces.com/blog/entry/66687?#comment-507285
 */

//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long[] a=new long[N+5];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i+1]=Integer.parseInt(s[i]);

        long[] sum=new long[N+5], end=new long[N+5], start=new long[N+5];
        long[] val=new long[N+5], bestL=new long[N+5];

        for(i=1;i<=N;i++) sum[i]=sum[i-1]+a[i]; //prefix sums
        for(i=1;i<=N;i++) end[i]=Math.max(Math.max(end[i-1]+a[i],a[i]),0); //max segment ending at i
        for(i=N;i>=1;i--) start[i]=Math.max(Math.max(start[i+1]+a[i],a[i]),0); //starting at i
        for(i=1;i<=N;i++) val[i]=end[i]-X*sum[i];
        for(i=1;i<=N;i++) bestL[i]=Math.max(bestL[i-1],val[i]); //best position to start segment from

        long ans=0;
        for(i=1;i<=N;i++)
        {
            long v=start[i+1]+X*sum[i]+bestL[i];
            ans=Math.max(ans,v);
        }
        System.out.println(ans);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static int l,r;
    private static long maxSum(long a[], int N)
    {
        long prev=a[0], max=Math.max(prev,0); int l2=0;

        if(max==prev) l=r=0;
        else l=r=-1;

        for(int i=1;i<N;i++)
        {
            prev=Math.max(prev+a[i],a[i]);
            max=Math.max(max,prev);

            if(prev==a[i]) l2=i;
            if(max==prev)
            {
                l=l2;
                r=i;
            }
        }
        return max;
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long a[]=new long[N];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        long max=maxSum(a,N);

        if(X==0) System.out.println(max);
        else if(X>1) System.out.println(X*max);
        else
        {
            for(i=0;i<N;i++) a[i]=-a[i];
            maxSum(a,N);

            for(i=0;i<N;i++) a[i]=-a[i];
            for(i=l;i<=r&&r!=-1;i++) a[i]*=X;

            System.out.println(Math.max(maxSum(a,N),max));
        }
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class D
{
    private static int l,r;
    private static long maxSum(long a[], int N)
    {
        long prev=a[0], max=Math.max(prev,0); int l2=0;

        if(max==prev) l=r=0;
        else l=r=-1;

        for(int i=1;i<N;i++)
        {
            prev=Math.max(prev+a[i],a[i]);
            max=Math.max(max,prev);

            if(prev==a[i]) l2=i;
            if(max==prev)
            {
                l=l2;
                r=i;
            }
        }
        return max;
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long a[]=new long[N];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        long max=maxSum(a,N);

        if(X==0) System.out.println(max);
        else if(X>1) System.out.println(X*max);
        else
        {
            for(i=0;i<N;i++) a[i]=-a[i];
            maxSum(a,N);

            for(i=0;i<N;i++) a[i]=-a[i];
            if(r!=-1&&l!=-1) for(i=l;i<=r;i++) a[i]*=X;

            System.out.println(Math.max(maxSum(a,N),max));
        }
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    private static void calc(long[] a, long[] dp, int start, int end, int incr)
    {
        for(int i=start;i!=end;i+=incr)
            dp[i]=Math.max(Math.max(0,a[i]),a[i]+dp[i-incr]);
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String[] s=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long[] a=new long[N+5];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i+1]=Integer.parseInt(s[i]);

        long[] prefMax=new long[N+5];
        long[] prefMin=new long[N+5];
        long[] sufMax=new long[N+5];
        long[] sufMin=new long[N+5];

        calc(a,prefMax,1,N+1,1);
        calc(a,sufMax,N,0,-1);

        for(i=1;i<=N;i++) a[i]=-a[i];
        calc(a,prefMin,1,N+1,1);
        calc(a,sufMin,N,0,-1);

        long ans=0;
        for(i=1;i<=N;i++) ans=Math.max(ans,prefMax[i]);

        ans=Math.max(ans,ans*X);

        if(X<0)
        {
            for (i = 0; i <= N; i++)
            {
                ans = Math.max(ans, prefMax[i] - sufMin[i + 1] * X);
                ans = Math.max(ans, -prefMin[i] * X + sufMax[i + 1]);
            }
        }
        System.out.println(ans);
    }
}


//created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    private static void calc(long[] a, long[] dp, int start, int end, int incr)
    {
        for(int i=start;i!=end;i+=incr)
            dp[i]=Math.max(Math.max(0,a[i]),a[i]+dp[i-incr]);
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String[] s=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        long X=Integer.parseInt(s[1]);

        long[] a=new long[N+5];
        s=br.readLine().trim().split(" ");
        for(i=0;i<N;i++) a[i+1]=Integer.parseInt(s[i]);

        long[] prefMax=new long[N+5];
        long[] prefMin=new long[N+5];
        long[] sufMax=new long[N+5];
        long[] sufMin=new long[N+5];

        calc(a,prefMax,1,N+1,1);
        calc(a,sufMax,N,0,-1);

        for(i=1;i<=N;i++) a[i]=-a[i];
        calc(a,prefMin,1,N+1,1);
        calc(a,sufMin,N,0,-1);

        long ans=0;
        for(i=1;i<=N;i++) ans=Math.max(ans,prefMax[i]);

        ans=Math.max(ans,ans*X);
        for(i=0;i<=N;i++)
        {
            ans=Math.max(ans,prefMax[i]-sufMin[i+1]*X);
            ans=Math.max(ans,-prefMin[i]*X+sufMax[i+1]);
        }

        System.out.println(ans);
    }
}


import java.awt.*;
import java.math.BigInteger;
import java.util.*;

public class Ada{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),x=sc.nextInt();
        int arr[]=new int[n+1];
        for (int i=1;i<=n;i++){
            arr[i]=sc.nextInt();
        }
        int dp[][]=new int[n+1][3];
        int max=0;
        for (int i=1;i<=n;i++){
            dp[i][0]=Math.max(dp[i-1][0]+arr[i],arr[i]);
            dp[i][1]=Math.max(Math.max(dp[i-1][1]+arr[i]*x,dp[i-1][0]+arr[i]*x),arr[i]*x);
            dp[i][2]=Math.max(Math.max(Math.max(dp[i-1][1]+arr[i],dp[i-1][2]+arr[i]),dp[i-1][0]),arr[i]);
            max=Math.max(Math.max(Math.max(dp[i][1],dp[i][2]),dp[i][0]),max);
        }
        System.out.println(max);
    }
}


import java.awt.*;
import java.math.BigInteger;
import java.util.*;

public class Ada{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),x=sc.nextInt();
        long arr[]=new long[n+1];
        for (int i=1;i<=n;i++){
            arr[i]=sc.nextInt();
        }
        long dp[][]=new long[n+1][3];
        long max=0;
        for (int i=1;i<=n;i++){
            dp[i][0]=Math.max(dp[i-1][0]+arr[i],arr[i]);
            dp[i][1]=Math.max(Math.max(dp[i-1][1]+arr[i]*x,dp[i-1][0]+arr[i]*x),arr[i]*x);
            dp[i][2]=Math.max(Math.max(Math.max(dp[i-1][1]+arr[i],dp[i-1][2]+arr[i]),dp[i-1][0]),arr[i]);
            max=Math.max(Math.max(Math.max(dp[i][1],dp[i][2]),dp[i][0]),max);
        }
        System.out.println(max);
    }
}


import java.awt.*;
import java.math.BigInteger;
import java.util.*;

public class Ada{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt(),x=sc.nextInt();
        long arr[]=new long[n+1];
        for (int i=1;i<=n;i++){
            arr[i]=sc.nextInt();
        }
        long dp[][]=new long[n+1][3];
        long max=0;
        for (int i=1;i<=n;i++){
            dp[i][0]=Math.max(dp[i-1][0]+arr[i],arr[i]);
            dp[i][1]=Math.max(Math.max(dp[i-1][1]+arr[i]*x,dp[i-1][0]+arr[i]*x),arr[i]*x);
            dp[i][2]=Math.max(Math.max(Math.max(dp[i-1][1]+arr[i],dp[i-1][2]+arr[i]),dp[i-1][0]+arr[i]),arr[i]);
            max=Math.max(Math.max(Math.max(dp[i][1],dp[i][2]),dp[i][0]),max);
        }
        System.out.println(max);
    }
}


import java.util.*;

public class Main {
	static long mod = 1000000007;
  static int size = 200000;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;

 	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long x = scanner.nextInt();
		long[] a = new long[n+1];
		for(int i = 1; i <= n; i++){
			a[i] = scanner.nextLong();
		}
		//dp[i][j]:=i番目の数を状態j(0:掛け算せず、かつ和に用いない、1:掛け算せず、和に用いる、2:掛け算し、和に用いる、
		//3:掛け算せず、和に用いる、4:掛け算せず、和に用いない)として使用する時の部分列和の最大値
		long[][] dp = new long[n+1][5];
		for(int i = 1; i <= n; i++){
			dp[i][0] = dp[i-1][0];
			dp[i][1] = Math.max(dp[i-1][0],dp[i-1][1])+a[i];
			dp[i][2] = Math.max(Math.max(dp[i-1][0],dp[i-1][1]),dp[i-1][2])+(long)a[i]*x;
			dp[i][3] = Math.max(Math.max(dp[i-1][0],dp[i-1][1]),Math.max(dp[i-1][2],dp[i-1][3]))+a[i];
			dp[i][4] = Math.max(Math.max(Math.max(dp[i-1][0],dp[i-1][1]),Math.max(dp[i-1][2],dp[i-1][3])),dp[i-1][4]);
		}
		long max = -INF;
		for(int i = 0; i < 5; i++){
			max = Math.max(max, dp[n][i]);
		}
		System.out.println(max);
	}

	public static boolean isPrime(int n){
		if(n == 1) return false;
		if(n == 2 || n == 3) return true;
		for(int i = 2; i <= Math.sqrt(n); i++){
			if(n % i == 0) return false;
		}
		return true;
	}
	// tar の方が数字が大きいかどうか
	static boolean compare(String tar, String src) {
		if (src == null) return true;
		if (src.length() == tar.length()) {
			int len = tar.length();
			for (int i = 0; i < len; i++) {
				if (src.charAt(i) > tar.charAt(i)) {
					return false;
				} else if (src.charAt(i) < tar.charAt(i)) {
					return true;
				}
			}
			return tar.compareTo(src) > 0 ? true : false;
		} else if (src.length() < tar.length()) {
			return true;
		} else if (src.length() > tar.length()) {
			return false;
		}
		return false;
	}
	public static class Edge{
		int to;
		Edge(int to){
			this.to = to;
		}
	}
	public static void swap(long a, long b){
		long tmp = 0;
		if(a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
	}
  static class Pair implements Comparable<Pair>{
    int first, second;
    Pair(int a, int b){
        first = a;
        second = b;
    }
    @Override
    public boolean equals(Object o){
        if (this == o) return true;
        if (!(o instanceof Pair)) return false;
        Pair p = (Pair) o;
        return first == p.first && second == p.second;
    }
    @Override
    public int compareTo(Pair p){
        //return first == p.first ? second - p.second : first - p.first; //firstで昇順にソート
        //return (first == p.first ? second - p.second : first - p.first) * -1; //firstで降順にソート
        return second == p.second ? first - p.first : second - p.second;//secondで昇順にソート
        //return (second == p.second ? first - p.first : second - p.second)*-1;//secondで降順にソート
    }
  }

  //繰り返し二乗法
  public static long pow(long x, long n){
    long ans = 1;
    while(n > 0){
      if((n & 1) == 1){
        ans = ans * x;
        ans %= mod;
      }
      x = x * x % mod;
      n >>= 1;
    }
    return ans;
  }

	public static long div(long x, long y){
		return (x*pow(y, mod-2))%mod;
	}

  //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}

	//nCk % mod
	public static long comb(int n, int k){
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}

	//n! % mod
	public static long fact(int n){
		return fac[n];
	}

	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}

  static class UnionFind {
    int[] parent;
    public UnionFind(int size) {
      parent = new int[size];
      Arrays.fill(parent, -1);
    }
    public boolean unite(int x, int y) {
      x = root(x);
      y = root(y);
      if (x != y) {
        if (parent[y] < parent[x]) {
          int tmp = y;
          y = x;
          x = tmp;
        }
        parent[x] += parent[y];
        parent[y] = x;
        return true;
      }
      return false;
    }
    public boolean same(int x, int y) {
      return root(x) == root(y);
    }
    public int root(int x) {
      return parent[x] < 0 ? x : (parent[x] = root(parent[x]));
    }
    public int size(int x) {
      return -parent[root(x)];
    }
  }
	public static int upperBound(int[] array, int value) {
			 int low = 0;
			 int high = array.length;
			 int mid;
			 while( low < high ) {
					 mid = ((high - low) >>> 1) + low; // (high + low) / 2
					 if( array[mid] <= value ) {
							 low = mid + 1;
					 } else {
							 high = mid;
					 }
			 }
			 return low;
	 }
	 public static final int lowerBound(final int[] arr, final int value) {
    	int low = 0;
    	int high = arr.length;
    	int mid;
    	while (low < high){
        	mid = ((high - low) >>> 1) + low;    //(low + high) / 2 (オーバーフロー対策)
        	if (arr[mid] < value) {
          	low = mid + 1;
        	} else {
            high = mid;
        	}
    	}
    	return low;
		}
  //n,mの最大公約数
  public static long gcd(long n, long m){
    if(m > n) return gcd(m,n);
    if(m == 0) return n;
    return gcd(m, n%m);
  }
	//3要素のソート
	private class Pair2 implements Comparable<Pair2> {
		String s;
		int p;
		int index;
		public Pair2(String s, int p, int index) {
				this.s = s;
				this.p = p;
				this.index = index;
		}

		public int compareTo(Pair2 other) {
				if (s.equals(other.s)) {
						return other.p - this.p;
				}
				return this.s.compareTo(other.s);
		}
	}
	//c -> intに変換
public static int c2i(char c){
	if('A' <= c && c <= 'Z'){
		return c - 'A';
	}else{
		return c - 'a' + 26;
	}
}
// int -> charに変換
public static char i2c(int i){
	if(0 <= i && i < 26){
			return (char)(i + 'A');
	}else{
			return (char)(i + 'a' - 26);
	}
}

}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.regex.*;
import java.util.stream.LongStream;

public class Main{

	static ArrayList a[]=new ArrayList[200001];

	public static void main(String[] args)
   {
       InputReader in=new InputReader(System.in);
       PrintWriter pw = new PrintWriter(System.out);
       int n=in.nextInt();
       long d=in.nextLong();
       long a[]=new long[n];
       for(int i=0;i<n;i++)
    	   a[i]=in.nextLong();
       long pre[]=new long[n+1];
       long suf[]=new long[n+1];
       pair mini[]=new pair [n+1];
       long sum=0L;
       int start=0;
       long mul=0L;
       long ans=0;
       for(int i=0;i<n;i++) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(a[i]>0) {
    			   sum=a[i];
    		   }
    		   if(d>0 && i!=0) {
    			   ans=Math.max(ans, pre[i-1]+(d-1)*mul);
    		   }
    		   ans=Math.max(ans,(i!=0)?pre[i-1]:0);
    		   pre[i]=a[i];
    		   mul=pre[i];
    	   }
    	   else
    	   {
    		   pre[i]=sum;
    		   if(pre[i]>mul) {
    			   mul=pre[i];
    		   }
    	   }
       }
       if(d>0) {
		   ans=Math.max(ans, pre[n-1]+(d-1)*mul);
	   }
       ans=Math.max(ans, pre[n-1]);
       sum=0L;
       for(int i=n-1;i>=0;i--) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(a[i]>0) {
    			   sum=a[i];
    		   }
    		   suf[i]=a[i];
    	   }
    	   else
    	   {
    		   suf[i]=sum;
    	   }
       }
       start=-1;
       if(d<0) {
    	   sum=0L;

    	   for(int i=0;i<n;i++) {
    		   sum+=a[i];
    		 if(sum>0) {
    			 sum=0;
    			 start=-1;
    		 }
    		 else{
    			 if(start==-1) {
    				 start=i-1;
    			 }
        		 ans=Math.max(ans,sum*d+((start!=-1)?pre[start]:0)+((i!=n-1)?suf[i+1]:0));
    		 }

    	   }
       }
       pw.println(ans);

       pw.flush();
       pw.close();

    }
         private static void debug(Object... o) {
     		System.out.println(Arrays.deepToString(o));
     	}
        static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

        public String readString()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine()
        {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
        public static long mod = 1000000007;
        public static int d;
        public static int p;
        public static int q;

        public static int[] suffle(int[] a,Random gen)
        {
            int n = a.length;
            for(int i=0;i<n;i++)
            {
                int ind = gen.nextInt(n-i)+i;
                int temp = a[ind];
                a[ind] = a[i];
                a[i] = temp;
            }
            return a;
        }

        public static void swap(int a, int b){
            int temp = a;
            a = b;
            b = temp;
        }

        public static void sieve(boolean[] isPrime,int n)
        {
            for(int i=1;i<n;i++)
                isPrime[i] = true;

            isPrime[0] = false;
            isPrime[1] = false;

            for(int i=2;i*i<n;i++)
            {
                if(isPrime[i] == true)
                {
                    for(int j=(2*i);j<n;j+=i)
                        isPrime[j] = false;
                }
            }
        }

        public static int GCD(int a,int b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static long GCD(long a,long b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static void extendedEuclid(int A,int B)
        {
            if(B==0)
            {
                d = A;
                p = 1 ;
                q = 0;
            }
            else
            {
                extendedEuclid(B, A%B);
                int temp = p;
                p = q;
                q = temp - (A/B)*q;
            }
        }

        public static long LCM(long a,long b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int LCM(int a,int b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int binaryExponentiation(int x,int n)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static long binaryExponentiation(long x,long n)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static int modularExponentiation(int x,int n,int M)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result * x)%M;
                x=(x%M*x)%M;
                n=n/2;
            }
            return result;
        }

        public static long modularExponentiation(long x,long n,long M)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result%M * x%M)%M;
                x=(x%M * x%M)%M;
                n=n/2;
            }
            return result;
        }

        public static long modInverse(int A,int M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static long modInverse(long A,long M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static boolean isPrime(int n)
        {

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

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

            return true;
        }

         public static long[] shuffle(long[] a, Random gen){
                for(int i = 0, n = a.length;i < n;i++){
                    int ind = gen.nextInt(n-i)+i;
                    long d = a[i];
                    a[i] = a[ind];
                    a[ind] = d;
                }
                return a;
            }
         static class pair implements Comparable<pair>{
             Long x;
             Integer y;
             pair(long sum,int id){
                 this.x=sum;
                 this.y=id;
             }
              public int compareTo(pair o) {
                     int result = x.compareTo(o.x);
                     if(result==0)
                         result = y.compareTo(o.y);

                 return result;
                 }
              public String toString(){
                 return (x+" "+y);
             }
       }
        static class query{
        	Long x;
        	Integer y;
        	query(long x,int y){
        		this.x=x;
        		this.y=y;
        	}
        	public String toString(){
                return (x+" "+y);
            }
        }

}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.regex.*;
import java.util.stream.LongStream;

public class Main{

	static ArrayList a[]=new ArrayList[200001];

	public static void main(String[] args)
   {
       InputReader in=new InputReader(System.in);
       PrintWriter pw = new PrintWriter(System.out);
       int n=in.nextInt();
       long d=in.nextLong();
       long a[]=new long[n];
       for(int i=0;i<n;i++)
    	   a[i]=in.nextLong();
       long pre[]=new long[n+1];
       long suf[]=new long[n+1];
       pair mini[]=new pair [n+1];
       long sum=0L;
       int start=0;
       long mul=0L;
       long ans=0;
       for(int i=0;i<n;i++) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(a[i]>0) {
    			   sum=a[i];
    		   }
    		   if(d>0 && i!=0) {
    			   ans=Math.max(ans, pre[i-1]+(d-1)*mul);
    		   }
    		   ans=Math.max(ans,(i!=0)?pre[i-1]:0);
    		   pre[i]=sum;
    		   mul=sum;
    	   }
    	   else
    	   {
    		   pre[i]=sum;
    		   if(pre[i]>mul) {
    			   mul=pre[i];
    		   }
    	   }
       }
       if(d>0) {
		   ans=Math.max(ans, pre[n-1]+(d-1)*mul);
	   }
       ans=Math.max(ans, pre[n-1]);
       sum=0L;
       for(int i=n-1;i>=0;i--) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(a[i]>0) {
    			   sum=a[i];
    		   }
    		   suf[i]=sum;
    	   }
    	   else
    	   {
    		   suf[i]=sum;
    	   }
       }
       start=-1;
       if(d<0) {
    	   sum=0L;

    	   for(int i=0;i<n;i++) {
    		   sum+=a[i];
    		 if(sum>0) {
    			 sum=0;
    			 start=-1;
    		 }
    		 else{
    			 if(start==-1) {
    				 start=i-1;
    			 }
        		 ans=Math.max(ans,sum*d+((start!=-1)?pre[start]:0)+((i!=n-1)?suf[i+1]:0));
    		 }

    	   }
       }
       pw.println(ans);

       pw.flush();
       pw.close();

    }
         private static void debug(Object... o) {
     		System.out.println(Arrays.deepToString(o));
     	}
        static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

        public String readString()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine()
        {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
        public static long mod = 1000000007;
        public static int d;
        public static int p;
        public static int q;

        public static int[] suffle(int[] a,Random gen)
        {
            int n = a.length;
            for(int i=0;i<n;i++)
            {
                int ind = gen.nextInt(n-i)+i;
                int temp = a[ind];
                a[ind] = a[i];
                a[i] = temp;
            }
            return a;
        }

        public static void swap(int a, int b){
            int temp = a;
            a = b;
            b = temp;
        }

        public static void sieve(boolean[] isPrime,int n)
        {
            for(int i=1;i<n;i++)
                isPrime[i] = true;

            isPrime[0] = false;
            isPrime[1] = false;

            for(int i=2;i*i<n;i++)
            {
                if(isPrime[i] == true)
                {
                    for(int j=(2*i);j<n;j+=i)
                        isPrime[j] = false;
                }
            }
        }

        public static int GCD(int a,int b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static long GCD(long a,long b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static void extendedEuclid(int A,int B)
        {
            if(B==0)
            {
                d = A;
                p = 1 ;
                q = 0;
            }
            else
            {
                extendedEuclid(B, A%B);
                int temp = p;
                p = q;
                q = temp - (A/B)*q;
            }
        }

        public static long LCM(long a,long b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int LCM(int a,int b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int binaryExponentiation(int x,int n)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static long binaryExponentiation(long x,long n)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static int modularExponentiation(int x,int n,int M)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result * x)%M;
                x=(x%M*x)%M;
                n=n/2;
            }
            return result;
        }

        public static long modularExponentiation(long x,long n,long M)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result%M * x%M)%M;
                x=(x%M * x%M)%M;
                n=n/2;
            }
            return result;
        }

        public static long modInverse(int A,int M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static long modInverse(long A,long M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static boolean isPrime(int n)
        {

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

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

            return true;
        }

         public static long[] shuffle(long[] a, Random gen){
                for(int i = 0, n = a.length;i < n;i++){
                    int ind = gen.nextInt(n-i)+i;
                    long d = a[i];
                    a[i] = a[ind];
                    a[ind] = d;
                }
                return a;
            }
         static class pair implements Comparable<pair>{
             Long x;
             Integer y;
             pair(long sum,int id){
                 this.x=sum;
                 this.y=id;
             }
              public int compareTo(pair o) {
                     int result = x.compareTo(o.x);
                     if(result==0)
                         result = y.compareTo(o.y);

                 return result;
                 }
              public String toString(){
                 return (x+" "+y);
             }
       }
        static class query{
        	Long x;
        	Integer y;
        	query(long x,int y){
        		this.x=x;
        		this.y=y;
        	}
        	public String toString(){
                return (x+" "+y);
            }
        }

}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.regex.*;
import java.util.stream.LongStream;

public class Main{

	static ArrayList a[]=new ArrayList[200001];

	public static void main(String[] args)
   {
       InputReader in=new InputReader(System.in);
       PrintWriter pw = new PrintWriter(System.out);
       int n=in.nextInt();
       long d=in.nextLong();
       long a[]=new long[n];
       for(int i=0;i<n;i++)
    	   a[i]=in.nextLong();
       long pre[]=new long[n+1];
       long suf[]=new long[n+1];
       long sum=0L;
       int start=0;
       long mul=0L;
       long ans=0;
       long maxi[]=new long[n+1];
       for(int i=0;i<n;i++) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(d>0 && i!=0) {
    			   ans=Math.max(ans, pre[i-1]+(d-1)*mul);
    		   }
    		   ans=Math.max(ans,(i!=0)?pre[i-1]:0);
    		   pre[i]=sum;
    		   mul=sum;
    	   }
    	   else
    	   {
    		   pre[i]=sum;
    		   if(pre[i]>mul) {
    			   mul=pre[i];
    		   }
    		   if(d>0) {
    			   ans=Math.max(ans, pre[i]+(d-1)*mul);
    		   }
    	   }
    	   if(i!=0)
    	   maxi[i]=Math.max(maxi[i-1], pre[i]);
    	   else
    		   maxi[i]=pre[i];
       }
       if(d>0) {
		   ans=Math.max(ans, pre[n-1]+(d-1)*mul);
	   }
       ans=Math.max(ans, pre[n-1]);
	   long fi=0;

       sum=0L;
       for(int i=n-1;i>=0;i--) {
    	   sum+=a[i];
    	   if(sum<0) {
    		   sum=0;
    		   if(a[i]>0) {
    			   sum=a[i];
    		   }
    		   suf[i]=sum;
    	   }
    	   else
    	   {
    		   suf[i]=sum;
    	   }
       }
       if(d==0) {
    	   for(int i=n-1;i>=0;i--) {
    		  ans=Math.max(ans,maxi[i]+suf[i+1]);
    	   }
       }
       start=-1;
       if(d<0) {
    	   sum=0L;
    	   long got=0L;
    	   for(int i=0;i<n;i++) {
    		  sum+=a[i];
    		 if(sum>0) {
    			 sum=0;
    			 got=0;
    			 start=-1;
    		 }
    		 else{
    			 if(start==-1) {
    				 start=i-1;
    				 if(start!=-1)
    				 got=pre[start];
    			 }
    			 if(got+sum*d<pre[i]) {
    				 got=pre[i];
    				 start=i;
    				 sum=0;
    			 }
        		 ans=Math.max(ans,sum*d+((start!=-1)?pre[start]:0)+((i!=n-1)?suf[i+1]:0));
    		 }
    	   }
       }
       pw.println(ans);

       pw.flush();
       pw.close();

    }
         private static void debug(Object... o) {
     		System.out.println(Arrays.deepToString(o));
     	}
        static class InputReader
        {
        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
        public int snext()
        {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars)
            {
                curChar = 0;
                try
                {
                    snumChars = stream.read(buf);
                }

                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

        public int[] nextIntArray(int n)
        {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = nextInt();
            }
            return a;
        }
        static class tri implements Comparable<tri> {
            int p, c, l;

            tri(int p, int c, int l) {
                this.p = p;
                this.c = c;
                this.l = l;
            }

            public int compareTo(tri o) {
                return Integer.compare(l, o.l);
            }
        }

        public String readString()
        {
            int c = snext();
            while (isSpaceChar(c))
            {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine()
        {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
        public static long mod = 1000000007;
        public static int d;
        public static int p;
        public static int q;

        public static int[] suffle(int[] a,Random gen)
        {
            int n = a.length;
            for(int i=0;i<n;i++)
            {
                int ind = gen.nextInt(n-i)+i;
                int temp = a[ind];
                a[ind] = a[i];
                a[i] = temp;
            }
            return a;
        }

        public static void swap(int a, int b){
            int temp = a;
            a = b;
            b = temp;
        }

        public static void sieve(boolean[] isPrime,int n)
        {
            for(int i=1;i<n;i++)
                isPrime[i] = true;

            isPrime[0] = false;
            isPrime[1] = false;

            for(int i=2;i*i<n;i++)
            {
                if(isPrime[i] == true)
                {
                    for(int j=(2*i);j<n;j+=i)
                        isPrime[j] = false;
                }
            }
        }

        public static int GCD(int a,int b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static long GCD(long a,long b)
        {
            if(b==0)
                return a;
            else
                return GCD(b,a%b);
        }

        public static void extendedEuclid(int A,int B)
        {
            if(B==0)
            {
                d = A;
                p = 1 ;
                q = 0;
            }
            else
            {
                extendedEuclid(B, A%B);
                int temp = p;
                p = q;
                q = temp - (A/B)*q;
            }
        }

        public static long LCM(long a,long b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int LCM(int a,int b)
        {
            return (a*b)/GCD(a,b);
        }

        public static int binaryExponentiation(int x,int n)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static long binaryExponentiation(long x,long n)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=result * x;
                x=x*x;
                n=n/2;
            }
            return result;
        }

        public static int modularExponentiation(int x,int n,int M)
        {
            int result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result * x)%M;
                x=(x%M*x)%M;
                n=n/2;
            }
            return result;
        }

        public static long modularExponentiation(long x,long n,long M)
        {
            long result=1;
            while(n>0)
            {
                if(n % 2 ==1)
                    result=(result%M * x%M)%M;
                x=(x%M * x%M)%M;
                n=n/2;
            }
            return result;
        }

        public static long modInverse(int A,int M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static long modInverse(long A,long M)
        {
            return modularExponentiation(A,M-2,M);
        }

        public static boolean isPrime(int n)
        {

            if (n <= 1)  return false;
            if (n <= 3)  return true;

            if (n%2 == 0 || n%3 == 0)
                return false;

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

            return true;
        }

         public static long[] shuffle(long[] a, Random gen){
                for(int i = 0, n = a.length;i < n;i++){
                    int ind = gen.nextInt(n-i)+i;
                    long d = a[i];
                    a[i] = a[ind];
                    a[ind] = d;
                }
                return a;
            }
         static class pair implements Comparable<pair>{
             Long x;
             Integer y;
             pair(long sum,int id){
                 this.x=sum;
                 this.y=id;
             }
              public int compareTo(pair o) {
                     int result = x.compareTo(o.x);
                     if(result==0)
                         result = y.compareTo(o.y);

                 return result;
                 }
              public String toString(){
                 return (x+" "+y);
             }
       }
        static class query{
        	Long x;
        	Integer y;
        	query(long x,int y){
        		this.x=x;
        		this.y=y;
        	}
        	public String toString(){
                return (x+" "+y);
            }
        }

}


import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long x=sc.nextLong();
		long a[]=new long[n];
		for( int i=0;i<n;i++)
		{
			a[i]=sc.nextLong();
		}
		long dp[][]=new long[100001][5];
		for( int i=0;i<n;i++)
		{
			dp[i+1][0]=dp[i][0];
			//System.out.println(dp[i+1][0]);
			dp[i+1][1]=Math.max(dp[i+1][0],dp[i][1]+a[i]);
			dp[i+1][2]=Math.max(dp[i+1][1],dp[i][2]+a[i]*x);
			dp[i+1][3]=Math.max(dp[i+1][2],dp[i][3]+a[i]);
			dp[i+1][4]=Math.max(dp[i+1][4],Math.max(dp[i+1][0],Math.max(dp[i+1][1],Math.max(dp[i+1][3],dp[i+1][2]))));
			//System.out.println(dp[i+1][4]);
		}
		System.out.println(dp[n][4]);
	}
}


import java.io.*;
import java.util.*;
public class Main
{
	static int s=0,e=0;
	public static long maxSubArraySum(long a[],int size)
{

    long max_so_far = 0, max_ending_here = 0;

    for (int i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_ending_here < 0)
		{
			max_ending_here = 0;
			s=i+1;
			e=i+1;
		}

        else if (max_so_far < max_ending_here)
		{
			max_so_far = max_ending_here;
				e=i;
		}

    }
    return max_so_far;
}
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int x=sc.nextInt();
		long a[]=new long[n];
		long b[]=new long[n];

		for( int i=0;i<n;i++)
		{
			a[i]=sc.nextLong();
			b[i]=a[i];
			if(x<0)
			{
				a[i]=-a[i];
			}

		}
		long ans=maxSubArraySum(a,n);
		long sum=0;long sum1=0;
		for( int i=0;i<n;i++)
		{
			if(i>=s&&i<=e)
			{
				b[i]=(b[i]*x);
			}

		}
		long ans1=maxSubArraySum(b,n);
		if((ans1)<0)
			System.out.println(0);
		else

		System.out.println(ans1);
	}
}


import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long x=sc.nextLong();
		long a[]=new long[n];
		for( int i=0;i<n;i++)
		{
			a[i]=sc.nextLong();
		}
		long dp[][]=new long[100001][5];
		for( int i=0;i<n;i++)
		{
			dp[i+1][0]=dp[i][0];
			//System.out.println(dp[i+1][0]);
			dp[i+1][1]=Math.max(dp[i+1][0],dp[i][1]+a[i]);
			dp[i+1][2]=Math.max(dp[i+1][1],dp[i][2]+a[i]*x);
			dp[i+1][3]=Math.max(dp[i+1][2],dp[i][3]+a[i]);
			dp[i+1][4]=(long)Math.max((long)dp[i+1][4],Math.max((long)dp[i+1][0],Math.max((long)dp[i+1][1],Math.max((long)dp[i+1][3],(long)dp[i+1][2]))));
			//System.out.println(dp[i+1][4]);
		}
		System.out.println(dp[n][4]);
	}
}


import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long x=sc.nextLong();
		long a[]=new long[n];
		for( int i=0;i<n;i++)
		{
			a[i]=sc.nextLong();
		}
		long dp[][]=new long[300004][5];
		for( int i=0;i<n;i++)
		{
			dp[i+1][0]=dp[i][0];
			//System.out.println(dp[i+1][0]);
			dp[i+1][1]=Math.max(dp[i+1][0],dp[i][1]+a[i]);
			dp[i+1][2]=Math.max(dp[i+1][1],dp[i][2]+a[i]*x);
			dp[i+1][3]=Math.max(dp[i+1][2],dp[i][3]+a[i]);
			dp[i+1][4]=(long)Math.max(dp[i][4],Math.max((long)dp[i+1][4],Math.max((long)dp[i+1][0],Math.max((long)dp[i+1][1],Math.max((long)dp[i+1][3],(long)dp[i+1][2])))));
			//System.out.println(dp[i+1][4]);
		}
		System.out.println(dp[n][4]);
	}
}


import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long x=sc.nextLong();
		long a[]=new long[n];
		for( int i=0;i<n;i++)
		{
			a[i]=sc.nextLong();
		}
		long dp[][]=new long[300004][5];
		for( int i=0;i<n;i++)
		{
			dp[i+1][0]=dp[i][0];
			//System.out.println(dp[i+1][0]);
			dp[i+1][1]=Math.max(dp[i+1][0],dp[i][1]+a[i]);
			dp[i+1][2]=Math.max(dp[i+1][1],dp[i][2]+a[i]*x);
			dp[i+1][3]=Math.max(dp[i+1][2],dp[i][3]+a[i]);
			dp[i+1][4]=(long)Math.max((long)dp[i+1][4],Math.max((long)dp[i+1][0],Math.max((long)dp[i+1][1],Math.max((long)dp[i+1][3],(long)dp[i+1][2]))));
			//System.out.println(dp[i+1][4]);
		}
		System.out.println(dp[n][4]);
	}
}


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

public class Cony {
    static int n ;
	static long L[] = new long[n];
	static long R[] = new long[n];
	static long S[] = new long[n];
	static long tab[] = new long[n];
	static int x ;
	static void create_S()
	{
		S[0]=tab[0] ;
		for(int i=1 ; i<n ;i++) S[i]+=(S[i-1]+tab[i]) ;
	}

	static void createL_And_R()
	{
		if(tab[0]>=0) L[0]=tab[0] ;
		if(tab[n-1]>=0) R[n-1]=tab[n-1] ;
		for(int i=1 ; i<n ;i++)
		{
			L[i]+=tab[i] ;
			if(L[i-1]>=0) L[i]+=L[i-1] ;
			L[i]=Long.max(0, L[i]) ;
		}
		for(int i=n-2 ; i>=0 ;i--)
		{
			R[i]+=tab[i] ;
			if(R[i+1]>=0) R[i]+=R[i+1] ;
			R[i]=Long.max(0, R[i]) ;
		}
	}
	static void create_new_L_AND_R()
	{
		for(int i=n-1 ; i>0 ;i--) L[i]= L[i-1]-x*S[i-1] ;
		L[0]=0 ;
		for(int i=0 ; i<n-1 ; i++) R[i]= R[i+1]+ x*S[i] ;
		R[n-1]= x*S[n-1]  ;

	}
	static void createMaxR()
	{
		for(int i = n-2 ; i>=0 ;i--) R[i]= Long.max(R[i], R[i+1]) ;
	}

	static long solve()
	{
		create_S();
		createL_And_R();
		create_new_L_AND_R();
		createMaxR();
		long res = 0 ;
		for(int i=0 ; i<n ;i++)
		{
			long ans = L[i]+R[i]  ;
			res = Long.max(res, ans) ;
		}
		return res ;
	}

	public static void main(String[] args) throws IOException
	{

		BufferedReader jk = new BufferedReader(new InputStreamReader(System.in)) ;
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)) ;
		StringTokenizer ana = new StringTokenizer(jk.readLine()) ;
		n = Integer.parseInt(ana.nextToken()) ;
	    x =  Integer.parseInt(ana.nextToken()) ;
	    tab = new long[n] ;
	    ana = new StringTokenizer(jk.readLine()) ;
		for(int i=0 ;i< n ;i++)
		{
			tab[i]= Long.parseLong(ana.nextToken()) ;
		}
		 L = new long[n] ;
		 R = new long[n] ;
		 S = new long[n] ;
         long ans = 0 ;
         long s = 0 ;
         for(int i = 0 ; i< n ;i++)
         {
        	 s+= tab[i] ;
        	 s= Long.max(0, s) ;
        	 ans = Long.max(ans, s) ;
         }
         ans  = Long.max(solve(), ans) ;
        System.out.println(ans);

		out.flush();

	}
}


import java.util.Scanner;

public class MainE {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			long[] e = new long[n+1];
			for(int i=1;i<=n;i++) {
				e[i] = sc.nextLong();
			}
			if(m>0) {
				long[] dp = new long[n+1];
				int[][] mark = new int[n+1][2];
				mark[1][0] = 1;
				mark[1][1] = 1;
				dp[1] = e[1];
				long max = dp[1];
				int u = 0,v = 0;
				for(int i=2;i<=n;i++) {
					if((long)dp[i-1]+e[i]<e[i]) {
						dp[i]=e[i];
						mark[i][0] = i;
						mark[i][1] = i;
					}else {
						dp[i]=(long)dp[i-1]+e[i];
						mark[i][0] = mark[i-1][0];
						mark[i][1] = mark[i-1][1] + 1;
					}
					if(dp[i]>max) {
						max = dp[i];
						u = mark[i][0];
						v = mark[i][1];
					}
				}
				System.out.println(max<=0?0:max*m);
			}else {
				long[] dp = new long[n+1];
				int[][] mark = new int[n+1][2];
				mark[1][0] = 1;
				mark[1][1] = 1;
				dp[1] = e[1];
				long min = dp[1];
				int u = 0,v = 0;
				for(int i=2;i<=n;i++) {
					if((long)dp[i-1]+e[i]>e[i]) {
						dp[i]=e[i];
						mark[i][0] = i;
						mark[i][1] = i;
					}else {
						dp[i]=(long)dp[i-1]+e[i];
						mark[i][0] = mark[i-1][0];
						mark[i][1] = mark[i-1][1] + 1;
					}
					if(dp[i]<=min) {
						min = dp[i];
						u = mark[i][0];
						v = mark[i][1];
					}
				}
				if(min>=0) {
					long sum = 0;
					for(int i=1;i<=n;i++) {
						sum += e[i];
					}
					System.out.println(sum);
				}else {
					for(int i=u;i<=v;i++) {
						e[i]=(long)e[i]*m;
					}
					long max = 0;
					for(int i=1;i<=n;i++) {
						if(dp[i-1]+e[i]<e[i]) {
							dp[i]=e[i];
						}else {
							dp[i]=(long)dp[i-1]+e[i];
						}
						if(dp[i]>max) {
							max = dp[i];
						}
					}
					System.out.println(max);
				}
			}
		}
	}
}


import java.util.Scanner;
import java.util.HashMap;

public class MainE {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int[] e = new int[n + 1];
			for (int i = 1; i <= n; i++) {
				e[i] = sc.nextInt();
			}
			if (x > 0) {
				long[] dp = new long[n + 1];
				long max = 0;
				for (int i = 1; i <= n; i++) {
					dp[i] = Math.max(dp[i - 1] + e[i], e[i]);
					max = Math.max(dp[i], max);
				}
				System.out.println(max > 0 ? max : 0);
			} else {
				long min = 0;
				int u = 0, v = 0;
				long[] dp = new long[n + 1];
				int[][] mark = new int[n + 1][2];
				long ans = 0;
				for (int i = 1; i <= n; i++) {
					if (dp[i - 1] + e[i] >= e[i]) {
						dp[i] = e[i];
						mark[i][0] = i;
						mark[i][1] = i;
					} else {
						dp[i] = dp[i - 1] + e[i];
						mark[i][0] = mark[i - 1][0];
						mark[i][1] = mark[i - 1][1] + 1;
					}
					if (dp[i] < min) {
						min = dp[i];
						u = mark[i][0];
						v = mark[i][1];
						ans = ha(e, u, v, x);
					} else if (dp[i] == min) {
						long anss = ha(e, mark[i][0], mark[i][1], x);
						if (anss > ans) {
							u = mark[i][0];
							v = mark[i][1];
							min = dp[i];
						}
					}
				}
				if (min == 0) {
					long sum = 0;
					for (int i = 1; i <= n; i++) {
						sum = (long) sum + e[i];
					}
					System.out.println(sum);
				} else {
					 System.out.println(u+" "+v);
					System.out.println(ans);
				}
			}
		}
	}

	public static long ha(int[] e, int u, int v, int x) {
		long ans = 0;
		long[] ee = new long[e.length];
		for (int i = u; i <= v; i++) {
			ee[i] = (long) e[i] * x;
		}
		if (u > 1) {
			for (int i = 1; i < u; i++) {
				ee[i] = e[i];
			}
		}
		if (v < e.length - 1) {
			for (int i = v + 1; i < e.length; i++) {
				ee[i] = e[i];
			}
		}
		long[] dp = new long[ee.length];
		long max = 0;
		for (int i = 1; i < ee.length; i++) {
			dp[i] = Math.max(dp[i - 1] + ee[i], ee[i]);
			max = Math.max(dp[i], max);
		}
		return max;
	}
}


#include<bits/stdc++.h>
#define MAXN 500009
#define INF 1000000007
#define LLINF 1000000000000000007
#define mp(x,y) make_pair(x,y)
#define wr cout<<"Continue Debugging!!!"<<endl;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(i, c) for(typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int arr[MAXN],vis[MAXN],from[MAXN*3],pr[MAXN*3],cnt[MAXN*3];
ll ans=0,cheer=0;
vector<int>adj[MAXN*3];
void dfs(int h,int k){
	if(k<=1)
		return;
	int fup=from[k];
	while(k%fup==0)
		k/=fup;
	adj[h].pb(fup);
	dfs(h,k);
}
void f(int x,int val,int gen,int bit){
	if(x==adj[gen].size()){
		if(!bit)
			cheer-=cnt[val];
		else
			cheer+=cnt[val];
		return;
	}
	f(x+1,val,gen,bit);
	f(x+1,val*adj[gen][x],gen,bit^1);
}
void f1(int x,int val,int gen){
	if(x==adj[gen].size())
		return;
	cnt[val*adj[gen][x]]++;
	f1(x+1,val,gen);
	f1(x+1,val*adj[gen][x],gen);
}
void f2(int x,int val,int gen){
	if(x==adj[gen].size())
		return;
	cnt[val*adj[gen][x]]--;
	f2(x+1,val,gen);
	f2(x+1,val*adj[gen][x],gen);
}
int main(){
	int n,q,sz=0;
	scanf("%d%d",&n,&q);
	for(int i=2;i<MAXN*3;i++){
		if(pr[i])
			continue;
		for(int j=i;j<MAXN*3;j+=i){
			pr[j]=1;
			from[j]=i;
		}
	}
	for(int i=1;i<=n;i++){
		scanf("%d",arr+i);
		int t1=arr[i];
		dfs(t1,t1);
	}
	while(q--){
		int x;
		scanf("%d",&x);
		int y=arr[x];
		if(vis[x]){
			f2(0,1,y);
			sz--;
			cheer=0;
			f(0,1,y,0);
			ans-=sz-cheer;
		}
		else{
			cheer=0;
			f(0,1,y,0);
			f1(0,1,y);
			ans+=sz-cheer;
			sz++;
		}
		vis[x]=!vis[x];
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define MAXN 300009
#define INF 1000000007
#define LLINF 1000000000000000007
#define mp(x,y) make_pair(x,y)
#define wr cout<<"Continue Debugging!!!"<<endl;
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define ppb() pop_back()
#define tr(i, c) for(typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T> bool umin(T& a, T b) { if(a > b){ a = b;return 1;}return 0;}
template<class T> bool umax(T& a, T b) { if(a < b){ a = b;return 1;}return 0;}
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
int arr[MAXN],vis[MAXN],from[MAXN*3],pr[MAXN*3],cnt[MAXN*30];
ll ans=0,cheer=0;
vector<int>adj[MAXN*3];
void dfs(int h,int k){
	while(k!=1){
		int fup=pr[k];
		adj[h].pb(fup);
		while(k%fup==0)
			k/=fup;
	}
}
void f(int x,int val,int gen,int bit){
	if(x==adj[gen].size()){
		if(!bit)
			cheer-=cnt[val];
		else
			cheer+=cnt[val];
		return;
	}
	f(x+1,val,gen,bit);
	f(x+1,val*adj[gen][x],gen,bit^1);
}
void f1(int x,int val,int gen){
	if(x==adj[gen].size())
		return;
	cnt[val*adj[gen][x]]++;
	f1(x+1,val,gen);
	f1(x+1,val*adj[gen][x],gen);
}
void f2(int x,int val,int gen){
	if(x==adj[gen].size())
		return;
	cnt[val*adj[gen][x]]--;
	f2(x+1,val,gen);
	f2(x+1,val*adj[gen][x],gen);
}
int main(){
	int n,q,sz=0;
	scanf("%d%d",&n,&q);
	for(int i=2;i<MAXN*3;i++){
		if(pr[i])
			continue;
		for(int j=i;j<MAXN*3;j+=i)
			pr[j]=i;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",arr+i);
		int t1=arr[i];
		dfs(t1,t1);
	}
	while(q--){
		int x;
		scanf("%d",&x);
		int y=arr[x];
		if(vis[x]){
			f2(0,1,y);
			sz--;
			cheer=0;
			f(0,1,y,0);
			ans-=sz-cheer;
		}
		else{
			cheer=0;
			f(0,1,y,0);
			f1(0,1,y);
			ans+=sz-cheer;
			sz++;
		}
		vis[x]=!vis[x];
		printf("%lld\n",ans);
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int Size = 500010;

int N, Q, Tmp, Now;
int Num[Size];
int P[8] = {0, 2, 3, 5, 7, 11, 13, 17};
int Cnt[200], Bit[200], L0, X;
int A[Size];
long long Ans;

void CalC(int D) {
	for (int S = 1; S < 128; ++S) {
		X = S;
		int Flag = 1;
		L0 = 0;
		for ( ; X; X >>= 1) {
			++L0;
			if (!(X & 1)) continue;
			if (Tmp % P[L0]) {
				Flag = 0;
				break;
			}
		}
		if (Flag == 0) continue;
		if (D == 0) --Cnt[S]; else ++Cnt[S];
	}
}

void Solve() {
	scanf("%d", &Tmp);
	Tmp = Num[Tmp];
	if (A[Tmp] == 0) {
		A[Tmp] = 1, ++Now;
		CalC(1);
	}
	else if (A[Tmp] == 1) {
		A[Tmp] = 0, --Now;
		CalC(0);
	}
//	printf("Now = %d\n", Now);
	if (Now < 2) {
		printf("0\n");
		return;
	}
	Ans = 0;
	for (int S = 1; S < 128; ++S) {
//		printf("%d : %d\n", S, Cnt[S]);
		if (Bit[S] % 2) Ans += (long long) Cnt[S] * (Cnt[S] - 1) / 2;
		else Ans -= (long long) Cnt[S] * (Cnt[S] - 1) / 2;
	}
	Ans = (long long) Now * (Now - 1) / 2 - Ans;
	printf("%I64d\n", Ans);
}

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; ++i) scanf("%d", &Tmp), Num[i] = Tmp;
	for (int i = 1; i <= 128; ++i) Bit[i] = Bit[i - (i & -i)] + 1;
	for ( ; Q; --Q) Solve();
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

const int Size = 500010;

int N, Q, Tmp;
int Num[Size], Vis[Size];
int Mu[Size], Cnt[Size];
vector <int> D[Size];
LL Ans;

void Sieve() {
    Mu[1] = 1;
    for (int j = 1; j <= Size - 10; ++j) {
        D[j].push_back(j);
        for (int i = j + j; i <= Size - 10; i += j) {
            D[i].push_back(j);
            Mu[i] -= Mu[j];
        }
    }
}

void Init() {
    scanf("%d%d", &N, &Q);
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &Tmp);
        Num[i] = Tmp;
    }
}

void Solve() {
    scanf("%d", &Tmp);
    Tmp = Num[Tmp];
    if (!Vis[Tmp])
        for (int j = 0; j < D[Tmp].size(); ++j) Ans += (LL) Mu[D[Tmp][j]] * (Cnt[D[Tmp][j]]++);
    else
        for (int j = 0; j < D[Tmp].size(); ++j) Ans -= (LL) Mu[D[Tmp][j]] * (--Cnt[D[Tmp][j]]);
    Vis[Tmp] ^= 1;
    printf("%I64d\n", Ans);
}

int main() {
    Sieve();
    Init();
    for ( ; Q; --Q) Solve();
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

const int Size = 500010;

int N, Q, Tmp;
int Num[Size], Vis[Size];
int Mu[Size], Cnt[Size];
vector <int> D[Size];
LL Ans;

void Sieve() {
    Mu[1] = 1;
    for (int j = 1; j <= Size - 10; ++j) {
        D[j].push_back(j);
        for (int i = j + j; i <= Size - 10; i += j) {
            D[i].push_back(j);
            Mu[i] -= Mu[j];
        }
    }
}

void Init() {
    scanf("%d%d", &N, &Q);
    for (int i = 1; i <= N; ++i) scanf("%d", &Num[i]);
}

void Solve() {
    scanf("%d", &Tmp);
//  Tmp = Num[Tmp];
    if (!Vis[Tmp])
        for (int j = 0; j < D[Tmp].size(); ++j) Ans += (LL) Mu[D[Tmp][j]] * (Cnt[D[Tmp][j]]++);
    else
        for (int j = 0; j < D[Tmp].size(); ++j) Ans -= (LL) Mu[D[Tmp][j]] * (--Cnt[D[Tmp][j]]);
    Vis[Tmp] ^= 1;
    printf("%I64d\n", Ans);
}

int main() {
    Sieve();
    Init();
    for ( ; Q; --Q) Solve();
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

const int Size = 500010;

int N, Q, Tmp;
int A[Size], Vis[Size];
int Mu[Size], Cnt[Size];
vector <int> D[Size];
LL Ans;

void Sieve() {
	Mu[1] = 1;
	for (int j = 1; j <= Size - 10; ++j) {
		D[j].push_back(j);
		for (int i = j + j; i <= Size - 10; i += j) {
			D[i].push_back(j);
			Mu[i] -= Mu[j];
		}
	}
}

void Init() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
}

void Solve() {
	int i;
	scanf("%d", &i);
	if (!Vis[i])
		for (int j = 0; j < D[A[i]].size(); ++j) Ans += (LL) Mu[D[A[i]][j]] * (Cnt[D[A[i]][j]]++);
	else
		for (int j = 0; j < D[A[i]].size(); ++j) Ans -= (LL) Mu[D[A[i]][j]] * (--Cnt[D[A[i]][j]]);
	Vis[i] ^= 1;
	printf("%I64d\n", Ans);
}

int main() {
	Sieve();
	Init();
	for ( ; Q; --Q) Solve();
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

const int Size = 500010;

int N, Q, Tmp;
int A[Size], Vis[Size];
int Mu[Size], Cnt[Size];
vector <int> D[Size];
LL Ans;

void Sieve() {
	Mu[1] = 1;
	for (int j = 1; j <= Size - 10; ++j) {
		D[j].push_back(j);
		for (int i = j + j; i <= Size - 10; i += j) {
			D[i].push_back(j);
			Mu[i] -= Mu[j];
		}
	}
}

void Init() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
}

void Solve() {
	scanf("%d", &i);
	if (!Vis[i])
		for (int j = 0; j < D[A[i]].size(); ++j) Ans += (LL) Mu[D[A[i]][j]] * (Cnt[D[A[i]][j]]++);
	else
		for (int j = 0; j < D[A[i]].size(); ++j) Ans -= (LL) Mu[D[A[i]][j]] * (--Cnt[D[A[i]][j]]);
	Vis[i] ^= 1;
	printf("%I64d\n", Ans);
}

int main() {
	Sieve();
	Init();
	for ( ; Q; --Q) Solve();
}


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 5e5 + 10;

int n , q;
int a[maxn];
long long f[maxn];
bool OnShelf[maxn];
long long Ans;

long long up ( int x , int sgn);

void factor ( int x , vector<int> &v ) {
    v.clear();
    for ( int i = 2 ; i*i <= x ; i++ ) {
        if ( x % i ) continue;
        v.push_back(i);
        while ( x % i  == 0) x /= i;
    }
    if ( x != 1 ) v.push_back(x);
}

int main() {
    //freopen("a.in","r",stdin);
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] , 1);
            now++;
        }
        else {
            now--;
            Ans -= now - up( a[x] , -1 );
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

long long up ( int x , int sgn) {
    vector <int> fact;
    factor ( x , fact );
    int up = fact.size();
    long long ret = 0;
    for ( int k = 1 ; k < ( 1<<up ) ; k++ ) {
       int t = k , count = 0 , cnt = 0 , num = 1;
       while ( t ) {
           if ( t & 1 ) {
               cnt++;
               num *= fact[count];
           }
           count++;
           t >>= 1;
       }
       if ( sgn == -1 ) f[num]--;
       if ( cnt & 1 ) ret += f[num];
       else ret -= f[num];
       if ( sgn == 1 ) f[num]++;
    }
    return ret;
}


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 2e5 + 10;

const int prime[] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 };

int n , q;
int a[maxn];
int f[maxn];
bool OnShelf[maxn];
int Ans;

int up ( int x  , int op);
void down( int x );

int main() {
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] , 1);
            now++;
        }
        else {
            now--;
            Ans -= now - up( a[x] , -1);
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

int up ( int x , int op ) {
    int ret = 0;
    int tmp = 0;
    for ( int i = 0 ; i < 7 ; i++ ) {
        if ( x % prime[i] == 0) tmp += ( 1 << i );
    }
    for ( int k = 1 ; k < ( 1 << 7 ) ; k++ ) {
        int t = tmp & k;
        if ( t == 0 ) continue;
        int count = 0 , cnt = 0;
        int num = 1;
        t = k;
        int tt = t;
        while ( t ) {
            if ( t & 1 ) { num *= prime[count]; cnt++; }
            count++; t >>= 1;
        }
        if ( cnt & 1 ) ret += f[tt] ;
        else ret -= f[tt] ;
    }
    for ( int k = 0 ; k < ( 1 << 7 ) ; k++ ) {
        if ( ~( tmp | ~k ) == 0 ) f[k] += 1 * op;
    }
    return ret;
}

void down ( int x ) {
}

// tmp k ans
//  0  0  0
//  0  1  0
//  1  0  0
//  1  1  1


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 2e5 + 10;

const int prime[] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 };

int n , q;
int a[maxn];
int f[maxn];
bool OnShelf[maxn];
int Ans;

int up ( int x );
int down( int x );

int main() {
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] );
            now++;
        }
        else {
            now--;
            Ans -= now - down( a[x] );
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

int up ( int x ) {
    int ret = 0;
    int tmp = 0;
    for ( int i = 0 ; i < 7 ; i++ ) {
        if ( x % prime[i] == 0) tmp += ( 1 << i );
    }
    for ( int k = 1 ; k < ( 1 << 7 ) ; k++ ) {
        int t = tmp & k;
        if ( t == 0 ) continue;
        int count = 0 , cnt = 0;
        int num = 1;
        t = k;
        int tt = t;
        while ( t ) {
            if ( t & 1 ) { num *= prime[count]; cnt++; }
            count++; t >>= 1;
        }
        if ( cnt & 1 ) ret += f[tt] ;
        else ret -= f[tt] ;
    }
    for ( int k = 0 ; k < ( 1 << 7 ) ; k++ ) {
        if ( ~( tmp | ~k ) == 0 ) f[k] += 1;
    }
    return ret;
}

int down ( int x ) {
    int tmp = 0 ,ret = 0;
    for ( int i = 0 ; i < 7 ; i++ ) {
        if ( x % prime[i] == 0 ) tmp += ( 1 << i );
    }
    for ( int k = 0 ; k < ( 1 << 7 ) ; k++ ) {
        if ( ~(tmp | ~k ) == 0 ) f[k] -= 1;
    }
    for ( int k = 1 ; k < ( 1 << 7 ) ; k++ ) {
        int t = tmp & k;
        if ( t == 0 ) continue;
        t = k;
        int count = 0 , cnt = 0;
        while ( t ) {
            if ( t & 1 ) cnt++;
            count++; t>>=1;
        }
        if ( cnt & 1 ) ret += f[k];
        else ret -= f[k];
    }
    return ret;
}


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 5e5 + 10;

int n , q;
int a[maxn];
long long f[maxn];
bool OnShelf[maxn];
long long Ans;

int up ( int x , int sgn);

void factor ( int x , vector<int> &v ) {
    v.clear();
    for ( int i = 2 ; i*i <= x ; i++ ) {
        if ( x % i ) continue;
        v.push_back(i);
        while ( x % i  == 0) x /= i;
    }
    if ( x != 1 ) v.push_back(x);
}

int main() {
    //freopen("a.in","r",stdin);
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] , 1);
            now++;
        }
        else {
            now--;
            Ans -= now - up( a[x] , -1 );
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

long long up ( int x , int sgn) {
    vector <int> fact;
    factor ( x , fact );
    int up = fact.size();
    long long ret = 0;
    for ( int k = 1 ; k < ( 1<<up ) ; k++ ) {
       int t = k , count = 0 , cnt = 0 , num = 1;
       while ( t ) {
           if ( t & 1 ) {
               cnt++;
               num *= fact[count];
           }
           count++;
           t >>= 1;
       }
       if ( sgn == -1 ) f[num]--;
       if ( cnt & 1 ) ret += f[num];
       else ret -= f[num];
       if ( sgn == 1 ) f[num]++;
    }
    return ret;
}


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 2e5 + 10;

int n , q;
int a[maxn];
int f[maxn];
bool OnShelf[maxn];
int Ans;

int up ( int x , int sgn);

void factor ( int x , vector<int> &v ) {
    v.clear();
    for ( int i = 2 ; i*i <= x ; i++ ) {
        if ( x % i ) continue;
        v.push_back(i);
        while ( x % i  == 0) x /= i;
    }
    if ( x != 1 ) v.push_back(x);
}

int main() {
    //freopen("a.in","r",stdin);
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] , 1);
            now++;
        }
        else {
            now--;
            Ans -= now - up( a[x] , -1 );
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

int up ( int x , int sgn) {
    vector <int> fact;
    factor ( x , fact );
    int up = fact.size();
    int ret = 0;
    for ( int k = 1 ; k < ( 1<<up ) ; k++ ) {
       int t = k , count = 0 , cnt = 0 , num = 1;
       while ( t ) {
           if ( t & 1 ) {
               cnt++;
               num *= fact[count];
           }
           count++;
           t >>= 1;
       }
       if ( sgn == -1 ) f[num]--;
       if ( cnt & 1 ) ret += f[num];
       else ret -= f[num];
       if ( sgn == 1 ) f[num]++;
    }
    return ret;
}


/*
 * Author:  Praesidio
 * Created Time:  2015/6/3 13:14:02
 * File Name: a.cpp
 */
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define bug(x) cout<<#x<<" "<<(x)<<endl

const int maxn = 5e5 + 10;

int n , q;
int a[maxn];
int f[maxn];
bool OnShelf[maxn];
int Ans;

int up ( int x , int sgn);

void factor ( int x , vector<int> &v ) {
    v.clear();
    for ( int i = 2 ; i*i <= x ; i++ ) {
        if ( x % i ) continue;
        v.push_back(i);
        while ( x % i  == 0) x /= i;
    }
    if ( x != 1 ) v.push_back(x);
}

int main() {
    //freopen("a.in","r",stdin);
    cin >> n >> q;
    for ( int i = 1 ; i <= n ; i++ ) cin >> a[i];
    memset(f,0,sizeof(f));
    memset(OnShelf,0,sizeof(OnShelf));
    Ans = 0; int now = 0;
    while ( q-- ) {
        int x;
        cin >> x;
        if ( !OnShelf[x] ) {
            Ans += now - up( a[x] , 1);
            now++;
        }
        else {
            now--;
            Ans -= now - up( a[x] , -1 );
        }
        cout << Ans << endl;
        OnShelf[x] = !OnShelf[x];
    }
    return 0;
}

int up ( int x , int sgn) {
    vector <int> fact;
    factor ( x , fact );
    int up = fact.size();
    int ret = 0;
    for ( int k = 1 ; k < ( 1<<up ) ; k++ ) {
       int t = k , count = 0 , cnt = 0 , num = 1;
       while ( t ) {
           if ( t & 1 ) {
               cnt++;
               num *= fact[count];
           }
           count++;
           t >>= 1;
       }
       if ( sgn == -1 ) f[num]--;
       if ( cnt & 1 ) ret += f[num];
       else ret -= f[num];
       if ( sgn == 1 ) f[num]++;
    }
    return ret;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

struct node
{
    int data;
    node *next;
};

struct dub
{
    int val;
    int rb;
};

int tmp[500000];
int primes[150000];
int num = 0, n;
dub a[500000];
node *factor[500000];
node *niz[500000];

bool cmp(dub a, dub b)
{
    return (a.val < b.val);
}

void addF(int pos, int p)
{
    node *tmp = new node;
    tmp -> data = p;
    tmp -> next = factor[pos];
    factor[pos] = tmp;
}

int bs(int val)
{
    int l = 0;
    int r = n;
    while(l < r - 1)
    {
        int mid = (l + r) / 2;
        if(a[mid].val <= val)
            l = mid;
        else
            r = mid;
    }
    return l;
}

int nov[500000];
int cnt = 0;
int in[500000];
int Fb[500000];

void add(int val)
{
    if(!tmp[val])
    {
        tmp[val] = 1;
        nov[cnt] = val;
        cnt++;
    }
}

void del()
{
    for(int i = 0; i < cnt; i++)
        tmp[nov[i]] = 0;
    cnt = 0;
}

long long sol = 0;

int main()
{
    //freopen("input.in", "r", stdin);
    for(int i = 2; i < 500001; i++)
        if(!tmp[i])
        {
            for(int j = i + i; j < 500001; j += i)
                tmp[j] = 1;
        }
    for(int i = 2; i < 500001; i++)
    {
        if(!tmp[i])
        {
            primes[num] = i;
            num++;
        }
        tmp[i] = 0;
    }
    primes[0] = 2;

    int q;
    scanf("%i", &n);
    scanf("%i", &q);
    for(int i = 0; i < n; i++)
    {
        a[i].rb = i;
        scanf("%i", &a[i].val);
    }
    sort(a, a + n, cmp);
    for(int i = 0; i < n; i++)
        Fb[a[i].rb] = i;

    for(int i = 0; i < n; i++)
    {
        int x = a[i].val;
        for(int j = 0; j < 128; j++)
        {
            if(!(x % primes[j]))
            {
                addF(i, primes[j]);
                while(!(x % primes[j]))
                    x /= primes[j];
            }
        }
        if(x != 1)
        addF(i, x);
    }
/*
    for(int i = 0; i < n; i++)
    {
        printf("%i:", a[i]);
        node *tmp = factor[i];
        while(tmp)
        {
            printf(" %i", tmp -> data);
            tmp = tmp -> next;
        }
        printf("\n");
    }
*/
    int broj = 0;
    for(int i = 0; i < q; i++)
    {
        int x;
        scanf("%i", &x);
        //printf(" %i\n", x);
        //x = bs(x);
        int kf = 1;
        x--;
        x = Fb[x];
        if(in[x])
        {
            in[x] = 0;
            kf = -1;
        }
        else
        {
            in[x] = 1;
        }
        broj += kf;
        node *tmp = factor[x];
        //printf("a%i\n", a[x]);
        while(tmp)
        {
            //printf("%i %i\n", x, tmp -> data);
            //printf("ulaz\n");
            //printf("%i:", tmp -> data);
            node *pom = niz[tmp -> data];
            while(pom)
            {
                //printf(" %i,", pom -> data);
                if(pom -> data == x)
                {
                    kf = -1;
                    if(pom -> next)
                    {
                        pom -> data = pom -> next -> data;
                        node *bris = pom -> next;
                        pom -> next = pom -> next -> next;
                        free(bris);
                    }
                    else
                    {
                        //printf("ulazi2\n");
                        node *neo = niz[tmp -> data];
                        if(neo == pom)
                            niz[tmp -> data] = niz[tmp -> data] -> next;
                        else
                        {
                            //printf("Hya\n");
                            while(neo -> next != pom)
                                neo = neo -> next;
                            neo -> next = neo -> next -> next;
                        }
                        //printf("Daym\n");
                        free(pom);
                        pom = NULL;
                        //printf("yeah\n");
                    }
                }
                if(pom)
                {
                    add(pom -> data);
                    pom = pom -> next;
                }
                //printf("wot\n");
            }
            //printf("\n");
            tmp = tmp -> next;
        }

        if(kf == 1)
        {
            node *tmp = factor[x];
            while(tmp)
            {
                node *pom = new node;
                pom -> data = x;
                pom -> next = niz[tmp -> data];
                niz[tmp -> data] = pom;

                tmp = tmp -> next;
            }
        }
        /*
        for(int i = 0; i < 4; i++)
        {
            int k = primes[i];
            node *tmp = niz[k];
            printf("%i:", k);
            while(tmp)
            {
                printf(" %i", tmp -> data);
                tmp = tmp -> next;
            }
            printf("\n");
        }
        printf("\n");
        */
        sol += kf * ((broj - (1 == kf)) - cnt);
        //printf("%i %i %i\n", broj, cnt, kf);
        cout << sol << endl;
        del();
    }
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>

using namespace std;

struct node
{
    int data;
    node *next;
};

int tmp[500000];
int primes[150000];
int num = 0, n;
int a[500000];
node *factor[500000];
node *niz[500000];

void addF(int pos, int p)
{
    node *tmp = new node;
    tmp -> data = p;
    tmp -> next = factor[pos];
    factor[pos] = tmp;
}

int bs(int val)
{
    int l = 0;
    int r = n;
    while(l < r - 1)
    {
        int mid = (l + r) / 2;
        if(a[mid] <= val)
            l = mid;
        else
            r = mid;
    }
    return l;
}

int nov[500000];
int cnt = 0;
int in[500000];

void add(int val)
{
    if(!tmp[val])
    {
        tmp[val] = 1;
        nov[cnt] = val;
        cnt++;
    }
}

void del()
{
    for(int i = 0; i < cnt; i++)
        tmp[nov[i]] = 0;
    cnt = 0;
}

long long sol = 0;

int main()
{
    //freopen("input.in", "r", stdin);
    for(int i = 2; i < 500001; i++)
        if(!tmp[i])
        {
            for(int j = i + i; j < 500001; j += i)
                tmp[j] = 1;
        }
    for(int i = 2; i < 500001; i++)
    {
        if(!tmp[i])
        {
            primes[num] = i;
            num++;
        }
        tmp[i] = 0;
    }
    primes[0] = 2;

    int q;
    scanf("%i", &n);
    scanf("%i", &q);
    for(int i = 0; i < n; i++)
        scanf("%i", &a[i]);
    sort(a, a + n);

    for(int i = 0; i < n; i++)
    {
        int x = a[i];
        for(int j = 0; j < 128; j++)
        {
            if(!(x % primes[j]))
            {
                addF(i, primes[j]);
                while(!(x % primes[j]))
                    x /= primes[j];
            }
        }
        if(x != 1)
        addF(i, x);
    }
/*
    for(int i = 0; i < n; i++)
    {
        printf("%i:", a[i]);
        node *tmp = factor[i];
        while(tmp)
        {
            printf(" %i", tmp -> data);
            tmp = tmp -> next;
        }
        printf("\n");
    }
*/
    int broj = 0;
    for(int i = 0; i < q; i++)
    {
        int x;
        scanf("%i", &x);
        //printf(" %i\n", x);
        //x = bs(x);
        int kf = 1;
        x--;
        if(in[x])
        {
            in[x] = 0;
            kf = -1;
        }
        else
        {
            in[x] = 1;
        }
        broj += kf;
        node *tmp = factor[x];
        //printf("a%i\n", a[x]);
        while(tmp)
        {
            //printf("ulaz\n");
            //printf("%i:", tmp -> data);
            node *pom = niz[tmp -> data];
            while(pom)
            {
                //printf(" %i,", pom -> data);
                if(pom -> data == x)
                {
                    kf = -1;
                    if(pom -> next)
                    {
                        pom -> data = pom -> next -> data;
                        node *bris = pom -> next;
                        pom -> next = pom -> next -> next;
                        free(bris);
                    }
                    else
                    {
                        //printf("ulazi2\n");
                        node *neo = niz[tmp -> data];
                        if(neo == pom)
                            niz[tmp -> data] = niz[tmp -> data] -> next;
                        else
                        {
                            //printf("Hya\n");
                            while(neo -> next != pom)
                                neo = neo -> next;
                            neo -> next = neo -> next -> next;
                        }
                        //printf("Daym\n");
                        free(pom);
                        pom = NULL;
                        //printf("yeah\n");
                    }
                }
                if(pom)
                {
                    add(pom -> data);
                    pom = pom -> next;
                }
                //printf("wot\n");
            }
            //printf("\n");
            tmp = tmp -> next;
        }

        if(kf == 1)
        {
            node *tmp = factor[x];
            while(tmp)
            {
                node *pom = new node;
                pom -> data = x;
                pom -> next = niz[tmp -> data];
                niz[tmp -> data] = pom;

                tmp = tmp -> next;
            }
        }
        /*
        for(int i = 0; i < 4; i++)
        {
            int k = primes[i];
            node *tmp = niz[k];
            printf("%i:", k);
            while(tmp)
            {
                printf(" %i", tmp -> data);
                tmp = tmp -> next;
            }
            printf("\n");
        }
        printf("\n");
        */
        sol += kf * ((broj - (1 == kf)) - cnt);
        //printf("%i %i %i\n", broj, cnt, kf);
        cout << sol << endl;
        del();
    }
    return 0;
}