Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = input()
S,T = input().split()

a = []
for i in range(N):
  a.append(S[i])
  a.append(T[i])
print(a)

Fixed submission:
N = int(input())
S,T = input().split()
 
a = ""
for i in range(N):
  a+=S[i]+T[i]
print(a)
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = input().split()
for i in range(N):
  a[i] = int(a[i])
index = 1
count = 0
for i in range(N):
  if a[i] = index:
  	index += 1
  else:
    count += 1
print(count)

Fixed submission:
N = int(input())
a = input().split()
for i in range(N):
  a[i] = int(a[i])
index = 1
count = 0
for i in range(N):
  if a[i] == index:
  	index += 1
  else:
    count += 1
if count == N:
  count = -1
print(count)
Buggy python submission (verdict: Runtime Error):
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

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

print(lcm(a, b))

Fixed submission:
a = int(input())
b = int(input())
l = list(range(4))
del l[0]
l.remove(a)
l.remove(b)
print(l[0])
Buggy python submission (verdict: Runtime Error):
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y

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

print(lcm(a, b))

Fixed submission:
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

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

print(lcm(a, b))

Buggy python submission (verdict: Runtime Error):
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y

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

print(lcm(a, b))

Fixed submission:
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

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

print(lcm(a, b))

Buggy python submission (verdict: Runtime Error):
import math
a,b = list(map(int, input().split()))

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

print(lcm(a, b))

Fixed submission:
import math
a,b = list(map(int, input().split()))

def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

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

print(lcm(a, b))
Buggy python submission (verdict: Runtime Error):
print(6-int(input()-int(input()))

Fixed submission:
print(6-int(input())-int(input()))
Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
   tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)
    
A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))




Fixed submission:
def gcd(x,y):
    tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)

A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))

Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
   tmp = x
    x = x if x >= y else x=y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)
    
A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(lcm(A,B))



Fixed submission:
def gcd(x,y):
    tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)

A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))

Buggy python submission (verdict: Runtime Error):
def gcd(x,y):
   tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)
    
A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(lcm(A,B))




Fixed submission:
def gcd(x,y):
    tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)

A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))

Buggy python submission (verdict: Runtime Error):
import math
A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(lcm(A,B))

Fixed submission:
def gcd(x,y):
    tmp = x
    x = x if x >= y else y
    if tmp != x:
        y = tmp
    if y == 0:
        return x
    return gcd(x%y, y)

A,B =  [int(x) for x in input().split(" ")]
def lcm(x, y):
    return (x * y) // gcd(x, y)
print(lcm(A,B))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
wa = a + b
sa = a - b
seki = a * b
if wa > sa and wa > seki:
    print(wa)
    break
elif sa > wa and sa > seki:
    print(sa)
    break
else:
    print(seki)


Fixed submission:
a, b = map(int, input().split())
wa = a + b
sa = a - b
seki = a * b
s = [a + b, a - b, a * b]
print(max(s))
Buggy python submission (verdict: Runtime Error):
s = input()
for w in s:
    a = s.index(w)
    if w == s[a+1]:
        print("Bad")
        break
    else:
        continue
else:
    print("Good")


Fixed submission:
s = input()
for w in range(3):
    if s[w] == s[w+1]:
        print("Bad")
        break
    else:
        continue
else:
    print("Good")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a <= b:
    print(a)
else:
    ptiny(a-1)


Fixed submission:
a, b = map(int, input().split())
if a <= b:
    print(a)
else:
    print(a-1)
Buggy python submission (verdict: Runtime Error):
s = input()
a = 700
for i in s:
    if i == o:
        a += 100
    if i == x:
        continue
print(a)


Fixed submission:
s = input()
a = 700
for i in s:
    if i == "o":
        a += 100
    if i == "x":
        continue
print(a)
Buggy python submission (verdict: Runtime Error):
r, g, b = map(int, input().split())
a = 100 * r + 10 * g + b
if a % 4 = 0:
    print("YES")
else:
    print("NO")


Fixed submission:
r, g, b = map(int, input().split())
a = 100 * r + 10 * g + b
if a % 4 == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
a, b = input(),split()
if a == b:
    print("H")
else:
    print("D")


Fixed submission:
a, b = input().split()
if a == b:
    print("H")
else:
    print("D")
Buggy python submission (verdict: Runtime Error):
def when_sunday(day):
    week_d = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
    if day == "SUN":
        return 7
    return 6 - week_d.index(day)
  

print(when_sunday(input())

Fixed submission:
def when_sunday(day):
    week_d = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
    if day == "SUN":
        return 7
    return 6 - week_d.index(day)
  
print(when_sunday(input()))
Buggy python submission (verdict: Runtime Error):
a, b = map(int(input().split()))

valid = range(1, 10)
if a in valid and b in valid:
  print(a*b)
else:
  print(-1)

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

valid = range(1, 10)
if a in valid and b in valid:
    print(a*b)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())

def min_walk(n):
    out = []
    for a in range(1, int(n**0.5)):
        if n % a == 0:
            out.append(a + (n//a) - 2)

    return min(out)


print(min_walk(n))

Fixed submission:
n = int(input())

def min_walk(n):
    out = []
    for a in range(1, int(n**0.5)+1):
        if n % a == 0:
            out.append(a + (n//a) - 2)

    return min(out)


print(min_walk(n))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

def find(target, list):
    for i in range(len(list)):
        if list[i] == target:
            return i+1

out = []
for j in range(1, n+1):
    out.append(find(j, a))

print(" ".join(map(str, out)))


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

out = sorted(range(1, len(a)+1 ), key=lambda i: a[i-1])
print(" ".join(map(str, out)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

out = [a.index(s)+1 for s in range(1, n+1)]
print(" ".join(map(str, out)))


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

out = sorted(range(1, len(a)+1 ), key=lambda i: a[i-1])
print(" ".join(map(str, out)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for s in range(1, n+1):
    print(a.index(s) + 1, end=" ")


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

out = sorted(range(1, len(a)+1 ), key=lambda i: a[i-1])
print(" ".join(map(str, out)))
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

players = [k for _ in range(n)]

for i in a:
    for p in range(len(players)):
        if p != i-1:
            players[p] -= 1

for p in players:
    if p > 0:
        print("Yes")
    else:
        print("No")


Fixed submission:
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

players = [k-q for _ in range(n)]

for i in a:
    players[i-1] += 1

for p in players:
    if p > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))

for _ in range(m):
    a[a.index(max(a))] = a[a.index(max(a))] // 2

print(sum(a))


Fixed submission:
import heapq

n, m = map(int, input().split())
a = []
for i in list(map(int, input().split())):
    heapq.heappush(a, -i)

for _ in range(m):
    p = heapq.heappop(a)
    heapq.heappush(a, int(p/2))

print(-sum(a))
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

print(s[1])

Fixed submission:
s = input()
k = int(input()) - 1


for i in range(len(s)):
    if s[i] != "1" or i == k:
        break

print(s[i])
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median

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

def naive(x):
    return [median(x[:i] + x[i+1:]) for i in range(len(x))]

for i in naive(x):
    print(i)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))

y = sorted(x)
a = y[len(x)//2]
b = y[(len(x)//2) - 1]

for i in range(n):
    if x[i] <= b:
        print(a)
    else:
        print(b)

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

def naive(x):
    return [median(x[:i] + x[i+1:]) for i in range(len(x))]
  
for i in naive(x):
  print(i)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))

y = sorted(x)
a = y[len(x)//2]
b = y[(len(x)//2) - 1]

for i in range(n):
    if x[i] <= b:
        print(a)
    else:
        print(b)

Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median

test = [0, 1, 2, 3, 4, 5]

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

for i in range(len(x)):
    print(median(x[:i] + x[i+1:]))


Fixed submission:
n = int(input())
x = list(map(int, input().split()))

y = sorted(x)
a = y[len(x)//2]
b = y[(len(x)//2) - 1]

for i in range(n):
    if x[i] <= b:
        print(a)
    else:
        print(b)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]

words = [w for w in s if w[0] in "MARCH"]

cnt = 0
for i in combinations(words, 3):
    if i[0][0] != i[1][0] and i[1][0] != i[2][0] and  i[0][0] != i[2][0]:
        cnt += 1

print(cnt)


Fixed submission:
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]

letters = {"M":0, "A":0, "R":0, "C":0, "H":0, }
to_check = combinations([i for i in "MARCH"], 3)

for word in s:
    if word[0] in letters:
        letters[word[0]] += 1

count = 0
for i in to_check:
    count += letters[i[0]] * letters[i[1]] * letters[i[2]]

print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())

sum = int(n[0]) + (len(n)-1) * 9
print(sum if set(n[1:]) == {"9"} else sum - 1)


Fixed submission:
n = input()

sum = int(n[0]) + (len(n)-1) * 9

if len(n) == 1:
    print(n)
else:
    print(sum if set(n[1:]) == {"9"} else sum - 1)
Buggy python submission (verdict: Runtime Error):
    n = int(input())
    pos = [list(map(int, input().split())) for _ in range(n)]
     
    def func(n, pos):
        c_t, c_x, c_y = 0, 0, 0
     
        for i in pos:
            d_t = i[0] - c_t
            z = abs(i[1] - c_x) + abs(i[2] - c_y)
     
            if z > d_t or (d_t - z) % 2 != 0:
                return "No"
            else:
                c_t, c_x, c_y = 0, 0, 0
     
        return "Yes"
     
     
    print(func(n, pos))

Fixed submission:
n = int(input())
pos = [list(map(int, input().split())) for _ in range(n)]

def func(n, pos):
    c_t, c_x, c_y = 0, 0, 0

    for i in pos:
        d_t = i[0] - c_t
        z = abs(i[1] - c_x) + abs(i[2] - c_y)

        if z > d_t or (d_t - z) % 2 != 0:
            return "No"
        else:
            c_t, c_x, c_y = i[0], i[1], i[2]

    return "Yes"


print(func(n, pos))
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

for i in set(pot_starts):
    if i in pot_ends:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(pot_ends):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

potential_ends =   [i[0] for i in a if i[1] == n]
potential_starts = [i[1] for i in a if i[0] == 1]

for p in potential_starts:
    if p in potential_ends:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(pot_ends):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

potentials = [i for i in a if i[1] == n]

for p in potentials:
    if [1, p[0]] in a:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")


Fixed submission:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

# n, m = 3, 2
# a = [[1, 2], [2, 3]]

pot_starts = []
pot_ends = []

for i in a:
    if i[0] == 1:
        pot_starts.append(i[1])
    elif i[1] == n:
        pot_ends.append(i[0])

if set(pot_starts).intersection(pot_ends):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()

b = []

for i in a:
    b.append(i)
    b.reverse()

print(" ".join(b))


Fixed submission:
n = 4
a = [1, 2, 3, 4]

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


if n % 2 == 0:
    y = [a[j] for j in range(1, n, 2)][::-1]
    z = [a[j] for j in range(0, n, 2)]

else:
    y = [a[j] for j in range(0, n, 2)][::-1]
    z = [a[j] for j in range(1, n, 2)]

print(" ".join(map(str, y + z)))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")


Fixed submission:
a = int(input())
b = int(input())

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")

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

if a > b:
	print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")


Fixed submission:
a = int(input())
b = int(input())

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")

Buggy python submission (verdict: Runtime Error):
a, b = map(int(input().split())
           
if a > b:
	print("GREATER")
elif a < b: 
    print("LESS")
elif a == b:
    print("EQUAL")



Fixed submission:
a = int(input())
b = int(input())

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
elif a == b:
    print("EQUAL")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

f = 1
for i in range(1, n+1):
    f *= i

print(f % (10**9+7))
    

Fixed submission:
import math

n = int(input())

print(math.factorial(n) % (10**9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = min(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)


Fixed submission:
n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = max(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = 2

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)


Fixed submission:
n = int(input())
votes = [list(map(int, input().split())) for _ in range(n)]

curr_a, curr_b = 0, 0

for v1, v2 in votes:
    a, b = v1, v2
    i = max(curr_a // v1, curr_b // v2)

    while a < curr_a or b < curr_b:
        a = v1 * i
        b = v2 * i
        i += 1

    curr_a, curr_b = a, b

print(curr_a + curr_b)
Buggy python submission (verdict: Runtime Error):
a, b, c, = map(int(input().split()))
h = [5, 5, 7]
b = [a, b, c]

if sorted(h) == sorted(b):
    print("YES")
else:
    print("NO")


Fixed submission:
a, b, c, = map(int, input().split())
h = [5, 5, 7]
b = [a, b, c]

if sorted(h) == sorted(b):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    A, B = [int(_) for _ in input().split()]

    product = A * B
    for divisor in range(min([A, B]) // 2, 2, -1):
        if A % divisor == 0 and B % divisor == 0:
            A = A // divisor
            B = B // divisor
            product = product // divisor

    print(product)


def correct_1():
    A, B = [int(_) for _ in input().split()]

    for i in range(1, B + 1):
        if A * i % B == 0:
            print(A * i)
            break


def correct_2():
    A, B = [int(_) for _ in input().split()]

    def gcd(a, b):
        while b != 0:
            a, b = b, a % b
        return a

    def lcm(a, b):
        return a * b // gcd(a, b)

    print(lcm(A, B))


if __name__ == "__main__":
    correct_1()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    A = int(input())
    B = int(input())

    print('{}'.format(6 - A - B))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def main():
    A, B = [int(_) for _ in input().split()]

    product = A * B
    for divisor in range(min([A, B]) // 2, 1, -1):
        if A % divisor == 0 and B % divisor == 0:
            A = A // divisor
            B = B // divisor
            product = product // divisor

    print(product)


if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    A = int(input())
    B = int(input())

    print('{}'.format(6 - A - B))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, M = li_input()
    A = li_input()

    ans = 0

    cumsum = [0]
    c_sum = 0
    for a in A:
        c_sum += a
        cumsum.append(c_sum)

    for r in range(1, len(cumsum)):
        for l in range(r):
            if (cumsum[r] - cumsum[l]) % M == 0:
                ans += 1

    print(ans)


main()


Fixed submission:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


# --------------------------------------------

dp = None


def main():
    N, M = li_input()
    A = li_input()

    ans = 0
    d = collections.defaultdict(lambda: 0)

    cumsum = [0]
    c_sum = 0
    for a in A:
        c_sum = (c_sum + a) % M
        cumsum.append(c_sum)

    for c in cumsum:
        d[c] += 1

    for v in d.values():
        if v >= 2:
            ans += v * (v - 1) // 2

    print(ans)


main()