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:
s = input()
n = len(s)

count = 0

for i in range(n-3):
    check = 0
    for j in range(i,n):
        check += int(s[j])
        if check % 3 == 0 and j > i+3:
            if int(s[i:j+1]) % 2019 == 0:
                count += 1
                
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
len = len(str(s))
s_list = list(str(s))
ans = 0
for i in range(len - 3):
    if len > 4:
        for j in range(i + 4, len):
            if int(''.join(s_list[i:j + 1])) % 2019 == 0:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
i=1
j=5
count=0
while i<len(s):
    a=int(s[i-1:j])
    if a%2019 == 0:
        count+=1
    if j>=len(s):
        i+=1
        j=i+4
    else:
        j+=1      
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

ori_size = len(S)
count = 0
for i in range(ori_size-2):
    for j in range(i+4, ori_size+1):
        num = int(S[i:j])
        if num % 3 == 0:
            if num % 673 == 0:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0

for i in range(0,len(s)-3):
  num = int(s[i]) + int(s[i+1]) + int(s[i+2])
  for j in range(i+3,len(s)):
    num += int(s[j])
    if num % 3 != 0:
      continue
    if int(s[i:j+1])%2019 == 0:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228', '26247', '28266', '30285',
              '32304', '34323', '36342','38361', '40380', '42399', '44418', '46437', '48456', '50475', '52494',
              '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646', '70665', '72684', '74703',
              '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912', '98931'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'100950', '102969', '104988', '107007', '109026', '111045', '113064', '115083', '117102', '119121',
             '121140', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311',
             '141330', '143349', '145368', '147387', '149406', '151425', '153444', '155463', '157482', '159501',
             '161520', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691',
             '181710', '183729', '185748', '187767', '189786', '191805', '193824', '195843', '197862', '199881'}
if l >= 4:
    for j in range(4,l):
        for k in range(l - j + 1):
            segment = str(int(S[k:k + j]))
            if len(segment) == 5:
                if segment in fiveDigi:
                    noCount += 1
            if len(segment) == 4:
                if segment in fourDigi:
                    noCount += 1
            if len(segment) == 6:
                if segment in sixDigi:
                        noCount += 1

print(noCount)

Submission status: Time Limit Exceeded

Solution code:
s=input()
lens=len(s)
count=0
for i in range(lens+1):
    for k in range(i,lens+1):
        num=s[i:k]
        if(len(num)>=4):
            if(int(num)%2019==0):
                count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = input()
a = [2019 * i for i in range(1,1000001)]
ans = 0
for i in a:
    st = N
    d = str(i)
    if st.find(d) != -1:
        while True:
            if st.find(d) != -1:
                ans += 1
                st = st[st.find(d)+1:]
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:

if __name__ == "__main__":
    S = str(input())
    cnt = 0
    for i in range(len(S)):
        for j in range(i+4, len(S)+1):
            # print(i, j)
            # print(S[i:j])
            if int(S[i:j]) % 2019 == 0:
                cnt += 1
            else:
                pass            
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = list(input())
# Ns = ''.join(N)
M = list(map(str, list(range(len(N)))))
S = list(itertools.combinations(M,2))
count = 0
for _, combi in enumerate(S):
    X,Y = map(int,combi)
    if Y - X > 2:
        A = N[X:Y+1]
        B = int(''.join(A))
        # print(A,B)
        if B%2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
n = len(S)
print(sum([int(S[i:j+1])%2019 == 0 for i in range(0,n-3) for j in range(i+4,n)]))

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np#not for pypy

def main():
    ##get int
    #first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    first_input = input().split(" ")
    #second_input = input().split(" ")

    S = first_input[0]

    mod_2019 = []
    for i in range(len(S)+1):
        if i==len(S):
            mod_2019.append(0)
        else:
            mod_2019.append(int(S[i:])%2019)

    count = 0
    for i in range(2019):
        Cn = mod_2019.count(i)
        count = count+Cn*(Cn-1)/2

    print(int(count))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
#1文字ずつにわけてリスト化
a = [str(c) for c in s]
count=0
for i in range(len(a)-1):
    for j in range(i+4, len(a)+1):
        num = a[i:j]
        num = "".join(num)
        if (int(num)%2019==0):
            count+=1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=input()
slen=len(s)
count=0
ri=slen-4
for i in range(5,slen):
  list=[]
  a=10**(i-1)
  a/=2019
  b=10**i
  b/=2019
  a=int(a+1)
  b=int(b+1)
  for j in range(a,b):
    if "0" not in str(2019*j):
      list.append(2019*j)
  for j in range(ri):
    targ=int(s[j:j+i])
    if targ in list:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
result = 0
s = input()
slen = len(s)
i = 0
while i+1 < slen:
    limit = slen-i+1
    p = 0
    seisuu = ""
    while p < limit:
        seisuu += s[i+p-1]
        p += 1
        if len(seisuu) > 4 and int(seisuu) % 2019 == 0:
            result += 1
    i += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
# A,B,C,D=map(int,input().split())

def main():
    S=list(input())
    count=0
    if len(S)<4:
        print(0)
        exit()
    for i in range(len(S)-4):
        for j in range(len(S)-3-i):
            if not i+4+j>len(S):
                if int("".join(S[i:i + 4 + j])) % 2019 == 0:
                    count += 1

    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
nums = []
ans = 0

for i in range(4,len(S)):
    nums_tmp = [S[j: j+i] for j in range(len(S)-i+1)]
    nums.extend(nums_tmp)

for i in nums:
    if int(i) % 2019 == 0:
        ans += 1
    else:
        continue
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = len(s)
dat = list(map(int, list(s)))
dp = [0] * 2020
ndp = [0] * 2020
res = 0
for r in range(ll):
    v = dat[r]
    ndp = [0] * 2020
    for i in range(2020):
        if dp[i] != 0:
            nt = (i * 10 + v) % 2019
            ndp[nt] += dp[i]
    res += dp[0]

    ndp[v] += 1
    dp = ndp
res += dp[0]
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = sys.stdin.readline().rstrip()
cnt = 0
def f(i, num):
  global cnt
  if int(n[i:i+num]) % 2019 == 0:
    cnt += 1
b = 4
l = len(n)
while b <= l:
  a = 0
  while a <= l - b:
    f(a, b)
    a += 1
  b += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

s = str(input())
tisa = []
for i in range(1,1000000):
  ww = str(2019*i)
  if '0' not in ww:
    tisa.append(ww)
#ok
#print(s)
#print(tisa)
#print(len(tisa))
#重複　count methodは無理
ans = 0
for c in tisa:
  if c in s:
    i = s.index(c)
    while i <len(s)-len(c)+1:
      if s[i:i+len(c)]==c:
        ans += 1
        i += 3
      else :
        i += 1
    

      
  

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys


input = sys.stdin.readline
s = input()
n = len(s)
count = 0
a = [str(2019 * i) for i in range(1, 1000)]
for i in range(len(a)):
    for j in range(len(s)):
        if s[j] == a[i][0]:
            if s[j : j + len(a[i])] == a[i]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, input()))
n = len(S)
 
fl = [False]*(n+1)
res = 0
 
for i in range(n-3):
    if fl[i]:
        continue
    
    x = 0
    cnt = 0
    for j in range(i, n):
        x = (x*10+S[j])%2019
        
        if x == 0:
            cnt += 1
            fl[j+1] = True
            
    
    res += (cnt+1)*cnt//2
 
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
P = 2019

N = len(str(S))

li = []

for i in range(N+1):
  li.append(S % pow(10, (N - i)))


li2 = []

for i in range(P):
  li2.append(0)

for i in li:
  li2[i % P] += 1

t = 0
for i in li2:
  if i == 0 or i == 1:
    pass
  else:
    t += i * (i -1) //2

print(t)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
sij0=0
#sij1=0
l=len(s)
a=list(map(int,list(s)))
for i in range(l-3):
  sij0=a[i]*1000+a[i+1]*100+a[i+2]*10+a[i+3]
  #print(sij0)
  sij0=sij0 % 2019
  if sij0 == 0:
    k=k+1
  for j in range(i+4,l):
    #sij1=int(s[j])
    sij0*=10
    sij0+=a[j]
    sij0 = sij0 % 2019
    if sij0 == 0:
      k=k+1
      j+=3
print(k)

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
if l<=4:
    print(0)
else:
    count=0
    for i in range(l-4):
        j=i+3
        while j<=l:
            if int(s[i:j])%2019==0:
                count+=1
                j+=5
            else:
                j+=1
                
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
target_val = input()

def cut_2019(val_):
    return val_ % 2019

ans_val = 0
for cut_num in range(4, len(target_val)):
    temp_list = list(map(int, 
                         [target_val[i:cut_num+i] for i in range(0, len(target_val)-cut_num+1)])
                    )
    temp_list = list(map(cut_2019, temp_list))
    ans_val += Counter(temp_list)[0]
print(ans_val)

Submission status: Time Limit Exceeded

Solution code:
S=input()

DP=[[0 for k in range(len(S))] for l in range(len(S))]

count=0
for i in range(len(S)-3):
    DP[i][i+3]=int(S[i:i+4])%2019
    if DP[i][i+3]==0:
        count+=1
    j=i+4
    while j in range(i+4,len(S)):
        DP[i][j]=(DP[i][j-1]*10+int(S[j]))%2019
        if DP[i][j]==0:
            count+=1
            j+=3
        else:
            j+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for i in range(4,2*(10**5)):
    for j in range(len(S)-i):
        l = j
        r = j + i
        if int(S[l:r+1])%2019==0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
n=len(str(s))
t=0
for j in range(n-3):
    j+=4
    for i in range(j-3):
        i+=1
        k=s
        k//=10**(n-j)
        k%=10**(j-i+1)
        if k%2019==0:
            t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import re
    S = input()

    num = [str(i*2019) for i in range(1, 2*10**5)]

    cnt = 0
    for i in range(len(num)):
        if(num[i] in S):
            cnt += S.count(num[i])
            m = [j.span() for j in re.finditer(num[i], S)]
            for j in range(len(m)):
                if(len(num[i])+m[j][1]) <= len(S):
                    tmp = S[m[j][1]-1:(len(num[i])+m[j][1]-1)]
                    if(tmp == num[i]):
                        cnt += 1
    print(cnt)

main()

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019

s = str(input())
ans = 0
 
for i in range(len(s)):
    for j in range(i+4, min(len(s),10000)):
        if int(s[i:j+1])%2019==0:
            ans += 1
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = len(s)
total = [0, int(s[0])]

for i in range(1,s_len):
    total.append(total[-1]+int(s[i]))

count=0
for i in range(s_len):
    for j in range(i+4,s_len):
        if int(s[j-3])%2!=0:
            continue
        if (total[i] - total[j+1])%3==0:
            if int(s[i:j+1])%2019==0:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
 
cnt = 0

i = 0
up = 1
up_j = 1
while i < len(s)-3:
  j = i+3
  up = 1
  while j < len(s):
    num = s[i:j+1]
    a = int(num) % 2019
    if a == 0:
      cnt += 1
      up = 4
    elif a < 10:
      up_j = 3
    elif a < 100:
      up_j = 2
    else:
      up_j = 1
    j += up_j
  i+=up
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

#N = str(1817181718171)
#print (len(N))

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+1, min(i+2019, lenN)):
#        print (i, j)
#        print (N[i:j])
        number = int(str(N[i:j]))
        if number%2019 == 0:
            count +=1

print (count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
leng = len(S);
intlist = list(map(int,list(S)))

for i in range(leng):
    buf = 0
    for j in range(i, leng):
        buf *= 10
        buf += intlist[j]
        buf %= 2019
        if(buf == 0):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
slen = len(S)
Sint = int(S)
count = 0
for i in range(slen-3):
    for j in range(i+3,slen):
        s4 = int(S[i:j+1])
        if s4 % 2019 == 0:
            count = count + 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=0
for i in range(len(S)-3):
    j=i+3
    while j<len(S):
        s=int(S[i:j+1])
        if s%2019==0:
            n+=1
            j+=3
        j+=1
print(n)

Submission status: Time Limit Exceeded

Solution code:
S = input()
num = list(map(int,S))
N = len(num)
a = []
for i in range(N):
    for j in range(N):
        if i>j:
            continue
        tmp = num[i:j+1]
        if len(tmp) >= 4:
            S = int(''.join([str(n) for n in tmp]))
            if S % 2019 == 0:
                a.append(S)
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
def floor1(x,a,b):
  return  x%(10**(b+1)) - x % (10**a)
S = input()
s = int(S)
res = 0
ress = sum(floor1(s,i[0],i[1]) % 2019 == 0 for i in combinations(range(len(S)),2))
print(ress)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(4100000)
n=input()
s=0
x=0
ans=0
a=len(n)-3
b=len(n)+1
for i in range(a):
  for j in range(4,b):
    s=len(n[i:j])
    if s>=4:
      x=int(n[i:j])
      if x%2019==0:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
U=int(S)
T=len(S)

list=[]
count=0
for i in range(0,T-3):
  for j in range(i+4,T+1):
    list.append(S[i:j])
list_2 = [int(n) for n in list if int(n)%673==0]
print(len(list_2))

Submission status: Time Limit Exceeded

Solution code:
S = input()

new_S = int(S)

#print(S[2:2])

cnt = 0



for i in range(len(S)):
  for j in range(len(S)):
    #print(int(S[i:j+i+1]))
    if int(S[i:j+i+1]) % 2019 == 0:
      cnt += 1
    if j+i+1 == len(S):
   	  	break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s=list(S)
count = 0
x=0
for i in range(len(s)):
 for j in range(i+4,len(s)+1):
  a=s[i:j]
  for k in range(len(a)):
   x = x+int(a[k])*(10**(len(a)-1-k))
  if x % 2019==0:
   count= count+1
  x = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
r = 0
b = [0]*2019
m = b[:]
for i in range(3,l):
    m2 = b[:]
    for j in range(1,2019):
        j2 = (j*10+int(s[i])) % 2019
        m2[j2] += m[j]
    m2[int(s[i-3:i+1]) % 2019] += 1
    r += m2[0]
    m = m2
print(r)

Submission status: Time Limit Exceeded

Solution code:
s = input()
num = len(s)
l = []
from collections import deque
l = deque(l)   # deque オブジェクトを取得

for _ in range(1, 20190000):
    if _%2019 == 0:
        l.append(str(_))
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if s[j:j+i] in l:
                x += 1
    print(x)

aaa(s, num)

Submission status: Time Limit Exceeded

Solution code:
S = input()

s = []
for i in S:
    s.append(int(i))
count = 0

for i in range(len(s)):
    j = i
    target = s[i]
    for k in range(len(s)-i):
        j += 1
        if(j >= len(s)):
            break
        target = target*10
        target += s[j]
        if ( target%2019 == 0):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0
if int(S) < 2019:
  print(ans)
else:
  for i in range(len(S)-4):
    for j in range(4, len(S)-i+1):
      T = S[i:i+j]
      N = int(T)
      if N % 2019 == 0:
        ans += 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
aa = 0
for i in range(len(S)):
    for j in range(len(S)-i):
        n = int(''.join(S[i:i+j+1]))
        if n%3 == 0:
            if n%673  == 0:
                aa = aa+1
            
print(aa)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S = input()
s = 0
S_sum = deque([0])
for i in range(len(S)):
    S_sum.append(s + int(S[len(S) - i - 1]) * 10**i)
    s += int(S[len(S) - i - 1]) * 10**i

ans = 0
for i in range(len(S_sum) - 1):
    for j in range(i + 4, len(S_sum)):
        if ((S_sum[j] - S_sum[i]) // 10**i) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = int(s)%2019
l = []
for i in range(t):
    l.append(str(2019*(i+1)))
ans = 0
for j in range(len(l)):
    ans += sum([s[k:k+len(l[j])]==l[j] for k in range(0, len(s)-len(l[j])+1)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = input()
le = len(n)

m = [1 for i in range(le) for j in range(i+1, le+1) if int(n[i:j])%2019==0 ]
print(len(m))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)

if l < 4:
    print(0)
    exit()

ans = 0
for i in range(0,l-3):
    temp = int(s[i])
    for j in range(i+1,l):
        temp = temp*10 + int(s[j])
        num = int(temp)
        if num%2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
List=[0]*(len(s)+1)
g=int(s[0])*(10**(len(s)-1))
List[1]=g%2019
for i in range(1,len(s)):
  List[i+1]=(List[i]+int(s[i])*(10**(len(s)-1-i)))%2019
count=0
for i in range(2020):
  d=List.count(i)
  count+=int(d*(d-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
input = stdin.readline

def main():
    S = list(input())
    S.pop()
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += 10**i*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import functools
def solve():
    s = int(input())

    t = [int(x) for x in list(str(s))]

    cnt = 0
    n= len(t)
    for i in range(n-4):
        for j in range(i+4, n):
            new = int(functools.reduce(lambda x, y: x + y, [str(x) for x in t[i:j+1]]))
            if new%2019 ==0:
                cnt += 1

    return cnt
    
print(solve())

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys


def solve(S: int):
    cnt = 0
    for i in range(len(str(S))):
        for j in range(i + 1, len(str(S))):
            if not int(str(S)[i:j+1]) % 2019:
                cnt += 1
    print(cnt)
    # cnt = 0
    # l = filter(lambda x: '0' not in str(x), range(2019, 200000, 2019))
    # l = [str(i) for i in l]
    # s = str(S)
    # for i in range(len(s)):
    #     if 5 + i > len(s) - 1:
    #         continue
    #     if s[i:4 + i] in l or s[i:5 + i] in l:
    #         cnt += 1
    # print(cnt)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

lenS = len(S)

sweep = 4
flag = 0
ans = 0
mem = 0
step = 1

if lenS < 3:
    print(0)
elif len(S) < 20:
    while sweep <= len(S):
        step = 1
        for i in range(mem, lenS - sweep + 1, step):
            if int(''.join(S[i:i + sweep])) % 2019 == 0:
                ans += 1
                step = sweep - 1
            if i > ((lenS // sweep)+1) and step == 1:
                break
        sweep += 1
    print(ans)
else:
    while sweep <= len(S)//2+1:
        step = 1
        for i in range(mem, lenS - sweep + 1, step):
            if int(''.join(S[i:i + sweep])) % 2019 == 0:
                ans += 1
                step = sweep - 1
            if i > ((lenS // sweep)+1) and step == 1:
                break
        sweep += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
n = len(S)
res = 0
cur = 0
count = [0] * 2020
for i, c in enumerate(map(int, S)):
    cur = cur * 10 + c
    if cur % 2019 == 0:
        res += 1
    temp = (cur * 10 ** (n - i)) % 2019
    res += count[temp]
    count[temp] += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
dp = [[0] * 2019 for _ in range(n + 1)]

for i in range(1, n + 1):
    x = int(s[i-1])
    dp[i][x] = 1
    for j in range(2019):
        dp[i][(j*10+x)%2019] += dp[i-1][j]

ans = 0

for i in range(1, n+1):
    ans += dp[i][0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
su = 0
right = 0
if l<=3:
  print(0)
  exit()
a = ["2019","4038","6057","8076"]
for j in a:
  su += s.count(j)
for i in range(5,l+1):
  right = i
  left = 0
  while right<=l:
    if int(s[left:right])%2019==0:
      su += 1
      left = right-1
      right += i-1
    else:
      right += 1
      left += 1
print(su)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
count=0
a=[0 for i in range(n)]
for i in range(3,n):
    a[i]=(10**i)%2019
if n<4:
    print(0)
else:
    for i in reversed(range(2,n)):
        k=int(s[i-2:i+1])%2019
        h=3
        for j in reversed(range(0,i-2)):
            k=(k+a[h]*int(s[j]))%2019
            h+=1
            if k%2019==0:
                count+=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
digits = len(s)
if digits < 4:
    print(0)
else:
    count = 0
    for i in range(digits-3):
        for j in range(i+3, digits):
            if int(s[i:j+1]) % 2019 == 0:
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = len(S)
cnt = 0
A = [0]*2019
for i in range(s):
  x = int(S[i:])%2019
  A[x] += 1
for i in range(1,2019):
  if A[i] >= 2:
    cnt += A[i]*(A[i]-1)//2
cnt += A[0]*(A[0]+1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect

s = input()
n = len(s)

s2 = [0 for _ in range(n)]

zero = []
one = []
two = []

for i in range(n):
  s2[i] = int(s[i]) % 3

for i in range(1,n):
  s2[i] += s2[i-1]
  s2[i] %= 3

for i in range(n):
  if s2[i] == 0:
    zero.append(i)
  elif s2[i] == 1:
    one.append(i)
  elif s2[i] == 2:
    two.append(i)
ans = 0
length = len(zero)
for i in range(length):
    if int(s[:zero[i]+1]) % 2019 == 0:
      ans += 1
length = len(zero)
for i in range(length-1):
  for j in range(i+1,length):
    if int(s[zero[i]+1:zero[j]+1]) % 2019 == 0:
      ans += 1

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

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

Submission status: Time Limit Exceeded

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

ans_set1 = set()
ans_set2 = set()

for i in range(N+1):
    for j in range(i+3,N+1):
        if int(S[i:j]) % 673 == 0:
            ans_set1.add((i,j))

for i,j in ans_set1:
    if int(S[i:j]) % 3 == 0:
        ans_set2.add((i,j))

print(len(ans_set2))

Submission status: Time Limit Exceeded

Solution code:
n = input()
l = len(n)
count = 0
for i in range(l-3):
  x = 0
  for j in range(i+3, l):
    if j == i+3:
      x = int(n[i]) + int(n[i+1]) + int(n[i+2]) + int(n[i+3])
    else:
      x += int(n[j])
    
    if x % 3 == 0:
      integer = int(n[i:j+1])
      if integer % 2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def solve(S, i, Ns):
    #print("i:{}".format(i))
    #print("Ns:{}".format(Ns)) 
    if len(S) <= i:
        return 0 # Ns[i] でインデックスの外
    if Ns[i] != -1:
        return Ns[i]
    N = 0
    for j in range(i+4, len(S)+1):
        s = int(S[i:j])
        #print(s)
        if s % 2019 == 0:
            N = 1+solve(S,i+j, Ns)
            break
    Ns[i] = N
    return N


if __name__ == "__main__":
    # 2019 = 3 * 673
    S = str(input())
    n = len(S)
    Ns = [-1 for i in range(n)]

    # ans = 0
    # # for i in range(2019):
    # #     for j in range(1, 10):
    # #         if (i*10+j) % 2019 == 0:
    # #             print(i,j)
    # # for i in range(0, n):
    # #     for j in range(i+1, n+1):
    # #         s = int(S[i:j])
    # #         #print(s)
    # #         if s % 2019 == 0:
    # #             #print("i,j : {}, {}".format(i, j))
    # #             ans += 1
    # print(ans)

    for i in range(len(S)):
        solve(S, i, Ns)
    #print(Ns)
    print(sum(Ns))

Submission status: Time Limit Exceeded

Solution code:
s=input()
res=0
ctr=0
# for i in range(len(s)):
#     res=(res+int(s[i]))*10
#     #res/=10;
#     print(res)
#     if(res%2019==0):
#         print("yeee")
#         ctr+=1
#         print(ctr)
for i in range(len(s)):
    res=0
    for j in range(i,len(s)):
        res=(res+int(s[j]))*10
        #res/=10;
        # print(res)
        if(res%2019==0):
            # print("yeees")
            ctr+=1
print(ctr)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	S = input()
	LEN = len(S)
	r = LEN
	l = LEN-1
	count = 0
	lst = []
	while(l >= 0):
		amari = int(S[l:r])%2019
		
		if amari in lst:
			count += 1
		elif amari == 0:
			count += 1
			lst.append(count)
		else:
			lst.append(amari)
		l -= 1

	print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0

for i in range(5,len(S)):
    for j in range(len(S)-i+1):
        if int(S[j:j+i]) % 2019 == 0:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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


def multiple2019(k):
    num = 0
    for i in range(k - 3):
        if int(S[i:k + 1]) % 2019 == 0:
            num += 1
    return num


dp = [0 for i in range(N + 1)]
for i in range(4, N):
    dp[i + 1] = dp[i] + multiple2019(i)

print(dp[N])

Submission status: Time Limit Exceeded

Solution code:
s = input()
sm = [0]
p = 673
for i in range(len(s)):
    sm.append(sm[-1] + int(s[i]))

#s = input()
rem_k = []
n = len(s)
for i in range(len(s)):
    rem_k.append(int(s[n-1-i:n])%673)
dic = {}
for i in range(673):
    dic[i] = 0

arr=[int(s[i]) for i in range(len(s))]
tmp = 0
for i in range(n-1,-1,-1):
    tmp+=arr[i]*pow(10,n-1-i,p)
    tmp%=p
    dic[tmp]+=1
ans=0
rem=0

for i in range(n-1,-1,-1):
    ans+=dic[rem]
    rem+=arr[i]*pow(10,n-1-i,p)
    rem%=p
    dic[rem]-=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
S = input()
count = 0
l = [0]*2019
l[0] = 1
l = np.array(l)

for i in range(1,len(S)+1):
    n =(int(S[len(S)-i:])%2019)
    l[n] += 1
    

for j in range(2019):
    if l[j] >= 2:
        count += l[j]*(l[j]-1)//2

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
indexs = []
count = 0
for i in reversed(range(3,N)):
    check_num = int(S[i-2]+S[i-1]+S[i])
    if (check_num % 19 == 0): 
        indexs.append(i)        
for i in indexs:
    for j in range(i):
        if int(S[j:i+1]) % 2019 == 0 :
            count = count + 1
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
N = len(S)
cnt = 0

for i in range(N):
    if N - i - 1 >= 3:
        for j in range(i+3,N):
            if int(S[i:j+1]) % 2019 == 0:
                cnt += 1
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
# TODO NG
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

s = input()

cnt = 0
lens = len(s)
for i in range(lens-3):
#     for j in range(i+3, len(s)):
    j = i + 3
    while(j < lens):
        num = int(s[i:j+1])
        if num % 2019 == 0:
            cnt += 1
            j += 4
        j += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
n = len(S)
res = 0
cur = 0
count = [0] * 2020
for i, c in enumerate(map(int, S)):
    cur = cur * 10 + c
    if cur % 2019 == 0:
        res += 1
    temp = (cur * 10 ** (n - i)) % 2019
    res += count[temp]
    count[temp] += 1
print(res)