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

const int N = 500010;
int n,a[N];

int main()
{
	int k,i,minn,maxn,mem,re,now;
	long long sum = 0;
	cin >> n >> k;
	for(i = 1; i<=n; i++) {
		scanf("%d", &a[i]), sum += a[i];
	}
	re = sum%n;
	sort(a+1, a+1+n);

	int final = sum/n,all = 0;//all:±ä³É×îÖÕÐÎÌ¬µÄ×Ü²½Êý
	for(i = 1; i<=n; i++) {
		if(i==n-re+1) final++;
		if(a[i]<final) all += final-a[i];
	}
	if(all<=k) {
		printf("%d", re==0? 0:1);
		return 0;
	}
	mem = k;
	minn = a[1]; //k==0Ê±²»¸üÐÂÕâ¸ö»á³öÊÂ
//	final = sum/n;
	for(i = 1,now = a[1]; k && i<=n; i++) {
//		if(i==n-re+1) final++;
		if(now!=a[i+1]) {
			if((a[i+1]-now)*i<=k) {
				k -= (a[i+1]-now)*i;
				minn = now = a[i+1];
			}
			else {
				minn = now+k/i, k = 0;
			}
		}
	}
	k = mem;
	maxn = a[n];
//	final = (sum+n-1)/n;
	for(i = n,now = a[n]; k && i>=1; i--) {
//		if(i==n-re) final--;
		if(now!=a[i-1]) {
			if((now-a[i-1])*(n-i+1)<=k) {
				k -= (now-a[i-1])*(n-i+1);
				maxn = now = a[i-1];
			}
			else {
				maxn = now-k/(n-i+1), k = 0;
			}
		}
	}
	cout << maxn-minn;
	return 0;
}


#include<iostream>

using namespace std;

const long long INF=1000000009;

int c[500004];

long long n,k;

long long max(long long a,long long b){return a>=b?a:b;}
long long min(long long a,long long b){return a<=b?a:b;}

long long f1(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(x-c[i],0);
	return re;
}
long long f2(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(c[i]-x,0);
	return re;
}
long long mi(){
	long long l=0,r=INF;
	while(r-l>1){
		if(f1((r+l)/2)<=k)l=(r+l)/2;
		else r=(r+l)/2;
	}
	if(f1(r)<=k)return r;
	return l;
}
long long ma(){
	long long l=0,r=INF;
	while(r-l>1){
		if(f2((r+l)/2)<=k)r=(r+l)/2;
		else l=(r+l)/2;
	}
	if(f2(l)<=k)return l;
	return r;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>c[i];
	long long ans=ma()-mi();
	if(ans<1){
		if(f2(0)%n==0)ans=0;
		else ans=1;
	}
	cout<<ans<<endl;
}


#include<iostream>

using namespace std;

const long long INF=1000000009;

int c[500004];

long long n,k;

long long max(long long a,long long b){return a>=b?a:b;}
long long min(long long a,long long b){return a<=b?a:b;}

long long f1(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(x-c[i],0);
	return re;
}
long long f2(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(c[i]-x,0);
	return re;
}
long long mi(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(mid==l)mid++;
		if(f1(mid)<=k)l=mid;
		else r=mid-1;
	}
	return l;
}
long long ma(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(f2(mid)<=k)r=mid;
		else l=mid+1;
	}
	return r;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>c[i];
	long long ans=ma()-mi();
	if(ans<1){
		if(f2(0)%n==0)ans=0;
		else ans=1;
	}
	cout<<ans<<endl;
}


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

using namespace std;

const long long INF=1000000009;

int c[500004];

long long n,k;

long long max(long long a,long long b){return a>=b?a:b;}
long long min(long long a,long long b){return a<=b?a:b;}

long long f1(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(x-c[i],0);
	return re;
}
long long f2(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(c[i]-x,0);
	return re;
}
long long mi(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(mid==l)mid++;
		if(f1(mid)<=k)l=mid;
		else r=mid-1;
	}
	return l;
}
long long ma(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(f2(mid)<=k)r=mid;
		else l=mid+1;
	}
	return r;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)scanf("%d",c+i);
	long long ans=ma()-mi();
	if(ans<1){
		if(f2(0)%n==0)ans=0;
		else ans=1;
	}
	cout<<ans<<endl;
}


#include<iostream>

using namespace std;

const long long INF=1000000009;

long long c[500004];

long long n,k;

long long max(long long a,long long b){return a>=b?a:b;}
long long min(long long a,long long b){return a<=b?a:b;}

long long f1(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(x-c[i],0);
	return re;
}
long long f2(long long x){
	long long re=0;
	for(int i=0;i<n;i++)re+=max(c[i]-x,0);
	return re;
}
long long mi(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(mid==l)mid++;
		if(f1(mid)<=k)l=mid;
		else r=mid-1;
	}
	return l;
}
long long ma(){
	long long l=0,r=INF;
	while(r>l){
		long long mid=(r+l)/2;
		if(f2(mid)<=k)r=mid;
		else l=mid+1;
	}
	return r;
}
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>c[i];
	long long ans=ma()-mi();
	if(ans<1){
		if(f2(0)%n==0)ans=0;
		else ans=1;
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    int prev_max = get_max_amt(), prev_min = get_min_amt(), prev_max_size = get_max_size(), prev_min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor_amt = get_min_amt(), poor_size = get_min_size();
        int poor = (get_2nd_min_amt() - poor_amt) * poor_size;
        int rich_amt = get_max_amt(), rich_size = get_max_size();
        int rich = (rich_amt - get_2nd_max_amt()) * rich_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        people.erase(--people.end());
        int new_min = poor_amt + (to_move + poor_size - 1) / poor_size;
        add(new_min, to_move % poor_size);
        add(poor_amt + to_move / poor_size, poor_size - to_move % poor_size);
        int new_max = rich_amt - (to_move + rich_size - 1) / rich_size;
        add(new_max, to_move % rich_size);
        add(rich_amt - to_move / rich_size, rich_size - to_move % rich_size);
        k -= to_move;
        int curr_max = get_max_amt(), curr_min = get_min_amt(), curr_max_size = get_max_size(), curr_min_size = get_min_size();
        if(curr_max == prev_max && curr_min == prev_min && curr_max_size == prev_max_size && curr_min_size == prev_min_size) {
            break;
        }
        prev_max = curr_max, prev_min = curr_min, prev_max_size = curr_max_size, prev_min_size = curr_min_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
        //printmap();
    }
    int prev_max = get_max_amt(), prev_min = get_min_amt(), prev_max_size = get_max_size(), prev_min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor_amt = get_min_amt(), poor_size = get_min_size();
        int poor = (get_2nd_min_amt() - poor_amt) * poor_size;
        int rich_amt = get_max_amt(), rich_size = get_max_size();
        int rich = (rich_amt - get_2nd_min_amt()) * rich_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        int new_min = poor_amt + (to_move + poor_size - 1) / poor_size;
        add(new_min, to_move % poor_size);
        add(poor_amt + to_move / poor_size, poor_size - to_move % poor_size);
        if(people.size() > 2) {
            people.erase(--people.end());
            int new_max = rich_amt - (to_move + rich_size - 1) / rich_size;
            add(new_max, to_move % rich_size);
            add(rich_amt - to_move / rich_size, rich_size - to_move % rich_size);
        }
        k -= to_move;
        //printmap();
        int curr_max = get_max_amt(), curr_min = get_min_amt(), curr_max_size = get_max_size(), curr_min_size = get_min_size();
        if(curr_max == prev_max && curr_min == prev_min && curr_max_size == prev_max_size && curr_min_size == prev_min_size) {
            break;
        }
        prev_max = curr_max, prev_min = curr_min, prev_max_size = curr_max_size, prev_min_size = curr_min_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    for(int i = 0; i < k; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int poor = people.size() == 1 ? k - i : (min_amt2 - min_amt) * min_size;
        int to_move = min(k - i, poor);
        remove_min();
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        add(min_amt + to_move / min_size + 1, to_move % min_size);
        i += to_move;
    }
    for(int i = 0; i < k; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int rich = people.size() == 1 ? k - i : (max_amt - max_amt2) * max_size;
        int to_move = min(k - i, rich);
        remove_max();
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        add(max_amt - to_move / max_size - 1, to_move % max_size);
        i += to_move;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    int max_amt = get_max_amt(), min_amt = get_min_amt(), max_size = get_max_size(), min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor = (get_2nd_min_amt() - min_amt) * min_size;
        int rich = (max_amt - get_2nd_max_amt()) * max_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        people.erase(--people.end());
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        k -= to_move;
        int nmax_amt = get_max_amt(), nmin_amt = get_min_amt(), nmax_size = get_max_size(), nmin_size = get_min_size();
        if(max_amt == nmax_amt && min_amt == nmin_amt && max_size == nmax_size && min_size == nmin_size) {
            break;
        }
        max_amt = nmax_amt, min_amt = nmin_amt, max_size = nmax_size, min_size = nmin_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    int amount = k;
    while(amount != 0 && people.size() > 1) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int poor = (min_amt2 - min_amt) * min_size;
        int to_move = min(amount, poor);
        remove_min();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        amount -= to_move;
    }
    amount = k;
    while(amount != 0 && people.size() > 1) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int rich = (max_amt - max_amt2) * max_size;
        int to_move = min(amount, rich);
        remove_max();
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        amount -= to_move;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
map<int, int>::iterator bg, en, bg2, en2;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return bg->second;
}
inline int get_min_amt() {
    return bg->first;
}
inline int get_2nd_min_amt() {
    return bg2->first;
}
inline int get_max_size() {
    return en->second;
}
inline int get_max_amt() {
    return en->first;
}
inline int get_2nd_max_amt() {
    return en2->first;
}
inline void remove_min() {
    people.erase(bg);
}
inline void remove_max() {
    people.erase(en);
}
inline void update_pointers() {
    bg = people.begin();
    bg2 = ++people.begin();
    en = --people.end();
    en2 = ----people.end();
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    update_pointers();
    int max_amt = get_max_amt(), min_amt = get_min_amt(), max_size = get_max_size(), min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        int poor = (get_2nd_min_amt() - min_amt) * min_size;
        int rich = (max_amt - get_2nd_max_amt()) * max_size;
        int to_move = min(k, min(poor, rich));
        remove_min();
        remove_max();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        update_pointers();
        k -= to_move;
        int nmax_amt = get_max_amt(), nmin_amt = get_min_amt(), nmax_size = get_max_size(), nmin_size = get_min_size();
        if(max_amt == nmax_amt && min_amt == nmin_amt && max_size == nmax_size && min_size == nmin_size) {
            break;
        }
        max_amt = nmax_amt, min_amt = nmin_amt, max_size = nmax_size, min_size = nmin_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    for(int i = 0; i < k; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        long long poor = people.size() == 1 ? k - i : (long long)(min_amt2 - min_amt) * min_size;
        int to_move = (int)min((long long)k - i, poor);
        remove_min();
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        add(min_amt + to_move / min_size + 1, to_move % min_size);
        i += to_move;
        // cout << i << ": "; printmap();
    }
    for(int i = 0; i < k; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        long long rich = people.size() == 1 ? k - i : (long long)(max_amt - max_amt2) * max_size;
        int to_move = (int)min((long long)k - i, rich);
        remove_max();
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        add(max_amt - to_move / max_size - 1, to_move % max_size);
        i += to_move;
        // cout << i << ": "; printmap();
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    for(int i = 0; i < k; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int to_move = min(k - i, min_size);
        remove_min();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        i += to_move;
    }
    for(int i = 0; i < k; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int to_move = min(k - i, max_size);
        remove_max();
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        i += to_move;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    for(int i = 0; i < k; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int poor = people.size() == 1 ? min_size : (min_amt2 - min_amt) * min_size;
        int to_move = min(k - i, poor);
        remove_min();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        i += to_move;
    }
    for(int i = 0; i < k; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int rich = people.size() == 1 ? max_size : (max_amt - max_amt2) * max_size;
        int to_move = min(k - i, rich);
        remove_max();
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        i += to_move;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    for(int i = 0; i < k; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int poor = people.size() == 1 ? k - i : (min_amt2 - min_amt) * min_size;
        int to_move = min(k - i, poor);
        remove_min();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        i += to_move;
    }
    for(int i = 0; i < k; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int rich = people.size() == 1 ? k - i : (max_amt - max_amt2) * max_size;
        int to_move = min(k - i, rich);
        remove_max();
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        i += to_move;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
map<int, int>::iterator bg_ptr;
map<int, int>::iterator en_ptr;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return bg_ptr->second;
}
int get_min_amt() {
    return bg_ptr->first;
}
int get_2nd_min_amt() {
    int ret = (++bg_ptr)->first;
    bg_ptr--;
    return ret;
}
int get_max_size() {
    return en_ptr->second;
}
int get_max_amt() {
    return en_ptr->first;
}
int get_2nd_max_amt() {
    int ret = (--en_ptr)->first;
    en_ptr++;
    return ret;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    bg_ptr = people.begin();
    en_ptr = --people.end();
    int max_amt = get_max_amt(), min_amt = get_min_amt(), max_size = get_max_size(), min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        int poor = (get_2nd_min_amt() - min_amt) * min_size;
        int rich = (max_amt - get_2nd_max_amt()) * max_size;
        int to_move = min(k, min(poor, rich));
        people.erase(bg_ptr);
        people.erase(en_ptr);
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        bg_ptr = people.begin();
        en_ptr = --people.end();
        k -= to_move;
        int nmax_amt = get_max_amt(), nmin_amt = get_min_amt(), nmax_size = get_max_size(), nmin_size = get_min_size();
        if(max_amt == nmax_amt && min_amt == nmin_amt && max_size == nmax_size && min_size == nmin_size) {
            break;
        }
        max_amt = nmax_amt, min_amt = nmin_amt, max_size = nmax_size, min_size = nmin_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
        //printmap();
    }
    int prev_d = get_max_amt() - get_min_amt();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor_amt = get_min_amt(), poor_size = get_min_size();
        int poor = (get_2nd_min_amt() - poor_amt) * poor_size;
        int rich_amt = get_max_amt(), rich_size = get_max_size();
        int rich = (rich_amt - get_2nd_min_amt()) * rich_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        int new_min = poor_amt + (to_move + poor_size - 1) / poor_size;
        add(new_min, to_move % poor_size);
        add(poor_amt + to_move / poor_size, poor_size - to_move % poor_size);
        if(people.size() > 2) {
            people.erase(--people.end());
            int new_max = rich_amt - (to_move + rich_size - 1) / rich_size;
            add(new_max, to_move % rich_size);
            add(rich_amt - to_move / rich_size, rich_size - to_move % rich_size);
        }
        k -= to_move;
        //printmap();
        int curr_d = get_max_amt() - get_min_amt();
        if(curr_d == prev_d) {
            break;
        }
        prev_d = curr_d;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
        //printmap();
    }
    int prev_max = get_max_amt(), prev_min = get_min_amt();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor_amt = get_min_amt(), poor_size = get_min_size();
        int poor = (get_2nd_min_amt() - poor_amt) * poor_size;
        int rich_amt = get_max_amt(), rich_size = get_max_size();
        int rich = (rich_amt - get_2nd_min_amt()) * rich_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        int new_min = poor_amt + (to_move + poor_size - 1) / poor_size;
        add(new_min, to_move % poor_size);
        add(poor_amt + to_move / poor_size, poor_size - to_move % poor_size);
        if(people.size() > 2) {
            people.erase(--people.end());
            int new_max = rich_amt - (to_move + rich_size - 1) / rich_size;
            add(new_max, to_move % rich_size);
            add(rich_amt - to_move / rich_size, rich_size - to_move % rich_size);
        }
        k -= to_move;
        //printmap();
        int curr_max = get_max_amt(), curr_min = get_min_amt();
        if(curr_max == prev_max && curr_min == prev_min) {
            break;
        }
        prev_max = curr_max, prev_min = curr_min;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
inline int get_min_size() {
    return people.begin()->second;
}
inline int get_min_amt() {
    return people.begin()->first;
}
inline int get_2nd_min_amt() {
    return (++people.begin())->first;
}
inline int get_max_size() {
    return (--people.end())->second;
}
inline int get_max_amt() {
    return (--people.end())->first;
}
inline int get_2nd_max_amt() {
    return (----people.end())->first;
}
inline void remove_min() {
    people.erase(people.begin());
}
inline void remove_max() {
    people.erase(--people.end());
}

void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    int i;
    for(i = 0; i < k && people.size() > 1; ) {
        int min_size = get_min_size(), min_amt = get_min_amt(), min_amt2 = get_2nd_min_amt();
        int poor = (min_amt2 - min_amt) * min_size;
        int to_move = min(k - i, poor);
        remove_min();
        int new_min = min_amt + (to_move + min_size - 1) / min_size;
        add(new_min, to_move % min_size);
        add(min_amt + to_move / min_size, min_size - to_move % min_size);
        i += to_move;
    }
    if(i != k) {
        int min_size = get_min_size(), min_amt = get_min_amt();
        remove_min();
        add(min_amt + (k - i) / min_size, min_size - (k - i) % min_size);
        add(min_amt + (k - i) / min_size + 1, (k - i) % min_size);
    }
    for(i = 0; i < k && people.size() > 1; ) {
        int max_size = get_max_size(), max_amt = get_max_amt(), max_amt2 = get_2nd_max_amt();
        int rich = (max_amt - max_amt2) * max_size;
        int to_move = min(k - i, rich);
        remove_max();
        int new_max = max_amt - (to_move + max_size - 1) / max_size;
        add(new_max, to_move % max_size);
        add(max_amt - to_move / max_size, max_size - to_move % max_size);
        i += to_move;
    }
    if(i != k) {
        int max_size = get_max_size(), max_amt = get_max_amt();
        remove_max();
        add(max_amt + (k - i) / max_size, max_size - (k - i) % max_size);
        add(max_amt + (k - i) / max_size + 1, (k - i) % max_size);
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <map>
using namespace std;
map<int, int> people;
void add(int amount, int persons) {
    if(persons > 0) {
        if(people.count(amount)) {
            people[amount] += persons;
        } else {
            people[amount] = persons;
        }
    }
}
int get_min_size() {
    return people.begin()->second;
}
int get_min_amt() {
    return people.begin()->first;
}
int get_2nd_min_amt() {
    return (++people.begin())->first;
}
int get_max_size() {
    return (--people.end())->second;
}
int get_max_amt() {
    return (--people.end())->first;
}
int get_2nd_max_amt() {
    return (----people.end())->first;
}
void printmap() {
    for(map<int, int>::iterator it = people.begin(); it != people.end(); it++) {
        for(int i = 0; i < it->second; i++) {
            cout << it->first << " ";
        }
    }
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        add(c, 1);
    }
    int prev_max = get_max_amt(), prev_min = get_min_amt(), prev_max_size = get_max_size(), prev_min_size = get_min_size();
    while(k != 0 && people.size() > 1) {
        map<int, int>::iterator it = people.begin();
        int poor_amt = get_min_amt(), poor_size = get_min_size();
        int poor = (get_2nd_min_amt() - poor_amt) * poor_size;
        int rich_amt = get_max_amt(), rich_size = get_max_size();
        int rich = (rich_amt - get_2nd_max_amt()) * rich_size;
        int to_move = min(k, min(poor, rich));
        people.erase(people.begin());
        people.erase(--people.end());
        int new_min = poor_amt + (to_move + poor_size - 1) / poor_size;
        add(new_min, to_move % poor_size);
        add(poor_amt + to_move / poor_size, poor_size - to_move % poor_size);
        int new_max = rich_amt - (to_move + rich_size - 1) / rich_size;
        add(new_max, to_move % rich_size);
        add(rich_amt - to_move / rich_size, rich_size - to_move % rich_size);
        k -= to_move;
        int curr_max = get_max_amt(), curr_min = get_min_amt(), curr_max_size = get_max_size(), curr_min_size = get_min_size();
        if(curr_max == prev_max && curr_min == prev_min && curr_max_size == prev_max_size && curr_min_size == prev_min_size) {
            break;
        }
        prev_max = curr_max, prev_min = curr_min, prev_max_size = curr_max_size, prev_min_size = curr_min_size;
    }
    cout << get_max_amt() - get_min_amt() << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#define INF 2000000000
using namespace std;
long long n,k,m,a[500001],b[500001],i,j,l,r,c,x,ans=INF,mid;
main()
{
cin>>n>>k;
for (i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for (i=1;i<=n/2;i++)
b[i]=a[n-i+1]-a[i];
m=n/2;
l=0;
r=b[1];
while (l<=r)
{
mid=(l+r)/2;
x=0;
if (b[1]>mid)
{
x=b[1]-mid;
for (i=2;i<=m;i++)
if (b[i]>mid)
x+=max(b[i]-mid,b[i-1]-mid-(a[i]-a[i-1]+a[n-i+1]-a[n-i+2])/2);
}
if (x<=k)
{
ans=min(mid,ans);
r=mid-1;
}
else
l=mid+1;
}
cout<<ans<<endl;
}


#include<iostream>
#include<cmath>
using namespace std;
long long c[500009];
main()
{long long n,k,s=0,t=0;
cin>>n>>k;
for (long long i=0; i<n; i++)
{cin>>c[i];t=max(t,c[i]);
s+=c[i];
}long long s2=0;
for (long long j=0; j<n; j++)
s2+=abs(c[j]-s/n);
if (s2/2<=k && s%n==0) {cout<<0<<endl; return 0;}
else if(s2/2<=k && s%n!=0) {cout<<1<<endl;  return 0;}
long long x=1,y=t;
while(x<y)
{
long long z=(x+y+1)/2;
long long s=0;
for (long long i=0; i<n; i++)
s+=max((long long)0,z-c[i]);
if (s<=k) x=z; else y=z-1;
}long long m=x;
 x=0;y=t;
while(x<y)
{long long z=(x+y)/2;
long long s=0;
for (long long i=0; i<n; i++)
s+=max((long long)0,c[i]-z);
if (s<=k) y=z; else x=z+1;
}
cout<<x-m<<endl;
}


#include <iostream>
#include <algorithm>
#define INF 2000000000
using namespace std;
long long n,k,m,a[500001],b[500001],i,j,l,r,c,x,ans=INF,mid;
main()
{
cin>>n>>k;
for (i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for (i=1;i<=n/2;i++)
b[i]=a[n-i+1]-a[i];
m=n/2;
l=0;
r=b[1];
while (l<=r)
{
mid=(l+r)/2;
x=0;
for (i=1;i<=m;i++)
if (b[i]>mid)
x+=b[i]-mid;
if (x<=k)
{
ans=min(mid,ans);
r=mid-1;
}
else
l=mid+1;
}
cout<<ans<<endl;
}


#include<stdio.h>
using namespace std;

int n, a[1000000], k, poor = 2000000000, rich = 0;

int maxa(int a, int b){return (a > b) ? a:b;}

int coinMin(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

int coinMax(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%d %d",&n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(rich < a[i]) rich = a[i];
		if(poor > a[i]) poor = a[i];
	}

	int l = poor, r = rich;
	while(l < r){
		int mid = (l+r)/2;
		if(coinMax(mid) <= k) r = mid;
		else l = mid+1;
	}
	int rem = k-coinMax(l);
	for(int i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]--; rem--;}
	//printf("Step 1 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");

	l = poor; r = rich;
	while(l < r){
		int mid = (l+r)/2;
		if(coinMin(mid) <= k) l = mid;
		else r = mid-1;
		//printf("coinMin(%d) = %d\n", mid, coinMin(mid));
	}
	rem = k-coinMin(l);
	for(int i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]++; rem--;}
	//printf("Step 2 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");
	int hi = 0, lo = 2000000000;
	for(int i = 0; i < n; i++){
		if(hi < a[i]) hi = a[i];
		if(lo > a[i]) lo = a[i];
	}
	printf("%d\n", hi-lo);
}


#include<stdio.h>
using namespace std;

#define ll long long int

ll n, k, a[1000000], l, r;

ll maxa(ll a, ll b){return (a > b) ? a:b;}

ll coinMin(ll x){
	ll res = 0;
	for(ll i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

ll coinMax(ll x){
	ll res = 0;
	for(ll i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%I64d %I64d", &n, &k);
	for(ll i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	//Add first
	l = 0; r = 2000000000;
	while(l < r){
		ll mid = (l+r)/2+1;
		if(coinMin(mid) <= k) l = mid;
		else r = mid-1;
	}
	for(ll i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	ll rem = k-coinMin(l);
	for(ll i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]++; rem--;}

	//Then remove
	l = 0; r = 2000000000;
	while(l < r){
		ll mid = (l+r)/2;
		if(coinMax(mid) > k) l = mid+1;
		else r = mid;
	}
	rem = k-coinMax(l);
	for(ll i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(ll i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]--; rem--;}

	//Finally ans
	ll lo = 2000000000, hi = 0;
	for(ll i = 0; i < n; i++){
		if(lo > a[i]) lo = a[i];
		if(hi < a[i]) hi = a[i];
	}
	printf("%I64d\n", hi-lo);
}


#include<stdio.h>
using namespace std;

int n, a[1000000], k, poor = 2000000000, rich = 0;

int maxa(int a, int b){return (a > b) ? a:b;}

int coinMin(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

int coinMax(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%d %d",&n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(rich < a[i]) rich = a[i];
		if(poor > a[i]) poor = a[i];
	}

	int l = poor, r = rich;
	while(l < r){
		int mid = (l+r)/2;
		//printf("coinMax(%d, %d)(%d) = %d\n", l, r, mid, coinMax(mid));
		if(coinMax(mid) <= k) r = mid;
		else l = mid+1;

	}
	int rem = k-coinMax(l);
	for(int i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]--; rem--;}
	//printf("Step 1 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");

	l = poor; r = rich;
	while(l < r){
		int mid = (l+r)/2+1;
		//printf("coinMin(%d, %d)(%d) = %d\n", l, r, mid, coinMin(mid));
		if(coinMin(mid) > k) r = mid-1;
		else l = mid;

		//printf("coinMin(%d, %d)\n", l, r);
		//printf("L\n");
	}
	rem = k-coinMin(l);
	for(int i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]++; rem--;}
	//printf("Step 2 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");
	int hi = 0, lo = 2000000000;
	for(int i = 0; i < n; i++){
		if(hi < a[i]) hi = a[i];
		if(lo > a[i]) lo = a[i];
	}
	printf("%d\n", hi-lo);
}
/*
10 20
6 4 7 10 4 5 5 3 7 10
*/


#include<stdio.h>
using namespace std;

#define ll long long int

ll n, k, a[1000000], l, r;

ll maxa(ll a, ll b){return (a > b) ? a:b;}

ll coinMin(ll x){
	ll res = 0;
	for(ll i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

ll coinMax(ll x){
	ll res = 0;
	for(ll i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%I64d %I64d", &n, &k);
	for(ll i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	//Add first
	l = -2000000000; r = 2000000000;
	while(l < r){
		ll mid = (l+r)/2+1;
		if(coinMin(mid) <= k) l = mid;
		else r = mid-1;
	}
	for(ll i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	ll rem = k-coinMin(l);
	for(ll i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]++; rem--;}

	//Then remove
	l = -2000000000; r = 2000000000;
	while(l < r){
		ll mid = (l+r)/2;
		if(coinMax(mid) > k) l = mid+1;
		else r = mid;
	}
	rem = k-coinMax(l);
	for(ll i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(ll i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]--; rem--;}

	//Finally ans
	ll lo = 2000000000, hi = 0;
	for(ll i = 0; i < n; i++){
		if(lo > a[i]) lo = a[i];
		if(hi < a[i]) hi = a[i];
	}
	printf("%I64d\n", hi-lo);
}


#include<stdio.h>
using namespace std;

int n, a[1000000], k, poor = 2000000000, rich = 0;

int maxa(int a, int b){return (a > b) ? a:b;}

int coinMin(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

int coinMax(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%d %d",&n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(rich < a[i]) rich = a[i];
		if(poor > a[i]) poor = a[i];
	}

	int l = poor, r = rich;
	while(l < r){
		int mid = (l+r)/2+1;
		if(coinMax(mid) > k) r = mid-1;
		else l = mid;
	}
	int rem = k-coinMax(l);
	for(int i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]--; rem--;}
	//printf("Step 1 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");

	l = poor; r = rich;
	while(l < r){
		int mid = (l+r)/2;
		if(coinMin(mid) > k) r = mid-1;
		else l = mid;
		//printf("coinMin(%d) = %d\n", mid, coinMin(mid));
	}
	rem = k-coinMin(l);
	for(int i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	for(int i = 0; i < n && rem > 0; i++) if(a[i] == l){a[i]++; rem--;}
	//printf("Step 2 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");
	int hi = 0, lo = 2000000000;
	for(int i = 0; i < n; i++){
		if(hi < a[i]) hi = a[i];
		if(lo > a[i]) lo = a[i];
	}
	printf("%d\n", hi-lo);
}


#include<stdio.h>
using namespace std;

int n, a[1000000], k, poor = 2000000000, rich = 0;

int maxa(int a, int b){return (a > b) ? a:b;}

int coinMin(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, x-a[i]);
	return res;
}

int coinMax(int x){
	int res = 0;
	for(int i = 0; i < n; i++) res += maxa(0, a[i]-x);
	return res;
}

int main(){
	scanf("%d %d",&n, &k);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if(rich < a[i]) rich = a[i];
		if(poor > a[i]) poor = a[i];
	}

	int l = poor, r = rich;
	while(l < r){
		int mid = (l+r)/2;
		//printf("coinMax(%d, %d)(%d) = %d\n", l, r, mid, coinMax(mid));
		if(coinMax(mid) <= k) r = mid;
		else l = mid+1;

	}
	int rem = k-coinMax(l);
	for(int i = 0; i < n; i++) if(a[i] > l) a[i] = l;
	for(int i = 0; rem > 0; i = (i+1)%n){
		if(a[i] == l){a[i]--; rem--;}
		if(i == n-1) l--;
	}
	//printf("Step 1 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");

	l = poor; r = rich;
	while(l < r){
		int mid = (l+r)/2+1;
		//printf("coinMin(%d, %d)(%d) = %d\n", l, r, mid, coinMin(mid));
		if(coinMin(mid) > k) r = mid-1;
		else l = mid;

		//printf("coinMin(%d, %d)\n", l, r);
		//printf("L\n");
	}
	rem = k-coinMin(l);
	for(int i = 0; i < n; i++) if(a[i] < l) a[i] = l;
	for(int i = 0; rem > 0; i = (i+1)%n){
		if(a[i] == l){a[i]++; rem--;}
		if(i == n-1){l++;}
	}
	//printf("Step 2 (%d):", l); for(int i = 0; i < n; i++) printf(" %d", a[i]); printf("\n");
	int hi = 0, lo = 2000000000;
	for(int i = 0; i < n; i++){
		if(hi < a[i]) hi = a[i];
		if(lo > a[i]) lo = a[i];
	}
	printf("%d\n", hi-lo);
}
/*
10 20
6 4 7 10 4 5 5 3 7 10
*/


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL  INF = 0x7fffffffffffffff; //beware overflow
const int mod = 1e9+7;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
#define maxn 100005
const double EPS = 1e-10;
int n ,k;
LL arr[maxn];
long double calc() {
    long double ret = 0;
    for(int i = n; i >= 0; i--) {
        ret *= (long double)k;
        ret += arr[i];
    }
    debug("%Lf\n", ret);
    return ret;
}
int main() {
    cin>>n>>k;char t[50];
    int d = 0, ud = 0;
    for(int i=0;i<n+1;i++) {
        scanf("%s", t);
        if( t[0] != '?') arr[i] = atoi(t), d++;
        else ud++;
    }

    if( !ud ) {
        puts(abs(calc())<EPS?"YES":"NO");
    }
    else{
        assert(d+ud == n+1);
        puts(((d+ud)&1)?"NO":"YES");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL  INF = 0x7fffffffffffffff; //beware overflow
const int mod = 1e9+7;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
#define maxn 100005
const long double EPS = 1e-10;
int n ,k;
LL arr[maxn];
long double calc() {
    long double ret = 0;
    for(int i = n; i >= 0; i--) {
        ret *= (long double)k;
        ret += (long double)arr[i];
    }
    debug("%Lf\n", ret);
    return ret;
}
int main() {
    cin>>n>>k;char t[50];
    int d = 0, ud = 0;
    for(int i=0;i<n+1;i++) {
        scanf("%s", t);
        if( t[0] != '?') arr[i] = atoi(t), d++;
        else ud++;
    }

    if( !ud ) {
        puts(abs(calc())<EPS?"YES":"NO");
        if( n = 100000) cout << calc() << endl;
    }
    else{
        assert(d+ud == n+1);
        puts(((d+ud)&1)?"NO":"YES");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL  INF = 0x7fffffffffffffff; //beware overflow
const int mod = 1e9+7;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
#define maxn 100005
int n ,k;
LL arr[maxn];
long double calc() {
    long double ret = 0;
    for(int i = n; i >= 0; i--) {
        ret *= (long double)k;
        ret += (long double)arr[i];
    }
    return ret;
}
int main() {
    cin>>n>>k;char t[maxn][50];
    int d = 0, ud = 0;
    for(int i=0;i<n+1;i++) {
        scanf("%s", t[i]);
        if( t[i][0] != '?') arr[i] = atoi(t[i]), d++;
        else ud++;
    }
    if( !k ) {
        if( t[0][0] == '?' ) puts( d&1?"YES":"NO");
        else puts((arr[0]==0)?"YES":"NO");
        return 0;
    }

    if( !ud ) puts(calc()==0?"YES":"NO");
    else puts(((d+ud)&1)?"NO":"YES");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL  INF = 0x7fffffffffffffff; //beware overflow
const int mod = 1e9+7;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
#define maxn 100005
const long double EPS = 1e-10;
int n ,k;
LL arr[maxn];
long double calc() {
    long double ret = 0;
    for(int i = n; i >= 0; i--) {
        ret *= (long double)k;
        ret += (long double)arr[i];
    }
    debug("%Lf\n", ret);
    return ret;
}
int main() {
    cin>>n>>k;char t[maxn][50];
    int d = 0, ud = 0;
    for(int i=0;i<n+1;i++) {
        scanf("%s", t[i]);
        if( t[i][0] != '?') arr[i] = atoi(t[i]), d++;
        else ud++;
    }
    if( !k ) {
        if( t[0][0] == '?' ) return puts( d&1?"YES":"NO"), 0;
        else puts((arr[0]==0)?"YES":"NO");
    }
    if( !ud ) {
        puts(abs(calc())<EPS?"YES":"NO");
    }
    else{
        assert(d+ud == n+1);
        puts(((d+ud)&1)?"NO":"YES");
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else{
        if (k<0){
            k *= -1;
            REP(i,n+1){
                if (i%2==1)
                    a[i] *= -1;
            }
        }
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else if (k==1){
        int s = 0;
        REP(i,n+1){
            s += a[i];
        }
        if (s==0)
            win = 1;
    }else{
        if (k<0){
            k *= -1;
            REP(i,n+1){
                if (i%2==1)
                    a[i] *= -1;
            }
        }
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else if (k==1){
        int s = 0;
        REP(i,n+1){
            s += a[i];
        }
        if (s==0)
            win = 1;
    }else{
        if (k<0){
            k *= -1;
            REP(i,n+1){
                if (i%2==1)
                    a[i] *= -1;
            }
        }
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        REP(i,n+1){
            cout << p[i] << " ";
        }
        cout << endl;
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else if (k==1){
        int s = 0;
        REP(i,n+1){
            s += a[i];
        }
        if (s==0)
            win = 1;
    }else{
        if (k<0){
            k *= -1;
            REP(i,n+1){
                if (i%2==1)
                    a[i] *= -1;
            }
        }
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b%k;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+100){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else if (k==1){
        int s = 0;
        REP(i,n+1){
            s += a[i];
        }
        if (s==0)
            win = 1;
    }else{
        if (k<0){
            k *= -1;
            REP(i,n+1){
                if (i%2==1)
                    a[i] *= -1;
            }
        }
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b%k;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else{
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else{
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b%k;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n+1);
    vector<bool> f(n+1);
    int x = 0;
    REP(i,n+1){
        int p;
        if (scanf("%d",&p) != 1){
            f[i] = 1;
            a[i] = 1e8;
            x++;
            scanf("%*s");
        }else{
            a[i] = p;
        }
    }
    int y = n+1-x;

    bool win = 0;
    if (k==0){
        if (a[0] == 0)
            win = 1;
        if (y%2==1 && f[0])
            win = 1;
    }else if (x>0){
        if (n%2==1)
            win = 1;
    }else{
        VI p(n+100), m(n+100);
        REP(i,n+1){
            int j = i;
            if (a[i]>0){
                int b = a[i];
                while(b){
                    p[j] += b%k;
                    b /= k;
                    b += p[j]/k;
                    p[j] %= k;
                    j++;
                }
            }else if (a[i]<0){
                int b = -a[i];
                while(b){
                    m[j] += b%k;
                    b /= k;
                    b += m[j]/k;
                    m[j] %= k;
                    j++;
                }
            }
            REP(i,n+1){
                cout << p[i] << " ";
            }cout << endl;
            REP(i,n+1){
                cout << m[i] << " ";
            }cout << endl;
        }
        bool q = 1;
        REP(i,n+1){
            if (p[i]!=m[i])
                q = 0;
        }
        if (q)
            win = 1;
    }

    if (win){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check2(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ll X[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){
    X[n] = A[n];
    for(int i=n-1; i>=0; i--)
    {
        if( abs(X[i+1] * K) > OO )
        {
            ans = "No";
            return;
        }

        X[i] = X[i+1] * K + A[i];
    }

    if(X[0] != 0)
        ans = "No";
}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check5(string &ans){
    ld sth = 0;
    for(int i=n; i>=0; i--)
    {
        sth = sth * K + A[i];
    }

    if(sth != 0)
        ans = "No";
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check5(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ll X[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){
    X[n] = A[n];
    for(int i=n-1; i>=0; i--)
    {
        if( abs(X[i+1]) > OO )
        {
            ans = "No";
            return;
        }

        X[i] = X[i+1] * K + A[i];
    }

    if(X[0] != 0)
        ans = "No";
}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check3(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ll X[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){
    X[n] = A[n];
    for(int i=n-1; i>=0; i--)
    {
        if( abs(X[i+1]) > OO )
            break;

        X[i] = X[i+1] * K + A[i];
    }

    if(X[0] != 0)
        ans = "No";
}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check3(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){

}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check4(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}