#include <bits/stdc++.h>
using namespace std;
int n;
long long x, y, p;
int a[1000006];
struct matrix {
  long long d[3][3];
};
matrix multiply(matrix A, matrix B) {
  matrix C;
  memset(C.d, 0, sizeof(C.d));
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 3; k++)
        C.d[i][j] = (C.d[i][j] + A.d[i][k] * B.d[k][j]) % p;
  return C;
}
matrix power(matrix A, long long deg) {
  if (deg == 1) return A;
  matrix B = power(A, deg / 2);
  B = multiply(B, B);
  if (deg & 1) B = multiply(A, B);
  return B;
}
long long getSum(long long sum, long long mini, long long maxi,
                 long long step) {
  if (!step) return sum;
  matrix Q;
  Q.d[0][0] = Q.d[0][1] = Q.d[0][2] = 0;
  Q.d[1][0] = 1;
  Q.d[1][1] = 3;
  Q.d[1][2] = 0;
  Q.d[2][0] = 0;
  Q.d[2][1] = -(mini + maxi) % p;
  if (Q.d[2][1] < 0) Q.d[2][1] += p;
  Q.d[2][2] = 1;
  Q = power(Q, step);
  long long base = (3LL * sum - mini - maxi) % p;
  if (base < 0) base += p;
  long long prod =
      (1LL * sum * Q.d[0][0] + 1LL * base * Q.d[1][0] + Q.d[2][0]) % p;
  return prod;
}
long long getMaxi(long long mini, long long maxi, long long step) {
  if (!step) return maxi;
  matrix Q;
  memset(Q.d, 0, sizeof(Q.d));
  Q.d[0][1] = Q.d[1][0] = Q.d[1][1] = 1;
  Q = power(Q, step);
  long long Fa = Q.d[1][0];
  long long Fb = Q.d[1][1] % p;
  return (Fa * mini + Fb * maxi) % p;
}
int main() {
  cin >> n >> x >> y >> p;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  if (n == 1) {
    printf("%d\n", a[0] % p);
    return 0;
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) sum = (sum + a[i]) % p;
  long long mini = a[0], maxi = a[n - 1];
  sum = getSum(sum, mini, maxi, x);
  maxi = getMaxi(a[n - 2], a[n - 1], x);
  sum = getSum(sum, mini, maxi, y);
  cout << sum << endl;
}
