Problem:


Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.



Sample input:
1817181712114


Sample output:
3

Submission status: Runtime Error

Solution code:
num = input()
count = 0
for i in range(len(num)):
  for j in range(len(num)):
    a = int(num[i:j])
    if a % 2019 == 0:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
num = str(input())
count = 0
for i in range(len(num)):
  for j in range(len(num)):
    a = int(num[i:j])
    if a % 2019 == 0:
      count+=1
print(count)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

template <class A, class B>
string to_string(pair<A, B> p);

template <class A, class B, class C>
string to_string(tuple<A, B, C> p);

template <class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <class A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <class A, class B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class A, class B, class C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <class Head, class... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using Int = unsigned int;
using llong = long long;
using Llong = unsigned long long;
using ldouble = long double;
using intV = vector<int>;
using intVV = vector<vector<int>>;
using llongV = vector<long long>;
using llongVV = vector<vector<long long>>;

template<class T = int>
using asc_pque = priority_queue<T, vector<T>, greater<T>>;
template<class T = int>
using desc_pque = priority_queue<T, vector<T>, less<T>>;

const llong MOD = 1000000007;
const int IINF = 1000000000;
const llong LINF = 100000000000000000LL;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define FOR(i, n) for (llong i = 0LL; i < llong(n); i++)
#define FORS(i, a, b) for (llong i = llong(a); i < llong(b); i++)
#define bisect_right(vec, a) upper_bound(vec.begin(), vec.end(), a) - vec.begin()
#define bisect_left(vec, a) lower_bound(vec.begin(), vec.end(), a) - vec.begin()
#define GET(i, p) get<i>(p)

int dp[2019] = {0};
int oldDp[2019] = {0};

void calc(int n) {
    FOR(i, 2019) {
        oldDp[i] = dp[i];
    }
    FOR(i, 2019) {
        dp[(i + n) % 2019] = oldDp[i];
    }
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S;
    cin >> S;

    int ans = 0;
    int pow = 1;
    dp[0] = 1;

    for(auto s = S.rbegin(); s != S.rend(); s++) {
        int n = (*s - '0') * pow % 2019;
        calc(n);
        ans += dp[0];
        dp[0] += 1;
        pow = pow * 10 % 2019;
    }

    cout << ans << endl;

    return 0;
}

Submission status: Runtime Error

Solution code:
S = input()
count = 0
for i in range(i, len(S) - 4):
    for j in range(i+4, len(S)):
        if int(S[i:j]) // 2019 == 0:
            count += 1
print(count)

Submission status: Runtime Error

Solution code:
S = input()
N = len(S)

tot = 0
count = [0] * 2019
ans = 0

for i in range(N):
    count[tot] += 1
    tot += (int(S[N-(i+1)])*(10**i))%2019
    ans += count[tot]

print(int(ans))

Submission status: Runtime Error

Solution code:
def main():
	s = raw_input()
    num_divisible = 0
    for i in range(len(s)-1):
    	for j in range(i, len(s)):
        	if int(s[i:j+1]) % 2019 == 0:
            	num_divisible += 1
    return num_divisible

Submission status: Runtime Error

Solution code:
s = str(input())
l = len(s)
p = 0
for i in range(l):
    for j in range(l+1):
        if j - i >=4:
            a = int(s[i:j])
            if -10**(-4) < (a / 673) -(a//673) <10**(-4):
                if a % 3 ==0:
                    p +=1
print(p)

Submission status: Runtime Error

Solution code:
s = str(input())
l = len(s)
p = 0
for i in range(l):
    for j in range(l+1):
        if j - i >=4:
            a = int(s[i:j])
            if -10**(-4) < a / 673 <10**(-4):
                if a % 3 ==0:
                    p +=1
print(p)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)):
    for j in range(i,len(s)):
        z = s[i:j]
        if int(z)%2019 == 0:
            c += 1

print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)-3):
  for j in range(i+4,len(s)+1):
    m=int(int(n/(10**i))%(10**j))
    if m%2019==0 and m == 0:
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)-3):
  for j in range(i,len(s)+1):
    m=int(int(n/(10**i))%(10**j))
    if m%2019==0 and m == 0:
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)-3):
  for j in range(i,len(s)+1):
    m=int(int(n/(10**i))%(10**j))
    if m%2019==0 and :
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)+1):
  for j in range(i,len(s)+1):
    m=int(int(n/(10**i))%(10**j))
    if m%2019==0:
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=int(s)
c=0
for i in range(len(s)):
  for j in range(i,len(s)):
    m=(n/(10**i))%(10**j)
    if m%2019==0:
      c+=1
print(c)

Submission status: Runtime Error

Solution code:
S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += i*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))

Submission status: Runtime Error

Solution code:
S = input()
mod = 2019
cnt = [0]*mod
cnt[0] = 1
n = 0
t = 1
for i in map(int,n[::-1]):
    n += i*t
    cnt[n%mod] += 1
    t *= 10
print(sum(i*(i-1)//2 for i in cnt))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
            c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            #c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
def mod10(x):
    p=x//10000
    q=x%10000
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    x=modi(i,dict)
    #print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
print(sum)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
def mod10(x):
    p=x//1000
    q=x%1000
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    x=modi(i,dict)
    #print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
print(sum)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
            c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    x=modi(i,dict)
    #print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
print(sum)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
            c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    x=modi(i,dict)
    #print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
print(sum)

Submission status: Runtime Error

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
S = input()
Slist = [S[i:] for i in range(len(S))]
Slist = list(map(lambda x: int(x) % 2019, Slist))
ans = 0
ans += Slist.count(0)
for i in range(2019):
    cnt = Slist.count(i+1)
    if cnt > 1:
        ans += combinations_count(cnt, 2)
print(ans)

Submission status: Runtime Error

Solution code:
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0

for i in range(len(s)):
    if i == 0:
        mods[0] = int(s[-1])
    else:
        mods[i] = mods[i-1] + (10**i % 2019) * int(s[len(s) - i - 1])
    countRemainder[mods[i]] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)

Submission status: Runtime Error

Solution code:
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 % 2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 %2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        mods[current % 2019] += 1
        x = x * 10 %2019
    
    for i in len(mods):
        ans += mods[i] * (mods[i]-1)//2
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+7,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data)):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Submission status: Runtime Error

Solution code:
S=input()
src={}
ans=0
pre=0
for s in range(len(S)):
  a=(int(S[-(s+1)])*(10**s)+pre)%2019
  if a not in src.keys():
    src[a]=1
  else:
    ans+=src[a]
    src[a]+=1
  pre+=int(S[-(s+1)])*(10**s)
print(ans+src[0])

Submission status: Runtime Error

Solution code:
s = input()[::-1]

counts = [0]*2019 # 剰余の余りの回数を保存
counts[0] = 1 # 0%2019を累積和として含めることを想定

num, d = 0,1　# numは余りの累積和、dはcharの桁数
'''
charに一桁ずつ取り出す。そのmod2019を考え、累積和をとる。
しかし、それぞれの数字には10の累乗がかかっているので、それについては別途dを用意してmod2019をとる
つまり、numは1桁目のmod2019、2桁目のmod2019に1桁目のmod2019を加える
'''
for char in s:
  num += int(char) * d
  num %= 2019
  d *= 10
  d %= 2019
  counts[num] += 1

ans = 0
for c in counts:
  ans += c*(c-1)//2
  
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# D - Multiple of 2019

s = input()

count = 0
counter = Counter([0])

suffix = 0
pow = 1
for i in range(len(s) - 1, -1, -1):
    suffix = (int(s[i]) * pow + suffix) % 2019
    pow = pow * 10 % 2019
    count += counter[suffix]
    counter[suffix] += 1

print(count)

Submission status: Runtime Error

Solution code:
import math

def comb_count(n, r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import log10
from collections import Counter
S = int(input())
l = int(log10(S)) + 1
print(sum(n * (n - 1) // 2 for n in Counter((S := S % 10 ** (l - i)) % 2019 for i in range(l + 1)).values()))

Submission status: Runtime Error

Solution code:
from collections import Counter

# print('input >>')

S = input()
S = S[::-1]

mods = [0] * (len(S)+1)
mods[0] = int(S[0]) % 2019

for i in range(len(mods)-1-1):
    mods[i+1] = (int(S[i+1]) * 10 ** (i+1) + mods[i]) % 2019

# print(mods)

# ans = 0

# counter = Counter(mods)

# for n in counter.values():
#     if n > 1:
#         ans += (n * (n-1)) // 2

# print('-----output-----')

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [int(c) for c in input().split(' ')]
T = [int(c) for c in input().split(' ')]
U = [int(c) for c in input().split(' ')]
V = [int(c) for c in input().split(' ')]

cnt = 0
for j in range(1, len(S)+1):
    for i in range(j-1):
        part = int(S[i:j])
        if not part % 3 == 0:
            continue
        if part % 2019 == 0:
            cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import numpy as np
s = input()
y = 2019
dp = np.zeros(y, dtype="int64")
tmp = np.zeros(y, dtype="int64")
k = 1
r = 0
for c in s[::-1]:
    i = int(c)*k%y
    tmp[i:] = dp[:y-i]
    tmp[:i] = dp[-i:]
    tmp[i] += 1
    dp, tmp = tmp, dp
    r += dp[0]
    k *= 10
    k %= y
print(r) 1

Submission status: Runtime Error

Solution code:
S = raw_input()
l = [0] * 2019
l[0] = 1
for i in range(len(S)):
    l[int(S[-1 - i:]) % 2019] += 1
sum = 0
for i in l:
    sum += i * (i - 1) / 2
print(sum)

Submission status: Runtime Error

Solution code:
import math
 
S=int(input())
n=int(math.log10(S))+1
cnt=0
a=[0]*n
md=[0]*n
sum=[0]*n

a[0]=S%10
md[0]=a[0]
sum[0]=a[0]
S=math.floor(S/10)


for i in range(1,n):
  a[i]=S%10
  sum[i]=a[i]*10**i+sum[i-1]
  md[i]=sum[i]%2019
  S=math.floor(S/10)
  #print(md)
  if md.count(md[i])>=2:cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
def main():
    S = input()
    # S = "1" * 200000
    S = S[::-1]

    x = float(1)
    tot = 0
    cnt = [0] * 2019
    ans = 0

    for i in range(len(S)):
        # print("-----")
        # print(f"i: {i}")
        # print(f"tot: {tot}")
        # print(f"S[i]: {S[i]}")
        # print(f"x: {x}")
        # print(f"cnt: {cnt}")
        # print(f"cnt[tot]: {cnt[tot]}")
        # print(f"ans: {ans}")

        cnt[tot] += 1
        tot = int((tot + (int(S[i]) * x)) % 2019)
        ans += cnt[tot]
        x = x * 10
    
    # print("-----")
    # print(f"i: {i}")
    # print(f"tot: {tot}")
    # print(f"S[i]: {S[i]}")
    # print(f"x: {x}")
    # print(f"cnt: {cnt}")
    # print(f"cnt[tot]: {cnt[tot]}")
    # print(f"ans: {ans}")
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)

a = [0]*2019
count = 0
val = 10
for i in range(n):
    tmp = int(s[n-i-1,n]) % 2019
    count = count + a[tmp]
    a[tmp] = a[tmp] + 1
    if(tmp == 0):
        count = count + 1
    val = val * 10

print(count)

Submission status: Runtime Error

Solution code:
s=input()
S=[]
for i in range(len(s)):
    S.append(s[i:])
b=2019
ans=0
for i in range(len(s)-1):
    if int(S[i]) % b == 0:
        ans+=1
    for j in range(i+1, len(s)):
        if (int(S[i]) - int(S[j])) % b == 0:
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
S=input()
mods=[0]*2019
nums=[""]*len(S)

nums[0]=S[-1]

for i in range(len(S)-1):
    nums[i+1]=S[-i-2]+nums[i]
for i in range(len(S)):
    k = int(nums[i])%2019
    mods[k]+=1

sums = 0

for i in range(1,2019):
    sums+=mods[i]*(mods[i]-1)//2

sums+=2**mods[0]-1

print(sums)

Submission status: Runtime Error

Solution code:
s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in range(len(s)):
  a = (a-int(s[i])*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
# ABC164 D - Multiple of 2019
import numpy as np

s = input()[::-1]
length = len(s)
a = np.zeros(length, dtype=int)
d = np.zeros(length, dtype=int)
ans = np.zeros(2019, dtype=int)

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * 10**i % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1

ans_f = ans[np.nonzero(ans)]

print(int(sum([ans_f[i] * (ans_f[i]-1) for i in range(ans_f.shape[0])]) / 2) + ans[0])

Submission status: Runtime Error

Solution code:
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 1
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))/10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(mod_N[i]*(mod_N[i]-1)/2)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
a = int(s)
mods = [a%2019]
for i in range(len(s)):
  a = int((a-int(s[-(i+1)]))10)
  mods.append(a%2019)
mod_N ={}
for i in mods:
  if not i in mod_N:
    mod_N[i] = 0
  else:
    mod_N[i] += 1
ans = 0
for i in mod_N:
  ans += int(i*(i-1)/2)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)

ct = 0
for i in range(n+1)[::-1]:
  for j in range(i+1,n+1)[::-1]:
    ss = int(s[i:j])
    # q = ss // 2019
    m = ss % 2019
    # print(f"{i}:{j}, {ss}, {q}, {m}")
    if m == 0 and q > 0:
      ct += 1
      # print(f"{ss}, {q}, {m}")

print(ct)

Submission status: Runtime Error

Solution code:
s=int(input())
n=len(str(s))
a=[0]*2019
ans=0
k=s%2019
a[k]+=1
for i in range(n):
  s=int(s*0.1)
  k=s%2019
  a[k]+=1
for i in range(2019):
  ans+=a[i]*(a[i]-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
s=int(input())
n=len(str(s))
a=[0]*2019
a[0]=1
ans=0
k=s%2019
a[k]+=1
for i in range(n):
  s=int(s*0.1)
  k=s%2019
  a[k]+=1
for i in range(2019):
  ans+=a[i]*(a[i]-1)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
import math
s=int(input())
n=len(str(s))
ans=0
if n>=4:
  for i in range(n-3):
    for j in range(i+3,n):
      k=math.floor((s%10**(n-i))/10**(n-j-1))
      if k%2019==0:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
def resolve():
    s=int(input())
    a=4
    count=0
    for i in range(len(s)-4):
        d= a+i
        e=s[:d]
        if i%d==0:
            count=count+1
    print(count)
resolve()

Submission status: Runtime Error

Solution code:
def resolve():
    s=int(input())
    a=4
    count=0
    for i in range(len(s)-4):
        d= a+i
        e=s[:d]
        if i%d==0:
            count=count+1
    print(count)

resolve()

Submission status: Runtime Error

Solution code:
s = str(input())
count = 0
for j in range(4, len(s)+1):
    for i in range(j-3):
        print(int(s[i:j]))