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()
ans = 0
if int(s) < 2019 :
  print(0)
else:
  for i in range(len(s)-3):
    for j in range(4,len(s)):
      a =s[i:j+1]
      if int(a) % 2019 == 0:
        ans += 1
        
print(ans)

s = input()
L = [s[i] for i in range(len(s))]
ans = 0

for j in range(0,len(L)-3):
  for k in range(3,len(L)):
    a = int(L[j:k+1])
    if a % 2019 == 0:
      ans += 1
print(ans)
               


s = input()
ans = 0
S =[]
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    S.append(a)
sa = set(S)
for i in range(len(se)):
  if int(sa[i]) % 2019 == 0:
    ans += 1

print(ans)


s = input()
ans = 0
for i in range(0,len(s)-3):
  for j in range(3,len(s)):
    a = int(s[i:j+1])
    if a % 2019 == 0:
      ans += 1
print(ans)
               


s = input()
ans = 0

for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    if int(a) % 2019 == 0:
      ans += 1

print(ans)


s = input()
ans = 0
sss = []
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    sss.append(a)
    
sssss = set(sss)
for i in sssss:
  if int(sssss[i]) % 2019 == 0:
    ans += 1
      
      
print(ans)


s = input()
ans = 0
L = [2019*k for k in range(10*10)]
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    if int(a) in L and int(a) != 0:
      ans += 1

print(ans)


s = input()
ans = 0

for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j]
    if int(a) % 2019 == 0:
      ans += 1

print(ans)


s = input()
ans = 0
for i in range(len(s)):
  for j in range(len(s)):
  a = s[i:i+j]
  if int(a) % 2019 == 0:
    ans += 1

print(ans)

s = input()
ans = 0

for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j]
    if int(a) % 2019 == 0:
      ans += 1

print(ans)


s = input()
ans = 0
af = 0
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+3]
    if len(a) <= 200000:
      af = 0
    else int(a) % 2019 == 0:
      ans += 1

print(ans)


s = input()
ans = 0
if int(s) < 2019:
  print(0)
else:
  for i in range(len(s)):
    for j in range(len(s)):
      a = s[i:i+j+2]
      if int(a) % 2019 == 0:
        ans += 1
  print(ans)



s = input()
ans = 0
for i in range(0,len(s)-2):
  for j in range(3,len(s)+1):
    a = s[i:j+1]
    if a%2019 == 0:
      ans += 1
print(ans)
               


s = input()
ans = 0

for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    if int(a) % 2019 == 0 and len(a) >= 4:
      ans += 1

print(ans)


def main():
    S = input()
    u = 0
    H = [0] * 2019
    H[0] = 1
    m = 1
    r = 0
    for s in reversed(S):
        u = (u + m * int(s)) % 2019
        r += H[u]
        H[u] += 1
        m = (m * 10) % 2019
    return r


print(main())


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted