Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
for i in range(N):
    base = pow(10 % 2019, N-i)
    num = num * 10 + S[i]
    CNT[(num*base)%2019] += 1
ans = 0 
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
for i in range(N):
    base = pow(10, N-i, 2019)
    num = num * 10 + S[i]
    CNT[(num*base)%2019] += 1
ans = 0 
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
base = pow(10, N+1)
num = 0
for i in range(N):
    base //= 10
    num = num * 10 + S[i]
    CNT[(num*base)%2019] += 1
ans = 0 
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    string S;
    cin >> S;
    ll N = S.size();
    vector<int> CNT(2019, 0);
    CNT[0] = 1;
    ll base = pow(10, N);
    ll num = 0;

    rep(i, N) {
        base /= 10;
        num = num * 10 + (S[i] - '0');
        ++CNT[(num*base)%2019];
    }
    int ans = 0;
    for(auto cnt : CNT) {
        ans += (cnt * (cnt - 1)) / 2;
    }
    cout << ans << endl;
    return 0;
}

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
base = pow(10, N)
num = 0
for i in range(N):
    base //= 10
    num = num * 10 + S[i]
    CNT[(num*base)%2019] += 1
ans = 0 
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(int, list(input())))
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
for i in range(N):
    num = num * 10 + S[i]
    CNT[num * pow(10, N-i)%2019] += 1
ans = 0
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
for i in range(N):
    num = num * 10 + int(S[i]) 
    CNT[num * pow(10, N-i)%2019] += 1
ans = 0
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
CNT = [0]*2019
CNT[0] = 1

for i in range(1, N+1):
    CNT[int(S[:i]) * pow(10, N-i)%2019] += 1
ans = 0
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)


Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)
CNT = [0]*2019
CNT[0] = 1

for i in range(1, N+1):
    CNT[int(S[:i]) * pow(10, N-i)%2019] += 1
ans = 0
for cnt in CNT:
    if cnt==0: continue
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def search(S):
    cnt = 0
    N = len(S)
    for i in range(N+1):
        for j in range(i+1, N+1):
            num = S[i:j]
            if int(num)%2019==0:
                cnt += 1
                i += 3
    return cnt 

if __name__ == "__main__":
    S = input()
    cnt = search(S)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def search(S):
    cnt = 0
    N = len(S)
    for i in range(N+1):
        for j in range(i+1, N+1):
            num = S[i:j]
            if int(num)%2019==0:
                cnt += 1
            
    return cnt 

if __name__ == "__main__":
    S = input()
    cnt = search(S)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and not(numS == 0)):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    
    s(start, end+1)

S = input()
s(0, 1)
print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    s(start, end+1)

S = str(input())
s(0, 0)
print cnt

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    s(start, end+1)

S = str(input())
s(0, 0)
print cnt

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
        
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+1
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    try:
        numS = int(S[start:end+1])
    except:
        numS = 0
    if(numS%2019==0 and numS!=0):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 1)
print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

S = input()
s(0, 0)
print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)
S = input()
s(0, 1)
print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0 and numS!=0):
        print(numS)
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    try:
        numS = int(S[start:end+1])
    except:
        numS = 0
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return 
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    print(start, end)
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end+1])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)

if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):
cnt = 0
def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)



if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)

Buggy python submission (verdict: Runtime Error):

cnt = 0

def s(start, end):
    global cnt
    if(start==len(S)-1):
        return cnt
    numS = int(S[start:end])
    if(numS%2019==0):
        cnt += 1
    if(end==len(S)-1):
        end = start+2
        s(start+1, end)
        return
    s(start, end+1)



if __name__ == '__main__':
    S = input()
    s(0, 1)
    print(cnt)

Fixed submission:
S = list(map(int, list(input())))[::-1]
N = len(S)
CNT = [0]*2019
CNT[0] = 1
num = 0
d = 0
for i in range(N):
    num += S[i]*pow(10, d, 2019)
    num %= 2019
    CNT[num] += 1
    d += 1
ans = 0 
for cnt in CNT:
    ans += (cnt*(cnt - 1)) // 2
print(ans)