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 = int(input())
x = str(s)
n = len(x)
a = list("")
c = 0
for i in range(1, 10000):
    a.append(str(2019 * i))
for i in range(n - 3):
    if x[i : i + 4] in a:
        c += 1
for i in range(n - 4):
    if x[i : i + 5] in a:
        c += 1
for i in range(n - 5):
    if x[i : i + 6] in a:
        c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()
p = 0
ans = 0
r = []
for i in range(len(S)-3):
    for j in range(i+3,len(S)):
        a = int(S[i:j+1])
        if a%2019 == 0:
            ans += 1
            r.append([i,j])
            break

for i in range(len(r)-1):
    for j in range(i,len(r)-1):
        if r[j][1] + 1 == r[j+1][0]:
            ans += 1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

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

count=0
for i in range(0,N-3):
  j=i+4
  while j<N+1:
    digi = int(S[i:j])
    if (digi%2019==0):
      count+=1
      j+=3
    else:
      j+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(S):
    ans = 0
    N = ""
    for i in range(len(S) - 4):
        N = S[i] + S[i + 1] + S[i + 2] + S[i + 3]
        for j in range(i + 4, len(S)):
            N += S[j]
            n = int(N)
            if n % 2019 == 0:
                ans += 1

    return ans


def main():
    S = list(input())

    print(solve(S))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    si = tuple(int(c) for c in s)  # integers of one digit
    # ms = {2019 * x for x in range(10 ** 200000 - 1 // 2019)}
    ans = 0
    lg = len(si)
    # to slice till the last letter, +1 is needed.
    for i in range(lg + 1):
        for j in range(i + 4, lg + 1):
            # 2019 = 673 * 3
            if sum(si[i:j]) % 3 != 0:
                continue
            if int(s[i:j]) % 673 == 0:
                ans += 1

    return ans


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_num = int(s)
len_s = len(s)
list=[0 for x in range(len_s+1)]
for i in range(len_s-1,-1,-1):
    for j in range(1,len_s-i+1):
        if int(s[i:i+j])%2019==0:
            list[i]=list[i+j]+1
            break
print(sum(list))

Submission status: Time Limit Exceeded

Solution code:
a=int(input())

A=0

for i in range(len(list(str(a)))-3):
    for j in range(4,len(list(str(a)))+1-i):
        b=list(str(a))
        b=b[i:j+i]
        pg = ''.join(b)
        pg=int(pg)
        if pg%2019==0:
            A+=1
print(A)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def digit_sum(n): # 各桁の和を求める
    ans = 0
    while n > 0:
        ans += n % 10
        n //= 10
    return ans

S=input()
A=0
while len(S)>3:
    d = digit_sum(int(S[:3]))
    for i in range(3,len(S)):
        #print('S[:i+1]',S[:i+1])
        d = d+int(S[i])
        #print('d',d)
        if d%3 == 0 :
            if int(S[:i+1])%673 ==0 :
                A+=1
    S=S[1:]
print(A)
#1817181712114

Submission status: Time Limit Exceeded

Solution code:
s=input()

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

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


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


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


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


# Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
input_str = input()
one_input = [str(x) for x in input_str]
count = 0
for i,one in enumerate(one_input):
    num = ""
    num += str(one)
    for j in (one_input[i+1:]):
        num += str(j)
        if int(num)%2019==0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ret = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            sum_num = sum([int(s) for s in S[i:j]])
        else:
            sum_num += int(S[j-1])
        
        if sum_num % 3 == 0:
            if int(S[i:j]) % 673 == 0:
                ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
s=input()
si=[int(ii) for ii in list(s)]
#print(si)
ls=len(si)
r=0
if ls<=3:
  print(r)
  exit()
import numpy as np
r=[]
n=0

import math
#print(2000/math.log10(2019))#
m=10000
r=[0]*m
for ii in range(m):
    r[ii]=2019*(ii+1)

for ii in range(ls-3):
    for jj in np.arange(ii+4,ls+1):
        #print(ints)
        if sum(si[ii:jj])%3==0:
            ints=int(s[ii:jj])
            if ints in r:
                n+=1
            elif ints%2019==0:
                n+=1            
                r.append(ints)
#print(r)
print(n)

"""for ii in range(m):
    print(r[ii])#=2019*(ii+1)
"""

Submission status: Time Limit Exceeded

Solution code:
s = input()
ll = []
for i in range(1, 200001//2019+2):
    ll.append(str(2019*i))

cnt = 0
for l in ll:
    if s.count(l) > 0:
        for i in range(0, len(s) - 3):
            for j in range(4, len(s) + 1):
                if s[i:j] == l:
                    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Sum = 0

for i in range(N+1):
  for j in range(i+5,N+1):
    hoge = S[i:j]
    if int(hoge) % 2019 == 0:
      Sum += 1

print(Sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
c = 0
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        a = int(s[i:j])
        if a>2019:
            if a%2019==0:
                c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
numMultiples=0
S=input()
N=len(S)
seenRemainders=[set()]*(N+1)
for i in range(N):
    remainder = 0
    prefixesFound = 0
    for j in range(i,N):
        remainder = (10 * remainder + int (S[j]) ) % 2019
        if remainder in seenRemainders[j]==True:
            break
        seenRemainders[j].add(remainder)
        if remainder == 0:
            prefixesFound+=1
    numMultiples += prefixesFound * (prefixesFound + 1) / 2
print(int(numMultiples))

Submission status: Time Limit Exceeded

Solution code:
def solve():
    S = input()
    dig = len(S)
    S = int(S)
    count = 0

    for i in reversed(range(dig)):
        for j in range(max(i-8,0),max(i-3, 0)):
            if (S % (10**(dig-j)) //(10 ** (dig-i-1) ))%2019 ==0:
                count += 1
                while True:
                    t = 1
                    if (S % (10**(dig-j-4*t)) //(10 ** (dig-i-1) ))%2019 ==0:
                        count += 1
                        t += 1

    print(count)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
s=input()
c=0
l=len(s)
for i in range(l):
    st=s[i]
    for j in range(i+1,l):
        st=st+s[j]
        I=int(st)
        if(I%2019==0):
            c=c+1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s=input()

if len(s)==4:
    print(0)
    exit()
cnt=0
for i in range(len(s)-4):
    for j in range(i+5,len(s)+1):
        if int(s[i:j])%2019==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

S_len = len(S)
ans = 0

for i in range(S_len - 3):
  for j in range(i+3, S_len+1):
    num = int("".join(map(str, S[i:j])))
    if num % 2019 == 0:
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

sum = [0] # sum[i] := i文字目目までの各桁の和

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

cnt = 0
for i in range(n-4):
    for j in range(i+5, n+1):
        if int(s[i:j]) % 673 == 0:
            if (sum[j] - sum[i]) % 3 == 0:
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 0
s2 = [int(x) for x in s]
table = []
for i in range(len(s2)):
  tmp = 0
  item = []
  for s_ in s2:
    tmp += s_
    item.append(tmp%3)
  s2 = s2[1:]
  table.append(item)


for i in range(len(table)):
  for j in range(len(table[i])):
    if table[i][j] == 0:
      n = int(s[i:j+i+1])
      if n % 673==0:
        count += 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 % 2019 is 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

bai2019 = []

ans = 0

for i in range(1,100):
    bai2019.append(2019*i)

for j in range(4,200001):
    if len(S) >= j:
        for i in range(len(S)-j+1):
            t = int(S[i:i+j])
            if t%2019 == 0:
                ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = list(str(input()))
si = [int(i) for i in s]
a = 0
for i in range(1,len(si)+1):
    if len(si)-i < 3:
        break
    for j in range(i+3,len(si)+1):
        b = 0
        for ix,k in enumerate(reversed(si[i-1:j])):
            b += k * (10**ix)
        if b % 2019 == 0:
            a +=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()
mod1 = 673
mod2 = 3

num1 = 0
num2 = 0
li1 = []
li2 = []
for i, e in enumerate(s, 1):
    num1 *= 10
    num1 += int(e)
    num1 %= mod1
    inv = pow(pow(10, i + 1), mod1 - 2, mod1)
    li1.append(num1 * inv % mod1)

    num2 *= 10
    num2 += int(e)
    num2 %= mod2
    inv = pow(pow(10, i + 1), mod2 - 2, mod2)
    li2.append(num2 * inv % mod2)

li = [0] + [10 * e1 + e2 for e1, e2 in zip(li1, li2)]
c = Counter(li)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
_len = len(s)
ans = 0
head = 0
while head < _len - 3:
  tail = head + 4
  while tail < _len+1:
    if int(s[head:tail]) % 2019 == 0:
      ans += 1
    tail += 1
  head += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = input()
l = len(N)
cnt = 0

for s, e in itertools.combinations(range(l+1), 2):
  if int(N[s:e]) % 2019 == 0 :
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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


total = 0


for i in range(length-1,3,-1):
    going = True
    x = 0
    while going == True:
        if x+i < length:
            temp = ""
            for j in range(i+1):
               temp = temp + S[x+j]
            if int(temp) % 2019 == 0:
                total = total + 1
        else:
            going = False
        x = x + 1


print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys

s = input()

if 4038 > int(s):
  print(0)
  sys.exit()

h = [i for i in range(len(s)+1)]
l = list(itertools.combinations(h, 2))

count = 0
for i in l:
  if int(s[i[0]:i[1]]) % 2019 == 0:
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
n_len = len(n)
count = 0

for i in range(n_len):
    for j in range(i+4, n_len):
        num = int(n[i:(j+1)])
        if num % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
cnt=0

for n in range (len(S)-4):
    for m in range(n+4,len(S)+1):
        if int(S[n:m])%2019==0:
            cnt+=1
        else:
            continue

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
x=0
for j in range(len(s)):
    for i in range(len(s)-j-4):
        a=s[j:j+i+5]
        if int(a) % 2019 ==0:
            x+=1
        else:
            continue
print(x)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s_len = len(s)
    cnt=0
    for i in range(s_len-3):
        for j in range(i+4, s_len+1):
            if int(s[i:j])%673 == 0: 
            	if int(s[i:j])%3 == 0:
              		cnt +=1

    return cnt

if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:

s = input('')
max_s = 200000
rec = 0
for m in (range(max_s+1)):
    ms=str(2019*m)
    idx=0
    while s.find(ms,idx) >= 0:
        rec+=1
        idx=s.find(ms,idx)+1
print(rec)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
n = len(s)

c = 0
for i in range(n-4):
  t = ''
  for j in range(i,n):
    t = t + s[j]
    k = int(t)
    if k%2019 == 0:
      i = j-1
      c += 1
    
    if i == 0 and j == n-1:
      break
      
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
result = []
for i in range(len(s)):
    for j in range(i+4, len(s)+1):
        if sum(map(int, list((s[i:j])))) % 3 == 0:
            if int(s[i:j]) % 673 == 0 :
                result.append((i, j))
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
s = input()
lst = []
for i in range(len(s)):
  n = int(s[i::])
  lst.append(n%2019)
lst.append(0)
lst.sort()
counter = 1
stock = lst[0]
ans = 0
for i in range(1, len(lst)):
  if stock == lst[i]:
    counter += 1
  else:
    ans += counter*(counter - 1)//2
    counter = 1
    stock = lst[i]
if counter >= 2:
  ans += counter*(counter - 1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
L = len(S)
con = 0


for j in range (4,L):
    for i in range (L-j):

        preche = S[i:i+j+1]
        che = int(preche)

        finche = che % 2019

        if(finche==0):
            con += 1

print(con)

Submission status: Time Limit Exceeded

Solution code:
S = input()
listS = list(map(int,list(S)))
ans = 0
for i in range(len(S) - 1):
    mod = int(S[i])
    for j in range(i + 1,len(S)):
        mod  = (10 * mod + int(S[j])) % 2019
        if mod == 0: ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
ls = len(s)
cnt = 0
dp = []
for i in range(ls-3):
    st = int(s[i:i+2])
    if st%2!=0:
        continue
    for j in range(i+3,ls):
        c = int(s[i:j+1])
        if c in dp:
            cnt+=1
        elif c%mod ==0:
            dp.append(c)
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from queue import deque

s = deque(input())
# print(s)
l = []
for i in range(len(s)):
    t = int(''.join(s))
    # print(t)
    while t >= 2019:
        if t>=2019 and t%2019==0:
            l.append(t)
        t = t // 10
        # print(t)
    s.popleft()
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
S = input()

j_max = len(S)

count = 0

for i in range(j_max):
    for j in range(i, j_max):
        target = int(S[i:j + 1])
        if (target % 2019 == 0):
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
answer = 0

for i in range(3, len(s)):
    for j in range(0, len(s) - i):
        num = int(''.join(s[j:(i + j + 1)]))
        if num % 2019 == 0:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

S = sr()
answer = 0
for i in range(len(S)-3):
    num = int(S[i:i+4])
    remain = num % 2019
    if remain == 0:
        answer += 1
    for j in range(i+4, len(S)):
        remain = (remain * 10 + int(S[j])) % 2019
        if remain == 0:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
A = input()
a = int(A)
ans  = 0 

for i in range(len(A)):
    for j in range(i+5,len(A)+1):
        t = A[i:j]
        ans += (int(t)%2019==0)
            # print(t)
# print(ans)

L =[]
for i in range(len(A)):
    t = A[i:i+4]
    L.append(int(t)%2019)
B = 0
for i in range(len(L)):
    T = L[i]
    for j in range(i+1,len(L)-3):
        T = 10*T+int(A[3+j])
        if T%2019==0:
            B+=1
            # print('w',T)
print(B)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
right = n-1
ans = 0

def count(s,i):
    counta = 0
    for left in range(n-i-3):
        k = int(s[left:n-i+1])
        if k%2019==0:
            counta += 1
    return counta


for i in range(2,n-2):
    ans += count(s,i-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(l-4):
    for j in range(i+4, l+1):
        m = int(s[i:j])
        if m % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s = input()
ls = len(s)
l_2019_set = set(list(range(2019, 20190000, 2019)))
ans = 0
for i in range(ls-3):
    for j in range(i+3, ls+1):
        if int(s[i:j]) in l_2019_set:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
for i in range(4, len(S)):
    tmp = 0
    for j in range(len(S) - 1, i - 1, -1):
        if tmp > 0:
            tmp -= 1
            continue
        if int(S[j - i: j + 1]) % 2019 == 0:
            ans += 1
            tmp = i - 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
a = len(str(S))
y = 0
for i in range(a):
    x = ""
    for j in range(i,a):
        x += str(S)[j]
        if int(x)%2019==0:
            y += 1
print(y)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = list(map(int, list(input())))

n = len(s)
memo = [-1 for _ in range(n+1)]
rst = 0
for i in range(n):
    if memo[i] != -1:
        rst += memo[i]
        continue

    tmp = 0
    _memo = []
    for j in range(n-i):
        tmp += s[i+j]
        tmp %= 2019
        if tmp == 0:
            rst += 1
            _memo.append(i + j)
        tmp *= 10

    m = len(_memo)
    if m >= 1:
        for k, idx in enumerate(_memo):
            memo[idx+1] = m - k - 1

print(rst)

Submission status: Time Limit Exceeded

Solution code:
# ABC164d


def main():
    import sys
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    def dump(*args):
        sys.stderr.write(str(args))

    s = input()

    def prime_factorize(n):  # 素因数分解
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a

    n = len(s)
    c = 0
    # for i in range(4, n + 1):
    #    for j in range(n - i+1):
    #        if int(s[j: j + i]) % 2019 == 0:
    #            c += 1
    import math

    def c_count(n, r):  # 組み合わせ
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    counter = [0] * 2019
    #counter2 = [0] * 2019
    for i in range(n):
        num = int(s[n - i - 1:])
        # print(num)
        counter[num % 2019] += 1
        #counter2[num % 673] += 1
    counter[0] += 1
    #counter2[0] += 1

    # print(counter)

    for i in range(len(counter)):
        num = counter[i]
        if num >= 2:
            c += c_count(num, 2)

    print(c)

    #c2 = 0
    # for i in range(len(counter2)):
    #    num = counter2[i]
    #    if num >= 2:
    #        c2 += c_count(num, 2)

    #print(c, c2)

    # print(prime_factorize(2019))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0
is_end = [False] * (len(S) + 1)
for i in range(len(S)):
    if is_end[i]:
        continue
    is_end[i] = True
    bingo = [i]
    for j in range(i+1, len(S)+1):
        if is_end[j]:
            continue
        if int(S[i:j]) % 2019 == 0:
            is_end[j] = True
            bingo.append(j)
    l = len(bingo)
    if l >= 2:
        cnt += int(l*(l-1)/2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve(s):
    N = len(s)
    ans = 0
    if N < 4:
        return 0

    for i in range(4,N+1):
        for j in range(N-i+1):
            ans += 1 if int(s[j:j+i])%2019==0 else 0
    return ans

S = str(input())    
print(solve(S))

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    s = input()
    dp = {}
    ans = 0
    calc = [[(i + j * 10) % 2019 for j in range(2030)] for i in range(10)]
    for c in map(int, s):
        if 0 not in dp:
            dp[0] = 0
        dp[0] += 1
        dp = {calc[c][k]: v for k,v in dp.items()}
        if 0 in dp:
            ans += dp[0]
    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()
intS = list(map(int, S))
n = len(S)

fl = [False]*n
l = 0
res = 0

for i in range(n-3):
    if fl[i]:
        continue
    
    x = int(S[i:i+3])
    l = 0
    cnt = 0
    for j in range(i+3, n):
        x *= 10
        x += intS[j]
        x %= 2019
        if x == 0:
            cnt += 1
            fl[l] = True
            l = j+1
    
    res += (cnt+1)*cnt//2

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0
ln = len(S)

for i in range(ln-3):
    T = S[i:]
    for j in range(i+4,ln+1):
        #print(S[i:j])
        tmp = int(T[:j])
        if tmp % 3 == 0:
            if tmp % 2019 == 0:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S0 = int(input())
total = 0
S = []
while S0 > 0:
    S.append(S0%10)
    S0 //= 10
for i in range(len(S)-1,2,-1):
  n = S[i]*100 + S[i-1]*10 + S[i-2]
  for j in range(i-3,-1,-1):
    n = n*10 + S[j]
    if n % 2019 == 0:
      total += 1
print(total)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
str_len = len(S)
X = 0

if len(S) >= 4:
    for i in range(4,str_len + 1):
        for j in range(str_len - i + 1):
            if int(S[j:j+i]) % 2019 == 0:
                X += 1

print(X)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
S = list(map(int,input().rstrip()))
result=0
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        n = reduce( lambda a,b:10*a+b, S[i:j])
        if n %2019==0:
            result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

def is_3bai(n):
    if n % 3 == 0:
        return True
    else:
        return False

def is_673bai(n):
    if n % 673 == 0:
        return True
    else:
        return False

def ketawa(string):
    res = 0
    for s in string:
        res += int(s)
    return res

sl = len(s)
res = 0
if sl >= 4:
    for i in range(sl - 4 + 1):
        sum_part = ketawa(s[i:i+3])
        for j in range(i + 3, sl):
            sum_part += int(s[j])
            if is_3bai(sum_part):
                part = s[i:j+1]
                if is_673bai(int(part)):
                    res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
import itertools
s=input()
l=len(s)
ans=0
for i,j in  itertools.product(range(0,l-3),range(1,l)):
    if j<i:
        continue    
    test=int(s[i:j+1])
    if test%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
d=0
for i in range(0,len(s)-4):
    c=0
    for j in range(i,len(s)):
        c=c*10+int(s[j])
        if c%2019==0:
            d+=1
    if c%2019==0:
        i+=1
print(d)

Submission status: Time Limit Exceeded

Solution code:
def main():
    from builtins import input,str,len,int,range
    s = input()
    ss = str(s)
    s_l = len(s)
    s = int(s)
    print(len([0 for x in range(s_l) for y in range(x+4, s_l+1) if not int(ss[x:y]) % 2019]))
main()

Submission status: Time Limit Exceeded

Solution code:
n=input()
s=0
x=0
li=[]
ans=0
for i in range(len(n)-3):
  for j in range(4,len(n)+1):
    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()

L = []
for i in range(len(S)+1):
  for j in range(len(S)+1):
    if i<j:
      if int(S[i:j])>2018:
        L.append(S[i:j])

B = list(map(int,L))
A = list(filter(lambda x:x%2019==0,B))
print(len(A))

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

counter = 0
for start in range(len(S)):
    for end in range(len(S)+1):
        if start < end:
            target = S[start:end]
            if (int(target) % 2019) == 0:
                counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())  #文字列の一文字ずつリストに

nums = []


for i in range(1,200000 // 2019 + 1):
    nums.append(2019*i)
        
#print(nums)

ans = 0
for j in range(len(S) - 4):
    for i in range(4, len(S) + 1 - j):
#        print(j,j + i)
#        print(S[j:j + i])
        A = (''.join(S[j: j + i]))
        #print(A)
        if int(A) in nums:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

ans = 0

for r in range(1, n-2):
	for l in range(r+3, n+1):
		if int(s[-l:-r]+s[-r])%2019 == 0:
			ans += 1

print(ans)

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):
		s = S[i:j]
		if int(s) % 2019 == 0:
			res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

#N = str(14282668646)

count = 0
lenN = len(N)+1
for i in range(0, lenN):
    for j in range(i+5, lenN):
#        print (i, j)
        number = int(N[i:j])
        if number%2019 == 0:
            count +=1
            break
#            print (i, j)
#T = int(N)//2019
#
#for t in range (T):
#    den = 2019*t
#    length = len(str(den))
#    sum_length = len(N)
#    for i in range(sum_length-length):
#        if den == int(N[i:i+length]):
#            count +=1

print (count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def f(s,l):
    for i in range(len(s)):
        if s[i] == l:
            return False
    return  True

s = list(input())
pair = [[]]
result = 0

for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        if int("".join(s[i:j])) % 2019 == 0 and f(pair,[i,j]):
            pair.append([i,j])
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sl = []
pre = 0
answer = 0
for i, s in enumerate(S):
    if i ==0:
        Sl.append(pre)
        Sl.append(pre+int(s))
        pre += int(s)
    else:
        Sl.append(pre+int(s))
        pre += int(s)


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

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(str(s))
result = 0
for i in range(5,l+1):
    t = s[0:i]
    for j in range(l-i+1):
        r = s[0+j:i+j]
        if int(r) % 2019 ==0:
            result +=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
number = str(input())
keta = len(number)

match = 0
for start in range(1, keta):
  for end in range(start+3, keta+1):
    kazu = int(number[start-1:end])
    if kazu % 2019 == 0:
      match += 1
print(match)