Problem:


Score : 400 points

Problem Statement

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

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
s = input()

keta = len(s)

count = 0

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

Submission status: Time Limit Exceeded

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

cnt = 0
i = 2019
while i < s:
  if (str(i) in str_s):
  	cnt += 1
  i += 2019

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
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
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

ans = 0
for i in range(len(S)):
  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 = input()
mod_dict = {}

mod_rev = []
for i in range(len(s)-1, -1, -1):
    current_num = int(s[i:len(s)])
    if (current_num%2019 in mod_dict.keys()):
        mod_dict[current_num%2019].append(i)
    else:
        mod_dict[current_num%2019] = [i]

count = 0
for k in mod_dict.keys():
    n = len(mod_dict[k])
    count += int(n*(n-1)/2)
    if (k == 0):
        count += n
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+3, len(S)):
        substring = int(S[i:j+1])
        if substring % 2019 == 0:
            ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

length = len(S)
count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

S = input()
count = 0

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
l = list(input())
amari = [0]*len(l)
mod = 2019
import math
for i in range(len(l)):
    amari[i] = int(l[i])*(10**(len(l)-1-i)) % mod
rui = [0]*len(l)
rui[len(l)-1] = amari[-1]
for i in range(len(l)-2,-1,-1):
    rui[i] = rui[i+1] + amari[i]
count = [0]*2020
for i in range(len(l)):
    count[rui[i]%2019] += 1
ans = 0
for i in range(1,2020):
    if count[i] == 0 or count[i] == 1:
        continue
    ans += count[i] * (count[i]-1)//2
ans += count[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

c = 0
x = 0
for x in range(len(S)*10):
    s = str(2019*x)
#    print (s)
    if s in S:
#        print (2019*i,S.count(str(2019*i)))
#        c += S.count(str(2019*i))
        for i in range(0,len(S)-3):
            for j in range(i+4,len(S)+1):
                t = S[i:j]
                if t == s:
                    c += 1

print (c)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from math import ceil

def main():
    string = stdin.readline()

    new_string = ""
    for char in string:
        if char in "123456789":
            new_string += char

    count = 0

    pos_start = 0
    for start in new_string:
        pos_end = pos_start + 2
        for end in new_string[pos_start+1:]:
            if (int(new_string[pos_start:pos_end]) % 2019) == 0:
                count += 1 
            pos_end += 1
        pos_start += 1

    print(count)

main()

Submission status: Time Limit Exceeded

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

# -- submit ----

# --- fetch input ---
inputs: list = []
while True:
    try:
        inputs.append(input().strip('\n'))
    except EOFError:
        break

# --- write code below ---

n = int(inputs[0])
max_n = len(str(n)) if len(str(n)) < 200000 else 200000


def check(window_width, cou):

    if window_width < 4:
        print(cou)
        return None

    for i in range(max_n - window_width + 1):
        if int(str(n)[i: i + window_width]) % 2019 == 0:
            cou += 1

    check(window_width - 1, cou)


check(max_n, 0)

Submission status: Time Limit Exceeded

Solution code:

def main():
    S = input()
    cnt = 0
    if len(S) < 4:
        return 0
    for j in range(4, len(S)):
        for i in range(0, len(S)-j+1):
            num = S[i:i+j]
            #print(num)
            num = int(num)
            if num % 2019 == 0:
                cnt += 1
    return cnt

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

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
print(d)

Submission status: Time Limit Exceeded

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

main()

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:
MOD=2019

S=list(int(s) for s in input()[::-1])
T=[S[0]]
for i in range(1,len(S)):
    T.append(T[-1]+S[i]*(10**i))
cnt={}
for i in range(2019):
    cnt[i]=0
for t in T:
    cnt[t%MOD]+=1
ans=0
for i in range(2019):
    c=cnt[i]
    if c>=2:
        ans+=c*(c-1)//2
ans+=cnt[0]
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
num = []
cnt = [0] * 2019
for i in range(N):
    num.append(int(S[i:]))
    cnt[num[i] % 2019] += 1
for i in range(N):
    ans += cnt[i] * (cnt[i] + 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
S = input()
dict_amari = {}
count = 0

def amari_new(dict_amari, s):
  dict_amari_new = {(10*k+s)%2019 : v for k,v in dict_amari.items()}
  if s in dict_amari_new.keys():
    dict_amari_new[s] += 1
  else:
    dict_amari_new[s] = 1
  return dict_amari_new

for s in S:
  dict_amari = amari_new(dict_amari, int(s))
  if 0 in dict_amari.keys():
    count += dict_amari[0]

print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

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

ans = 0
for a in ls:
  ans += a*(a-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC 164D

s = str(input())

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = list(S)
result = []
for i in range(len(s)):
    j = 4
    while i+j <= len(s):
        s2 = int(''.join(s[i:i+j]))
        if s2%2019 == 0:
            result.append((i+1,i+j))
        j += 1
print(len(result))

Submission status: Time Limit Exceeded

Solution code:
s = input()
k = 2019

numMultiples = 0
n = len(s)
seenRemainders = [set() for _ in range(n)]
for i in range(n):
    remainder = 0
    prefixesFound = 0
    for j in range(i, n):
        remainder = (10 * remainder + int(s[j])) % k
        if remainder in seenRemainders[j]:
            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:
s=input()
List=[0]*len(s)
List[0]=int(s[0])*(10**(len(s)-1))
for i in range(len(s)-1):
  List[i+1]=List[i]+int(s[i+1])*(10**(len(s)-2-i))
count=0
List.insert(0,0)
for i in range(len(s)+1):
  for j in range(i+1,len(s)+1):
    if (List[j]-List[i])%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+4,len(s)+1):
        if int(s[i:j])%2019==0:
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


S = input()
N = len(S)

L = [0] * (N + 1)
s = 0
for i in range(N):
    s += int(S[N - 1 - i]) * pow(10, i)
    L[i + 1] = (s % 2019)

C = Counter(L)
cnt = 0
for key in list(C.keys()):
    k = C[key]
    cnt += (k * (k - 1)) // 2

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

s = input()
ans =0
nums =""
for i in range(len(s)):
    for j in range(i+3,len(s)):
        """for k in range(i,j+1):
            nums += s[k]"""
        num =int(s[i:j+1])
        #nums=""
        if num%2019==0:
            ans+=1
            #print(i,j,num)



print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

length = len(S)

cnt = 0
for x in range(length):
    temp = int(S[x : x + 4])
    for i in range(x + 4, length + 1):
        if temp % 2019 == 0:
            cnt += 1
        #print(temp, cnt)

        if i < length:
            temp = temp * 10 + int(S[i])

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
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 = input()
len_s = len(s)
res = 0
num = 0
for i in range(len_s):
  if i+3 >= len_s:
    break
  for j in range(i+3, len_s):
    use_s = int(s[i:j+1])
    res += int(use_s%2019==0)
    num+=1
print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

answer = 0

for start in range(N-3):
    for end in range(start+3,N+1):
        if int(S[start:end]) % 2019 == 0:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
def countSubStr(str1, l, k): 
    count = 0
  
    for i in range(l): 
        n = 0
  
        # Take all sub-strings starting from i 
        for j in range(i, l, 1): 
            n = n * 10 + (ord(str1[j]) - ord('0')) 
  
            # If current sub-string is divisible by k 
            if (n % k == 0): 
                count += 1
      
    # Return the required count 
    return count 
  
# Driver code 
 
str1 = str(input())
l = len(str1) 
k = 2019
print(countSubStr(str1, l, k))

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate
s = input()
l = len(s)
if 4>l:
    print(0)
    exit()
c = 0
a = [0] + list(accumulate(map(int, list(s))))
for i in range(l-3):
    for j in range(i+4, l):
        if (a[j+1] - a[i]) % 3 == 0:
            if int(s[i:j+1]) % 673 == 0:
                c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
 
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 = list(input())
ok = list()
test = str()

for i in range(1, len(S) + 2):
    for j in range(i, len(S) + 2):
        test = "".join((S[i - 1:j - 1]))
        if len(test) == 0:
            pass
        else:
            test = int(test)
            if test % 2019 == 0:
                ok.append(test)

print(len(ok))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
G =[2019]
g = 2019
while g <= s:
    g += 2019
    G.append(g)
con = 0
for i in G:
    #print(i)
    con += str(s).count(str(i))
print(con)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
num = input()
word_len = 0
for i in num:
  word_len += 1

count = 0
for a in range(0,word_len+1):
  for b in range(a+1,word_len+1):
    nums = int(num[a:b])
    if nums%2019 ==0:
      count += 1
    else:
      pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    n = len(S)
    if n < 4:
        print(0)
        return
    ans = 0
    for i in range(n-3):
        s  = int(S[i])+int(S[i+1])+int(S[i+2])
        for j in range(i+3, n):
            s += int(S[j])
            #print(i,j,S[j],s)
            if s % 3 == 0:
                if int(S[i:j+1]) % 673 == 0:
                    ans += 1
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
ls = list(input())
c = 0
for j in range(len(ls)-3):
    for i in range(4+j,len(ls)+1):
        a = ls[j:i]
        b = ''.join(a)
        if int(b) % 2019 == 0:
            c += 1
        else:
            continue
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
l = len(s)
cnt = 0
for i in range(l-3):
    for j in range(i+4, l+1):
        x = int(''.join(s[i:j]))
        if x % 2019 == 0:
            cnt+= 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from math import log10
s = input()
tmp = []
num = [0]
for char in s:
    tmp.append(char)
    num.append(int("".join(tmp)))

c = 0
for m, n in combinations(num, 2):
    if m == 0:
        check = n
    else:
        check = n - m * 10 ** (-int(-log10(n)) - -int(-log10(m)))
    if check % 2019 == 0:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
def main():
  S=input()
  S_len=len(S)
  s_count=0
  for i in range(0,S_len-3):
    for j in range(i+3,S_len):
      tgtS=S[i:j+1]
      int_tgtS=int(tgtS)
      if(int_tgtS%2019==0):
        s_count=s_count+1
  print(s_count)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

i=0
while i<=L-1:
    j=i+3
    while j<=L-1:
        ans+=1*(int(S[i:j+1])%2019==0)
        j+=1
    i+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)


def solve(S):
    n=len(S)
    if n<=3:
        print(0)
        return
    ans=0
    for i in range(n-3):
        j=i+4
        tmp=int(S[i:j])%2019
        if tmp==0:
            ans+=1
        while j<n:
            j+=1
            tmp=(tmp*10+int(S[j-1]))%2019
            if tmp==0:
                ans+=1
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

T = S()

def match(v):
    return int(v) % 2019 == 0

cnt = 0
A = []

for s in T:
    A.append(s)


M = {}
for i in range(0, len(A)):
    x = ""
    x += A[i]
    for j in range(i+1, len(A)):
        x += A[j]
        if x in M:
            cnt += 1
            continue

        if match(x):
            M[x] = True
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#D

#デバッグ
debug=0
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力

S=input()


#処理
T=[int(S[i])%3 for i in range(len(S))]
sT=[0]
for i in T:
    sT.append((sT[-1]+i)%3)
x=[]
for i in range(len(S)+1):
    for j in range(i):
        if (sT[i]-sT[j])%3==0:
            x.append((j,i))
xx=0
for i,j in x:
    if int(S[i:j])%673==0:
        xx+=1
print(xx)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
c = 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:
			c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
Slist = list(input())
keta = len(Slist)
count = 0
for i in range(keta):
    for j in range(i+3,keta):
        a = Slist[i:j+1]
        if int("".join(a))%2019==0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()

# 求解処理
size = len(S)
result = 0
for i in range(size-3):
    for j in range(i+3, size):
        number = int(S[i:j+1])
        if number % 2019 == 0:
            result += 1

# 結果出力
print(result)

Submission status: Time Limit Exceeded

Solution code:
line = input()
num = [int(x) for x in list(str(line))]
i = 0
count = 0
while i<=len(line):
    j = i + 3
    while j<=len(line):
        x = num[i:j]
        s = ""
        for k in range(len(x)):
            s = s + str(x[k])
        
        if int(s)%2019 == 0:
            count = count+1
        
        j = j + 1
        
        
        
    i = i + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

S = In.str()
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

Out.int(ans)

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
l=len(S)
t=0
p=0
for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):
        p=(p+int(S[i-j])*(10**j))%2019

        if p==0:

            t+=1

print(t)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
mem_mod = [0 for i in range(0,2019,1)]
N = len(S)
counter = 0
S_num_tmp = list(S)
S_num = list(map(int, S_num_tmp))
for i in range(1,N,1):
    S_num[N-i-1] = S_num[N-i] + (10**i)*S_num[N-i-1]
for i in range(0,N,1):
    X = S_num[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()
ret = 0
for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        ret += 1 if int(S[i:j]) % 3 == 0 and int(S[i:j]) % 673 == 0 else 0
print(ret)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(l):
    for j in range(i + 4,l + 1):
        str = s[i:j]
        #print("str is " + str)
        if int(str) % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

if len(s) < 4:
    print(0)
else:
    ans = 0
    for i in range(len(s)-1):
        if 0 <= i <= 2:
            continue

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

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = str(input())

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

print (count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
mods = [0]*2019
mods[0] = 1
accu = 0
for i, j in enumerate(reversed(s)):
    accu += int(j)*10**i
    accu %= 2019
    mods[accu] += 1
ans = 0
for i in mods:
    ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
A=list(input())
ans=0
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    if sum(map(int,A[i:j+1]))%3!=0:
      continue
    if int("".join(A[i:j+1]))%2019==0:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# A,B,C,D=map(int,input().split())
S=list(input())
count=0
if len(S)<4:
    print(0)
    exit()
for i in range(4,len(S)):
    for j in range(len(S)-(i-1)):
        if int("".join(S[j:j+i]))%2019==0:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

    n = 0
    count = 0

    for i in range(len(s)-3):
        for j in range(3, len(s)):
            if i > j:
                continue

            n = s[i:j+1]
            n = ''.join(n)

            # print(n)
            if int(n) % 2019 == 0:
                count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
keta = len(s)
if keta < 4:
    print(0)
    exit()
ans = 0

for i in range(keta-3):
    for j in range(i + 3,keta):
        tmp = s[i:j+1]
        if tmp!='' and int(tmp) % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
count = [0]*n


for i in range(n-4,-1,-1):
    length = n-i
    for j in range(4, length+1):
        f = S[i:i+j]
        #print(f,i,j)
        if int(f)%2019 == 0:
            if (i+j) >= n:
                count[i] = 1
            else:
                count[i] = 1+count[i+j]
            
print(sum(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans=0
mathlen=len(str(N))
strN=str(N)
#print(mathlen)
i=0
while i<mathlen-1:
    j=i+1
    while j<mathlen+1:
        check=strN[i:j]
        #print(check)
        if int(check)%2019==0:
            ans+=1
        j+=1
    i+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# N = int(input())
# K = list(map(int, input().split()))
# N, M = map(int, input().split())

S = list(input())

# print(int(''.join(S)) / 2019)
# print(int(''.join(S)) % 2019)

cnt = 0

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

for i in range(0,len(S)-3) :
    amari = int(''.join(S[i:i+3]))
    for j in range(i+3, len(S)) :
        amari = ((amari * 10) + int(S[j])) % 2019
        if amari == 0 :
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
a=len(S)
for i in range(a):
  for j in range(i+1,a):
    num=int(S[i:j+1])
    if(num%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(4, len(S) - i + 1):
        x = int(S[i:i + j])
        if x < 2019:
            continue

        if x % 2019 == 0:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = []
for i in range(len(S)):
    for j in range(i+1, len(S)):
        A = S[i:j+1]
        int_join_A = int(''.join(A))
        if int_join_A % 2019 == 0:
            ans.extend((i, j))
print(len(ans) // 2)