Buggy python submission (verdict: Time Limit Exceeded):
S=input()[::-1]
l=len(S)
t=0
p=0

ss=[0]*2019
ss[0]=1
d=1
for i in S:
    p=(p+int(i)*d)%2019
    d*=10
    ss[p]+=1

for c in ss:
    t+=c*(c-1)//2
print(t)


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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()[::-1]
l=len(S)
t=0
p=0

ss=[0]*2019
ss[0]=1
d=1
for i in S:
    p=(p+int(i)*d)%2019
    d*=10
    ss[p]+=1

for c in ss:
    t+=c*(c-1)//2
print(t)


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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
l=len(S)
t=0
p=0
m=[]
ss=[0]*2019
ss[0]=1
for i in range(l):
    p=(p+int(S[i])*(10**(l-1-i)))%2019
    ss[p]+=1
for c in ss:
    t+=c*(c-1)//2
print(t)


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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
l=len(S)
t=0
p=0
m=[]
ss=[0]
for i in range(l):
    m.append(int(S[i])*(10**(l-1-i))%2019)
    ss.append((ss[i]+m[i])%2019)

k=collections.Counter(ss)

for i in k.values():
    t+=(i-1)
print(t)



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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
l=len(S)
t=0
p=0
m=[]
ss=[0]
for i in range(l):
    m.append(int(S[i])*(10**(l-1-i))%2019)
    ss.append((ss[i]+m[i])%2019)

k=collections.Counter(ss)

for i in k.values():
    if i>1:
        t+=(i-1)
print(t)


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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
import collections
S=input()
l=len(S)
t=0
p=0
m=[0] * l
ss=[0]*(l+1)
for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019
    ss[i+1]=(ss[i]+m[i])%2019

k=collections.Counter(ss)

for i in k.values():
    if i>1:
        t+=(i-1)
print(t)



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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l-3):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)



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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Runtime Error):
S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)

S=input()
l=len(S)
t=0
p=0
m=[0] * l

for i in range(l):
    m[i]=int(S[i])*(10**(l-1-i))%2019

for i in range(l):
    p=0
    for j in range(l-i):
        p=(p+m[i+j])%2019
        if p==0:
            t+=1
print(t)



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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
mm=[[0] * l for i in range(10)]

for i in range(10):
    for j in range(l):
        mm[i][j]=i*(10**j)%2019




for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):


        p=(p+mm[int(S[i-j])][j])%2019

        if p==0:

            t+=1

print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0

for k in range(4,l+1):
   for i in range(l-k+1):

      if int(S[i:(i+k)])%2019==0:
         t+=1
print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
mm=[[0] * l for i in range(10)]

for i in range(10):
    for j in range(l):
        mm[i][j]=i*(10**j)%2019




for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):


        p=(p+mm[int(S[i-j])][j])%2019

        if p==0:

            t+=1

print(t)


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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
m=[[0] * l for i in range(l)]

for i in range(l):
    for j in range(l-i):
        m[i][j]=int(S[i])*(10**j)%2019

for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):
        p=(p+m[i-j][j])%2019

        if p==0:

            t+=1

print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
for i in range(l-1,2,-1):

    p=0
    for j in range(i+1):
        p=(p+int(S[i-j])*(10**j))%2019

        if p==0:

            t+=1

print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0
p=0
for i in range(l-1,2,-1):
    p=0
    for j in range(i+1):
        p+=int(S[i-j])*(10**j)%2019

        if p%2019==0:

            t+=1

print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
l=len(S)
t=0

for k in range(4,l+1):
   for i in range(l-k+1):

      if int(S[i:(i+k)])%2019==0:
         t+=1
print(t)

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

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

num, d = 0, 1

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

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

print(ans) # 答えの出力