Buggy python submission (verdict: Time Limit Exceeded):
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10

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

print(ans)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = list(input())
del S[-1]
Surpus = [-1 for i in range(2019)]
Surpus[0] = 0

T = 0
for count, i in enumerate(S):
    T += int(S[-1 - count]) * (10 ** count)
    Surpus[T % 2019] += 1

ans = 0
for i in Surpus:
    ans += int(i * (i + 1) / 2)

print(ans)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = int(input())
S_Len = len(str(S))
Surpus = [-1 for i in range(2019)]
Surpus[0] = 0

for i in range(1,S_Len + 1):
    x = S % (10 ** i)
    Surpus[x % 2019] += 1


ans = 0
for i in Surpus:
    ans += int(i * (i + 1) / 2)

print(ans)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = int(input())
StrS = str(S)
S_Surpus = S % 2019
LenS = len(str(S))
ListSurpus = []


for i in range(LenS):
    Surpus = (int(StrS[i]) * (10 ** (LenS - i - 1) )) % 2019
    ListSurpus.append(Surpus)

#print(ListSurpus)

ans = 0

for i in range(LenS):
    sum = ListSurpus[i]
    for j in range(i+1, LenS):
        sum += ListSurpus[j]
        if(sum % 2019 == 0):
            ans += 1
print(ans)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = int(input())
StrS = str(S)
S_Surpus = S % 2019
LenS = len(str(S))
ListSurpus = []


for i in range(LenS):
    Surpus = (int(StrS[i]) * (10 ** (LenS - i - 1) )) % 2019
    ListSurpus.append(Surpus)

#print(ListSurpus)

ans = 0

for i in range(LenS):
    sum = ListSurpus[i]
    for j in range(i+1, LenS):
        sum += ListSurpus[j]
        if(sum % 2019 == 0):
            ans += 1
print(ans)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
def search2019(x):
    """
    i: 始める場所
    x: 数字のみからなる文字列
    """
    xLen = len(x)
    if xLen < 4:
        return 0
    else:
        ans = 0

        for i in range(3,xLen):
                Slice = int(x[0:i+1])
                if (Slice != 0 and Slice % 2019 == 0):
                    #print(i)
                    #print(S,Slice)
                    ans += 1 + search2019(x[i+1:xLen])
                    break
        return ans

S = str(input())
S = S[0:len(S)-1]
#print(S)
#print(search2019(S))


Slen = len(S)
if (Slen < 4):
    print(0)

else:
    ans = 0
    for i in range(Slen - 3):
        for j in range(i+3, Slen):
            Slice = S[i:j+1]
            if ( int(Slice) != 0 and int(Slice) % 2019 == 0):
                ans += 1 + search2019(S[j+1:Slen])
                break
                #print(i, j)
    print(ans)
    #print(Slen)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def EachSumStr(x):
    Len = len(x)
    sum = 0
    for i in range(Len):
        sum += int(x[i])
    #print(sum)

S = str(input())
Slen = len(S) - 1
if (Slen < 4):
    print(0)

else:
    ans = 0
    for i in range(Slen - 3):
        for j in range(i+3, Slen):
            Slice = S[i:j+1]
            if ( int(Slice) != 0 and int(Slice) % 2019 == 0):
                ans += 1
                #print(i, j)
    print(ans)
    #print(Slen)

Fixed submission:
S = input()[::-1]
Surpus = [0] * 2019
Surpus[0] = 1

sum = 0
x = 1
for i in S:
    sum += int(i) * x
    Surpus[sum % 2019] += 1
    x *= 10
    x %= 2019

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

print(ans)