Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
list = [int(i) for i in input().split()]

dif_list = []
answer = 0

for i in range(n):
    t_i = t - list(i) * 0.006
    t_i_dif = abs(a - t_i)
    dif_list.append(t_i_dif)
    if min(dif_list) == t_i_dif:
        answer = i + 1

print(answer)


Fixed submission:
n = int(input())
t, a = map(int, input().split())
list = [int(i) for i in input().split()]

dif_list = []
answer = 0

for i in range(n):
    t_i = t - list[i] * 0.006
    t_i_dif = abs(a - t_i)
    dif_list.append(t_i_dif)
    if min(dif_list) == t_i_dif:
        answer = i + 1

print(answer)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
s = [list(input()) for i in range(N)]

S = []
for i in s: #S[i]=0なら頂点iのラベルは"A"、S[i]=1なら頂点iのラベルは"B"
    if i == "A": S.append(0)
    else: S.append(1)

#R[i]には頂点iと辺でつながっている頂点を入れる
R = [list() for _ in range(N)]
#C[i][0]には頂点iと辺でつながっているラベル"A"の数
#C[i][1]には頂点iと辺でつながっているラベル"B"の数
C = [[0, 0] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    R[a-1].append(b-1)
    R[b-1].append(a-1)
    C[a-1][S[b-1]] += 1
    C[b-1][S[a-1]] += 1

O = [0] * N #ダメな頂点には1を入れる
q = deque() #調べる頂点の候補リスト
for i in range(N):
    if C[i][0] * C[i][1] == 0: #もし少なくとも"A","B"どちらかに行けないなら
        q.append(i)
        O[i] = 1

while q:
    x = q.popleft()
    for v in R[x]:
        C[v][S[x]] -= 1
        if C[v][S[x]] == 0 and O[v] != 0:
            O[v] = 1
            q.append(v)

if sum(O) == N:
    answer = "No"
else:
    answer = "Yes"

print(answer)


Fixed submission:
from collections import deque

N, M = map(int, input().split())
s = list(input())

S = []
for i in s: #S[i]=0なら頂点iのラベルは"A"、S[i]=1なら頂点iのラベルは"B"
    if i == "A": S.append(0)
    else: S.append(1)

#R[i]には頂点iと辺でつながっている頂点を入れる
R = [list() for _ in range(N)]
#C[i][0]には頂点iと辺でつながっているラベル"A"の数
#C[i][1]には頂点iと辺でつながっているラベル"B"の数
C = [[0, 0] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    R[a-1].append(b-1)
    R[b-1].append(a-1)
    C[a-1][S[b-1]] += 1
    C[b-1][S[a-1]] += 1

O = [0] * N #ダメな頂点には1を入れる
q = deque() #調べる頂点の候補リスト
for i in range(N):
    if C[i][0] * C[i][1] == 0: #もし少なくとも"A","B"どちらかに行けないなら
        q.append(i)
        O[i] = 1

while q:
    x = q.popleft()
    for v in R[x]:
        C[v][S[x]] -= 1
        if C[v][S[x]] == 0 and O[v] == 0:
            O[v] = 1
            q.append(v)

if sum(O) == N:
    answer = "No"
else:
    answer = "Yes"

print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]

ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()

a = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            a += 1
            ab.remove([a, b])
            break

print(a)


Fixed submission:
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]

ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()

x = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            x += 1
            ab.remove([a, b])
            break

print(x)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array(input().split())
B = np.array(input().split())

ans = 0
mod = 1
for k in range(30):
    T = mod
    mod *= 2
    c = 0
    b = np.sort(B % mod)
    a = A % mod
    L1, R1, L2, R2 = (np.searchsorted(b, x - a).sum() for x in (T, 2*T, 3*T, 4*T))
    c += R1 - L1
    c += R2 - L2

    if c % 2:
        ans += T

print(ans)


Fixed submission:
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)
B = np.array(input().split(), dtype=np.int32)

ans = 0
mod = 1
for k in range(30):
    T = mod
    mod *= 2
    c = 0
    b = np.sort(B % mod)
    a = A % mod
    L1, R1, L2, R2 = (np.searchsorted(b, x - a).sum() for x in (T, 2*T, 3*T, 4*T))
    c += R1 - L1
    c += R2 - L2

    if c % 2:
        ans += T

print(ans)
Buggy python submission (verdict: Runtime Error):
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(input().split())
count = 0
for i in range(A, B+1):
    if f(i):
        count += 1
print(count)


Fixed submission:
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(int, input().split())
count = 0
for i in range(A, B+1):
    if f(str(i)):
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(int, input().split())
count = 0
for i in range(A, B+1):
    if f(i):
        count += 1
print(count)


Fixed submission:
def f(x):
    l = len(x)
    i = 0
    while x[i] == x[l-i-1]:
        i += 1
        if i > (l//2):
            return True
            break
    return False

A, B = map(int, input().split())
count = 0
for i in range(A, B+1):
    if f(str(i)):
        count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
def f(x):
    if x == 0:
        return 1
    elif x == 1:
        return 0

N, M = map(int, input().split())

a = [[0]*(M+2) for _ in range(N+2)]
for i in range(N):
    for j in range(M):
        a[i][j] = f(a[i][j])
        a[i][j+1] = f(a[i][j+1])
        a[i][j+2] = f(a[i][j+2])
        a[i+1][j] = f(a[i+1][j])
        a[i+1][j+1] = f(a[i+1][j+1])
        a[i+1][j+2] = f(a[i+1][j+2])
        a[i+2][j] = f(a[i+2][j])
        a[i+2][j+1] = f(a[i+2][j+1])
        a[i+2][j+2] = f(a[i+2][j+2])
print(sum(a[1:N+1, 1:M+1]))


Fixed submission:
N, M = map(int, input().split())

if N==1 and M==1:
    print(1)
elif N==1:
    print(M-2)
elif M==1:
    print(N-2)
elif N==2 or M==2:
    print(0)
else:
    print((N-2)*(M-2))

Buggy python submission (verdict: Runtime Error):
def f(x):
    if x == 0:
        return 1
    elif x == 1:
        return 0

N, M = map(int, input().split())

a = [[0]*(M+2) for _ in range(N+2)]
for i in range(N):
    for j in range(M):
        for k in range(3):
            for l in range(3):
                a[i+k][j+l] = f(a[i+k][j+l])
print(sum(a[1:N+1, 1:M+1]))


Fixed submission:
N, M = map(int, input().split())

if N==1 and M==1:
    print(1)
elif N==1:
    print(M-2)
elif M==1:
    print(N-2)
elif N==2 or M==2:
    print(0)
else:
    print((N-2)*(M-2))
Buggy python submission (verdict: Runtime Error):
import collections

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

z = [["b"] * W for _ in range(H)] #チェックしたマスはb(before)からa(after)にする
black = 0
for i in range(H):
    black += s[i].count("#") #最初の黒の数を数える
v = [[1,0] [0,1] [-1,0] [0,-1]] #動き方4パターン(↓ → ↑ ←)
que = collections.deque() #調べる候補リスト #調べ終わった要素は消す

#まず[0,0]
z[0][0] = "a"
s[0][0] = 1 #何歩で来れたかを代入していく #最初は1
que.append([0,0]) #最初の候補は[0,0]

#最短ルートを探す
while len(que) != 0: #候補がなくなるまで繰り返す
    i = que.popleft() #候補のうち1つを取り出し、リストから消す
    for dy, dx in v: #4パターンの動き方を考える
        y = i[0] + dy
        x = i[1] + dx
        if (0<=y<H and 0<=x<W and s[y][x]=="." and z[y][x]=="b"):
            z[y][x] == "a"
            s[y][x] == s[i[0]][i[1]] + 1
            que.append([y,x]) #進んだマスを新しく候補に入れる

if s[-1][-1] == ".": #[H,W]のマスに数字が入ってない→ゴールできない
    print(-1)
else: #「消せる白の最大数」=「全マス」-「黒マス」-「最短ルート」
    print(H*W - black - s[-1][-1])


Fixed submission:
import collections

H, W = map(int, input().split())
s = [list(input()) for i in range(H)]

z = [["b"] * W for _ in range(H)] #チェックしたマスはb(before)からa(after)にする
black = 0
for i in range(H):
    black += s[i].count("#") #最初の黒の数を数える
v = [[1,0], [0,1], [-1,0], [0,-1]] #動き方4パターン(↓ → ↑ ←)
que = collections.deque() #調べる候補リスト #調べ終わった要素は消す

#まず[0,0]
z[0][0] = "a"
s[0][0] = 1 #何歩で来れたかを代入していく #最初は1
que.append([0,0]) #最初の候補は[0,0]

#最短ルートを探す
while len(que) != 0: #候補がなくなるまで繰り返す
    i = que.popleft() #候補のうち1つを取り出し、リストから消す
    for dy, dx in v: #4パターンの動き方を考える
        y = i[0] + dy
        x = i[1] + dx
        if (0<=y<H and 0<=x<W and s[y][x]=="." and z[y][x]=="b"):
            z[y][x] = "a"
            s[y][x] = s[i[0]][i[1]] + 1
            que.append([y,x]) #進んだマスを新しく候補に入れる

if s[-1][-1] == ".": #[H,W]のマスに数字が入ってない→ゴールできない
    print(-1)
else: #「消せる白の最大数」=「全マス」-「黒マス」-「最短ルート」
    print(H*W - black - s[-1][-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [[int(i) for i in input().split()] for j in range(2)]
count = 0
Max = 0

for i in range(N):
    for j in range(i+1):
        count += A[0][j]
    for j in range(N-i):
        count += A[1][i+j]
    Max = max(Max, count
    count = 0

print(Max)


Fixed submission:
N = int(input())
A = [[int(i) for i in input().split()] for j in range(2)]
count = 0
Max = 0

for i in range(N):
    for j in range(i+1):
        count += A[0][j]
    for j in range(N-i):
        count += A[1][i+j]
    Max = max(Max, count)
    count = 0

print(Max)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())

m1 = Y // 10000
m2 = Y % 10000
if m1 > N:
    print("-1 -1 -1")
elif m1 == N and m2 > 0:
    print("-1 -1 -1")
else:
    c =False
    for i in range(m1+1):
        if Y - 10000*i > 5000*(N-i):
            pass
        else:
            for j in range(N+1-i):
                if Y == 10000*i + 5000*j + 1000*(N-i-j):
                    a = [str(i), str(j), str(N-i-j)]
                    print(" ".join(a))
                    c = True
                    break
        if c:
            break
if not c:
    print("-1 -1 -1")


Fixed submission:
N, Y = map(int, input().split())

c =False
for i in range(N+1):
    for j in range(N+1-i):
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            a = [str(i), str(j), str(N-i-j)]
            print(" ".join(a))
            c = True
            break
    if c:
        break
if not c:
    print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
S = input()

a = n
n = len(S)
for i in range(n-1):
    if S[i] != S[i+1]:
        a = min(a, max(i+1, n-i+1))

print(a)


Fixed submission:
S = input()

n = len(S)
a = n
for i in range(n-1):
    if S[i] != S[i+1]:
        a = min(a, max(i+1, n-i-1))

print(a)
Buggy python submission (verdict: Runtime Error):
N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for j in range(N)]

ci = 0
c = []
P_max = -1000000000
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        if i==j==k==l==m==n==o==p==q==r==0:
                                            pass
                                        for s in range(N):
                                            ci = F[s][0]*i + F[s][1]*j + F[s][2]*k + F[s][3]*l + F[s][4]*m + F[s][5]*n + F[s][6]*o + F[s][7]*p + F[s][8]*q + F[s][9]*r
                                            c.append(ci)
                                        P_sample = P[0][c[0]] + P[1][c[1]] + P[2][c[2]] + P[3][c[3]] + P[4][c[4]] + P[5][c[5]] + P[6][c[6]] + P[7][c[7]] + P[8][c[8]] + P[9][c[9]]
                                        P_max = max(P_max, P_sample)

print(P_max)


Fixed submission:
N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for j in range(N)]

ci = 0
c = []
P_max = -1000000000
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        if i==0 and j==0 and k==0 and l==0 and m==0 and n==0 and o==0 and p==0 and q==0:
                                            r = 1
                                        P_sample = 0
                                        for s in range(N):
                                            ci = F[s][0]*i + F[s][1]*j + F[s][2]*k + F[s][3]*l + F[s][4]*m + F[s][5]*n + F[s][6]*o + F[s][7]*p + F[s][8]*q + F[s][9]*r
                                            P_sample += P[s][ci]
                                        P_max = max(P_max, P_sample)

print(P_max)
Buggy python submission (verdict: Runtime Error):
from math import gcd

A, B, C, D, E, F = map(int, input().split())

N = 0
f = F//100; a = f//A; b = f//B
cn = D // gcd(C, D)

for j in range(b+1): #Bをj杯入れる
    for i in range(a+1): #Aをi杯入れる
        if i==0 and j==0:
            continue
        elif A*i + B*j > f:
            continue
        w = (A*i + B*j) * 100 #水の量
        e = (A*i + B*j) * E #この場合において溶ける砂糖の最大値
        S = min(e, F-w) #ビーカーも考慮した砂糖を入れられる限界
        s = 0
        for ci in range(min(S//C, cn)+1):
            s = max(s, S - (S - C*ci) % D)
        if s/(w+s) > N:
            N = s/(w+s)
            max_SW = s + w
            max_S = s

print(max_SW, max_S)


Fixed submission:
from math import gcd

A, B, C, D, E, F = map(int, input().split())

N = 0; max_SW = A*100; max_S = 0
f = F//100; a = f//A; b = f//B
cn = D // gcd(C, D)

for j in range(b+1): #Bをj杯入れる
    for i in range(a+1): #Aをi杯入れる
        if i==0 and j==0:
            continue
        elif A*i + B*j > f:
            continue
        w = (A*i + B*j) * 100 #水の量
        e = (A*i + B*j) * E #この場合において溶ける砂糖の最大値
        S = min(e, F-w) #ビーカーも考慮した砂糖を入れられる限界
        s = 0
        for ci in range(min(S//C, cn)+1):
            s = max(s, S - (S - C*ci) % D)
        if s/(w+s) > N:
            N = s/(w+s)
            max_SW = s + w
            max_S = s

print(max_SW, max_S)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = np.array([input().split() for _ in range(N)], dtype=np.int64)

fill_diagonal(A, 10**9)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = np.min(A[i]+A[j])
    if A[i][j] < d:
      ans += A[i][j]
    elif d < A[i][j]:
      print(-1)
      exit()

print(ans)


Fixed submission:
from numpy import *
N = int(input())
A = array([list(map(int,input().split())) for n in range(N)])

fill_diagonal(A, 10**10)

ans = 0
for i in range(N):
  for j in range(i+1,N):
    d = min(A[i]+A[j])
    if A[i][j] < d:
      ans += A[i][j]
    elif d < A[i][j]:
      print(-1)
      exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()

oddstring = s[0]
a = (len(s) + 1) // 2

for i in renge(a-1)}:
    oddstring += s[2*i+2]

print(oddstring)


Fixed submission:
s = input()

oddstring = s[0]
a = ((len(s) + 1) // 2) - 1

if a > 0:
    for i in range(a):
        oddstring += s[2*i+2]

print(oddstring)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S1 = list(input())
S2 = list(input())

if len(S1) == 1:
    print(3)
else:
    if S1[0] != S2[0]:
        t = 2
        i = 2
        a = 6
    else:
        t = 1
        i = 1
        a = 3
    while True:
        if S1[i] != S2[i]:
            if t == 2:
                a *= 3
            else:
                a *= 2
            i += 2
            t = 2
        else:
            if t == 2:
                a *= 1
            else:
                a *= 2
            i += 1
            t = 1
        a %= 1000000007
        if i == len(S1):
            print(a)
            break


Fixed submission:
N = int(input())
S1 = list(input())
S2 = list(input())

if len(S1) == 1:
    print(3)
elif len(S1) == 2:
    print(6)
else:
    if S1[0] != S2[0]:
        t = 2
        i = 2
        a = 6
    else:
        t = 1
        i = 1
        a = 3
    while True:
        if S1[i] != S2[i]:
            if t == 2:
                a *= 3
            else:
                a *= 2
            i += 2
            t = 2
        else:
            if t == 2:
                a *= 1
            else:
                a *= 2
            i += 1
            t = 1
        a %= 1000000007
        if i == len(S1):
            print(a)
            break
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
c = 0
for i in range(N-1):
    c += a[i]
    b.append(abs(2*b-sum_a))
print(min(b))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
c = 0
for i in range(N-1):
    c += a[i]
    b.append(abs(2*c-sum_a))
print(min(b))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
for i in range(N-1):
    b.append(abs(2*sum(a[:i+1])-sum_a))
print(min(b))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
c = 0
for i in range(N-1):
    c += a[i]
    b.append(abs(2*c-sum_a))
print(min(b))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]

b = []
for i in range(N-1):
    b.append(abs(sum(a[:i+1])-sum(a[:i:-1])))
print(min(b))


Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]
sum_a = sum(a)
b = []
c = 0
for i in range(N-1):
    c += a[i]
    b.append(abs(2*c-sum_a))
print(min(b))
Buggy python submission (verdict: Runtime Error):
import collections

N = int(input())
tree = [[] for _ in range(N)] #i行目には、i番目のマスと隣り合っているマスの番号が加えられる
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

color = [0] * N #色が塗られていなければ0、黒は1、白は-1
color[0] = 1
color[N-1] = -1
que = collections.depue() #色が塗られたマスの番号を、隣り合うマスが全て塗られるまでここに入れる
que.append(0)
que.append(N-1)
while que: #塗るべきマスがなくなるまで繰り返す
    i = que.popleft() #「左から」が重要 #n回でたどり着けるマスはn回目に全て塗って良い
    for x in tree[i]:
        if color[x] == 0:
            color[x] = color[i]
            que.append(x) #塗ったマスは調べるリストに入れる

if sum(color) > 0: #合計が正、つまり黒が多い場合は先手の勝ち
    print("Fennec")
else: #合計が0でも先手の塗るマスがないため後手の勝ち
    print("Snuke")


Fixed submission:
import collections

N = int(input())
tree = [[] for _ in range(N)] #i行目には、i番目のマスと隣り合っているマスの番号が加えられる
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

color = [0] * N #色が塗られていなければ0、黒は1、白は-1
color[0] = 1
color[N-1] = -1
que = collections.deque() #色が塗られたマスの番号を、隣り合うマスが全て塗られるまでここに入れる
que.append(0)
que.append(N-1)
while que: #塗るべきマスがなくなるまで繰り返す
    i = que.popleft() #「左から」が重要 #n回でたどり着けるマスはn回目に全て塗って良い
    for x in tree[i]:
        if color[x] == 0:
            color[x] = color[i]
            que.append(x) #塗ったマスは調べるリストに入れる

if sum(color) > 0: #合計が正、つまり黒が多い場合は先手の勝ち
    print("Fennec")
else: #合計が0でも先手の塗るマスがないため後手の勝ち
    print("Snuke")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

R = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    R[a - 1].append((b - 1, c))

INF = 10 ** 40
S = [-INF] * N
S[0] = 0

def score(fst, s, C):
    for nx, p in R[fst]:
        if S[nx] >= s + p or S[nx] >= INF:
            continue
        S[nx] = s + p
        if nx in C:
            S[nx] = INF
        C[nx] = C.get(nx, 0) + 1
        score(nx, S[nx], C)
        C[nx] -= 1
        if C[nx] == 0:
            del C[nx]

score(0, 0, {0: 1})

if S[-1] < INF:
    ans = S[-1]
else:
    ans = "inf"

print(ans)


Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())

R = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    R[a - 1].append((b - 1, c))

INF = 10 ** 40
S = [-INF] * N
S[0] = 0

def score(fst, s, C):
    for nx, p in R[fst]:
        if S[nx] >= s + p or S[nx] >= INF:
            continue
        S[nx] = s + p
        if nx in C:
            S[nx] = INF
        C[nx] = C.get(nx, 0) + 1
        score(nx, S[nx], C)
        C[nx] -= 1
        if C[nx] == 0:
            del C[nx]

score(0, 0, {0: 1})

if S[-1] < INF:
    ans = S[-1]
else:
    ans = "inf"

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

a=A[0]; c=1; i=1; w=0
def f(x):
    return A[x], x+1

while True:
    if w==0:
        if A[i]==a:
            a,i=f(i)
        elif A[i] > a:
            w=1; a,i=f(i)
        else:
            w=-1; f(i)
    elif w>0:
        if A[i]>=a:
            a,i=f(i)
        else:
            c+=1; a,i=f(i); w=0
    elif w<0:
        if A[i]<=a:
            a,i=f(i)
        else:
            c+=1; a,i=f(i); w=0
    if i==N:
        break

print(c)


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

c = 1; w = 0
for i in range(N-1):
    if w == 0:
        if A[i] < A[i+1]:
            w = 1
        elif A[i] > A[i+1]:
            w = -1
    elif (w > 0 and A[i] > A[i+1]) or (w < 0 and A[i] < A[i+1]):
         w = 0
         c += 1

print(c)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

a=A[0]; c=1; i=1; w=0
def f(x):
    return A[x], x+1

while True:
    if w==0:
        if A[i]==a:
            a,i=f(i)
        elif A[i] > a:
            w=1; a,i=f(i)
        else:
            w=-1; f(i)
    elif w>0:
        if A[i]>=a:
            a,i=f(i)
        else:
            c+=1; a,i=f(i); w=0
    elif w<0:
        if A[i]<=a:
            a,i=f(i)
        else:
            c+=1; a,i=f(); w=0
    if i==N:
        break

print(c)


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

c = 1; w = 0
for i in range(N-1):
    if w == 0:
        if A[i] < A[i+1]:
            w = 1
        elif A[i] > A[i+1]:
            w = -1
    elif (w > 0 and A[i] > A[i+1]) or (w < 0 and A[i] < A[i+1]):
         w = 0
         c += 1

print(c)