Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02788 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque
import math


n, d, a = map(int, input().split())

XH = []
for _ in range(n):
    x, h = map(int, input().split())
    XH.append((x, h))
XH.sort()

answer = 0
damage = 0
QUEUE = deque()
for x, h in XH:
    if QUEUE:
        while x > QUEUE[0][0]:
            damage -= QUEUE[0][1]
            QUEUE.popleft()
            if not QUEUE:
                break
    h -= damage
    if h <= 0:
        continue
    bomb = math.ceil(h / a)
    QUEUE.append((x + 2 * d, a * bomb))
    damage += a * bomb
    answer += bomb

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
import bisect
import math


n, d, a = map(int, input().split())

XH = []
for _ in range(n):
    x, h = map(int, input().split())
    XH.append((x, h))
XH.sort()

X, H = [], []
for x, h in XH:
    X.append(x)
    H.append(h)
H = np.array(H)

answer = 0
for i in range(n):
    if H[i] <= 0:
        continue
    j = bisect.bisect(X, X[i] + 2 * d)
    bomb = math.ceil(H[i] / a)
    H[i:j] -= a * bomb
    answer += bomb

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
import bisect
import math


n, d, a = map(int, input().split())

XH = []
for _ in range(n):
    x, h = map(int, input().split())
    XH.append((x, h))
XH.sort()

X, H = [], []
for x, h in XH:
    X.append(x)
    H.append(h)
H = np.array(H)

answer = 0
for i in range(n):
    if H[i] <= 0:
        continue
    j = bisect.bisect(X, X[i] + 2 * d)
    bomb = math.ceil(H[i] / a)
    H[i:j] -= a * bomb
    answer += bomb

print(answer)
Problem p02801 (python)

Fixed submission:
import sys
input = sys.stdin.readline


alphabets = "abcdefghijklmnopqrstuvwxyz"

c = input().strip()
i = alphabets.index(c)

answer = alphabets[i + 1]
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


alphabets = "abcdefghijklmnopqrstuvwxyz"

c = input()
i = alphabets.index(c)

answer = alphabets[i + 1]
print(answer)
Problem p02804 (python)

Fixed submission:
import sys
input = sys.stdin.readline

mod = 10**9 + 7


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

FACTORIAL = [1] * (n + 1)
for i in range(1, n + 1):
    FACTORIAL[i] = FACTORIAL[i - 1] * i % mod
INVERSE = [1] * (n + 1)
INVERSE[n] = pow(FACTORIAL[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    INVERSE[i] = INVERSE[i + 1] * (i + 1) % mod

def combination(n, r):
    return FACTORIAL[n] * INVERSE[n - r] % mod * INVERSE[r] % mod

A.sort()
sum_max = 0
for i in range(k - 1, n):
    sum_max = (sum_max + A[i] * combination(i, k - 1)) % mod

A.sort(reverse = True)
sum_min = 0
for i in range(k - 1, n):
    sum_min = (sum_min + A[i] * combination(i, k - 1)) % mod

print((sum_max - sum_min) % mod)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

mod = 10**9 + 7


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

C1 = [1]
for i in range(n - k):
    C1.append((k + i) / (i + 1))
C2 = [1]
for i in range(n - k):
    C2.append(int(C2[i] * C1[i + 1]))

A.sort()
A_max = A[k - 1:]
sum_max = 0
for i in range(n - k + 1):
    sum_max += A_max[i] * C2[i]

A.sort(reverse = True)
A_min = A[k - 1:]
sum_min = 0
for i in range(n - k + 1):
    sum_min += A_min[i] * C2[i]

print((sum_max - sum_min) % mod)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline()


n, q = map(int, input().split())
GRAPH = [[] for _ in range(n + 1)]
COUNTS = [0] * (n + 1)

for _ in range(n - 1):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    COUNTS[p] += x

def dfs(now, prev):
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        else:
            next = vertex
        COUNTS[next] += COUNTS[now]
        dfs(next, now)
dfs(1, 0)

answer = " ".join(map(str, COUNTS[1:]))
print(answer)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2 * 10**5)
def input():
    return sys.stdin.readline()


n, q = map(int, input().split())
GRAPH = [[] for _ in range(n + 1)]
COUNTS = [0] * (n + 1)

for _ in range(n - 1):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    COUNTS[p] += x

def dfs(now, prev):
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        else:
            next = vertex
        COUNTS[next] += COUNTS[now]
        dfs(next, now)
dfs(1, 0)

answer = " ".join(map(str, COUNTS[1:]))
print(answer)
Problem p02953 (python)

Fixed submission:
import sys
 
n = int(input())
nums = list(map(int, input().split()))
maxnum = 0

for x in range(n):
    if maxnum < nums[x]:
        maxnum = nums[x]
    if maxnum - nums[x] > 1:
        print('No')
        sys.exit() 
 
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
nums = list(map(int, input().split()))

for x in range(n-1)
  	if nums[x] > nums[x+1]:
    	nums[x] -= 1

    if nums[x] > nums[x+1]:
      	print('No')
      	sys.exit()

print('Yes')
Problem p03059 (python)

Fixed submission:
a,b,t = map(int,input().split())
print(0 if a>t else (t//a)*b)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
 
n,*a = map(int, open(0).read().split())
 
rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))
 
print(max(gcd(r, l) for r, l in zip(rs, ls[::-1])))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce

n=int(input());Alist=list(map(int,input().split()))

def gcd_L(numbers):
    return reduce(gcd, numbers)

M_list = []
for i in range(n):
    alist = Alist[:i] + Alist[i+1:]
    M_list.append(gcd_L(alist))

print(max(M_list))

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

n=int(input());Alist=list(map(int,input().split()))

def gcd_L(numbers):
    return reduce(gcd, numbers)

M_list = []
for i in range(n):
    alist = Alist[:i] + Alist[i+1:]
    M_list.append(gcd_L(alist))

print(max(M_list))
Problem p02993 (python)

Fixed submission:
pre = 0
for i in list(input()):
    if i == pre:
        print("Bad")
        exit()
    pre = i
print("Good")

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)//gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm)))

Buggy submission (verdict: Runtime Error):
pre = None
for i in list(input()):
	if i == pre:
      	print("Bad")
        exit()
    pre = i
print("Good")
Problem p02995 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)//gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm)))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)/gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d
import fractions
def lcm(x,y):
    return (x*y) // fractions.gcd(x,y)
tmplcm=sub//lcm(c,d)
print(max(sub-(tmpc+tmpd-tmplcm)), 0)

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d

import math
def lcm(x,y):
  return (x*y) // math.gcd(x,y)

tmplcm=sub//lcm(c,d)
print(sub-(tmpc+tmpd-tmplcm))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int, input().split())
# for i , a<i<b, i % c|d != 0
sub=b-a
tmpc=sub//c
tmpd=sub//d
import math
def lcm(a,b):
    return (a*b) // math.gcd(a,b)
tmplcm=sub//lcm(c,d)
print(sub-(tmpc+tmpd-tmplcm))
Problem p03032 (python)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0 
# left
for i in range(min(n, k) + 1):
    # right
    for j in range(min(n, k) - i + 1):
        # print(i,j)
        par_seq = sorted(v[:i] + v[-j:] if j != 0 else v[:i])
        par_seq_sum = sum(par_seq)
        if par_seq_sum > ans:
            ans = par_seq_sum
        ope = k - (i + j)
        # print(par_seq, par_seq_sum)
        for _ in range(min(ope, len(par_seq))):
            rm = par_seq.pop(0)
            if rm < 0 and sum(par_seq) > ans:
                ans = sum(par_seq)

print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0 
# left
for i in range(min(n, k) + 1):
    # right
    for j in range(min(n, k) - i + 1):
        par_seq = sorted(v[:i] + v[-j:] if j != 0 else v[:i])
        par_seq_sum = sum(par_seq)
        if par_seq_sum > ans:
            ans = par_seq_sum
        m = k - (i + j)
        tmp = max([sum(par_seq[i:]) for i in range(min(m, len(par_seq)))])
        if tmp > ans:
          ans = tmp
print(ans)
Problem p03037 (python)

Fixed submission:
n,m=map(int,input().split())
mis,mas=[],[]
for _ in range(m):
  tmp=list(map(int,input().split()))
  mis.append(tmp[0])
  mas.append(tmp[1])
ans=min(mas)-max(mis)+1
print(ans if ans>0 else 0)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
mis,mas=[],[]
for _ in range(m-1):
  tmp=list(map(int,input().split()))
  mis.append(tmp[0])
  mas.append(tmp[1])
ans=max(mas)-min(mis)
print(ans if ans>0 else 0)
Problem p03071 (python)

Fixed submission:
i, j = map(int, input().split())
print(max(i + j, i * 2 - 1, j * 2 - 1))

Buggy submission (verdict: Runtime Error):
i, j = map(int, input().split())
print(max(i + j, i * 2 - 1, j * 2 - 1)
Problem p03088 (python)

Fixed submission:
n, mod = int(input()), 10 ** 9 + 7
memo = [{} for i in range(n+1)]
def check(l):
    for i in range(4):
        t = list(l)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1] # 順序の入れ替え
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == n:
        return 1
    ret = 0
    for c in 'ACGT':
        if check(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))

Buggy submission (verdict: Runtime Error):
n, mod = int(input()), 10 ** 9 + 7
memo = [{} for i in range(n+1)]
def check(l):
    for i in range(4):
        t = list(l)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1] # 順序の入れ替え
        if ''.join(t).count('AGC') >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == n:
        return 1
    ret = 0
    for c in 'ACGT':
        if check(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % mod
    memo[cur][last3] = ret
    print(memo)
    return ret

print(dfs(0, 'TTT'))
Problem p03111 (python)

Fixed submission:
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else 10**9
  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+l[cur], b, c) + 10
  ret2 = dfs(cur+1, a, b+l[cur], c) + 10
  ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A)+abs(b-B)+abs(c-C) if min(a,b,c) > 0 else return 10**8
  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+l[cur], b, c) + 10
  ret2 = dfs(cur+1, a, b+l[cur], c) + 10
  ret3 = dfs(cur+1, a, b, c+l[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

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

take_list_global = []
for _ in range(N):
    take_list_global.append(int(input()))


abc = [A, B, C]

if A in take_list_global:
    take_list_global.remove(A)
    acb.remove(A)

if B in take_list_global:
    take_list_global.remove(B)
    abc.remove(B)

if C in take_list_global:
    take_list_global.remove(C)
    abc.remove(C)

if len(abc) == 0:
    print(0)


def combination(n: int) -> list:
    c = []
    for i in range(1<<n):
        if i == 0:
            continue
        l = []
        for j in range(n):
            if i&(1<<j) != 0:
                l.append(j)
        c.append(l)
    return c

from itertools import permutations
tar_lists = permutations(abc)

ans_list = []

for tar_list in tar_lists:
    
    ans = 0
    take_list = take_list_global.copy()
    
    for tar in tar_list:
        cost = 0
        com_lists = combination(len(take_list))
        min_abs = 1001
        min_com = []
        
        for com_list in com_lists:
            s = 0
            for c in com_list:
                s += take_list[c]
            if min_abs > abs(tar - s):
                min_abs = abs(tar - s)
                min_com = com_list

        del_take = []
        
        for c in min_com:
            del_take.append(take_list[c])

        for d in del_take:
            take_list.remove(d)

        cost += 10 * (len(min_com) - 1)
        cost += min_abs
        ans += cost

    ans_list.append(ans)

print(min(ans_list))
Problem p03162 (python)

Fixed submission:
N = int(input())
util = [[int(i) for i in input().split()] for _ in range(N)]
"""
memo = [0 for _ in range(N + 1)]
def dp(i, u, rem_i):
    if i == N:
        return u
    elif i == 0:
        ret = max(dp(i + 1, u+util[i][0], 0), dp(i + 1, u+util[i][1], 1), dp(i + 1, util[i][2], 2))
    else:
        index = list({0, 1, 2} - {rem_i})
        ret = max(dp(i + 1, u+util[i][index[0]], index[0]), dp(i + 1, u+util[i][index[1]], index[1]))
    memo[i] = ret
    print(memo)
    return ret

print(dp(0, 0, 3))
"""

memo = [{} for i in range(N)]
for i in range(3):
    memo[-1][i] = util[-1][i]
for i in range(N-2, -1, -1):
    for j in range(3):
        memo[i][j] = util[i][j] + max(memo[i+1][k] for k in range(3) if j != k)
print(max(memo[0].values()))

Buggy submission (verdict: Runtime Error):
N = int(input())
util = [[int(i) for i in input().split()] for _ in range(N)]
memo = [0 for _ in range(N + 1)]
def dp(i, u, rem_i):
    if i == N:
        return u
    elif i == 0:
        ret = max(dp(i + 1, u+util[i][0], 0), dp(i + 1, u+util[i][1], 1), dp(i + 1, util[i][2], 2))
    else:
        index = list({0, 1, 2} - {rem_i})
        ret = max(dp(i + 1, u+util[i][index[0]], index[0]), dp(i + 1, u+util[i][index[1]], index[1]))
    memo[i] = ret
    return ret

print(dp(0, 0, 3))
Problem p03206 (python)

Fixed submission:
d = int(input())
if d==25:
    print("Christmas")
if d==24:
    print("Christmas Eve")
if d==23:
    print("Christmas Eve Eve")
if d==22:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d = int(input())
if d=25:
    print("Christmas")
if d=24:
    print("Christmas Eve")
if d=23:
    print("Christmas Eve Eve")
if d=22:
    print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d = int(input())
if d=25:
	print("Christmas")
if d=24:
	print("Christmas Eve")
if d=23:
	print("Christmas Eve Eve")
if d=22:
	print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
d = int(input())
if d=25:
	print("Christmas")
if d=24:
	print("Christmas Eve")
if d=23:
	print("Christmas Eve Eve")
if d=22:
	print("Christmas Eve Eve Eve")
Problem p03211 (python)

Fixed submission:
s = input()
err = []
for i in range(len(s) - 2):
  err.append(abs(int(s[i:i+3]) - 753))
print(min(err))

Buggy submission (verdict: Runtime Error):
s = input()
err = []
for i in range(len(s) - 3):
  err.append(abs(int(s[i:i+3]), 753))
print(min(err))
Problem p03239 (python)

Fixed submission:
N,T = map(int, input().split())
l = []
for i in range(N):
  c, t = map(int, input().split())
  if not t > T:
    l.append([i+1, c])
if l == []:
    print('TLE'); exit()
l.sort(key=lambda x: x[1])
print(l[0][1])

Buggy submission (verdict: Runtime Error):
n,t = map(int, input().split())
l = []
for _ in range(n):
  i, c = map(int, input().split())
  if not c => j:
    l.append([c, j])
l.sort(key=lambda x: x[1])
print(l[0][0])
Problem p03308 (python)

Fixed submission:

n = input()
a = input().split(" ")

l = list()
for x in a:
	l.append(int(x))

print(abs(max(l) - min(l)))

Buggy submission (verdict: Runtime Error):

n = input()
l = input()
print(abs(max(l) - min(l)))
Problem p03309 (python)

Fixed submission:
input()
a = list(map(int, input().split()))
b = sorted([a[i]-i-1 for i in range(len(a))])
med=b[len(b)//2]
print(sum(list(map(abs,list(map(lambda x: x-med ,b))))))

Buggy submission (verdict: Runtime Error):
n = input()
xs = input().split(" ")

l = list()
for x in xs:
	l.append(int(x))


ll = list()
for index, argv in enumerate(l):
	for x in range(max(l)):
		ls = list()		
		ab = abs(argv - (n + index))
		ls.append(ab)
	ll.append(ls)

sum_list = list()
for line in ls:
	s = sum(line)
	sum_list.append(s)

print(min(sum_list))
Problem p03324 (python)

Fixed submission:
d, n = map(int, input().split())
print(100 ** d * 101 if n == 100 else 100 ** d * n)

Buggy submission (verdict: Runtime Error):
print(int(input()) * (100 ** int(input())))
Problem p03597 (python)

Fixed submission:
a = input()
n = int(a) ** 2 

b = input()

print(n - int(b))

Buggy submission (verdict: Runtime Error):
def solve():
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            dist = 100*s/(w+s)
                            memo[a,b,c,d] = dist
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
	solve()
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

l_list = [LR[i][0] for i in range(M)]
r_list = [LR[i][1] for i in range(M)]

l = max(l_list)
r = min(r_list)

if r-l < 0:
  print(0)
else:
  print(r-l+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(N)]

l_list = [LR[i][0] for i in range(M)]
r_list = [LR[i][1] for i in range(M)]

l = max(l_list)
r = min(r_list)
if r-l <= 0:
    print(0)
else:
    print(r-l+1)
Problem p03079 (python)

Fixed submission:
a, b, c = map(int, input().split())

if a == b == c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a, b, c = map(int(input().split()))

if a == b == c:
    print('Yes')
else:
    print('No')
Problem p03086 (python)

Fixed submission:
S = input()
nagasa = len(S)
ichi_list = []
counter = 0
for i in range(nagasa):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'C' or S[i] == 'G':
        counter += 1
    else:
        ichi_list.append(counter)
        counter = 0

ichi_list.append(counter)
print(max(ichi_list))

Buggy submission (verdict: Runtime Error):
S = input()

nagasa = len(S)
ichi_list = []
counter = 0
for i in range(nagasa):
    if S[i] == 'A' or S[i] == 'T' or S[i] == 'C' or S[i] == 'G':
        counter += 1
    else:
        counter = ichi_list.append(counter)
        counter = 0

print(max(ichi_list))
Problem p03101 (python)

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H, W = map(int, input.split())
h, w = map(int, input.split())

print((H-h)*(W-w))
Problem p03103 (python)

Fixed submission:
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort()
cost = 0
for i in range(N):
    M -= AB[i][1]
    cost += AB[i][1]*AB[i][0]
    if M<=0:
        store_num = i
        break
if M<0:
    m = abs(M)
    cost -= m*AB[store_num][0]
print(cost)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
AB = list(map(int, input().split()) for _ in range(N))

sorted_ab = sorted(AB)
cost = 0
while M > 0:
    for i in range(N):
        for j in range(sorted_ab[i][1]):
            M -= 1
            cost += sorted_ab[i][0]
print(cost)
Problem p03363 (python)

Fixed submission:
N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0
'''
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0: #要素が等しい物の数数えたらええんか...
                ans += 1
'''
#やってることの中身というか本質を見逃してた
ruiseki_A_list.sort()
kosuu = [1]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(1)
        
for num in kosuu:
    if num <= 1:
        ans += 0
    else:
        ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))
print(int(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0

ruiseki_A_list.sort()
kosuu = [1]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(1)
kosuu[-1] += 1
print(kosuu)
for num in kosuu:
    ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))

print(int(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
A_list = list(map(int, input().split()))
import math
#部分列の和を考えるなら累積和を
ruiseki_A_list = [0 for _ in range(N)]

for i in range(N):
    if i == 0:
        ruiseki_A_list[i] = A_list[i]
    else:
        ruiseki_A_list[i] = A_list[i] + ruiseki_A_list[i-1]

#元のある区間の総和が知りたい

ruiseki_A_list.insert(0,0)
ans = 0
'''
for left_num in range(N+1):
    for right_num in range(N+1):
        if left_num < right_num:
            if ruiseki_A_list[right_num] - ruiseki_A_list[left_num]==0: #要素が等しい物の数数えたらええんか...
                ans += 1
'''
#やってることの中身というか本質を見逃してた
ruiseki_A_list.sort()
kosuu = [0]
k = 0
for i in range(N):
    if ruiseki_A_list[i+1] - ruiseki_A_list[i] == 0:
        kosuu[k] += 1
    else:
        k += 1
        kosuu.append(0)

for num in kosuu:
    ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))

print(ans)