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:
import sys

input = sys.stdin.readline


def solve():
    S = input().strip()
    len_s = len(S)
    answer = 0
    for i in range(len_s):
        for j in range(1, len_s + 1):
            if not (j - i > 4):
                continue
            number = S[i:j]

            if sum(map(int, number)) % 3 != 0:
                continue

            if int(number) % 673 == 0:
                answer += 1
    return answer


if __name__ == '__main__':
    answer = solve()
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import itertools

s = input().rstrip()

s_l = len(s)

s_nums = list(range(len(s)+1))

ans = 0

for i_1, i_2 in itertools.combinations(s_nums,2):
  if int(s[i_1:i_2]) % 2019 == 0:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
s = str(input())

num_list = []
for j in range(4, len(s)+1):
    for i in range(len(s)-j+1):
        num_list.append(int(s[i:j+i]))
        
print(np.where(np.array(num_list) % 2019 == 0, 1, 0).sum())

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
l=len(s)
se=dict()
k=0
for i in range(l-1,-1,-1):
    k+=((10**(l-1-i))*int(s[i]))
    k%=2019
    if k in se:
        se[k]+=1
    else:
        se[k]=1

ans=0
for j in se:
    i=se[j]
    if i>1:
        ans+=(i*(i-1)//2)
    if j==0:
        ans+=i
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s=input()

def is2019(s):
    num=int(s)
    return num % 2019 == 0

i=0
ans=0
while i<len(s):
    found=False
    for j in range(1,len(s)-i+1):
        if is2019(s[i:i+j]):
            found=True
            ans+=1
            break
    i+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

count = 0
s = input()
for i in range(len(s)-4):
    j = i+4
    while j < len(s)+1:
        if int(s[i:j])%2019 == 0:
            count+=1
        j+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
S = str(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)
ans = 0
for i in range(len(S)-3):
    for j in range(i+4,len(S)+1):
        if int(S[i:j]) % 2019 == 0:
            ans += 1
        #print(S[i:j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
key = [0]*2019
for i in range(l):
  n = int(s[l-i-1:])
  k = n%2019
  key[k] += 1

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S=input()
A=0
while len(S)>3:
    for i in range(len(S)-3):
        X=int(S[:i+4])
        if X%2019 ==0:
            A+=1
    S=S[1:]
print(A)

Submission status: Time Limit Exceeded

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

sum = 0
for i in range(N+1):
    for j in range(i+1,N+1):
        A = S[i:j]
        A = int(A.replace("",""))
        if A % 2019 == 0:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(start_i, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1
    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(ret)

Submission status: Time Limit Exceeded

Solution code:
S=list(map(int,input()))
num=0
ans=0
for i in range(len(S)-3):
    num=S[i]*1000+S[i+1]*100+S[i+2]*10+S[i+3]
    if num%2019==0:
        ans=ans+1
    for j in range(i+4,len(S)):
        num=num*10+S[j]
        if num%2019==0:
            ans=ans+1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
size = len(S)
count = 0

for i in range(size):
    for j in range(i+1, size):
        #if j >= size:
            #break
        N = int(S[i:j+1])
        if (N % 2019) == 0:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
Slen = len(S)

ans = 0
if len(S)<=3:
    print(0)
    exit()
for num_s in range(4,Slen+1):
    for i in range(Slen - num_s + 1):
        num = int(S[i:i+num_s])
        if num%2019 == 0:
            ans += 1

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
ans = 0
for i in reversed(range(5, N+1)):
  for j in range(i-5, -1, -1):
    if int(S[j:i]) % 2019 == 0:
      ans += 1
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
k=0
l=len(s)

for i in range(4,l+1):
    for j in range(0,l-i+1):
        ss=s[j:j+i]
        ss_n=int(ss)
        if ss_n%2019==0:
            k+=1

print(k)

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
            i += 3
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
l=list(str(input()))
val=0
ct=0
lim=len(l)
for i in range(0,lim-3):
    for j in range(i,lim):
        if(i!=j)and((j-i)>2):
            val=int("".join(l[i:j+1]))
            if(val%2019==0):
                ct+=1
print(ct)

Submission status: Time Limit Exceeded

Solution code:

MOD = 10 ** 9 + 7

def main():
    for _ in inputt(1):
        S = input()
        D = {}
        t = 0
        for ch in S:
            c = ord(ch) - 48
            nD = {c : 1}
            for d in D:
                nd = (d * 10 + c) % 2019
                nD[nd] = nD.get(nd, 0) + D[d]
            D = nD
            t += D.get(0, 0)
        print(t)

# region M


# region import
# 所有import部分

from math import *
from heapq import *
from itertools import *
from functools import reduce, lru_cache, partial
from collections import Counter, defaultdict
import re, copy, operator, cmath
import sys, io, os, builtins
sys.setrecursionlimit(1000)

# endregion

# region fastio

BUFSIZE = 8192
class FastIO(io.IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = io.BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    if args:
        sys.stdout.write(str(args[0]))
        split = kwargs.pop("split", " ")
        for arg in args[1:]:
            sys.stdout.write(split)
            sys.stdout.write(str(arg))
    sys.stdout.write(kwargs.pop("end", "\n"))
def debug(*args, **kwargs):
    print("debug", *args, **kwargs)
    sys.stdout.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip()
inputt = lambda t = 0: range(t) if t else range(int(input()))
inputs = lambda: input().split()
inputi = lambda: map(int, inputs())
inputl = lambda t = 0, k = lambda: list(inputi()): [k() for _ in range(t)] if t else list(k())

# endregion

# region bisect

def len(a):
    if isinstance(a, range):
        return -((a.start - a.stop) // a.step)
    return builtins.len(a)
def bisect_left(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if key(a[mid]) < x: lo = mid + 1
        else: hi = mid
    return lo
def bisect_right(a, x, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    while lo < hi:
        mid = (lo + hi) // 2
        if x < key(a[mid]): hi = mid
        else: lo = mid + 1
    return lo
def insort_left(a, x, key = None, lo = 0, hi = None):
    lo = bisect_left(a, x, key, lo, hi)
    a.insert(lo, x)
def insort_right(a, x, key = None, lo = 0, hi = None):
    lo = bisect_right(a, x, key, lo, hi)
    a.insert(lo, x)
do_nothing = lambda x: x
bisect = bisect_right
insort = insort_right
def index(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    if key == None: key = do_nothing
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi and key(a[i]) == x: return a[i]
    if default != None: return default
    raise ValueError
def find_lt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_le(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo < i <= hi: return a[i - 1]
    if default != None: return default
    raise ValueError
def find_gt(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_right(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError
def find_ge(a, x, default = None, key = None, lo = 0, hi = None):
    if lo < 0: lo = 0
    if hi == None: hi = len(a)
    i = bisect_left(a, x, key, lo, hi)
    if lo <= i < hi: return a[i]
    if default != None: return default
    raise ValueError

# endregion

# region csgraph
# TODO

class Tree:
    def __init__(n):
        self._n = n
        self._conn = [[] for _ in range(n)]
        self._list = [0] * n
    def connect(a, b):
        pass

# endregion

# region ntheory
# TODO

class Sieve:
    def __init__(self):
        self._n = 6
        self._list = [2, 3, 5, 7, 11, 13]
    def extend(self, n):
        pass


sieve = Sieve()
def isprime(n):
    pass
def prime(n):
    pass
def factorint(n):
    factordict = defaultdict(int)
    for i in sieve:
        if n <= i * i:
            break
        while not n % i:
            factordict[i] += 1
            n //= i
    if n != 1:
        factordict[n] += 1
    return factordict

# endregion

# region main

if __name__ == "__main__":
    main()

# endregion


# endregion

Submission status: Time Limit Exceeded

Solution code:
#


def main():
    s = input()
    length = len(s)
    count = 0
    for i in range(length - 2):
        for j in range(i + 4, length + 1):
            n = int(s[i:j])
            if n % 2019 == 0:
                count += 1
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
s = input()
dp = [ [0] * 2019 for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(2019):
        dp[i+1][((10*j)+int(s[i]))%2019] += dp[i][j]
    dp[i+1][int(s[i])] += 1

print(sum(dp[i][0] for i in range(len(s)+1)))

Submission status: Time Limit Exceeded

Solution code:
input_str = input()

output_cnt = 0
for i in range(len(input_str) - 3):
  for j in range(3 + i, len(input_str) + 1):
    sliced_value = int(input_str[i : j])
    if sliced_value % 2019 == 0:
      output_cnt += 1

print(output_cnt)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=0
b=''
import sys
for i in range(len(s)):
    
    for j in range(i,len(s)):
        b+=s[j]
        if int(b)%2019==0:
            a+=1
        
    b=''
    if len(s)-i==3:
        break
        
print(a)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=len(S)
count=0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()

count = 0
for i in range(len(S)):
  for j in range(len(S)):
    conv = S[i:j+1]
    if (conv == ''):
      continue
    check_int = int(conv)
    if (check_int % 2019 == 0):
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

    S = list(input())

    N = len(S)

    c = 0
    for i in range(0, N-3):
        for j in range(i+4, N+1):
            num = int(''.join(S[i:j]))
            if num % 2019 == 0:
                c += 1
    print(c)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()

match = 0
for i in range(len(s)):
    for j in range(i + 3, len(s) + 1):
        val = int(s[i:j])
        if val >= 2019 and val % 2019 == 0:
            match += 1

print(match)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    S = input()

    res = 0
    for i in range(0, len(S)):
        for j in range(i + 5, len(S) + 1):
            n = S[i:j]
            if int(n) % 2019 == 0:
                res += 1

    print(res)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
s = list(map(int, list(input())))

n = len(s)
rst = 0
for i in range(n):
    tmp = 0
    for j in range(n-i):
        tmp += s[i+j]
        tmp %= 2019
        if tmp == 0:
            rst += 1
        tmp *= 10

print(rst)

Submission status: Time Limit Exceeded

Solution code:
S = input()

ans = 0
for i in range(len(S) - 3):
    for j in range(i + 3, len(S) + 1):
        s = int(S[i : j])
        if s % 3 != 0 or s % 673 != 0:
            pass
        else:
            ans += 1
            # print(i, j, S[i : j])
    # print(i, j)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0

for i in range(len(s) - 3): 
    for j in range(i + 4, len(s) + 1):
        sub_s = int(s[i:j])
        if sub_s % 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+1,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+1 ,len(S) + 1):
        s = S[i:j]
        if int(s) % 2019 == 0:
            ans += 1

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    answer = 0
    for i in range(1, len(S)+1):
        for j in range(i+1, len(S)+1):
            if int(S[i-1:j]) % 2019 == 0:
                answer += 1
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline


def solve():
    S = input().strip()
    len_s = len(S)
    answer = 0
    for i in range(len_s):
        for j in range(1, len_s + 1):
            if not (j - i > 4):
                continue
            number = S[i:j]

            if int(number) % 2019 == 0:
                answer += 1
    return answer


if __name__ == '__main__':
    answer = solve()
    print(answer)

Submission status: Time Limit Exceeded

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

residue = [0] * n
count = 0

for i in range(n):
  residue[i] = (int(s[i]) * 10 ** (n - 1 - i)) % 2019

for i in range(n):
  for j in range(i + 4, n):
    if sum(residue[i:j + 1]) % 2019 == 0:
      count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
a = [int(c) for c in s]
count = 0
for i in range(len(a)):
    for j in range(i+3,len(a)):
        b=0
        for k in range(i,j+1):
            b=b*10+a[k]
        if b%2019==0:
            count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
inp = input()

s = 0

for i in range(len(inp)-3):
	for j in range(i+4, len(inp)+1):
		num = int(inp[i:j])
		if num % 2019 == 0:
			s += 1

print(s)

Submission status: Time Limit Exceeded

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

pair = 0

if num < 4:
    print(0)
else:
    for i in range(num-3):
        for j in range(i+3,num):
            temp = int(S[i:j+1])
            if temp % 2019 == 0:
                pair += 1

    print(pair)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_n = str(n)
lenn = len(str(n))+1
res = []
for i in range(0,lenn):
    for j in range(i+4,lenn):
        if int(s_n[i:j]) % 2019 == 0:
            res.append([i,j])
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0

for i in range(len(s)-3):
    for j in range(i+3,len(s)+1):
        tmp = s[i:j]
        # print(i,j)
        if int(tmp)% 2019==0:
            ans += 1
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
print(count)

Submission status: Time Limit Exceeded

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

    l = [[] for i in range(673)]
    l[0].append(0)
    ten = 1
    mod = 673
    now = 0
    for i in range(len(s)):
        now = (now+int(s[i])*ten)%mod
        l[now].append(i+1)
        ten *= 10
    ans = 0
    for i in l:
        if len(i) >= 2:
            for j in range(len(i)-1):
                for k in range(j+1,len(i)):
                    a = sum(list(map(int,s[i[j]:i[k]])))
                    if a %3 == 0:
                        ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
s=[int(x) for x in list(str(input()))]
ans=0
for i in range(1,len(s)+1):
    for j in range(i+2,len(s)+1):
        figure=0
        for k in range(j-i+1):
            figure+=s[-(i+k)]*10**k
        if(figure%2019==0):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s=input()
a=0
now=1
l=[0]*2019
for i in list(s)[::-1]:
    a=(a+now*int(i))%2019
    l[a]+=1

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=input()

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

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def main():
    s = input()
    n = len(s)
    cnt = 0

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

    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
baisu = [2019*i for i in range(1,10**6)]
for i in range(len(s)):
    for j in range(i+4,len(s)+1):
        if int(s[i:j]) in baisu:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
counter = 0
if len(S) < 4:
  print(0)
  exit()
for left in range(len(S)-3):
  for right in range(left+4,len(S)+1):
    if int(S[left:right])%2019==0:
      counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
S = input()

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

Submission status: Time Limit Exceeded

Solution code:
s = input()

ans = 0
f = 0
for i in range(len(s)-3):
    st = s[i]+s[i+1]+s[i+2]
    for j in range(len(s)-3-i):
        st += s[i+3+j]
        if f > 0 :
            f -= 1
        else:
            if int(st)%2019 == 0:
                ans += 1
                f = 3

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 2020/04/26
# AtCoder Beginner Contest 164 - D

# Input
s = input()
ls = len(s)

# Calc
ans = 0
for i in range(ls-3):
    for j in range(i+4, ls+1):
        cval = int(s[i:j])
        if cval % 2019 == 0:
            ans = ans + 1

# Output
print(ans)

Submission status: Time Limit Exceeded

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

print(count_ij)

Submission status: Time Limit Exceeded

Solution code:
S = input()
#revS = S[::-1]
ls = len(S)
cur_num = 0
cur_r = 0
r = [0]*ls
ans = 0
for i in range(ls):
    if i == 0:
        r[i] = (int(S[ls-i-1])*pow(10,i))%2019
    else:
        r[i] = r[i-1] + (int(S[ls-i-1])*pow(10,i))%2019
        r[i] %= 2019
#print(r)
from collections import Counter
c = Counter(r)

#print(c)
ans = 0
c[0] += 1
for k,v in c.items():
    # if k == 0:
    #     pass
    if v >= 2:
        ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
 
answers = []
for start in range(len(s)-3):
    for end in range(start+4, len(s)+1):
        if int(s[start:end]) % 2019 == 0:
            answers.append((start, end))
print(len(answers))

Submission status: Time Limit Exceeded

Solution code:
s = input()

def make_num(x,y):
    return int(s[x:y])

ans=0
for i in range(len(s)-3):
    for j in range(i+4, len(s)+1):
        if make_num(i,j)%2019==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    *s, = map(int, input())  # <= 2*10**5

    r = [0] * 2019
    r[0] = 1

    ans = 0

    t = 0
    p = 1
    for x in reversed(s):
        t = (t + x * p) % 2019
        p *= 10
        ans += r[t]
        r[t] += 1

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok