Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(1, n):
    arr[i + 1] = arr[i] + a[i]
setarr = set(arr)
countarr = [[0 for _ in range(max(setarr) - min(setarr) + 1)] for _ in range(n + 1)]
countarr[0][arr[0]] = 1
for i in range(1, n + 1):
    countarr[i] = deepcopy(countarr[i - 1])
    countarr[i][arr[i]] += 1
ans = 0
for i in range(n):
    s = arr[i]
    ans += countarr[n][s] - countarr[i][s]
print(ans)

Fixed submission:
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(2, n + 1):
    arr[i] = arr[i - 1] + a[i - 1]
arr2= Counter(arr)
arr3 = list(set(arr))
ans = 0
for i in range(len(arr3)):
    ans += arr2[arr3[i]] * (arr2[arr3[i]] - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(1, n):
    arr[i + 1] = arr[i] + a[i]
setarr = set(arr)
countarr = Counter(arr)
ans = 0
for i in range(n):
    s = arr[i]
    if s in setarr:
        ans += arr[i+1:].count(s)
print(ans)

Fixed submission:
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(2, n + 1):
    arr[i] = arr[i - 1] + a[i - 1]
arr2= Counter(arr)
arr3 = list(set(arr))
ans = 0
for i in range(len(arr3)):
    ans += arr2[arr3[i]] * (arr2[arr3[i]] - 1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(1, n):
    arr[i + 1] = arr[i] + a[i]
setarr = set(arr)
countarr = Counter(arr)
ans = 0
for i in range(n):
    s = arr[i]
    if s in setarr:
        ans += Counter(arr[i + 1:])[s]
print(ans)

Fixed submission:
import sys, re, os
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
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
arr = [0 for _ in range(n + 1)]
arr[1] = a[0]
for i in range(2, n + 1):
    arr[i] = arr[i - 1] + a[i - 1]
arr2= Counter(arr)
arr3 = list(set(arr))
ans = 0
for i in range(len(arr3)):
    ans += arr2[arr3[i]] * (arr2[arr3[i]] - 1) // 2
print(ans)