Problem:


Score : 400 points

Problem Statement

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

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

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

Constraints

1 ≤ |S| ≤ 200000

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

Input

Input is given from Standard Input in the following format:

S

Output

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

Sample Input 1

1817181712114

Sample Output 1

3

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

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) <= 3:
  print(0)
  exit()
chk = [0]*2019
for i in range(len(s)):
  c = int(s[i:])
  chk[c%2019] += 1
ans = chk[0]
for i in chk:
  ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
t = 0
number = 0
m = [0 for i in range(2019)]
m[0] = 1
for i in range(len(s)):
    t = t  +  int(s[len(s) - 1 - i])* (10**i)
    #print(t)
    m[t % 2019] += 1
    #print(t%2019)

for j in range(2019):
    if m[j]>= 2:
        number += (m[j]*(m[j] - 1))//2

print(number)

Submission status: Time Limit Exceeded

Solution code:
s=input()



"""
例)
1817181712114の
18171が2019で割り切れるかどうかを判断する。

18171は(181712114-2114)/10000となるので、
181712114mod2019＝2114mod2019の時、2019で割り切れる。

1817181712114mod2019
 817181712114mod2019
  17181712114mod2019
   7181712114mod2019
    181712114mod2019
     81712114mod2019
      1712114mod2019
       712114mod2019
    　　・・・・
とmodを調べていき、値が同じペアは割り切れる。
"""

result=0

#初期値が0の辞書
from collections import defaultdict
mod_num = defaultdict(lambda: 0) 

for i in range(1,len(s)+1):
    temp = int(s[len(s)-i:])
    if temp%2019==0:
        result+=1
    else:
        result+=mod_num[temp%2019]
        mod_num[temp%2019]+=1


print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()

"""
例)
1817181712114の
前から5文字目から始まる18171が2019で割り切れるかどうかを判断する。

18171は(181712114-2114)/10000となるので、
181712114mod2019＝2114mod2019の時、2019で割り切れる。

1817181712114mod2019
 817181712114mod2019
  17181712114mod2019
   7181712114mod2019
    181712114mod2019
     81712114mod2019
      1712114mod2019
       712114mod2019
    　　・・・・
とmodを調べていき、modの値が同じペアは割り切れる。
"""

result=0

#初期値が0の辞書
from collections import defaultdict
mod_num = defaultdict(lambda: 0) 

for i in range(1,len(s)+1):
    temp = int(s[len(s)-i:])
    if temp%2019==0:
        result+=1
    else:
        result+=mod_num[temp%2019]
        mod_num[temp%2019]+=1


print(result)

Submission status: Time Limit Exceeded

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

A=[]
for i in range(len(S)):
  A.append(int(S[i:])%2019)

B=set(A)
b=0
for i in B:
  if i!=0:
    a = A.count(i)
    b += a*(a-1)/2
  else:
    b += 1

print(int(b))

Submission status: Time Limit Exceeded

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

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == 0:
        continue
    else:
        s += S[len(S)-i-1] * 10**i
        amari[s % 2019] += 1

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

counter += amari[0]

print(int(counter))

Submission status: Time Limit Exceeded

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

counter = 0
amari = [0]*2019

s = 0
for i in range(len(S)):
    if S[len(S)-i-1] == "0":
        continue
    else:
        s += int(S[len(S)-i-1]) * 10**i
        amari[s % 2019] += 1

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

counter += amari[0]

print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 2019

    S = input()[::-1]
    N = len(S)

    if N < 4:
        print(0)
        return

    R = [0] * 2019
    R[0] = 1 # '' の分
    t = 0
    b = 1
    for c in S:
        t += int(c) * b
        t %= 2019
        R[t] += 1
        b *= 10
    ans = 0
    for r in R:
        ans += r*(r-1)//2
    print(ans)
    




    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = str(input())[::-1]
sum_of_digits = 0
cnt = [0] * 2019

cnt[0] = 1
d = 1
for i, c in enumerate(s, start=1):
    sum_of_digits *= 1
    d = 10 ** (i-1)
    d %= 2019
    sum_of_digits += d * int(c)
    sum_of_digits %= 2019
    cnt[sum_of_digits] += 1
    #print(sum_of_digits)

print(sum([i*(i-1)//2 for i in cnt]))

Submission status: Time Limit Exceeded

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 2019

    S = input()[::-1]
    N = len(S)
    nums = [0] * N
    for i in range(N):
        nums[i] = int(S[i])
    if N < 4:
        print(0)
        return

    R = [0] * 2019
    R[0] = 1 # '' の分
    t = 0
    b = 1
    for i in range(N):
        t += nums[i] * b
        t %= 2019
        R[t] += 1
        b *= 10
    ans = 0
    for r in R:
        ans += r*(r-1)//2
    print(ans)
    




    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = str(input())[::-1]
sum_of_digits = 0
cnt = [0] * 2019

cnt[0] = 1
d = 1
for i, c in enumerate(s, start=1):
    sum_of_digits *= 1
    d = 10 ** (i-1)
    #d %= 2019
    sum_of_digits += d * int(c)
    sum_of_digits %= 2019
    cnt[sum_of_digits] += 1
    #print(sum_of_digits)

print(sum([i*(i-1)//2 for i in cnt]))

Submission status: Time Limit Exceeded

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 2019

    S = input()[::-1]
    N = len(S)
    nums = [0] * N
    for i in range(N):
        nums[i] = int(S[i])
    if N < 4:
        print(0)
        return

    R = [0] * 2019
    R[0] = 1 # '' の分
    t = 0
    for i in range(N):
        t += nums[i] * (10**i)
        t %= 2019
        R[t] += 1
    ans = 0
    for r in R:
        ans += r*(r-1)//2
    print(ans)
    




    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N = len(S)
    S = int(S)
    work, temp = [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    print(sum([w*(w-1)//2 for w in work]))
main()

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
_MOD = {0:1}

for i in range(len(S)):
    j = int(S[i:]) % 2019
    if j in _MOD:
        _MOD[j] = _MOD[j] + 1
    else:
        _MOD[j] = 1
        
for i in _MOD:
    m= _MOD[i]
#    ans += (_MOD[i] * (_MOD[i] - 1)) // 2
    ans += (m * (m - 1)) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
ans = 0
mod = [0]*2019
mod[0] += 1
for i in range(l):
    num = int(S[-i-1:])
    
    k = num % 2019
    mod[k] += 1
for i in mod:
    if i != 0:
        ans += (i-1)
        


print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
_MOD = {0:1}

for i in range(len(S)):
    j = int(S[i:]) % 2019
    if j in _MOD:
        _MOD[j] = _MOD[j] + 1
    else:
        _MOD[j] = 1
        
for i in _MOD:
    ans += (_MOD[i] * (_MOD[i] - 1)) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()[::-1]
current = 0
a = [0] * 2019
a[0] = 1
digit = 1
for i in s:
  current += int(i) * digit
  digit *= 10
  current %= 2019
  a[current] += 1
ans = 0
for i in a:
  ans += i * (i - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N = len(S)
    S = int(S)
    result, work, temp = 0, [0] * 2019, 0
    for i in range(N+1): work[(S % 10**i) % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Submission status: Time Limit Exceeded

Solution code:
S=input()[::-1]
l=[0]*2019
a=1
d=0

for s in S:
  d=d+int(s)*a
  l[d%2019]+=1
  a*=10
  
ans=l[0]
for i in l:
  if i>=2:
    ans+=i*(i-1)//2
    
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
for i in range(m-1,-1,-1):
    a=str(a)
    a=int(s[i]+a)
    d=a%2019
    c[d]=c[d]+1
for i in c:
    if i<=1:
        continue
    e+=i*(i-1)//2
print(e)

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    i = 0
    for s in S[::-1]:
        temp += _int(s) * 10**i
        work[temp % 2019] += 1
        i += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
S = input()
list1 = []

for i in range(len(S)+1):
    for j in range(len(S)+1):
        if i<j:
            list1.append(int(S[i:j]))
arr = np.array(list1)%2019
print(np.sum(arr==0))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = input()
    N, result, work, temp, _int = len(S), 0, [0] * 2019, 0, int
    work[0] += 1
    for i in range(N):
        temp += _int(S[N - i - 1]) * 10**i
        work[temp % 2019] += 1
    for w in work: result += w*(w-1)//2
    print(result)
main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
for i, s in enumerate(Sr):
  T += int(s) * ((10 ** (i+1)) % 2019 % 2019)
  mod[T%2019] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Time Limit Exceeded

Solution code:
s=input()
b=0
m=len(s)
c=[0 for i in range(2019)]
c[0]=c[0]+1
a=""
e=0
for i in range(m-1,-1,-1):
    a=str(a)
    a=s[i]+a
    a=int(a)
    d=a%2019
    c[d]=c[d]+1
for i in c:
    e+=i*(i-1)//2
print(e)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
for i, s in enumerate(Sr):
  T += int(s) * ((10 ** (i+1)) % 2019)
  mod[T%2019] += 1
  
# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Time Limit Exceeded

Solution code:
number = input()
match = 0
for start in range(1, len(number)):
  for end in range(start+3, len(number)+1):
    if int(number[start-1:end]) % 2019==0:
      match += 1
print(match)

Submission status: Time Limit Exceeded

Solution code:
S = input()
list1 = []

for i in range(len(S)+1):
    for j in range(len(S)+1):
        if i<j and int(S[i:j])%2019==0:
            list1.append(1)
print(sum(list1))

Submission status: Time Limit Exceeded

Solution code:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
for i in range(len(s)):
    ans[tmp%2019]+=1
    tmp=10**i*int(s[-i-1])+tmp
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    S = input()
    N = len(S)
    result = 0
    work = [0] * (N + 1)
    temp = 0
    for i in range(N):
        temp += int(S[N - i - 1]) * 10**i
        work[i] = temp % 2019
    for v in Counter(work).values(): result += v*(v-1)//2
    print(result)
main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()
N = len(S)
result = 0
work = [0] * (N + 1)
temp = 0
for i in range(N):
    temp += int(S[N - i - 1]) * 10**i
    work[i] = temp % 2019
for v in Counter(work).values(): result += v*(v-1)//2
print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
for i in range(len(s)):
    ans[tmp%2019]+=1
    tmp=pow(10,i)*int(s[-i-1])+tmp
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Submission status: Time Limit Exceeded

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

p = 1
d = 0
for t in reversed(s):
    d += int(t) * p
    p *= 10
    m = d % n
    mod_list[m] += 1

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
_MOD = [0] * 2019
_MOD[0] = 1

for i in range(len(S)):
    j = int(S[i:]) % 2019
    _MOD[j] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
Sr = S[::-1] # 一の位から考える

T = 0 # 部分文字列
mod = [0] * 2019 # mod数え上げ配列
mod[0] += 1 # 「部分文字列T = S」の場合の、 「0 % 2019 = 0」を予めカウント
for i, s in enumerate(Sr):
  T += int(s) * (10 ** i)
  mod[T%2019] += 1

# ペアを合計
mod = [m//2 for m in mod]
print(sum(mod))

Submission status: Time Limit Exceeded

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

countdic = {}
mod = 2019

num = 0
d = 1
for i in range(1,n+1):
    num += s[n-i]*d
    remainder = num%mod
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1
    d *= 10

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

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

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(s_len):
    t_i = int(s[i:])
    m = t_i % n
    mod_list[m] += 1

result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
List=[0]*2019
ans=0

for i in range(0,n):
  List[(int(s[i:])%2019)]+=1
  #print(s[i:],int(s[i:])%2019)
  
#print(List)
ans=List[0]
for i in List:
  if (i>=2):
    ans+=(i*(i-1))//2
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
surplus = [0]*2019
surplus[0] += 1

d = 1
n = 1
T = 0

for i in reversed(input()):
    T += int(i)*n
    d = T%2019
    n *=10
    surplus[d] +=1
    #print (T, d)
    

#for i in surplus:
#    print (i)
    
print(sum([i*(i-1)//2 for i in surplus]))

Submission status: Time Limit Exceeded

Solution code:
S = input()
n = len(S)
k = 2019

# Let S = s[0]s[1]....s[n - 1] and
# let A[i] = s[i]s[i+1]...s[n-1] = s[i]*10^(n-i-1) + ... + s[n-1]*10^0
A = [0] * (n + 1) # A[n]はダミー

w = 1
for i in range(n - 1, -1, -1):
    A[i] = (A[i + 1] + w * int(S[i])) % k
    w = w * 10 % k

ans = 0
for j in range(k):
    c = A.count(j)
    ans += c * (c - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

countdic = {}
mod = 2019

num = 0
for i in range(1,n+1):
    num += s[n-i]*(10**(i-1))
    num %= mod
    if num in countdic:
        countdic[num] += 1
    if num not in countdic:
        countdic[num] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
surplus = [0]*2019
surplus[0] += 1

d = 1
n = 0
T = 0

for i in reversed(input()):
    T += int(i)*(10**n)
    d = T%2019
    n +=1
    surplus[d] +=1
    #print (T, d)
    

#for i in surplus:
#    print (i)
    
print(sum([i*(i-1)//2 for i in surplus]))

Submission status: Time Limit Exceeded

Solution code:
s=input().rstrip()
ans=[0 for i in range(2019)]
ans[0]=1
for i in range(len(s)):
    tmp=int(s[i:])%2019
    ans[tmp]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

s = input()
s_len = len(s)
n = 2019
mod_list = [0] * n
mod_list[0] = 1

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    #mod_list.append(m)
    mod_list[m] += 1

#c = collections.Counter(mod_list)
#result = sum(i * (i - 1) // 2 for i in c.values())
result = sum(i * (i - 1) // 2 for i in mod_list)
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

s = input()
s_len = len(s)
n = 2019
mod_list = [0]

for i in range(s_len):
    t = s[i:]
    t_i = int(t)
    m = t_i % n
    mod_list.append(m)

c = collections.Counter(mod_list)
result = sum(i * (i - 1) // 2 for i in c.values())
print(result)

Submission status: Time Limit Exceeded

Solution code:
s=input()
n=len(s)
List=[0]*2019
ans=0
for i in range(0,n):
  List[(int(s[i:])%2019)]+=1
  #print(s[i:],int(s[i:])%2019)
  
#print(List)
ans=List[0]
for i in range(2019):
  ans+=(List[i]*(List[i]-1))//2
  
print(ans)

Submission status: Time Limit Exceeded

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

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

a = 1
d = 0

for s in S:
    d = d + int(s)*a
    num = d%2019
    counts[num] += 1
    a *= 10

ans = 0

for i in counts:
    if i >=2:
        x = (i*(i-1))//2
        ans += x

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

S = input()[::-1] # 入力文字列を逆順でsに格納

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

a = 1
d = 0

for s in S:
    d = d + int(s)*a
    num = d%2019
    counts[num] += 1
    a *= 10

ans = 0

for i in counts:
    if i >=2:
        x = (i*(i-1))//2
        ans += x

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

S = input()[::-1] # 入力文字列を逆順でsに格納

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

a = 1
d = 0

for s in S:
    d = d + int(s)*a
    num = d%2019
    counts[num] += 1
    a *= 10

ans = 0

for i in counts:
    if i >=2:
        x = len(list(combinations(list(range(i)),2)))
        ans += x

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,deque
from scipy import special
S = input()
l = [int(n) for n in S]
a = [0]
t = 0
m = 1
d = deque(l)
while d:
    temp = d.pop()
    t += temp*m
    m *= 10
    a.append(t%2019)
b = [special.comb(kv,2,exact=True) for kv in Counter(a).values() if kv > 1]
print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
s = list(map(int, list(input())))[::-1]
n = len(s)
c = [0]*2019
c[0]+=1
t = 0
ten = 1
for i in range(n):
    t = (t+s[i]*ten) % 2019
    ten*=10
    c[t]+=1
ans = 0
ans = sum(cc*(cc-1)//2 for cc in c)
print(ans)

Submission status: Time Limit Exceeded

Solution code:


for i in range(1):
    # n,m=map(int,input().split())
    n=input()
    count=0;
    for i in range(0,len(n)+1):
        for j in range(i+3,len(n)+1):
            if(int(n[i:j])%2019==0):
                # print(n[i:j],end=" ")
                count+=1
    # print()
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = list(map(int, list(input())))[::-1]
n = len(s)
c = Counter([])
c[0]+=1
t = 0
ten = 1
for i in range(n):
    t = (t+s[i]*ten) % 2019
    ten*=10
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
mc=[0]*2019

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mc[tg%2019]+=1
    digit*=10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Submission status: Time Limit Exceeded

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

countdic = {}
mod = 2019

for i in range(1,n+1):
    num = int(s[n-i:n])
    remainder = num%mod
    if remainder in countdic:
        countdic[remainder] += 1
    if remainder not in countdic:
        countdic[remainder] = 1

ans = 0
for key in countdic:
    ans += countdic[key]*(countdic[key]-1)//2

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = list(map(int, list(input())))[::-1]
n = len(s)
c = Counter([])
c[0]+=1
t = 0
for i in range(n):
    t = (t+int(s[i])*pow(10, i))%2019
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    mc[mt]+=1
    digit*=10%2019

ans=sum(m*(m-1)//2 for m in mc)
print(ans+mc[0])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S = input()
a = [0,int(S)%2019]
init = 0
for i in range(len(S)-1):
    S = S[1:]
    a.append(int(S)%2019)
b = [kv*(kv-1)//2 for kv in Counter(a).values() if kv > 1]
print(sum(b))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()
n = len(s)
c = Counter([])
c[0]+=1
for i in range(n):
    t = int(s[i:])%2019
    c[t]+=1
ans = 0
for v in c.values():
    ans+=v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    digit*=10%2019
    
print(cnt)

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1

print(sum([i*(i-1)//2 for i in surplus]))

Submission status: Time Limit Exceeded

Solution code:
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

tg=0
digit=1
for s in S[::-1]:
    tg+=int(s)*digit
    mt=tg%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    digit*=10
    
print(cnt)

Submission status: Time Limit Exceeded

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

dp = [0] * (n+1)

for i in range(n):
    t = int(s[i:])%2019
    dp[i] = t
c = Counter(dp)
ans = 0
for k, v in c.items():
    ans+=v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
cnt=0
S=str(input())
mc=[0]*2019
L=len(S)

for i in range(L):
    mt=int(S[L-1-i:])%2019
    if mt==0:cnt+=1
    cnt+=mc[mt]
    mc[mt]+=1
    
print(cnt)

Submission status: Time Limit Exceeded

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

S = input()
N = len(S)

counter = 0
surplus = [0]*2019
surplus[0] += 1

for i in range(N):
    surplus[int(S[i:]) % 2019] += 1
#print(surplus)
for x in surplus:
    if x >= 2:
        counter += int(x*(x-1)/2)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
s = input()
p = 0
dp = [0] * 2019
dp[0] = 1
for i in range(len(s)):
    p = (p + (int(s[-1 - i]) * (10 ** (i)))) % 2019
    dp[p] += 1
ans = 0
for i in dp:
    ans += i * (i - 1) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = list(input())[::-1]
    ary_mod = [0] * 2019
    ary_mod[0] = 1
    now = 0

    for i, ss in enumerate(s):
        now += int(ss) *( 10 ** i) % 2019
        remind = now % 2019
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.

    temp = 0
    digit = 1
    for i, c in enumerate(s[::-1]):
        # No time to pow.
        temp += int(c) * digit
        rem[temp % 2019] += 1
        digit *= 10

    return sum(c * (c - 1) // 2 for c in rem)


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

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
p = 0
dp = [0]
for i in range(len(s)):
    p = (p + (int(s[-1 - i]) * (10 ** (i)))) % 2019
    dp.append(p % 2019)
t = collections.Counter(dp)
ans = 0
for i in t.values():
    ans += i * (i - 1) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
cnt=0
S=str(input())
m=[0]*len(S)
L=len(S)

for i in range(L):
    m[i]=int(S[L-1-i:])%2019
    if m[i]==0:cnt+=1
    for j in range(L-i,L):
        if m[i]==m[L-1-j]:
            cnt+=1 
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.

    temp = 0
    for i, c in enumerate(s[::-1]):
        temp += 10 ** i * int(c)
        rem[temp % 2019] += 1

    return sum(c * (c - 1) // 2 for c in rem)


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

Submission status: Time Limit Exceeded

Solution code:
import os

def main():
	s = input()
	count = 0
	for i in range(len(s) - 4):
		for j in range(len(s) - 3):
			if j < i:
				continue
			if int(s[i:j+4])%2019 == 0:
				count += 1
	print(count)			


if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = list(input())[::-1]
    ary_mod = [0] * 2019
    ary_mod[0] = 1
    now = 0

    for i, ss in enumerate(s):
        now += (int(ss) * 10 ** i)
        remind = now % 2019
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
s = input()
p = 0
dp = [0]
for i in range(len(s)):
    p = p + (int(s[-1 - i]) * (10 ** (i)))
    dp.append(p % 2019)
t = collections.Counter(dp)
ans = 0
for i in t.values():
    ans += i * (i - 1) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = list(input())[::-1]
    ary_mod = [0] * 2019
    ary_mod[0] = 1
    now = 0

    for i, ss in enumerate(s):
        now += (int(ss) * 10 ** i) % 2019
        remind = now % 2019
        ary_mod[remind] += 1
    ans = 0
    for i, n in enumerate(ary_mod):
        ans += (n*(n-1)) // 2
    print(ans)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections


def main():
    s = collections.deque(int(c) for c in input())
    rem = [0] * 2019  # the count of the each remainder: 0 ~ 2018
    rem[0] = 1  # why? can't understand.

    temp = 0
    s_pop = s.pop
    for i in range(len(s)):
        temp += s_pop() * 10 ** i
        rem[temp % 2019] += 1

    return sum(c * (c - 1) // 2 for c in rem)


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

Submission status: Time Limit Exceeded

Solution code:
s = input()
el = []
nn = len(s)
for i in range(nn):
  el.append( int(s[i]))

jt=[[ (j*10 + i ) % 2019 for j in range(2019)] for i in range(10)]
cnt = 0

for i in range(nn-3):
  wk = el[i]
  for j in range(i+1,nn):
    wk = jt[el[j]][wk]
    if wk == 0 :
      cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  n, d, mods = 0, 1, [1]+[0]*2019
  for i in reversed(input()):
    n = (n+int(i)*d)%2019
    d = d*10
    mods[n] += 1
  print(sum([i*(i-1)//2 for i in mods]))
main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
from collections import defaultdict 
t = [0 for i in range(len(s))]
mods = defaultdict(int)
mods[0] += 1
for i in range(len(s)):
  mods[int(s[i:])%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
from collections import defaultdict 
mods = defaultdict(int)
mods[0] += 1
for i in range(len(s)):
  mods[int(s[i:])%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()
from collections import defaultdict 
t = [0 for i in range(len(s))]
mods = defaultdict(int)
mods[0] += 1
for i in range(len(s)):
  mods[int(s[i:])%2019] += 1
cnt = 0
for key, value in mods.items():
  cnt += value*(value-1)//2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,deque
from scipy import special
def pow_k(x, n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K * x)
        x = (x * x)
        n //= 2
    return (K * x)
S = input()
l = [int(n) for n in list(S)]
a = [0]
init = 0
i = 0
d = deque(l)
while d:
    temp = d.pop()
    init += temp*pow_k(10,i)
    a.append(init%2019)
    i += 1
b = [special.comb(kv,2,exact=True) for kv in Counter(a).values() if kv > 1]
print(sum(b))

Submission status: Time Limit Exceeded

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

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

num, d = 0, 1

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

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