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:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 1
    first_flag = True
    i = 1
    while True:
        if i > len(A_arr):
            cnt += 1
            break
        elif i == len(A_arr):
            break
        else:
            if first_flag:
                if A_arr[i]>A_arr[i-1]:
                    increase = True
                    first_flag = False
                elif A_arr[i]<A_arr[i-1]:
                    increase = False
                    first_flag = False
            else:
                if (increase and A_arr[i]<A_arr[i-1]) or (not increase and A_arr[i]>A_arr[i-1]):
                    increase = not increase
                    cnt += 1
                    i += 1
        i += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())

a = list(map(int,input().split()))

index = 1

ans = 0

while index < n:
    ans += 1
    if a[index-1] < a[index]:
        flag = True
    elif a[index-1] > a[index]:
        flag = False
    else:
        for i in range(index,n):
            if a[index] != a[i]:
                if a[index] < a[i]:
                    flag = True
                else:
                    flag = False
    flag2 = True
    for i in range(index,n):
        if flag and a[i] < a[i-1]:
            index = i+1
            flag2 = False
            break
        elif a[i] > a[i-1] and flag == False:
            index = i+1
            flag2 = False
            break
    if flag2:
        break
if index == n:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = True
f = True
horyuu = True
while i < N-1:
    if A[i] == A[i+1]:
        b.append(A[i])
        i += 1
        horyuu = True
        continue

    if horyuu:
        horyuu = False
        if A[i] < A[i+1]: zouka = True
        else: zouka = False


        
    if A[i] < A[i+1]:
        f = True
    else:
        f = False

    if f: #増加
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: #減少
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = True
f = True
while i < N-1:
    if A[i] == A[i+1]:
        if zouka == True:
            f = True
        else:
            f = False
    elif A[i] < A[i+1]:
        f = True
    else:
        f = False

    if f: #増加
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: #減少
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = True
f = True
while i < N-1:
    if len(b) == 1:
        if A[i] < A[i+1]: zouka = True
        else: zouka = False
    if A[i] == A[i+1]:
        if zouka == True:
            f = True
        else:
            f = False
    elif A[i] < A[i+1]:
        f = True
    else:
        f = False

    if f: #増加
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: #減少
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
if N == 1:
    print(1)
    exit()
i = 0
B = []
b = [A[0]]
zouka = True
f = True
while i < N-1:
    if len(b) == 1:
        if A[i] < A[i+1]: zouka = True
        else: zouka = False
    if zouka == True and A[i] <= A[i+1]:
        f = True
    elif zouka == False and A[i] >= A[i+1]:
        f = False
    elif A[i] < A[i+1]:
        f = True
    else:
        f = False

    if f: #増加
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: #減少
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

if n == 1:
    print(1)
else:
    ans = 1
    state = lambda n1, n2: 0 if n1 == n2 else (1 if n2 > n1 else -1)
    diff = [state(a1, a2) for a1, a2 in zip(a[:-1], a[1:])]

    p = 1
    while p < len(diff):
        if abs(diff[p] - diff[p-1]) == 2:
            ans += 1
            p += 1

        p += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
n = int(input())
#  = map(int, input().split())
a  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()


ans = 1
state = lambda n1, n2: 0 if n1 == n2 else (1 if n2 > n1 else -1)
diff = [state(a1, a2) for a1, a2 in zip(a[:-1], a[1:])]

p = 1
while p < len(diff):
    if abs(diff[p] - diff[p-1]) == 2:
        ans += 1
        p += 1

    p += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

i = 0
B = []
b = [A[0]]
zouka = True
while i < N-1:
    if len(b) == 1:
        if A[i] < A[i+1]: zouka = True
        else: zouka = False
    if A[i] < A[i+1]: #増加
        if zouka == True:
            b.append(A[i+1])
        else:
            B.append(b)
            b = [A[i+1]]
            
    else: #減少
        if zouka == True:
            B.append(b)
            b = [A[i+1]]
        else:
            b.append(A[i+1])
    i += 1
B.append(b)
print(len(B))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

S = ''
for i in range(N-1):
    if A[i] < A[i+1]:
        S += 'p'
    else:
        S += 'm'

i = 0
ans = 0
while i < len(S)-1:
    if S[i] == S[i+1]:
        i += 1
    elif S[i:i+2] == 'pm':
        ans += 1
        i += 2
    elif S[i:i+2] == 'mp':
        ans += 1
        i += 2
print(ans+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = 1
b = [0] + a
c = [(i-j)//abs(i-j) for i, j in zip(a, b) if i != j]
mae=c[0]
d=iter(c)
for x in d:
  if x != mae:
    cnt += 1
    try:
      mae = d.__next__()
    except StopIteration:
      break
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = 1
i = -1
flg = True
while True:
  i += 1
  if i >= n-1:
    break
  if a[i] < a[i+1]:
    flg = True
  elif a[i] > a[i+1]:
    flg = False
  else:
    continue
  for k in range(i, n-1):
    if (flg and a[k] > a[k+1]) or ((not flg) and a[k] < a[k+1]):
      cnt += 1
      i = k
      break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''

    N = int(input())
    A_list = [int(item) for item in input().split()]

    if N >=2:
        prev_num = A_list[0]
        new_list = []
        prev_direction = 0
        cnt = 1
        for item in A_list[1:]:
            # print(item - prev_num)
            if item != prev_num:
                if item - prev_num > 0:
                    if prev_direction == 1:
                        pass
                    else:
                        cnt += 1

                    prev_direction = 1
                    
                else:
                    if prev_direction == -1:
                        pass
                    else:
                        cnt += 1

                    prev_direction = -1
            prev_num = item
    else:
        cnt = 1

    print(cnt//2+1)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

i = 1
ans = 1
change = [False,False]

while i<n:
    if change == [True,True]:
        ans += 1
        change = [False,False]
        print(change)
    elif a[i]>a[i-1]:
        change[0] = True
        i += 1
        print(change)
    elif a[i]<a[i-1]:
        change[1] = True
        i += 1
        print(change)
    else:
        i += 1
        print(change)
if i==n and change==[True,True]:
    ans += 1
print(ans)

Submission status: Wrong Answer

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

before = A[0]
is_ascending = -1
ans = 0
for a in A:
    d = a - before
    if d == 0:
        pass
    elif d == 1:
        if is_ascending == -1:
            is_ascending = True
        elif is_ascending == False:
            ans += 1
            is_ascending = -1
    elif d == -1:
        if is_ascending == -1:
            is_ascending = False
        elif is_ascending == True:
            ans += 1
            is_ascending = -1
    elif abs(d) >= 2:
        ans += 1
        is_ascending = -1
    
    before = a

print(ans+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
src = list(map(int,input().split()))
asc = None
ans=1
for i in range(N-1):
    #隣接項間の差
    d = src[i+1]-src[i]
    #最初または区切った直後のとき
    if asc==None:
        asc = d > 0
        continue
    #隣接項が等しいとき
    if d==0:
        continue
    #隣接項が等しくないとき:
        #ascと隣接項間の差が一致していなければ区切る
    if (asc and d<0) or (not asc and d>0):
        asc = None
        ans+=1
print(ans)

Submission status: Wrong Answer

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

i = 2
ans = 0

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

Submission status: Wrong Answer

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

i = 2
ans = 1

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

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
state = 1
count = 1
tmp = a[0]
for i in a:
  if i == tmp:
    tmp = i
  elif i > tmp:
    state = 1
    break
  else:
    state = 0
    break
tmp = a[0]
for i in a:
  if i == tmp:
    pass
  elif i > tmp:
    if state == 1:
      pass
    else:
      state = 0
      count += 1
  else:
    if state == 0:
      pass
    else:
      state = 1
      count += 1
  tmp = i
print(count)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 1
i = 2
while (i < N):
    sub1 = A[i-1]-A[i-2]
    sub2 = A[i]-A[i-1]
    if (sub1 >= 0 and sub2 >= 0) or (sub1 <= 0 and sub2 <= 0):
        i += 1
        pass
    else:
        ans +=1
        i += 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int( input())
    A = list( map( int, input().split()))
    if N == 1 or N == 2:
        print(1)
        return
    sing = 0
    now = A[0]
    ans = 1
    for a in A[1:]:
        if sing == 0:
            if now < a:
                sing = 1
            elif now > a:
                sing = -1
        elif sing > 0:
            if not ( now < a):
                ans += 1
                sing = 0
        else:
            if not ( now > a ):
                ans += 1
                sing = 0
        now = a
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
def solve(N,A):
    ans = 0
    lis = []
    lis.append(A[0])
    a = A[0]
    for i in range(1,N):
        if len(lis)==1 or prev==0:
            prev = A[i]-a
        elif (A[i]-a)*prev<0:
            ans += 1
            lis = []
        lis.append(A[i])
        a = A[i]
    return ans
print(solve(N,A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
def solve(N,A):
    liss = []
    lis = []
    lis.append(A[0])
    a = A[0]
    for i in range(1,N):
        if len(lis)==1 or prev==0:
            if A[i]>a:
                prev = 1
            elif A[i]<a:
                prev = -1
            else:
                prev = 0
        elif ((A[i]>a)-0.5)*prev<0:
            liss.append(lis)
            lis = []
        lis.append(A[i])
        a = A[i]
    liss.append(lis)
    ans = len(liss)
    return ans
print(solve(N,A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
from collections import deque
def solve(N,A):
    lis = []
    d = deque()
    d.append(A[0])
    a = A[0]
    for i in range(1,N):
        if len(d)==1 or prev==0:
            if A[i]>a:
                prev = 1
            elif A[i]<a:
                prev = -1
            else:
                prev = 0
        elif ((A[i]>a)-0.5)*prev<0:
            lis.append(d)
            d = deque()
        d.append(A[i])
        a = A[i]
    lis.append(d)
    ans = len(lis)
    return ans
print(solve(N,A))

Submission status: Wrong Answer

Solution code:
si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
lmsi = lambda: list(map(str, input().split()))
smii = lambda: sorted(map(int, input().split()))

# ----------

N = ii()
A = lmii()

if N <= 2:
    print(1)
    exit()

ans = 1
i = 2
while i < N:
    if A[i-2]-A[i-1] >= 0 and A[i-1]-A[i] >= 0:
        i += 1
        continue
    if A[i-2]-A[i-1] <= 0 and A[i-1]-A[i] <= 0:
        i += 1
        continue
    ans += 1
    i += 2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = []
for i in range(n-1):
    x.append(a[i+1]-a[i])
c = 1
i = 0
while i<len(x)-1:
    if x[i]*x[i+1]<0:
        c+=1
        i+=2
    else:i+=1

print(c)

Submission status: Wrong Answer

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

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)

print(len(d))

Submission status: Wrong Answer

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

order = 0
subs = []
tmp = []

prev = 0
d = []
t = [l[0]]
for x in range(len(l)-1):
  a,b = l[x],l[x+1]
  c = a-b
  print(a,b,c, prev)
  if c == 0:
    t.append(b)
  elif prev == 0:
    t.append(b)
    prev = c
  elif (c < 0  and prev < 0) or (c > 0 and prev > 0):
    t.append(b)
  else:
    prev = 0
    d.append(t)
    t = [b]
d.append(t)

Submission status: Wrong Answer

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

diff = 0
subs = []
tmp = [l[0]]
for i in range(len(l)-1):
  # print(diff)
  a,b = l[i], l[i+1]
  d = a-b
  if diff == 0 or d == 0 or (diff < 0 and d < 0) or (diff > 0 and d > 0):
    tmp.append(b)
    diff = d
    continue
  diff = 0
  subs.append(tmp)
  tmp = [b]
subs.append(tmp)

print(len(subs))

Submission status: Wrong Answer

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

diff = 0
subs = []
tmp = [l[0]]
for i in range(len(l)-1):
  # print(diff)
  a,b = l[i], l[i+1]
  d = a-b
  if diff == 0 or (diff < 0 and d < 0) or (diff > 0 and d > 0):
    tmp.append(b)
    diff = d
    continue
  diff = 0
  subs.append(tmp)
  tmp = [b]
subs.append(tmp)

print(len(subs))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

v = A[1:] - A[:-1]
# print(v)

cnt = 0
i = 0
while i < len(v) - 1:
    # print('i', i)
    if v[i] * v[i + 1] < 0:
        cnt += 1
        i += 1
    i += 1
ans = cnt + 1
print(ans)

# 単調非減少 : v[i + 1] - v[i] >= 0
# 単調非増加 : v[i + 1] - v[i] <= 0
# 折り返し点 : v[i] * v[i + 1] < 0 and v[i + 1] * v[i + 2] < 0

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc013/tasks/agc013_a

n = int(input())

nums = [int(i) for i in input().split()]

ans = 0

incre = True
for i in range(n - 1):
    if incre:
        if nums[i] <= nums[i + 1]:
            continue
        else:
            ans += 1
            if i + 2 < n and nums[i + 1] >= nums[i + 2]:
                incre = False
    else:
        if nums[i] >= nums[i + 1]:
            continue
        else:
            ans += 1
            if i + 2 < n and nums[i + 1] <= nums[i + 2]:
                incre = True
print(ans + 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=1
bef=a[0]
c=0 #前との大小関係 
for i in range(1,n):
    if bef==a[i]:
        c=0
    elif bef<a[i]: #増加
        if c==2:
            ans+=1
            c=0
        else:
            c=1
    else: #減少
        if c==1:
            ans+=1
            c=0
        else:
            c=2
    bef=a[i]
print(ans)

Submission status: Wrong Answer

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

state = None # inc,dec,same
c = 0

for i in range(1,len(A)):
    if A[i] > A[i-1]:
        if state == None:
            state = "inc"
        elif state == "inc":
            pass
        elif state == "dec":
            c += 1
            state = None
        elif state == "same":
            state = "inc"
        else:
            pass

    elif A[i] < A[i-1]:
        if state == None:
            state = "dec"
        elif state == "dec":
            pass
        elif state == "inc":
            c += 1
            state = None
        elif state == "same":
            state = "dec"
        else:
            pass
    else:
        state = "same"

print (c+1)

Submission status: Wrong Answer

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

last = alist[0]
count = 1
status = 0  # 0-start, 1-asc, 2-desc
for a in alist[1:]:
    if abs(last - a) > 1 or (status == 1 and last > a) or (status == 2 and last < a):
        count += 1
        status = 0
    elif status == 0 and last > a:
        status = 2
    elif status == 0 and last < a:
        status = 1
    last = a
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-2:
      ans -= 1
      break
  ans += 1 
  i = tmp+2
else:
  if i == N-3 and (A[N-2]-A[N-3])*(A[N-1]-A[N-2])<0:
    ans += 1
print(ans+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-3:
      ans -= 1
      break
  ans += 1 
  i = tmp+2
else:
  if i == N-3 and (A[N-2]-A[N-3])*(A[N-1]-A[N-2])<0:
    ans += 1
print(ans+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-3:
      break
  ans += 1 
  i = tmp+2
else:
  if i == N-3 and (A[N-2]-A[N-3])*(A[N-1]-A[N-2])<0:
    ans += 1
print(ans+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-3:
      ans -= 1
      break
  ans += 1 
  i = tmp+2
else:
  if i == N-3:
    if (A[N-2]-A[N-3])*(A[N-1]-A[N-2])>=0:
      ans += 1
    else:
      ans += 2
  else:
    ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-3:
      ans -= 1
      break
  ans += 1 
  i = tmp+2
else:
  if (A[N-2]-A[N-3])*(A[N-1]-A[N-2])>=0:
    ans += 1
  else:
    ans += 2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N <3:
  print(1)
  exit()

ans = 0
i = 0
while i < N-3:
  tmp = i
  while (A[tmp+1]-A[tmp])*(A[tmp+2]-A[tmp+1])>=0:
    tmp += 1
    if tmp == N-3:
      break
  ans += 1 
  i = tmp+2
else:
  if (A[N-2]-A[N-3])*(A[N-1]-A[N-2])>=0:
    ans += 1
  else:
    ans += 2
print(ans)

Submission status: Wrong Answer

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

ans = 0
i = 0
while i < N-2:
  tmp = i

  while (A[tmp+1] - A[tmp]) * (A[tmp+2] - A[tmp+1]) >= 0:
    tmp += 1
    if tmp == N-2:
      break
  else:
    if tmp == N-3:
      ans +=1
  ans += 1 
  i = tmp+2
  if i == N-2:
    ans += 1
print(ans)

Submission status: Wrong Answer

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

ans = 1
inc = 0

if N == 1:
    print(ans)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0
for i in range(1,N):
  tmp = A[i]
  if (up == 0) and (down == 0):
    if tmp > before:
      up = 1
      before = tmp
    elif tmp < before:
      down = 1
      before = tmp
    else:
      continue

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
up = 0
down = 0
before = A[0]
tmp = 0

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
up = down = False
for i in range(n-1):
    if a[i] < a[i+1]:
        if up:continue
        up = True
        if down:
            ans+=1
            up = down = False
    else:
        if down:continue
        down = True
        if up:
            ans+=1
            up = down = False
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

# 入力
n = int(input())
a = list(map(int, input().split()))

# 主処理
result = 1
isSkip = False
for i in range(1, n-1):
    if isSkip:
        isSkip = False
        continue
    center = a[i]
    left = a[i-1]
    right = a[i+1]
    if ((center < left and center < right) or (left < center and right < center)):
        result += 1
        isSkip = True

# 出力
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if N == 1:
    print(1)
elif N == 2:
    print(1)
else:


    i = 1
    ans = 1
    n = len(A)
    while i < n - 1:
        if A[i-1] <= A[i] <= A[i+1] or A[i-1] >= A[i] >= A[i+1]:
            pass
        else:
            i += 1
            ans += 1
        i += 1
    print(ans)

Submission status: Wrong Answer

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

if N == 1:
    print(1)
elif N == 2:
    print(1)
else:


    i = 1
    ans = 1
    n = len(A)
    while i < n - 1:
        if A[i-1] < A[i] < A[i+1] or A[i-1] > A[i] > A[i+1]:
            pass
        else:
            i += 1
            ans += 1
        i += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
result = 1
if n > 2:
    h = a[0]<a[1]
    for i in range(n-1):
        if a[i]!=a[i+1]:
            c = a[i]<a[i+1]
            if h<0:
                h = c
            else:
                if h==c:
                    continue
                else:
                    h = -1
                    result += 1
print(result)

Submission status: Wrong Answer

Solution code:
# Problem A - Sorted Arrays

# input
N = int(input())
a_list = list(map(int, input().split()))

# initialization
flip_count = 0

# count
if not N==0:
    tmp = 0
    for i in range(1, N, 2):
        if i==N-1:
            continue
        if a_list[i-1]<a_list[i] and a_list[i]>a_list[i+1]:
            tmp += 1
        elif a_list[i-1]>a_list[i] and a_list[i]<a_list[i+1]:
            tmp += 1
    flip_count = max(flip_count, tmp)

    tmp = 0
    for i in range(0, N, 2):
        if i==0 or i==N-1:
            continue
        if a_list[i-1]<a_list[i] and a_list[i]>a_list[i+1]:
            tmp += 1
        elif a_list[i-1]>a_list[i] and a_list[i]<a_list[i+1]:
            tmp += 1
    flip_count = max(flip_count, tmp)


# output
print(flip_count+1)

Submission status: Wrong Answer

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

s=0
ans=1
for i in range(1,N):
    if s==0:
        if A[i] < A[i-1]:
            s=-1
        elif A[i] == A[i-1]:
            s=0
        elif A[i] > A[i-1]:
            s=1
    elif s==-1:
        if A[i] < A[i-1]:
            s=-1
        elif A[i] == A[i-1]:
            s=0
            ans+=1
        elif A[i] > A[i-1]:
            s=0
            ans+=1
    elif s==1:
        if A[i] < A[i-1]:
            s=0
            ans+=1
        elif A[i] == A[i-1]:
            s=0
            ans+=1
        elif A[i] > A[i-1]:
            s=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
result = 1
if n != 1:
    h = a[0]<a[1]
    for i in range(n-1):
        if a[i]!=a[i+1]:
            c = a[i]<a[i+1]
            if h<0:
                h = c
            else:
                if h==c:
                    continue
                else:
                    h = -1
                    result += 1
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
result = 1
if n != 1:
    h = a[0]<a[1]
    for i in range(n-1):
        c = a[i]<a[i+1]
        if h<0:
            h = c
        else:
            if h==c:
                continue
            else:
                h = -1
                result += 1
print(result)

Submission status: Wrong Answer

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

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