#include using namespace std; long long gcd(long long x, long long y) { if (x < y) swap(x, y); while (y > 0) { long long r = x % y; x = y; y = r; } return x; } long long lcm(long long x, long long y) { return x * y / gcd(x, y); } long long solve(vector A, long long M, long long L) { long long N = A.size(); vector rui(2 * N); rui[0] = A[0]; for (int i = 1; i < 2 * N; i++) { rui[i] = rui[i - 1] + A[(i * (L % N)) % N]; } if (L <= N) { long long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } vector ans(L, (M / L) * sum); M %= L; for (int i = 0; i < N; i++) { if ((i * L) % N < L && N * M - 1 - (i * L) % N >= 0) { ans[(i * L) % N] += rui[i + (N * M - 1 - (i * L) % N) / L] - rui[i] + A[(i * L) % N]; } } long long max_ = -1000000000000000000; for (int i = 0; i < L; i++) { max_ = max(max_, ans[i]); } return max_; } else { long long sum = 0; for (int i = 0; i < N; i++) { sum += A[i]; } vector ans(N, (M / L) * sum); M %= L; for (int i = 0; i < N; i++) { if (N * M - 1 - (i * (L % N)) % N >= 0) { ans[(i * (L % N)) % N] += rui[i + (N * M - 1 - (i * (L % N)) % N) / L] - rui[i] + A[(i * (L % N)) % N]; } } long long max_ = -1000000000000000000; for (int i = 0; i < N; i++) { max_ = max(max_, ans[i]); } return max_; } } int main() { long long N, M, L; cin >> N >> M >> L; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; long long max_ = -1000000000000000000; for (int i = 0; i < gcd(N, L); i++) { vector B; for (int j = 0; j < N / gcd(N, L); j++) { B.push_back(A[j * gcd(N, L) + i]); } max_ = max(max_, solve(B, M, L / gcd(N, L))); } cout << max_ << endl; }