Skip to content

Instantly share code, notes, and snippets.

@SudhagarS
Created October 30, 2012 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudhagarS/3982358 to your computer and use it in GitHub Desktop.
Save SudhagarS/3982358 to your computer and use it in GitHub Desktop.
N, R = int(raw_input()), []
V = [1] * N
for x in xrange(N):
R.append(int(raw_input()))
while True:
finished = True
for i in xrange(N):
for k in [-1, 1]:
next = i + k
if next >= 0 and next < N and R[next] > R[i] and V[next] <= V[i]:
V[next] = V[i] + 1
finished = False
if finished:
break
print sum(V)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment