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:
from collections import defaultdict, deque

S = input()

L = deque()
D1 = defaultdict(set)
D2 = {}
for i in range(len(S)-3):
  for j in range(i+4, len(S)+1):
    X = int(S[i:j])
    r = X % 2019
    if r == 0:
      L.append(i)
      D1[i].add(j)
      D2[j] = i
      break

for x in reversed(L):
  if x in D2:
    D1[D2[x]] += D1[x]
print(sum(len(x) for x in D1.values()))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
s = input()
counter = 0
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    target = int(s[i:j])
    #print(target)
    if (target%2019)==0 and target != 0:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
s=input()
N=len(s)
ans=0
li=[1,2,4,6,8]
num=[]
"""
for i in range(N):
    for j in range(i,N):
        if int(s[i:j+1])%2019==0:
            ans+=1
"""
for i in range(N):
    if int(s[i]) in li:
        num.append(i)

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

Submission status: Time Limit Exceeded

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

    s = input()
    n = len(s)-1
    c = 0

    def modinv(a, mod=10**9+7):
        return pow(a, mod - 2, mod)

    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

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

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

    print(c)

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

    #print(c, c2)

    # print(prime_factorize(2019))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    s = stdin.readline().rstrip()
    ans = 0
    start = 0
    goal = 4
    keta = 4

    while start <= len(s) - 3:
        while goal <= len(s):
            check = int(s[start:goal])
            if check % 2019 == 0:
                ans += 1
            goal += 1
        start += 1
        goal = start + 4
    print(ans)
    
main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
skip = 99999999
for i in range(len(s)):
    if i > skip:
        continue
    for j in range(int(i)+1 , len(s)+1):

        if int(s[i:j]) % 2019 == 0:
            ans += 1
            skip = j
            break
print(ans)

Submission status: Time Limit Exceeded

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

fl = [False]*(n+1)
l = 0
res = 0

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

print(res)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(n):
    for d in range(3,n):
        j = i+d
        if j >= n:
            break
        num = [s[i] for i in range(i, j+1)]
        num_str = map(str, num)
        num_num = ''.join(num_str)
        number = int(num_num)
        if number % 2019 == 0:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0
memo=[]
for l in range(len(s)-3):
    for r in range(l+4,len(s)+1):
        a=s[l:r]
        if a in memo:
            ans+=1
            break
        if int(a)%2019==0:
            ans+=1
            memo.append(a)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
r = []
for i in range(len(s)):
  r.append(int(s[i:])%2019)
d = collections.Counter(r) 
ans = 0
if 0 in d:
  ans += d[0]
for k,v in d.items():
  if v >= 2:
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    memo = set()
    cnt = 0
    for i in range(len(S)):
        for j in range(i+3,len(S)):
            if j == i+3:
                mod = int(S[len(S)-j-1:len(S)-i])%3
            else:
                mod = (mod+int(S[len(S)-j-1]))%3
            if mod == 0:
                _ = int(S[len(S)-j-1:len(S)-i])
                if _%2019==0:
                    cnt += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

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


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
D = len(N)
answer = 0
if D >3 :
    for i in range(D-3):
        for k in range(D-3-i):
            if int(N[i:D-k]) % 2019 ==0:
                answer +=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
S=list(input())
SS=""
N=len(S)

MAX=2100
MOD=10**9+7

fac=[None for i in range(MAX)]
finv=[None for i in range(MAX)]
inv=[None for i in range(MAX)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(MAX)

M=[[0 for j in range(10)] for i in range(2019)]
ans=0
for i in range(N):
    SS=S[-(1+i)]+SS
    num=int(SS)
    I=num%2019
    if I==0:
        ans+=1
    syou=num//2019
    J=syou%10
    M[I][J]+=1

for i in range(2019):
    for j in range(10):
        if M[i][j]>=2:
            ans+=COM(M[i][j],2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for _ in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(list)
for i in range(len(s)):
    cum[i+1]=cum[i]+int(s[i])
for i in range(len(s)+1):
    d[cum[i]%3].append(i)
ret = 0
#print(cum,d)
for l in d.values():
    #print(l)
    n = len(l)
    can = [[l[i],l[j]] for i in range(n) for j in range(i,n) if l[j] > l[i]+3]
    #print(can)
    #print([[i,j,int(s[i:j])] for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    #print([1 for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    ret += sum(1 for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0)
print(ret)

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 >= j:
            continue
        d = int(s[i:j+1])
        if d%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):
    if i+3 > n-1:
        continue
    for j in range(i+3,n):
        NUM=0
        cnt=0
        for p in range(j,i-1,-1):
            nn = int(S[p])
            NUM += nn * 10**cnt
            cnt+=1
        if NUM%2019==0:
            if NUM!=0:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import os

def file_input():
    f = open('../Beginner_Contest_164/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # A,B,C,D=map(int, input().split())
    S = input()
    val = 0
    for i in range(len(S)):
        for j in range(i+4,len(S)+1):
            if int(S[i:j])%2019==0:
                # print("("+str(i)+","+str(j)+")")
                val+=1

    print(val)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def sol():
    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
    print(ans)


if __name__ == '__main__':
    sol()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
#s = '2119'
pair=0

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

print(pair)

Submission status: Time Limit Exceeded

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

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

sumij=[[False]*(ls) for ii in range(ls-3)]
for ii in range(ls-3):
    for jj in np.arange(ii+3,ls+1):
    	if sum(si[ii:jj])%3==0:
    		sumij[ii][jj-3]=True

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = input()
N_list = []


for i in range(len(N)):
    N_list.append(N[i])

answer = []
for i in range(len(N)-2):
    for j in range(3,len(N)+1):
        number = [n for n in N_list[i:j+1]]
        str_number = ""
        for k in range(len(number)):
            
            str_number += number[k]
       
        if str_number != "" :
            if int(str_number) % 2019 == 0 and j < len(N):
                
                answer.append([i+1,j+1])
print(len(answer))

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

for i in range(len(S)-3):
    if int(S[i])%2 == 0:
        start = 4
    else:
        start = 5
    j = i+start
    sumS = sum(list(map(int, S[i:j-1])))
    while j < len(S)+1:
        sumS += int(S[j-1])
        if sumS % 3 != 0:
            j += 1
            continue
        if int(S[i:j]) % 2019 == 0:
            ans += 1
            j += 4
        else:
            j += 1
print(ans)

Submission status: Time Limit Exceeded

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

t = []

S = list(map(int, s))

for i in range(len(S)-1):
    for j in range(i+1,len(S)):
        for k in range(j-i+1):
            sum += S[j-k]*pow(10,k)
        if sum % 2019 == 0:
            ans += 1
        sum = 0
print(ans)

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:
        ij = int(s[i:j+1])
        while len(str(ij)) > 8:
            ij = int(str(ij)[:-1]) - int(str(ij)[-1])*2
        if ij % 2019 ==0:
            count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
ans = 0
dp = [0]*200000
c = 0
for i in range(1,l+1):
    dp[i] = dp[i-1]
    for j in range(2,i+1):
        if i -j>=0:
            n = int(s[(i-j):i])
            if n % 2019 == 0:
                c += 1
                dp[i] += c
            c = 0
print(dp[l])

Submission status: Time Limit Exceeded

Solution code:
s=input()

answer=0
for n in range(4,len(s)):
  for i in range(len(s)-n+1):
    a=s[i:i+n]
    b=int(a)
    if b%2019==0:
      answer=answer+1
        
print(answer)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
base = 2019

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
if N<4:
  print(0)
  exit(0)
M=2019
X=[0]+[int(S[i])*pow(10,N-1-i)%M for i in range(N)]
import itertools
X = list(itertools.accumulate(X))
ans=0
x=[]
for l in range(N-2):
  for r in range(l+4,N+1):
    if (X[l]-X[r])%M==0:
      ans+=1
      x.append([l,r])
      break
def search(a,x,j):
  while j<len(x):
    if a[1]==x[j][0]:
      return 1+search(x[j][1],x,j+1)
    j+=1
  return 0
  
for i,a in enumerate(x):
  ans+=search(a,x,i+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = list(s)
lLen = len(l)
lLimit = len(l) - 3
cnt = 0

for i in range(lLen):
    
    for j in range(i+3, lLen):
        n = int(s[i:j+1])
        if n % 673 == 0:
            if n % 3 == 0:
                cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
if len(S)>3:
    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:
from functools import reduce
S = list(map(int,input().rstrip()))
l=len(S)
result=0
for i in range(0,int(l-3)):
    for j in range(i+4,int(l+1)):
        n = reduce( lambda a,b:10*a+b, S[i:j])
        if n %673==0:
            if n%3==0:
                result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
s = int(S)
n = len(S)
count = 0
for i in range(1,n+1):
    for j in range(i+4,n+1):
        si = s%10**(n-i+1)
        sij = si//10**(n-j)
        if sij!= 0 and sij % 2019 == 0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
text = input()
l = len(text)
import itertools
lis = []
a = list(itertools.combinations(range(1,l+1), 2))
for i in a:
  t=text[i[0]-1:i[1]]
  if len(t)>=4 and int(t)%2019==0:
    lis.append(t)
print(len(lis))

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
a = [[int(s[0]),1]]
count = 0
for i in s[1:]:
    b = []
    c = 0
    for j in a:
        d = (j[0]*10+int(i))%2019
        if d == int(i):
            c = 1
            b.append([d,j[1]+1])
            if d == 0:
                count += j[1]+1
        else:
            b.append([d,j[1]])
            if d == 0:
                count += j[1]
    if c == 0:
        b.append([int(i),1])
    a = b
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    import collections
    def input():
        return sys.stdin.readline()[:-1]
    S=input()
    result=0
    for i in range(len(S)-3):
        Q1=collections.deque(S[i:])
        Q2=collections.deque()
        for j in range(len(S)-i):
            a=S[i:j]
            b=Q1.popleft()
            Q2.append(b)
            if int("".join(Q2))%2019==0:
                result+=1
    print(result)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = int(input())

leng = len(str(S))
count = 0

for j in range(leng-3):
    for i in range(leng-j, 3, -1):
        partial = S // (10 ** j)
        partial = partial % (10 ** i)
        if partial == 0:
            continue
        if partial % 2019 == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
count = 0
for i in range(0, 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 = int(input())

count = 0
num = 2
aaa = 2019
while aaa <= s:
    if str(aaa) in str(s):
        count += 1
    aaa = 2019 * num
    num += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n = 0
for i in range(len(N)+1):

    for j in range(i+1):
        if i-j<4: continue
        num = int(N[j:i])

        if (num%2019)==0: n += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
n_list = list(input())
L = len(n_list)
counter = 0
for i in range(L-3):
    step = 1
    try:
        j = i+3
        while j < L:
            temp = eval("".join(n_list[i:j+1]))
            if temp % 2019 == 0:
                counter += 1
                if step == 1:
                    step = j-i+1
                j += step
            else:
                if step == 1:
                    j += 1
                else:
                    break
    except:
        continue
print(counter)

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

print(count)

Submission status: Time Limit Exceeded

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

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
            break
print(c)

Submission status: Time Limit Exceeded

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

S = input().strip()
#-----

S_sum = [0]
tmp_sum = 0

for word in S:
    tmp_sum += int(word)
    S_sum.append(tmp_sum)


cnt = 0
for i in range(1,len(S_sum)):
    for j in range(i+3, len(S_sum)):
        diff = S_sum[j] - S_sum[i-1]
        sub_S = S[(i-1):j]
        
        if diff % 3 == 0  and  int(sub_S) % 673 == 0:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# Problem D
s = input()
count_ij = 0
for i in range(len(s) - 3):
    for j in range(i + 5, len(s)+1):
        sub_s = int(s[i: j])
        if sub_s % 2019 == 0:
            count_ij += 1

print(count_ij)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = input()
leng = len(N)

counter = 0 
num_list = [i for i in range(leng-3)]

for v in itertools.combinations(num_list,2):
    listv = list(v)
    listv[1] = listv[1] + 4
    temp_num = int(N[listv[0]:listv[1]])
    if temp_num % 2019 == 0:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
aaa = input()

b = 0
ans = []

a = 0
c = 2
for a in range(len(aaa)):
    for c in range(4,len(aaa)+1):
        b = aaa[a:c]
        if len(b) == 0:continue
        if int(b) % 2019 == 0:
            ans.append(b)

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
S=list(map(str,input()))
#print(S)
p=0;K="0"
for i in range((len(S)-3)):
  for j in range(i,len(S)+1):
    if j-i<4:
      continue
    for k in S[i:j]:
      K=K+k
    if int(K)!=0 and int(K)%2019==0:
      p=p+1
    K="0"
print(p)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
S_str=str(S)
length = len(S_str)
count =0
if (S<2019):
  print(0)
else:
  for i in range(length-3):
    for j in range(i+3,length):
      num1 = S//(10**(length-i))
      s1 = S-num1 *(10**(length-i))
      s2 = s1//(10**(length-j-1))
      if (s2%2019 == 0):
        count +=1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n2 = str(n)
n_ = len(str(n2))

count = 0
for i in range(n_):
  for j in range(i,n_):
    if n2[i] != "0":
      num = n2[i:j+1]
      if int(num)%2019 ==0:
        count += 1
    else:
      count = count
print(count)

Submission status: Time Limit Exceeded

Solution code:
str1 = str(input())
n = len(str1)
numMultiples = 0 
seenRemainders = [[] for i in range(n+2)]


    

for i in range(n):
    remainder = 0 
    prefixesFound = 0 
    for j in range(i,n):
        remainder =  (10*remainder + int(str1[j])) % 2019
        if remainder in seenRemainders[j]:
            break
        seenRemainders[j].append(remainder)
        if remainder == 0:
            prefixesFound+=1 
    numMultiples += prefixesFound*(prefixesFound+1)//2
print(numMultiples)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(flg)

Submission status: Time Limit Exceeded

Solution code:


s = 0

def format_input(filename = None):
	global s
	if filename == None:
		s = int(input())

	elif filename == '__random__':
		from random import randint as rng
		from random import choices
		s = int(''.join(choices('123456789', k = rng(1, 2 * 10**5))))
		print(s)

def get_answer():
	cum_sum = [0]
	for i in range(len(str(s))):
		cum_sum.append((((s // 10**i) % 10) * 10**i + cum_sum[-1]) % 2019)

	answer = len(cum_sum) - len(set(cum_sum))
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
if len(S) <= 4:
  print(0)
  exit()
for left in range(len(S)-3):
  for right in range(left+5,len(S)+1):
    if int(S[left:right])%2019==0:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
s=input()
t=[]
ans=0
for c in s:
    l=len(t)
    for i in range(l):
        t[i]*=10
        t[i]+=int(c)
        t[i]%=2019
        if t[i]==0:
            ans+=1
    t.append(int(c))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
A = [[0 for _ in range(2019)] for _ in range(n)] 


A[0][int(S[0])] = 1
for i in range(0,n-1):
    s = int(S[i+1])
    for j in range(2019):
        #pre = (j+2019-10-s)%2019
        fol = (10*j+s)%2019
        A[i+1][fol] += A[i][j]
    A[i+1][s]+=1

    
ans = 0
for i in range(n):
    ans += A[i][0]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    sol()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

L = 0
length = len(S)+1
for i in range(length):
  for j in range(length):
    if i<j:
      if int(S[i:j])>2018:
        if int(S[i:j])%2019==0:
          L += 1
print(L)

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
Slen = len(S)

if len(S)<=3:
    print(0)
    exit()

@lru_cache(maxsize=10000)
def check(n):
    if n%2019 == 0:
        return True
    else:
        return False

ans = 0
for i in range(Slen - 4 + 1):
    num_s = 4
    # for num_s in range(4,Slen+1-i):
    while num_s < Slen+1-i:
        num = int(S[i:i+num_s])
        if check(num):
            ans += 1
            num_s += 4
        else:
            num_s += 1
        # print(num,num_s,ans)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0

for i in range(0,len(S)-4):
    for j in range(1,len(S)+1):
        s = S[i:j]
        if s == '':
            pass
        else:
            int_s = int(s)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, input()))
ls = len(S)
c = 0
for s in range(ls - 3):
    n = sum(S[s:s+3])
    if S[s] == 0:
        continue
    for e in range(s + 3, ls):
        n += S[e]
        if e - s == 3 and S[s] == 1:
            continue
        if n % 3 == 0 and int(bytearray(map(lambda x: x + 48, S[s:e+1]))) % 673 == 0:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
s=input()
# print(len(s));
i=0
count=0

for k in range(4,len(s)+1):
    i=0
    for j in range(k,len(s)+1):

    
        m=s[i:j]
        i=i+1
        # print(m)
    
        # print(int(m))
        if int(m)%2019==0:
            count+=1
        # i=i+1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
len_s = len(s)
res = 0
res_dict = {0:1}
for i in range(len_s):
  use_s = int(s[i:])
  m = use_s % 2019
  if m not in res_dict:
    res_dict[m] = 1
  else:
    res_dict[m] += 1
for k, v in res_dict.items():
  if v == 1:
    continue
  else:
    res += int((v * (v-1)) / 2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
N = input()
nagasa = len(N)
count = 0
for a in range(1, nagasa+1):
    for b in range(a+1, nagasa+2):
        c = 0
        keta = b - a + 1
        for k in range(1,keta):
            c += int(N[a - 2 + k]) * 10 ** (keta-k-1)
        if c % 2019 == 0  and c != 0:
            count += 1
print(count)