1. '''
  2. # Sample code to perform I/O:
  3.  
  4. name = input() # Reading input from STDIN
  5. print('Hi, %s.' % name) # Writing output to STDOUT
  6.  
  7. # Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
  8. '''
  9.  
  10. # Write your code here
  11. from itertools import accumulate
  12. def execute():
  13. n = int(input())
  14. array = list(map(int, input().strip().split()))
  15. cumulative = [0] + list(accumulate(array))
  16. # print(cumulative)
  17. total = sum(array)
  18. result = []
  19. for l in range(n):
  20. for r in range(l, n):
  21. n_array = r - l + 1
  22. sum_array = cumulative[r+1] - cumulative[l]
  23. if not (sum_array / n_array <= (total - sum_array) / (n - n_array or 1)):
  24. result.append((l+1, r+1))
  25. print(len(result))
  26. print("\n".join("{} {}".format(l,r) for l, r in sorted(result)))
  27. if __name__ == "__main__":
  28. execute()
Language: Python 3.8