Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
lenS = len(str(S))

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, accumulate
mod = 2019

a = list(map(int,input()))
n = len(a) #入力の桁数

for i in range(n):
    a[i] *= pow(10,n-i-1) #pow(a,b)==a^b べき乗
    a[i] %= mod
s = [0]+list(accumulate(a)) #accumulate([1,2,3,4,5]) --> 1 3 6 10 15
d = [0]*mod
ans = 0
for i in s:
    j = i%mod
    ans += d[j]
    d[j] += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations, accumulate
mod = 2019

a = list(map(int,input()))
n = len(a) #入力の桁数

for i in range(n):
    a[i] *= pow(10,n-i-1) #pow(a,b)==a^b べき乗
    
s = [0]+list(accumulate(a)) #accumulate([1,2,3,4,5]) --> 1 3 6 10 15
d = [0]*mod
ans = 0
for i in s:
    j = i%mod
    ans += d[j]
    d[j] += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = 2019
cnt = [0] * N
S = input()
ans = 0
for s in S:
    s = int(s)
    new = [0] * N
    for n in range(N):
        idx = (10 * n + s) % N
        new[idx] += cnt[n]
    cnt = new
    cnt[s] += 1
    ans += cnt[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    S = list(map(int, input().rstrip("\r\n")))
    N = len(S)
    P = 2019
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        D = [0] * (N+1)
        tenpow = 1
        for i in range(N):
            S[i] = S[i] * tenpow % P
            tenpow *= 10 % P
            D[i+1] = (S[i] + D[i]) % P
        c = Counter(D)
        for v in c.values():
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections
import math

s = input()[::-1]
length = len(s)
a = []
d = []
for i in range(length):
    a.append(int(s[i]) * pow(10, i) % 2019)
d.append(a[0])
for i in range(length-1):
    d.append((d[i] + a[i+1]) % 2019)
x = np.array([i for i in collections.Counter(d).values()])
x = x[np.where(x > 1)]
print(int(sum([math.factorial(x[i]) for i in range(x.shape[0])]) / 2) + d.count(0))

Submission status: Time Limit Exceeded

Solution code:

# 2019 = 3 * 637

S = input()

size = len(S)

# print(size)

count = 0
for i_ in range(size):
    i = i_ # i文字目から(0-based)
    for j_ in range(i, size):
        j = j_ + 1 #j文字目まで(1-based)

        # print(S[i:j])
        subnum = int(S[i:j])
        # print(subnum)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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 = ans + 1

    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
original = input()[::-1]

target = 2019

# s = reversed(original)

counts = [0] * 2019
counts[0] = 1

digit = 1
mod = 0
for c in original:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)  # 答えの出力

Submission status: Time Limit Exceeded

Solution code:
original = input()[::-1]

target = 2019

# s = reversed(original)
s = original

counts = [0] * 2019
counts[0] = 1

digit = 1
mod = 0
for c in s:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)  # 答えの出力

Submission status: Time Limit Exceeded

Solution code:
original = input()

target = 2019

results = {}
countOfMod = {0:1}
s = reversed(original)

counts = [0] * 2019
counts[0] = 1

digit = 1
mod = 0
for c in s:
    val = int(c) * digit
    currentMod = val % target
    mod = (currentMod + mod) % target
    digit *= 10

    counts[mod] += 1
    # count = countOfMod.get(mod, 0) + 1
    # countOfMod[mod] = count
    # if countOfMod[mod] > 1:
    #     results.setdefault(mod, int(count*(count-1)/2))

# print(sum(results.values()))

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans)  # 答えの出力

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
length = len(s)
a = []
d = []
for i in range(length):
    a.append(int(s[i]) * pow(10, i) % 2019)
d.append(a[0])
for i in range(length-1):
    d.append((d[i] + a[i+1]) % 2019)
print(sum(d[i] == d[j] for i in range(length-1) for j in range(i+1, length)) + d.count(0))

Submission status: Time Limit Exceeded

Solution code:
s = input()
 
ans = 0 
for i in range(len(s)):
    r = int(s[i:len(s)])%2019
    for j in range(i, len(s)):
        tmp = s[j+1:len(s)]
        #print('tmp =', tmp)
        if len(tmp) > 0:
            if r == int(tmp)%2019:
                #import pdb; pdb.set_trace()
                #print('int(s[i:len(s)] =', int(s[i:len(s)]))
                #print('int(s[j:len(s)] =', int(s[j:len(s)]))
                #print('r =', r)
                ans += 1
        elif len(tmp) == 0:
            if r == 0:
                ans += 1
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
s = input()

ans = 0 
for i in range(len(s)):
    r = int(s[i:len(s)])%2019
    for j in range(i, len(s)):
        tmp = s[j+1:len(s)]
        #print('tmp =', tmp)
        if len(tmp) > 0:
            if r == int(tmp)%2019:
                #import pdb; pdb.set_trace()
                #print('int(s[i:len(s)] =', int(s[i:len(s)]))
                #print('int(s[j:len(s)] =', int(s[j:len(s)]))
                #print('r =', r)
                ans += 1
        elif len(tmp) == 0:
            if r == 0:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
original = input()

target = 2019

results = {}
countOfMod = {}
length = len(str(original))
for i in range(0, length+1):
    value = int(original[-i:]) if i > 0 else 0
    mod = value % target
    val = countOfMod.get(mod, 0) + 1
    countOfMod[mod] = val
    if countOfMod[mod] > 1:
        results.setdefault(mod, int(val*(val-1)/2))

print(sum(results.values()))

Submission status: Time Limit Exceeded

Solution code:
s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019
s = input()[::-1]
length = len(s)
a = []
d = []
for i in range(length):
    a.append(int(s[i]) * pow(10, i) % 2019)
d.append(a[0])
for i in range(length-1):
    d.append((d[i] + a[i+1]) % 2019)
print(sum(d[i] == d[j] for i in range(length-1) for j in range(i+1, length)) + d.count(0))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = int( input() )
ss = str( s )
n = len( ss )

cmod = np.zeros( 2019 )
cmod[ 0 ] += int( 1 )

tkm1 = int( 0 )
for km in range( n ):
    k = n - km
    tkm1 = tkm1 + 10**( n - k ) * int( ss[ k - 1 ] )
    lmod = tkm1 % 2019
    cmod[ lmod ] += 1
#    print( lmod, tkm1 )

ans = int( 0 )
for icmod in cmod:
    ans += icmod * ( icmod-1 ) * 0.5e0

ans = int( ans )
print( ans )

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019
s = input()[::-1]
length = len(s)
a = []
d = []

for i in range(length):
    a.append(int(s[i]) * pow(10, i) % 2019)
d.append(a[0])
for i in range(length-1):
    d.append((d[i] + a[i+1]) % 2019)
cnt = sum(d[i] == d[j] for i in range(length-1) for j in range(i+1, length))
print(cnt + d.count(0))

Submission status: Time Limit Exceeded

Solution code:
s = input()

target = 2019

memo = [0]*200000

counts = []
countOfMod = {}
# i = 0
# while s >= 10:
#     mod = s % target
#     s = int(s / 10)
#     countOfMod[mod] = countOfMod.get(mod, 0) + 1

length = len(s)
for i in range(0, length+1):
    value = int(s[-i:]) if i > 0 else 0
    mod = value % target
    countOfMod[mod] = countOfMod.get(mod, 0) + 1

results = [int(m*(m-1)/2) for m in countOfMod.values() if m > 1]


print(sum(results))
# print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
length = len(s)
a = []
d = []

for i in range(len(s)):
    a.append(int(s[i]) * pow(10, i) % 2019)
d.append(a[0])
for i in range(len(s)-1):
    d.append((d[i] + a[i+1]) % 2019)
cnt = 0
for i in range(len(d)-1):
    for j in range(i+1, len(d)):
        if d[i] == d[j]:
            cnt += 1
print(cnt + d.count(0))

Submission status: Time Limit Exceeded

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

for i in range(2019):
    count[i] = count[i]*(count[i]-1)/2

print(int(sum(count)))

Submission status: Time Limit Exceeded

Solution code:
s = input()

length = len(s)

target = 2019


dic = {}
for i in range(0, length+1):
    value = int(s[-i:]) if i > 0 else 0
    mod = value % target
    dic[mod] = dic.get(mod, []) + [i]

counts = [len(vals) for vals in dic.values() if len(vals) > 1]

# count = 0
# for m in counts:
#     count += int(m(m-1)/2)

results = [int(m*(m-1)/2) for m in counts]

print(sum(results))
# print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
MOD = 2019

r = 0
C = [0 for _ in range(MOD)]
C[0] = 1

for i,s in enumerate(S):
    r += int(s)*((10**i)%MOD)
    r %= MOD
    C[r] += 1

a = 0
for c in C:
    a += c*(c-1)/2

print(int(a))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = int( input() )
ss = str( s )
l = len( ss )
#print( s, l )

ans = int( 0 )
for i in range( l-4 ):
    for j in range( i+4, l+1 ):
        ssij = ss[ i:j ]
        sij = int( ssij )
#        print( i, j, sij )
        if sij % 2019 == 0:
#            print( "Yes" )
            ans = ans + 1

print( ans )

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019
s = input()[::-1]
length = len(s)
a = []
for i in range(len(s)):
    a.append(int(s[i]) * pow(10, i) % 2019)
print(0) if int(s) < 2019 else print(sum(sum(a[j:i+j]) % 2019 == 0 for i in range(4, length) for j in range(length-i+1)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]

dp = [0]*2019
dp[0]=1
total = 0
a = 1

for i in list(s):
  total += (int(i)*a)%2019
  dp[total%2019] += 1
  a *= 10
count=0
  
for i in range(2019):
    count += dp[i]*(dp[i]-1)//2
 
print(count)

Submission status: Time Limit Exceeded

Solution code:
string = input()
array = list(string)
#print(len(array))
count = 0
for i in range(len(array)-3):
    for j in range(i+3, len(array)):
#        print(str(i) + ' ' + str(j))
        n_str = ''
        for k in range(i, j+1):
            n_str += array[k]
#            print(n_str)
#            print('----------')
        n = int(n_str)
#        print('----------')
        if n % 2019 == 0:
            count += 1
#            print(i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
answer = 0
for st in range(len(s)):
    for en in range(st + 1, len(s) + 1):
        w = int(s[st:en:])
        if w % 2019 == 0:
            answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
s = input()
dp = [0]*2019
dp[0] = 1
total = int(s)
k=1

for n in list(map(int, list(s))):
  dp[total%2019]+=1
  total -= n*(10**(len(s)-k))
  k+=1
  

count=0
for i in range(2019):
  m=dp[i]
  count += m*(m-1)/2
 
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
# D
import numpy as np

S = input()
N = len(S)
T = [0]
for i in range(N-1, -1, -1):
    T = [(10 ** (N-1-i) * int(S[i])+T[0]) % 2019] + T
    
u, counts = np.unique(T, return_counts=True)
print(len([1 for c in counts if c > 1]))

Submission status: Time Limit Exceeded

Solution code:
# D
            
import itertools
S = input()
N = len(S)
T = [0]
power = 1
for i in range(N-1, -1, -1):
    T = [(power * int(S[i])+T[0]) % 2019] + T
    power *= 10
    # print(i, S[i], N-i, T)
T_set = set(T)
c = 0
for t_ in T_set:
    n = len([1 for t in T if t == t_])
    if n > 0:
        c += int(n * (n-1)/2)
print(c)

Submission status: Time Limit Exceeded

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

for n in range(len(s)):
  dp[n+1] = (dp[n]+int(s[-n-1])*(10**n))%2019

count=0
for i in range(2019):
  m=dp.count(i)
  count += m*(m-1)/2
 
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = input()
print(0) if int(s) < 2019 else print(sum(np.mod(int(s[j:i+j]), 2019) == 0 for i in range(4, len(s)) for j in range(len(s)-i+1)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    S=input()
    P=2019
    ans=0
    
    count=[0]*P
    count[0]=1
    u=0
    
    for i,s in enumerate(reversed(S)):
        u=(int(s)*pow(10,i)%P+u)%P
        ans+=count[u]
        count[u]+=1
    print(ans)
    

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

    counter_list = [0] * 2019
    counter_list[0] = 1
    cumulative_sum_list = [0]

    for i in range(len(s)):
        value = int(s[len(s)-i-1:len(s)]) % 2019
        cumulative_sum_list.append(value)
        counter_list[value] += 1

    ans = 0

    for i in counter_list:
        ans += i * (i - 1) // 2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    counter_list = [0] * 2019
    counter_list[0] = 1
    cumulative_sum_list = [0] * (len(s) + 1)

    for i in range(len(s)):
        cumulative_sum_list[i + 1] = int(s[len(s)-i-1:len(s)]) % 2019
        counter_list[cumulative_sum_list[i + 1]] += 1

    ans = 0

    for i in counter_list:
        ans += i * (i - 1) // 2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * pow(10, len(S) - 1 - i)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    T = [0 for _ in range(len(S) + 1)]
    for i in range(len(S) - 1, -1, -1):
        T[i] = (T[i+1] + int(S[i]) * 10 ** (len(S) - 1 - i)) % 2019
    # T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [0 for _ in range(2019)]
    # M = [T.count(i) for i in range(2019)]
    for t in T:
        M[t] += 1
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def solve(S: str):
    T = [int(S[i:]) % 2019 if i < len(S) else 0 for i in range(len(S) + 1)]
    M = [T.count(i) for i in range(2019)]
    ct = 0
    for m in M:
        ct += m * (m - 1) / 2

    print(int(ct))

    # mx = int(S) // 2019
    # print(mx)
    # bl = [2019 * i for i in range(1, mx+1)]
    # ct = 0
    # for b in bl:
    #     blen = len(str(b))
    #     for i in range(len(S) - blen + 1):
    #         s = S[i:(i+blen)]
    #         if s == b:
    #             ct += 1
    # print(ct)

    # bf = [0 for _ in range(2019)]
    # for i in range(len(S)):



    # sl = [int(S[i]) for i in range(len(S))]
    # ct = 0
    # for i in range(len(S)):
    #     crt = sl[i]
    #     for j in range(i, len(S)):
    #         if i != j:
    #             crt *= 10
    #             crt += sl[j]
    #         # s = S[i:(j+1)]
    #         # si = int(s)
    #         if crt % 2019 == 0:
    #             ct += 1
    # print(ct)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    # S = int(next(tokens))  # type: int
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

# print(s[1:3])

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0

for i in range(0,len(S)-4):
    check3=int(S[i])+int(S[i+1])+int(S[i+2])+int(S[i+3])
    for j in range(i+5,len(S)+1):
        check3+=int(S[j-1])
        check3%=3
        #print(S[i:j])
        #print(check3)
        if check3==0:
            if int(S[i:j])%673==0:
                count+=1
                
print(str(count))

Submission status: Time Limit Exceeded

Solution code:
S=input()
count=0
S3=''

for i in range(len(S)):
    S3+=str(int(S[i])%3)
for i in range(0,len(S)-4):
    check3=int(S3[i])+int(S3[i+1])+int(S3[i+2])+int(S3[i+3])
    for j in range(i+5,len(S)+1):
        check3+=int(S3[j-1])
        check3%=3
        if check3==0:
            if int(S[i:j])%673==0:
                count+=1
                
print(str(count))

Submission status: Time Limit Exceeded

Solution code:
s = input()

counter_list = [0] * 2019
counter_list[0] = 1
cumulative_sum_list = [0] * (len(s) + 1)

for i in range(len(s)):
    cumulative_sum_list[i + 1] = int(s[len(s)-i-1:len(s)]) % 2019
    counter_list[cumulative_sum_list[i + 1]] += 1

ans = 0

for i in counter_list:
    ans += i * (i - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]

cnt = [0] * 2019
cnt[0] = 1
total = 0
x = 1
ans = 0

for a in S:
    total += int(a) * x
    total %= 2019
    cnt[total] += 1
    x = x*10

for i in range(2019):
    ans += cnt[i]*(cnt[i]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import sys 
# import os
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

import numpy as np
S = input()
cand = np.zeros(2019,dtype=int)
rem = 0
order = 1
mod = 2019
for s in S[::-1]:
    rem += (int(s)*order)%mod
    rem %= mod
    cand[rem] +=1
    order *= 10
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
S.reverse()

cnt = [0] * 2019
total = 0
x = 1
ans = 0

for a in S:
    cnt[total] += 1
    total += int(a) * x
    total %= 2019
    ans += cnt[total]
    x = x*10

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import sys 
# import os
# path = os.path.join(os.getcwd(),'input.txt')
# input = open(path).readline

import numpy as np
S = input()
cand = np.zeros(2019,dtype=int)
ans = 0
rem = 0
for i,s in enumerate(S[::-1]):
    rem += int(s)*(10**i)
    rem %= 2019
    cand[rem] +=1
ans = cand[0]
cand = cand[cand>1]
for c in cand:
    ans += c*(c-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
S = int(S)
ans = 0
for i in range(L,3,-1):
    for j in range(i-4,-1,-1):
        if S%(10**i)%2019 == S%(10**j)%2019:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=[0]*2019
c=0

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

if a[0]!=0:
  a[0]+=1

for i in a:
  c+=i*(i-1)/2

print('{:.0f}'.format(c))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s=input()[::-1]
ans=0
lst=[0]
num=0
p=1
for i in s:
    lst.append((int(i)*p+lst[-1])%2019)
    p=p*10


ans=sum(x*(x-1)//2 for x in Counter(lst).values())
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s=input()[::-1]
ans=0
lst=[0]
num=0
p=1
for i in s:
    lst.append((int(i)*p+lst[-1])%2019)
    p=p*10

cou=dict(Counter(lst))
ans=sum(x*(x-1)//2 for x in Counter(lst).values())
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s=input()[::-1]
ans=0
lst=[0]
num=0
p=1
for i in s:
    lst.append((int(i)*p+lst[-1])%2019)
    p=p*10

cou=dict(Counter(lst))
for x in cou.values():
    ans+=x*(x-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s=input()[::-1]
ans=0
lst=[]
num=0
for j in range(len(s)):
    
    lst.append(num%2019)
    num+=int(s[j])*10**(j)
lst.append(num%2019)

cou=dict(Counter(lst))
for x in cou.values():
    ans+=x*(x-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:

s=input()
s= s[::-1]

S=[0,]

for n,i in enumerate(s):
    # print(s[n], i, n)
    S.append((int(S[n]) + int(i) * 10**n) % 2019)

# print(S)
ans=0
for i in range(0,len(s)-4):
    for j in range(i+5, len(s)+1):
        if S[i]- S[j]==0:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s=list(input())
lst=[]  #sのリバース
lst2=[] #累積和を2019で割ったあまり

num=0
for j in reversed(range(0,len(s))):
    
    lst2.append(num%2019)
    num+=int(s[j])*10**(len(s)-j-1)
lst2.append(num%2019)

ans=0
cou=dict(Counter(lst2))
for x in cou.values():
    ans+=x*(x-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s=list(input())
lst=[]  #sのリバース
lst2=[] #累積和を2019で割ったあまり
for i in range(len(s)):
    lst.append(s.pop())

num=0
for j in range(len(lst)):
    lst2.append(num%2019)
    num+=int(lst[j])*10**(j)
lst2.append(num%2019)
ans=0
cou=dict(Counter(lst2))
for x in cou.values():
    ans+=x*(x-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s=list(input())
lst=[]  #sのリバース
lst2=[] #累積和を2019で割ったあまり
for i in range(len(s)):
    lst.append(s.pop())

num=0
for j in range(len(lst)):
    lst2.append(num)
    num+=int(lst[j])*10**(j)
lst2.append(num)
for k in range(len(lst2)):
    lst2[k]=lst2[k]%2019
ans=0
cou=dict(Counter(lst2))
for x in cou.values():
    ans+=x*(x-1)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

S = list(map(int, list(input())))
num = 0
dict = [0 for i in range(2019)]
dict[0] = 1
ans = 0

for i , n in enumerate(S[::-1]):
    num += n * (pow(10,i) % 2019)
    dict[num % 2019] += 1

for i in range(2019):
    ans += dict[i] * (dict[i] - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    # for i in S:
    #     cnt[i % 2019] += 1

    ans = 0

    for i in cnt:
        ans += i * (i - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    A = input()[::-1]
    A = "0" + A
    # lis_num = [int(s) for s in A]

    # print(lis_num)

    # S = [0] * len(lis_num)
    S = [0] * len(A)
    cnt = [0] * 2019
    cnt[0] = 1

    for i in range(len(A) - 1):
        S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i)) % 2019
        cnt[S[i + 1] % 2019] += 1

    # print(S)

    # for i in S:
    #     cnt[i % 2019] += 1

    ans = 0

    for i in range(2019):
        ans += cnt[i] * (cnt[i] - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()