ZhenlongDai/ACPR huggingface dataset:
Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


n,l=map(int,input().split())
s=[0 for i in range(n)]
for i in range(n):
    s[i]=input()

print(s)
s.sort()
print(s)
ans=""
for i in range(n):
    ans+=s[i]

print(ans)

Failing test case input:
3 2
exx
axw
cwx

Expected output:
axwcwxexx


Actual output:
['exx', 'axw', 'cwx']
['axw', 'cwx', 'exx']
axwcwxexx


Fixed submission (verdict: Accepted):


n,l=map(int,input().split())
s=[0 for i in range(n)]
for i in range(n):
    s[i]=input()

s.sort()
ans=""
for i in range(n):
    ans+=s[i]

print(ans)

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = input().split()

s = [input() for i in range(int(a[0]))]
b = ''

s.sort()
print(s)

for i in range(int(a[0]),0):
  b = s[i] + b
  
print(b)

Failing test case input:
3 3
cwy
xxa
yxd

Expected output:
cwyxxayxd


Actual output:
cwy, xxa, yxd

Fixed submission (verdict: Accepted):
a = input().split()

s = [input() for i in range(int(a[0]))]
b = ''

s.sort()

b = ''.join(s)

print(b)

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,L = map(int,input().split())
S = []
ans = ""
for i in range(N):
  S.append(input())
sorted(S)
for i in range(len(S)):
  ans += S[i]
print(ans)


Failing test case input:
3 3
xxd
xxa
xxd

Expected output:
xxaxxdxxd


Actual output:
xxdxxaxxd


Fixed submission (verdict: Accepted):
l=[]
a=''
N,L=map(int,input().split())
for i in range(N):
	l.append(input())
	l.sort()
for i in range(N):
	a += l[i]
print(a)

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, l = map(int, input().split())

list = []
for _ in range(n):
    list.append(input())

list.sort()
str = ""
for s in list:
    str += s

print(s)

Failing test case input:
3 3
xdx
axw
xxd

Expected output:
axwxdxxxd


Actual output:
xxd


Fixed submission (verdict: Accepted):
n, l = map(int, input().split())

list = []
for _ in range(n):
    list.append(input())

list.sort()
str = ""
for s in list:
    str += s

print(str)

Problem: p04044
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n,l = map(int,input().split())
word_list=[]
for i in range(n):
    word = str(input())
    word_list.append(word)
x = sorted(word_list)
print(''.join(word_list))

Failing test case input:
3 3
cwx
axx
dxy

Expected output:
axxcwxdxy


Actual output:
cwxaxxdxy


Fixed submission (verdict: Accepted):

n,l = map(int,input().split())
word_list=[]
for i in range(n):
    word = str(input())
    word_list.append(word)
x = sorted(word_list)
print(''.join(x))

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, L = list(map(int,input().split()))
S = [input() for _ in range(N)]
print(sorted(S))


Failing test case input:
3 3
dxx
xxa
xxd

Expected output:
dxxxxaxxd


Actual output:
dxx, xxa, xxd

Fixed submission (verdict: Accepted):
N, L = list(map(int,input().split()))
S = [input() for i in range(N)]
S.sort()
for str in S:
    print(str, end="")
Problem: p04044
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, L = map(int, readline().split())
    S = [readline().strip() for _ in range(L)]

    S.sort()
    ans = ''.join(S)
    print(ans)
    return


if __name__ == '__main__':
    main()


Failing test case input:
3 1
xxd
xax
xyd

Expected output:
xaxxxdxyd


Actual output:
xxd


Fixed submission (verdict: Accepted):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, L = map(int, readline().split())
    S = [readline().strip() for _ in range(N)]

    S.sort()
    ans = ''.join(S)
    print(ans)
    return


if __name__ == '__main__':
    main()

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, l = map(int, input().split())
d = {input() for _ in range(n)}
print(sorted(d))

Failing test case input:
3 3
cwx
xxa
yxd

Expected output:
cwxxxayxd


Actual output:
cwx, xxa, yxd

Fixed submission (verdict: Accepted):
n, l = map(int, input().split())
d = sorted([input() for _ in range(n)])
print(''.join(d))

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,l = map(int,input().split())
s = [0]*n
for i in range(n):
    s[i] = input()
s = sorted(s)
ans = []
for i in range(n):
    ans.extend(s[i])
print(ans)

Failing test case input:
3 3
xcw
xxa
dxy

Expected output:
dxyxcwxxa


Actual output:
d, x, y, x, c, w, x, x, a

Fixed submission (verdict: Accepted):
n,l = map(int,input().split())
s = [0]*n
for i in range(n):
    s[i] = input()
s = sorted(s)
ans = []
for i in range(n):
    print(s[i],end="")
print("")

Problem: p04044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,l=map(int,input().split())
s=[str(input()) for _ in range(n)]
sort_s=sorted(s)

print(''.join(s))

Failing test case input:
3 3
cxx
axx
xxd

Expected output:
axxcxxxxd


Actual output:
cxxaxxxxd


Fixed submission (verdict: Accepted):
n,l=map(int,input().split())
s=[str(input()) for _ in range(n)]
sort_s=sorted(s)

print(''.join(sort_s))
Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = str(input())

M = 0
for n in range(1,N) :
    set1 = set([])
    set2 = set([])
    I = set([])
    for c in (S[:n]) :
        set1.add(c)
    for d in (S[n+1:]) :
        set2.add(d)
    I = set1 & set2
    if(len(I)>M) :
        M = len(I)
print(M)

Failing test case input:
6
caacb^

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
S = str(input())

M = 0
for n in range(1,N) :
    set1 = set([])
    set2 = set([])
    I = set([])
    for c in (S[:n]) :
        set1.add(c)
    for d in (S[n:]) :
        set2.add(d)
    I = set1 & set2
    if(len(I)>M) :
        M = len(I)
print(M)

Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
s = input()
ch = []
for i in range(1, n):
    x = s[:i+1]
    y = s[i:len(s)]
    a = set(x)
    b = set(y)
    c = a.intersection(b)
    ch.append(len(c))
print(max(ch))

Failing test case input:
10
aba`ababbb

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
s = input()
ch = []
for i in range(0, n):
    x = s[:i+1]
    y = s[i+1:len(s)]
    a = set(x)
    b = set(y)
    c = a.intersection(b)
    ch.append(len(c))
print(max(ch))

Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
a = set(S[:1])
b = set(S[1:])
M = a & b

for i in range(2,N):
  a = set(S[:i])
  b = set(S[i:])
  if (a & b) > M:
    M = (a & b)
  else:
    print(M)
    break

Failing test case input:
6
abdbb`

Expected output:
1


Actual output:
{'b'}


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
a = set(S[:1])
b = set(S[1:])
M = len(a & b)

for i in range(2,N):
  a = set(S[:i])
  b = set(S[i:])
  if len(a & b) > M:
    M = len(a & b)

print(M)

Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int( input())
S = list( input())

intger2 = 0

for i in range(N):
  intger1 = 0
  str1 = list(set(S[i:]))
  str2 = list(set(S[:i + 1]))
  l = len(str2)
  
  for j in range(l):
    if( str2[j] in str1):
      intger1 += 1
      
    else:
      continue
  
  if( intger2 <= intger1):
    intger2 = intger1
    
  else:
    continue
    
print(intger2)

Failing test case input:
6
ab`dcb

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int( input())
S = list( input())

intger2 = 0
c = []

for i in range(N):
  intger1 = 0
  str1 = list(set(S[i + 1:]))
  str2 = list(set(S[:i + 1]))
  l = len(str2)
  
  for j in range(l):
    if( str2[j] in str1):
      intger1 += 1
      
    else:
      continue
  
  if( intger2 <= intger1):
    intger2 = intger1
    c.append(intger2)
    
  else:
    continue

print(max(c))
Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
L=list(input())
ans=[]
for i in range(N):
  a=set(L[:i+1])
  b=set(L[i+1:])
  ans.append(a & b)
print(len(max(ans)))

Failing test case input:
10
a_a``bccbb

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
L=list(input())
ans=[]
for i in range(N):
  a=set(L[:i+1])
  b=set(L[i+1:])
  ans.append(len(a & b))
print(max(ans))

Problem: p03338
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import math
import bisect

def solve(s):
    n = len(s)
    max_val = 0
    for i in range(1, n):
        s1 = set(list(s[0:i]))
        s2 = set(list(s[i:]))
        val = len(s1 ^ s2)
        max_val = max(max_val, val)
    return max_val

def main():
    n = int(input())
    s = input()
    print(solve(s))

if __name__ == "__main__":
    main()


Failing test case input:
10
aaabaaabaa

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
import math
import bisect

def solve(s):
    n = len(s)
    max_val = 0
    for i in range(1, n):
        s1 = set(list(s[0:i]))
        s2 = set(list(s[i:]))
        val = len(s1 & s2)
        max_val = max(max_val, val)
    return max_val

def main():
    n = int(input())
    s = input()
    print(solve(s))

if __name__ == "__main__":
    main()

Problem: p03338
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
S=input()
ans=1
for i in range(N-2):
  ans=max(ans,len(list(set(list(S[:i+1])) & set(list(S[i+1:])))))
print(ans)

Failing test case input:
6
b`^dca

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
S=input()
ans=0
for i in range(N):
  ans=max(ans,len(list(set(list(set(list(S[:i+1])) & set(list(S[i+1:])))))))
print(ans)

Problem: p03338
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
def main():
  n = int(input())
  s = input()
  ans=0
  for i in range(0,int(n/2)+1):
    sum=0
    x=s[:i+1]
    y=s[i+1:]
    while len(x)>0:
      if x[0] in y :
        sum+=1
      x=x.replace(x[0],'')
    if sum>ans:
      ans=sum
  print(ans)
main()


Failing test case input:
10
aaa`abccbb

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import math
def main():
  n = int(input())
  s = input()
  ans=0
  for i in range(0,n):
    sum=0
    x=s[:i+1]
    y=s[i+1:]
    while len(x)>0:
      if x[0] in y :
        sum+=1
      x=x.replace(x[0],'')
    if sum>ans:
      ans=sum
  print(ans)
main()
Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
from functools import reduce



def solve(lines):
    def func(n, i, initializer=0):
        a = set(S[:i])
        b = set(S[i:])
        return max( n, len(a & b) )

    N = int(lines.pop(0))
    S = lines.pop(0)

    print( reduce( func, range(1,N) ) )




lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Failing test case input:
6
b`^dca

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):

import sys
from functools import reduce



def solve(lines):
    def func(n, i):
        a = set(S[:i])
        b = set(S[i:])
        return max( n, len(a & b) )

    N = int(lines.pop(0))
    S = lines.pop(0)

    print( reduce( func, range(1,N), 0 ) )




lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Problem: p03338
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    x, y = set(S[:i+1]), set(S[i:])
    cnt = 0
    for c in x:
        if c in y:
            cnt += 1
    ans = max(ans, cnt)
print(ans)


Failing test case input:
45
otyczfqfmgbjrfblyrtrupdiplldjktuzxhejykqthxmb

Expected output:
11


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
S = input()
ans = 0
for i in range(1, N):
    x, y = set(S[:i]), set(S[i:])
    cnt = 0
    for c in x:
        if c in y:
            cnt += 1
    ans = max(ans, cnt)
print(ans)
Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

ans = [0] * N
for i,a in enumerate(A):
  ans[a-1] = i+1

print(ans)

Failing test case input:
3
3 -2 -1

Expected output:
2 3 1 


Actual output:
[2, 3, 1]


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

ans = [0] * N
for i,a in enumerate(A):
  ans[a-1] = i+1

print(*ans)

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    for l in range(n):
        if a[i]==l+1:
            b[i]=l+1
            break
print(*b)

Failing test case input:
3
-2 0 -1

Expected output:
1 3 2 


Actual output:
0 0 0


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[i]=[a[i],i+1]
b=sorted(b, key=lambda x: x[0])
for i in range(n):
    if i!=n-1:
        print(b[i][1],end=" ")
    else:
        print(b[i][1])

Problem: p02899
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	A = LI()
	order = [0]*N
	for i,a in enumerate(A):
		order[a-1] = i+1
	A = list(map(str,A))
	print("".join(A))

main()

Failing test case input:
3
2 -2 3

Expected output:
2 1 3 


Actual output:
2-23


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	A = LI()
	order = [0]*N
	for i,a in enumerate(A):
		order[a-1] = i+1
	order = list(map(str,order))
	print(" ".join(order))

main()
Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
L = [0]*N
for i in range(0, N):
    L[A[i]-1] = i + 1
    print(L,A[i])
print(*L)

Failing test case input:
5
2 1 3 4 5

Expected output:
2 1 3 4 5 


Actual output:
[0, 1, 0, 0, 0] 2
[2, 1, 0, 0, 0] 1
[2, 1, 3, 0, 0] 3
[2, 1, 3, 4, 0] 4
[2, 1, 3, 4, 5] 5
2 1 3 4 5


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
L = [0]*N
for i in range(0, N):
    L[A[i]-1] = i + 1
print(*L)

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ls = list(map(str,input().split()))
a = [0 for j in range(n)]
for i in range(n):
    a[i] = ls[i] + str(i+1)
a.sort()
for k in range(n):
    print(a[k][int(len(a[k]))-1],end=' ')

Failing test case input:
3
-2 0 -1

Expected output:
1 3 2 


Actual output:
3 1 2 

Fixed submission (verdict: Accepted):
n = int(input())
ls = list(map(int,input().split()))
a = [0 for j in range(n)]
for i in range(n):
    a[i] = [ls[i],str(i+1)]
a.sort()
for k in range(n):
    print(a[k][1],end=' ')

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

output = list(range(0,N))

for i in range(N):
    output[A[i] - 1] = i + 1

print(output)

Failing test case input:
3
2 -2 3

Expected output:
2 1 3 


Actual output:
[2, 1, 3]


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

output = list(range(0,N))

for i in range(N):
    output[A[i] - 1] = i + 1

print(*output)

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input())
num_list = list(map(int, input().split()))
order_list = sorted(range(len(num_list)), key=lambda k: num_list[k])
order_list = list(map(lambda x: x+1, order_list))
print('{}'.format(order_list))


Failing test case input:
3
2 -2 3

Expected output:
2 1 3 


Actual output:
[2, 1, 3]


Fixed submission (verdict: Accepted):


N = int(input())
num_list = list(map(int, input().split()))
order_list = sorted(range(len(num_list)), key=lambda k: num_list[k])
order_list = list(map(lambda x: x+1, order_list))
[print(' '.join([str(i) for i in order_list]))]

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
A=list(map(int,input().split()))
a=[]
for i in range(n):
  a.append([i+1])
for j in range(n):
  a[j].append(A[j])
sorted(a,key=lambda x:x[1])
lst=[]
for i in range(n):
  lst.append(a[i][0])
print(lst)
  


Failing test case input:
5
2 1 3 4 5

Expected output:
2 1 3 4 5 


Actual output:
[1, 2, 3, 4, 5]


Fixed submission (verdict: Accepted):
n=int(input())
A=list(map(int,input().split()))
a=[]
for i in range(n):
  a.append([i+1,A[i]])
b=sorted(a,key=lambda x:x[1])
lst=[]
for k in range(n):
  lst.append(b[k][0])
print(*lst)
Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
Num = [int(i) for i in range(1,N+1)]

List = []
for i in range(len(A)):
    List.append([A[i],i+1])
print(List)

List.sort()
ans = []
for i in range(len(List)):
    ans.append(List[i][1])
print(*ans)


Failing test case input:
3
-2 0 -1

Expected output:
1 3 2 


Actual output:
[[-2, 1], [0, 2], [-1, 3]]
1 3 2


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]
Num = [int(i) for i in range(1,N+1)]

List = []
for i in range(len(A)):
    List.append([A[i],i+1])


List.sort()
ans = []
for i in range(len(List)):
    ans.append(List[i][1])
print(*ans)

Problem: p02899
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

from sys import stdin
import heapq

N = int(input())
As = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0] * N

for i in range(N):
    x = As[i]
    ans[x-1] = i + 1

print(ans)


Failing test case input:
8
8 2 7 3 4 5 6 1

Expected output:
8 2 4 5 6 7 3 1

Actual output:
[8, 2, 4, 5, 6, 7, 3, 1]


Fixed submission (verdict: Accepted):

from sys import stdin
import heapq

N = int(input())
As = [int(x) for x in stdin.readline().rstrip().split()]
ans = [0] * N

for i in range(N):
    x = As[i]
    ans[x-1] = i + 1

ans = ' '.join(map(str, ans))
print(ans)
Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=input()
n=len(s)
rst=[0 for j in range(2019)]
x=0
ans=0
for i in range(n):
    y=(int(s[n-1-i])*(10**i))%2019
    x+=y
    if x>=2019:
        x%=2019
    print(x,y)
    ans+=rst[x]
    rst[x]+=1
if rst[0]==1:
    ans+=1

print(ans)

Failing test case input:
1176854830

Expected output:
1


Actual output:
0 0
30 30
830 800
792 1981
317 1544
793 476
325 1551
1595 1270
525 949
1939 1414
1


Fixed submission (verdict: Accepted):
s=input()
n=len(s)
rst=[0 for j in range(2019)]
rst[0]=1
x=0
ans=0
drst=1
for i in range(n):
    y=(int(s[n-1-i])*drst)%2019
    drst=(drst*10)%2019
    x+=y
    if x>=2019:
        x%=2019
    
    ans+=rst[x]
    rst[x]+=1

    

print(ans)

Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N + 1):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

Failing test case input:
3054417607960

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)

Problem: p02702
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


S = input()[::-1] 
N = len(S)


remainder = [0] * 2019
tmp = 0
for i in range(N):
    r = int(S[i])
    tmp += r*10**(i)
    
    remainder[tmp%2019] += 1
    tmp %= 2019

    
    
remainder[0] += 1
print(-1)




Failing test case input:
5235394296

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):


S = input()[::-1] 
N = len(S)


remainder = [0] * 2019
tmp = 0
rad = 1 
for i in range(N):
    r = int(S[i])
    tmp += r*rad
    tmp %= 2019
    
    remainder[tmp] += 1
    rad *= 10
    rad %= 2019

    
    
remainder[0] += 1




answer = 0
for i in range(2019):
    p = remainder[i]
    answer += p*(p-1)/2
print(int(answer))

Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=input()
n=len(s)
rst=[0 for j in range(2019)]
x=0
ans=0
drst=1
for i in range(n):
    y=int(s[n-1-i])*drst%2019
    drst=(drst*10)%2019
    x+=y
    if x>=2019:
        x%=2019
    
    ans+=rst[x]
    rst[x]+=1
if rst[0]==1:
    ans+=1

print(ans)

Failing test case input:
880430372400

Expected output:
5


Actual output:
3


Fixed submission (verdict: Accepted):
s=input()
n=len(s)
rst=[0 for j in range(2019)]
rst[0]=1
x=0
ans=0
drst=1
for i in range(n):
    y=(int(s[n-1-i])*drst)%2019
    drst=(drst*10)%2019
    x+=y
    if x>=2019:
        x%=2019
    
    ans+=rst[x]
    rst[x]+=1

    

print(ans)
Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
  s=input()[::-1]
  l,mod=len(s),2019
  x=[0]*(l+1)
  x[1]=(int(s[0])*(pow(10,1,mod)))%mod
  for i in range(2,l+1):
    x[i]=((int(s[i-1])*(pow(10,i,mod)))+x[i-1])%mod
  ll=len(set(x))
  print(l-ll+1)
if __name__=='__main__':
  main()

Failing test case input:
649171600089

Expected output:
6


Actual output:
3


Fixed submission (verdict: Accepted):
def main():
  s=input()[::-1]
  l,mod=len(s),2019
  x=[0]*mod
  x[0]=1
  a,t=0,1
  for i in range(l):
    a = (a + int(s[i])*t) % 2019
    x[a]+=1
    t=(t*10)%mod
  ans=sum([i*(i-1)
  print(ans)
if __name__=='__main__':
  main()

Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    ans = 0
    for i in range(0, 200000, 2019):
        ind = -1
        stri = str(i)
        while True:
            ind = S.find(stri, ind + 1)
            if ind >= 0:
                ans += 1
            else:
                break
    print(ans)

if __name__ == '__main__':
    main()


Failing test case input:
2612900314

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    S = input()
    s_list = list(map(int, list(S)))[::-1]
    MOD = 2019

    sum_v = 0
    cnt = [0] * MOD
    cnt[0] = 1
    for i, s in enumerate(s_list):
        sum_v += s * pow(10, i, MOD)
        sum_v %= MOD
        cnt[sum_v] += 1
    print(sum([c * (c - 1) 

if __name__ == '__main__':
    main()

Problem: p02702
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
S = input()
amari = [0]*2019
ans = 0
for i in range(len(S)):
    amari[int(S[len(S)-1-i:]) % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(ans)
    

Failing test case input:
8498035987509

Expected output:
2


Actual output:
2.0


Fixed submission (verdict: Accepted):
S = input()
amari = [0]*2019
ans = 0
amari[0] = 1
A = 0
for i in range(len(S)):
    A += pow(10, i, 2019)*(int(S[len(S)-1-i]))
    amari[A % 2019] += 1
for i in amari:
    if i >= 2:
        ans += i*(i-1)/2
print(int(ans))

Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = str(input())


A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019


X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0


for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += flag*(flag-1)
    flag = 1
print(n)

Failing test case input:
5256140109

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
S = str(input())


A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019


X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0


for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
n += int(flag*(flag-1)/2)
if X[len(X)-1]==0:
  n +=1
print(n)
Problem: p02702
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from sys import stdin

S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)


res_map[N-1] = int(S[N-1])
index=1
for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

res_map.sort()
temp_num=res_map[0]
index=1
tot = 0

for i in range(1,N):
    if temp_num==res_map[i]:
        index+=1
        continue
    else:
        if index==1 and temp_num==0:
            tot+=1
        elif index>1:
            tot += index*(index-1)/2
            
        index=1
        temp_num=res_map[i]





print(int(tot))



Failing test case input:
3054417607960

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
from sys import stdin

S = stdin.readline().rstrip()
N = len(S)
Sp = S

res_map = [0 for _ in range(N)]

aa_list2 = [1]
for i in range(1,N):
    aa_list2.append((aa_list2[i-1]*10)%2019)

res_map[N-1] = int(S[N-1])
index=1


for i in range(N-2,-1,-1):
    res_map[i] = (int(S[i])*aa_list2[index] + res_map[i+1])%2019
    index+=1

aa_table = [0 for i in range(2019)]
for i in range(len(res_map)):
    aa_table[res_map[i]]+=1

aa_table[0]+=1

tot = 0
for i in range(2019):
    tot+=int((aa_table[i]-1)*aa_table[i]/2)

print(tot)

Problem: p02702
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()

n = len(S)

modlist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    mods = mods % 2019
    num = (num + fig * mods) % 2019
    modlist[num] = modlist[num] + 1
    mods = mods * 10

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if n != 0:
        result += m * (m - 1) / 2

print(int(result))

Failing test case input:
880430372400

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
S = input()

n = len(S)

medalist = [0] * 2019
medalist[0] = 1
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * mods) % 2019
    medalist[num] = medalist[num] + 1
    mods = (mods * 10) % 2019

result = 0

for i in range(2019):
    m = medalist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))
Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
INF = float("inf")


def solve(n: int, a: "List[int]"):

    
    tot = 0
    countA = 0
    for i, x in enumerate(a):
        tot += x
        if i % 2 == 0:
            if tot <= 0:
                countA += -tot+1
                tot = 1
        elif i % 2 == 1:
            if tot >= 0:
                countA += tot+1
                tot = -1

    tot = 0
    countB = 0
    for i, x in enumerate(a):
        tot += x
        if i % 2 == 1:
            if tot <= 0:
                countB += -tot+1
                tot = 1
        elif i % 2 == 0:
            if tot >= 1:
                countB += tot+1
                tot = -1
    print(min(countA, countB))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(n)]  
    solve(n, a)


if __name__ == '__main__':
    main()


Failing test case input:
5
55 -1 -1 1 -6

Expected output:
61


Actual output:
59


Fixed submission (verdict: Accepted):

import sys
INF = float("inf")


def solve(n: int, a: "List[int]"):

    
    tot = 0
    countA = 0
    for i, x in enumerate(a):
        tot += x
        if i % 2 == 0:
            if tot <= 0:
                countA += -tot+1
                tot = 1
        else:
            if tot >= 0:
                countA += tot+1
                tot = -1

    tot = 0
    countB = 0
    for i, x in enumerate(a):
        tot += x
        if i % 2 == 1:
            if tot <= 0:
                countB += -tot+1
                tot = 1
        else:
            if tot >= 0:
                countB += tot+1
                tot = -1
    print(min(countA, countB))

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(n)]  
    solve(n, a)


if __name__ == '__main__':
    main()
Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input().strip())
A = list(map(int, input().strip().split(" ")))

s = A[0]
count = 0

if s == 0:
    if n == 1:
        count += 1
    else:
        count += 1
        if A[1] > 0:
            s = -1
        else:
            s = 1

for a in A[1:]:
    prev = s
    sign = prev > 0
    s += a
    if s == 0:
        count += 1
        if sign: 
            s = -1
        else: 
            s = 1
    elif sign == (s > 0): 
        count += abs(s)+1
        if s > 0:
            s = -1
        else:
            s = 1
    else:
        pass

print(count)


Failing test case input:
5
40 -1 -1 1 -5

Expected output:
46


Actual output:
53


Fixed submission (verdict: Accepted):
n = int(input().strip())
A = list(map(int, input().strip().split(" ")))

def solver(_sign):
    s = A[0]
    count = 0

    if _sign:
        if s <= 0: 
            count += abs(s) + 1
            s = 1
    else:
        if s >= 0: 
            count += abs(s) + 1
            s = -1

    for a in A[1:]:
        prev = s
        sign = prev > 0
        s += a
        if s == 0:
            count += 1
            if sign: 
                s = -1
            else: 
                s = 1
        elif sign == (s > 0): 
            count += abs(s)+1
            if s > 0:
                s = -1
            else:
                s = 1
        else:
            pass
    return count

print(min(solver(True), solver(False)))

Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A2 = list(map(int,input().split()))



def getSign(a):
	if a < 0:
		return -1
	elif a == 0:
		return 0
	else:
		return 1

counts = []
for j in range(2):
	A = list(A2)
	count = 0
	sumN = A[0]
	beforeSign = getSign(A[0])
	
	if j == 0:
		add = -A[0] - beforeSign
		A[0] += add
		count += abs(add)
	
	for i in range(1,N):
		sumN += A[i]

		

		if 0 <= beforeSign * sumN:
			add = -sumN - beforeSign
			A[i] += add
			sumN += add
			count += abs(add)
		
		beforeSign = getSign(sumN)
		
	
	counts.append(count)
	
print(min(counts))

Failing test case input:
5
40 -1 -1 1 -5

Expected output:
46


Actual output:
53


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



def getSign(a):
	if a < 0:
		return -1
	elif a == 0:
		return 0
	else:
		return 1

counts = []
for beforeSign in [-1,1]:
	count = 0
	sumN = 0
	for i in range(N):
		sumN += A[i]

		

		if 0 <= beforeSign * sumN:
			add = -sumN - beforeSign
			sumN += add
			count += abs(add)
		
		beforeSign = getSign(sumN)
		
	
	counts.append(count)
	
print(min(counts))
Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = list(map(int,input().split()))
def func(list1,op,acc = 0,count = 0):
    for i in range(n):
        acc += list1[i]
        if i % 2 == 1 and acc * op >= 0:
            count += op * acc + 1
            acc = -op
        elif i % 2 == 0 and acc * op <= 0:
            count += -op * acc + 1
            acc = op
    if acc == 0:
        count += 1
    return count
if A[0] > 0:
    ans = func(A,1)
elif A[0] < 0:
    ans = func(A,-1)
elif A[0] == 0:
    ans = min(func(A,1),func(A,-1))
print(ans)

Failing test case input:
5
40 -1 -1 1 -5

Expected output:
46


Actual output:
53


Fixed submission (verdict: Accepted):
n = int(input())
A = list(map(int,input().split()))
def func(list1,op,acc = 0,count = 0):
    for i in range(n):
        acc += list1[i]
        if i % 2 == 1 and acc * op >= 0:
            count += op * acc + 1
            acc = -op
        elif i % 2 == 0 and acc * op <= 0:
            count += -op * acc + 1
            acc = op
    if acc == 0:
        count += 1
    return count
ans = min(func(A,1),func(A,-1))
print(ans)

Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())

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

kp=0
asum=0
flag=-1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            kp=kp+asum+1
            asum=-1
    else:
        if asum<=0:
            kp=kp+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",kp)            
km=0
asum=0
flag=1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            km=km+asum+1
            asum=-1
    else:
        if asum<=0:
            km=km+1-asum
            asum=1
    flag=-flag
    print(asum)
print("-----",km)            

print(min(kp,km))
        

Failing test case input:
6
0 8 0 2 -5 -1

Expected output:
15


Actual output:
-1
7
-1
1
-4
1
----- 15
1
-1
1
-1
1
-1
----- 25
15


Fixed submission (verdict: Accepted):
n=int(input())

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

kp=0
asum=0
flag=-1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            kp=kp+asum+1
            asum=-1
    else:
        if asum<=0:
            kp=kp+1-asum
            asum=1
    flag=-flag


km=0
asum=0
flag=1
for i in range(n):
    asum=asum+a[i]
    if flag==-1:
        if asum>=0:
            km=km+asum+1
            asum=-1
    else:
        if asum<=0:
            km=km+1-asum
            asum=1
    flag=-flag



print(min(kp,km))
Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
l = len(a)
b = []
for i in range(l):
  b.append(a[i])
  
ans = 0
Ans = 0
summary = a[0]

if(summary == 0):
  a[0] = 1
  ans+= 1
  b[0] = -1
  Ans+= 1
else:
  b[0] = int(-a[0]/ abs(a[0]))
  Ans+= abs(a[0]- b[0])

Summary = b[0]  
  
for i in range(1, l):
  if(summary* (summary+ a[i])>= 0):
    if(summary > 0):
      ans+= a[i]+ summary+ 1
      a[i] = -summary- 1 
      summary= -1
    else:
      ans+= -summary+ 1- a[i]
      a[i] = -summary+ 1
      summary= 1
  else:
    summary+= a[i]

for i in range(1, l):
  if(Summary* (Summary+ b[i])>= 0):
    if(Summary > 0):
      Ans+= b[i]+ Summary+ 1
      b[i] = -Summary- 1 
      Summary= -1
    else:
      Ans+= -Summary+ 1- b[i]
      b[i] = -Summary+ 1
      Summary= 1
  else:
    Summary+= b[i]
    
print(min(ans, Ans))
print(a, b)

Failing test case input:
6
9 -1 -7 1 -1 0

Expected output:
22


Actual output:
22
[9, -10, 2, -2, 2, -2] [-1, 2, -7, 7, -2, 2]


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
l = len(a)
b = []
for i in range(l):
  b.append(a[i])
  
ans = 0
Ans = 0
summary = a[0]

if(summary == 0):
  summary = 1
  ans+= 1
  Summary = -1
  Ans+= 1
else:
  b[0] = int(-a[0]/ abs(a[0]))
  Ans+= abs(a[0]- b[0])
  Summary = b[0]  
  
for i in range(1, l):
  if(summary* (summary+ a[i])>= 0):
    if(summary > 0):
      ans+= a[i]+ summary+ 1
      a[i] = -summary- 1 
      summary= -1
    else:
      ans+= -summary+ 1- a[i]
      a[i] = -summary+ 1
      summary= 1
  else:
    summary+= a[i]

for i in range(1, l):
  if(Summary* (Summary+ b[i])>= 0):
    if(Summary > 0):
      Ans+= b[i]+ Summary+ 1
      b[i] = -Summary- 1 
      Summary= -1
    else:
      Ans+= -Summary+ 1- b[i]
      b[i] = -Summary+ 1
      Summary= 1
  else:
    Summary+= b[i]
    
print(min(ans, Ans))

Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
s = A[0]
ans = 0

for k in range(1,N):
    if s*(s+A[k])<=-1:
        s += A[k]
    else:
        if s > 0:
            if s + A[k] >= 0:
                ans += s + A[k] + 1
                s = -1
        elif s < 0:
            if s + A[k] <= 0:
                ans += 1 - s - A[k]
                s = 1
print(ans)

Failing test case input:
6
0 1 2 -1 -2 -1

Expected output:
10


Actual output:
0


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

s = 0
ans1 = 0
for k in range(N):
    s += A[k]
    if k%2==0:
        if s <= 0:
            ans1 += -s+1
            s = 1
    else:
        if s >= 0:
            ans1 += s+1
            s = -1

s = 0
ans2 = 0
for k in range(N):
    s += A[k]
    if k%2==0:
        if s >= 0:
            ans2 += s+1
            s = -1
    else:
        if s <= 0:
            ans2 += -s+1
            s = 1

print(min(ans1,ans2))
Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

result = []

for i in range(1):
    num = 0
    r = 0
    for j in range(len(a)):
        num += a[j]
        if (j + i) % 2 == 0:
            if num <= 0:
                r -= num - 1
                num = 1

        else:
            if num >= 0:
                r += num + 1
                num = -1

    result.append(r)

print(min(result))


Failing test case input:
5
35 -1 -1 1 -2

Expected output:
41


Actual output:
45


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

result = []

for i in range(2):
    num = 0
    r = 0
    for j in range(len(a)):
        num += a[j]
        if (j + i) % 2 == 0:
            if num <= 0:
                r -= num - 1
                num = 1

        else:
            if num >= 0:
                r += num + 1
                num = -1

    result.append(r)

print(min(result))

Problem: p03739
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
ans = 0

while a[0] == 0:
    if a[1] > 0:
        a[0] = -1
    elif a[1] < 0:
        a[0] = 1
    else:
        a.pop(0)
    ans += 1

if a[0] < 0:
    a = list(map(lambda x: x * (-1), a))

product = 0

for i in range(len(a)):
    product += a[i]

    if i % 2 == 0:
        if product <= 0:
            ans += abs(product) + 1
            product = 1

    elif i % 2 == 1:
        if product >= 0:
            ans += abs(product) + 1
            product = -1

print(ans)


Failing test case input:
5
113 -1 -1 1 -2

Expected output:
119


Actual output:
123


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
_a = list(map(lambda x: x * (-1), a))


def func(l: list):
    _ans = 0
    product = 0
    for i in range(n):
        product += l[i]

        if i % 2 == 0:
            if product <= 0:
                _ans += abs(product) + 1
                product = 1

        elif i % 2 == 1:
            if product >= 0:
                _ans += abs(product) + 1
                product = -1
    return _ans

ans = min(func(a), func(_a))
print(ans)
Problem: p03363
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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
for num in kosuu:
    if num <= 1:
        ans += 0
    else:
        ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))
print(ans)

Failing test case input:
6
-1 1 -3 2 1 -3

Expected output:
5


Actual output:
8.0


Fixed submission (verdict: Accepted):
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)
        
for num in kosuu:
    if num <= 1:
        ans += 0
    else:
        ans += math.factorial(num)/(math.factorial(2) * math.factorial(num-2))
print(int(ans))

Problem: p03363
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_list = [0]
memo_dict = {}
for i in range(0,n):
    memo += list_a[i]
    memo_list.append(memo)
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))


Failing test case input:
7
0 -2 2 -4 0 0 1

Expected output:
6


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
list_a = list((map(int, input().split())))
memo = 0
memo_dict = {0:1}
for i in range(0,n):
    memo += list_a[i]
    if memo in memo_dict:
        memo_dict[memo] += 1
    else:
        memo_dict[memo] = 1
ans = 0
for number in memo_dict.values():
    ans += number * (number-1) / 2
print(int(ans))
Problem: p03363
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]
ca = [A[0]] + [0]*(N-1)

for i in range(1,N):
    ca[i] = ca[i-1] + A[i]

count = 0
for i in list(set(ca)):
    if i == 0:
        count += sum([1 if j == 0 else 0 for j in ca])
    number = sum([1 if j == i else 0 for j in ca])
    count += number * (number-1) /2


print(count)

Failing test case input:
7
0 -2 2 -4 0 0 0

Expected output:
9


Actual output:
9.0


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]
ca = [A[0]] + [0]*(N-1)

for i in range(1,N):
    ca[i] = ca[i-1] + A[i]

count = 1
number = 0
number += ca.count(0)
sca = sorted(ca) + ['hoge']
for i in range(1,N+1):
    if sca[i] == sca[i-1]:
        count += 1
    else:
        number += count*(count - 1)/2
        count = 1


print(int(number))

Problem: p03363
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
import math
n = int(input())
a = list(map(int,input().split()))
 
s = []

tem = 0
s.append(tem)
for i in range(n):
    tem += a[i]
    s.append(tem)
    
b = Counter(s)
c = b.values()

ans = 0
for i in c:
    if i != 1:
        ans += math.factorial(i-1)
        
print(ans)

Failing test case input:
7
0 -2 2 -11 0 0 0

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
from collections import Counter
import math
n = int(input())
a = list(map(int,input().split()))
 
s = []

tem = 0
s.append(tem)
for i in range(n):
    tem += a[i]
    s.append(tem)
    
b = Counter(s)
c = b.values()

ans = 0
for i in c:
    ans += (i*(i-1)
        
print(ans)
Problem: p03363
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
L=list(map(int,input().split()))
N=200000
L=[i for i in range(N)]
Left=[[0,0]]
Right=[[0,N]]
for i in range(N):
    Left.append([Left[i][0]+L[i],i+1])
for i in range(N):
    Right.append([Right[i][0]+L[i*(-1)-1],N-i-1])
Right=list(reversed(Right))
Left=sorted(Left, key=lambda x: x[0])
_sum_=Right[0][0]
Left=sorted(Left, key=lambda x: x[0],reverse=True)
Right=sorted(Right, key=lambda x: x[0])
Left.append([0,0])
Right.append([0,0])

j=0
s=0
ans=0
for i in range(N+1):
    if i != 0:
        if Left[i][0]!=Left[i-1][0]:
            s=0
    while(Left[i][0]+Right[j][0]<_sum_ and j<=N):
        j+=1
    if j>N:
        break
    elif Left[i][0]+Right[j][0]>_sum_:
        continue
    else:
        while(Left[i][0]+Right[j][0]==_sum_ and j<=N):
            if Left[i][1]>=Right[j][1]:
                j+=1
            else:
                s+=1
                ans+=s
                break
print(ans)

Failing test case input:
6
1 3 -2 2 0 -4

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
N=int(input())
L=list(map(int,input().split()))
Left=[[0,0]]
Right=[[0,N]]
for i in range(N):
    Left.append([Left[i][0]+L[i],i+1])
for i in range(N):
    Right.append([Right[i][0]+L[i*(-1)-1],N-i-1])
Right=list(reversed(Right))
Left=sorted(Left, key=lambda x: x[0])
_sum_=Right[0][0]
Left=sorted(Left, key=lambda x: x[0],reverse=True)
Right=sorted(Right, key=lambda x: x[0])
Left.append([0,0])
Right.append([0,0])
 
j=0
s=0
ans=0
for i in range(N+1):
    if i != 0:
        if Left[i][0]!=Left[i-1][0]:
            s=0
    while(Left[i][0]+Right[j][0]<_sum_ and j<=N):
        j+=1
    if j>N:
        break
    elif Left[i][0]+Right[j][0]>_sum_:
        continue
    else:
        while(Left[i][0]+Right[j][0]==_sum_ and j<=N):
            if Left[i][1]>=Right[j][1]:
                j+=1
            else:
                s+=1
                ans+=s
                break
print(ans)

Problem: p03363
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


n = int(input())
s = list(map(int, input().split()))
for i in range(1, n):
    s[i] += s[i-1]

ans = 0
print(s)
s = sorted(s)
print(s)
i = 0
while True:
    mid = 0
    for j in range(i+1, n):
        if s[j] == s[i]:
            mid += 1
            ans += mid
        else:
            break
    if s[i] == 0:
        ans += mid+1
    i += mid
    i += 1
    if i >= n:
        break
print(ans)

Failing test case input:
5
0 0 3 1 8

Expected output:
3


Actual output:
[0, 0, 3, 4, 12]
[0, 0, 3, 4, 12]
3


Fixed submission (verdict: Accepted):


n = int(input())
s = list(map(int, input().split()))
for i in range(1, n):
    s[i] += s[i-1]

ans = 0
s = sorted(s)
i = 0
while True:
    mid = 0
    for j in range(i+1, n):
        if s[j] == s[i]:
            mid += 1
            ans += mid
        else:
            break
    if s[i] == 0:
        ans += mid+1
    i += mid
    i += 1
    if i >= n:
        break
print(ans)