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:
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
s = list(SI())
le = len(s)
l = []
count = 0
for i in range(100):
	l.append(list(str((i+1)*2019)))
for i in l:
	aa = len(i)
	for j in range(le-aa+1):
		boo = True
		for z in range(aa):
			if s[j+z]!=i[z]:
				boo = False
		if boo:
			count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

  chk = [str((i+1)*2019) for i in range(1000)]
  ans = 0
  for i in range(4,len(s)+1):
    for j in range(len(s)-i+1):
      c = s[j:j+i]
      if c in chk:
        ans += 1
  print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

base=1
for i in range(length+1):
    mod=(S%base)%2019
    count[mod]+=1
    base*=10


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
s = input()
sur = []
n = len(s)
p = 2019
ans = 0
for i in range(n-1, -1, -1):
    sur += [int(s[i:]) % p]

d = defaultdict(int)
for x in sur:
    d[x] += 1

for k,v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        ans += v * (v-1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
dp = [[-1 for i in range(len(S))] for j in range(len(S))]

ans = 0

for i in range(len(S)):
    for j in range(len(S)):
        if dp[i][j]!=-1:
            continue
        else:
            if j<i+3:
                dp[i][j]=0
            else:
                num = int(S[i:j+1])
                if num%2019==0:
                    dp[i][j]=1
                    ans+=1
                    for w in range(-3,4):
                        if j+w>=0 and j+w<len(S):
                            dp[i][j]=0
                
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections as c

S = input()
N = len(S)
MOD = 2019
dp = [0] * (len(S))
dp[0] = int(S[-1])
for i in range(1,N):
    tmp = (int(S[-(i+1)]) * (10 ** i)) % 2019
    dp[i] = dp[i-1] + tmp
    dp[i] %= 2019 

D = c.Counter(dp)
ans = 0
for k,v in zip(D.keys(),D.values()):
    if k == 0:
        ans += v
        ans += v * (v - 1) //2
    elif v >= 2:
        ans += v * (v - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=len(S)
ans=0
dp=[]
for i in range(2019):
  dp.append([])
  for j in range(n):
    dp[i].append(0)
dp[int(S[0])][0]=1
for i in range(1,n):
  dp[int(S[i])][i]=1
  for j in range(2019):
    dp[(10*j+int(S[i]))%2019][i]+=dp[j][i-1]
  ans+=dp[0][i]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
s_l = len(str(S))
l = [];l_a = l.append
for x in range(s_l):
    for y in range(x+3, s_l+1):
        if not int(str(S)[x:y]) % 2019:
            l_a((x,y))
print(len(l))

Submission status: Time Limit Exceeded

Solution code:
a=input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019

S = input()
N = len(S)
cnt = 0
for i in range(N):
    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()

cnt = 0
for i in range(len(s)):
    for j in range(len(s)):
        if (i + 2) < j:
            num = int(s[i:j+1])
            if num % 2019 == 0:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math


def main():
    s = input()
    s_len = len(s)
    ans = 0
    for i in range(s_len):
        for j in range(i, s_len+1):
            if i == j:
                continue
            num = int(s[i:j])
            if num < 2019:
                continue
            if num % 2019 != 0:
                continue
            ans += 1
    print(ans)


def input_list():
    return list(map(int, input().split()))


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def i1str():
    return input()


def istrs(n=None):
    if n is None:
        return input().split()
    a = []
    for _ in range(n):
        a.append(istrs())
    return a


def i1num():
    return int(input())


def inums(n=None):
    if n is None:
        return list(map(int, input().split()))
    a = []
    for _ in range(n):
        a.append(inums())
    return a


def ostrs(l, sp=" "):
    print(sp.join(l))


def onums(l, sp=" "):
    print(sp.join(map(str, l)))


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


if __name__ == "__main__":
    s = i1str()
    print(solve(s))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
def get_2019():
    all = input()
    total = 0

    for n in range(len(all)):
        i=4
        x=total
        while n+i<=len(all):
            cut = float(all[n:n+i])
            if cut%2019 == 0:
                total+=1
                break
            else:
                i+=1
    print(total)

    return None
get_2019()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-04-26 21:06

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    n = len(s)
    now = 0
    m = [0] * 2019
    for i, si in zip(range(n), s[::-1]):
        now = (now + int(si) * (10**i)) % 2019
        #print(now)
        m[now] += 1
    ans = m[0]
    for mi in m[1:]:
        ans += (mi-1) * mi //2
    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools

def main():
    s = input().rstrip()

    s_l = len(s)

    s_nums = list(range(len(s)+1))

    ans = 0

    for i_1, i_2 in itertools.combinations(s_nums,2):
        if int(s[i_1:i_2]) % 2019 == 0:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: int):
    S = [int(s) for s in str(S)]

    magic = lambda nums: sum(digit * 10 ** (len(nums) - 1 - i) for i, digit in enumerate(nums))

    count = 0
    for i in range(len(S)-1):
        for j in range(i+3, len(S)):
            lst = S[i:j+1]
            num = magic(lst)
            if num % 2019 == 0:
                count += 1

    print(count)
    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 = input()
N = len(S)

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    from collections import defaultdict
    S=sys.stdin.readline().strip()
    L=[0]*len(S)
    for i in range(len(S)):
        L[-i-1]=int(S[-i-1:])%2019

    dic=defaultdict(int)
    for a in L:
        dic[a]+=1

    
    output=0
    for _,val in dic.items():
        output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()

Submission status: Time Limit Exceeded

Solution code:
import math
import fractions
import collections
import itertools
from collections import deque
S=input()
N=len(S)
cnt=0

amari=[0]*(N+1)
num=0
for i in range(N):
    num=(num+pow(10,i)*int(S[N-1-i]))%2019
    amari[i+1]=num
#print(amari)
c=collections.Counter(amari)
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)

#for i in range(len(key)):
#    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
#xprint(l)
for i in range(len(values)):
    cnt=cnt+(values[i]*(values[i]-1))//2
print(cnt)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(4, len_S+1):
  for j in range(len_S+1-i):
#    print(S[j:j+i])
    if int(S[j:j+i]) % 2019 == 0:
      count += 1
  
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

for a in range(len(S)):
  for b in range(a+1, len(S)+1):
    d = int(S[a:b])
    if d % 2019 == 0:
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
s_len = len(s)
n = 2019
n_len = len(str(n))
result = 0
for i in range(s_len - n_len):
    for j in range(i + n_len, s_len + 1):
        m = int(s[i:j])
        if m % n == 0:
            result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
a=0
b=[0]*2019
for i in S:
    l=[None]*2019
    k=int(i)
    for j in range(2019):
        l[(j*10+k)%2019]=b[j]
    l[k]+=1
    a+=l[0]
    b=l
print(a)

Submission status: Time Limit Exceeded

Solution code:
myWord = input()
lastChar = len(myWord)
answer = 0

for i in range(lastChar):
    for j in range(i + 3, lastChar):
        num = int(myWord[i:j + 1])
        if (num % 2019 == 0):
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    for j in range(i, n):
        temp = int(s[i:j + 1])
        if temp % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
#input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    S = input()
    
    base = 1
    cum = 0
    d = defaultdict(int)
    d[0] = 1
    ans = 0
    
    for st in S[::-1]:
        num = (int(st)*base)%2019
        base *= 10
        cum += num
        ans += d[cum%2019]
        d[cum%2019] += 1

    print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
str = str(input())

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

n = len(S)
r = 0
l = 4
ans = 0
for i in range(l,n):
    while r <= n-4:
        s = int(S[r:l])
        ans += 1 if s % 2019 == 0 else 0
        if l < n:
            l += 1
        else:
            r += 1
            l = r + 4
            
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    cnt = 0
    for i in range(len(s)-1):
        for j in range(i, len(s)+1):
            if i == j : continue
            tmp = s[i:j]
            if int(tmp) % 2019 == 0:
                cnt += 1
    print(cnt)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
se = {i * 2019 for i in range(100)}
count = 0
for i in range(n - 3):
    for j in range(i + 4, n + 1):
        a = int(s[i:j])
        if a in se:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
length=len(S)
S=int(S)
count=[0 for i in range(2019)]

for i in range(length+1):
    mod=(S%(10**i))%2019
    count[mod]+=1


retval=0
for key in range(2019):
    retval+=count[key]*(count[key]-1)//2

print(retval)

Submission status: Time Limit Exceeded

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


def solve(S: str):
    sl = [int(S[i]) for i in range(len(S))]
    ct = 0
    for i in range(len(S)):
        crt = sl[i]
        for j in range(i, len(S)):
            if i != j:
                crt *= 10
                crt += sl[j]
            # s = S[i:(j+1)]
            # si = int(s)
            if crt % 2019 == 0:
                ct += 1
    print(ct)
    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
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
problemInput = input()
count = 0

for i in range(1, len(problemInput)):
    for j in range(0, i):
        temp_str = problemInput[j: i+1]
        tempNum = int(temp_str)

        if tempNum % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math


def main():
    s = input() * 10000
    s_len = len(s)
    ans = 0
    for i in range(s_len):
        for j in range(i, s_len+1):
            if i == j:
                continue
            num = int(s[i:j])
            if num < 2019:
                continue
            if num % 2019 != 0:
                continue
            ans += 1
    print(ans)


def input_list():
    return list(map(int, input().split()))


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019

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

print(cnt)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(l):
    j = i+1
    while j <= l:
        num = int(s[i:j])
        if num != 0 and num % 2019 == 0:
            count += 1
        
        j += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
s=0

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

print(s)

Submission status: Time Limit Exceeded

Solution code:
#create date: 2020-04-26 21:06

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    s = ns()
    n = len(s)
    now = 0
    m = [0] * 2019
    for i in range(n):
        now = (now + int(s[n-i-1]) * (10**i)) % 2019
        #print(now)
        m[now] += 1
    ans = m[0]
    for mi in m[1:]:
        ans += (mi-1) * mi //2
    print(ans)

    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
s += '0'



mod = 2019
cnt = {}
ans = 0
p = 0
x = 0
for i in range(len(s)-1,-1,-1):
    m = int(s[i])
    
    
    x = (m*(10**(len(s)-i))+ x )%mod
    if x not in cnt:cnt[x] = 0
    ans += cnt[x]
    cnt[x] +=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import queue
import copy
import math
from collections import deque
import bisect

# そのまま入力文字列の入力
s = input()

ans = 0
for i in range(0, len(s) - 1):
    for j in range(i + 2, len(s) + 1):
        num = int(s[i:j])
        d, m = divmod(num, 2019)
        if m == 0:
            ans += 1
        else:
            pass

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=0
now=1
l=[0]*2019
for i in list(s)[::-1]:
    a=a+now*int(i)
    l[a%2019]+=1

    now*=10





ans=0

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()

    len_s = len(s)

    if len_s <=3:
        print(0)
        exit()
    
    count = 0

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

    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
# input処理を高速化する
input = sys.stdin.readline

S=input()
N=len(S)

number=''
cnt=0
for i in range(N-2):
    for j in range(i+4,N):
        number=S[i:j]
        if int(number)%2019 ==0:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
    s = list(map(int,input()[::-1]))

    t = []
    m = 0
    for i,s_i in enumerate(s):
        m = m+s_i*10**i
        t.append(m%2019)
    
    c = Counter(t)
    ans = c[0]
    for i in c.values():

        ans += i*(i-1)//2
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

S = input()

cnt = 0
for i in range(len(S) - 3):
    for j in range(i + 3, len(S)):
        p = S[i:j+1]
        v = int(p)
        if v % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
b=0
m=len(s)
for i in range(m-3):
    a=s[i]+s[i+1]+s[i+2]
    
    for j in range(i+3,m):

        a=a+s[j]
        a=int(a)

        if a%2019==0:
            b+=1
        a=str(a)
print(b)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(4,l):
    for k in range(0,l-i+1):
        ss = int(s[k:k+i])
        if ss% 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
import sys
l = len(S)
if l <= 3:
    print(0)
    sys.exit(0)

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
n = len(s)
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
lns=len(s)
kaz=2019
now=[0]*kaz
next=[0]*kaz
answer=0
for i in range(lns):
    next=[0]*kaz
    for j in range(kaz):
        next[(int(s[i])+(j*10))%kaz]=now[j]
    now=next
    now[int(s[i])]+=1
    answer+=now[0]

print(answer)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

s=input()
n=len(s)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def n_gram(target,n):
    return [int(target[idx:idx + n]) for idx in range(len(target) - n + 1)]

count = 0
s = input()
n = 4
while n <= len(s):
    for num in n_gram(s,n):
        if int(num) % 2019 == 0:
            count += 1
    n += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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