Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(10**i))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)


Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp = [0]
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp.append(t)

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

print(ans)


Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp = [0]
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(10**i))%2019
    dp.append(t)

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

print(ans)


Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

anya = 100
ans = 0
flag = -1
for i in range(n-1,3,-1):
    for j in range(i-4,-1,-1):
        if flag > 0:
            flag -= 1
            continue
        val = int(''.join(s_l[j:i+1]))
        if val%2019 == 0 and val != 0:
            ans += 1
            flag = 4
        else:
            flag = -1
        if flag == 0:
            anya = 0
    if anya == 0:
        break


print(ans)

Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

ans = 0
flag = -1
for i in range(n-1,3,-1):
    for j in range(i-4,-1,-1):
        if flag > 0:
            flag -= 1
            continue
        val = int(''.join(s_l[j:i+1]))
        if val%2019 == 0 and val != 0:
            ans += 1
            flag = 4
        else:
            flag = -1

print(ans)

Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())
n = len(s_l)

ans = 0
flag = -1
for i in range(n-1,-1,-1):
    for j in range(i,-1,-1):
        if flag > 0:
            flag -= 1
            continue
        val = int(''.join(s_l[j:i+1]))
        if val%2019 == 0 and val != 0:
            ans += 1
            flag = 4
        else:
            flag = -1

print(ans)

Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())

ans = 0
for i in range(len(s_l)-1):
    for j in range(i+3,len(s_l)):
        val = int(''.join(s_l[i:j+1]))
        if val%2019 == 0 and val != 0:
            ans += 1

print(ans)

Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s_l = list(input())

ans = 0
for i in range(len(s_l)-1):
    for j in range(i,len(s_l)):
        val = int(''.join(s_l[i:j+1]))
        if val%2019 == 0 and val != 0:
            ans += 1

print(ans)

Fixed submission:
s_l = list(input())
n = len(s_l)

# 公式解説参照
dp_dict = {0:1}
t = 0
for i in range(n):
    a = int(s_l[-(i+1)])
    t = (t + a*(pow(10,i,2019)))%2019
    dp_dict[t] = dp_dict.get(t,0) + 1

ans = 0
for val in dp_dict.values():
    ans += val*(val-1)//2

print(ans)