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: Wrong Answer

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

count=0
for i in range(s_num-1):
    for j in range(i+1,s_num+1):
        if int(s[i:j])%2019==0:
            print(i,j,int(s[i:j]))
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
s=input()
string=set([str(i*2019) for i in range(1,101)])
ans=0
for i in range(4,7):
    for g in range(len(s)-i+1):
        if s[g:g+i] in string:
            ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
ls = []
for i in range(1,1000):
    ls.append(str(i*2019))
ans = 0
for i in ls:
    ans += s.count(i)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input()
    N = len(S)
    mult = []
    for i in range(1, 200000 // 2019 + 2):
        mult.append(str(2019 * i))
    ans = 0
    for i in range(N - 6):
        s = S[i : i + 6]
        for m in mult:
            ans += s.count(m)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()

A = []
print(len(S))
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            A.append((i+1,j))

print(len(A))

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = collections.Counter(l)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


s = input()
c = 0
n = ceil(200000/2019)
for i in range(1,n):
	c+= s.count(str(2019*i))
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys

# sys.setrecursionlimit(100000)
# input = sys.stdin.buffer.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    # 2019 = 3 * 673

    rl = set([0])
    ans = 0
    for c in S:
        n = int(c)
        nrl = set([0])
        for r in rl:
            r = (r * 10 + n) % 2019
            if r == 0:
                ans += 1
            nrl.add(r)
        rl = nrl

    return ans


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
target = [str(2019*(i+1)) for i in range(100)]
s = input()

ans = 0
for tar in target:
    lg = len(tar)
    for j in range(len(s)-lg+1):
        if s[j:j+lg] == tar:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    ans = 0
    for i in range(len(s)):
        for j in range(i-3):
            if int(s[j:i]) % 2019 == 0:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = collections.Counter(l)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


s = input()
c = 0
n = ceil(200000/2019)
for i in range(1,n+1):
	c+= s.count(str(2019*i))
print(c)

Submission status: Wrong Answer

Solution code:
n = input()
x = int(n)//2019
counter = 0
for i in range(1, x+1):
    if str(20199*i) in n:
        counter += 1
print(counter)

Submission status: Wrong Answer

Solution code:
target = [str(2019*i) for i in range(200)]
s = input()

ans = 0
for tar in target:
    lg = len(tar)
    for j in range(len(s)-lg+1):
        if s[j:j+lg] == tar:
            ans += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
import sys
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq


# l = ['a', 'a', 'a', 'a', 'b', 'c', 'c']
# c = collections.Counter(l)

sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1

# リストの要素を改行を挟んで表示する
p2D = lambda x: print(*x, sep="\n")
# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

# 入力全てを整数に変換したものの配列を受け取る
# def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))


s = input()
c = 0
n = 200000//2019
for i in range(1,n+1):
	c+= s.count(str(2019*i))
print(c)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    S = input().rstrip('\n')
    NS = len(S)

    ans = 0
    for i in range(1, 100):
        T = str(2019 * i)
        NT = len(T)
        if NT > NS:
            break
        for j in range(NS - NT + 1):
            if S[j: j+NT] == T:
                ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
ln = len(s)
d = [int(i) for i in s]
count = 0
for i in range(ln - 3):
    total = sum(d[i:i+3])
    for j in range(i + 3, ln):
        total += d[j]
        if total % 3 == 0 and int(s[i:j+1]) % 673 == 0:
            # print(i, j, int(s[i:j+1]))
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

            ans += 1
print(ans)
#3*673

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

S = input()
S_len = len(S)

S_nums = [0] * (S_len+1)
for i in range(S_len):
    S_nums[i] = int(S[i:])

rem_count = [0] * 2019
for n in S_nums:
    rem_count[n % 2019] += 1

result = 0
for c in rem_count:
    result += c * (c - 1) // 2

print(result)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
s=int(S)

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

#print(c)  
d=[0]*2019
m=0
for i in range(2019):
  d[i]=c.count(i)
  m+=d[i]*(d[i]-1)//2
#print(d)
print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S=input()
s=int(S)
c=0
for i in range(1,s//2019+1):
  C=str(2019*i)
  if '0' in C:
    continue
  if C in S:
    c+=1
print(c)


exit()




c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))

Submission status: Time Limit Exceeded

Solution code:
S=input()
c=0;s=[]
for i in range(0,len(S)+1):
  for j in range(i,len(S)):
    s.append(S[i:j+1])
del s[0]
ss = [int(i) for i in s]    
#print(ss)
sss = list(map(lambda x: x %2019, ss))

#print(sss)
print(sss.count(0))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

S = input()

ans = 0

kTarget = 2019

carries = {0:1}

ord_z = ord('0')
for d in S[::-1]:
    d = ord(d) - ord_z
    next_carries = defaultdict(int)
    for carry, cnt in carries.items():
        x = carry - d
        mult = x%10
        x += mult*kTarget
        if carry != 0 and x == 0:
            ans += cnt
        x //= 10
        x %= kTarget
        next_carries[x] += cnt
    next_carries[0] += 1
    carries = next_carries
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
mod = 2019

t = len(S)
l = [0] * t
for i in range(t-1, -1, -1):
    l[i] = int(S[i:]) % mod
l.append(0)

from collections import Counter

def nC2(n):
    return n * (n - 1) // 2


l = list(Counter(l).values())

ans = 0
for i in l:
    ans += nC2(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(map(int, list(input())))

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = S.pop()

    pops = (pops + s * digi) % 2019
    digi *= 10

    cnt[pops] += 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

pops = 0
digi = 1
cnt = [0] * 2019
cnt[0] = 1

while S:
    s = int(S.pop())

    pops = (pops + s * digi) % 2019
    digi *= 10

    cnt[pops] += 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

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

D = dict()
for j in L:
    if j in D:
        D[j] += 1
    else:
        D[j] = 1
ans = 0
for k in D.values():
    ans += k * (k-1) //2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
if int(S) < 2009:
  print(0)
  
else:
  count = 0
  for i in range(len(S) - 3):
    for j in range(i + 3, len(S)):
      num = int(S[i:j + 1])
      if num % 2019 == 0:
        count += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    s = tuple(map(int, input()))
    lens = len(s)

    d1 = defaultdict(int)
    ss = 0
    k = 1
    while k <= lens:
        ss += (int(s[-k]) * (10 ** (k - 1))) % 2019
        ss = ss % 2019
        d1[ss] += 1
        k += 1
    r = d1[0]
    for v in d1.values():
        r += v * (v - 1) // 2
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
s_int = list(int(i) for i in s)

cnt = 0
for i in range(4,len(s)):
  for j in range(len(s)-i+1):
    if sum(s_int[j:j+i]) % 3 == 0:
      if int(''.join(s[j:j+i])) % 2019 == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())
s_int = list(int(i) for i in s)

cnt = 0
for i in range(4,2*10**6):
  for j in range(len(s)-i+1):
    if sum(s_int[j:j+i]) % 3 == 0:
      if int(''.join(s[j:j+i])) % 2019 == 0:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = list(input())

cnt = 0
for i in range(4,2*10**6):
  for j in range(len(s)-i+1):
    if int(''.join(s[j:j+i])) % 2019 == 0:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

print( ans )

Submission status: Time Limit Exceeded

Solution code:
counter = [0]*2019
counter[0] = 1 # 0 = 0 (mod 2019)

S = input()
tmp = 0
for i in range(1,len(S)+1):
    tmp += int(S[-i])*10**(i-1)    #スライスの方が早い（けど、漸化式的に累積和を出せ）
    #print(tmp%2019)
    tmp %= 2019                    #大きい数を割るな
    counter[tmp%2019] += 1

ans = 0
for i in range(2019):
    if counter[i] >= 2:
        #ans += comb(counter[i], 2, exact=True)
        ans += counter[i]*(counter[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
counter = [0]*2019
counter[0] = 1 # 0 = 0 (mod 2019)

S = input()
tmp = 0
for i in range(1,len(S)+1):
    tmp += int(S[-i])*10**(i-1)
    #print(tmp%2019)
    counter[tmp%2019] += 1

ans = 0
for i in range(2019):
    if counter[i] >= 2:
        #ans += comb(counter[i], 2, exact=True)
        ans += counter[i]*(counter[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def combinations_count(n, r):
    if n == 1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))



def main():
    S = SI()
    
    ls = []
    for s in range(len(S)):
        ls.append(int(S[s:])%2019)

    import collections

    ls_c = collections.Counter(ls)
    ls_cv = list(ls_c.values())

    ans = 0

    for p in ls_cv:
        ans += combinations_count(p,2)
    ans += ls_c[0]
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#from scipy.special import comb

counter = [0]*2019
counter[0] = 1 # 0 = 0 (mod 2019)

S = input()
for i in range(1,len(S)+1):
    tmp = int(S[-i:])
    #print(tmp%2019)
    counter[tmp%2019] += 1

ans = 0
for i in range(2019):
    if counter[i] >= 2:
        #ans += comb(counter[i], 2, exact=True)
        ans += counter[i]*(counter[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  6 23:39:24 2020

@author: liang
"""
from scipy.special import comb

counter = [0]*2019
counter[0] = 1 # 0 = 0 (mod 2019)

S = input()
for i in range(1,len(S)+1):
    tmp = int(S[-i:])
    #print(tmp%2019)
    counter[tmp%2019] += 1

ans = 0
for i in range(2019):
    ans += comb(counter[i], 2, exact=True)
    
print(ans)

Submission status: Time Limit Exceeded

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

p = 2019
X = [0 for _ in range(p)]
X[0] = 1

dp = X[:]
ans = 0
for i in range(N):
    v = int(S[i])
    np = X[:]
    for k in range(p):
        x = (k * 10 + v) % p
        np[x] += dp[k]
    dp = np[:]
    ans += dp[0] - 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

def solve(S: str):
    if len(S) < 4:
        return 0
    answer = 0
    for l in range(0, len(S) - 3):
        for r in range(l + 4, len(S) + 1):
            answer += int(S[l:r]) % 2019 == 0
    return answer


def main():
    S = input().strip()
    answer = solve(S)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def solve(S: str):
    if len(S) < 4:
        return 0
    answer = 0
    for l in range(0, len(S) - 3):
        for r in range(l + 4, len(S) + 1):
            answer += int(S[l:r]) % 2019 == 0
    return answer


def main():
    S = input().strip()
    answer = solve(S)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

r_list = [0] * 2019
r_list[0] = 1
num, d = 0, 1
for i in range(len(S)):
    num += d*int(s_rev[i])
    num %= 2019
    r_list[num] += 1
    d *= 10

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

print(ans)

Submission status: Time Limit Exceeded

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

r_list = [0] * 2019
r_list[0] = 1
num = 0
for i in range(len(S)):
    num += (10**i)*int(s_rev[i])
    num %= 2019
    r_list[num] += 1

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

print(ans)

Submission status: Time Limit Exceeded

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

r_list = [0] * 2019
r_list[0] = 1
m = len(S)
num = 0
for i in range(len(S)):
    num += (10**i)*int(s_rev[i])
    r_list[num % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
dp = [0 for _ in range(n)]
dp[-1] = int(s[-1])
for i in range(n-2, -1, -1):
    dp[i] = (dp[i+1] + int(s[i]) * (10**(n-i-1))) % 2019

cnt_dic = {}

for i in dp:
    if not i in cnt_dic:
        cnt_dic[i] = 0

    cnt_dic[i] += 1

# print(dp)
ans = 0
# print(cnt_dic)
for i, j in cnt_dic.items():
    if i == 0:
        ans += j
    else:
        ans += j * (j - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

r_list = [0] * 2019
r_list[0] = 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

r_list = [0] * 2019
r_list[0 % 2019] += 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

r_list = [0 for _ in range(2019)]
r_list[0 % 2019] += 1
m = len(S)
for i in range(1,m+1):
    r_list[int(S[m-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

r_list = [0 for _ in range(2019)]
r_list[0 % 2019] += 1
for i in range(1,len(S)+1):
    r_list[int(S[len(S)-i:]) % 2019] += 1

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

S_sum = [0]
r_list = [0 for _ in range(2019)]
for i in range(1,len(S)+1):
    S_sum.append(int(S[len(S)-i:]))
#print(S_sum)

for i in range(len(S_sum)): 
    r_list[S_sum[i] % 2019] += 1 

ans = r_list[0] - 1
for i in range(1,2019):
    if r_list[i] >= 2:
        ans += r_list[i]*(r_list[i]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
d = 1
for i in reversed(range(len(s))):
    tmp += int(s[i]) * d
    tmp %= mod
    d *= 10
    #d %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Submission status: Time Limit Exceeded

Solution code:
s = input()
mod = 2019
dic = [0] * mod
dic[0] += 1

tmp = 0
for i in reversed(range(len(s))):
    tmp += int(s[i]) * (10 ** (len(s)-1-i))
    tmp %= mod
    dic[tmp] += 1

ans = [i * (i-1) / 2 for i in dic]
print(int(sum(ans)))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

s = input()
dic = defaultdict(int)
dic[0] += 1

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

ans = [i * (i-1) / 2 for i in dic.values()]
print(int(sum(ans)))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

s = input()
dic = defaultdict(int)
ans = 0

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

for i in dic.values():
    ans += i * (i-1) / 2
    
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s_len = len(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    # 2以上なら共通するmodがあったということになる
    for i, s in enumerate(reversed(s)):
        rev_num += int(s) * (10**i%mod)
        rev_num %= mod
        d[rev_num] += 1
    # 2以上同じmodがあったらそこから2つ選ぶ選び方
    # それを全てのmodで
    print(sum(i*(i-1)//2 for i in d))
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    s = s[::-1]
    s_len = len(s)
    mod = 2019
    d = [0] * mod
    d[0] = 1
    rev_num = 0
    # 2以上なら共通するmodがあったということになる
    for i in range(s_len):
        rev_num += int(s[i]) * (10**i%mod)
        rev_num %= mod
        d[rev_num] += 1
    # 2以上同じmodがあったらそこから2つ選ぶ選び方
    # それを全てのmodで
    print(sum(i*(i-1)//2 for i in d))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
N=len(S)
counter=[0]*2019
counter[0]=1
ans=0
for i in range(1,N+1):
    s=S[-i:]
    r=int(s)%2019
    counter[r]+=1
for i in counter:
    ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=str(input())
N=len(S)
s=[0]*(N+1)
s[0]=0
counter=[0]*2019
counter[0]=1
ans=0
for i in range(1,N+1):
    s[i]=S[-i:]
    r=int(s[i])%2019
    counter[r]+=1
for i in counter:
    ans += i*(i-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=str(input())
l=len(N)
 
ans=0
for i in range(l):
    for j in range(i+4,l+1):
        if int(N[i:j])%2019==0:
            ans+=1
 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
S = input()
S = S[::-1]

num = 0
ans = 0
memo = defaultdict(int)
memo[0] = 1
for i in range(len(S)):
    num += int(S[i])*pow(10,i)
    rest = num % 2019
    ans += memo[rest]
    memo[rest] += 1
print(ans)