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 = str(input())
ans = 0

for start in range(len(s)):
    for end in range(start + 4, len(s) + 1):
        if int(s[start:end]) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = [int(x) for x in list(str(input()))]
c = 0
for i in range(len(s)):
    for j in range(i+1,len(s)+1):
        jl = s[i:j]
        jn = int(''.join([str(n) for n in jl]))
        if jn % 2019 == 0:
            c+=1
print(c)

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 collections import deque

s=input() 
cnt = 0
que = deque()
for i in range(len(s)):
    que.append(s[i])
l = []
tmp = ''

for i in range(len(s)):
    for j in range(len(que)):
        l.append(que[j])
        for k in range(len(l)):
            tmp = str(tmp) + str(l[k])
        tmp = int(tmp)
        if tmp % 2019 == 0:
            cnt = cnt + 1
        tmp=''
    l=[]
    que.popleft()

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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)):
        if int(S[i:j + 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
num_list = []
while n <= len(s):
    num_list.extend(n_gram(s,n))
    n += 1

for num in num_list:
    if num % 2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
# S = int(s)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count = 0

for i in range(n):
  for j in range(i + 4, 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)
dp = [0]*(N+1)
for j in range(3,N):
    add = 0
    for i in range(0,j-3):
        if(int(S[i:j+1])%2019 == 0):
            add += 1
    dp[j+1] = dp[j]+add
print(dp[N])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
ans=0
if int(s)<2019: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:ans+=1
    print(ans)

Submission status: Time Limit Exceeded

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

count = 0

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

Submission status: Time Limit Exceeded

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

s = input()
mul(s)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sint = int(S)
i = 1
ans = 0
while i * 2019 < Sint:
    ans += S.count(str((i * 2019)))
    i += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

remain = [0]*2020
now = 0
ans = 0
for i in range(len(s)-1, -1, -1):
    now += int(s[i])*pow(10, len(s)-i-1)
    ans += remain[now%2019]
    remain[now%2019] += 1

ans += remain[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

length = len(S)
ans = 0

for i in range(length - 4):
    j = i + 4
    while j <= length:
        num = int(S[i:j])
        #  print(num)
        j += 1
        if num % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

res = 0

for i in range(l+1):
  for j in range(l+1):
    if len(s[i:j]) >= 4:
      if int(s[i:j]) % 2019 == 0:
        res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

counter = 0
for i in range(N-3):
    for j in  range(i+3,N):
        s = int(S[i:j+1])
        m = s % 2019
        if m == 0:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
a = input()
b = len(a)

total = 0
for i in range(b-1):
    for j in range(b-i):
        s = int(a[i:(j+i+1)])
        if s % 2019 == 0:
            total += 1

print(total)

Submission status: Time Limit Exceeded

Solution code:
S = input()

lenS = len(S)

sweep = 4
flag = 0
ans = 0

if lenS < 3:
    print(0)
else:
    while sweep <= len(S):
        for i in range(lenS - sweep + 1):
            if int(S[i:i + sweep]) % 2019 == 0:
                ans += 1
        sweep += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
C = [int(S[-(i + 1):]) % 2019 for i in range(len(S))]
Cd, C0 = {}, 0
for c in C:
    if c == 0:
        C0 += 1
    else:
        Cd[c] = Cd.get(c, 0) + 1
print(C0 + sum([v * (v - 1) // 2 for v in Cd.values()]))

Submission status: Time Limit Exceeded

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

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

# 2019 = 3, 673

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
i = 0
j = 4
c = 0

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

Submission status: Time Limit Exceeded

Solution code:
import sys
S = sys.stdin.readline().rstrip()
N = len(S)
ans = 0

if int(S) < 2019:
    print(0)
    exit()

for i in range(N - 3):
    for k in range(4, N + 1):
        j = i + k
        if j <= N and int(S[i:j]) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()
s = len(S)

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

Submission status: Time Limit Exceeded

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

cnt = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

S = read().decode().rstrip()

l = 0

cnt = 0
while l < len(S):
    r = l + 3
    while r < len(S):
        acc = S[l:r + 1]
        if int(acc) % 2019 == 0:
            cnt += 1
        r += 1
    l += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
ans = 0
for i in range(l):
    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 = str(input())
L = len(S)

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

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=len(s)
ans=0
for i in range(n-4):
    for j in range(i+4,n+1):
        if int(''.join(s[i:j]))%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+3,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()

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

Submission status: Time Limit Exceeded

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

for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        n=int(''.join(s[i:j+1]))
        if n%2019==0 and n>=2019:
            ans+=1
            
print(ans)

Submission status: Time Limit Exceeded

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

print(count1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc164/tasks/abc164_d

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
counter = 0
#iは切り出す文字列の長さ
for i in range(1,L):
    for j in range(L-i+1):
        if int(S[j:i+j]) % 2019 == 0:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    s = input()
    check = 2019
    ret = 0

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

    return ret


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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = 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()
N=len(S)

l=[]

if N < 4:
    ans=0
else:
    ans = 0
    for i in range(N-3):
        for j in range(i+3,N):
            s=S[i:j+1]
            if s in l:
                ans +=1
            elif (int(s))%2019==0:
                ans +=1
                l.append(s)
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
seped = [[],[]]
for i in range(len(S)-3):
  pp = 0
  if i in seped[0]:
    for j in range(len(seped[0])):
      if i == seped[0][j]:
        pp = seped[1][j]
  for j in range(i+4,len(S)+1):
    t = int(S[i:j])
    if t % 2019 == 0:
      seped[0].append(j)
      seped[1].append(1+pp)
      count += 1+pp
      break
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()
def main():
    S = input()
    cnt = 0
    for i in range(len(S)):
        for j in range(i+4,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()

count = 0
for times in range(1, 101):
    num = 2019 * times
    num_length = len(str(num))
    for i in range(len(S) - 3):
        for j in range(i + 3, len(S)):
            if j-i+1 != num_length:
                continue
            sub_S = int(S[i:j+1])
            if num == sub_S:
                count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    a = input()
    count = 0
    compare = 0
    for i in range(len(a)-3):
        for j in range(i+3,len(a)):
            for k in range(i,j+1):
                compare+=int(a[k])*10**(j-k)
            if compare%2019==0:
                count+=1
            compare = 0;
    print(count)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s) 
ls = [0]*(n+1)

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

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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

s = input()

# a = [
#     0, 2019, 4038, 6057, 8076, 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
# ]

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(str(input()))]
ans=0
for i in range(1,len(s)+1):
    for j in range(i+3,len(s)+1):
        figure=0
        for k in range(j-i+1):
            figure+=s[-(i+k)]*10**k
        if(figure%2019==0):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

s = input()
l = len(s)
cnt = 0

for i in range(l):
    for j in range(i+4,l):
            a = int(s[i:j+1])
            if a % 2019 == 0 and j < l:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(str,input()))

counter = 0

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input().strip()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=list(str(input()))
t=0
cnt=0
for i in range(len(s)):
  S=s[i]
  while t+i+3<len(s):
    if t==0:
        S+=s[t+i+1]+s[t+i+2]+s[t+i+3]
    else:
        S+=s[t+i+3]
    #print(S)
    if int(S)%2019==0:
      cnt+=1
    t+=1
  t=0
  #print(i,cnt)
print(cnt)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())

S = str(S)
s = len(S)
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

num = input()
count = 0

if len(num) <= 3:
    count = 0
else:
    for i in range(len(num) - 3):
        for j in range(len(num) - 2 - i):
            if int(num[j:j + (i + 3)]) % 2019 == 0:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

s = input()
ans = 0
for i in range(len(s) - 4):
    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:
s = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

##### 割り算の切り上げ #####
# tmp = -(-4 // 3)

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	S = input()
	S = S[:-1]
	S = list(S)

	target = 4
	ans = 0
	for i in range(target,len(S)):
		for j in range(len(S)):
			if i+j > len(S):
				break
			tmp = S[j:j+i]
			tmp_int = int(''.join(tmp))
			if tmp_int % 2019 == 0:
				ans += 1

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

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)):
    strNum=''
    for n in range(i,j+1):
      strNum+=S[n]
    num=int(strNum)
    if(num%2019==0):
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
# s = '14282668646'

length = len(s)

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
N = len(s)
#2019の倍数になる連続した値をさがす
n = []
a = 1
while 2019 * a < 2 * 10 ** 5:
    n.append(str(2019*a))
    a += 1
ans = 0
for i in range(N-3):
    number = s[i:i+3]
    for j in range(i+3, N):
        number += s[j]
        if number in n: 
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#author: raghav_0901
from math import *

mod = 998244353


def CountOccurrences(string, substring):
    if(len(substring) > len(string)):
        return 0
    count = 0
    start = 0
    while start < len(string):

        pos = string.find(substring, start)

        if pos != -1:
            start = pos + 1

            # Increment the count
            count += 1
        else:
            # If no further substring is present
            break
    # return the value of count
    return count


def _in():
    return [int(x) for x in input().split(' ')]


if __name__ == "__main__":
    s = input()
    ans = 0
    for i in range(1, 2000001):
        ans += CountOccurrences(s, str(2019 * i))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
for i in range(0,N,1):
    X = int(S[N-i-1::]) % 2019
    if X==0:
        counter+=1
    counter += mem_mod[X]
    mem_mod[X] += 1
print(counter)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

amari=[0]*(N+1)
num=0
for i in range(N):
    d.append(int(S[i]))
#print(d)
for i in range(N):
    n=d.pop()
    num=(num+pow(10,i)*n)%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()
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()
s=0
for i in range(len(S)):
  for j in range(i+1,len(S)):
    n=int(S[i:j+1])
    if n%2019==0:
      s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ans)

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):
        n = int(S[i:j])
        ans += n % 2019 == 0

print(ans)

Submission status: Time Limit Exceeded

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

counter = 0
for i in range(N-3):
    for j in  range(i+3,N):
        s = int(S[i:j+1])
        m = s % 2019
        if m == 0:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=len(str(n))
c=0
for i in range(1,l-2):
    for j in range(i+3,l+1):
        if int(str(n)[i-1:j])%2019==0:
            c+=1
            #print(i,j)
            #print(str(n)[0:j])
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 int(s[i:j]) % 2019 == 0 :
            result.append((i, j))
print(len(result))