fork download
  1. L = []
  2. while True:
  3. x = int(input ())
  4. if x == 0: break
  5. L.append(x)
  6.  
  7. n = len(L)
  8. L.insert(0, L[-1])
  9. L.append(L[1])
  10.  
  11. g = d = 0
  12. for i in range (1, n+1):
  13. if L[i-1] < L[i] and L[i] > L[i+1]: g += 1
  14. if L[i-1] > L[i] and L[i] < L[i+1]: d += 1
  15.  
  16. print(g, d)
Success #stdin #stdout 0.08s 7920KB
stdin
4
3
7
2
0
stdout
2 2