Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- if not os.environ.get("ONLINE_JUDGE"):
- sys.stdin = open('./in.txt', 'r')
- sys.stdout = open('./out.txt', 'w')
- def totalPairs(n, values):
- # Participants code will be here
- res = 0
- # max_val = -sys.maxsize
- for i in range(n-2):
- sub_max = values[i+1]
- for j in range(i+2,n):
- if values[i] > sub_max and values[j] > sub_max:
- # print(values[i],values[j])
- res += 1
- sub_max = max(sub_max,values[j])
- return res
- if __name__ == "__main__":
- n = int(input())
- values = list(map(int, input().split()))
- answer = totalPairs(n, values)
- print(answer+(n-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement