Buggy python submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	n = INT()
	a = LIST()
	p = 0
	q = 0
	l = []
	temp = 0

	if a[0] < a[1]:
		sign = 1
	elif a[0] > a[1]:
		sign = -1
	else:
		sign = 0

	for i in range(n-1):
		if a[i] < a[i+1] and sign == -1:
			p += 1
			sign = 1
			# print("a")
			if temp == 0:
				q += 1
				temp = 1

		elif a[i] > a[i+1] and sign == 1:
			q += 1
			sign = -1
			# print("b")
			if temp == 0:
				p += 1
				temp = 1


	# print(p, q)
	print(max(p, q) + 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    a = LIST()

    ans = 0

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

    if a[0] < a[1]:
        sign = 1
    elif a[0] > a[1]:
        sign = -1
    else:
        sign = 0

    for i in range(n-1):
        if a[i] < a[i+1] and sign == -1:
            ans += 1
            sign = 0

        elif a[i] > a[i+1] and sign == 1:
            ans += 1
            sign = 0

        elif sign == 0:
            if a[i] < a[i+1]:
                sign = 1
            elif a[i] > a[i+1]:
                sign = -1

    print(ans + 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	n = INT()
	a = LIST()
	p = 0
	q = 0
	l = []

	sign = (a[1]-a[0]) / abs(a[1]-a[0])

	for i in range(n-1):
		if a[i] < a[i+1] and sign == -1:
			p += 1
			sign = 1
			#print("a")

		elif a[i] > a[i+1] and sign == 1:
			q += 1
			sign = -1
			#print("b")

	print(p + 2)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    a = LIST()

    ans = 0

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

    if a[0] < a[1]:
        sign = 1
    elif a[0] > a[1]:
        sign = -1
    else:
        sign = 0

    for i in range(n-1):
        if a[i] < a[i+1] and sign == -1:
            ans += 1
            sign = 0

        elif a[i] > a[i+1] and sign == 1:
            ans += 1
            sign = 0

        elif sign == 0:
            if a[i] < a[i+1]:
                sign = 1
            elif a[i] > a[i+1]:
                sign = -1

    print(ans + 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	n = INT()
	a = LIST()
	p = 0
	q = 0
	l = []

	sign = (a[1]-a[0]) / abs(a[1]-a[0])

	for i in range(n-1):
		if a[i] < a[i+1] and sign == -1:
			p += 1
			sign *= -1

		elif a[i] > a[i+1] and sign == 1:
			q += 1
			sign *= -1


	print(max(p, q) + 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    a = LIST()

    ans = 0

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

    if a[0] < a[1]:
        sign = 1
    elif a[0] > a[1]:
        sign = -1
    else:
        sign = 0

    for i in range(n-1):
        if a[i] < a[i+1] and sign == -1:
            ans += 1
            sign = 0

        elif a[i] > a[i+1] and sign == 1:
            ans += 1
            sign = 0

        elif sign == 0:
            if a[i] < a[i+1]:
                sign = 1
            elif a[i] > a[i+1]:
                sign = -1

    print(ans + 1)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
	n = INT()
	a = LIST()
	p = 0
	q = 0
	l = []

	sign = (a[1]-a[0]) / abs(a[1]-a[0])

	for i in range(n-1):
		print(i)
		if a[i] < a[i+1] and sign == -1:
			p += 1
			sign *= -1

		elif a[i] > a[i+1] and sign == 1:
			q += 1
			sign *= -1


	print(max(p, q) + 1)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    a = LIST()

    ans = 0

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

    if a[0] < a[1]:
        sign = 1
    elif a[0] > a[1]:
        sign = -1
    else:
        sign = 0

    for i in range(n-1):
        if a[i] < a[i+1] and sign == -1:
            ans += 1
            sign = 0

        elif a[i] > a[i+1] and sign == 1:
            ans += 1
            sign = 0

        elif sign == 0:
            if a[i] < a[i+1]:
                sign = 1
            elif a[i] > a[i+1]:
                sign = -1

    print(ans + 1)


if __name__ == '__main__':
    main()