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 Counter
s = input()
ac = [0]
for i in range(len(s)):
    char = s[i]
    digit = len(s) - i - 1
    ac.append((ac[-1] + (int(char) * 10**digit)) % 2019)
#print(ac)

C = Counter(ac)
#print(C)
ans = 0
for val in C.values():
    ans += val * (val - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)
mod = [int(s[n-i-1:]) % 2019 for i in range(n)]
mod.insert(0, 0)

cnt = n+1 - len(list(set(mod)))

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)
mod = [int(s[n-i-1:]) % 2019 for i in range(n)]
mod.insert(0, 0)

cnt = 0
for i in range(n-3):
    for I in range(i+4,n+1):
        if mod[i] == mod[I]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
count = 0
div = 1
surplus = 0
while (s // div > 10):
  t = s // div
  surplus = s % div
  if t % 2019 == 0:
    count += 1
  while (surplus >= 1000):
    if surplus % 2019 == 0:
      count += 1
    surplus = surplus // 10
  div *= 10
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# import itertools
S = input()
l = len(S)
# nums = range(1, l+1)
count = [0]*2019
count[0] = 1
for i in range(l):
    a = int(S[-i-1:]) % 2019
    count[a] += 1

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict


read = sys.stdin.read
readline = sys.stdin.buffer.readline

INF = float('inf')


def main():
    S = input()
    L = len(S)
    d = defaultdict(int)

    for i in range(L):
        s = int(S[i:])
        a = s % 2019
        d[a] += 1

    ans = 0

    for key, value in d.items():
        ans += value * (value - 1) // 2
        if key == 0:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = input()
l = len(S)
nums = range(1, l+1)
ans = 0
for i in itertools.combinations_with_replacement(nums, 2):
    # print(i[0])
    n = int(S[i[0]-1:i[1]])
    if n % 2019 == 0:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    rem_l = [0]*2019
    rem_l[0] = 1
    curr_rem = 0
    for i, s_i in enumerate(s[::-1]):
        num = int(s_i)
        curr_rem = (curr_rem + num*pow(10,i))%2019
        rem_l[curr_rem] += 1

    ans = 0
    for r in rem_l:
        ans += r*(r-1)//2

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=input()
l=[1]+[0]*2019
m=2019
x=0
ans=0
for i in range(len(a)-1,-1,-1):
  x=(x+(10**(len(a)-1-i))*int(a[i]))%m
  ans+=l[x]
  l[x]+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
for i in range(len(S)):
    q = (t[-1] + int(S[i]) * ((10**i) % MOD)) % MOD
    t.append(q)

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = list(input())
S.reverse()
MOD = 2019

t = [0]
for i in range(len(S)):
    q = (t[-1] + int(S[i]) * (10**i)) % MOD
    t.append(q)

cnt = Counter(t)
cnt_mc = cnt.most_common()

ans = 0
for _, j in cnt_mc:
    if j >= 2:
        ans += j * (j - 1) // 2
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    s=sys.stdin.readline().strip()
    d,c={0:1},0
    for i in range(len(s)):
        k=int(s[-1-i:])%2019
        d[k]=d[k]+1 if k in d else 1
    for v in d.values():c+=v*(v-1)//2
    print(c)
if __name__=='__main__':main()

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
    s=sys.stdin.readline().strip()
    d,c={0:1},0
    for i in range(len(s)):
        k=int(s[-1-i:])%2019
        d[k]=d.get(k,0)+1
    for v in d.values():c+=v*(v-1)//2
    print(c)
if __name__=='__main__':main()

Submission status: Time Limit Exceeded

Solution code:
s = int(input())
n = len(str(s))
count=0
for i in range(n+1):
  for j in range(i):
    if((s%(10**i)//(10**j))%2019==0):
      count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()
    l = len(s)

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        num%=2019
        dec *= 10
        cnt[num] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()
    l = len(s)

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        dec *= 10
        cnt[num % 2019] += 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()

    l = len(s)

    cnt = [0 for _ in range(2019)]
    tmp = int(s)
    for i in range(l + 1):
        tmp %= 10 ** (l-i)
        tmp_mod = tmp % 2019
        cnt[tmp_mod] += 1

    ans = 0
    for c in cnt:
        if c > 1:
            ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():

    s = input()

    l = len(s)

    cnt = [0 for _ in range(2019)]

    for i in range(l + 1):
        tmp = s[i:]
        if len(tmp) == 0:
            tmp = '0'
        tmp = int(tmp)
        tmp %= 2019
        cnt[tmp] += 1

    ans = 0
    for c in cnt:
        if c > 1:
            ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    # MODを使わない普通のComb
    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            fac *= i + 1
        return res // fac

    s = input()

    l = len(s)

    cnt = [0 for _ in range(2019)]

    for i in range(l + 1):
        tmp = s[i:]
        if len(tmp) == 0:
            tmp = '0'
        tmp = int(tmp)
        tmp %= 2019
        cnt[tmp] += 1

    ans = 0
    for c in cnt:
        if c > 1:
            ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    # MODを使わない普通のComb
    def choose(n, r):
        res = 1
        fac = 1
        for i in range(r):
            res *= n - i
            fac *= i + 1
        return res // fac

    s = input()

    l = len(s)

    cnt = dict()

    for i in range(l + 1):
        tmp = s[i:]
        if len(tmp) == 0:
            tmp = '0'
        tmp = int(tmp)
        tmp %= 2019
        if tmp in cnt.keys():
            cnt[tmp] += 1
        else:
            cnt[tmp] = 1

    ans = 0
    for v in cnt.values():
        ans += choose(v, 2)

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect
from collections import defaultdict
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	s = inp().strip();# dic = defaultdict(int)
	sett = set(); sett.add(0)
	ans = 0; cum = 0
	for i in range(len(s)-1, -1, -1):

		cum += (int(s[i])*(10**(len(s)-i-1)% 2019)) % 2019
		cum %= 2019
		# print((int(s[i])*(10**(len(s)-i-1)% 2019)) % 2019, i, cum)
		if cum in sett:
			ans += 1
		sett.add(cum)
	# print(sett)
	print(ans)






if __name__ == "__main__":
	solve()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
MOD = 2019
ts = [0]
cur = 0
for i, j in enumerate(s[::-1], 1):
    cur = (cur + 10**i % MOD * int(j)) % MOD
    ts.append(cur)
ct = Counter(ts)
res = 0
for k, v in ct.items():
    if v > 1:
        res += v * (v-1) // 2
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
MOD = 2019
ts = [0]
cur = 0
for i, j in enumerate(s[::-1], 1):
    cur = (cur + int(j) * 10**i % MOD) % MOD
    ts.append(cur)
ct = Counter(ts)
res = 0
for k, v in ct.items():
    if v > 1:
        res += v * (v-1) // 2
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S=input()
n=len(S)

T=[0]*n
U=[0]*n
for i in range(n):
    T[i]=int(S[i:])
    U[i]=T[i]%2019
T.append(0)
U.append(0)
    
#print(T)
#print(U)
#print(Counter(U))
ans=0
di= dict(Counter(U))
for a in di:
    b=di[a]
    if b>=2:
        ans += b*(b-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
start=0
end=len(s)
Ans=0

while len(s)>=4:
    for tmp in range(4,end+1):
        tmp_list=[s[tmp2] for tmp2 in range(start,tmp)]
        mojiretu = ''.join(tmp_list)
        if int(mojiretu)%2019 == 0:
            Ans+=1
    del s[0]
    end-=1

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
#print(s)

start=0 #開始位置
end=len(s) #終了位置 (今回の場合 end=13)
Ans=0

while len(s)>=4:
    for tmp in range(4,end+1): #先頭から4個取る,5個取る...end個取る
        tmp_list=[s[tmp2] for tmp2 in range(start,tmp)]
        #print(tmp_list)
        mojiretu = ''.join(tmp_list)
        #print(mojiretu)
        if int(mojiretu)%2019 == 0:
            Ans+=1
    del s[0]
    end-=1

print(Ans)

Submission status: Time Limit Exceeded

Solution code:
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1364",problemID = "A",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    s = insr()
    count = 0
    for i in range(len(s)): 
        n = 0
        for j in range(i,len(s), 1): 
            n = n * 10 + (ord(s[j]) - ord('0'))
            if (n % 2019 == 0): 
                count += 1      
    print(count)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def getLeftmostBit(n): 
    m = 0
    while (n > 1) : 
        n = n >> 1
        m += 1
    return(m)
def getNextLeftmostBit(n, m) : 
    temp = 1 << m 
    while (n < temp) : 
        temp = temp >> 1
        m -= 1
    return m
def bitcounter(n) :
    m = getLeftmostBit(n) 
    return _countSetBits(n, m) 
def _countSetBits(n, m) :
    if (n == 0) : 
        return 0
    m = getNextLeftmostBit(n, m)
    if (n == (1 << (m + 1)) - 1) : 
        return ((m + 1) * (1 << m))
    n = n - (1 << m)
    return (n + 1) + bitcounter(n) + m * (1 << (m - 1)) 

def log_two(n): 
    return(math.log(n) / math.log(2))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Submission status: Time Limit Exceeded

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

    n = 0
    R = [0] * mod
    R[0] += 1
    for i in range(len(s)):
        n += int(s[-i - 1]) * (10 ** i) % mod
        R[n % mod] += 1

    print(sum([r * (r - 1) // 2 for r in R]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    s2 = ''
    R = [0] * mod
    R[0] += 1
    for i in range(len(s)):
        s2 = ''.join([s[-i - 1], s2])
        R[int(s2) % mod] += 1

    print(sum([r * (r - 1) // 2 for r in R]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    s2 = ''
    R = [0] * mod
    R[0] += 1
    for i in range(len(s)):
        s2 = f'{s[-i - 1]}{s2}'
        R[int(s2) % mod] += 1

    print(sum([r * (r - 1) // 2 for r in R]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    R = [0] * mod
    R[0] += 1
    for i in range(len(s)):
        R[int(s[-i - 1:]) % mod] += 1

    print(sum([r * (r - 1) // 2 for r in R]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

s = str(input())
ans = 0

for i in range(len(s)-1):
    for q in range(i+1 ,len(s)+1):
        if(int(s[i:q])%2019==0):
            ans+=1
print(ans)
#1817181712114

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

dp = [[0]*2019 for _ in [0]*(N+1)]
ans = 0
for i,s in enumerate(S,1):
    s = int(s)
    dpi = dp[i]
    dpi1 = dp[i-1]
    dpi[s] += 1
    for j in range(2019):
        dpi[(j*10+s)%2019] += dpi1[j]
    ans += dpi[0]

print(ans)

Submission status: Time Limit Exceeded

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

dp = [[0]*2019 for _ in [0]*(N+1)]
for i,s in enumerate(S,1):
    s = int(s)
    dpi = dp[i]
    dpi1 = dp[i-1]
    dpi[s] += 1
    for j in range(2019):
        dpi[(j*10+s)%2019] += dpi1[j]

ans = sum(dp[i][0] for i in range(N+1))
print(ans)

Submission status: Time Limit Exceeded

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

dp = [[0]*2019 for _ in [0]*(N+1)]
for i,s in enumerate(S,1):
    s = int(s)
    dp[i][s] += 1
    for j in range(2019):
        dp[i][(j*10+s)%2019] += dp[i-1][j]

ans = sum(dp[i][0] for i in range(N+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = list(input())
a.reverse()
add = 0
ans = [1] + [0] * 2018
ans_int = 0

for i in range(len(a)):
    add = (add + int(a[i]) * 10 ** i) %2019
    if ans[add] == 1:
        ans_int += 1
        continue
    else:
        ans[add] = 1


print(ans_int)

Submission status: Time Limit Exceeded

Solution code:
a = list(input())
a.reverse()
s = [0]
ans = [1] + [0] * 2018
ans_int = 0

for i in range(len(a)):
    add = s[i] + int(a[i]) * 10 ** i
    add = add % 2019
    ans[add] += 1
    s.append(add)
    if ans[add] > 1:
        ans_int += 1


print(ans_int)

Submission status: Time Limit Exceeded

Solution code:
a = list(input())
a = [int(s) for s in a]
a = a[::-1]
s = [0]
ans = [1] + [0] * 2018
ans_int = 0

for i in range(len(a)):
    add = s[i] + a[i] * 10 ** i
    add = add % 2019
    ans[add] += 1
    s.append(add)
    if ans[add] > 1:
        ans_int += 1


print(ans_int)

Submission status: Time Limit Exceeded

Solution code:
a = list(input())
a = [int(s) for s in a]
a = a[::-1]
s = [0]
ans = [1] + [0] * 2018

for i in range(len(a)):
    add = s[i] + a[i] * 10 ** i
    add = add % 2019
    ans[add] += 1
    s.append(add)

ans_int = 0

for i in range(2019):
    if ans[i] > 1:
        ans_int += (ans[i] - 1)

print(ans_int)

Submission status: Time Limit Exceeded

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

for i in range(len(a)):
    add = s[i] + int(a[i]) * 10**i
    add = add % 2019
    s.append(add)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = list(input())
a = [int(s) for s in a]
a = a[::-1]
s = [0]

for i in range(len(a)):
    add = s[i] + a[i] * 10**i
    add = add % 2019
    s.append(add)

#print(s)
ans = 0

for i in range(len(s)):
    for j in range(i+1,len(s)):
        if s[i] == s[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
l = len(s)
p = 0
for i in range(l):
    for j in range(i+4,l+1):
        a = int(s[i:j])
        if a % 673 == 0:
            if a % 3 ==0:
                p +=1
print(p)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
num=input()
ruiseki = [0]
for i in range(1, len(num) + 1):
  ruiseki.append((int)(num[:i]) % 2019)
#print(ruiseki)
count = 0
for i in itertools.combinations(range(len(ruiseki)), 2):
  #print(((ruiseki[i[0]] * 10 ** (i[1] - i[0])) - ruiseki[i[1]]) % 2019, i[0], i[1])
  if ((ruiseki[i[0]] * 10 ** (i[1] - i[0])) - ruiseki[i[1]]) % 2019 == 0:
    count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# D - Multiple of 2019
S = input()
mod = [1]+[0]*2018
tmp = 0
for k in range(len(S)):
    tmp = (10**k*int(S[len(S)-1-k])+tmp)%2019
    mod[tmp] += 1
ans = 0
for k in range(2019):
    ans += mod[k]*(mod[k]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()[::-1]
cur = 0
mods = Counter()
mods[0] += 1
for i,d in enumerate(S):
  cur += int(d) * 10**i
  mods[cur%2019] += 1

res = 0
for k,v in mods.items():
  res += (v * (v-1) // 2)

print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import Counter
s=str(input())
s1=len(s)
k=0
a=0
p=list()
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=(a+b)%2019
    if a==0:
        k=k+1
    p.append(a)
p=Counter(p)
p=p.values()
p1=int(sum(list(map(lambda x:x*(x-1)/2,p))))
print(p1+k)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
s=str(input())
s1=len(s)
k=0
a=0
p=[0 for i in range(2019)]
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=(a+b)%2019
    if a==0:
        k=k+1
    p[a]=p[a]+1
p=list(map(lambda x:x*(x-1)/2,p))
print(int(sum(p)+k))

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
s=str(input())
s1=len(s)
k=0
a=0
p=list()
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=(a+b)%2019
    if a==0:
        k=k+1
    k=k+p.count(a)
    p.append(a)
print(k)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
s=str(input())
s1=len(s)
k=0
a=0
p=list()
if s1<4:
    print(0)
    sys.exit()
for i in range(s1):
    b=(int(s[s1-i-1])*10**i)%2019
    a=a+b
    p.append(a%2019)
for i in range(1,2019):
    l=p.count(i)
    k=k+l*(l-1)/2
x=p.count(0)
print(int(k+x*(x+1)/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from collections import deque
from collections import Counter

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

#nCr
def cmb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n - r)


def main():
    S = SI()
    l = len(S)
    T = [0] * (l+1)
    for i in range(l):
        T[i] = int(S[i:]) % 2019
    C = Counter(Counter(T).values())
    ans = 0
    for n, x in C.items():
        if n == 1: continue
        ans += cmb(n, 2) * x
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
counts = [0] * 2019
counts[0] = 1
digit = 1
sum = 0
for c in s:
  sum += int(c) * digit
  digit = digit * 10 
  amari = sum % 2019
  counts[amari] += 1

result = 0
for c in counts:
  result += c * (c - 1) // 2

print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()[::-1]
l=[0]*2019
sm=0
cnt=0
l[0]=1
for i in range(len(s)):
    sm += int(s[i])*(10**i)
    sm %= 2019
    cnt += l[sm]
    l[sm] += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in input()]
from collections import deque
L=deque()
sum=0
for i in range(len(s)):
    t=s[i]*(10**(len(s)-i))
    sum += t
    L.append(sum%2019)
L=sorted(L)

ans=0
count=1
for i in range(len(L)-1):
    if L[i]==L[i+1]:
        count += 1
    else:
        if L[i]==0:
            count += 1
        if count>1:
            ans += count*(count-1)//2
        count=1
if count>1:
    ans += count*(count-1)//2

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = input()
len_s = len(s)
counter = []
for i in range(len_s + 1):
  for index in range(i + 1):
    if i != index:
      counter.append(int(s[index:i]))
np_counter = np.array(counter)
np_2019 = np_counter % 2019
print(np.count_nonzero(np_2019 == 0))

Submission status: Time Limit Exceeded

Solution code:
s = input()
len_s = len(s)
count = 0
for i in range(len_s + 1):
  for index in range(i + 1):
    if i != index and int(s[index:i])%2019 == 0:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
s  = input()[::-1]
lsts = [0] * 2019
kai = 1
cou = 0
st = 0
lsts[0] = 1
for i in s:
  st =(st + int(i) * kai) % 2019
  cou += lsts[st]
  lsts[st] += 1  
  kai = kai * 10
 
print(cou)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1
current = 0
x = 1

for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current]
    mods[current] += 1
    x = x * 10

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = int(input())#対象の文字列(整数)

st = str(s)#対象の文字列(文字)

ans = 0

n = len(st) #sの桁数をとる

for i in range(n):
    for j in range(i,n):
        eva = ''
        for k in range(i,j+1):
            eva += st[k]

        l = int(eva)

        if l % 2019 == 0:
            ans += 1

print(ans)