#include <bits/stdc++.h> 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<long long> A, long long M, long long L) { long long N = A.size(); vector<long long> 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<long long> 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<long long> ans(N, (M / L) * sum), ans2(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]; } if (N * (M - (L - (i * (L % N)) % N - 1) / N) - 1 - (i * (L % N)) % N >= 0) { ans2[(i * (L % N)) % N] += rui[i + (N * (M - (L - (i * (L % N)) % N - 1) / N) - 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]); max_ = max(max_, ans2[i]); } return max_; } } int main() { long long N, M, L; cin >> N >> M >> L; vector<long long> 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<long long> 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; }