func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   struct node {     int val, id;     node(int val = 0, int id = 0) : val(val), id(id) {}     bool operator<(const node c) const { return val < c.val; }   };   int n, m, g, r;   int a[10005];   int d[10005][1005];   bool vis[10005][1005];   priority_queue<node> q;   int id(int x, int y) { return (x - 1) * g + y - 1; }   void dij() {     memset(d, 0x3f, sizeof(d));     q.push(node(0, id(1, g)));     d[1][g] = 0;     while (!q.empty()) {       int tid = q.top().id;       q.pop();       pair<int, int> t = make_pair(tid / g + 1, tid % g + 1);       if (vis[t.first][t.second]) continue;       if (t.first == m) {         if (t.second == g)           printf( %d n , d[t.first][t.second] - r);         else           printf( %d n , d[t.first][t.second]);         return;       }       vis[t.first][t.second] = 1;       if (t.first > 1) {         int tx = t.first - 1, ty = t.second - a[t.first] + a[t.first - 1];         if (ty > 0) {           if (chkmin(d[tx][ty],                      d[t.first][t.second] + a[t.first] - a[t.first - 1]))             q.push(node(-d[tx][ty], id(tx, ty)));         }         if (t.second == a[t.first] - a[t.first - 1]) {           ty = g;           if (chkmin(d[tx][ty],                      d[t.first][t.second] + a[t.first] - a[t.first - 1] + r))             q.push(node(-d[tx][ty], id(tx, ty)));         }       }       if (t.first < m) {         int tx = t.first + 1, ty = t.second - a[t.first + 1] + a[t.first];         if (ty > 0) {           if (chkmin(d[tx][ty],                      d[t.first][t.second] + a[t.first + 1] - a[t.first]))             q.push(node(-d[tx][ty], id(tx, ty)));         }         if (t.second == a[t.first + 1] - a[t.first]) {           ty = g;           if (chkmin(d[tx][ty],                      d[t.first][t.second] + a[t.first + 1] - a[t.first] + r))             q.push(node(-d[tx][ty], id(tx, ty)));         }       }     }     printf( -1 n );   }   int main() {     n = readint();     m = readint();     for (int i = 1; i <= m; i++) a[i] = readint();     sort(a + 1, a + m + 1);     g = readint();     r = readint();     dij();     return 0;   }   