Problem:


Score : 300 points

Problem Statement

You are given an array A of length N.
Your task is to divide it into several contiguous subarrays.
Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order.
At least how many subarrays do you need to divide A into?

Constraints

1 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Each A_i is an integer.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible number of subarrays after division of A.

Sample Input 1

6
1 2 3 2 2 1

Sample Output 1

2

One optimal solution is to divide the array into [1,2,3] and [2,2,1].

Sample Input 2

9
1 2 1 2 1 2 1 2 1

Sample Output 2

5

Sample Input 3

7
1 2 3 2 1 999999999 1000000000

Sample Output 3

3



Sample input:
6
1 2 3 2 2 1


Sample output:
2

Submission status: Runtime Error

Solution code:
N, L, T = list(map(int, input().split()))
data = [list(map(int, input().split())) for _ in range(N)]

d = {1: 1, 2: -1}
x0, w0 = data[0]
d0 = d[w0]
# 0番目の蟻が反時計回りの場合、周回してから衝突するため、`全長 + 現在位置`が初期値であると考える
if w0 == 2:
    x0 += L
# 0番目の蟻が衝突する回数
n_collisions = 0

positions = []
for i, (x, w) in enumerate(data):
    _x = (x + d[w] * T) % L
    positions.append(_x)
    if i > 0 and w0 != w:
        # 0番目の蟻と初めて衝突する時刻
        t = T - (d0 * (x - x0) / 2)
        n_collisions += int(t >= 0)
        n_collisions += max(int(t // (L / 2)), 0)

n_collisions  *= d0
results = positions[-n_collisions:] + positions[:-n_collisions]
print('\n'.join(map(str, results)))

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int,input().split()))

def chk(i,j):
    if i < j:
        return 0
    else:
        return 1
    
ans=1
a=A.pop(0)
x = chk(a,A[0])

while A!=[]:
    b = A.pop(0)
    if x == 0 and a>b:
        ans+=1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    elif x == 1 and a<b:
        ans += 1
        if A != []:
            x=chk(b,A[0])
        else:
            break
    a=b
    
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int,input().split()))
ans=1
if A[0] <A[1]:
    x=0
else:
    x=1
i=1
while i<N-1:
    if x == 0 and A[i]>A[i+1]:
        ans+=1
        x+=1
        x=x%2
    elif x==1 and A[i]<A[i+1]:
        ans+=1
        x+=1
        x=x%2
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A = list(map(int,input().split()))
ans=1
if A[0] <A[1]:
    x=0
else:
    x=1
i=1
while i<N-1:
    if x == 0 and A[i]>A[i+1]:
        ans+=1
        x+=1
        x=x%2
    elif x==1 and A[i]<A[i+1]:
        ans+=1
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))

data = []
for i in range(N-1):
  if a[i+1]-a[i] == 0:
    continue
  else:
    data.append(a[i+1]-a[i])

#print(data)
ans = 0
i = 0
while i<len(data)-1:
  if (data[i+1] * data[i]) < 0:
    ans += 1
    i += 1
    left = i
  i += 1
else:
  if left == len(data):
    pass
  else:
    ans += 1
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(c) for c in input().split(' ')]
prev = None
c = 1
inc = None

for i in range(l):
    current = a[i]
    if i == 0 :
        continue
    if inc == None:
        if a[i] > a[i-1] :
            inc = True
        elif             a[i] < a[i - 1]:
            inc = False
        else:
            continue 
    elif inc == True:
        if a[i-1] < a[i]:
            pass
        elif a[i -1] > a[i]:
            c += 1
            inc = None
    elif inc == False:
        if a[i-1] > a[i]:
            pass
        elif a[i - 1] < a[i]:
            c += 1
            inc = None
print(c)

Submission status: Runtime Error

Solution code:
n,c,k=map(int,input().split())
lista=[int(input())for i in range(n)]
listb=sorted(lista)
count=0
bustime=0
buspeople=0
for i in listb:
    if buspeople==0 or bustime<i:
        count+=1
        buspeople=c-1
        bustime=i+k
    else :
        buspeople-=1
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ud = []
for i in range(n-1):
    k="u" if a[i] < a[i+1] else "d" if a[i] > a[i+1] else False
    if not k:
        if len(ud)==0:
            continue
        else:
            k=ud[i-1]
    ud.append(k)

def ccount(l):  # v: finding val, l: list
    ans = 0
    i = 0
    n = len(l)
    while i < n:
        v = l[i]
        if l[i]!=v:
            i += 1
        else:
            ans += 1
            while i < n and l[i] == v:
                i += 1
    return ans
print(ccount(ud))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ans = 1
if A[1] - A[0] > 0:
  pre = 1
elif A[1] - A[0] == 0:
  pre = 0
else:
  pre = -1

for i in range(2,N):
  if A[i] - A[i-1] > 0:
    now = 1
  elif A[i] - A[i-1] == 0:
    now = 0
  else:
    now = -1
  if now*pre < 0:
    ans += 1
    pre = 0
  else:
    pre = now
  
print(ans)

Submission status: Runtime Error

Solution code:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i+((x-1+C)//C)*C-1,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

c = 0
i =2

if N ==1 or N ==2:
    print(1)
    exit()
while i<N+1:
    if (A[i-1]-A[i-2])*(A[i]-A[i-1])<0:
        c=c+1
        i = i+1
    i = i+1
print(c+1)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    ls = [int(x) for x in input().split()]
    right,left = 0,1
    cnt = 0
    flg = 0
    while 1:
        now = ls[left]
        nex = ls[right]   
        if now<nex:
            if flg ==-1:
                cnt +=1
                flg = 0
            else:
                flg = 1
            left +=1
            right +=1
        elif nex==now:
            left +=1
            right +=1         

        else:
            if flg ==1:
                cnt += 1
                flg = 0
            else:
                flg = -1
            left +=1
            right +=1
        if right==n-1:
            cnt +=1
            break
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 1
ans = 1
while(i<=n-2):
  if (a[i]-a[i-1]>=0) and (a[i+1]-a[i]>=0) or (a[i]-a[i-1]<=0) and (a[i+1]-a[i]<=0):
    cotinue
  else:
    ans += 1
    i += 1
  i += 1

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 1
ans = 1
while(i<=n-2):
  if (a[i]-a[i-1]>=0 and a[i+1]-a[i]>=0) or (a[i]-a[i-1]<=0 and a[i+1]-a[i]<=0):
    cotinue
  else:
    ans += 1
    i += 1
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 1
ans = 1
while (1<=n-2):
  if (a[i]-a[i-1]>=0 and a[i+1]-a[i]>=0) or a[i]-a[i-1]<=0 and a[i+1]-a[i]<=0):
    cotinue
  else:
    ans += 1
    i += 1
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
i = 1
ans = 1
whlie (1<=n-2):
  if (a[i]-a[i-1]>=0 and a[i+1]-a[i]>=0) or a[i]-a[i-1]<=0 and a[i+1]-a[i]<=0):
    cotinue
  else:
    ans += 1
    i += 1
  i += 1
print(ans)

Submission status: Runtime Error

Solution code:
n,l,T = map(int,input().split())
s = [0 for i in range(n)]
for i in range(n):
    s[i] = list(map(int, input().split()))

def f(w):
    if w == 1:
        return 1
    elif w == 2:
        return -1
    
t = 0
d = l
i_d = []

while t < T:
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] < d:
                    d = s[i+1][0] - s[i][0]
    
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] < d:
                    d = s[i+1][0] + l - s[i][0]
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] < d:
                    d = s[0][0] - s[i][0]
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] < d:
                    d = s[0][0] + l - s[i][0]
                    
    for i in range(n):
        if i < n-1 :
            if s[i][0] < s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] - s[i][0] == d:
                    i_d.append(i)
            elif s[i][0] > s[i+1][0] and s[i][1] == 1 and s[i+1][1] == 2:
                if s[i+1][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
        elif i == n-1:
            if s[i][0] < s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] - s[i][0] == d:
                    i_d.append(i)
                    
            elif s[i][0] > s[0][0] and s[i][1] == 1 and s[0][1] == 2:
                if s[0][0] + l - s[i][0] == d:
                    i_d.append(i)
                    
    for j in range(n):
        if t + d/2 <= T:
            s[j][0] += f(s[j][1]) * (d/2)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
            
        else:
            s[j][0] += f(s[j][1]) * (T-t)
            if s[j][0] >= l:
                s[j][0] -= l
            elif s[j][0] < 0:
                s[j][0] += l
    for j in i_d:
        if j < n-1:
            s[j][1], s[j+1][1] = s[j+1][1], s[j][1]
        else:
            s[j][1], s[0][1] = s[0][1], s[j][1]
    t = t + d/2
    i_d.clear()
    d = l
    
for i in range(n):
    print(s[i][0])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))


if a[1] > a[0]:
    inc = True
else:
    inc = False
count = 1
for i in range(2, len(a)):
    if a[i] > a[i - 1]:
        if inc:
            pass
        else:
            count += 1
            inc = False
    elif a[i] < a[i - 1]:
        if inc:
            count += 1
            inc = True
        else:
            pass

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

diff_list = [a[i] - a[i - 1]  for i in range(1, len(a))]
print(diff_list)

diff = a[1] - a[0]
count = 1
for i in range(2, len(a)):
    if a[i] - a[i - 1] != 1:
        count += 1
    elif a[i] - a[i - 1] == 1:
        if diff != 1:
            count += 1
        diff = 1
    elif a[i] - a[i - 1] == -1:
        if diff != -1:
            count += 1
        diff = -1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

dif = [0] * (N-1)
for i in range(1,N): dif[i-1] = A[i] - A[i-1]

ans = 1
t = dif[0]
for i in range(N-1):
    if dif[i]*t < 0:
        ans += 1
        if i < N-2:
            t = dif[i+1]
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

B = []
tmp = -1
for a in A:
    if a != tmp:
        B.append(a)
        tmp = a

def f(A):
    ans = 1
    n = len(A)
    if A[0] < A[1]:
        ff = 1
    else:
        ff = -1
    for i in range(1, n - 1):
        if ff == 0:
            if A[i] < A[i + 1]:
                ff = 1
            else:
                ff = -1
        elif ff == 1:
            if A[i] > A[i + 1]:
                ans += 1
                ff = 0
        else:
            if A[i] < A[i + 1]:
                ans += 1
                ff = 0
    return ans

print(f(B))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if A[0] == A[1]:
    pre = 0
elif A[0] > A[1]:
    pre = -1
else:
    pre = 1
prevalue = A[1]
ans = 0
for a in A[2:]:
    if a > prevalue:
        if pre == -1:
            ans += 1
            pre = 0
        else:
            pre = 1
    elif a < prevalue:
        if pre == 1:
            ans += 1
            pre = 0
        else:
            pre = -1
    prevalue = a
print(ans+1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=n
for i in range(n-1):
  if a[i]!=a[i+1]:
    s=i
    f=0 if a[s]<a[s+1] else f=1
    break
p=0
for i in range(s+1,n-1):
  if f==0:
    if a[i]>a[i+1]:
      p+=1
      f=1
  else:
    if a[i]<a[i+1]:
      p+=1
      f=0
print(p)

Submission status: Runtime Error

Solution code:
n = int(input())
num_list = [ int(v) for v in input().split() ]
mode = 1
ans = 0
for i in range(n-1):
  if mode == 1 and num_list[i+1] < num_list[i]:
  	mode = -1
    ans += 1
  elif mode == -1 and num_list[i+1] > num_list[i]:
  	mode = 1
    ans += 1
  
  
print(ans+1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 1
num = 0
for i in range(1,len(a)-1):
        if a[i+1]-a[i] == 0:
                num = a[i+1] - a[i]
        elif (a[i+1]-a[i])*d < 0:
                count += 1
                num = 0
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 1
num = 0
for i in range(1,len(a)-1):
        if a[i+1]-a[i] == 0:
                num = a[i+1] - a[i]
        elif (a[i+1]-a[i])*d < 0:
                count += 1
                scope = 0
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
pre = a[0]
increase = True
if a[1] < a[0]:
    increase = False

for i in range(1, n):
    if a[i] < pre:
        if increase:
            ans += 1
            increase = not increase
    elif a[i] > pre:
        if not increase:
            ans += 1
            increase = not increase
    pre = a[i]
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
A - Sorted Arrays
https://atcoder.jp/contests/agc013/tasks/agc013_a

"""
import sys
from typing import List


def solve(N, array):
    ans = 1
    prev = None
    direction = None

    for a in array:
        if prev == None:
            pass
        elif a > prev:
            if direction == 'd':
                ans += 1
                direction = None
            else:
                if a > prev:
                    direction = 'u'
        elif a < prev:
            if direction == 'u':
                ans += 1
                direction = None
            else:
                if a < prev:
                    direction = 'd'
        prev = a
    return ans


def main(args):
    N = int(input())
    array = [int(a) for a in input().split()]
    ans = solve(N, array)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Runtime Error

Solution code:
n=int(input())
ans=1
t=0
for i in input().split():
    a=int(i)
    if pre==0:
        pre=a
    else:
        if pre>a:
            if -t<0 and t**2==1:
                ans+=1
                t=-2
            else:
                t=-1
        elif pre<a:
            if t<0 and t**2==1:
                ans+=1
                t=2
            else:
                t=1
        else:
            continue
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
before=0
state=-1
ans=0
for a in A:
  
  if a==before:
    continue
  elif a-before>0:
    if state==-1:
      state=1
      ans+=1
    if state==0:
      state=-1
  else:
    if state==-1:
      state=0
      ans+=1
    if state==1:
      state=-1
  before=a
if (A[-1]-A[-2])*(A[-2]-A[-3])<0:
  ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0

tmp = A[0]
bf = 1 if tmp < A[1] else 2 if tmp > A[1] else 0
af = 0  # {1: '+', 2: '-'}
for i in range(1, N):
    if tmp < A[i]:
        af = 1
    elif tmp > A[i]:
        af = 2

    tmp = A[i]
    if af != bf:
        count += 1
        if i+1 < N:
            af = 1 if tmp < A[i+1] else 2 if tmp > A[i+1] else 0
        else:
            break
    bf = af

print(count if bf == 0 else count+1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 1

tmp = A[0]
bf = 1 if tmp < A[1] else 2 if tmp > A[1] else 0
af = 0  # {1: '+', 2: '-'}
for i in range(1, N):
    if tmp < A[i]:
        af = 1
    elif tmp > A[i]:
        af = 2

    tmp = A[i]
    if af != bf:
        count += 1
        if i+1 < N:
            af = 1 if tmp < A[i+1] else 2 if tmp > A[i+1] else 0
    bf = af

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
sub = 0
count = 1
A = [int(i) for i in input().split()]
pre_num = A[1]
pre_sub = A[1] - A[0]
for num in A[2:]:
    if not pre_num == num:
        if pre_sub * (num - pre_num) < 0:
            count += 1
            pre_sub = 0
        else:
          	pre_sub = num - pre_num
        pre_num = num
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
	A[i] = int(input())

for j in range(1, N):
	if A[j] in A[: j]:
		A[A[: j].index(A[j])] = -1
		A[j] = -1


print(len([k for k in A if k != -1]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
if a[1] > a[0]:
    temp = 1
elif a[1] < a[0]:
    temp = -1
else:
    temp = 0
ans = 1
for i in range(1, n-1):
    if a[i+1] > a[i]:
        if temp >= 0:
            temp = 1
        elif temp == -1:
            ans += 1
            temp = 0
    elif a[i+1] < a[i]:
        if temp <= 0:
            temp = -1
        elif temp == 1:
            ans += 1
            temp = 0
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

if A[0] < A[1]:
    flag = 1
elif A[0] > A[1]:
    flag = -1
else:
    flag = 0
    
cnt = 1
x = A[1]
for i in range(2, n):
    if flag == 1:
        if x <= A[i]:
            pass
        else:
            cnt += 1
            flag = 0
    if flag == -1:
        if x < A[i]:
            cnt += 1
            flag = 0
        else:
            pass
    else:
        if x < A[i]:
            flag = 1
        elif x > A[i]:
            flag = -1
        else:
            flag = 0
    x = A[i]
    
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

if A[0] <= A[1]:
    flag = 1
else:
    flag = -1
cnt = 1
x = A[1]
for i in range(2, n):
    if flag == 1:
        if x <= A[i]:
            pass
        else:
            cnt += 1
            flag = 0
    if flag == -1:
        if x < A[i]:
            cnt += 1
            flag = 0
        else:
            pass
    else:
        if x < A[i]:
            flag = 1
        elif x > A[i]:
            flag = -1
        else:
            flag = 0
    x = A[i]
    
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
divide = 0
if A[0] < A[1]:
    up = 1
elif A[0] > A[1]:
    up = -1
else:
    up = 0
for i in range(1,N-1):
    if A[i] == A[i+1]:
        continue
    elif A[i] < A[i+1]:
        if up < 0:
            divide += 1
            up = 0
        else:
            up = 1
            continue
    else:
        if up > 0:
            divide += 1
            up = 0
        else:
            up = -1
            continue
print(divide+1)

Submission status: Runtime Error

Solution code:
n,l,t=list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(list(map(int,input().split())))
a=0
for i in range(1,n):
    if L[0][1]==1 and L[i][1]==2:
        a+=max(int((t-abs(L[0][0]-L[i][0])/2)/(l/2))+1,0)
    elif L[0][1]==2 and L[i][1]==1:
        a+=max(int((t-(l-abs(L[0][0]-L[i][0]))/2)/(l/2))+1,0)
if L[0][1]==1 :
    b=a%n
else:
    b=-a%n
Q=[]
for i in range(n):
    Q.append(((L[i][0]+t*(3-L[i][1]*2))%l))
Q.sort()
d=Q.index(((L[0][0]+t*(3-L[0][1]*2))%l))
W=[]
for i in range (n):
    if i+(-d+b)>=0 and i+(-d+b)<n:
        W.append(i+(-d+b))
    elif i+(-d+b)>=n:
        W.append(i+(-d+b)-n)
    else:
        W.append(i+(-d+b)+n)
for i in range(n):
    print(Q[W.index(i)])

Submission status: Runtime Error

Solution code:
n,*a=map(int,open(0).read().split())

ans=0
x=a[0]
if a[1]>a[0]:
  mode=0
else:
  mode=1
for s in a:
#  print(x,s,mode,ans)
  if x<s and mode==0:
    ans+=1
    mode=1
  elif x>s and mode==1:
    ans+=1
    mode=0
  x=s
print(ans//2+1)

Submission status: Runtime Error

Solution code:
n = int(input())
aa = list(map(int, input().split()))

if n==1:
    print(1)
else:
    mode = None
    ans = 1
    for i in range(n-1):
        if aa[i] != aa[i+1]:
            if mode == None:
                mode = aa[i]<aa[i+1]
            if (aa[i] < aa[i+1]) != mode:
                ans+=1
                mode = aa[+1]<aa[i+2]
        # print(aa[i], aa[i+1], aa[i]<aa[i+1],  mode, ans)
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
u=a[0]<=a[1]
d=a[0]>=a[1]
res=0
for i in range(2,n):
    u=u and a[i-1]<=a[i]
    d=d and a[i-1]>=a[i]
    #print(i,u,d)
    if not any([u,d]):
        res+=1
        u=True
        d=True
print(res+1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
id = 1
while a != []:
    if a[0] == a[1]:
        while a[id-1] == a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
        del(a[:id-1])
        if id == n:
          cnt = 1
          break
        id = 1
    if a[0] > a[1]:
        while  a[id-1] >= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    cnt += 1
    del(a[:id])
    id = 1

    if len(a)==1:
        cnt += 1
        break

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
id = 1
while a != []:
    if a[0] == a[1]:
        while a[id-1] == a[id] and id < len(a)-1:
            id += 1
        del(a[:id-1])
        id = 1
    if a[0] > a[1]:
        while  a[id-1] >= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id <= len(a)-1:
            id += 1
            if id == len(a):break
    cnt += 1
    del(a[:id])
    id = 1

    if len(a)==1:
        cnt += 1
        break

print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
while a != []:
    id = 1
    if a[0] == a[1]:
        while a[id-1] == a[id]:
            id += 1
        del(a[:id-1])
        id = 1

    if a[0] > a[1]:
        while a[id-1] >= a[id] and id < len(a)-1:
            id += 1
    elif a[0] < a[1]:
        while a[id-1] <= a[id] and id < len(a)-1:
            id += 1
    cnt += 1
    if id ==len(a)-1:break 
    del(a[:id])

    if len(a)==1:
        cnt += 1
        break
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
cnt = 0
L = list(map(int,input()..split()))
for i in range(N-2):
  if (L[i] > L[i+1] < L[i+2]) or (L[i] < L[i+1] > L[i+2]):
    cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest013-A
#  TODO https://atcoder.jp/contests/agc013/tasks/agc013_a


def solveProblem(allNumber,aList):
	flag = "Flat"
	count = 1
	for i in range(allNumber - 1):
		b = aList[i + 1] - aList[i]
		if flag == "Plus":
			if b < 0:
				flag = "Flat"
				count = count+1
		elif flag == "Minus":
			if b > 0:
				flag = "Flag"
				count = count+1
		else:
			if b > 0:
				flag = "Plus"
			elif b < 0:
				flag = "Minus"
		answer = count
	return answer

if __name__ == '__main__':
	N = int(input().strip())
	As = list(map(int,input().split()))
	solution = solveProblem(N,As)
	print("{}".format(solution))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int,input().split()))
ans = 1

if a[0] < a[1]:
	flag = 1
if a[0] > a[1]:
	flag = -1
if a[0] == a[1]:
	flag = 0


for i in range(2,N):
	if flag == 1 and a[i-1] > a[i]:
		ans += 1
		flag = 0
	elif flag == -1 and a[i-1] < a[i]:
		ans += 1
		flag = 0
	elif flag == 0 and a[i-1] < a[i]:
		flag = 1
	elif flag == 0 and a[i-1] > a[i]:
		flag = -1
	
print(ans)

Submission status: Runtime Error

Solution code:
iipt=lambda:int(input())
miipt=lambda: list(map(int, input().split()))

n,l,t=miipt()
a=[miipt() for i in range(n)]
d=0
for x,w in a:
    d+=(x+(t if w==1 else -t))//l
d=d%n

e=[(x+(t if w==1 else -t))%l for x, w in a]

e.sort()


for i in range(n):
    print(e[(d+i)%n])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))
t=1
p=a[0]
m=0
for i in a:
  if(p==i):
    continue
  if(m>0):
    if(i<p):
      t+=1
      m=0
  elif(m<0):
    if(i>p):
      t+=1
      m=0
  else:
    if(i>p):
      m=1
    elif(i<p):
      m=-1
  p=i
print(t)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))
t=1
p=a[0]
m=0
for i in a:
  if(p==i):
    continue
  if(m>0):
    if(i<p):
      t+=1
      m=0
  elif(m<0):
    if(i>p):
      t+=1
      m=0
  else:
    if(i>p):
      m=1
    eif(i<p):
      m=-1
  p=i
print(t)

Submission status: Runtime Error

Solution code:
import sys

lines = sys.stdin.readlines()

for n, line in enumerate(lines):
  if n == 0:
    continue
  inputs = [int(_) for _ in line.strip().split(' ')]

log = []
res = [[]]
for n, input_ in inputs:
  mono_inc = True
  mono_dec = True
  if n > 0:
    if input_ > prev
      mono_dec = False
    elif input_ < prev
      mono_inc = False
    if (not mono_inc and not mono_dec) or ((mono_inc or mono_dec) and n == len(inputs)):
      res[-1].append(log)
  else:
    pass
  prev = input_
  log.append(input_)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N == 1:
    print(1)
    exit()
d = [A[i+1] - A[i] for i in range(N-1)]
def judge(list_hoge = d,count = 1):
    if len(list_hoge) == 1:
        print(count)
        return
    for i in range(1,len(list_hoge)):
        if list_hoge[i] * list_hoge[0] < 0:
            if i == len(list_hoge) - 1:
                print(count + 1)
                return
            else:
                return judge(list_hoge[i+1:],count + 1)
    print(count)
    return
judge()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N <= 2:
    print(1)
    exit()
d = [A[i+1] - A[i] for i in range(N-1)]
def judge(list_hoge = d,count = 1):
    for i in range(1,len(list_hoge)):
        if list_hoge[i] * list_hoge[0] < 0:
            return judge(list_hoge[i+1:],count + 1)
    print(count)
judge()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if N == 1:
    print(1)
    exit()
d = [A[i+1] - A[i] for i in range(N-1)]
def judge(list_hoge = d,count = 1):
    for i in range(1,len(list_hoge)):
        if list_hoge[i] * list_hoge[0] < 0:
            return judge(list_hoge[i+1:],count + 1)
    print(count)
judge()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = [A[i+1] - A[i] for i in range(N-1)]
def judge(list_hoge = d,count = 1):
    for i in range(1,len(list_hoge)):
        if list_hoge[i] * list_hoge[0] < 0:
            return judge(list_hoge[i+1:],count + 1)
    print(count)
judge()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

i = 0
c = 1
if a[0] <= a[1]:
    s = 0
elif a[0] >= a[1]:
    s = 1
else:
    s = 2

while i < n-1:
    if s ==2:
        if a[i] <= a[i+1]:
            s = 0
            i += 1
        elif a[i] >= a[i+1]:
            s = 1
            i += 1
        else:
            s = 2
            i += 1
    elif a[i] == a[i+1]:
        i += 1
    elif s == 0 and a[i] < a[i+1]:
        i += 1
    elif s == 1 and a[i] < a[i+1]:
        i += 1
        s = 0
        c +=1
    elif s == 1 and a[i] > a[i+1]:
        i += 1
    else:
        i += 1
        s = 1
        c += 1
print(1+c//2)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

i = 0
c = 1
if a[0] <= a[1]:
    s = 0
elif a[0] >= a[1]:
    s = 1
else:
    s = 2

while i < n-1:
    if s ==2:
        if a[i] <= a[i+1]:
            s = 0
            i += 1
        elif a[i] >= a[i+1]:
            s = 1
            i += 1
        else:
            s = 2
            i += 1
    elif a[i] == a[i+1]:
        i += 1
    elif s == 0 and a[i] < a[i+1]:
        i += 1
    elif s == 1 and a[i] < a[i+1]:
        i += 1
        s = 0
        c +=1
    elif s == 1 and a[i] > a[i+1]:
        i += 1
    else:
        i += 1
        s = 1
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

i = 0
c = 1
if a[0] <= a[1]:
    s = 0
elif a[0] >= a[1]:
    s = 1
else:
    s = 2

while i < n-1:
    if a[i] == a[i+1]:
        i += 1
    elif s == 0 or s ==2 and a[i] < a[i+1]:
        i += 1
    elif s == 1 or s ==2 and a[i] < a[i+1]:
        i += 1
        s = 0
        c +=1
    elif s == 1 or s ==2 and a[i] > a[i+1]:
        i += 1
    else:
        i += 1
        s = 1
        c += 1
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

ans = 1
pm = 1

i = 0
tmp = []
while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
            if pm == 0 and A[i] != A[i-1]:
                if A[i-1] < A[i]:
                    pm = 1
                else:
                    pm = -1
        else:
            i += 1
            if N <= i:
                ans += 1
                break

            if A[i-1] == A[i]:
                pm = 0
            elif A[i-1] < A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))

ans = 1
pm = 1

i = 0

while i < N:

    if i == 0:
        if A[i] <= A[i+1]:
            pm = 1
        else:
            pm = -1

        i += 1
    else:
        if pm*(A[i] - A[i-1]) >= 0:
            i += 1
        else:
            i += 1
            if N <= i:
                ans += 1
                break
            if A[i-1] <= A[i]:
                pm = 1
            else:
                pm = -1

            ans += 1


print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

i = 0
c = 1
if a[0] <= a[1]:
    s = 0
else:
    s = 1
while i < n-1:
    if a[i] == a[i+1]:
        i += 1
    elif s == 0 and a[i] < a[i+1]:
        i += 1
    elif s == 1 and a[i] < a[i+1]:
        i += 1
        s = 0
        c +=1
    elif s == 1 and a[i] > a[i+1]:
        i += 1
    else:
        i += 1
        s = 1
        c += 1
print(c)