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:
S = input()

import itertools

n = len(S)

l = [val for val in range(n)]

p = itertools.permutations(l, 2)
r = []
for i in p:
    if i[0]+3 <= i[1]: 
        r.append(i)

s = 0

for val in r:
    a = int(val[0])
    b = int(val[1] + 1)
    if int(S[a:b])%2019 == 0:
        s += 1

print(s)

Submission status: Time Limit Exceeded

Solution code:
s = input("")
d = int(s) // 2019
l = [str(2019 * i) for i in range(1, d)]
res = 0
for i in l:
	if(len(i)< len(s)):
		b = s.find(i)
		while (b!= -1):
			res+=1
			b = s.find(i, b + 1)
print(res)

Submission status: Time Limit Exceeded

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


ans = 0

s = 0
e = 0
while s <= len(S)-5:
    e = s + 5
    while e <= len(S):
        if int(S[s:e]) % 2019 == 0:
            ans += 1
        e += 1
    s += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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





print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

ans = 0

start = 0
end = 4

while True:
    tmp = S[start:end]
    if int(tmp) % 2019 == 0:
        ans += 1
        start += 1
        end = start + 4
    elif end == len(S):
        start += 1
        end = start + 4
    else:
        end += 1

    if start == len(S) - 3:
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
l = [0]* len(S)
for i in range(len(S)):
    T = S[i:]
    t = int(T)
    l[i] = t%2019
l.sort()
m = [0] * len(S)
k = 1
for i in range (len(S) - 1):
    if l[i] != l[i + 1]:
        m[i] = int(k*(k-1)/2)
        k = 1
    else:
        m[i] = 0
        k += 1
if k != 1:
    m[len(S) - 1] = int(k*(k-1)/2)
a = 0
for i in range(len(S)):
    if l[i] == 0:
        a += 1
    else:
        break
print(sum(m) + a)

Submission status: Time Limit Exceeded

Solution code:
S=input()
S1=int(S)
#print(len(S))
S_count=len(S)
sum=0
sum1=0
ii=0
jj=4
SSSS=int(S_count)
for i in range(S_count):
  sum1+=i
#print(sum1)
for i in range(sum1):
  if ii==int(S_count-1):
    break
  SS=S[ii:jj]
  #print(SS)
  SSS=int(SS)
  if SSS%2019==0:
    sum+=1
  jj+=1
  if jj==int(S_count+1):
    ii+=1
    if ii>=4:
      jj=ii+1
    else:
      jj=4
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def main():
    ans = 0
    s = input()
    for i in range(20001):
        t = (2019*i)
        if str(t) in s:
          for i in range(len(s)-3):
            for j in range(i+3, len(s)):
              if s[i:j+1] == str(t):
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()

n = len(s)

ans = 0
for i in range(0, n-3):
   j = 4
   while i + j <= n:
      x = int(s[i:i+j])
      if x % 2019 == 0:
         ans += 1
         j += 4
      else:
         j += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# Sの入力
S = input()

# j番目の初期化
j_s = 4

# 条件を満たす個数の初期化
cnt = 0

for i in range(1,len(S)-2):
    for j in range(j_s,len(S)+1):
        baisu = int(S[i-1:j]) % 2019
        if baisu == 0:
            cnt += 1
    j_s += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
import math

s = int(input())
n = math.ceil(math.log10(s))
count = 0


for i in range(n):
    num = s % (10 ** (n - i))
    for j in range(n):
        if num % 2019 == 0:
            count += 1
            break
        num = num // 10
        if num == 0:
            break
        
print("{}".format(count))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

s = input()
l = Counter()
for i in range(len(s)):
    l[int(s[i:])%2019]+=1

res = 0
for key, val in l.most_common():
    res += val*(val-1)//2

res+=l[0]
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict,Counter

s = ns()
d = defaultdict(int)
d[0] += 1
k = 0
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*(10**k)
    n%=2019
    d[n] += 1
    k+=1

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=int(input())
K=len(str(S))
lst= [int(x) for x in list(str(S))]
A=[[0 for v in range(K)] for j in range(2019)]
A[lst[0]][0]+=1
for i in range(1,K):
 c=lst[i]
 A[c][i]+=1
 for k in range(2019):
  d=(k*10+c)%2019
  A[d][i]+=A[k][i-1]
print(sum(A[0]))

Submission status: Time Limit Exceeded

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

    print(ans)

if __name__ == '__main__':
    main()

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+1):
    if int(S[i:j]) % 2019 == 0 :
      count += 1
      #print(i,j)
print(count)

Submission status: Time Limit Exceeded

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

def check(n):
  global count
  if (n % 2019 == 0):
    count += 1

for i in range(0,limit - 3):
  for j in range(i+3,limit):
    check(int(S[i:j+1]))

print(count)

Submission status: Time Limit Exceeded

Solution code:
def solve(s, left, right):
    global ans
    if int(s[left:right+1]) >= 2019:
        if dic.get((left, right)) is None:
            dic[(left, right)] = 0
            #print(s[left:right+1], left, right)
            if int(s[left:right+1]) % 2019 == 0:
                #print("!!!!")
                ans += 1
            solve(s, left+1, right)
            solve(s, left, right-1)

ans = 0
s = input()
dic = {}
solve(s, 0, len(s)-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
su = 0
right = 0
if l<=3:
  print(0)
  exit()
for i in range(4,l+1):
  right = i
  left = 0
  while right<=l:
    if int(s[left:right])%2019==0:
      su += 1
      left = right-1
      right += i-1
    else:
      right += 1
      left += 1
print(su)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())

lenS = len(S)

sweep = 4
flag = 0
ans = 0
mem = 0
step = 1

if lenS < 3:
    print(0)
else:
    while sweep <= len(S):
        step = 1
        for i in range(mem, lenS - sweep + 1, step):
            if int(''.join(S[i:i + sweep])) % 2019 == 0:
                ans += 1
                step = sweep - 1
            if i > ((lenS // sweep)+1) and step == 1:
                break
        sweep += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
s = [0]*(len(S)+1)
for i in range(len(S)):
    s[i+1] = s[i] +int(S[i])
L1 = []
L2 = []
L3 = []
for i in range(len(s)):
    if s[i]%3==0:
        L1.append(i)
    if s[i]%3==1:
        L2.append(i)
    if s[i]%3==2:
        L3.append(i)

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

Submission status: Time Limit Exceeded

Solution code:
s=input()

k=0

for i in range(len(s)-3):

    for j in range(i+1,len(s)+1):

        if j<=i:

            pass

        else:

            if int(s[i:j])%2019 == 0:

                k+=1

            else:pass


print(k)

Submission status: Time Limit Exceeded

Solution code:
s = str(input())

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

Submission status: Time Limit Exceeded

Solution code:
def ss(li):
  i = ""
  for k in li:
    i += k
  return int(i)
S = input()
li = list(S)
n = len(S)
count = 0
if n >= 4:
  for i in range(n+1-4):
    for k in range(i+4,n+1):
      p = ss(li[i:(k)])
      if p % 2019 == 0:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy
ls = list(input())
ls = [int(s) for s in ls]
new_ls = numpy.cumsum(numpy.array(ls))
c = 0
ls = [str(p) for p in ls]
for q in range(len(ls)):
    if new_ls[q] % 3 == 0:
        u = ls[:q+1]
        v = ''.join(u)
        if int(v) % 673 == 0:
            c += 1
        else:
            continue
    else:
        continue
for i in range(4,len(ls)):
    for j in range(len(ls)-3):
        if i - j >= 4:
            if (new_ls[i] - new_ls[j]) % 3 == 0:
                a = ls[j+1:i+1]
                b = ''.join(a)
                if int(b) % 673 == 0:
                    c += 1
                else:
                    continue
        else:
            continue
print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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

memo = ["019",
"038",
"057",
"076",
"095",
"114",
"133",
"152",
"171",
"190",
"209",
"228",
"247",
"266",
"285",
"304",
"323",
"342",
"361",
"380",
"399",
"418",
"437",
"456",
"475",
"494",
"513",
"532",
"551",
"570",
"589",
"608",
"627",
"646",
"665",
"684",
"703",
"722",
"741",
"760",
"779",
"798",
"817",
"836",
"855",
"874",
"893",
"912",
"931",
"950",
"969",
"988",
"007",
"026",
"045",
"064",
"083",
"102",
"121",
"140",
"159",
"178",
"197",
"216",
"235",
"254",
"273",
"292",
"311",
"330",
"349",
"368",
"387",
"406",
"425",
"444",
"463",
"482",
"501",
"520",
"539",
"558",
"577",
"596",
"615",
"634",
"653",
"672",
"691",
"710",
"729",
"748",
"767",
"786",
"805",
"824",
"843",
"862",
"881",
"900",
"919",
"938",
"957",
"976",
"995",
"014",
"033",
"052",
"071",
"090",
"109",
"128",
"147",
"166",
"185",
"204",
"223",
"242",
"261",
"280",
"299",
"318",
"337",
"356",
"375",
"394",
"413",
"432",
"451",
"470",
"489",
"508",
"527",
"546",
"565",
"584",
"603",
"622",
"641",
"660",
"679",
"698",
"717",
"736",
"755",
"774",
"793",
"812",
"831",
"850",
"869",
"888",
"907",
"926",
"945",
"964",
"983",
"002",
"021",
"040",
"059",
"078",
"097",
"116",
"135",
"154",
"173",
"192",
"211",
"230",
"249",
"268",
"287",
"306",
"325",
"344",
"363",
"382",
"401",
"420",
"439",
"458",
"477",
"496",
"515",
"534",
"553",
"572",
"591",
"610",
"629",
"648",
"667",
"686",
"705",
"724",
"743",
"762",
"781",
"800",
"819",
"838",
"857",
"876",
"895",
"914",
"933",
"952",
"971",
"990",
"009",
"028",
"047",
"066",
"085",
"104",
"123",
"142",
"161",
"180",
"199",
"218",
"237",
"256",
"275",
"294",
"313",
"332",
"351",
"370",
"389",
"408",
"427",
"446",
"465",
"484",
"503",
"522",
"541",
"560",
"579",
"598",
"617",
"636",
"655",
"674",
"693",
"712",
"731",
"750",
"769",
"788",
"807",
"826",
"845",
"864",
"883",
"902",
"921",
"940",
"959",
"978",
"997",
"016",
"035",
"054",
"073",
"092",
"111",
"130",
"149",
"168",
"187",
"206",
"225",
"244",
"263",
"282",
"301",
"320",
"339",
"358",
"377",
"396",
"415",
"434",
"453",
"472",
"491",
"510",
"529",
"548",
"567",
"586",
"605",
"624",
"643",
"662",
"681",
"700",
"719",
"738",
"757",
"776",
"795",
"814",
"833",
"852",
"871",
"890",
"909",
"928",
"947",
"966",
"985",
"004",
"023",
"042",
"061",
"080",
"099",
"118",
"137",
"156",
"175",
"194",
"213",
"232",
"251",
"270",
"289",
"308",
"327",
"346",
"365",
"384",
"403",
"422",
"441",
"460",
"479",
"498",
"517",
"536",
"555",
"574",
"593",
"612",
"631",
"650",
"669",
"688",
"707",
"726",
"745",
"764",
"783",
"802",
"821",
"840",
"859",
"878",
"897",
"916",
"935",
"954",
"973",
"992",
"011",
"030",
"049",
"068",
"087",
"106",
"125",
"144",
"163",
"182",
"201",
"220",
"239",
"258",
"277",
"296",
"315",
"334",
"353",
"372",
"391",
"410",
"429",
"448",
"467",
"486",
"505",
"524",
"543",
"562",
"581",
"600",
"619",
"638",
"657",
"676",
"695",
"714",
"733",
"752",
"771",
"790",
"809",
"828",
"847",
"866",
"885",
"904",
"923",
"942",
"961",
"980",
"999",
"018",
"037",
"056",
"075",
"094",
"113",
"132",
"151",
"170",
"189",
"208",
"227",
"246",
"265",
"284",
"303",
"322",
"341",
"360",
"379",
"398",
"417",
"436",
"455",
"474",
"493",
"512",
"531",
"550",
"569",
"588",
"607",
"626",
"645",
"664",
"683",
"702",
"721",
"740",
"759",
"778",
"797",
"816",
"835",
"854",
"873",
"892",
"911",
"930",
"949",
"968",
"987",
"006",
"025",
"044",
"063",
"082",
"101",
"120",
"139",
"158",
"177",
"196",
"215",
"234",
"253",
"272",
"291",
"310",
"329",
"348",
"367",
"386",
"405",
"424",
"443",
"462",
"481",
"500",
"519",
"538",
"557",
"576",
"595",
"614",
"633",
"652",
"671",
"690",
"709",
"728",
"747",
"766",
"785",
"804",
"823",
"842",
"861",
"880",
"899",
"918",
"937",
"956",
"975",
"994",
"013",
"032",
"051",
"070",
"089",
"108",
"127",
"146",
"165",
"184",
"203",
"222",
"241",
"260",
"279",
"298",
"317",
"336",
"355",
"374",
"393",
"412",
"431",
"450",
"469",
"488",
"507",
"526",
"545",
"564",
"583",
"602",
"621",
"640",
"659",
"678",
"697",
"716",
"735",
"754",
"773",
"792",
"811",
"830",
"849",
"868",
"887",
"906",
"925",
"944",
"963",
"982",
"001",
"020",
"039",
"058",
"077",
"096",
"115",
"134",
"153",
"172",
"191",
"210",
"229",
"248",
"267",
"286",
"305",
"324",
"343",
"362",
"381",
"400",
"419",
"438",
"457",
"476",
"495",
"514",
"533",
"552",
"571",
"590",
"609",
"628",
"647",
"666",
"685",
"704",
"723",
"742",
"761",
"780",
"799",
"818",
"837",
"856",
"875",
"894",
"913",
"932",
"951",
"970",
"989",
"008",
"027",
"046",
"065",
"084",
"103",
"122",
"141",
"160",
"179",
"198",
"217",
"236",
"255",
"274",
"293",
"312",
"331",
"350",
"369",
"388",
"407",
"426",
"445",
"464",
"483",
"502",
"521",
"540",
"559",
"578",
"597",
"616",
"635",
"654",
"673",
"692",
"711",
"730",
"749",
"768",
"787",
"806",
"825",
"844",
"863",
"882",
"901",
"920",
"939",
"958",
"977",
"996",
"015",
"034",
"053",
"072",
"091",
"110",
"129",
"148",
"167",
"186",
"205",
"224",
"243",
"262",
"281",
"300",
"319",
"338",
"357",
"376",
"395",
"414",
"433",
"452",
"471",
"490",
"509",
"528",
"547",
"566",
"585",
"604",
"623",
"642",
"661",
"680",
"699",
"718",
"737",
"756",
"775",
"794",
"813",
"832",
"851",
"870",
"889",
"908",
"927",
"946",
"965",
"984",
"003",
"022",
"041",
"060",
"079",
"098",
"117",
"136",
"155",
"174",
"193",
"212",
"231",
"250",
"269",
"288",
"307",
"326",
"345",
"364",
"383",
"402",
"421",
"440",
"459",
"478",
"497",
"516",
"535",
"554",
"573",
"592",
"611",
"630",
"649",
"668",
"687",
"706",
"725",
"744",
"763",
"782",
"801",
"820",
"839",
"858",
"877",
"896",
"915",
"934",
"953",
"972",
"991",
"010",
"029",
"048",
"067",
"086",
"105",
"124",
"143",
"162",
"181",
"200",
"219",
"238",
"257",
"276",
"295",
"314",
"333",
"352",
"371",
"390",
"409",
"428",
"447",
"466",
"485",
"504",
"523",
"542",
"561",
"580",
"599",
"618",
"637",
"656",
"675",
"694",
"713",
"732",
"751",
"770",
"789",
"808",
"827",
"846",
"865",
"884",
"903",
"922",
"941",
"960",
"979",
"998",
"017",
"036",
"055",
"074",
"093",
"112",
"131",
"150",
"169",
"188",
"207",
"226",
"245",
"264",
"283",
"302",
"321",
"340",
"359",
"378",
"397",
"416",
"435",
"454",
"473",
"492",
"511",
"530",
"549",
"568",
"587",
"606",
"625",
"644",
"663",
"682",
"701",
"720",
"739",
"758",
"777",
"796",
"815",
"834",
"853",
"872",
"891",
"910",
"929",
"948",
"967",
"986",
"005",
"024",
"043",
"062",
"081",
"100",
"119",
"138",
"157",
"176",
"195",
"214",
"233",
"252",
"271",
"290",
"309",
"328",
"347",
"366",
"385",
"404",
"423",
"442",
"461",
"480",
"499",
"518",
"537",
"556",
"575",
"594",
"613",
"632",
"651",
"670",
"689",
"708",
"727",
"746",
"765",
"784",
"803",
"822",
"841",
"860",
"879",
"898",
"917",
"936",
"955",
"974",
"993",
"012",
"031",
"050",
"069",
"088",
"107",
"126",
"145",
"164",
"183",
"202",
"221",
"240",
"259",
"278",
"297",
"316",
"335",
"354",
"373",
"392",
"411",
"430",
"449",
"468",
"487",
"506",
"525",
"544",
"563",
"582",
"601",
"620",
"639",
"658",
"677",
"696",
"715",
"734",
"753",
"772",
"791",
"810",
"829",
"848",
"867",
"886",
"905",
"924",
"943",
"962",
"981",
"000",
"019"]

for i in range(n,2,-1):
    sub_s = s[i-3:i]
    # print(sub_s)
    if sub_s in memo:
        # print(i)
        for j in range(i-4,-1,-1):
            num = int(s[j:i])
            # print("aaa")
            # print(i)
            # print(j)
            # print(num)

            if(num % 2019 == 0):
                # print("res//////////////////////////////////////////////")
                res +=1
            # print()
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:57:47 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

x = 2019
S = input()
l = len(S)
S = int(S)

a, b = [],[0]
s = 0
for i in range(l):
    s = (S%10**(i+1))
    b.append(s % x)

ans = 0

xx = [0 for _ in range(2019)]
for i in range(len(b)):
    xx[b[i]] += 1

def a(n):
    return n*(n+1)//2 

for i in range(len(xx)):
    if xx[i] > 1:
        ans += a(xx[i] - 1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
start = time.time()
N = input()
NN = list(map(int, list(N)))

num = 0
for i in range(len(N)+1):
    for j in range(i+4, len(N)+1):
        if sum(NN[i:j]) % 3 == 0:
            if int(N[i:j]) % 673 == 0:
                num += 1


print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
A =str(input())


N = int(len(A))

S = 0

for i in range(N):
  
  for j in range(N):
      
      if i >= j:
          continue
      
      x = (A[i:j+1])
      
      
      y = int(x)
      
      if y % 2019 == 0:
            
            S += 1

print(int(S))

Submission status: Time Limit Exceeded

Solution code:
x =input()
count = 0
while(True):
    for i in range(1,100):
        count += x.count(str(2019*i))
    if 2019*i > int(x):
        break
print(str(count))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s=input()
ss=len(s)
res=0
target=2019

l=r=0
ff=False

for i in range(ss-4):
    l=i
    if ff : l =r-1
    if l > ss-4:break


    ff=False
    for j in range(l+4,ss+1):
        r=j

        tmp=int(s[l:r])
        # print(tmp)
        if ff == True and s[r] != '0':break


        if tmp % target ==0:
            # print(l,r,tmp)
            # print('xxxx',tmp)
            ff=True
            res+=1

print(res)

Submission status: Time Limit Exceeded

Solution code:
S = input()
len = len(S)
List =[]
for i in range(0,len-3):
  for j in range(i+4,len+1):
    List.append(int(S[i:j])%2019)
      

print(List.count(0))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
length = len(s)
count_dict = {}

num = int(s)%2019
count_dict[num] = 1

for i in range(1,length):
    num = (num-int(s[-i])*10**(i-1)%2019)%2019
    # num = num+int(s[-i])
    if num not in count_dict:
        count_dict[num] = 1
    else:
        count_dict[num] += 1


count = 0
for k,v in count_dict.items():
    count += v*(v-1)/2
    if k == 0:
        count += v

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
s = input()
count = 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:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

counter = 0

for i in range(len(S)):
    for j in range(1,len(S)-i):
        s = int("".join(S[i:i+j+1]))
        if s % 2019 == 0:
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from math import factorial

S=list(map(int,input()))
N=len(S)
MAX=2100
MOD=10**9+7

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

fac=[None for i in range(MAX)]
finv=[None for i in range(MAX)]
inv=[None for i in range(MAX)]

def COMinit(num):
    global fac
    global finv
    global inv
    fac[0]=1
    fac[1]=1
    finv[0]=1
    finv[1]=1
    inv[1]=1

    for i in range(2,num):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def COM(n,k):
    if n<k:
        return 0
    elif n<0 or k<0:
        return 0
    else:
        return int(fac[n] * (finv[k] * finv[n - k] % MOD) % MOD)


COMinit(MAX)

M=[[0 for j in range(10)] for i in range(2019)]

ans=0
num=0
for i in range(N):
    num+=S[-(1+i)]*(10**i)
    I=num%2019
    if I==0:
        ans+=1
    syou=num//2019
    J=syou%10
    M[I][J]+=1

for i in range(2019):
    for j in range(10):
        if M[i][j]>=2:
            ans+=COM(M[i][j],2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    sl = list(map(int, s))
    lens = len(s)
    ans = 0
    
    if lens <= 3:
      print(0)
      exit()
    
    total = 0
    cur = [0]
    for l in sl:
        total += l
        cur.append(total)
    
    for i in range(lens-3):
        for j in range(i+4, lens+1):
            su = cur[j] - cur[i]
            if su%3 != 0:
                continue
            else:
                if int(s[i:j]) % 2019==0:
                    ans += 1
    print(ans)

main()

Submission status: Time Limit Exceeded

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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    s = input()
    check = 2019
    ret = 0

    for i in range(1, len(s) + 1):
        pre = ""
        if i == 1:
            pre = s[-(i + 2):]
        else:
            pre = s[-(i + 2):-(i - 1)]

        pre_amari = int(pre)
        keta = len(pre)
        for j in range(i + 3, len(s) + 1):
            plus_s = s[-j]
            keta += 1

            check_amari = (int(plus_s + "0" * (keta - 1)) + pre_amari) % check
            if check_amari == 0:
                ret += 1

            pre_amari = check_amari
    return ret


if __name__ == "__main__":
    print(main())

Submission status: Time Limit Exceeded

Solution code:
def main():
    from collections import Counter

    s = str(input())
    num = ""
    li = []
    f = 0
    mi = 0
    li_append = li.append

    cm = {}
    for i in range(1,2*(10 ** 5)):
        cm[i] = i * (i - 1) // 2
    cm[0] = 0



    for i in range(1, len(s) + 1):
        num = s[-i] + num
        li_append(int(num) % 2019)
        if num[0] == "0":
            f += 1
        else:
            mi += cm[f+1]
            f = 0

    co = Counter(li)
    val = [i for i in co.values() if i > 1]
    ans_1 = 0

    for x in val:
        ans_1 += cm[x]
    ans2 = 0
    if 0 in co:
        ans2 = co[0]
    print(ans_1 + ans2 - mi)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
indexs = []
count = 0
for i in reversed(range(3,N)):
    check_num = int(S[i-2]+S[i-1]+S[i])
    if (check_num % 19 == 0)&(int(S[i-3]) % 2 == 0 ): 
        indexs.append(i)        
for i in indexs:
    for j in range(i):
        if int(S[j:i+1]) % 2019 == 0 :
            count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

s = str(input())

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
n = 2019
cnt = 0
if S == '0':
    cnt += 1
elif int(S) >= n:
    i = 4
    while l >= i:
        for j in range(0,l-i+1):
            if int(S[j:j+i]) % n == 0:
                cnt += 1
        i += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)

answer = 0

for start in range(N-3):
    for end in range(start+4,N+1):
        if int(S[start:end]) % 2019 == 0:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as C

S = input()
S_l = len(S)

count = 0
k = [i for i in list(C(list(range(S_l)), 2)) if i[1] - i[0] > 3]

for i in k:
    n = int(S[i[0] : i[1] + 1])
    if n % 2019 == 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
A =str(input())


N = int(len(A))

S = 0

for i in range(N):
  
  for j in range(N):
      
      if i >= j:
          continue
      
      x = (A[i:j+1])
      
      
      y = int(x)
      
      if y % 2019 == 0:
            
            S += 1

print(int(S))

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = s.__len__()
c = 0
l = list()
for i in range(n):
    l.append(s[i])

for i2 in range(l.__len__()):
    start = s[i2]
    for i3 in range(l.__len__()-i2-1):
        start += s[i3+i2+1]
        if int(start) % 2019 ==0:
            c = c + 1
print(c)