Problem: Given is a string S consisting of digits from `1` through `9`.  Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:  Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Submission attempts (in order):
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 1
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

s = input()
a = int(s)
mod_N = [0]*2019
mod_N[a%2019] += 1
for i in range(len(s)):
  a = a-int(s[i])*10**(len(s)-i-1)
  mod_N[a%2019] += 1
ans = 0
for i in mod_N:
  ans += mod_N[i]*(mod_N[i]-1)//2
print(ans)


s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

s = input()
a = int(s)%2019
mods = [0]*2019
mods[a] += 1
d = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*d)%2019
  d = d//10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in range(len(s)):
  a = (a-int(s[i])*10**r)%2019
  r = r//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

s = input()
a = int(s)
mod_N = [0]*2019
mod_N[a%2019] += 1
for i in range(len(s)):
  a = a-int(s[i])*10**(len(s)-i-1)
  mod_N[a%2019] = 1
ans = 0
for i in mod_N:
  ans += mod_N[i]*(mod_N[i]-1)//2
print(ans)


s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in range(len(s)):
  a = (a-int(s[i])*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(i*(i-1)/2)
print(ans)

s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*10**r)%2019
  r = r//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

S = input()
ans = 0
for i in range(6, int(S)//2019 + 1):
  d = str(2019*i)
  ans += S.count(d)
print(ans)


s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

S = input()
ans = 0
for i in range(int(S)//2019 + 1):
  d = str(2019*i)
  ans += S.count(d)
print(ans)

S = input()
ans = 0
for i in range(6, int(S)//2019 + 1):
  d = str(2019*i)
  if "0" in d:
    continue
  ans += S.count(d)
print(ans)


s = input()
a = int(s)%2019
mods = [0]*2019
mods[a] += 1
d = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*d)%2019
  d = d//10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Time Limit Exceeded

Wrong Answer

Runtime Error

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Accepted