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:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.zeros_like(dp)
        newdp[x:] += dp[:-x]
        newdp[:x] += dp[-x:]
        answer += newdp[0]
        pow10 *= 10
        pow10 %= 2019
        dp = newdp
    return answer


S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print(solve(S))

Submission status: Time Limit Exceeded

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


def solve(S: str):

    l = [0] * 2019
    ps = ""
    for i in range(1, len(S) + 1):
        ps = S[-i:]
        l[ int(ps) % 2019 ] += 1

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

    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 = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

res = 0
tmp = [0] * 2019
tmp[0] = 1
for i in range(1, len(S) + 1):
    tmp[(int(S[len(S) - i:]) % 2019)] += 1
    # print(S[len(S) - i:])

for t in tmp:
    res += (t * (t - 1)) // 2

print(res)

Submission status: Time Limit Exceeded

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

nums = [0] * (len(S) + 1)
pow10 = 1
counter = dict({0: 1})
for i in range(1, len(S) + 1):
    nums[i] = (nums[i - 1] + pow10 * S[-i]) % 2019
    if nums[i] not in counter:
        counter[nums[i]] = 1
    else:
        counter[nums[i]] += 1

    pow10 *= 10

ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
string=input()
length=len(string)
mod=[0]*2019
while length > 0:
  mod[int(string[length-1:])%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod]))+mod[0])

Submission status: Time Limit Exceeded

Solution code:
S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  x = 0
  d = [0]*2019
  d[0] = 1
  for i, s in enumerate(reversed(S)):
    x += int(s)*(10**i)
    d[x%2019] += 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import collections
s = (input())

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

n = len(s)
ans = 0
l = 0
#r = l
num = int(s)

tmp = [0 for _ in range(n+1)]
tmp1 = 0
for i in range(0,n):
    tmp1 += (int(s[n-i-1]) * pow(10, i))
    tmp[i+1] = tmp1 % 2019
#print(tmp)

c = collections.Counter(tmp)
#print(c)
for i in range(0, 2020):
    if c[i] > 0:
        ans += ((2 * c[i] - 1) // 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():

  s=input()
  s=s.strip("\n")
  n=len(s)
  res=0
  d={key:0 for key in range(2019)}
  t=[0]*(n+1)
  d[0]=1
  for i in range(1,n+1):
      t[n-i]=(t[n-i+1]+(int(s[n-i])*10**(i-1))%2019)%2019
      d[t[n-i]]+=1
  for i in d.values():
      if i<2:
        continue
      res+=int(i*(i-1)/2)
  print(res)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

def main():
    S = input()
    d = defaultdict(int)
    d[0] = 1
    for i in range(len(S)):
        rem = int(S[-(i+1):])%2019
        d[rem] += 1
    ans = sum([d[i]*(d[i]-1)//2 for i in range(2019)])
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
listS = list(str(S))
l = len(listS)
dp = int(listS[-1])
suml = [dp]
mod = [0]
for i in range(l-1):
    dp = dp + (10**(i+1))*int(listS[-2-i])
    suml.append(dp)
for a in suml:
    mod.append(a % 2019)
cnt = 0
for i in range(2019):
    if mod.count(i) > 1:
        cnt += ((mod.count(i))*(mod.count(i)-1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
string=input()
length=len(string)
mod=[0]*2019
s=''
while length > 0:
  s=string[length-1]+s
  mod[int(s)%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod]))+mod[0])

Submission status: Time Limit Exceeded

Solution code:
S = raw_input()

r = 0
for i in xrange(len(S)):
    for j in xrange(i + 1, len(S) + 1):
        t = int(S[i:j])
        if 1 <= t <= 200000:
            if t % 2019 == 0:
                r += 1

print(r)

Submission status: Time Limit Exceeded

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


def solve(S: str):

    l = [0] * 2019
    ps = ""
    for i in range(1, len(S) + 1):
        ps = S[-i:]
        l[ int(ps) % 2019 ] += 1

    
    ans = 0
    for i in range(0, len(l)):
        ans += l[i] * (l[i] - 1) // 2
    
    ans += l[0]
    
    print(ans)

    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 = str(next(tokens))  # type: str
    solve(S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=int(s)
m=len(s)
if n<2019:
    print(0)
    exit()
from collections import Counter
c=Counter()
for i in range(m+1):
    c[(n%(pow(10,i)))%2019]+=1

ll=c.most_common()
ans=0
for i,j in ll:
    if j>=2:
        ans+=j*(j-1)//2
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(lambda x: int(x),list(input())))
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = (kar + s[n-1-i]*10**i)%2019
    p[kar] += 1

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

r = 0
for i in range(len(S)):
    for j in range(i + 1, len(S) + 1):
        t = int(S[i:j])
        if 1 <= t <= 200000:
            if t % 2019 == 0:
                r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from bisect import bisect

S = input()
if len(S) < 4:
  print(0)
else:
  N = len(S)
  d = [0]*2019
  d[0] = 1
  i = N-1
  while i >= 0:
    d[int(S[i:])%2019] += 1
    i -= 1
  ans = 0
  for m in d:
    ans += m*(m-1)//2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

s = input()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	ai[i] = (int(s[-1*i-1])*pow(10,i))%p
for i in range(len(ai)):
	si[i] = sum(ai[:i+1])%p
	#print(ai[:i+1],1)
countarr = [0]*2019
for i in si:
	countarr[i]+=1

res = countarr[0]
for i in range(p):
	c = countarr[i]
	res += c*(c-1)//2

print(res)

Submission status: Time Limit Exceeded

Solution code:
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)
S = input()[::-1]
N = len(S)
cnt = [0]*(N+1)
ans = 0
keta = 1
for i in range(N):
    cnt[i] = (cnt[i-1] + int(S[i])*keta)%2019
    keta *= 10
cnt2 = [0]*2020
for i in cnt:
    cnt2[i] += 1
for i in cnt2:
    if i >= 2:
        ans += C(i,2)
print(ans)

Submission status: Time Limit Exceeded

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

mod_list = []
for i in range(N-1, -1, -1):
    if i == N-1:
        num = int(S[i])
    else:
        num += int(S[i]) * (10 ** (N-1-i))
    mod_list.append(num % 2019)

mod_list.sort()

cnt = 0
ans = 0
for i in range(len(mod_list)-1):
    if mod_list[i] == 0:
        ans += 1
    if mod_list[i+1] == mod_list[i]:
        cnt += 1
    else:
        ans += cnt
        cnt = 0
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
h = [int(x) for x in list(S)]
N = len(h)
a = []
T = 0
r = 1
for i in range(N-1, -1, -1):
    T = T + h[i] * r
    r = r * 10
    a.append(T%2019)
b = []
for j in range(0, N):
    if a[j] not in b:
        b.append(a[j])
c = 0
for k in range(0, len(b)):
    d = a.count(b[k])
    c += d * (d-1) /2
c += a.count(0)
print(int(c))

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
R=[0]*(N+1)
for i in range(1,N+1):
    R[-(i+1)]=((int(S[-i])*10**(i-1))%(2019)+R[-i])%2019
#print(R)
L=[0]*2019
for r in R:
    L[r]+=1
ans=0
for l in L:
    if l>=2:
        ans+=l*(l-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

r = 0
for i in range(len(S)):
    for j in range(i + 1, len(S) + 1):
        t = int(S[i:j])
        if 1 <= t <= 200000 and t % 2019 == 0:
            r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    S_list = []
    for i in range(len(S)):
        S_list.append(int(S[i]))
    num = 0
    for i in range(len(S_list)-3):
        sum_temp = 0
        k = 0
        for v in range(i, i+3)[::-1]:
            sum_temp += 10**k*S_list[v]
            k += 1
        for j in range(i+3, len(S)):
            #print(S_list[j])
            sum_temp *= 10
            sum_temp += S_list[j]
            if sum_temp % 2019 == 0:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()
S = list(map(int, S))

nums = [0] * (len(S) + 1)
pow10 = 1
for i in range(1, len(S) + 1):
    nums[i] = (nums[i - 1] + pow10 * S[-i]) % 2019
    pow10 *= 10

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=input()
length=len(n)
rs=0
for i in range(1,length-2):
    num=0
    start=0
    end=length-i
    gap=length-end
    for j in range(i):
        num=int(n[start+j:end+1+j])
        if num%2019==0:
            rs+=1
print(rs)

Submission status: Time Limit Exceeded

Solution code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

s = input()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	ai[i] = (int(s[-1*i-1])*pow(10,i))%p
for i in range(len(ai)):
	si[i] = sum(ai[:i+1])%p
	#print(ai[:i+1],1)
countarr = [0]*2019
for i in si:
	countarr[i]+=1

res = si.count(0)
for i in range(p):
	c = countarr[i]
	res += c*(c-1)//2

print(res)

Submission status: Time Limit Exceeded

Solution code:
s = list(map(lambda x: int(x),list(input())))
p = [0 for i in range(2019)]
n = len(s)
ans = 0
kar = 0
for i in range(n):
    kar = kar + s[n-1-i]*10**i
    p[kar%2019] += 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

s=input()
s=s.strip("\n")
n=len(s)
res=0
d={key:0 for key in range(2019)}
t=[0]*(n+1)
d[0]=1
for i in range(1,n+1):
    t[n-i]=(t[n-i+1]+(int(s[n-i])*10**(i-1))%2019)%2019
    d[t[n-i]]+=1
for i in d.values():
    if i<2:
      continue
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

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

mod_list = []
for i in range(N-1, -1, -1):
    num = int(S[i:])
    mod_list.append(num % 2019)

mod_list.sort()

cnt = 0
ans = 0
for i in range(len(mod_list)-1):
    if mod_list[i] == 0:
        ans += 1
    if mod_list[i+1] == mod_list[i]:
        cnt += 1
    else:
        ans += cnt
        cnt = 0
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
listS = list(str(S))
l = len(listS)
cnt = 0
suml = [0]
for i in range(l):
    suml.append(int("".join(map(str, listS[l-i-1:l+1]))))
mod = []
for a in suml:
    mod.append(a % 2019)
for i in range(2019):
    if mod.count(i) > 1:
        cnt += ((mod.count(i))*(mod.count(i)-1))//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
L = [0]*2019
L[0]=1
digit = 1
x = 0

for i in S[::-1]:
    x += digit*int(i)
    digit *= 10
    x = x%2019
    L[x] += 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
import queue

def readInt():
	return int(input())

def readInts():
	return list(map(int, input().split()))

def readChars():
	return input().split()

s = input()

ai = [0]*len(s)
si = [0]*len(s)

p = 2019

for i in range(len(s)):
	ai[i] = (int(s[-1*i-1])*pow(10,i))%p
for i in range(len(ai)):
	si[i] = sum(ai[:i+1])%p
	#print(ai[:i+1],1)


res = si.count(0)
for i in range(p):
	c = si.count(i)
	res += c*(c-1)//2

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()
S = list(map(int, S))

S = S[::-1]
pow10 = 10
for i in range(1, len(S)):
    S[i] = S[i - 1] + S[i] * pow10
    pow10 *= 10

S = [0] + [n % 2019 for n in S]

counter = Counter(S)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

r = 0
for i in range(len(S)):
    for j in range(i + 1, len(S) + 1):
        t = float(S[i:j])
        if t:
            if t / 2019.0 == t // 2019:
                r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

s=input()
s=s.strip("\n")
n=len(s)
res=0
d={}
t=[0]*(n+1)
d[0]=1
for i in range(1,n+1):
    t[n-i]=(t[n-i+1]+(int(s[n-i])*10**(i-1))%2019)%2019
    if t[n-i] not in d:
        d[t[n-i]]=1
    else:
        d[t[n-i]]+=1
for i in d.values():
    if i<2:
      continue
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
import math

S = input()

tmp = []

for i in range(1,50008):
    x = 2019 * i
    if str(x).find("0") == -1:
        tmp.append(x)

ans = 0
ll = len(S)
for wide in range(5,9):
    for i in range(ll - wide + 1):
        if i + wide > ll:
            break
        ss = int(S[i:i+wide])
        if ss in tmp:
            ans += 1
        else:
            continue
        index = 0
        while True :
            flag = 0
            for ww in range(5,9):
                if i + wide + 1 + index + index + ww >=  ll :
                    flag  = 1
                    break
                if int(S[i+wide + 1 + index : i + wide + 1 + index + ww]) in tmp:
                    ans += 1
                index += 8
            if flag == 1:
                break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


s = input()
n = len(s)

dd = defaultdict(int)

# d = [0] * 2019
dd[0] = 1
tmp = 0
_10 = 1
# print(s, n)
for i in range(n - 1, -1, -1):
    # print(i, s[i])
    tmp = tmp + int(s[i]) * _10
    _10 *= 10
    # print(tmp, tmp % 2019)
    dd[tmp % 2019] += 1

# print(dd)
print(sum(v*(v-1)//2 for v in dd.values()))

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 1

for c in s:
    current += int(c) * d
    d *= 10
    current %= 2019
    counts[current] += 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

mod = 2019

s = input().rstrip()
n = len(s)

t = [int(s[n - 1])]

mul = 10
for i in range(n - 2, -1, -1):
    t.append((t[-1] + int(s[i])*mul) % mod)
    mul *= 10
t.append(0)

from collections import Counter

c = Counter(t)
ans = 0

for i in c.keys():
    ans += c[i]*(c[i] - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

S = input()
S = list(map(int, S))

nums = S[::-1]
pow10 = 10
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * pow10
    pow10 *= 10

nums = [0] + [n % 2019 for n in nums]

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += count * (count - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
p,*d,a,i=[1,1]+[0]*2020
for j in input()[::-1]:
  i=(i+int(j)*p)%2019
  a+=d[i]
  d[i]+=1
  p*=10
print(a)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[n-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import deque

s=input()
s=s.strip("\n")
n=len(s)
res=0
d={}
t=[0]*(n+1)
d[0]=1
for i in range(1,n+1):
    t[n-i]=(t[n-i+1]+(int(s[n-i])*10**(i-1))%2019)%2019
    if t[n-i] not in d:
        d[t[n-i]]=1
    else:
        d[t[n-i]]+=1
for i in d.values():
    res+=int(i*(i-1)/2)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = IN()
	s = input()
	
	ll=len(s)
	ret_count=0
	for i in range(ll-2):
		v = int(s[i:i+3])
		for c in s[i+3:]:
			v = (v * 10 + int(c))% 2019
			if v == 0:
				#print(i,j,s[i:j])
				#print(s[i:i+3],'aaa')
				ret_count += 1
	print(ret_count)
				
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
def solve(s):
    dp = [0] * 2019
    dp[0] = 1
    r = 0
    for i in range(1, len(s) + 1):
        r += int(s[-i]) * (10 ** (i - 1))
        r %= 2019
        dp[r] += 1
    res = 0
    for r in range(2019):
        res += dp[r] * (dp[r] - 1) // 2
    return res


def main():
    s = input()
    res = solve(s)
    print(res)


def test():
    assert solve("1817181712114") == 3
    assert solve("14282668646") == 2
    assert solve("2119") == 0


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

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for c in s:
    current += int(c) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

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

Submission status: Time Limit Exceeded

Solution code:
n=input()
length=len(n)
rs=0
for i in range(1,length-2):
    num=0
    start=0
    end=length-i
    gap=length-(end-start)
    for j in range(i):
        num=int(n[start+j:end+1+j])
        if num%2019==0:
            rs+=1
print(rs)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Time Limit Exceeded

Solution code:
import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)

uniques = list(set(mod))
for i in uniques:
  hoge = mod.count(i)
  if hoge != 1:
    cnt += (hoge * (hoge - 1)) // 2


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for c in s:
    current += int(c) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

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

Submission status: Time Limit Exceeded

Solution code:
string=input()
length=len(string)
mod=[0]*2019
while length > 0:
  mod[int(string[length-1:])%2019]+=1
  length-=1
print(int(sum([(i*(i-1))/2 for i in mod]))+mod[0])

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    s = input()
    m = [0] * (len(s) + 1)
    a = 1
    i = 1
    for c in map(int, reversed(s)):
        m[i] = (m[i-1] + c * a) % 2019
        a *= 10
        i += 1
    ans = 0
    for i in Counter(m).values():
        ans += (i - 1) * i // 2
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def main():
    S = input()
    S_list = []
    for i in range(len(S)):
        S_list.append(int(S[i]))
    S_list = np.array(S_list)
    num = 0
    for i in range(len(S_list)-3):
        sum_temp = np.sum([v * np.power(10, k) for k, v in enumerate(S_list[i:i+3][::-1])])
        #print(i, i+3, sum_temp)
        k = 0
        for j in range(i+3, len(S)):
            #print(S_list[j])
            sum_temp *= 10
            sum_temp += S_list[j]
            if sum_temp % 2019 == 0:
                num += 1
    print(num)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import log10
n = input()

MOD = 2019
ans = 0
dp = [0]*MOD
dp[0] = 1
temp = 0
for i in range(len(n)):
    temp = (temp+int(n[-i-1])*10**i) % MOD
    dp[temp] += 1

for item in dp:
    ans += item*(item-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


s = input()
n = len(s)

dd = defaultdict(int)

# d = [0] * 2019
dd[0] = 1

# print(s, n)
for i in range(n - 1, -1, -1):
    # print(i, s[i])
    tmp = s[i:n]
    # print(tmp, int(tmp) % 2019)
    dd[int(tmp) % 2019] += 1

# print(dd)
print(sum(v*(v-1)//2 for v in dd.values()))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import collections

def main():
    S = str(input())
    n = len(S)

    T = [-1 for i in range(n+1)]
    T[-1] = 0
    # for i in range(n):
    #     #print(S[i:])
    #     T[i] = int(S[i:]) % 2019
    # print(T)
    for i in reversed(range(n)):
        T[i] = (int(S[i])*10**(n-1 -i) + T[i+1]) % 2019

    #print(T)
    C = collections.Counter(T)
    #print(C) # dict 型のサブクラス，Counter
    ans = 0
    for value, count in C.items():
        ans += int(count*(count-1)/2)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Submission status: Time Limit Exceeded

Solution code:
import collections
n = str(input())
ans,div = 0,[]
for i in range(0,len(n)):
        k = int(n[i:len(n)])
        div.append(k % 2019)
div.append(0)
c = collections.Counter(div)
values, counts = zip(*c.most_common())
for i in range(0,len(counts)):
    ans += counts[i] *(counts[i]-1) /2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)

uniques = list(set(mod))
for i in uniques:
  if mod.count(i) != 1:
    cnt += (mod.count(i) * (mod.count(i) - 1)) // 2


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for c in s:
    current += int(c) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

ans = 0
for i, count in enumerate(counts):
    if count > 1:
        # print(i)
        ans += count * (count-1) //2
print(ans)


# res = [int(s[a:])%2019 for a in range(n)]
# res.append(0)

# ans = 0
# # count = Counter(res)
# # for i in range(2019):
# #     ans += (count[i] * (count[i] - 1)) // 2
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict


s = input()
n = len(s)

dd = defaultdict(int)

d = [0] * 2019
dd[0] = 1

# print(s, n)
for i in range(n - 1, -1, -1):
    # print(i, s[i])
    tmp = s[i:n]
    # print(tmp, int(tmp) % 2019)
    dd[int(tmp) % 2019] += 1

# print(dd)
print(sum(v*(v-1)//2 for v in dd.values()))

Submission status: Time Limit Exceeded

Solution code:
import collections
s = list(input())
p = []
n = len(s)
kar = 0
for i in range(n):
    kar = (kar + int(s[n-1-i])*(10**i))%2019
    p.append(kar)
c = collections.Counter(p)
ans = 0
for x , y in c.items():
    ans += y*(y-1)//2
    if x == 0:
        ans += y
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from math import factorial

S = input()
S = list(map(int, S))

nums = S[::-1]
for i in range(1, len(nums)):
    nums[i] = nums[i - 1] + nums[i] * 10 ** i

nums = [0] + [n % 2019 for n in nums]

counter = Counter(nums)
ans = 0
for count in counter.values():
    if count >= 2:
        ans += factorial(count) // (factorial(count - 2) * factorial(2))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
L = [0]*2019
L[0]=1

for i in range(len(S)):
    N = int("".join(S[i:]))%2019
    L[N] += 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#n,p = map(int,input().split())
s=input()
p = 2019
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
for i in s[::-1]:
    i = int(i)
    tmp=(tmp+i*ten)%p
    ten = ten*10
    l[tmp]+=1
for i in l:
    ans+= i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    s = input()
    l = len(s)
    m = [0] * (l + 1)
    a = 1
    for i in range(l - 1, -1, -1):
        m[i] = (m[i+1] + int(s[i]) * a) % 2019
        a *= 10
    ans = 0
    for i in Counter(m).values():
        ans += (i - 1) * i // 2
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()[::-1]
n = len(s)
counts = [0] * 2019
counts[0] = 1
current = 0
d = 0

for i in range(n):
    current += int(s[i]) * 10**d
    d += 1
    current %= 2019
    counts[current] += 1

ans = 0
for i, count in enumerate(counts):
    if count > 1:
        # print(i)
        ans += count * (count-1) //2
print(ans)


# res = [int(s[a:])%2019 for a in range(n)]
# res.append(0)

# ans = 0
# # count = Counter(res)
# # for i in range(2019):
# #     ans += (count[i] * (count[i] - 1)) // 2
# print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())

r = 0
for i in range(len(S)):
    for j in range(i, len(S) + 1):
        t = S[i:j]
        if t:
            t = float(t)
            if t >= 1 and t <= 200000:
                if str(t / 2019.0) == str(t // 2019):
                    r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    s = list(map(int, list(input())))
    l = len(s)
    m = [0] * (l + 1)
    a = 1
    for i in range(l - 1, -1, -1):
        m[i] = (m[i+1] + s[i] * a) % 2019
        a *= 10
    ans = 0
    for i in Counter(m).values():
        ans += (i - 1) * i // 2
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#n,p = map(int,input().split())
s=input()[::-1]
p = 2019
n = len(s)
ans = 0
l = [0 for i in range(p)]
l[0] = 1
z = 0
ten = 1
tmp = 0
for i in s:
    i = int(i)
    tmp=(tmp+i*ten)%p
    ten = ten*10
    l[tmp]+=1
for i in l:
    ans+= i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=int(input())
n=len(str(s))
t=0
for j in range(n-3):
    j+=4
    for i in range(j):
        k=s
        l=s
        k%=10**(n-j)
        l%=10**(n-i)
        if k%2019==l%2019:
            t+=1
print(t)

Submission status: Time Limit Exceeded

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

li = [int(s[-1])]

for i in range(n-1):
    t = int(s[-i-2])
    li.append((li[-1] + t * 10 ** (i+1)) % 2019)

dict1 = {}
for i in li:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1

ans = 0

for v in dict1.values():
    ans += v * (v-1) // 2

if 0 in dict1:
    ans += dict1[0]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

    N = len(S)

    M = [0 for i in range(2019)]
    M[0] += 1

    T = 0
    r = 1
    for i in range(N):
        T = int(S[N-i-1]) * r + T
        T = T % 2019
        M[T] += 1
        r *= 10

    res = 0

    for m in M:
        res += m * (m-1) // 2


    print(res)



main()

Submission status: Time Limit Exceeded

Solution code:
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    s = list(map(int, list(input())))
    l = len(s)
    m = [0] * (l + 1)
    for i in range(l - 1, -1, -1):
        m[i] = (m[i+1] + s[i] * pow(10, l - i - 1)) % 2019
    ans = 0
    for i in Counter(m).values():
        ans += (i - 1) * i // 2
    print(ans)

main()