qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
summ = 0
summ2 = 0
a2 = a[:]


for i in range(n):
    if i % 2 == 0:
        if summ + a[i] <= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ + 1
            summ = 1
        else:
            summ += a[i]
    else:
        if summ + a[i] >= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ -1
            summ = -1
        else:
            summ += a[i]

for i in range(n):
    if i % 2 != 0:
        if summ2 + a2[i] <= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 + 1
            summ2 = 1
        else:
            summ2 += a[i]
    else:
        if summ2 + a2[i] >= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 -1
            summ2 = -1
        else:
            summ2 += a2[i]

print(min(ans1, ans2))


# Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
summ = 0
summ2 = 0
a2 = a[:]


for i in range(n):
    if i % 2 == 0:
        if summ + a[i] <= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ + 1
            summ = 1
        else:
            summ += a[i]
    else:
        if summ + a[i] >= 0:
            ans1 += abs(summ + a[i]) + 1
            a[i] = -summ -1
            summ = -1
        else:
            summ += a[i]
#-+-
for i in range(n):
    if i % 2 != 0:
        if summ2 + a2[i] <= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 + 1
            summ2 = 1
        else:
            summ2 += a2[i]
    else:
        if summ2 + a2[i] >= 0:
            ans2 += abs(summ2 + a2[i]) + 1
            a2[i] = -summ2 -1
            summ2 = -1
        else:
            summ2 += a2[i]


print(min(ans1, ans2))
# Buggy code:
n = int(input())
a = [int(i) for i in input().split()]
cur = 0
ans1, ans2 = 0,0
for i, x in enumerate(a):
    cur += x
    if i%2 == 0:
        if cur >= 1:
            continue
        else:
            ans1 += abs(1-x)
    else:
        if cur <= -1:
            continue
        else:
            ans1 += abs(-1-x)
for i, x in enumerate(a):
    cur += x
    if i%2 != 0:
        if cur >= 1:
            continue
        else:
            ans2 += abs(1-x)
    else:
        if cur <= -1:
            continue
        else:
            ans2 += abs(-1-x)
print(min(ans1, ans2))

# Fixed code:
n = int(input())
a = [int(i) for i in input().split()]
cur = 0
ans1, ans2 = 0,0
for i, x in enumerate(a):
    cur += x
    if i%2 == 0:
        if cur >= 1:
            continue
        else:
            ans1 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans1 += abs(-1-cur)
            cur = -1
cur = 0
for i, x in enumerate(a):
    cur += x
    if i%2 != 0:
        if cur >= 1:
            continue
        else:
            ans2 += abs(1-cur)
            cur = 1
    else:
        if cur <= -1:
            continue
        else:
            ans2 += abs(-1-cur)
            cur = -1
print(min(ans1, ans2))
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

sa = 0
count = [0, 0]

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 0:
        count[0] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 1:
        count[0] += 1 + sa
        sa = -1

sa = 0

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 1:
        count[1] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 0:
        count[1] += 1 + sa
        sa = -1

print(count)

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

sa = 0
count = [0, 0]

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 0:
        count[0] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 1:
        count[0] += 1 + sa
        sa = -1

sa = 0

for i in range(n):
    now = a[i]
    sa += now
    if sa <= 0 and i%2 == 1:
        count[1] += 1 - sa
        sa = 1
    elif sa >= 0 and i%2 == 0:
        count[1] += 1 + sa
        sa = -1

print(min(count))
# Buggy code:
N = int(input())
a = list(map(int, input().split()))

res = []
for start in [1, -1]:

    ans = 0
    _a = [a[0]]
    prev_sign = start
    for i in range(0, N):
        c = a[i]
        if c >= 0 and prev_sign > 0:
            ans += abs(c - (-1))
            c = -1
        elif c <= 0 and prev_sign < 0:
            ans += abs(c - 1)
            c = 1
        if c > 0:
            prev_sign = 1
        else:
            prev_sign = -1
        _a.append(c)

    __a = [_a[0]]
    acm_sum = _a[0]
    for i in range(1, N):
        c = _a[i]
        if abs(acm_sum) >= abs(c):
            if c < 0:
                c = -1*(abs(acm_sum)+1)
            else:
                c = abs(acm_sum)+1
        acm_sum += c
        ans += abs(c - _a[i])
        __a.append(c)
    res.append(ans)

print(min(res))

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

res = []
for start in [1, -1]:

    ans = 0
    _a = []
    prev_sign = start
    for i in range(0, N):
        c = a[i]
        if c >= 0 and prev_sign > 0:
            ans += abs(c - (-1))
            c = -1
        elif c <= 0 and prev_sign < 0:
            ans += abs(c - 1)
            c = 1
        if c > 0:
            prev_sign = 1
        else:
            prev_sign = -1
        _a.append(c)

    __a = [_a[0]]
    acm_sum = _a[0]
    for i in range(1, N):
        c = _a[i]
        if abs(acm_sum) >= abs(c):
            if c < 0:
                c = -1*(abs(acm_sum)+1)
            else:
                c = abs(acm_sum)+1
        acm_sum += c
        ans += abs(c - _a[i])
        __a.append(c)
    res.append(ans)

print(min(res))
# Buggy code:
def z(s,l):
	for i in range(n-1):
		r=l+a[i+1]
		if r*l>=0:
			if l<=0:
				s+=1-r
				r=1
			else:
				s+=1+r
				r=-1
		print(a[i+1],r,s)
		l=r
	return s
n=int(input())
a=list(map(int,input().split()))
s1=0
l1=a[0]
if a[0]<=0:
	s1=1-a[0]
	l1=1
s2=0
l2=a[0]
if a[0]>=0:
	s2=a[0]+1
	l2=-1
print(min(z(s1,l1),z(s2,l2)))

# Fixed code:
def z(s,l):
	for i in range(n-1):
		r=l+a[i+1]
		if r*l>=0:
			if l<=0:
				s+=1-r
				r=1
			else:
				s+=1+r
				r=-1
		l=r
	return s
n=int(input())
a=list(map(int,input().split()))
s1=0
l1=a[0]
if a[0]<=0:
	s1=1-a[0]
	l1=1
s2=0
l2=a[0]
if a[0]>=0:
	s2=a[0]+1
	l2=-1
print(min(z(s1,l1),z(s2,l2)))
# Buggy code:
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    c1 = c2 = s1 = s2 = 0
    for i in range(n):
        s1 += a[i]
        s2 += a[i]
        if i & 1:
            if s1 >= 0:
                c1 += s1 + 1
                s1 = -1
            if s2 <= 0:
                c2 += 1 - s2
                s2 = 1
        else:
            if s1 <= 0:
                c1 += 1 - s2
                s1 = 1
            if s2 >= 0:
                c2 += s2 + 1
                s2 = -1
    print(min(c1, c2))

if __name__ ==  '__main__':
    main()

# Fixed code:
import sys

n, *a = map(int, sys.stdin.read().split())

def main():
    s1 = s2 = c1 = c2 = 0
    for i in range(n):
        s1 += a[i]
        s2 += a[i]
        if i & 1:
            if s1 >= 0:
                c1 += abs(-1 - s1)
                s1 = -1

            if s2 <= 0:
                c2 += 1 - s2
                s2 = 1
        else:
            if s1 <= 0:
                c1 += 1 - s1
                s1 = 1

            if s2 >= 0:
                c2 += abs(-1 - s2)
                s2 = -1
    
    return min(c1, c2)

if __name__ == '__main__':
    ans = main()
    print(ans)
# Buggy code:
n = int(input())
i = input()

i = i.split()
for item in range(len(i)):
    i[item] = int(i[item])

totn = 0
totp = 0

countp = 0
countn = 0

for x in range(len(i)):
    totp += i[x]
    totn += i[x]
'''    
    if x == 0:
        if totp == 0:   
            totn = -1
            countn = 1

            totp = 1
            countp = 1
            
        elif totp < 0:
            countp = abs(totp) + 1
            totp = 1

        elif totp > 0:
            countn = abs(totn) + 1
            totn = -1
'''
    if x %2 == 1:
        if totn == 0:
            countn += 1
            totn = 1
        elif totn < 0:
            countn += abs(totn) + 1
            totn = 1

        if totp == 0:
            countp += 1
            totp = -1
        elif totp > 0:
            countp += abs(totp) + 1
            totp = -1

    elif x %2 == 0:
        if totn == 0:
            countn += 1
            totn = -1
        elif totn > 0:
            countn += abs(totn) + 1
            totn = -1

        if totp == 0:
            countp += 1
            totp = 1
        elif totp < 0:
            countp += abs(totp) + 1
            totp = 1
    '''print('totn', totn)
    print('countn', countn)
    print('totp', totp)
    print('countp', countp) '''   
count = min(countn, countp)
print(count)


# Fixed code:
n = int(input())
i = input()

i = i.split()
for item in range(len(i)):
    i[item] = int(i[item])

totn = 0
totp = 0

countp = 0
countn = 0

for x in range(len(i)):
    totp += i[x]
    totn += i[x]
    
    if x == 0:
        if totp == 0:   
            totn = -1
            countn = 1

            totp = 1
            countp = 1
            
        elif totp < 0:
            countp = abs(totp) + 1
            totp = 1

        elif totp > 0:
            countn = abs(totn) + 1
            totn = -1

    elif x %2 == 1:
        if totn == 0:
            countn += 1
            totn = 1
        elif totn < 0:
            countn += abs(totn) + 1
            totn = 1

        if totp == 0:
            countp += 1
            totp = -1
        elif totp > 0:
            countp += abs(totp) + 1
            totp = -1

    elif x %2 == 0:
        if totn == 0:
            countn += 1
            totn = -1
        elif totn > 0:
            countn += abs(totn) + 1
            totn = -1

        if totp == 0:
            countp += 1
            totp = 1
        elif totp < 0:
            countp += abs(totp) + 1
            totp = 1
    '''print('totn', totn)
    print('countn', countn)
    print('totp', totp)
    print('countp', countp) '''   
count = min(countn, countp)
print(count)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

def check(f):
        flag = f 
        t = 0 
        c = 0 
        for i in range(n):
                if t + a[i] <= 0 and flag == 1:
                        c += 1 - t - a[i]
                        t = 1 
                elif t + a[i] >= 0 and flag == -1: 
                        c += 1 + t + a[i]
                        t = -1
                else:
                        t += a[i] 
                flag *= -1
                print(t)
        return c 
    
total_p = check(1)
total_m = check(-1)
print(min(total_p, total_m))

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

def check(f):
        flag = f 
        t = 0 
        c = 0 
        for i in range(n):
                if t + a[i] <= 0 and flag == 1:
                        c += 1 - t - a[i]
                        t = 1 
                elif t + a[i] >= 0 and flag == -1: 
                        c += 1 + t + a[i]
                        t = -1
                else:
                        t += a[i] 
                flag *= -1
        return c 
    
total_p = check(1)
total_m = check(-1)
print(min(total_p, total_m))
# Buggy code:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] += -abs(sum)-1
        sum += -abs(sum)-1
        ans += abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        sum += abs(sum)+1
        ans += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        sum += abs(sum)+1
        ans += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] += -abs(sum)-1
        sum += -abs(sum)-1
        ans += abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)

# Fixed code:

def check1(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
    else:
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
  return ans

def check2(a):
  sum = 0
  ans = 0
  for i in range(len(a)):
    if(i % 2 == 0):
      sum += a[i]
      if(sum <= 0):
        a[i] += abs(sum)+1
        ans += abs(sum)+1
        sum += abs(sum)+1
    else:
      sum += a[i]
      if(sum >= 0):
        a[i] -= abs(sum)+1
        ans += abs(sum)+1
        sum -= abs(sum)+1
  return ans



n = input()
b = input().split()
a = [int(b[i]) for i in range(len(b))]
a2 = list(a)

ans1 = check1(a)
ans2 = check2(a2)


print(ans1) if(ans1<ans2) else print(ans2)
# Buggy code:
a = list(map(int, input().split()))
t1, s1 = 0, 0
for i, x in enumerate(a):
    s1 += x
    if i % 2 == 0:
        if s1 < 1:
            t1 += (1-s1)
            s1 = 1
    else:
        if s1 > -1:
            t1 += (s1+1)
            s1 = -1
t2, s2 = 0, 0
for i, x in enumerate(a):
    s2 += x
    if i % 2 == 0:
        if s2 > -1:
            t2 += (s2+1)
            s2 = -1
    else:
        if s2 < 1:
            t2 += (1-s2)
            s2 = 1
print(min(t1, t2))

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
t1, s1 = 0, 0
for i, x in enumerate(a):
    s1 += x
    if i % 2 == 0:
        if s1 < 1:
            t1 += (1-s1)
            s1 = 1
    else:
        if s1 > -1:
            t1 += (s1+1)
            s1 = -1
t2, s2 = 0, 0
for i, x in enumerate(a):
    s2 += x
    if i % 2 == 0:
        if s2 > -1:
            t2 += (s2+1)
            s2 = -1
    else:
        if s2 < 1:
            t2 += (1-s2)
            s2 = 1
print(min(t1, t2))
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

ans = 1
up = None
for l, r in zip(a, a[1:]):
    if l == r:
        continue
    if l < r:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = True
        elif up:
            ans += 1
            up = None

print(ans)


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

ans = 1
up = None
for l, r in zip(a, a[1:]):
    if l == r:
        continue
    if l < r:
        if up is None:
            up = True
        elif not up:
            ans += 1
            up = None
    else:
        if up is None:
            up = False
        elif up:
            ans += 1
            up = None

print(ans)
# Buggy 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))

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

ans=0
def plus_minus(i):
    while True:
        if a[i]==a[i+1]:
            i+=1
            continue
        if a[i]<a[i+1]:
            return 1
        if a[i]>a[i+1]:
            return -1

plus_minus(0)            
ans=1
for j in range(i,n-1):
    if check==1:
        if a[j] <= a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
    else:
        if a[j]>=a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
print(ans)

# Fixed code:
n=int(input())
a=[int(i) for i in input().split()]

ans=0
def plus_minus(i):
    while True:
        if i==n-1:
            break
        if a[i]==a[i+1]:
            i+=1
            continue
        if a[i]<a[i+1]:
            return 1
        if a[i]>a[i+1]:
            return -1

check=plus_minus(0)            
ans=1
for j in range(n-1):
    if check==1:
        if a[j] <= a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
    else:
        if a[j]>=a[j+1]:
            continue
        else:
            ans+=1
            check=plus_minus(j+1)
print(ans)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))

ans = 1
flag = 0
base = -1
count = 0
for i in range(n):
  if count == 0:
    count += 1
    base = a[i]
  elif count == 1:
    count += 1
    if a[i] < base:
      flag = 0
    elif a[i] > base:
      flag = 1
    else:
      continue
  else:
    if flag == 0:
      if a[i] <= a[i-1]:
        continue
      else:
        count = 1
        base = a[i]
        ans += 1
    else:
      if a[i] >= a[i-1]:
        continue
      else:
        count = 1
        base = a[i]
        ans += 1

        

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

ans = 1
flag = 0
base = -1
count = 0
for i in range(n):
  if count == 0:
    count += 1
    base = a[i]
  elif count == 1:
    
    if a[i] < base:
      flag = 0
      count += 1
    elif a[i] > base:
      flag = 1
      count += 1
    else:
      continue
  else:
    if flag == 0:
      if a[i] <= a[i-1]:
        continue
      else:
        count = 1
        base = a[i]
        ans += 1
    else:
      if a[i] >= a[i-1]:
        continue
      else:
        count = 1
        base = a[i]
        ans += 1
print(ans)
# Buggy 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)

# Fixed code:
n = int(input())

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

b = 0
ans = 1

for i in range(n-1):
    if a[i] == a[i+1]:
        continue
    elif a[i] > a[i+1]:
        if b <= 0:
            b = -1
        else:
            b = 0
            ans += 1
    else:
        if b >= 0:
            b = 1
        else:
            b = 0
            ans += 1
print(ans)
# Buggy code:
N = int(input())
A = list(map(int, input().split()))
cnt = 1
flg = 0
for i in range(1, len(A)):
    if flg == 0:
        if A[i-1] < A[i]:
            flg = 1
        elif A[i-1] > A[i]:
            flg = -1
    elif flg == -1:
        if A[i-1] < A[i]:
            flg = 1
            cnt += 1
    if flg == 1:
        if A[i-1] > A[i]:
            flg = -1
            cnt += 1
print(cnt)

# Fixed code:
N = int(input())

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

cnt = 1
flag = 0

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

print(cnt)
# Buggy code:
n = int(input())
a_ = list(map(int, input().split(' ')))
a = [-1]
i = 0
while  i < n:
    if a[-1] != a_[i]:
        a.append(a_[i])
    i += 1
a = a[1:]

ret = 1

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

# Fixed code:

n = int(input())
a_ = list(map(int, input().split(' ')))
a = [-1]
i = 0
while  i < n:
    if a[-1] != a_[i]:
        a.append(a_[i])
    i += 1
a = a[1:]
n = len(a)

ret = 1

i = 0
while i < n-2:
    if (a[i] > a[i+1] and a[i+1] < a[i+2]) or (a[i] < a[i+1] and a[i+1] > a[i+2]):
        ret += 1
        i += 2
    else:
        i += 1
        
print(ret)
# Buggy code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
m = 0
for i in range(n):
    if (a[i] - a[i - 1]) * m < 0:
        ans += 1
        m = 0
    elif a[i] - a[i - 1] != 0:
        m = a[i] - a[i - 1]
print(ans)

# Fixed code:
n = int(input())
a = list(map(int, input().split()))
ans = 1
m = 0
for i in range(1, n):
    if (a[i] - a[i - 1]) * m < 0:
        ans += 1
        m = 0
    elif a[i] - a[i - 1] != 0:
        m = a[i] - a[i - 1]
print(ans)
# Buggy code:
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-3:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    j+=1
  count+=1
  j+=2
print(count)

# Fixed code:
N=int(input())
count=1
size=1
p=list(map(int,input().split()))
q=[p[0]]
for i in range (1,N):
  if p[i]!=p[i-1]:
    q.append(p[i])
    size+=1
j=0
while True:
  if j>=size-2:
    break
  while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:
    if j>=size-3:
      count-=1
      break
    j+=1    
  count+=1
  j+=2
print(count)
# Buggy code:
N=int(input())
*A, = map(int,input().split())

ans = 0
l = 0
ud = 0
for a in A:
  if l==0:
    ans += 1
  elif l==1:
    if b>a:
      ud = 1
      l+=1
    elif b<a:
      ud = -1
      l+=1
  else:
    if b>a and ud == -1:
      ans += 1
      l = 1
    elif b<a and ud == 1:
      ans += 1
      l = 1
  b = a
print(ans)

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

ans = 0
l = 0
ud = 0
for a in A:
  if l==0:
    ans += 1
    l+=1
  elif l==1:
    if b<a:
      ud = 1
      l+=1
    elif b>a:
      ud = -1
      l+=1
  else:
    if b<a and ud == -1:
      ans += 1
      l = 1
    elif b>a and ud == 1:
      ans += 1
      l = 1
  b = a
print(ans)
# Buggy code:
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(1,n-1):
    if a[i-1] < a[i] > a[i+1]:
        ans += 1
    elif a[i-1] > a[i] < a[i+1]:
        ans += 1
print(ans) 

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

ans = 1
x = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        if x == -1:
            ans += 1
            x = 0
        elif x == 0:
            x = 1
    elif a[i] > a[i+1]:
        if x == 1:
            ans += 1
            x = 0
        elif x == 0:
            x = -1
print(ans)
# Buggy code:
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans = 0

    mode = 0

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

    ans += 1

    print(ans)

if __name__ == '__main__':
    solve()

# Fixed code:
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans = 0

    mode = 0

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

    ans += 1

    print(ans)

if __name__ == '__main__':
    solve()
# Buggy code:
N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f:
  if(f<0)&(i<j)|(0>f)&(i>j):a+=1;f=0
 else:f=(i<j)-(i>j)
print(a+1)

# Fixed code:
N,*A=map(int,open(0).read().split());f=a=0
for i,j in zip(A,A[1:]):
 if f<0:
  if i<j:a+=1;f=0
 elif f<1:f=(i<j)-(i>j)
 else:
  if i>j:a+=1;f=0
print(a+1)