# Function to find the maximum range
# whose sum is divisible by M.
def maxrange(n, a, m):
pre = [0] * (n + 5)
mpp = {}
value, l, r, lans, rans, ans = -1, -1, -1, 0, 0, 0
# Calculate the prefix sum
pre[0] = a[0]
for i in range(1, n):
pre[i] = a[i] + pre[i - 1]
# Replacing the values with modulo M
# and inserting the indices into the map
for i in range(n):
pre[i] = pre[i] % m
if pre[i] not in mpp:
mpp[pre[i]] = set()
mpp[pre[i]].add(i)
# Calculate the range [L, R]
for key in mpp:
if key == 0:
value = max(mpp[key]) + 1
l, r = 1, value
else:
value = max(mpp[key]) - min(mpp[key])
l, r = min(mpp[key]) + 2, max(mpp[key]) + 1
if value > ans and l <= r:
ans = value
lans = l
rans = r
return (lans, rans)
# Driver code
A = [3, 7, 5, 2, 5, 10]
N = len(A)
M = 3
value = maxrange(N, A, M)
if value[0] == -1:
print(-1)
else:
print(value[0], value[1])
# This code is contributed by shiv1o43g