1. """
  2. #If FastIO not needed, use this and don't forget to strip
  3. #import sys, math
  4. #input = sys.stdin.readline
  5. """
  6. import os
  7. import sys
  8. from io import BytesIO, IOBase
  9. import heapq as h
  10. from bisect import bisect_left, bisect_right
  11. import time
  12. from types import GeneratorType
  13. BUFSIZE = 8192
  14. class FastIO(IOBase):
  15. newlines = 0
  16. def __init__(self, file):
  17. import os
  18. self.os = os
  19. self._fd = file.fileno()
  20. self.buffer = BytesIO()
  21. self.writable = "x" in file.mode or "r" not in file.mode
  22. self.write = self.buffer.write if self.writable else None
  23. def read(self):
  24. while True:
  25. b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
  26. if not b:
  27. break
  28. ptr = self.buffer.tell()
  29. self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  30. self.newlines = 0
  31. return self.buffer.read()
  32. def readline(self):
  33. while self.newlines == 0:
  34. b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
  35. self.newlines = b.count(b"\n") + (not b)
  36. ptr = self.buffer.tell()
  37. self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  38. self.newlines -= 1
  39. return self.buffer.readline()
  40. def flush(self):
  41. if self.writable:
  42. self.os.write(self._fd, self.buffer.getvalue())
  43. self.buffer.truncate(0), self.buffer.seek(0)
  44. class IOWrapper(IOBase):
  45. def __init__(self, file):
  46. self.buffer = FastIO(file)
  47. self.flush = self.buffer.flush
  48. self.writable = self.buffer.writable
  49. self.write = lambda s: self.buffer.write(s.encode("ascii"))
  50. self.read = lambda: self.buffer.read().decode("ascii")
  51. self.readline = lambda: self.buffer.readline().decode("ascii")
  52. sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  53. input = lambda: sys.stdin.readline().rstrip("\r\n")
  54. from collections import defaultdict as dd, deque as dq, Counter as dc
  55. import math, string
  56. #start_time = time.time()
  57. def getInts():
  58. return [int(s) for s in input().split()]
  59. def getInt():
  60. return int(input())
  61. def getStrs():
  62. return [s for s in input().split()]
  63. def getStr():
  64. return input()
  65. def listStr():
  66. return list(input())
  67. def getMat(n):
  68. return [getInts() for _ in range(n)]
  69. def isInt(s):
  70. return '0' <= s[0] <= '9'
  71. MOD = 10**9 + 7
  72. """
  73. """
  74. def solve():
  75. def find(a):
  76. if a != p[a]:
  77. p[a] = find(p[a])
  78. return p[a]
  79. def union(a, b):
  80. global max_size
  81. a, b = find(a), find(b)
  82. if size[a] > size[b]:
  83. a, b = b, a
  84. p[a] = b
  85. size[b] += size[a]
  86. max_size = max(max_size,size[b])
  87. return
  88. N = getInt()
  89. p = [i for i in range(N)]
  90. size = [1]*N
  91. global max_size
  92. max_size = 1
  93. A = getInts()
  94. ans = 0
  95. inds = dd(set)
  96. bools = [False for i in range(N)]
  97. for i,a in enumerate(A):
  98. inds[a].add(i)
  99. flag = False
  100. for i in range(10**5,0,-1):
  101. for ind in inds[i]:
  102. flag = True
  103. bools[ind] = True
  104. if ind < N-1 and bools[ind+1]: union(ind,ind+1)
  105. if ind > 0 and bools[ind-1]: union(ind,ind-1)
  106. if flag: ans = max(ans,i*max_size)
  107. return ans
  108. #for _ in range(getInt()):
  109. print(solve())
  110. #solve()
  111. #print(time.time()-start_time)
Comments powered by Disqus