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: Time Limit Exceeded

Solution code:
#ABC164d
s = str(input())
S = int(s)
s = list(s)

for i in range(len(s)):
    s[i] = int(s[i])

ans = 0
T = 0

for i in range(len(s)):
    for j in range(i,len(s)):
        t = s[i:j+1]
        for i2 in range(len(t)):
            T += t[i2] * 10**(len(t)-1-i2)
        if T%2019==0 and T != 0:
            ans += 1
        T = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
count = 0
for i in range(len(S) - 3) :
    num = int(S[-i-1])
    # print("num",num)
    for k in range(1,len(S)-i) :
        # print("k", k, "S", S[-i-k-1])
        num += pow(10,k) * int(S[-i-k-1])
        # print(num)
        if (num % 2019 == 0) :
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S=input()
i=2019
x = 0
while i <= int(S):
    for j in range(1,len(S)-len(str(i))+2,1):
        if int(S[j-1:j-1+len(str(i))]) == i:
            x += 1
    i += 2019
print(x)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
mod = 2019
s = input()
n = len(s)
w = 0
d = {}
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	w %= mod
	if w in d:
		d[w] += 1
	else:
		d[w] = 1
if 0 in d:
	d[0] += 1
else:
	d[0] = 1
o = 0
for x in d:
	o += d[x] * (d[x] - 1) // 2
print(o)

Submission status: Time Limit Exceeded

Solution code:
S = input()
mod = 2019
L = [0]*mod
n = 0
for i in range(len(S)-1, -1, -1):
    n += (int(S[i])*10**(len(S)-i-1))%mod
    n %= mod
    L[n] += 1

ans = 0
L[0] += 1
for l in L:
    ans += l*(l-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()

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

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

counter=[0]*2019
counter[0]=1
for i in range(len(s)):
    num=int(s[i:])
    counter[num%2019]+=1

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

Submission status: Time Limit Exceeded

Solution code:
suuji = list(input())
count = 0
for i in range(0, len(suuji) - 3):
  for j in range(i+4, len(suuji) + 1):
    if (int)(''.join(suuji[i:j])) % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
suuji = list(input())
count = 0
for i in range(0, len(suuji)):
  for j in range(i+1, len(suuji) + 1):
    if (int)(''.join(suuji[i:j])) % 2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

count=0
for i in range(len(s)):
  k=int(s[i])
  r = k
  if(r==0): count+=1
    
  for j in range(i+1,len(s)):
    r=(10*r+int(s[j])) % 2019
    if(r==0):
      count+=1
       
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()

ans = 0
mods = []
x = int(s)%2019
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)%2019
    a = x%2019
    mods.append(a)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = input()

ans = 0
mods = []
x = int(s)
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)
    a = x%2019
    mods.append(a)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
mods = {}
x = int(s)
s = [int(a) for a in s]
for i in range(len(s)+1):
    if i != 0:
        x -= s[i-1] * 10**(len(s)-i)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
mod_list = [0]*2019
mod_list[0] = 1
t = 0
for i in range(n-1, -1, -1):
  t = int(s[i])*10**(n-1-i)+t
  mod_list[t%2019]+= 1
count = 0
for k in range(2019):
  count += mod_list[k] * (mod_list[k]-1)//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
mods = {0: 1} # 0 % n = 0
x = int(s)
for i in range(len(s)):
    if i != 0:
        x -= int(s[i-1]) * 10**(len(s)-i)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
mods = {0: 1} # 0 % n = 0
for i in range(1, len(s)+1):
    x = int(s[len(s)-i:])
    # print(x)
    a = x%2019
    if a in mods.keys():
        mods[a] += 1
    else:
        mods[a] = 1
# print(mods)
for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
for l in range(len(s)):
    for r in range(l+1, len(s)):
        # print("idx", l, r)
        s_l0 = s[l:]
        s_r10 = s[r+1:]
        if len(s_r10) != 0:
            x_l0 = int(s_l0)
            x_r10 = int(s_r10)
            if (x_l0 % 2019) == (x_r10 % 2019):
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
        else:
            x_l0 = int(s_l0)
            if x_l0 % 2019 == 0:
                ans += 1
                # print("l, r ({},{})".format(l+1, r+1))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as col
cnt = col.Counter()

s = input()
n = len(s)

for i in range(n+1):
    num = 0 if i==0 else int(s[-i:])
    cnt[num%2019] += 1

ans = 0
for key,val in cnt.items():
    ans += val*(val-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = input()
dic = {}
a = 0
bef = 0
ten = 1
for i in range(len(N)):
  num = int(N[len(N) - i -1]) % 2019#各桁取り出し
  bef = (num * ten + bef) % 2019
  #print(bef)
  dic.setdefault(bef, 0)
  dic[bef] += 1
  ten *= 10
  ten % 2019
for k, v in dic.items():
  if k != 0:
    if v != 1:
      a += v * (v - 1) / 2
  else:
    a += v * (v + 1) / 2
print(int(a))

Submission status: Time Limit Exceeded

Solution code:
N = input()
dic = {}
a = 0
bef = 0
ten = 1
for i in range(len(N)):
  num = int(N[len(N) - i -1]) #各桁取り出し
  bef = (num * ten + bef) % 2019
  #print(bef)
  dic.setdefault(bef, 0)
  dic[bef] += 1
  ten *= 10
  ten % 2019
for k, v in dic.items():
  if k != 0:
    if v != 1:
      a += v * (v - 1) / 2
  else:
    a += v * (v + 1) / 2
print(int(a))

Submission status: Time Limit Exceeded

Solution code:
N = input()
dic = {}
a = 0
bef = 0
ten = 1
for i in range(len(N)):
  num = int(N[len(N) - i -1]) #各桁取り出し
  bef = (num * ten + bef) % 2019
  #print(bef)
  if dic.setdefault(bef, 0):
    dic[bef] += 1
  else:
    dic[bef] = 1
  ten *= 10
  ten % 2019
for k, v in dic.items():
  if k != 0:
    a += v * (v - 1) / 2
  else:
    a += v * (v + 1) / 2
print(int(a))

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
ls = [1]+[0]*2018
ans = 0
for i in range(len(s)):
    ls[int(s[i:])%mod] += 1
for i in ls:
    ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter

def solve(S: str):
    # S[i, j) % 2019 == 0となる(i, j)の数
    # S[i..n) - S[j, n) === 0 (mod 2019)
    # 累積mod c[i] = S[i:]
    n = len(S)
    c = [0] * (n + 1)
    for i in range(n):
        c[i] = int(S[i:]) % 2019
    print(sum(v * (v - 1) // 2 for v in Counter(c).values()))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
d = defaultdict(int)
S=input()
S=S[::-1]
_=''
MOD=2019
for s in S:
  _=s+_
  d[int(_)%MOD]+=1
ans=0
for k in d.values():
  ans=ans+k*(k-1)//2
print(ans+d[0])

Submission status: Time Limit Exceeded

Solution code:
S = input()

from collections import defaultdict
mod = 2019
N = len(S)
D = defaultdict(int)
S = S[::-1]
ans = 0
T = [0]
D[0]+=1
for i in range(N):
    s = int(S[i])*pow(10,i)
    T.append((T[i]+s)%mod)
    ans += D[T[i+1]]
    D[T[i+1]]+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
mod = 2019
S = input()
N = len(S)

S = S[::-1]
A = []
for i in range(N):
    s = int(S[i])*pow(10,i)
    A.append(s%mod)
B = [0]
for i in range(N):
    s = B[i]+A[i]
    B.append(s%mod)

D = defaultdict(int)
for i in range(N+1):
    D[B[i]]+=1
ans = 0
for key in D.keys():
    m = D[key]
    ans += m*(m-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
mod = 2019
S = input()
N = len(S)

S = S[::-1]
A = []
for i in range(N):
    s = int(S[i])*pow(10,i)
    A.append(s%mod)
B = [0]
for i in range(N):
    s = B[i]+A[i]
    B.append(s%mod)

C = Counter(B)
ans = 0
for key in C.keys():
    m = C[key]
    ans += m*(m-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019

    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * (times % mod)
        times = times * 10

    # 累積和
    R = [0] * (n + 1)
    for i in range(n):
        R[i+1] = (R[i] + A[i]) % mod
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % mod
        # print(r)
        ans = ans + cnt.get(r, 0)
        # cnt.setdefault(r, 0)
        # ans = ans + cnt[r]
        cnt[r] = cnt.get(r, 0) + 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019

    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * times % mod
        times = times * 10

    # 累積和
    R = [0] * (n + 1)
    for i in range(n):
        R[i+1] = (R[i] + A[i]) % mod
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % mod
        # print(r)
        ans = ans + cnt.get(r, 0)
        # cnt.setdefault(r, 0)
        # ans = ans + cnt[r]
        cnt[r] = cnt.get(r, 0) + 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    S=input()
    remainders=[0]
    sub=0
    for i in range(len(S)-1,-1,-1):
        sub=int(S[i])*pow(10,len(S)-i-1)+sub
        remainders.append(sub%2019)
    d=Counter(remainders)
    ans=0
    for key in d:
        ans+=(d[key]*(d[key]-1))//2
    print(ans)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019
    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * times % mod
        times = times * 10

    # 累積和
    R = [0] * (n + 1)
    for i in range(n):
        R[i+1] = (R[i] + A[i]) % mod
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % mod
        # print(r)
        ans = ans + cnt.get(r, 0)
        # cnt.setdefault(r, 0)
        # ans = ans + cnt[r]
        cnt[r] = cnt.get(r, 0) + 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019
    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * times % mod
        times *= 10

    # 累積和
    R = [0] * (n + 1)
    for i in range(n):
        R[i+1] = (R[i] + A[i]) % mod
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % mod
        # print(r)
        cnt.setdefault(r, 0)
        ans += cnt[r]
        cnt[r] += 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
s=input()

ans=0

for l in range(len(s)-3):
    for r in range(l+4,len(s)+1):
        a=s[l:r]
        if int(a)%2019==0:
            ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    S = list(map(int, list(input())))
    S = S[::-1]
    n = len(S)
    mod = 2019
    A = [0] * n
    times = 1
    for i in range(n):
        A[i] = S[i] * times % mod
        times *= 10

    # 累積和
    R = [0]
    for i in range(n):
        R.append((R[i] + A[i]) % mod)
    # print(R)
    cnt = {}
    ans = 0
    for i in range(n+1):
        r = R[i] % 2019
        # print(r)
        cnt.setdefault(r, 0)
        ans += cnt[r]
        cnt[r] += 1
    # print(cnt)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
n = input()
ans = 0
for i in range(1,int(200000/2019)+1):
    times = sum(1 for x in range(len(n)) if n[x:].startswith(str(2019*i)))
    ans += times
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

cnt = 0
l = len(s)

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

Submission status: Time Limit Exceeded

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) % 2019
    mod = current % 2019
    # ans += mods[mod]
    mods[mod] += 1
    tmp = tmp * 10

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

print(ans)

Submission status: Time Limit Exceeded

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
    ans += mods[mod]
    mods[mod] += 1
    tmp = tmp * 10

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

Submission status: Time Limit Exceeded

Solution code:
X=input()
a=list()
for i in range(len(X)):
    a.append(int(X[i:len(X)])%2019)
S=a.count(0)    
for j in set(a):
    b=a.count(j)
    S+=int(b*(b-1)/2)
print(S)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

t = 4
cnt = 0

while (t < len(s)):
    for i in range(len(s) - t):
        if int(s[i : i + t + 1]) % 2019 == 0:
            cnt += 1

    t += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
now = [0] * 2019
mod = 2019
ans,cnt = 0,1
lis = [int(s[-(1+i)]) for i in range(len(s))]
for num in lis:
    now[0] += 1
    num *= cnt
    num %= mod
    next = [0] * mod
    for i in range(2019-num):
        next[num+i] += now[i]
    for i in range(num):
        next[i] += now[2019-num+i]
    ans += next[0]
    cnt *= 10
    cnt %= mod
    now = next
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
now = [0] * 2019
mod = 2019
ans,cnt = 0,1
lis = [int(s[-(1+i)]) for i in range(len(s))]
for num in lis:
    now[0] += 1
    num *= 10**cnt
    num %= mod
    next = [0] * mod
    for i in range(2019-num):
        next[num+i] += now[i]
    for i in range(num):
        next[i] += now[2019-num+i]
    ans += next[0]
    cnt += 1
    now = next
print(ans)

Submission status: Time Limit Exceeded

Solution code:
X=input()
a=list()
for i in range(len(X)):
    a.append(int(X[i:len(X)])%2019)
S=a.count(0)
for j in range(1,2018):
    b=a.count(j)
    S+=int(b*(b-1)/2)
print(S)

Submission status: Time Limit Exceeded

Solution code:
X=input()
a=list()
for i in range(len(X)):
    a.append(int(X[i:len(X)])%2019)
S=a.count(0)
for j in range(1,2018):
    b=a.count(j)
    S+=int(b*(b-1)/2)
print(S)

Submission status: Time Limit Exceeded

Solution code:
s = input()

t = 3
cnt = 0

while (t < len(s)):
    for i in range(len(s) - t):
        if int(s[i : i + t + 1]) % 2019 == 0:
            cnt += 1

    t += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
X=input()
a=list()
for i in range(len(X)):
    a.append(int(X[i:len(X)])%2019)
S=a.count(0)
for j in range(1,2018):
    S+=int(a.count(j)*(a.count(j)-1)/2)
print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# from sys import stderr
from functools import reduce

def debug(*args):
    print(*args, file=stderr)

s = input()

checked = {}

for left_i in range(len(s)):
    for right_i in range(left_i + 1, len(s) + 1):
        now_checking_str = s[left_i:right_i]

        if not now_checking_str in checked:
            checked[now_checking_str] = 0

        elif checked[now_checking_str] > 0:
            checked[now_checking_str] += 1
            continue

        # debug(left_i, right_i, now_checking_str)

        now_checking_int = int(now_checking_str)
        checked[now_checking_str] += 1 if now_checking_int % 2019 == 0 else 0

# debug(checked)

result = reduce(lambda x, y: x+y, checked.values(), 0)
print(result)


# echo "1817181712114" | python3 d.py && echo "14282668646" | python3 d.py && echo "2119" | python3 d.py

Submission status: Time Limit Exceeded

Solution code:
from sys import stderr
from functools import reduce

def debug(*args):
    print(*args, file=stderr)

s = input()

checked = {}

for left_i in range(len(s)):
    for right_i in range(left_i + 1, len(s) + 1):
        now_checking_str = s[left_i:right_i]

        if not now_checking_str in checked:
            checked[now_checking_str] = 0

        debug(left_i, right_i, now_checking_str)

        now_checking_int = int(now_checking_str)
        checked[now_checking_str] += 1 if now_checking_int % 2019 == 0 else 0

debug(checked)

result = reduce(lambda x, y: x+y, checked.values(), 0)
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)


S = readChar()

re = [0]*len(S)

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

res = [0]*len(S)
for j in range(1,len(S)+1):
	res[j*-1] = sum(re[j*-1:])%2019

d = defaultdict(int)
for i in res:
	d[i]+=1

ans = d[0]
for key in d:
	if d[key]>1:
		ans+=comb(d[key],2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
moji = len(s)
count = 0
for i in range(moji):
    if (i < 4) or (i > 200000): continue
    start = 0
    end = i
    while end < moji:
        end = end + 1
        num = int(s[start:end])
        if num % 2019 == 0:
            count += 1
        start = start + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
moji = len(s)
count = 0
for i in range(moji):
    if i < 4 : continue
    start = 0
    end = i
    while end < moji:
        end = end + 1
        num = int(s[start:end])
        if num % 2019 == 0:
            count += 1
        start = start + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import re

s = input()
moji = len(s)
count = 0
for i in range(moji):
    start = 0
    end = i
    while end < moji:
        end = end + 1
        num = int(s[start:end])
        if num % 2019 == 0:
            count += 1
        start = start + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

if __name__ == '__main__':
    s = sys.stdin.readline().rstrip()
    # s = '1817181712114'
    # s = '14282668646'
    ans = 0
    for i in range(len(s)-4):
        for j in range(i+4, len(s)+1):
            # print(s[i:j])
            if int(s[i:j])%2019 == 0:
                # print(i+1, j)
                ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

cnt = 0
for i in range(len(S)):
  for j in range(i+3,len(S)):
    num = int(S[i:j+1])
    if num%2019==0:
      cnt+=1
      
print(cnt)

Submission status: Time Limit Exceeded

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

count = 0

for i in range(0,leng):
    for j in range(i,leng):
      num = int(''.join(map(str,s[i:j+1])))
      if num%2019 ==0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
from collections import defaultdict
import math
import copy
#input = sys.stdin.readline
sys.setrecursionlimit(20000000)
s = input()
n = len(s)
dp = [[0]*2019 for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 1
for i in range(n):
    for j in range(2019):
        dp[i+1][(j*10+int(s[i]))%2019] += dp[i][j]
ans = 0
for i in range(n+1):
    ans += dp[i][0]
print(ans-n-1)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
N = len(S)

"""
    例： S = '31415926535'
        S[3:8] = '15926535' が 2019 で割り切れるかどうか？
     <=> S[3:-1] - S[8:-1] が 2019 で割り切れるかどうか
     <=> S[3:-1] % 2019 == S[8:-1] % 2019 か
    よって、2019で割ったときの異なるあまりをそれぞれカウントすればよい
"""

mod_cnts = [0] * 2019
mod_cnts[0] = 1 # 累積和のはじめ
current_cusum, ans = 0, 0
# O(N)
# d = 1
for i in range(N):
# for s in S:
    s = S[i]
    current_cusum += (pow(10, i)% 2019) * int(s) # 累積和
    # current_cusum += d * int(s)
    current_cusum %= 2019
    mod_cnts[current_cusum] += 1

    # d *= 10 % 2019

# O(2019)
for cnt in mod_cnts:
    ans += cnt * (cnt - 1) // 2 # n_C_2 2つ選ぶ組み合わせ
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
N = len(S)

"""
    例： S = '31415926535'
        S[3:8] = '15926535' が 2019 で割り切れるかどうか？
     <=> S[3:-1] - S[8:-1] が 2019 で割り切れるかどうか
     <=> S[3:-1] % 2019 == S[8:-1] % 2019 か
    よって、2019で割ったときの異なるあまりをそれぞれカウントすればよい
"""

mod_cnts = [0] * 2019
mod_cnts[0] = 1 # 累積和のはじめ
current_cusum, ans = 0, 0
# O(N)
d = 1
# for i in range(N):
for s in S:
    # s = S[i]
    # current_cusum += pow(10, i) * int(s) # 累積和
    current_cusum += d * int(s)
    current_cusum %= 2019
    mod_cnts[current_cusum] += 1

    d *= 10 % 2019

# O(2019)
for cnt in mod_cnts:
    ans += cnt * (cnt - 1) // 2 # n_C_2 2つ選ぶ組み合わせ
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
N = len(S)

"""
    例： S = '31415926535'
        S[3:8] = '15926535' が 2019 で割り切れるかどうか？
     <=> S[3:-1] - S[8:-1] が 2019 で割り切れるかどうか
     <=> S[3:-1] % 2019 == S[8:-1] % 2019 か
    よって、2019で割ったときの異なるあまりをそれぞれカウントすればよい
"""

mod_cnts = [0] * 2019
mod_cnts[0] = 1 # 累積和のはじめ
current_cusum, ans = 0, 0
# O(N)
d = 1
# for i in range(N):
for s in S:
    # s = S[i]
    # current_cusum += pow(10, i) * int(s) # 累積和
    current_cusum += d * int(s)
    current_cusum %= 2019
    mod_cnts[current_cusum] += 1

    d *= 10

# O(2019)
for cnt in mod_cnts:
    ans += cnt * (cnt - 1) // 2 # n_C_2 2つ選ぶ組み合わせ
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()[::-1]
N = len(S)

"""
    例： S = '31415926535'
        S[3:8] = '15926535' が 2019 で割り切れるかどうか？
     <=> S[3:-1] - S[8:-1] が 2019 で割り切れるかどうか
     <=> S[3:-1] % 2019 == S[8:-1] % 2019 か
    よって、2019で割ったときの異なるあまりをそれぞれカウントすればよい
"""

mod_cnts = [0] * 2019
mod_cnts[0] = 1 # 累積和のはじめ
current_cusum, ans = 0, 0
for i in range(N):
    s = S[i]
    current_cusum += pow(10, i) * int(s) # 累積和
    current_cusum %= 2019
    mod_cnts[current_cusum] += 1

for cnt in mod_cnts:
    ans += cnt * (cnt - 1) // 2 # n_C_2 2つ選ぶ組み合わせ
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

n = len(S)

modlist = [0] * 2019
num = 0

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * (10 ** i)) % 2019
    modlist[num] = modlist[num] + 1

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    m = modlist[i]
    if n != 0:
        result += m * (m - 1) / 2

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
S = input()

n = len(S)

modlist = [0] * 2019
num = 0

for i in range(n):
    fig = int(S[n - i - 1])
    num += (fig * (10 ** i)) % 2019
    modlist[num % 2019] = modlist[num % 2019] + 1

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    if modlist[i] != 0:
        result += modlist[i] * (modlist[i] - 1) / 2

print(int(result))

Submission status: Time Limit Exceeded

Solution code:
S = input()

n = len(S)

modlist = [0] * 2019
num = 0

for i in range(n):
    fig = int(S[n - i - 1])
    num += fig * (10 ** i)
    modlist[num % 2019] = modlist[num % 2019] + 1

result = 0
if modlist[0] > 0:
    result += 1

for i in range(2019):
    if modlist[i] != 0:
        result += modlist[i] * (modlist[i] - 1) / 2

print(int(result))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)