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):
import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

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
 
print(n)

import sys
lines = sys.stdin.readlines()

S = str(lines[0])


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)//2
    flag = 1
print(n)

import sys
lines = sys.stdin.readlines()

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

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

X.sort()


import sys

lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

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

import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

a = 0
for i in range(len(S)):
  a += int(S[len(S)-1-i])*10**i %2019
print(X)


import sys
import math
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)

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
 
print(n)


import sys
lines = sys.stdin.readlines()

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

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)//2
    flag = 1
 
print(n)
    



import sys
lines = sys.stdin.readlines()

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

a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019


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

    



import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)

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)//2
    flag = 1
 
print(n)


import sys
lines = sys.stdin.readlines()

S = str(lines[0])


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])) %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)//2
    flag = 1
print(n)

import sys
lines = sys.stdin.readlines()

S = 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)//2
    flag = 1
print(n)

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)/2
    flag = 1
print(n)

import sys
lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-(a//2019)*2019
  X.append(c)
print(c)

import sys
lines = sys.stdin.readlines()

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

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)//2
    flag = 1
print(n)
    



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)//2
    flag = 1
    



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)):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
if X[len(X)-1]==0:
  n +=1
print(n)


import sys

lines = sys.stdin.readlines()

S = str(lines[0])
X = []

for i in range(len(S)):
  a = int(S[i:])
  c = a-int(a/2019)*2019
  X.append(c)

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 = flag +1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
 
print(n)

import sys
lines = sys.stdin.readlines()

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

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)//2
    flag = 1
 
print(n)
    




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)//2
    flag = 1
print(n)
    



import sys
lines = sys.stdin.readlines()

S = str(lines[0])


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)-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)//2
    flag = 1
print(n)

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)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted