Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[n-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()


Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        if rem_num >= 2:
            ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    s = input()
    n = len(s)
    mod = 2019

    reminder = [0]*mod
    pre_rem = 0

    for i in range(n):
        pre_rem = (int(s[-i-1])*pow(10, i) + pre_rem) % mod
        reminder[pre_rem] += 1

    ans = reminder[0]  # そのまま割り切れる奴ら
    for rem_num in reminder[1:]:  # _nC_2をしてる
        ans += (rem_num * (rem_num -1))//2
    print(ans)
    
solve()

Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    s = input()

    ans = 0
    if len(s) >= 5:
        for i in range(5, len(s)):
            for j in range(i):
                for k in range((len(s)-j)//i):
                    if int(s[i*k+j:i*(k+1)+j]) % 2019 == 0:
                        ans += 1
                        #print(i*k+j, i*(k+1)+j)
                        #print(s[i*k+j:i*(k+1)+j])
    print(ans)
    
solve()

Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

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

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    s = input()

    ans = 0
    for i in range(len(s)):
        for j in range(i+3,len(s)):
            #print(s)
            #print(i, j)
            #print(s[i:j])
            if int(s[i:j+1]) % 2019 == 0:
                ans += 1
                #print(i, j)

    print(ans)

solve()

Fixed submission:
S=input()
N=len(S)
M=2019

remainder=[0]*M
val=0
for i in range(N):
  val=(int(S[N-1-i])*pow(10,i,M)+val)%M
  remainder[val]+=1

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