import sys import math def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]); idx +=1 M = int(input[idx]); idx +=1 L = int(input[idx]); idx +=1 A = list(map(int, input[idx:idx+N])) g = math.gcd(N, L) L_prime = L // g N_prime = N // g # Compute modular inverse of N_prime modulo L_prime def modinv(a, m): g, x, y = extended_gcd(a, m) if g != 1: return None # inverse doesn't exist else: return x % m def extended_gcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = extended_gcd(b % a, a) return (g, x - (b // a) * y, y) inv_N = modinv(N_prime, L_prime) if inv_N is None: # This should not happen since N_prime and L_prime are coprime print(0) return # Precompute cnt array cnt = [0] * L for c in range(L): if c % g != 0: cnt[c] = 0 else: k = c // g m0 = (k * inv_N) % L_prime if m0 >= M: cnt[c] = 0 else: count = (M - 1 - m0) // L_prime + 1 cnt[c] = count # Compute S array S = [0] * L for k in range(N): pos = (k + 1) % L # since positions are 1-based if pos == 0: pos = L S[pos - 1] += A[k] # S is 0-based max_C = -float('inf') for i in range(1, L + 1): current = 0 for d in range(L): c = (i - (d + 1)) % L # because d is 0-based in S, but represents (d+1) mod L current += S[d] * cnt[c] if current > max_C: max_C = current print(max_C) if __name__ == '__main__': main()