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())
A = list(map(int, input().split()))
B=[2]*(N)
for i in range(N-1):
    if A[i]>A[i+1]:
        B[i]=-1
    elif A[i]==A[i+1]:
        B[i]=0
    elif A[i]<A[i+1]:
        B[i]=1
i=0
cnt=[0]*N
while True:
    if B[i]==1:
        if B[i+1]==0 or B[i+1]==1:
            i+=1
        elif B[i+1]==-1:
            if cnt[i-1]==0 or i==0:
                cnt[i]=1
            i+=1
        else:
            i+=1
    if B[i]==0:
        i+=1
    if B[i]==-1:
        if B[i+1]==0 or B[i+1]==-1:
            i+=1
        elif B[i+1]==1:
            if cnt[i-1]==0 or i==0:
                cnt[i]=1
            i+=1
        else:
            i+=1
    if B[i]==2:
        break
print(cnt.count(1)+1)

Submission status: Wrong Answer

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

flg = 0
i = 0
cnt = 1
pre = None
for a in A:
    if pre is None:
        pre = a
    if flg * (a-pre) < 0:
        flg = 0
        cnt += 1
        pre = None
    else:
        flg = a-pre
        pre = a

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def solve():
  ans = 1
  N = int(input())
  A = list(map(int, input().split()))
  i = 1
  while i<N-1:
    if (A[i]-A[i-1])*(A[i+1]-A[i])<0:
      ans += 1
      i += 1
    i += 1
  return ans
print(solve())

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
counter=1
res=0
for i in range(len(A)-1):
    if (A[i+1]<A[i] and res>0) or (A[i+1]>A[i] and res<0):
        counter+=1
        res=0
    else:
        res=A[i+1]-A[i]


print(counter)

Submission status: Wrong Answer

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

while len(A)>1:
    res=(A[1]>=A[0])
    for i in range(len(A)-1):
        if (A[i+1]<A[i] and res) or (A[i+1]>A[i] and not res):
            A=A[i+1:]
            counter+=1
            break

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
nb = 0
da = 0
for i in range(len(A)-1):
    if A[i] > A[i+1] and da > 0:
        nb += 1
        da = 0
    elif A[i] < A[i+1] and da < 0:
        nb += 1
        da = 0
    else:
        da = A[i+1] - A[i]
print(nb + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
zougen = 2
ans = 0

for i in range(1,n):
    if i == n-1:
        if zougen == 2:
            ans += 1
        elif zougen == 0:
            if a[i]-a[i-1]<0:
                ans += 2
            else:
                ans += 1
        else:
            if a[i]-a[i-1] > 0:
                ans += 2
            else:
                ans += 1
    elif zougen == 2:
        if a[i]-a[i-1]>0:
            zougen = 0
        elif a[i]-a[i-1]<0:
            zougen = 1
        else:
            zougen = 2
    elif zougen == 0:
        if a[i]-a[i-1]<0:
            zougen = 2
            ans += 1
    elif zougen == 1:
        if a[i]-a[i-1]>0:
            zougen = 2
            ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
c = 1
d = [1] * n
for i in range(2, n):
    if (a[i] - a[i - 1]) * (a[i - 1] - a[i - 2]) < 0 and d[i - 1]:
        c += 1
        d[i] = 0
print(c)

Submission status: Wrong Answer

Solution code:
# 10
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
a = LI()
ans = 1
for i in range(n - 1):
    if i == 0:
        continue
    if a[i - 1] <= a[i] <= a[i + 1] or a[i - 1] >= a[i] >= a[i + 1]:
        continue
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
# 10
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


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

    elif a[i] < a[i + 1]:
        flag = 1
    elif a[i] == a[i + 1]:
        flag = 0
    elif a[i] > a[i + 1]:
        flag = -1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
temp=[1]*n
i,up=0,0
while i<n:
    flag=0
    while i+1<n and a[i]<=a[i+1]:
        flag=1
        temp[i]=0
        temp[i+1]=0
        i+=1
    if flag: up+=1
    i+=1

i,down=0,0
while i<n:
    flag=0
    while i<n and temp[i]:
        flag=1
        i+=1
    if flag: down+=1
    i+=1
print(up+down)

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
d = [0 for _ in range(n-1)]
for i in range(n-1):
    d[i] = a[i+1]-a[i]

ans = 0 
flg = False
for i in range(n-1):
    if i == 0 or flg == True:
        flg = False
        continue
    else:
        if d[i]*d[i-1] < 0:
            ans += 1
            flg = True

print(ans+1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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


def solve(n,a,c=0,ans=1,prev_da=0):
  if c == n-1:
    return ans
  
  da = a[c+1] - a[c]
  #変化しないならcontinue
  if da == 0:
    return(n,a,c+1,ans,prev_da)
  #減少→増加
  elif da > 0 and prev_da < 0:
    return solve(n,a,c+1,ans+1,0)
  #増加→減少
  elif da < 0 and prev_da > 0:
    return solve(n,a,c+1,ans+1,0)
  else:
    return solve(n,a,c+1,ans,da)
    
print(solve(N,a))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = 0
S = 0
num = 1
for i in range(1,N):
    if A[i] - A[i - 1] == 0:
        a = 0
    elif A[i] - A[i - 1] > 0:
        a = 1
    else:
        a = 2
    if S == 0:
        S = a
    elif S != a:
        num += 1
        S = 0
print(num)

Submission status: Wrong Answer

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

for i in range(n - 1):
    if x[i] <= x[i + 1]:
        a += 1
        if b != 1:
            ans = max(a, b)
            b = 1
    elif x[i] >= x[i + 1]:
        b += 1
        if a != 1:
            ans = max(a, b)
            a = 1

print((n + ans  - 1) // ans)

Submission status: Wrong Answer

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

for i in range(n - 1):
    if x[i] == x[i + 1]:
        a += 1
        b += 1
    if x[i] < x[i + 1]:
        a += 1
        if b != 1:
            ans = max(a, b)
            b = 1
    else:
        b += 1
        if a != 1:
            ans = max(a, b)
            a = 1

print((n + ans  - 1) // ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())
    a = deque(a)
    r = 1
    flag = False
    muki = 0
    n1 = a.popleft()
    while a:
        n2 = a.popleft()
        if flag:
            if n1 < n2 and muki:
                n1 = n2
            elif n1 > n2 and not muki:
                n1 = n2
            else:
                r += 1
                flag = False
                n1 = n2
        else:
            if n1 < n2:
                flag = True
                muki = 1
                n1 = n2
            elif n1 > n2:
                flag = True
                muki = 0
                n1 = n2
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())
    a = deque(a)
    r = 1
    flag = False
    muki = 0
    char1 = a.popleft()
    while a:
        char = a.popleft()
        if flag:
            if muki == char > char1:
                continue
            else:
                r += 1
                flag = False
                char1 = char
        else:
            if char > char1:
                flag = True
                muki = 1
            elif char < char1:
                flag = True
                muki = 0
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
def main():
    n, *a = map(int, read().split())
    a = deque(a)
    r = 1
    flag = False
    muki = 0
    char1 = a.popleft()
    while a:
        char = a.popleft()
        if flag:
            if muki == char > char1:
                continue
            else:
                r += 1
                flag = False
                char1 = char
        else:
            if char > char1:
                flag = True
                muki = 1
            elif char < char:
                flag = True
                muki = 0
    print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = []
    p = 0
    for e in a:
        if p != e:
            b.append(e)
        p = e

    a = b
    n = len(a)
    p = -1
    ans = 0
    i = 1
    while i < n:
        if a[i-1] > a[i]:
            x = 0
        else:
            x = 1
        if p != x:
            ans += x
        p = x
        i += 1

    print(ans + 1)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    b = [0] * n
    b[0] = 1
    for i in range(1, n):
        if a[i] >= a[i-1]:
            b[i] = b[i-1] + 1
        else:
            b[i] = 1
    c = [0] * n
    c[n-1] = 1
    for i in range(n-2,-1,-1):
        if a[i+1] <= a[i]:
            c[i] = c[i+1] + 1
        else:
            c[i] = 1

    a.append(-1)
    for i in range(1,n+1):
        if a[i] < a[i-1]:
            x = b[i-1]
            for j in range(i-b[i-1],i):
                b[j] = x

    ans = 0
    i = 0
    while i < n:
        ans += 1
        i += max(c[i], b[i])

    print(ans)



t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

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

i = 1
ans = 1
plus = False
minus = False
if n != 1:
    while True:
        if i == n:
            break
        while A[i] - A[i-1] == 0:
            i += 1
            if i == n:
                break
        if i == n:
            break
        if A[i] - A[i - 1] > 0:
            plus = True
        else:
            minus = True
        if plus:
            while A[i] - A[i - 1] >= 0:
                i += 1
                if i == n:
                    break
        else:
            while A[i] - A[i -1] <= 0:
                i += 1
                if i == n:
                    break
        if i == n:
            break
        if plus:
            minus = True
            plus = False
        else:
            plus = True
            minus = False
        ans += 1
        i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split())) 
cnt = 1
bdelta = 0
for i in range(1, n):
    if (abs(l[i]-l[i-1])!=1 ) & (l[i]!=l[i-1]):
        #print("1"+str(l[i]))
        cnt+=1
        bdelta=0
    elif(bdelta != 0) & (bdelta != l[i]-l[i-1]):
        #print("2"+str(l[i]))
        cnt+=1
        bdelta=0
    else:
        #print("3" + str(l[i]-l[i-1]))
        bdelta = l[i]-l[i-1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split())) 
cnt = 1
bdelta = 0
for i in range(1, n):
    if abs(l[i]-l[i-1])!=1 | (l[i]==l[i-1]):
        #print("1"+str(l[i]))
        cnt+=1
        bdelta=0
    elif(bdelta != 0) & (bdelta != l[i]-l[i-1]):
        #print("2"+str(l[i]))
        cnt+=1
        bdelta=0
    else:
        #print("3" + str(l[i]-l[i-1]))
        bdelta = l[i]-l[i-1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
aset=set(a)
ans=1
if len(aset)>1:
    num1=a[0]
    num2=a[1]
    num3=0 #Ai<Ai+1 1  Ai>Ai+1 0
    if num1<num2:
        num3=1
    for i in range(len(a)-2):
        num=a[2+i]
        if num3==2 and num2>num:
            num3=0
        if num3==2 and num2<num:
            num3=1
        if num3==0 and num2<num:
            ans+=1
            num3=2
        if num3==1 and num2>num:
            ans+=1
            num3=2
        num2=num
print(ans)

Submission status: Wrong Answer

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


p = 0
res = 0

while p < N:
    while p + 1 < N and A[p] == A[p + 1]:
        p += 1
    if p + 1 < N and A[p] < A[p + 1]:
        while p + 1 < N and A[p] < A[p + 1]:
            p += 1
    elif p + 1 < N and A[p] > A[p + 1]:
        while p + 1 < N and A[p] > A[p + 1]:
            p += 1
    res += 1
    p += 1
print(res)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ans=1
vec=0
for i in range(n-1):
    now=a[i+1]-a[i]
    if vec*now<0:
        ans+=1
        vec=0
    if vec==0:
        vec=now
print(ans)

Submission status: Wrong Answer

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

if N == 1:
  print(1)
else:
  ans = 0
  i = 0
  while i < N:
    while i + 1 < N and A[i] == A[i + 1]:
      i += 1
    if i + 1 < N and A[i] < A[i + 1]:
      while i + 1 < N and A[i] < A[i + 1]:
        i += 1
    elif i + 1 < N and A[i] > A[i + 1]:
      while i + 1 < N and A[i] > A[i + 1]:
        i += 1
    
    ans += 1
    i += 1
      
  print(ans)

Submission status: Wrong Answer

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

li = []

for i in range(N-1):
    if A[i+1] - A[i] > 0:
       li.append('+')
    elif A[i+1] - A[i] < 0:
        li.append('-')
    else:
        pass
print(li)
ans = 1
p = 0
m = 0
for i in li:
    if i == '+':
        p = 1
    elif i == '-':
        m = 1
    if p == 1 & m == 1:
        ans += 1
        p = 0
        m = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=''
ans=1
for i in range(n-1):
  if a[i]<a[i+1]:
    s+='x'
  elif a[i]>a[i+1]:
    s+='y'
for i in range(len(s)-1):
  if s[i]!=s[i+1]:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
p = -1
xp = -1
ans = 1
input()
for i in input().split(" "):
  i = int(i)
  if i == p: continue
  if p != -1:
    x = p < i
    if xp != -1:
      ans += x != xp
    if xp != -1 and x != xp:
      xp = -1
    else:
      xp = x
    print(x)
  p = i
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 1
c = 0; s = 0
while s < n:
    if A[s] > c:
        for j in range(s,n):
            if A[j] >= c:
                c = A[j]
                continue
            else:
                c = A[j]
                s = j + 1
                ans += 1
                break
            s = j + 1
    elif A[s] < c:
        for j in range(s, n):
            if A[j] <= c:
                c = A[j]
                continue
            else:
                c = A[j]
                s = j + 1
                ans += 1
                break
            s = j + 1
    else:
        s += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

i = 1
cnt = 0
flg = True
while i < N:
    if flg:
        if A[i-1] <= A[i]:
            i += 1
        else:
            cnt += 1
            i += 1
            if i < N:
                if A[i-1] < A[i]:
                    flg = True
                else:
                    flg = False
    else:
        if A[i-1] >= A[i]:
            i += 1
        else:
            cnt += 1
            i += 1
            if i < N:
                if A[i-1] < A[i]:
                    flg = True
                else:
                    flg = False
print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

i = 1
cnt = 0

while i < N-1:
    if A[i-1] <= A[i] <= A[i+1] or A[i-1] >= A[i] >= A[i+1]:
        i += 1
        continue
    else:
        cnt += 1
        i += 2
print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

i = 0
cnt = 0
flg = True
while i < N-1:
    if A[i] == A[i+1]:
        i+=1
    elif A[i] < A[i+1]:
        flg = True
        while A[i] < A[i+1]:
            i += 1
            if N-1 <= i:
                break
        cnt += 1
    else:
        flg = False
        while A[i] > A[i+1]:
            i += 1
            if N-1 <= i:
                break
        cnt += 1
    i += 1
if flg:
    if A[N-2] <= A[N-1]:
        print(cnt)
    else:
        print(cnt+1)
else:
    if A[N-2] >= A[N-1]:
        print(cnt)
    else:
        print(cnt+1)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

i = 0
cnt = 0
flg = True
while i < N-1:
    if A[i] == A[i+1]:
        i+=1
    elif A[i] < A[i+1]:
        flg = True
        while A[i] < A[i+1]:
            i += 1
            if N-1 <= i:
                break
        cnt += 1
    else:
        flg = False
        while A[i] > A[i+1]:
            i += 1
            if N-1 <= i:
                break
        cnt += 1
    i += 1
if flg and A[N-2] <= A[N-1]:
    print(cnt)
elif not flg and A[N-2] >= A[N-1]:
    print(cnt)
else:
    print(cnt+1)

Submission status: Wrong Answer

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

ans = 1
mode = 0
for i in range(N-1):
    check = A[i+1] - A[i]
    if check >= 0:
        # asending
        if mode == check == 0:
            pass
        elif mode >= 0 and check > 0:
            pass
            mode = check
        else:
            ans += 1
            # print("BRK")
            mode = 0
    else:
        # desending
        if mode <= 0 and check < 0:
            pass
            mode = check
        else:
            ans += 1
            # print("BRK")
            mode = 0

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
X=0
cnt=0
for i in range(N-1):
  if A[i+1]-A[i]>0:
    if X!=1:cnt+=1
    X=1
  elif A[i+1]-A[i]<0:
    if X!=-1:cnt+=1
    X=-1
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
X=0
cnt=1
for i in range(N-1):
  if A[i+1]-A[i]>0:
    if X==-1:cnt+=1
    X=1
  elif A[i+1]-A[i]<0:
    if X==1:cnt+=1
    X=-1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
trend = 0
reg_trend = 0
cnt = 1

for i in range(1,n):
  if a[i]>a[i-1]:
    trend = 1
  elif a[i]<a[i-1]:
    trend = -1
  if trend == reg_trend*(-1):
    cnt += 1
    reg_trend = 0
  else:
    reg_trend = trend
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
trend = 0
reg_trend = 0
cnt = 1

for i in range(1,n):
  if a[i]>a[i-1]:
    trend = 1
  elif a[i]<a[i-1]:
    trend = -1
  if trend == reg_trend*(-1):
    cnt += 1
    reg_trend = 0
    if i > n - 1:
      cnt += 1
  else:
    reg_trend = trend
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
trend = 0
reg_trend = 0
cnt = 1

for i in range(1,n):
  if a[i]>a[i-1]:
    trend = 1
  elif a[i]<a[i-1]:
    trend = -1
  if trend == reg_trend*(-1):
    cnt += 1
    reg_trend = 0
    if i > n:
      cnt += 1
  else:
    reg_trend = trend
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0
up = dn = False
pre = A[0]
for a in A[1:]:
    if pre < a:
        up = True
    elif pre > a:
        dn = True
    if up and dn:
        ans += 1
        up = dn = False
    pre = a

print(ans)

Submission status: Wrong Answer

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

Plus = True
ans = 1
last = a[0]
count = 1
for i in range(n):
    if last > a[i] and Plus:
        if count > 1:
            ans += 1
            count = 0
        Plus = False
    if last < a[i] and Plus == False:
        if count > 1:
            ans += 1
            count = 0
        Plus = True
    #print(Plus)
    last = a[i]
    count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N == 1 or N == 2:
  print(1)
  exit(0)

i = 2
ans = 1
while i < N:
  if A[i-2] >= A[i-1]:
    checker1 = True
  else:
    checker1 = False
  if A[i-1] >= A[i]:
    checker2 = True
  else:
    checker2 = False
  i += 1
  if checker1 != checker2:
    ans += 1
    i += 1  
print(ans)

Submission status: Wrong Answer

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

for i in range(N-1):
    if a[i] == a[i+1]:
        continue
    if a[i] < a[i+1] and num == 0:
        num  = 1
        cut += 1
    elif a[i] > a[i+1] and num == 0:
        num = -1
        cut += 1
    elif num == 1 and a[i] > a[i+1]:
        if i == N-2:
            cut += 1
        num = 0
    elif num == -1 and a[i] < a[i+1]:
        if i == N-2:
            cut += 1
        num = 0
print(cut)

Submission status: Wrong Answer

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

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx > len(A) - 2:
            break

        status = ""

        if A[idx] < A[idx + 1]:
            status = "U"
        elif A[idx] > A[idx + 1]:
            status = "D"
        else:
            flat = True
            for j in range(idx, len(A) - 1):
                if A[j] < A[j + 1]:
                    status = "U"
                    flat = False
                    break

                elif A[j] > A[j + 1]:
                    status ="D"
                    Flat = False
                    break
            if flat:
                print(ans + 1)
                exit()

        if status == "U":
            for j in range(idx, len(A) - 1):
                if A[idx] <= A[idx + 1]:
                    idx += 1
                else:
                    ans += 1
                    idx += 1
                    break

        elif status == "D":
            for j in range(idx, len(A) - 1):
                if A[idx] >= A[idx + 1]:
                    idx += 1
                else:
                    ans += 1
                    idx += 1
                    break

    print(ans + 1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx > len(A) - 2:
            break

        status = ""

        if A[idx] < A[idx + 1]:
            status = "U"
        elif A[idx] > A[idx + 1]:
            status = "D"
        else:
            flat = True
            for j in range(idx, len(A) - 1):
                if A[j] < A[j + 1]:
                    status = "U"
                    flat = False
                    break

                elif A[j] > A[j + 1]:
                    status ="D"
                    Flat = False
                    break
            if flat:
                print(ans + 1)
                exit()

        if status == "U":
            for j in range(idx, len(A) - 1):
                if A[j] <= A[j + 1]:
                    pass
                else:
                    ans += 1
                    idx = j + 1
                    break

        elif status == "D":
            for j in range(idx, len(A) - 1):
                if A[j] >= A[j + 1]:
                    pass
                else:
                    ans += 1
                    idx = j + 1
                    break

    print(ans + 1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx > len(A) - 2:
            break

        status = ""

        if A[idx] < A[idx + 1]:
            status = "U"
        elif A[idx] > A[idx + 1]:
            status = "D"
        else:
            flat = True
            for j in range(idx, len(A) - 1):
                if A[j] < A[j + 1]:
                    status = "U"
                    flat = False
                elif A[j] > A[j + 1]:
                    status ="D"
                    Flat = False
            if flat:
                print(ans + 1)
                exit()


        if status == "U":
            for j in range(idx, len(A) - 1):
                if A[j] <= A[j + 1]:
                    pass
                else:
                    ans += 1
                    idx = j + 1
                    break

        elif status == "D":
            for j in range(idx, len(A) - 1):
                if A[j] >= A[j + 1]:
                    pass
                else:
                    ans += 1
                    idx = j + 1
                    break

    print(ans + 1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    idx = 0
    ans = 0
    for i in range(len(A)):
        if idx + 1 > len(A) - 1 :
            break

        m = ""
        if A[idx] < A[idx + 1]:
            m = "+"
        elif A[idx] > A[idx + 1]:
            m = "-"
        else:
            find = False
            for j in range(idx, len(A)-1):
                if A[j] < A[j + 1]:
                    m = "+"
                    find = True
                elif A[j] > A[j + 1]:
                    m = "-"
                    find = True
            if find == False:
                print(ans + 1)
                exit()

        for j in range(idx, len(A) - 1):
            if m == "+":
                if A[j] <= A[j+1]:
                    idx += 1
                else:
                    find = True
                    idx += 1
                    ans += 1
                    break
            elif m == "-":
                if A[j] >= A[j+1]:
                    idx += 1
                else:
                    find = True
                    idx += 1
                    ans += 1
                    break

    print(ans + 1)

if __name__ == "__main__":
    main()