n = int(input()) ciag = input().split() for i in range(n): ciag[i] = int(ciag[i]) wyn = 0 nr = 1 kier = None while nr < n: if ciag[nr] < ciag[nr-1]: kier = 1 break if ciag[nr] > ciag[nr-1]: kier = -1 break nr += 2 wyn += 1 if kier != None: nr += 1 while nr < n: if kier == 1: if ciag[nr] > ciag[nr-1]: kier = -1 nr += 1 else: wyn += 1 nr += 2 else: if ciag[nr] < ciag[nr-1]: kier = 1 nr += 1 else: nr += 2 wyn += 1 print(wyn)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | n = int(input()) ciag = input().split() for i in range(n): ciag[i] = int(ciag[i]) wyn = 0 nr = 1 kier = None while nr < n: if ciag[nr] < ciag[nr-1]: kier = 1 break if ciag[nr] > ciag[nr-1]: kier = -1 break nr += 2 wyn += 1 if kier != None: nr += 1 while nr < n: if kier == 1: if ciag[nr] > ciag[nr-1]: kier = -1 nr += 1 else: wyn += 1 nr += 2 else: if ciag[nr] < ciag[nr-1]: kier = 1 nr += 1 else: nr += 2 wyn += 1 print(wyn) |