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: Wrong Answer

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
if N == 1:
    print(0)
if N == 2:
    print(0)
if N >= 3:
    ans = 0
    now_a = [Alist[0]]
    for i in range(N):
        if Alist[i] != now_a[-1]:
            now_a.append(Alist[i])
    la = len(now_a)
    if now_a[0] > now_a[1]:
        flg = "down"
    else:
        flg = "up"
    skip = False
    for i in range(2, la):
        if skip:
            skip = False
            continue
        if now_a[i - 1] > now_a[i]:
            now = "down"
        else:
            now = "up"
        if now != flg:
            ans += 1
            skip = True
        flg = now
    # print(now_a)
    print(ans + 1 + int(skip))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

flag = 0
cnt = 1

for i in range(n-1):
    if a[i] < a[i+1] and flag == 0:
        flag = 1
    elif a[i] > a[i+1] and flag == 0:
        flag = 2
    elif flag == 1 and a[i] > a[i+1]:
        cnt += 1
        flag = 0
    elif flag == 1 and a[i] > a[i+1]:
        cnt += 1
        flag = 0

print(cnt)

Submission status: Wrong Answer

Solution code:

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

count = 1
state = 0
for i in range(1, N):
    diff = A[i] - A[i - 1]
    if state == 0:
        if diff > 0:
            state = 1
            continue
        if diff == 0:
            state = 0
            continue
        if diff < 0:
            state = -1
            continue
    if state == 1:
        if diff > 0:
            state = 1
            continue
        if diff == 0:
            state = 0
            continue
        if diff < 0:
            count += 1
            state = 0
            continue
    if state == -1:
        if diff > 0:
            count += 1
            state = 0
            continue
        if diff == 0:
            state = 0
            continue
        if diff < 0:
            state = -1
            continue

print(count)

Submission status: Wrong Answer

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

count = 1
while len(a) > 1:
    first_tilt = 0
    for i in range(1, len(a)):
        if a[i] - a[i - 1] > 0:
            first_tilt = 1
            break
        if a[i] - a[i - 1] < 0:
            first_tilt = -1
            break

    if first_tilt == 1:
        for i in range(1, len(a)):
            if a[i] - a[i-1] < 0:
                a = a[i:]
                count += 1
                break
            if len(a)-1 == i:  # 配列の最後
                a = a[i:]

    if first_tilt == -1:

        for i in range(1, len(a)):
            print(i, a[i])
            if a[i] - a[i-1] > 0:
                a = a[i:]
                count += 1
                break
            if len(a)-1 == i:  # 配列の最後
                a = a[i:]

print(count)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

ans = 0
last = a[0]
i = 1
while i < n:
    ans += 1
    last = a[i]
    if last == a[i]:
        while i < n and last == a[i]:
            last = a[i]
            i += 1
    if i < n and last < a[i]:
        while i < n and last <= a[i]:
            last = a[i]
            i += 1
    elif i < n and last > a[i]:
        while i < n and last >= a[i]:
            last = a[i]
            i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

ans = 0
last = a[0]
i = 1
while i < n:
    ans += 1
    if last == a[i]:
        while i < n and last == a[i]:
            last = a[i]
            i += 1
    if i < n and last < a[i]:
        while i < n and last <= a[i]:
            last = a[i]
            i += 1
        if i < n:
            last = a[i]
    elif i < n and last > a[i]:
        while i < n and last >= a[i]:
            last = a[i]
            i += 1
        if i < n:
            last = a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split( )))
cnt = 1
i=0
while i < n-2:
    if (a[i]-a[i+1])*(a[i+1]-a[i+2])<0:
        cnt += 1
        i+=1
    i+=1
        
        
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 
for i in range(1,N):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int,input().split()))
cnt = 1
flag = 0 #flag 0=,1=+,2=-
for i in range(1,N):
    if P[i-1]!=P[i] and flag == 0:
        flag = 1
    elif flag == 1 and ((P[i-1] > P[i]) != (P[i-2]>P[i-1])):
        cnt += 1
        flag = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
#長さが2以下の数列に関しては絶対答えは1になる
if n <= 2:
    print(1)
    exit()
#そうでない場合
count = 1
flag = 0
for i in range(1,n-1):
    if flag == 1:
        flag = 0
        continue
    else:
        if li[i-1] > li[i] < li[i+1] or li[i-1] < li[i] > li[i+1]:
            flag = 1
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
flag = 0
zouka = 0
gensyo = 0
for i in range(n-1):
    if flag == 0:
        if li[i] > li[i+1]:
            flag = 1
    else:
        if li[i] <= li[i+1]:
            flag = 0
            zouka += 1
flag = 0
for i in range(n-1):
    if flag == 0:
        if li[i] < li[i+1]:
            flag = 1
    else:
        if li[i] >= li[i+1]:
            flag = 0
            gensyo += 1
print(max(zouka+1,gensyo+1))

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(1,N):

    if A[j-1]>A[j] and flag==1:
        count+=1
        flag=0

    elif A[j-1]>=A[j] and (flag==0 or flag==-1):
        flag=-1

    elif A[j-1]<A[j] and flag==-1:
        count+=1
        flag=0
    elif A[j-1]<=A[j] and (flag==0 or flag==1):
        flag=1




print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):

    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>=A[j+1] and (flag==0 or flag==-1):
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<=A[j+1] and (flag==0 or flag==1):
        flag=1




print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]==A[j+1]:
        flag=0
    elif A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>A[j+1] and (flag==0 or flag==-1):
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<A[j+1] and (flag==0 or flag==1):
        flag=1




print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]==A[j+1]:
        flag=0
    elif A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>A[j+1]:
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<A[j+1]:
        flag=1




print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]==A[j+1]:
        flag=0
    elif A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>A[j+1] and flag==0:
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<A[j+1] and flag==0:
        flag=1




print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>A[j+1] and flag==0:
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<A[j+1] and flag==0:
        flag=1

    if A[j]==A[j+1]:
        flag=0


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    elif A[j]>A[j+1] and flag==0:
        flag=-1

    elif A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    elif A[j]<A[j+1] and flag==0:
        flag=1

    elif A[j]==A[j+1]:
        flag=0


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


flag=0
count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    if A[j]>A[j+1] and flag==0:
        flag=-1

    if A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    if A[j]<A[j+1] and flag==0:
        flag=1

    if A[j]==A[j+1]:
        flag=0


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


for i in range(0, N):
    if A[0]>A[i]:
        flag = -1
        break

    if A[0]<A[i]:
        flag=1
        break


count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    if A[j]>A[j+1] and flag==0:
        flag=-1

    if A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    if A[j]<A[j+1] and flag==0:
        flag=-1

    if A[j]==A[j+1]:
        flag=0


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


for i in range(0, N):
    if A[0]>A[i]:
        flag = -1
        break

    if A[0]<A[i]:
        flag=1
        break


count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    if A[j]>A[j+1] and flag==0:
        flag=-1

    if A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    if A[j]<A[j+1] and flag==0:
        flag=-1

    if A[i]==A[j+1]:
        flag=0    


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


for i in range(0, N):
    if A[0]>A[i]:
        flag = -1
        break

    if A[0]<A[i]:
        flag=1
        break


count=1
for j in range(0,N-1):
    if A[j]>A[j+1] and flag==1:
        count+=1
        flag=0

    if A[j]>A[j+1] and flag==0:
        flag=-1

    if A[j]<A[j+1] and flag==-1:
        count+=1
        flag=0
    if A[j]<A[j+1] and flag==0:
        flag=-1


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

A = [int(_) for _ in input().split()]


for i in range(0, N):
    if A[0]>A[i]:
        flag = -1
        break

    if A[0]<A[i]:
        flag=1
        break


count=1
for j in range(0,N-1):
    if A[i]>A[j+1] and flag==1:
        count+=1
        flag=-1

    if A[i]<A[j+1] and flag==-1:
        count+=1
        flag=1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    ans = 1
    t = -1
    for i in range(n - 1):
        if a[i] < a[i + 1]:
            if t == 1:
                continue
            elif t == -1:
                t = 1
            else:
                t = 1
                ans += 1
        elif a[i + 1] < a[i]:
            if t == 0:
                continue
            elif t == -1:
                t = 0
            else:
                t = 0
                ans += 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

#%%
ans = 1
up = False
down = False
for n in range(N-1):
    if A[n] < A[n+1]:
        up = True
    elif A[n] > A[n+1]:
        down = True
    if up == True and down == True:
        ans += 1
        up = False
        down = False

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt=0
bflag=False
sflag=False

for i in range(1,N):
  if A[i]>A[i-1]:
    if sflag==True:
      cnt+=1
      bflag=False
      sflag=False
    else:
      bflag=True
      sflag=False
  elif A[i]<A[i-1]:
    if bflag==True:
      cnt+=1
      bflag=False
      sflag=False
    else:  
      bflag=False
      sflag=True    
  else:
    bflag=False
    sflag=False
    
print(cnt+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=0
ans=0
if n<=2:
    print(1)
    exit()
while i<n-1:
    if a[i]<a[i+1]:
        i+=1
        while i<n-1:
            if a[i]<=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    elif a[i]>a[i+1]:
        i+=1
        while i<n-1:
            if a[i]>=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    else:
        i+=1
        if i==n-1:
            ans+=1
if not (a[n-3]<=a[n-2]<=a[n-1] or a[n-3]>=a[n-2]>=a[n-1]):
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=0
ans=0
if n<=2:
    print(1)
    exit()
while i<n-1:
    if a[i]<a[i+1]:
        i+=1
        while i<n-1:
            if a[i]<=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    elif a[i]>a[i+1]:
        i+=1
        while i<n-1:
            if a[i]>=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    else:
        i+=1
if not (a[n-3]<=a[n-2]<=a[n-1] or a[n-3]>=a[n-2]>=a[n-1]):
    ans+=1
if ans==0:
    ans=1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
i=0
ans=0
if n<=2:
    print(1)
    exit()
while i<n-1:
    if a[i]<a[i+1]:
        i+=1
        while i<n-1:
            if a[i]<=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    elif a[i]>a[i+1]:
        i+=1
        while i<n-1:
            if a[i]>=a[i+1]:
                i+=1
            else:
                break
        #print(i)
        i+=1
        ans+=1
    else:
        i+=1
if not (a[n-3]<=a[n-2]<=a[n-1] or a[n-3]>=a[n-2]>=a[n-1]):
    ans+=1
print(ans)

Submission status: Wrong Answer

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

B = []
for i in range(1, n):
    B.append(A[i] - A[i-1])

ans = 1
p = -1
for i in range(1, n-1):
    if i != p+1 and B[i] * B[i-1] < 0:
        ans += 1
        p = i

print(ans)

Submission status: Wrong Answer

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

B = []
for i in range(1, n):
    B.append(A[i] - A[i-1])

ans = 1
for i in range(1, n-1):
    if B[i] * B[i-1] < 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = 1
b = [0] * (n-1)
for i in range(n-1):
    b[i] = a[i+1] - a[i]
# print(b)
f = False
for i in range(len(b)-1):
    if f:
        f = False
        continue
    if (b[i]>0 and b[i+1]<0) or (b[i]<0 and b[i+1]>0):
        res += 1
        f = True
    
a = a[::-1]
r = 1
b = [0] * (n-1)
for i in range(n-1):
    b[i] = a[i+1] - a[i]
# print(b)
f = False
for i in range(len(b)-1):
    if f:
        f = False
        continue
    if (b[i]>0 and b[i+1]<0) or (b[i]<0 and b[i+1]>0):
        r += 1
        f = True
print(min(res,r))

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
res = 1
b = [0] * (n-1)
for i in range(n-1):
    b[i] = a[i+1] - a[i]
# print(b)
f = False
for i in range(len(b)-1):
    if f:
        f = False
        continue
    if (b[i]>0 and b[i+1]<0) or (b[i]<0 and b[i+1]>0):
        res += 1
        f = True
print(res)

Submission status: Wrong Answer

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

d=False#単調減少
u=False#単調増加

cnt=0

for i in range(0,n-1):
  l=a[i];r=a[i+1]
  if l<r:u=True
  elif l>r:d=True
  else:pass  
  print((u,d))
  if u and d:
    cnt+=1
    u=False;d=False
print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    if up == down:
        ret += 1
        up, down = False, False
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    if up and down:
        ret += 1
        up, false = False, False
print(ret)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
kazu = len(data)
kai = 0
toku = kazu - 1
i = 1
if toku <= i:
    kai += 1
elif data[i] <= data[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if data[i] <= data[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if data[i] <= data[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    else:
    	i += 1
    	tane = n
    	if i == kazu:
        	kai += 1
        	break
print(kai)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
kazu = len(data)
kai = 0
toku = kazu - 1
i = 1
if toku <= i:
    kai += 1
elif data[i] <= data[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if data[i] <= data[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if data[i] <= data[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    i += 1
    tane = n
    if i >= kazu:
        kai += 1
        break
print(kai)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
num = 0
kazu = 0
kai = 0
toku = kazu - 1
i = 1
flag = 1
if toku <= i:
    kai += 1
    flag = 0
elif a[i] <= a[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if a[i] <= a[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if a[i] <= a[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    i += 1
    tane = n
    if i >= kazu:
        kai += 1
        break
print(kai)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
num = 0
kazu = 0
kai = 0
toku = kazu - 1
i = 1
flag = 1
if toku <= i:
    kai += 1
    flag = 0
elif data[i] <= data[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if data[i] <= data[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if data[i] <= data[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    i += 1
    tane = n
    if i >= kazu:
        kai += 1
        break
print(kai)

Submission status: Wrong Answer

Solution code:
n = int(input())
data = list(map(int, input().split()))
num = 0
kazu = 0
kai = 0
toku = kazu - 1
i = 1
flag = 1
if toku <= i:
    kai += 1
    flag = 0
elif data[i] <= data[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if flag == 0:
        break
    if data[i] <= data[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if data[i] <= data[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    i += 1
    tane = n
    if i >= kazu:
        kai += 1
        break
print(kai)

Submission status: Wrong Answer

Solution code:
num = 0
kazu = 0
n = int(input())
data = list(map(int, input().split()))
kai = 0
toku = kazu - 1
i = 1
flag = 1
if toku <= i:
    kai += 1
    flag = 0
elif data[i] <= data[i - 1]:
    n = 0
else:
    n = 1
tane = n
i = 2
while i <= kazu - 1:
    if flag == 1:
        break
    if data[i] <= data[i - 1]:
        n = 0
    else:
        n = 1
    if tane != n:
        kai += 1
        i += 1
        if i == kazu:
            kai += 1
            break
        if data[i] <= data[i - 1]:
            n = 0
            tane = n
        else:
            n = 1
            tane = n
        continue
    i += 1
    tane = n
    if i >= kazu:
        kai += 1
        break
print(kai)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = list(map(int,input().split()))
count = 0
up = False
down =False
for i in range(n - 1):
  if line[i] < line[i + 1]:
    up = True
  elif line[i] > line[i + 1]:
    down = True
  if up == down == True:
    count += 1
    up =False
    down =False
  if i == n - 2 and up == True and down == False:
    count += 1
  if i == n - 2 and up == False and down == True:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = list(map(int,input().split()))
count = 0
up = False
down =False
for i in range(n - 1):
  if line[i] < line[i + 1]:
    up = True
  elif line[i] > line[i + 1]:
    down = True
  if up == down == True:
    count += 1
    up =False
    down =False
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
flag = 0 
c = 0 
def check(i):
        for j in range(i, N - 1): 
                if A[j] - A[j + 1] < 0:
                        return 1 
                elif A[j] - A[j + 1] > 0:
                        return -1
flag = check(0)
for i in range(N - 1): 
        if flag == 0:
                break
        elif flag == 1:
                if A[i] - A[i + 1] > 0:
                        c += 1
                        flag = check(i + 1)
        elif flag == -1: 
                if A[i] - A[i + 1] < 0:
                        c += 1
                        flag = check(i + 1)

if c:
        print(c + 1)
else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
ret = 1
up, down = False, False
for i in range(N - 1):
    if A[i] < A[i + 1]:
        up = True
    elif A[i] > A[i + 1]:
        down = True
    print(i, A[i], A[i + 1], up, down)
    if up and down:
        ret += 1
        up, false = False, False
print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
flag = None
for i in range(N-1):
  if flag is None:
    flag = 1 if A[i]<A[i+1] else -1 if A[i]>A[i+1] else 0
  else:
    if A[i]<A[i+1] and flag == -1:
      ans += 1
      flag = None
    elif A[i]>A[i+1] and flag == 1:
      ans += 1
      flag = None
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())      
a+=[0]
b,c,=a[0]>a[1],0
for i in range(n-1):
    if a[i]==a[i+1]:
        continue
    elif (a[i]>a[i+1])!=b:
        b=a[i+1]>a[i+2]
        c+=1
print(c+1)

Submission status: Wrong Answer

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

res = 0
for i in range(N-1):
  if L[i] > L[i+1]:
    res += 1
    
print(res)

Submission status: Wrong Answer

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

res = 0
for i in range(N-1):
  if L[i] < L[i+1]:
    res += 1
    
print(res)

Submission status: Wrong Answer

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

ret = 1
i = 2
while i < N :
  if (A[i] - A[i-1]) * (A[i-1] - A[i-2]) < 0 :
    ret += 1
    i += 1
  i += 1

print(ret)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import numpy as np
count=1
dif_before=0
for i in range(n-1):
  dif=a[i+1]-a[i]
  #print(dif)
  #print(dif_before)
  if dif_before==0 or dif==0:
    dif_before=dif
  elif np.sign(dif)!=np.sign(dif_before):
    #print(dif)
    count+=1
    dif_before=0

print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
import numpy as np
count=1
dif_before=0
for i in range(n-1):
  dif=a[i+1]-a[i]
  #print(dif)
  #print(dif_before)
  if dif_before==0:
    dif_before=dif
  elif np.sign(dif)!=np.sign(dif_before):
    #print(dif)
    count+=1
    dif_before=0

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        i += 1
        if i == n:
            break
    if a[i] != a[i-1]:
        pre = a[i] - a[i-1]
    i += 1
print(ans + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
if n <= 2:
    print(1)
    exit()
pre = a[1] - a[0]
i = 2
while i < n:
    if pre * (a[i] - a[i-1]) < 0:
        ans += 1
        i += 1
        if i == n:
            break
    pre = a[i] - a[i-1]
    i += 1
print(ans + 1)

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()

# 0減少　1そのまま　2増加
flg = [-1] * n

if a[0] < a[1]:
    flg[1] = 2
elif a[0] == a[1]:
    flg[1] = 1
elif a[0] > a[1]:
    flg[1] = 0

cnt = 0

for i in range(2,n):
    if a[i-1] < a[i]:
        if flg[i-1] == 0:
            flg[i] = 100
            cnt += 1
        elif flg[i-1] == 1 or flg[i-1] == 2 or flg[i-1] == 100:
            flg[i] = 2
    elif a[i-1] == a[i]:
        flg[i] = 1
    elif a[i-1] > a[i]:
        if flg[i-1] == 0 or flg[i-1] == 1 or flg[i-1] == 100:
            flg[i] = 0
        elif flg[i-1] == 2:
            flg[i] = 100
            cnt += 1

# print(flg)
print(cnt+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = list(map(int,input().split()))
cnt = 0
cnt1 = 0
ans = 0
aa = a_list[0]
##貪欲法
##一つの値を固定してそれをどんどん更新していく
##cnt,cnt1に状態を保管する変数として保存する
for i in range(n):
    if aa>a_list[i] and cnt1==0:
        cnt = 1
        aa = a_list[i]
    elif aa<a_list[i] and cnt ==0:
        cnt =1
        aa = a_list[i]
    elif aa>a_list[i] and cnt1 != 0:
        aa = a_list[i] 
        cnt1 = 0
        ans += 1
    elif aa<a_list[i] and cnt != 0:
        aa = a_list[i]
        cnt = 0
        ans +=1
    else:
        continue
print(ans)

Submission status: Wrong Answer

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

plus_start = "+"
ans_plus_start = 1
minus_start = "-"
ans_minus_start = 1
before = A[0]
before_ = "="
count = 1
for idx, a in enumerate(A[1:]):
    if before == a:
        now = "="
    if before < a:
        now = "+"
    if before > a:
        now = "-"

    if (before_ == "+" and now == "-") or (before_ == "-" and now == "+"):
        count += 1
        before_ = "="
    else:
        before_ = now
    before = a
print(count)

Submission status: Wrong Answer

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

beforeitem = 0
count = 0

for item in A:
    if(beforeitem < item):
      count = count + 1
    beforeitem = item

print(count)

Submission status: Wrong Answer

Solution code:
N = input()
As = [int(x) for x in input().split()]

new_As = []
for i in range(1, len(As)):
    if As[i-1] != As[i]:
        new_As.append(As[i-1])
As = new_As

idx = 0
mode_change_count = 1
while True:            
    if idx >= (len(As)-2):
        break
    if (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) > 0:
        idx += 1
    elif (As[idx+1] - As[idx])*(As[idx+2] - As[idx+1]) < 0:
        idx += 2
        mode_change_count += 1

        
print(mode_change_count)