Buggy python submission (verdict: Time Limit Exceeded):
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
for i,u in enumerate(U):
    now+=int(u)*(10**i)
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Fixed submission:
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
for i,u in enumerate(U):
    now+=int(u)*(10**i)
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Fixed submission:
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
for i,u in enumerate(U):
    now+=int(u)*(10**i)
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Fixed submission:
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#D
S = list(str(input()))
N = len(S)
S = S[::-1]

DP = [-1]*(N+1)
DP[0] = 0
now = 0
for i in range(N):
    now+=int(S[i])*(10**i)
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Fixed submission:
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#D
S = list(str(input()))
N = len(S)
S = S[::-1]

DP = [-1]*(N+1)
DP[0] = 0
now = 0
for i in range(N):
    now+=int(S[i])*(10**i)
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)




Fixed submission:
#D
S = list(str(input()))
N = len(S)

U = []
for i in range(N):
    U.append(int(S[N-i-1]))


DP = [-1]*(N+1)
DP[0] = 0
now = 0
pnow = 1
for i,u in enumerate(U):
    pnow*=10
    pnow%=2019
    now+=int(u)*pnow
    now%=2019
    DP[i+1] = now
    
#print(DP)
tyo = [0]*2019
for dp in DP:
    tyo[dp]+=1

ans = 0
for t in tyo:
    ans+=(t*(t-1))//2
    
print(ans)