'''
# Sample code to perform I/O:
name = input() # Reading input from STDIN
print('Hi, %s.' % name) # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
from itertools import accumulate
def execute():
n = int(input())
array = list(map(int, input().strip().split()))
cumulative = [0] + list(accumulate(array))
# print(cumulative)
total = sum(array)
result = []
for l in range(n):
for r in range(l, n):
n_array = r - l + 1
sum_array = cumulative[r+1] - cumulative[l]
if not (sum_array / n_array <= (total - sum_array) / (n - n_array or 1)):
result.append((l+1, r+1))
print(len(result))
print("\n".join("{} {}".format(l,r) for l, r in sorted(result)))
if __name__ == "__main__":
execute()
Language: Python 3.8