Problem:


Score : 400 points

Problem Statement

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.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
n = len(s)
# 累積和の準備
sum_list = [0]*(n+1)  # s[0]は０であってほしいから配列数ひとつおおい
for i in range(1, n + 1):
    sum_list[i] += (sum_list[i-1] + int(s[n-i])*10**(i-1)) % 2019  # ここでmodしておく
"""
(s[j]-s[i]/10**i)が区間の整数
区間の整数が2019で割り切れればよい
つまり、(s[j]-s[i]/10**i)≡0 (mod=2019)
ここで10**iと2019(素数)は互いに素なので、
10**iをかけて上の式はs[j]-s[i]≡0 (mod=2019)と同値
s[j]≡s[i] (mod=2019)となる。
"""
c = Counter(sum_list)
ans = 0

for value in c.values():
    ans += value*(value-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
  s = input().strip()
  remains = Counter([int(s[-i:]) % 2019 for i in range(1, len(s)+1)]).items()

  cnt = 0
  for k, v in remains:
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
# 累積和の準備
sum_list = [0]*(len(s)+1)  # s[0]は０であってほしいから配列数ひとつおおい
for i in range(1, len(s) + 1):
    sum_list[i] += (sum_list[i-1] + int(s[len(s)-i])*10**(i-1)) % 2019
"""
(s[j]-s[i]/10**i)が区間の整数
区間の整数が2019で割り切れればよい
つまり、(s[j]-s[i]/10**i)≡0 (mod=2019)
ここで10**iと2019(素数)は互いに素なので、
10**iをかけて上の式はs[j]-s[i]≡0 (mod=2019)と同値
s[j]≡s[i] (mod=2019)となる。
"""
# s[i]のmod=2019を記憶しておくリスト用意
#mod_s = [[] for _ in range(len(sum_list))]
#mod_s[0] = 0
#for i in range(1, len(sum_list)):
    #mod_s[i] = sum_list[i] % 2019

#print(mod_s)
#c = Counter(mod_s)
c = Counter(sum_list)
ans = 0
#print(c)
for value in c.values():
    ans += value*(value-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  s = input().strip()
  remains = dict(Counter([int(s[-i:]) % 2019 for i in range(1, len(s)+1)]).items())

  cnt = 0
  for k, v in remains.items():
    cnt += (v * (v - 1)) // 2
    if k == 0:
      cnt += v
  print(cnt)
  
if __name__=='__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
# 累積和の準備
sum_list = [0]*(len(s)+1)  # s[0]は０であってほしいから配列数ひとつおおい
for i in range(1, len(s) + 1):
    sum_list[i] += sum_list[i-1] + int(s[len(s)-i])*10**(i-1)
"""
(s[j]-s[i]/10**i)が区間の整数
区間の整数が2019で割り切れればよい
つまり、(s[j]-s[i]/10**i)≡0 (mod=2019)
ここで10**iと2019(素数)は互いに素なので、
10**iをかけて上の式はs[j]-s[i]≡0 (mod=2019)と同値
s[j]≡s[i] (mod=2019)となる。
"""
# s[i]のmod=2019を記憶しておくリスト用意
mod_s = [[] for _ in range(len(sum_list))]
mod_s[0] = 0
for i in range(1, len(sum_list)):
    mod_s[i] = sum_list[i] % 2019

#print(mod_s)
c = Counter(mod_s)
ans = 0
#print(c)
for value in c.values():
    ans += value*(value-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
s = s[::-1]

sum_list = [0]*(len(s)+1)
for i in range(1, len(s) + 1):
    sum_list[i] += sum_list[i-1] + int(s[i-1])*10**(i-1)
    
mod_s = [[] for _ in range(len(sum_list))]
mod_s[0] = 0
for i in range(1, len(sum_list)):
    mod_s[i] = sum_list[i] % 2019

c = Counter(mod_s)
ans = 0
for value in c.values():
    ans += value*(value-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
k=[0]*2019
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*(10**i)
  l=t%2019
  k[l]+=1
  
ans=0
for l in k:
  ans+=l*(l-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
s = s[::-1]
# 累積和の準備
sum_list = [0]*(len(s)+1)  # s[0]は０であってほしいから配列数ひとつおおい
for i in range(1, len(s) + 1):
    sum_list[i] += sum_list[i-1] + int(s[i-1])*10**(i-1)
"""
(s[j]-s[i]/10**i)が区間の整数
区間の整数が2019で割り切れればよい
つまり、(s[j]-s[i]/10**i)≡0 (mod=2019)
ここで10**iと2019(素数)は互いに素なので、
10**iをかけて上の式はs[j]-s[i]≡0 (mod=2019)と同値
s[j]≡s[i] (mod=2019)となる。
"""
# s[i]のmod=2019を記憶しておくリスト用意
mod_s = [[] for _ in range(len(sum_list))]
mod_s[0] = 0
for i in range(1, len(sum_list)):
    mod_s[i] = sum_list[i] % 2019

#print(mod_s)
c = Counter(mod_s)
ans = 0
#print(c)
for value in c.values():
    if value > 1:
        ans += value*(value-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
le = len(s)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as dd

S = input()
rem = {}
answer = 0
for c in S:
  i = int(c)
  new_rem = dd(int)
  new_rem[i] = 1
  for r, c in rem.items():
    if r == 0:
      answer += c
    new_rem[(10 * r + i) % 2019] += c
  rem = new_rem
  # print (rem)

print (answer + rem[0])

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
ans = 0
T = []
for i in range(N):
    T.append(int(S[i : N]) % 2019)
T.sort()
ans += T.count(0)
t = set(T)
counted = []
for i in t:
    a = T.count(i)
    if a > 1:
        counted.append(a)
for i in counted:
    ans += i * (i - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
for i in range(len(S)+1):
    for j in range(i,len(S)+1):
        if i == j: continue
        n = int(S[i:j])
        if n % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
k = len(str(n))
if k >= 200001:
    k = 200000
for i in range (1, k-2):
    for j in range (i+3 , k+1):
        aa = n // 10 ** (k - i + 1)
        bb = 10 ** (k - i + 1)
        cc = (n * 10)  // (10 ** (k - j + 1))
        if k - j == 0:
            dd = 1
            if (n - (aa * bb) - (n - (cc * dd))) % 2019 == 0:
                c = c + 1
        else:
            dd = 10 ** (k - j)
            if (n - (aa * bb) - (n - (cc * dd))) % 2019 == 0:
                c = c + 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)

dp = [0] * 2019
for i in reversed(range(N)):
    mod = int(S[i:]) % 2019
    dp[mod] += 1

ret = [i*(i-1)//2 for i in dp if i > 1]
print(sum(ret) + dp[0])

Submission status: Time Limit Exceeded

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


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

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for i in range(len(s)):
        b = b + int(s[len(s)-i-1]) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10 % 2019

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
k = len(str(n))
if k >= 200001:
    k=200000
for i in range (1, k-2):
    for j in range (i+3 , k+1):
        aa = n // 10 ** (k - i + 1)
        bb = 10 ** (k - i + 1)
        cc = (n * 10)  // (10 ** (k - j + 1))
        if k - j == 0:
            dd = 1
            if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                c = c + 1
        else:
            dd = 10 ** (k - j)
            if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                c = c + 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


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

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for i in range(len(s)):
        b = b + int(s[len(s)-i-1]) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10 % 2019

    for i in range(2019):
        ans += cnt[i] * (cnt[i] - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
ans = 0
C = [0] * (L+1)
A = [0] * 2020
A[0] = 1
for i in range(L-1, -1, -1):
    C[i] = (int(S[i]) * 10**(L-1-i) % 2019 + C[i+1])%2019
    A[C[i]] += 1

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


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

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()[::-1]

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for c in s:
        b = b + int(c) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10 % 2019

    for i in range(2019):
        ans += cnt[i] * (cnt[i] - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
k = len(str(n))
if n <= 2018:
    c = 0
else:
    for i in range (1, k-2):
        for j in range (i+3 , k+1):
            aa = n // 10 ** (k - i + 1)
            bb = 10 ** (k - i + 1)
            cc = (n * 10)  // (10 ** (k - j + 1))
            if k - j == 0:
                dd = 1
                if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                    c = c + 1
            else:
                dd = 10 ** (k - j)
                if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
                    c = c + 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) <= 3:
  print(0)
  exit()

chk = [str((i+1)*2019) for i in range(100000)]
ans = 0
for i in chk:
    if s.count(i) > 0:
      ans += s.count(i[1:])
      k = i[0]
      for j in range(1,10):
        if j == int(k):
          continue
        ans -= s.count(str(j)+i[1:])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
k={}
t=0
k[0]=1
for i,s in enumerate(S[::-1]):
  t+=int(s)*(10**i)
  l=t%2019
  if l in k:
    k[l]+=1
  else:
    k[l]=1
  
ans=0
for i in k.values():
  ans+=i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
from collections import deque, defaultdict, Counter
import math
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


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

# a/b の切り上げ


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def main():
    s = input()[::-1]

    cnt = [0] * 2019
    # print(cnt)
    cnt[0] = 1
    ans = 0
    b = 0
    t = 1
    for c in s:
        b = b + int(c) * t
        amari = b % 2019
        cnt[amari] += 1
        t *= 10

    for i in range(2019):
        ans += cnt[i] * (cnt[i] - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
k = len(str(n))
for i in range (1, k-2):
    for j in range (i+3 , k+1):
        aa = n // 10 ** (k - i + 1)
        bb = 10 ** (k - i + 1)
        cc = (n * 10)  // (10 ** (k - j + 1))
        if k - j == 0:
          dd = 1
          if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
            c = c + 1
        else:
          dd = 10 ** (k - j)
          if ((n - (aa * bb) - (n - (cc * dd))) // dd) % 2019 == 0:
            c = c + 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
import collections
a=input()
n=len(a)
ans=0
mod=2019
# for i in range(n-4):
#     for j in range(i+4,n):
#         x=a[i:j+1]
#         v=int(x)
#         if v%2019==0:
#             ans+=1
            # print(v)
dp=[2020 for i in range(n+1)]
dp[n]=0
for i in range(n-1,-1,-1):
    dp[i]=(dp[i+1]+(int(a[i])*(10**(n-i-1))))%mod
# print(dp)
# for j in range(2019):
#     m=dp.count(j)
c=[[0]for i in range(2019)]
for i in dp:
    c[i][0]+=1
# print(c)
for j in range(2019):
    m=c[j][0]
    if m!=0:
        ans+=(m*(m-1)//2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

S = input()
l = [0]
for i in range(1,len(S)+1):
  tmp = int(S[-i:])
  l.append(tmp%2019)

c = collections.Counter(l)

rlt = 0
for k in c:
  rlt += c[k]*(c[k]-1)//2

print(rlt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
ans = 0
A = [0] * 2020
A[0] = 1
for i in range(L):
     x = int(S[i:]) % 2019
     A[x] += 1

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
import collections
a=input()
n=len(a)
ans=0
mod=2019
# for i in range(n-4):
#     for j in range(i+4,n):
#         x=a[i:j+1]
#         v=int(x)
#         if v%2019==0:
#             ans+=1
            # print(v)
dp=[2020 for i in range(n+1)]
dp[n]=0
for i in range(n-1,-1,-1):
    dp[i]=(dp[i+1]+(int(a[i])*(10**(n-i-1))))%mod
# print(dp)
# for j in range(2019):
#     m=dp.count(j)
c = collections.Counter(dp)
# print(c)
for j in range(2019):
    m=c[j]
    if m!=0:
        ans+=(m*(m-1)//2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
A = [0] * 2020
A[0] = 1
for i in range(len(S)):
     x = int(S[-i-1:]) % 2019
     A[x] += 1

while 0 in A:
    A.remove(0)

while 1 in A:
    A.remove(1)

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#input
S = str(input())[::-1]

#output
from collections import Counter
#2019 = 3 * 673
N = len(S)
#上からi桁目までの数を決めた時2019の個数をdp[i]とする。
dp = [0] * (N)
dp[0] = int(S[0])
for i in range(N-1):
    dp[i+1] = (dp[i] + int(S[i+1]) * 10**(i+1)) % 2019

T = Counter(dp)

answer = T[0]

for t in T.values():
    answer += t*(t-1)//2

print(answer)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s = input()
    n = len(s)
    counter = [0] * 2019
    counter[0] += 1
    temp = ""
    for i, c in enumerate(s[::-1], 1):
        temp = c + temp
        counter[int(temp) % 2019] += 1

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

    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import collections
S=str(input())

T=[0 for i in range(len(S))]
T[0]=int(S[-1])

for i in range(1,len(S)):
    T[i]=((10**i)*int(S[len(S)-1-i])+T[i-1])%2019
    
cnt=0
T_di=collections.Counter(T)

for key in T_di.keys():
    x=T_di[key]
    cnt+=x*(x-1)/2
    if key==0:
        cnt+=x

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    s = list(input())
    n = len(s)
    #s_cu = [] 
    counter = [0] * 2019

    counter[0] += 1
    temp=""
    for i in range(1, n+1):
        c=s.pop()
        temp = c + (temp if i != 1 else "")
        #s_cu.append(temp)
        counter[int(temp) % 2019] += 1

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

    print(ans)
resolve()

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = [0] * 2019
mod[0] = 1
d = 1
n = 0
for i in reversed(s):
    n += int(i) * d
    n %= 2019
    d *= 10
    mod[n % 2019] += 1
print(sum(i*(i-1)//2 for i in mod))

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = [0] * 2019
mod[0] = 1
d = 1
n = 0
for i in reversed(s):
    n += int(i) * d
    d *= 10
    mod[n % 2019] += 1
print(sum(i*(i-1)//2 for i in mod))

Submission status: Time Limit Exceeded

Solution code:
# import math
# import numpy as np
# import itertools
# import heapq
# =map(int,input().split())
a=input()
n=len(a)
ans=0
mod=2019
# for i in range(n-4):
#     for j in range(i+4,n):
#         x=a[i:j+1]
#         v=int(x)
#         if v%2019==0:
#             ans+=1
            # print(v)
dp=[2020 for i in range(n+1)]
dp[n]=0
for i in range(n-1,-1,-1):
    dp[i]=(dp[i+1]+(int(a[i])*(10**(n-i-1))))%mod
# print(dp)
for j in range(2019):
    m=dp.count(j)
    ans+=(m*(m-1)//2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) <= 3:
  print(0)
  exit()

chk = [str((i+1)*2019) for i in range(1000000)]
ans = 0
for i in chk:
    if s.count(i) > 0:
      ans += s.count(i[1:])
      k = i[0]
      for j in range(1,10):
        if j == int(k):
          continue
        ans -= s.count(str(j)+i[1:])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
#s_cu = [] 
counter = [0] * 2019

counter[0] += 1
temp=""
for i in range(1, n+1):
    temp = s[n-i] + (temp if i != 1 else "")
    #s_cu.append(temp)
    counter[int(temp) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
s_cu = [] 
counter = [0] * 2019

counter[0] += 1
temp=""
for i in range(1, n+1):
    temp = s[n-i] + (temp if i != 1 else "")
    s_cu.append(temp)
    counter[int(temp) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
A = [0] * 2020
A[0] = 1
for i in range(len(S)):
     x = int(S[-i-1:]) % 2019
     A[x] += 1

for i in A:
    ans += int(i * (i-1) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
d = {}
ans = 0
cnts = [0] * 2019
digit = int(s) % 2019
cnts[0] = 1
for i in range(len(s)):
    digit = int(s[i:]) % 2019
    cnts[digit] += 1
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = list(map(int, list(input())))
#print(S)
mod = 2019
mod_list = [0]
#last = 0
ten = 1

for num in S[::-1]:
    yo = (num * ten + mod_list[-1]) % mod
    #print(yo)
    mod_list.append(yo)
    #last = yo
    ten *= 10 % mod

cnt = [0]*2019

for yo in mod_list:
    cnt[yo] += 1

ans = 0
for i in range(2019):
    ans += cnt[i] * (cnt[i]-1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = list(map(int, list(input())))
#print(S)
mod = 2019
mod_list = [0]
#last = 0
ten = 1

for num in S[::-1]:
    yo = (num * ten + mod_list[-1]) % mod
    #print(yo)
    mod_list.append(yo)
    #last = yo
    ten *= 10

cnt = [0]*2019

for yo in mod_list:
    cnt[yo] += 1

ans = 0
for i in range(2019):
    ans += cnt[i] * (cnt[i]-1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
s_cu = ["0"] * (n+1)
counter = [0] * 2019

counter[0] += 1
for i in range(1, n+1):
    s_cu[i] = s[n-i] + (s_cu[i-1] if i != 1 else "")
    counter[int(s_cu[i]) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(2020):
    num = A.count(i)
    ans += int(num * (num-1) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
res = 0
for i in range(n):
    pre = 0
    for j in range(i + 4, n + 1):
        if pre == 0:
            pre = int(S[i:j])
        else:
            pre = pre * 10 + int(S[j - 1])
        if pre % 2019 == 0:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[0 for i in range(N+1)]#T[i]はi桁より右側の数字


def kaizyou(n):
  c=1
  c=c*10**n
  return c%2019


for i in range(N):
  T[N-i-1]=(T[N-i]+kaizyou(i)*Slis[N-i-1])%2019

MOD=[0 for i in range(2019)]
for i in range(N+1):
  tmp=T[i]%2019
  MOD[tmp]+=1


  
ans=0

for i in range(2019):
  tmp=MOD[i]
  ans+=tmp*(tmp-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
counter = [0] * 2019

counter[0] += 1
for i in range(1, n+1):
    counter[int(s[n-i:]) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
t = 0
for i in range(N-3):
    for j in range(N-i-3):
        A = int(S[i:i+j+4])
        if(A % 2019 == 0):
            t = t+1
print(t)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = str(input())
ans= 0
t=[0]*2019
t[0]=1
for i in range(0,len(n)):
        k = int(n[i:len(n)]) % 2019
        t[k] +=1
for i in t:
    ans += i *(i-1) /2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
s=[int(j) for j in input()][::-1]
c=[0]*2019
tmp=0
c[0]+=1
t=1
import numpy as np
for i in s:
    tmp+=t*i
    c[tmp%2019]+=1
    t*=10
c=np.array(c)
ans=c*(c-1)//2
print(ans.sum())

Submission status: Time Limit Exceeded

Solution code:
#input
S = str(input())

#output
from collections import Counter
#2019 = 3 * 673
N = len(S)
#上からi桁目までの数を決めた時2019の個数をdp[i]とする。
dp = [0] * (N+1)
dp[1] = int(S[-1])
for i in range(1, N):
    dp[i+1] = (dp[i] + int(S[-(i+1)]) * 10**i) % 2019

T = Counter(dp[1:])

answer = 0
answer += T[0]

for t in T.values():
    answer += t*(t-1)//2

print(answer)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
res = 0
for i in range(n):
    for j in range(i + 1, n + 1):
        if int(S[i:j]) % 2019 == 0:
            res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
#input
S = str(input())

#output
from collections import Counter
#2019 = 3 * 673
N = len(S)
#上からi桁目までの数を決めた時2019の個数をdp[i]とする。
dp = [0] * (N+1)
dp[1] = int(S[-1])
for i in range(1, N):
    dp[i+1] = (dp[i] + int(S[-(i+1)]) * 10**i) % 2019

T = Counter(dp[1:])

answer = 0
answer += T[0]

for t in T.values():
    if t >= 2:
        answer += t*(t-1)//2

print(answer)

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
Slis=[]
for i in range(N):
  Slis+=[int(S[i])]
T=[0 for i in range(N+1)]#T[i]はi桁より右側の数字


def kaizyou(n):
  c=1
  for p in range(n):
    c=(c*10)%2019
  return c


for i in range(N):
  T[N-i-1]=(T[N-i]+kaizyou(i)*Slis[N-i-1])%2019

MOD=[0 for i in range(2019)]
for i in range(N+1):
  tmp=T[i]%2019
  MOD[tmp]+=1


  
ans=0

for i in range(2019):
  tmp=MOD[i]
  ans+=tmp*(tmp-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i, j in enumerate(reversed(input())):
    n = (n+int(j)*10**i%2019)%2019
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
s_cu = [0] * n
counter = [0] * 2019

counter[0] += 1
for i in range(1, n):
    s_cu[i] = int(s[n-i:])
    counter[int(s[n-i-1:]) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s_str = input()
s = int(s_str)

count = 0
for x in range(len(s_str)+1):
    for y in range(x+1,len(s_str)+1):
        if int(s_str[x:y]) % 2019 == 0:
            count +=1


print(count)