Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
for i in range(l):
    mod[int(s[i:])%2019] += 1

cnt += mod[0]

for i in range(1,2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
print(int(cnt))


Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [[0]*(l-3) for i in range(l-3)]
#print(mod)
mod2 = [[0]*9 for i in range(l-3)]
for i in range(l-3):
    for j in range(1,10):
        mod2[i][j-1] = (j*pow(10,i+3,2019))%2019
#print(mod2)
for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        if (w == 4):
            m = (mod2[0][int(s[i])-1]+int(s[i+1:j]))%2019
            mod[w-4][i] = m
            if m == 0:
                cnt += 1
        else:
            m = (mod2[w-4][int(s[i])-1]+mod[w-5][i+1])%2019
            mod[w-4][w-4+i] = m
            if m == 0:
                cnt += 1
#print(mod)
print(cnt)

Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [[0]*(l-3) for i in range(l-3)]
#print(mod)
for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        if (w == 4):
            m = int(s[i:j])%2019
            mod[w-4][i] = m
            if m == 0:
                cnt += 1
        else:
            m = (int(s[i])*pow(10,w-1,2019)+mod[w-5][i+1])%2019
            mod[w-4][w-4+i] = m
            if m == 0:
                cnt += 1
#print(mod)
print(cnt)

Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [[0]*(l-3) for i in range(l-3)]
#print(mod)
for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        if (w == 4):
            m = int(s[i:j])%2019
            mod[w-4][i] = m
            if m == 0:
                cnt += 1
        else:
            m = (int(s[i])*pow(10,w-1)+mod[w-5][i+1])%2019
            mod[w-4][w-4+i] = m
            if m == 0:
                cnt += 1
#print(mod)
print(cnt)

Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0

for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        #print(s[i:j])
        if (int(s[i:j])%2019 == 0):
            cnt += 1
print(cnt)

Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0

for w in range(4,l+1):
    for i in range(l+1-w):
        j = i + w
        #print(s[i:j])
        if (int(s[i:j])%2019 == 0):
            cnt += 1
print(cnt)

Fixed submission:
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

s = input()
n = int(s)
l = len(s)
cnt = 0
mod = [0]*2019
m = 0
for i in range(l):
    m = (int(s[l-1-i])*pow(10,i,2019) + m)%2019
    mod[m] += 1

cnt += mod[0]

for i in range(2019):
    if mod[i] > 1:
        cnt += (mod[i]*(mod[i]-1))/2
        #print(i)
print(int(cnt))