#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
//    for(int ii = i;ii<n;ii++)
//    {
        res1 = func(i+1,tot) + func(i+1,arr[i]+tot);
//    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        if( (arr[ii]+tot)%m == 0 )foundAns = true;
        res1 = func(ii+1,arr[ii]) + func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;

    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        sf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

bool dp[1010][1010];
bool vis[1010][1010];

bool foundAns = false;
int n;
int m;
bool func(int i,long long tot)
{
//    cout << tot << endl;

    if(i >= n || foundAns)
    {
        if(tot%m == 0)
        {
            foundAns = true;
            return true;
        }
        else return false;
    }

    if(vis[i][tot%m])return dp[i][tot%m];
    vis[i][tot%m] = true;

    bool res1,res2;
    for(int ii = i;ii<n;ii++)
    {
        res1 = func(ii+1,tot);
        res2 = func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1 || res2;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m && n > 1) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n == 1)
    {
        if(arr[0]%m == 0)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        res1 = func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,int tot)
{
//    cout << tot << endl;

    if(tot%m == 0 )foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        res1 = func(ii+1,arr[ii]) + func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;

    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        sf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,int tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        res1 = func(ii+1,arr[ii]) + func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;

    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        sf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
//    for(int ii = i;ii<n;ii++)
//    {
        res1 = func(i+1,arr[i]) + func(i+1,arr[i]+tot);
//    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        if( (arr[ii]+tot)%m == 0 )foundAns = true;
        res1 = func(ii+1,arr[ii]) + func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
    for(int ii = i;ii<n;ii++)
    {
        res1 = func(ii+1,arr[ii]) + func(ii+1,arr[ii]+tot);
    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;

    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        sf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
long long func(int i,long long tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns || i>=n)return tot;

    if(dp[i][tot%m] != -1)return dp[i][tot%m];

    long long res1=0,res2;
//    for(int ii = i;ii<n;ii++)
//    {
        res1 = func(i+1,arr[ii]) + func(i+1,arr[ii]+tot);
//    }
    return dp[i][tot%m] = res1;
}

int main()
{
//    READ();
//    WRITE();

//    cin >> n;
    sf(n);
    sf(m);

//    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        lsf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

//#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
//#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

int arr[1000010];

int n;
int m;
int dp[1010][1010][3];
bool foundAns = false;
int func(int i,int curTot,int fl)
{
//    cout << curTot << endl;
    if(foundAns)return 1;
    if(i>=n)
    {
        if(curTot == 0 && fl == 1)
        {
            foundAns = true;
            return 1;
        }
        else return 0;
    }

    if(dp[i][curTot][fl] != -1)return dp[i][curTot][fl];

    int res1 = func(i+1,(curTot+arr[i])%m,1);
    int res2 = func(i+1,(curTot),fl);

    return dp[i][curTot][fl] = res1 || res2;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;
    cin >> m;

    for(int i=0;i<n;i++)
    {
        cin >> arr[i];
    }

    if(n > m)cout << "YES" << endl;

    else if(n <= m)
    {
        memset(dp,-1,sizeof(dp));
        func(0,0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

//#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
//#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

int arr[1000010];

int n;
int m;
int dp[1010][1010][3];
bool foundAns = false;
int func(int i,int curTot,int fl)
{
//    cout << curTot << endl;
    if(foundAns)return 1;
    if(i>=n)
    {
        if(curTot == 0 && fl == 1)
        {
            foundAns = true;
            return 1;
        }
        else return 0;
    }

    if(dp[i][curTot][fl] != -1)return dp[i][curTot][fl];

    int res1 = func(i+1,(curTot+arr[i])%m,1);
    int res2 = func(i+1,(curTot),fl);

    return dp[i][curTot][fl] = res1 || res2;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;
    cin >> m;

    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];
        lsf(arr[i]);
    }

    if(n > m)cout << "YES" << endl;

    else if(n <= m)
    {
        memset(dp,-1,sizeof(dp));
        func(0,0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iterator>
#include <map>
#include <cstring>

using namespace std;

#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define sf(n) scanf("%d",&n)
#define lsf(n) scanf("%lld", &n)
#define pb(n) push_back(n)

#define debug(x,xString) cout << "value of " << xString<< "  : " << x << endl
#define debug() cout << "working!!" << endl;
#define MAX 10000007
#define MOD 1000000007

long long arr[1000010];
long long cum[1000010];

//long long dp[1010][1010];

bool foundAns = false;
int n;
int m;
void func(int i,int tot)
{
//    cout << tot << endl;

    if(tot%m == 0 && i>0)foundAns = true;
    if(foundAns)return;

    long long res1,res2;
    for(int ii = i;ii<n;ii++)
    {
        func(ii+1,(arr[ii]+tot));
    }
    return;
}

int main()
{
//    READ();
//    WRITE();

    cin >> n;

    cin >> m;

    bool found = false;
    map <long long, int> mp;
    for(int i=0;i<n;i++)
    {
//        cin >> arr[i];

        sf(arr[i]);

        if(i == 0)cum[i] = arr[i]%m;
        else cum[i] = (cum[i-1] + arr[i])%m;

        if(mp[cum[i]] == 1)
        {
            found = true;
//                break;
        }
        else mp[cum[i]]++;
    }

    if(n > m) /// piegeionhole thrm
    {

        if(found)cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    else if(n <= m) /// generate all subsequence
    {
//        memset(dp,-1,sizeof(dp));
        func(0,0);

        if(foundAns)cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

vi a;
vii points;
int n,d;

int dist(int i, int j){
	return abs(points[i].first - points[j].first) + abs(points[i].second - points[j].second);
}

bool check(int mid){
	vb vis(n,0);
	stack<ii> dfs;
	dfs.push(mp(0,mid));
	vis[0] = 1;
	while(!dfs.empty()){
		int curr = dfs.top().first, mon = dfs.top().second;
		dfs.pop();
		for(int i=0;i<n;i++){
			if(!vis[i] && d*dist(i,curr) <= mon){
				vis[i] = true;
				dfs.push(mp(i,mon - d*dist(i,curr)+a[i]));
			}
		}
	}
	return vis[n-1];

}

int main(){
	cin>>n>>d;
	a.resize(n);points.resize(n);
	for(int i=1;i<n-1;i++) cin>>a[i];
	a[0] = a[n-1] = 0;
	for(int i=0;i<n;i++) cin>>points[i].first>>points[i].second;
	int left = 0, right = 1000000000+1;
	while(left<right){
		int mid = (right-left)/2 + left;
		if(check(mid)) right = mid;
		else left = mid+1;
	}
	cout<<left<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back

typedef long long ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

vi a;
vii points;
int n,d;

int dist(int i, int j){
	return abs(points[i].first - points[j].first) + abs(points[i].second - points[j].second);
}

#define INF 1000000000

bool check(int mid){
	vb vis(n,0);
	vi dis(n,-1);

	priority_queue<ii> dfs;
	dfs.push(mp(mid,0));
	while(!dfs.empty()){
		int mon = dfs.top().first, curr = dfs.top().second;
		dfs.pop();
		vis[curr] = true;
		if(curr == n-1) return true;
		for(int i=0;i<n;i++){
			if(i!=curr && d*dist(i,curr) <= mon && dis[i] < mon - d*dist(i,curr) + a[i]){
				dis[i] = mon - d*dist(i,curr) + a[i];
				dfs.push(mp(dis[i],i));
			}
		}
	}
	return false;
}

int main(){
	cin>>n>>d;
	a.resize(n);points.resize(n);
	for(int i=1;i<n-1;i++) cin>>a[i];
	a[0] = a[n-1] = 0;
	for(int i=0;i<n;i++) cin>>points[i].first>>points[i].second;
	int left = 0, right = 1000000000+1;
	while(left<right){
		int mid = (right-left)/2 + left;
		if(check(mid)) right = mid;
		else left = mid+1;
	}
	cout<<left<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N=1e9+1;
int dd,z[1001],a[1001],heap[1001],top,n,d[1001],x[1001],y[1001],h[1001],pos[1001],aa[1001];
int p[1001];
bool td[1001];
struct gg
{
    int x,y;
}b[101];

void nhap()
{
    int i,j,m=0;
    scanf("%d %d\n",&n,&dd);
    for (i=2;i<=n-1;i++)
    {
        scanf("%d ",&aa[i]);
    }
    scanf("\n");
    for (i=1;i<=n;i++)
    {
        scanf("%d %d\n",&b[i].x,&b[i].y);
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i!=j)
            {
                m++;
                x[m]=i;
                y[m]=j;
                z[m]=abs(b[i].x-b[j].x)+abs(b[i].y-b[j].y);
                h[x[m]]++;
            }
        }
    }
    for (i=1;i<=n+1;i++)
    {
        h[i]+=h[i-1];
    }
    for (i=1;i<=m;i++)
    {
        a[h[x[i]]]=y[i];
        p[h[x[i]]]=z[i];
        h[x[i]]--;
    }
}

void swaph(int i,int j)
{
    swap(heap[i],heap[j]);
    pos[heap[i]]=i;
    pos[heap[j]]=j;
}

void up(int i)
{
    int j;
    j=i/2;
    if (i==1 || d[heap[i]]<d[heap[j]]) {return;}
    swaph(i,j);
    up(j);
}

void down(int i)
{
    int j;
    j=i*2;
    if (j>top) {return;}
    if (j<top && d[heap[j]]<d[heap[j+1]]) {j++;}
    if (d[heap[i]]>d[heap[j]]) {return;}
    swaph(i,j);
    down(j);
}

void push(int x)
{
    top++;
    heap[top]=x;
    pos[x]=top;
    up(top);
}

int pop()
{

    int t=heap[1];
    swaph(1,top);
    top--;
    down(1);
    return t;
}

bool kt(int x)
{
    int i,j,u,v;
    for (i=1;i<=n;i++)
    {
        d[i]=-2*N;
        td[i]=false;
        pos[i]=0;
    }
  //  cout<<x<<endl;
    top=0;
    d[1]=x;
    push(1);
    td[1]=true;
    while (top>0)
    {
        u=pop();
        td[u]=true;
        for (i=h[u]+1;i<=h[u+1];i++)
        {
            v=a[i];
          //  cout<<u<<" "<<v<<" "<<p[i]*dd<<" "<<d[u]<<endl;
            if (td[v]==true) {continue;}
            if (d[v]<d[u]-p[i]*dd+aa[v] && d[u]>=p[i]*dd)
            {
                d[v]=d[u]-p[i]*dd+aa[v];
                if (pos[v]==0) {push(v);}
                else {up(pos[v]);}
            }
        }
    }
    if (d[n]>=0) {return true;}
    else {return false;}
}
void xuli()
{
    int i,l=1,r=N,m,res;bool kt1,kt2;
    while (l<=r)
    {
        m=(l+r)/2;
        //cout<<m<<endl
        kt1=kt(m-1);
        kt2=kt(m);
        if (kt1==false && kt2==true) {res=m;break;}
        if (kt2==true) {r=m-1;}
        else {l=m+1;}
    }
    cout<<res;
}
int main()
{
   // freopen("tham.inp","r",stdin);
  //  freopen("tham.out","w",stdout);
    nhap();
    xuli();
}


#include <bits/stdc++.h>

using namespace std;

const int N=1e9+1;
int dd,z[101],a[1001],heap[1001],top,n,d[101],x[101],y[101],h[101],pos[101],aa[101];
int p[1001];
bool td[101];
struct gg
{
    int x,y;
}b[101];

void nhap()
{
    int i,j,m=0;
    scanf("%d %d\n",&n,&dd);
    for (i=2;i<=n-1;i++)
    {
        scanf("%d ",&aa[i]);
    }
    scanf("\n");
    for (i=1;i<=n;i++)
    {
        scanf("%d %d\n",&b[i].x,&b[i].y);
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i!=j)
            {
                m++;
                x[m]=i;
                y[m]=j;
                z[m]=abs(b[i].x-b[j].x)+abs(b[i].y-b[j].y);
                h[x[m]]++;
            }
        }
    }
    for (i=1;i<=n+1;i++)
    {
        h[i]+=h[i-1];
    }
    for (i=1;i<=m;i++)
    {
        a[h[x[i]]]=y[i];
        p[h[x[i]]]=z[i];
        h[x[i]]--;
    }
}

void swaph(int i,int j)
{
    swap(heap[i],heap[j]);
    pos[heap[i]]=i;
    pos[heap[j]]=j;
}

void up(int i)
{
    int j;
    j=i/2;
    if (i==1 || d[heap[i]]<d[heap[j]]) {return;}
    swaph(i,j);
    up(j);
}

void down(int i)
{
    int j;
    j=i*2;
    if (j>top) {return;}
    if (j<top && d[heap[j]]<d[heap[j+1]]) {j++;}
    if (d[heap[i]]>d[heap[j]]) {return;}
    swaph(i,j);
    down(j);
}

void push(int x)
{
    top++;
    heap[top]=x;
    pos[x]=top;
    up(top);
}

int pop()
{

    int t=heap[1];
    swaph(1,top);
    top--;
    down(1);
    return t;
}

bool kt(int x)
{
    int i,j,u,v;
    for (i=1;i<=n;i++)
    {
        d[i]=-100000;
        td[i]=false;
        pos[i]=0;
    }
  //  cout<<x<<endl;
    top=0;
    d[1]=x;
    push(1);
    td[1]=true;
    while (top>0)
    {
        u=pop();
        td[u]=true;
        for (i=h[u]+1;i<=h[u+1];i++)
        {
            v=a[i];
          //  cout<<u<<" "<<v<<" "<<p[i]*dd<<" "<<d[u]<<endl;
            if (td[v]==true) {continue;}
            if (d[v]<d[u]-p[i]*dd+aa[v] && d[u]>=p[i]*dd)
            {
                d[v]=d[u]-p[i]*dd+aa[v];
                if (pos[v]==0) {push(v);}
                else {up(pos[v]);}
            }
        }
    }
    if (d[n]>=0) {return true;}
    else {return false;}
}
void xuli()
{
    int i,l=1,r=N,m,res;
    while (l<=r)
    {
        m=(l+r)/2;
        //cout<<m<<endl;
        if (kt(m)==true) {res=m;r=m-1;}
        else {l=m+1;}
    }
    cout<<res;
}
int main()
{
  //  freopen("tham.inp","r",stdin);
  //  freopen("tham.out","w",stdout);
    nhap();
    xuli();
}


#include <bits/stdc++.h>

using namespace std;

const int N=1e9+1;
int dd,z[101],a[1001],heap[1001],top,n,d[101],x[101],y[101],h[101],pos[101],aa[101];
int p[1001];
bool td[101];
struct gg
{
    int x,y;
}b[101];

void nhap()
{
    int i,j,m=0;
    scanf("%d %d\n",&n,&dd);
    for (i=2;i<=n-1;i++)
    {
        scanf("%d ",&aa[i]);
    }
    scanf("\n");
    for (i=1;i<=n;i++)
    {
        scanf("%d %d\n",&b[i].x,&b[i].y);
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i!=j)
            {
                m++;
                x[m]=i;
                y[m]=j;
                z[m]=abs(b[i].x-b[j].x)+abs(b[i].y-b[j].y);
                h[x[m]]++;
            }
        }
    }
    for (i=1;i<=n+1;i++)
    {
        h[i]+=h[i-1];
    }
    for (i=1;i<=m;i++)
    {
        a[h[x[i]]]=y[i];
        p[h[x[i]]]=z[i];
        h[x[i]]--;
    }
}

void swaph(int i,int j)
{
    swap(heap[i],heap[j]);
    pos[heap[i]]=i;
    pos[heap[j]]=j;
}

void up(int i)
{
    int j;
    j=i/2;
    if (i==1 || d[heap[i]]<d[heap[j]]) {return;}
    swaph(i,j);
    up(j);
}

void down(int i)
{
    int j;
    j=i*2;
    if (j>top) {return;}
    if (j<top && d[heap[j]]<d[heap[j+1]]) {j++;}
    if (d[heap[i]]>d[heap[j]]) {return;}
    swaph(i,j);
    down(j);
}

void push(int x)
{
    top++;
    heap[top]=x;
    pos[x]=top;
    up(top);
}

int pop()
{

    int t=heap[1];
    swaph(1,top);
    top--;
    down(1);
    return t;
}

bool kt(int x)
{
    int i,j,u,v;
    for (i=1;i<=n;i++)
    {
        d[i]=-2*N;
        td[i]=false;
        pos[i]=0;
    }
  //  cout<<x<<endl;
    top=0;
    d[1]=x;
    push(1);
    td[1]=true;
    while (top>0)
    {
        u=pop();
        td[u]=true;
        for (i=h[u]+1;i<=h[u+1];i++)
        {
            v=a[i];
          //  cout<<u<<" "<<v<<" "<<p[i]*dd<<" "<<d[u]<<endl;
            if (td[v]==true) {continue;}
            if (d[v]<d[u]-p[i]*dd+aa[v] && d[u]>=p[i]*dd)
            {
                d[v]=d[u]-p[i]*dd+aa[v];
                if (pos[v]==0) {push(v);}
                else {up(pos[v]);}
            }
        }
    }
    if (d[n]>=0) {return true;}
    else {return false;}
}
void xuli()
{
    int i,l=1,r=N,m,res;
    while (l<=r)
    {
        m=(l+r)/2;
        //cout<<m<<endl;
        if (kt(m)==true) {res=m;r=m-1;}
        else {l=m+1;}
    }
    cout<<res;
}
int main()
{
   // freopen("tham.inp","r",stdin);
   // freopen("tham.out","w",stdout);
    nhap();
    xuli();
}


#include <bits/stdc++.h>

using namespace std;

const int N=1e9+1;
int dd,z[101],a[1001],heap[1001],top,n,d[101],x[101],y[101],h[101],pos[101],aa[101];
int p[1001];
bool td[101];
struct gg
{
    int x,y;
}b[101];

void nhap()
{
    int i,j,m=0;
    scanf("%d %d\n",&n,&dd);
    for (i=2;i<=n-1;i++)
    {
        scanf("%d ",&aa[i]);
    }
    scanf("\n");
    for (i=1;i<=n;i++)
    {
        scanf("%d %d\n",&b[i].x,&b[i].y);
    }
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=n;j++)
        {
            if (i!=j)
            {
                m++;
                x[m]=i;
                y[m]=j;
                z[m]=abs(b[i].x-b[j].x)+abs(b[i].y-b[j].y);
                h[x[m]]++;
            }
        }
    }
    for (i=1;i<=n+1;i++)
    {
        h[i]+=h[i-1];
    }
    for (i=1;i<=m;i++)
    {
        a[h[x[i]]]=y[i];
        p[h[x[i]]]=z[i];
        h[x[i]]--;
    }
}

void swaph(int i,int j)
{
    swap(heap[i],heap[j]);
    pos[heap[i]]=i;
    pos[heap[j]]=j;
}

void up(int i)
{
    int j;
    j=i/2;
    if (i==1 || d[heap[i]]<d[heap[j]]) {return;}
    swaph(i,j);
    up(j);
}

void down(int i)
{
    int j;
    j=i*2;
    if (j>top) {return;}
    if (j<top && d[heap[j]]<d[heap[j+1]]) {j++;}
    if (d[heap[i]]>d[heap[j]]) {return;}
    swaph(i,j);
    down(j);
}

void push(int x)
{
    top++;
    heap[top]=x;
    pos[x]=top;
    up(top);
}

int pop()
{

    int t=heap[1];
    swaph(1,top);
    top--;
    down(1);
    return t;
}

bool kt(int x)
{
    int i,j,u,v;
    for (i=1;i<=n;i++)
    {
        d[i]=-2*N;
        td[i]=false;
        pos[i]=0;
    }
  //  cout<<x<<endl;
    top=0;
    d[1]=x;
    push(1);
    td[1]=true;
    while (top>0)
    {
        u=pop();
        td[u]=true;
        for (i=h[u]+1;i<=h[u+1];i++)
        {
            v=a[i];
          //  cout<<u<<" "<<v<<" "<<p[i]*dd<<" "<<d[u]<<endl;
            if (td[v]==true) {continue;}
            if (d[v]<d[u]-p[i]*dd+aa[v] && d[u]>=p[i]*dd)
            {
                d[v]=d[u]-p[i]*dd+aa[v];
                if (pos[v]==0) {push(v);}
                else {up(pos[v]);}
            }
        }
    }
    if (d[n]>=0) {return true;}
    else {return false;}
}
void xuli()
{
    int i,l=1,r=N,m,res;bool kt1,kt2;
    while (l<=r)
    {
        m=(l+r)/2;
        //cout<<m<<endl
        kt1=kt(m-1);
        kt2=kt(m);
        if (kt1==false && kt2==true) {res=m;break;}
        if (kt2==true) {r=m-1;}
        else {l=m+1;}
    }
    cout<<res;
}
int main()
{
  //  freopen("tham.inp","r",stdin);
  //  freopen("tham.out","w",stdout);
    nhap();
    xuli();
}


#include<bits/stdc++.h>

using namespace std;
const int maxn = 105;
int e[maxn][maxn], a[maxn], x[maxn], y[maxn], d, n;
int main() {
	cin >> n >> d;
	for (int i = 1; i <= n - 2; i++) cin >> a[i];
	for (int i = 0; i<n; i++) cin >> x[i] >> y[i];
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			e[i][j] = d*(abs(x[j] - x[i]) + abs(y[j] - y[i])) - a[i];
		}
		e[i][i] = 0;
	}
	for (int k = 0; k<n; k++)
		for (int i = 0; i<n; i++)
			for (int j = 0; j<n; j++)
				e[i][j] = min(e[i][j], e[i][k] + e[k][j]);
	cout << e[0][n - 1];
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, d, a[101], x[101], y[101];
long long dt[101][101];
int main() {
	scanf("%d%d",&n,&d);
	for(int i = 2; i < n; i++) scanf("%d",a+i);
	for(int i = 1; i <= n; i++) scanf("%d%d",x+i,y+i);
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) if(i != j) dt[i][j] = d*(abs(x[i]-x[j])+abs(y[i]-y[j]))-a[i];
	for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dt[i][j] = min(dt[i][k]+dt[k][j], dt[i][j]);
	printf("%lld", dt[1][n]);
}


#include <bits/stdc++.h>

using namespace std;

const int inf = 100000;

int main(){
    int n,d;
    cin>>n>>d;

    int x[n],y[n],a[n];

    memset(a,0,sizeof(a));

    for(int i=1;i<n-1;i++) cin>>a[i];

    for(int i=0;i<n;i++) cin>>x[i]>>y[i];

    int dist[n],p[n];
    for(int i=0;i<n;i++) dist[i] = inf;

    dist[0] = 0;
    p[0] = -1;
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                if(k==j) continue;
                if(dist[k] >= dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k])){
                    dist[k] = dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k]);
                    p[k] = j;
                }
            }
        }
    }

    int ans = 0;
    ans = dist[n-1]*d;
    int i = n-1;
    while(i!=0){
        ans -= a[p[i]];
        i = p[i];
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long inf = 100000000;

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

    long x[n],y[n],a[n];

    memset(a,0,sizeof(a));

    for(long i=1;i<n-1;i++) cin>>a[i];

    for(long i=0;i<n;i++) cin>>x[i]>>y[i];

    long dist[n],p[n],cost[n];

    for(long i=0;i<n;i++) dist[i] = inf;
    for(int i=0;i<n;i++) p[i] = 0;
    for(int i=0;i<n;i++) cost[i] = inf;
    dist[0] = 0;
    p[0] = -1;
    cost[0] = 0;

    for(long i=0;i<n-1;i++){
        for(long j=0;j<n;j++){
            for(long k=0;k<n;k++){
                if(k==j) continue;
                if(cost[k] > cost[j] + d*(abs(x[j]-x[k]) + abs(y[j]-y[k])) - a[j]){

                    cost[k] = cost[j] + d*(abs(x[j]-x[k]) + abs(y[j]-y[k])) - a[j];

                    dist[k] = dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k]);
                }
            }
        }
    }

    cout<<cost[n-1];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long inf = 100000000;

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

    long x[n],y[n],a[n];

    memset(a,0,sizeof(a));

    for(long i=1;i<n-1;i++) cin>>a[i];

    for(long i=0;i<n;i++) cin>>x[i]>>y[i];

    long dist[n],p[n];
    for(long i=0;i<n;i++) dist[i] = inf;
    for(int i=0;i<n;i++) p[i] = 0;

    dist[0] = 0;
    p[0] = -1;
    for(long i=0;i<n-1;i++){
        for(long j=0;j<n;j++){
            for(long k=0;k<n;k++){
                if(k==j) continue;
                if(dist[k] > dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k])){
                    dist[k] = dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k]);
                    p[k] = j;
                }
                else if(dist[k] == dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k])){
                    if(a[p[k]]<a[j]){
                        dist[k] = dist[j] + abs(x[j]-x[k]) + abs(y[j]-y[k]);
                        p[k] = j;
                    }
                }
            }
        }
    }

    long ans = 0;
    ans = dist[n-1]*d;
    long i = n-1;
    while(i!=0){
        ans -= a[p[i]];
        i = p[i];
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define _for(i,a,b) for(int i=(a),_b=(b);i<_b;++i)

using namespace std;
const int maxn=101;
struct coor
{
    int x,y;
    coor(){}
    coor(int aa,int bb)
    {
        x=aa; y=bb;
    }
};
coor a[maxn];
int n,d;
int b[maxn];
void enter()
{
    cin>>n>>d;
    _for(i,2,n) cin>>b[i];
    _for(i,1,n+1) cin>>a[i].x>>a[i].y;
}
int f[maxn];
bool D[maxn];
typedef pair<int,int> pir;
#define fi first
#define se second
int dis(int X,int Y)
{
    return abs(a[X].x - a[Y].x) + abs(a[X].y - a[Y].y);
}
void dijkstra()
{
    priority_queue<pir,vector<pir>,greater<pir>> heap;
    heap.push(pir(0,1));
    while(!heap.empty())
    {
        pir q=heap.top();
        heap.pop();
        if (D[q.se]==false)
        {
            D[q.se]=true;
            f[q.se]=q.fi;
            _for(i,1,n+1)
                if (i!=q.se && D[i]==false)
                {
                    int tt=dis(q.se, i)*d - b[q.se];
                    heap.push(pir(tt + f[q.se], i));
                }
        }
    }
    cout<<f[n];
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    enter();
    dijkstra();
}


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define int         long long
    #define pb          push_back
    #define vi          vector<int>
    #define vvi         vector<vector<int>>
    #define pii         pair<int,int>
    #define all(a)      (a).begin(),(a).end()
    #define ff           first
    #define ss           second

    /*----------------------Graph Moves----------------*/
    // const int fx[]={+1,-1,+0,+0};
    // const int fy[]={+0,+0,+1,-1};
    //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
    //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
    // const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
    // const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
    /*------------------------------------------------*/

    const int N = 1e2 + 5, K = 20, mod = 1000000007, MOD = 1000000007, INF = LLONG_MAX/2;
    int n,dc;
    vector<pii> ver(N);
    vi d(N), p(N), vis(N);
    vector<pair<int, int>> adj[N];
    vi a(N);

    void dijkstra(int s) {
        for(int i=0; i<N; i++)
            d[i] = INF;

        d[s] = 0;
        priority_queue<pii, vector<pii>, greater<pii>> q;
        q.push({0, s});
        while (!q.empty()) {
            int v = q.top().second;
            int d_v = q.top().first;
            q.pop();
            if (vis[v])
                continue;
            vis[v] = 1;
            for (auto edge : adj[v]) {
                int to = edge.first;
                int len = edge.second;

                if (d[v] + len - a[v] < d[to]) {
                    d[to] = d[v] + len - a[v];
                    p[to] = v;
                    q.push({d[to], to});
                }
            }
        }
    }
    void solve(){
        cin>>n>>dc;
        for(int i=2; i<n; i++){
            cin>>a[i];
        }
        int x,y;
        for(int i=1; i<=n; i++){
            cin>>x>>y;
            ver[i] = {x,y};
        }
        for(int i=1; i<n; i++){
            for(int j=i+1; j<=n; j++){
                int dis = abs(ver[i].ff - ver[j].ff) + abs(ver[i].ss - ver[j].ss);
                adj[i].pb({j,dis*dc});
                if(j<n) adj[j].pb({i,dis*dc});
            }
        }
        dijkstra(1);
        cout<<d[n]<<endl;
    }

    int32_t main()
    {
        IOS;
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();
        }
        return 0;
    }


#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define add(x,y) ((ll)(x)+(y))%mod
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//
const int N = 201;
ll bd[N ][N ];
int a[100];
const int DD = 100; int d;
int dist(int i1, int j1, int i2, int j2) {
	return d*(abs(i1 - i2) + abs(j1 - j2));
}
int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; nii(n, d);
	F(i, n - 2) {
		ni(a[i + 1]);
	}
	int x, y; nii(x, y);
	x += DD; y += DD;
	F(i, N)F(j, N)bd[i][j] = 9000000000000000000LL;
	bd[x][y] = 0;
	F(i, N)F(j, N) {
		bd[i][j] = min(bd[i][j], bd[x][y] + dist(x, y, i, j));
	}
	F(i, n - 2) {
		int x, y;
		nii(x, y); x += DD; y += DD;
		bd[x][y] -= a[i + 1];
		F(i, N)F(j, N)bd[i][j] = min(bd[i][j], bd[x][y] + dist(x, y, i, j));
	}
	 nii(x, y); x += DD; y += DD;
	printf("%I64d\n", (bd[x][y]<0)?0:bd[x][y]);
	return 0;
}


#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define add(x,y) ((ll)(x)+(y))%mod
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//
const int N = 100;
int x[N], y[N], a[N];
int cst[N], chk[N];
int d;
int dist(int i, int j) {
	return d*(abs(x[i] - x[j]) + abs(y[i] - y[j]));
}
int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n; nii(n, d);
	FF(i, n - 2)  ni(a[i]);
	F(i, n) nii(x[i], y[i]);
	chk[n - 1] = 1;
	while (!chk[0]) {
		int ii = -1; int cur = inf;
		F(i, n) {
			if (chk[i]) continue;
			int c = inf;
			F(j, n) {
				if (chk[j]) {
					c = min(c, max(dist(i,j) - a[i],cst[j] + dist(i, j) - a[i]));
				}
			}
			if (c < cur) {
				ii = i;
				cur = c;
			}
		}
		chk[ii] = 1;
		cst[ii] = cur;
	}
	if (cst[0] < 0) cst[0] = 0;
	printf("%d\n", cst[0]);
	return 0;
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public BigInteger big() throws IOException{
            if(st.hasMoreTokens())
                return new BigInteger(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return big();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){
        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){
            @SuppressWarnings("unused")
            int pos = array.length - 1;
            int bitmask = i;
            while(bitmask > 0){
                if((bitmask & 1) == 1)
//                    ww.print(array[pos]+" ");
                bitmask >>= 1;
                pos--;
            }
//            ww.println();
        }
    }

    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static long lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static long lcm(long a, long b){
        return (a*b/gcd(a,b));
    }

    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }

    ////////////////////////////////////////////////////////////////////

//    FastScanner s = new FastScanner(new File("input.txt"));
//    PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream);
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int d = s.nextInt();
        Point[] point = new Point[n];
        int[] a = new int[n];
        a[0] = 0;
        a[n-1] = 0;
        int[][] dist = new int[n][n];

        for(int i=1;i<n-1;i++) a[i] = s.nextInt();

        for(int i=0;i<n;i++){
            int x = s.nextInt();
            int y = s.nextInt();
            point[i] = new Point(x,y);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i == j) continue;
                if(j != n-1)    dist[i][j] = (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d - a[j];
                else  dist[i][j] += (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;
            }
        }

        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (dist[i][j] > dist[i][k] + dist[k][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        ww.println(dist[0][n-1]);

    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public BigInteger big() throws IOException{
            if(st.hasMoreTokens())
                return new BigInteger(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return big();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){
        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){
            @SuppressWarnings("unused")
            int pos = array.length - 1;
            int bitmask = i;
            while(bitmask > 0){
                if((bitmask & 1) == 1)
//                    ww.print(array[pos]+" ");
                bitmask >>= 1;
                pos--;
            }
//            ww.println();
        }
    }

    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static long lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static long lcm(long a, long b){
        return (a*b/gcd(a,b));
    }

    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }

    ////////////////////////////////////////////////////////////////////

//    FastScanner s = new FastScanner(new File("input.txt"));
//    PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream);
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int d = s.nextInt();
        Point[] point = new Point[n];
        int[] a = new int[n];
        a[0] = 0;
        a[n-1] = 0;
        int[][] dist = new int[n][n];

        for(int i=1;i<n-1;i++) a[i] = s.nextInt();

        for(int i=0;i<n;i++){
            int x = s.nextInt();
            int y = s.nextInt();
            point[i] = new Point(x,y);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i == j){
                    dist[i][j] = 0;
                    continue;
                }
                if(j != n-1){
//                  System.out.println(j);
//                  System.out.println(((int)point[i].distance(point[j]))*d);
                    dist[i][j] = a[j] - (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;

                }else{
                    dist[i][j] -= (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;
                }
            }
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
//              ww.print(dist[i][j]+" ");
                dist[i][j] = Math.abs(dist[i][j]);
            }
//          ww.println();
        }

        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (dist[i][j] > dist[i][k] + dist[k][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

/*      ww.println("\n");
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                ww.print(dist[i][j]+" ");
            ww.println();
        }
*/
        ww.println(dist[0][n-1]);

    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public BigInteger big() throws IOException{
            if(st.hasMoreTokens())
                return new BigInteger(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return big();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){
        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){
            @SuppressWarnings("unused")
			int pos = array.length - 1;
            int bitmask = i;
            while(bitmask > 0){
                if((bitmask & 1) == 1)
//                    ww.print(array[pos]+" ");
                bitmask >>= 1;
                pos--;
            }
//            ww.println();
        }
    }

    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static long lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static long lcm(long a, long b){
        return (a*b/gcd(a,b));
    }

    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }

    ////////////////////////////////////////////////////////////////////

//    FastScanner s = new FastScanner(new File("input.txt"));
//    PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream);
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

    	int n = s.nextInt();
    	int d = s.nextInt();
    	Point[] point = new Point[n];
    	int[] a = new int[n-2];
    	int[][] dist = new int[n][n];

    	for(int i=0;i<n-2;i++) a[i] = s.nextInt();

    	for(int i=0;i<n;i++){
    		int x = s.nextInt();
    		int y = s.nextInt();
    		point[i] = new Point(x,y);
    	}

    	for(int i=0;i<n;i++){
    		for(int j=0;j<n;j++){
    			if(i == j || j < i){
    				dist[i][j] = 0;
    				continue;
    			}
    			if(j != n-1){
//    				System.out.println(j);
//    				System.out.println(((int)point[i].distance(point[j]))*d);
    				dist[i][j] = a[j-1] - (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;

    			}else{
    				dist[i][j] -= (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;
    			}
    		}
    	}

    	for(int i=0;i<n;i++){
    		for(int j=0;j<n;j++){
 //   			ww.print(dist[i][j]+" ");
    			dist[i][j] = Math.abs(dist[i][j]);
    		}
 //   		ww.println();
    	}

    	for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                	if(j < i) continue;
                    if (dist[i][j] > dist[i][k] + dist[k][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

/*    	ww.println("\n");
    	for(int i=0;i<n;i++){
    		for(int j=0;j<n;j++)
    			ww.print(dist[i][j]+" ");
    		ww.println();
    	}
*/
    	ww.println(dist[0][n-1]);

    }
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Solution{

    ///////////////////////////////////////////////////////////////////////////
    static class FastScanner{
        BufferedReader s;
        StringTokenizer st;

        public FastScanner(InputStream InputStream){
            st = new StringTokenizer("");
            s = new BufferedReader(new InputStreamReader(InputStream));
        }

        public FastScanner(File f) throws FileNotFoundException{
            st = new StringTokenizer("");
            s = new BufferedReader (new FileReader(f));
        }

        public int nextInt() throws IOException{
            if(st.hasMoreTokens())
                return Integer.parseInt(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextInt();
            }
        }

        public BigInteger big() throws IOException{
            if(st.hasMoreTokens())
                return new BigInteger(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return big();
            }
        }

        public double nextDouble() throws IOException{
            if(st.hasMoreTokens())
                return Double.parseDouble(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextDouble();
            }
        }

        public long nextLong() throws IOException{
            if(st.hasMoreTokens())
                return Long.parseLong(st.nextToken());
            else{
                st = new StringTokenizer(s.readLine());
                return nextLong();
            }
        }

        public String nextString() throws IOException{
            if(st.hasMoreTokens())
                return st.nextToken();
            else{
                st = new StringTokenizer(s.readLine());
                return nextString();
            }

        }
        public String readLine() throws IOException{
            return s.readLine();
        }

        public void close() throws IOException{
            s.close();
        }

    }

    ////////////////////////////////////////////////////////////////////
    //      Number Theory

    long pow(long a,long b,long mod){
        long x = 1; long y = a;
        while(b > 0){
            if(b % 2 == 1){
                x = (x*y);
                x %= mod;
            }
            y = (y*y);
            y %= mod;
            b /= 2;
        }
        return x;
    }

    int divisor(long x,long[] a){
        long limit = x;
        int numberOfDivisors = 0;

        for (int i=1; i < limit; ++i) {
            if (x % i == 0) {
                limit = x / i;
                if (limit != i) {
                    numberOfDivisors++;
                }
                numberOfDivisors++;
            }
        }
        return numberOfDivisors;
    }

    void findSubsets(int array[]){
        long numOfSubsets = 1 << array.length;
        for(int i = 0; i < numOfSubsets; i++){
            @SuppressWarnings("unused")
            int pos = array.length - 1;
            int bitmask = i;
            while(bitmask > 0){
                if((bitmask & 1) == 1)
//                    ww.print(array[pos]+" ");
                bitmask >>= 1;
                pos--;
            }
//            ww.println();
        }
    }

    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a%b);
    }

    public static long lcm(int a,int b, int c){
        return lcm(lcm(a,b),c);
    }

    public static long lcm(long a, long b){
        return (a*b/gcd(a,b));
    }

    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }

    ////////////////////////////////////////////////////////////////////

//    FastScanner s = new FastScanner(new File("input.txt"));
//    PrintWriter ww = new PrintWriter(new FileWriter("output.txt"));
    static InputStream inputStream = System.in;
    static FastScanner s = new FastScanner(inputStream);
    static OutputStream outputStream = System.out;
    static PrintWriter ww = new PrintWriter(new OutputStreamWriter(outputStream));
//      private static Scanner s = new Scanner(System.in);
    @SuppressWarnings("unused")
    private static int[][] states = { {-1,0} , {1,0} , {0,-1} , {0,1} };

    ////////////////////////////////////////////////////////////////////

    public static void main(String[] args) throws IOException{
        new Solution().solve();
        s.close();
        ww.close();
    }

    ////////////////////////////////////////////////////////////////////

    void solve() throws IOException{

        int n = s.nextInt();
        int d = s.nextInt();
        Point[] point = new Point[n];
        int[] a = new int[n];
        a[0] = 0;
        a[n-1] = 0;
        int[][] dist = new int[n][n];

        for(int i=1;i<n-1;i++) a[i] = s.nextInt();

        for(int i=0;i<n;i++){
            int x = s.nextInt();
            int y = s.nextInt();
            point[i] = new Point(x,y);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i == j){
                    dist[i][j] = 0;
                    continue;
                }
                if(j != n-1){
                    dist[i][j] = (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d - a[j];

                }else{
                    dist[i][j] += (Math.abs(point[i].x-point[j].x)+Math.abs(point[i].y-point[j].y))*d;
                }
            }
        }

        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (dist[i][j] > dist[i][k] + dist[k][j]) {
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        ww.println(dist[0][n-1]);

    }
}


import static java.lang.Math.*;

public class B {

	private final static boolean autoflush = false;

	public B () {
		int N = sc.nextInt();
		long D = sc.nextLong();
		Long [] A = sc.nextLongs();
		Integer [][] P = sc.nextInts(N);

		long [][] G = new long [N][N];
		for (int i : rep(N))
			for (int j : rep(N))
				if (i != j) {
					for (int k : rep(2))
						G[i][j] += D * abs(P[i][k] - P[j][k]);
					if (i > 0 && i < N-1)
						G[i][j] -= A[i-1];
				}

		fw(G);
		long res = G[0][N-1];
		exit(res);
	}

	void fw(long [][] G) {
		int N = G.length;
		for (int k = 0; k < N; ++k)
			for (int i = 0; i < N; ++i)
				for (int j = 0; j < N; ++j)
					G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public long nextLong() { return Long.parseLong(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}
		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextInts();
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}


import static java.lang.Math.*;

public class B {

	private final static boolean autoflush = false;

	public B () {
		N = sc.nextInt();
		d = sc.nextInt();
		A = sc.nextLongs();
		P = sc.nextInts(N);

		G = new int [N][N];
		for (int i : rep(N))
			for (int j : rep(N))
				for (int k : rep(2))
					G[i][j] += abs(P[i][k] - P[j][k]);

		long p = -1, q = (long)1e18, m;
		while (q - p > 1) {
			m = (p+q)/2;
			if (eval(m))
				q = m;
			else p = m;
		}

		exit(q);
	}

	int N; long d; Long [] A; Integer [][] P; int [][] G;

	boolean eval(long M) {
		boolean [] V = new boolean [N];
		return dfs(0, M, V);
	}

	boolean dfs(int S, long M, boolean [] V) {
		if (M < 0)
			return false;

		if (S == N-1)
			return true;

		V[S] = true;
		if (S > 0)
			M += A[S-1];

		for (int T = N-1; T > 0; ++T)
			if (!V[T]) {
				long m = M - d * G[S][T];
				if (m >= 0 && dfs(T, m, V))
					return true;
			}

		V[S] = false;
		return false;
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}
		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextInts();
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}


import static java.lang.Math.*;

public class B {

	private final static boolean autoflush = false;

	public B () {
		N = sc.nextInt();
		d = sc.nextInt();
		A = sc.nextLongs();
		P = sc.nextInts(N);

		G = new int [N][N];
		for (int i : rep(N))
			for (int j : rep(N))
				for (int k : rep(2))
					G[i][j] += abs(P[i][k] - P[j][k]);

		long p = -1, q = (long)1e18, m;
		while (q - p > 1) {
			m = (p+q)/2;
			if (eval(m))
				q = m;
			else p = m;
		}

		exit(q);
	}

	int N; long d; Long [] A; Integer [][] P; int [][] G;

	boolean eval(long M) {
		boolean [] V = new boolean [N];
		return dfs(0, M, V);
	}

	boolean dfs(int S, long M, boolean [] V) {
		if (M < 0)
			return false;

		if (S == N-1)
			return true;

		V[S] = true;
		if (S > 0)
			M += A[S-1];

		for (int T = N-1; T > 0; --T)
			if (!V[T]) {
				long m = M - d * G[S][T];
				if (m >= 0 && dfs(T, m, V))
					return true;
			}

		V[S] = false;
		return false;
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}
		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextInts();
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}


import static java.lang.Math.*;

public class B {

	private final static boolean autoflush = false;

	public B () {
		N = sc.nextInt();
		d = sc.nextInt();
		A = sc.nextLongs();
		P = sc.nextInts(N);

		G = new int [N][N];
		for (int i : rep(N))
			for (int j : rep(N))
				for (int k : rep(2))
					G[i][j] += abs(P[i][k] - P[j][k]);

		long p = -1, q = (long)1e18, m;
		while (q - p > 1) {
			m = (p+q)/2;
			if (eval(m))
				q = m;
			else p = m;
		}

		exit(q);
	}

	int N; long d; Long [] A; Integer [][] P; int [][] G;

	boolean eval(long M) {
		boolean [] V = new boolean [N];
		return dfs(0, M, V);
	}

	boolean dfs(int S, long M, boolean [] V) {
		if (M < 0)
			return false;

		if (S == N-1)
			return true;

		V[S] = true;
		if (S > 0)
			M += A[S-1];

		for (int T = 1; T < N; ++T)
			if (!V[T])
				if (dfs(T, M - d * G[S][T], V))
					return true;

		V[S] = false;
		return false;
	}

	////////////////////////////////////////////////////////////////////////////////////
	private static int [] rep(int N) { return rep(0, N); }
	private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		public Long [] nextLongs() {
			String [] L = nextStrings();
			Long [] res = new Long [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Long.parseLong(L[i]);
			return res;
		}
		public Integer [][] nextInts (int N) {
			Integer [][] res = new Integer [N][];
			for (int i = 0; i < N; ++i)
				res[i] = nextInts();
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit (Object o, Object... a) { print(o, a); exit(); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}


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

public class Solver {

	static final int inf = 1000000000;

	class Point {
		int x, y;
	}

	void solve() throws IOException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();
		int d = in.nextInt();
		int[] a = new int[n];
		Point[] p = new Point[n];
		int[][] m = new int[n][n];
		int[] s = new int[n];

		for (int i = 1; i < n - 1; i++) a[i] = in.nextInt();
		for (int i = 0; i < n; i++) {
			p[i] = new Point();
			p[i].x = in.nextInt();
			p[i].y = in.nextInt();
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				m[i][j] = (Math.abs(p[i].x - p[j].x) + Math.abs(p[i].y - p[j].y)) * d - a[i];
			}
		}
		boolean[] used = new boolean[n];
		for (int i = 0; i < n; i++) s[i] = inf;
		s[0] = 0;
		for (int step = 0; step < n; step++) {
			int minVal = inf + 1;
			int minInd = -1;

			for (int i = 0; i < n; i++) {
				if (!used[i] && minVal > s[i]) {
					minVal = s[i];
					minInd = i;
				}
			}
			used[minInd] = true;
			for (int i = 0; i < n; i++) {
				if (!used[i]) s[i] = Math.min(s[i], s[minInd] + m[minInd][i]);
			}
		}
		out.print(s[n - 1]);

		out.close();
	}

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


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

public class Solver {

	static final int inf = 1000000000;

	class Point {
		int x, y;
	}

	void solve() throws IOException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();
		int d = in.nextInt();
		int[] a = new int[n];
		Point[] p = new Point[n];
		int[][] m = new int[n][n];

		for (int i = 1; i < n - 1; i++) a[i] = in.nextInt();
		for (int i = 0; i < n; i++) {
			p[i] = new Point();
			p[i].x = in.nextInt();
			p[i].y = in.nextInt();
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				m[i][j] = (Math.abs(p[i].x - p[j].x) + Math.abs(p[i].y - p[j].y)) * d - a[i];
			}
			m[i][i] = 0;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					m[j][k] = Math.min(m[j][k], m[j][i] + m[i][k]);
				}
			}
		}
		out.print(m[0][n - 1]);

		out.close();
	}

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


// @author Sanzhar
import java.io.*;
import java.util.*;
import java.awt.Point;

public class Template {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer st;

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(in.readLine());
            } catch (Exception e) {
            }
        }
        return st.nextToken();
    }

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

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

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

    public void run() throws Exception {
        //in = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter(new FileWriter("output.txt"));
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
        in.close();
    }

    public void solve() throws Exception {
        int n = nextInt();
        long cost = nextLong();
        long[] a = new long[n];
        for (int i = 1; i < n - 1; i++) {
            a[i] = nextLong();
        }
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = nextInt();
            y[i] = nextInt();
        }
        long[][] d = new long[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                d[i][j] = cost * (Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j])) - a[j];
            }
        }
        for (int k = 0; k < n; k++) {
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        out.println(d[0][n - 1]);
    }

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


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Solver {

    static final int inf = 1000000000;

    class Point{
        int x, y;
    }

    public void solve() throws IOException{
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int d = in.nextInt();
        int[] a = new int[n];
        Point[] p = new Point[n];
        int[][] m = new int[n][n];

        for(int i=1;i<n-1;i++)
            a[i] = in.nextInt();

        for(int i=0;i<n;i++){
                p[i] = new Point();
                p[i].x = in.nextInt();
                p[i].y = in.nextInt();
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                m[i][j] = (Math.abs(p[i].x-p[j].x) + Math.abs(p[i].y-p[j].y))*d - a[i];
            m[i][i] = 0;
        }

        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                for(int k=0;k<n;k++){
                    m[j][k] = Math.min(m[j][k], m[j][i]+m[i][k]);
                }

        out.print(m[0][n-1]);
        out.close();
    }

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

}