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):
number = str(input())[::-1]
remainderDictionary = {}
    
sum = 0
x = 1
for i in number:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x = (x * 10) % 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

S = str(input())
remainderDictionary = {}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x *= 10
  x %= 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

string = input()

pairs = 0
limit = len(string)-3
secondLimit
for i in range(limit):
  substring += string[i]
  for j in range(i+1,secondLimit):
    substring += string[j]
    if j-i > 3 and int(substring) % 673 == 0:
      n += 1
  substring = ''
print(n)

string = str(input())
  n = 0
  limit = len(string)-4
  secondLimit = len(string)
  size = len(string)-1
  potencys = [0] * 1500 
  potencys.append(1)
  thirdLimit = size
  for i in range(size, 2, -1):
    intValue = int(string[i])
    potencyIndex = 0
    thirdLimit = i - 1
    for j in range(thirdLimit, -1, -1):
      potencyIndex += 1
      if potencyIndex >= len(potencys):
        potencys.append(potencys[-1]*10)
      intValue += int(string[j])* potencys[potencyIndex]
      if i-j > 2 and intValue % 673 == 0:
        n += 1
  print(n)

string = str(input())

pairs = 0
limit = len(string)-4
secondLimit = len(string)
substringArray = list()
substringArray.append(string[0])
for i in range(1, secondLimit):
  substringArray.append(substringArray[i-1] + string[i])

for i in range(0,limit):
  for j in range(i+3,secondLimit):
    print(substringArray[j][i:])
    if j >= 3 and int(substringArray[j][i:]) % 673 == 0:
      pairs += 1
print(pairs)

S = str(input())
remainderDictionary = {}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderDictionary[remainder] += remainderDictionary.get(remainder,0) + 1
  x = (x * 10) % 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

S = str(input())
remainderDictionary = {0: 1}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x *= 10
  x %= 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

string = str(input())
n = 0
limit = len(string)-4
secondLimit = len(string)
size = len(string)-1
potencys = [0] * 1500 
potencys.append(1)
thirdLimit = size
for i in range(size, 2, -1):
  intValue = int(string[i])
  potencyIndex = 0
  thirdLimit -= 1
  for j in range(thirdLimit, -1, -1):
    potencyIndex += 1
    if potencyIndex >= len(potencys):
      potencys.append(potencys[-1]*10)
    intValue += int(string[j])* potencys[potencyIndex]
    if i-j > 2 and intValue % 673 == 0:
      n += 1
print(n)

S = str(input())
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
  sum += int(i) * x
  Surpus[sum % 2019] += 1
  x *= 10
  x %= 2019

ans = 0
for i in Surpus:
  ans += i * (i - 1) // 2
print(ans)

S = str(input())
remainderDictionary = {}
    
sum = 0
x = 1
for i in S:
  sum += int(i) * x
  remainder = sum % 2019
  remainderValue = remainderDictionary.get(remainder,0) + 1
  remainderDictionary[remainder] = remainderValue
  x = (x * 10) % 2019
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

string = str(input())
n = 0
limit = len(string)-4
secondLimit = len(string)
size = len(string)-1
potencys = [1, 10, 100, 1000]
thousandList = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]
oldIntValue = 0
potencyIndex = 0
thirdLimit = size
if secondLimit > 3:
  for i in range(size, size-4, -1):
    oldIntValue += int(string[i])*potencys[potencyIndex]
    potencyIndex += 1

potencyIndex = 3
intValue = oldIntValue
for j in range(size-4, -1, -1):
  potencyIndex += 1
  if potencyIndex >= len(potencys):
    potencys.append(potencys[-1]*10)
  intValue += int(string[j])* potencys[potencyIndex]
  if intValue % 673 == 0:
    n += 1

size -= 1
for i in range(size, 2, -1):
  intValue = (oldIntValue / 10) + thousandList[int(string[i-3])] # it is the fourth value in the intValue or 10^3
  oldIntValue = intValue
  potencyIndex = 3
  for j in range(i-4, -1, -1):
    potencyIndex += 1
    if potencyIndex >= len(potencys):
      potencys.append(potencys[-1]*10)
    intValue += int(string[j])* potencys[potencyIndex]
    if intValue % 673 == 0:
      n += 1
print(n)

number = str(input())[::-1]
remainderDictionary = {0: 1}
digitDictionary = {'1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum = (sum + digitDictionary[i] * x) % 2019 
  remainderDictionary[sum] = remainderDictionary.get(sum,0) + 1

ansDictionary = {} # dictionary with the number of occurences and the corresponding N combinations of 2
ans = 0
for i in remainderDictionary:
  remainderOccurences = remainderDictionary[i]
  value = ansDictionary.get(remainderOccurences,-1)
  if value == -1:
    value = remainderOccurences * (remainderOccurences - 1) // 2 # N combinations of 2
    ansDictionary[remainderOccurences] = value
  ans += value
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted