#include <iostream>
#include <vector>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	long long n,p,k,s=0;
	cin>>n>>k;
	vector<int> a;
	a.push_back(0);
	for(int i=1;i<=n;i++){
		cin>>p;
		a.push_back(a[i-1]+p);
	}
	if(k==1){
		int i,j;
		for(i=0;i<=n;i++){
			for(j=i+1;j<=n;j++){
				s=s+(a[j]-a[i]);
			}
		}
	}
	else{
		s=a[n]-a[0];
	}
	cout<<s;
	return 0;

}