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:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S)
    for i in range(len(S)):
        if i==0:
            pass
        else:
            n-=int(S[i-1])*pow(10,(len(S)-i))
        li[n%2019]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# ABC164d
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    s = input()
    n = len(s)-1
    c = 0

    def modinv(a, mod=10**9+7):
        return pow(a, mod - 2, mod)

    def combination(n, r, mod=10**9+7):
        r = min(r, n-r)
        res = 1
        for i in range(r):
            res = res * (n - i) * modinv(i+1, mod) % mod
        return res

    import math

    def c_count(n, r):  # 組み合わせ
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    counter = [0] * 2019
    number = 0
    for i in range(n):
        # print(s[n-i-1])
        #number += int(s[n-i-1])*10**(i+1)
        number = int(s[n-i-1:])
        counter[number % 2019] += 1
    counter[0] += 1

    for i in range(len(counter)):
        num = counter[i]
        if num >= 2:
            c += c_count(num, 2)

    print(c)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
if len(s) <= 4 and int(s) != 2019 and int(s) < 4038:
    print(0)
elif len(s) <= 4 and int(s) == 2019:
    print(1)
else:
    count = 0
    for i in range(len(s)-3):
        for j in range(4,len(s)+1):
            x = s[i:j]
            if x != "" and int(x) % 2019 == 0:
                count += 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
  S=input()
  S_len=len(S)
  s_count=0
  for i in range(0,S_len-3):
    for j in range(i+3,S_len):
      int_tgtS=int(S[i:j+1])
      if(int_tgtS%2019==0):
        s_count=s_count+1
  print(s_count)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import sys


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


def resolve():
    s = input()

    ans_list = []
    """
    for i in range(len(s)):
        jump = 4
        start = 0
        for j in range(0, len(s)):

            start = start
            end = start + j

            if start >= end:
                continue

            print(start, end)
            int_s = int(s[start:end])

            if int_s % 2019 == 0:
                ans_list.append((start, end))

            jump += 1
    """

    for i in range(0, 5):
        for j in range(4, len(s)):
            for k in range(0, len(s), j):
                if i // j >= 2:
                    continue

                start = i + k
                end = start + j

                if end >= len(s):
                    continue

                # print(start, end)
                int_s = int(s[start:end])

                if int_s % 2019 == 0:
                    ans_list.append((start, end))
    print(len(ans_list))



if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 標準入力の取得
S = input()
size = len(S)

# 求解処理
NUMBER = 2019
i_max = size - 3
counter = 1
expected = 0
result = 0
for i in range(i_max):
    j_min = i + 3
    for j in range(j_min, size):
        number = int(S[i:j+1])
        if number % NUMBER == expected:
            result += counter

# 結果出力
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

S=int(input())
n=int(math.log10(S))+1
cnt=0

for i in range(5,n):
  for j in range(n-i+1):
    if (S//(10**(n-i-j))%(10**(i)))%2019==0:
      cnt+=1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:

s = input()

i = 0
ns = len(s)
ans = 0
while i < ns - 1:
    j = i + 1
    while j < ns:
        j += 1
        n = int(s[i:j])
        if n % 2019 == 0:
            ans += 1
    
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
dict = {}
cnt = 0
tot = 0

sum = {}
sum[0] = 0
for i in range(len(S)):
    tot += int(S[i])
    sum[i+1] = tot
#print(sum)


for i in range(len(S)-3):
    for j in range(i+3, len(S)):
        if S[i:j+1] in dict:
            dict[S[i:j+1]] += 1
        else:
            if (sum[j+1]-sum[i])%3 == 0:
                dict[S[i:j+1]] = 1


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

'''

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,3,-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:
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
            break
        e += 1
    s += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s= int(input())

s=str(s)
import itertools
List = list(itertools.combinations(range(len(s)), 2))

cnt =0
for i in List:

    
    if (int(s[(int(i[0])):(int(i[1])+1)])%2019)==0:
        cnt +=1
  
    

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = len(S)
noCount = 0
fourDigi = {'2019', '4038', '6057', '8076'}
fiveDigi = {'10095', '12114', '14133', '16152', '18171', '20190', '22209', '24228', '26247', '28266', '30285',
              '32304', '34323', '36342','38361', '40380', '42399', '44418', '46437', '48456', '50475', '52494',
              '54513', '56532', '58551', '60570', '62589', '64608', '66627', '68646', '70665', '72684', '74703',
              '76722', '78741', '80760', '82779', '84798', '86817', '88836', '90855', '92874', '94893', '96912', '98931'}
fiveD2nd = {'0','2','4','6','8'}
sixDigi = {'100950', '102969', '104988', '107007', '109026', '111045', '113064', '115083', '117102', '119121',
             '121140', '123159', '125178', '127197', '129216', '131235', '133254', '135273', '137292', '139311',
             '141330', '143349', '145368', '147387', '149406', '151425', '153444', '155463', '157482', '159501',
             '161520', '163539', '165558', '167577', '169596', '171615', '173634', '175653', '177672', '179691',
             '181710', '183729', '185748', '187767', '189786', '191805', '193824', '195843', '197862', '199881'}
for j in range(1,l):
    for k in range(l - j + 1):
        segment = str(int(S[k:k + j]))
        if segment in fiveDigi or segment in fourDigi or segment in sixDigi:
            noCount += 1

print(noCount)

Submission status: Time Limit Exceeded

Solution code:
#A,B,C,D=map(int,input().split(" "))

mod=2019
a=input()

N=len(a)
t=[]
ans=0

for i in range(N):
  for j in range(i+1,N+1):
    u=int(a[i:j])
    #print(u)
    if (u % mod)==0:
      ans+=1
      #print(i+1,j)
      break
print(ans)

Submission status: Time Limit Exceeded

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

l = []
for _ in range(1, 20190000):
    if _%2019 == 0:
        l.append(_)
l = set(l)
#print(l)

def aaa(s, num):
    x = 0
    for i in range(4,num+1):
        for j in range(num - i + 1):
            if int(s[j:j+i]) in l:
                x += 1
    print(x)

aaa(s, num)

Submission status: Time Limit Exceeded

Solution code:
s=list(input())
n=[]
ans=0
for i in range(len(s)):
  a=int(s[i])
  n.append(a)
for j in range(len(n)-3):
  for k in range(j+3,len(n)):
    #if n[k]==0 or n[k]==2 or n[k]==4 or n[k]==5 or n[k]==6 or n[k]==8:
    #  break
    #sum=0
    #for l in range(j+1,k+1):
    #  sum=sum+n[l]
    #if sum%3!=0:
    #  break
    num=0
    for m in range(k-j,-1,-1):
      num=num+n[k-m]*(10**(m))
#    print(num)
    if num%2019==0:
      ans=ans+1
#print(len(n))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
L = len(S)
cnt = 0

li = [0]
for i in range(L):
    li.append(li[-1]+int(S[i]))

li.append(li[-1])

for i in range(0,L-4):
    for j in range(i+5,L+1):
        if (li[j]-li[i]) % 3 == 0:
            integer = int(S[i:j])
            if integer % 673 == 0:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S_input = input()
S_list = list(S_input)
S_len = len(S_list)
S = 0
count =0
j =0
k = 0
for i in range(0,S_len-3):
  for j in range(k,S_len):
    S = S+int(S_list[j])
    if S % 2019 == 0:
      count+=1
    S *= 10
  S = 0
  k += 1
print(count)

Submission status: Time Limit Exceeded

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

for i,item in enumerate(s):
    dp[i][item] += 1
    for j in range(2019):
        tmp = (10 * j + item) % 2019
        dp[i][tmp] += dp[i-1][j]
#         if dp[i-1][j]!=0:
#             print(i, tmp, dp[i-1][j])
print(sum(dp[j][0] for j in range(len(dp))))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from collections import deque

s=input()
l=len(s)
i=0
d=0
while i+3<=l-1:
    for j in range(i+3,l):
        if int(s[i:j+1])%2019!=0:
            continue
        else:
            d+=1
            i=i+1
            break
    else:
        i+=1
print(d)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
baisu=set([])


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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s = input()

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


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = str(input())
n = len(S)
print(sum(int(S[a:b+1]) % 2019 == 0 for a in range(0,n-3)  for b in range(a+3,n)))

Submission status: Time Limit Exceeded

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

for i in range(0,mojisuu-4):
    for k in range(mojisuu,3+i,-1):
        check=int(s[i:k])
        if(check%2019==0):
            count+=1
           
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
rest = [0] * (len(S) + 1)
rest[0] = 0
rd = 1
for i in range(len(S)):
    rest[i+1] = (rest[i] + int(S[-(i+1)]) * rd) % 2019
    rd *= 10
    # print(i, rest[i+1], rest[i], int(S[-(i+2)]), int(S[-(i+2)]) * 10 ** (i+1))
# print(rest)
cnt = [0] * (2019 + 1)
for i in rest: cnt[i] += 1
ans = 0
for i in range(2020):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
l = len(s)
d = [[0] * 2020 for i in range(l + 1)]

for i in range(0, l):
    for j in range(2019):
        d[i + 1][(j * 10 + int(s[i])) % 2019] = d[i][j]
    d[i + 1][int(s[i])] += 1
    d[i + 1][2019] += d[i][2019] + d[i + 1][0]

print(d[l][2019])

Submission status: Time Limit Exceeded

Solution code:
s = input()
start_idx = 0
end_idx = 4
count = 0

while start_idx < len(s)-4:
    if (end_idx > len(s)):
        start_idx += 1
        end_idx = 3+start_idx
    if (int(s[start_idx:end_idx]) % 2019) == 0:
        count += 1
    end_idx += 1
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, n):
        if int(S[i:j + 1]) % 2019 == 0:
            ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

S = input()

ss = len(S)

count = 0
for a in range(ss-4):
    for b in range(a+4, ss+1):
        if int(S[a:b]) % 2019 == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()
l = [i*2019 for i in range(1,200000) if i*2019 <= int(S)]
m = [str(i) for i in l if str(i).find('0') == -1]
c = 0
st = str(S)
mls = len(S)

sl = [S[mls-i:mls] for i in range(5,mls+1)]

for i in m:
    for j in sl:
        if j.startswith(i):
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
s = input()
ans = 0
for i in range(len(s)-3):
  j = i + 3
  while(j <= len(s)):
    if int(s[i:j+1]) % 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)-3):
    j=4
    while i+j <= len(S):
        q = int(S[i:i+j])%2019
        if q==0:
            ans+=1
            j+=4
        elif len(str(q))==4:
            j+=1
        else :
            j += 4-len(str(q))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
input_s = input()
len_s = len(input_s)
ans = 0

for digit in range(4, len_s):
    for i in range(len_s - digit):
        j = i + digit
        if (int(input_s[i:j+1]) % 2019) == 0:
            ans += 1
            i = j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# TODO NG
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline

s = input()

cnt = 0
s_n = np.ones(200000*200, dtype='int64')
for i in range(len(s)-3):
    for j in range(i+3, len(s)):
        s_n[cnt] = int(s[i:j+1]) % 2019
        cnt += 1
#         if num % 2019 == 0:
#             cnt += 1
n_2019 = s_n[s_n == 0]
print(len(n_2019))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    S =     _in[0]   # type:str
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    len_S = len(S)
    memo = set()
    cnt = 0
    for i in range(len_S):
        for j in range(i+3,len_S):
            #print(int(S[len_S-j-1:len_S-i]))
            if j == i+3:
                mod = int(S[len_S-j-1:len_S-i])%3
            else:
                mod = (mod+int(S[len_S-j-1]))%3
            if mod == 0:
                _ = int(S[len_S-j-1:len_S-i])
                if _ in memo:
                    cnt += 1
                elif _%2019==0:
                    cnt += 1
                    memo.add(_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def run():
    target_num = 2019

    str_n = input()
    dp = [[0 for i in range(target_num)] for j in range(len(str_n) + 1)]

    for i, new_int in enumerate(str_n, 1):
        new_int = int(new_int)
        for j, dp_prev_i_j in enumerate(dp[i - 1]):
            if dp_prev_i_j != 0:
                dp[i][(j * 10 + new_int) % target_num] = dp_prev_i_j
        if new_int != 0:
            dp[i][new_int % target_num] += 1

    ans = sum([d[0] for d in dp])
    print(ans)


if __name__ == '__main__':
    run()

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

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 = input()
count = 0

i = 0
j = len(s) - 1
while j > 0:
    if int(s[i:j+1]) % 2019 == 0:
        count += 1
        # print(i, j)
    i += 1
    if i + 3 >= j:
        j -= 1
        i = 0

print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
D = input()
S = int(D)
L = len(D)

R = 0


for i in range(L-3):
  for j in range(3+i,L+1):
    judge = int(D[i:j])
    if judge % 2019 == 0:
      R += 1

print(R)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(20000*20000)

S = str(input())
ans = set()

def dfs(i, j):
    if int(S[i:j+1])%2019 == 0:
        ans.add((i, j))
        return
    if j == len(S)-1:
        return

    dfs(i+1, j+1)
    dfs(i, j+1)

if len(S) < 4:
    print(0)

else:
    dfs(0, 3)
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
S = input()
ls = len(S)
res = 0

for i in range(0,ls-4):
    for j in range(i+5,ls+1):
        if int(S[i:j]) % 2019 ==0:
            res = res+1
            
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
n2 = str(n)
n_ = len(str(n2))

count = 0
if n_ >200000:
  n_ = 200000
  
for i in range(n_):
  for j in range(i+3,n_):
    if n2[i] != "0":
      num = n2[i:j+1]
      if int(num)%2019 ==0:
        count += 1
    else:
      count = count
print(count)

Submission status: Time Limit Exceeded

Solution code:
num=input()
counter=0
for y in range(len(num)+1):
  for x in range(y):
    if int(num[x:y])%2019==0:
      counter=counter+1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
a = input()
a = list(a)

s = 0
r = 1
cnt = 0
for l in range(len(a)):
    s = a[l]
    r =l
    while int(s)%2019 != 0 and r<=len(a)-2:
        #print(l,r)
        s +=a[r+1]
        if int(s)%2019 == 0:
            cnt +=1
        #print(s,cnt,l,r)   
        r += 1
    #r +=1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
S = input()
ret = 0
iS = [int(s) for s in S]

for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        if j == i + 4:
            if i == 0:
                sum_num0 = sum(iS[i:j])
            else:
                sum_num0 = sum_num0 - iS[i-1] + iS[j-1]
            sum_num = sum_num0
            if int(S[i:j]) != 2019:
                continue
        else:
            sum_num += iS[j-1]
        
        if sum_num % 3 == 0:
            test = int(S[i:j]) // 3
            if test % 673 == 0:
                ret += 1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

m = 2019
div_list = [0]*m
div_list[0] += 1
S = np.array(list(input()))
N = len(S)
num = 0
for i in range(N):
    num += 10**i*int(S[N-i-1])
    div_list[num%m] += 1

ans = 0
for i, item in enumerate(div_list):
    ans += int(item*(item-1)/2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=str(input())
ans=0
nn=len(n)
for i in range(0,nn-3):
  for j in range(i+3,nn+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()
c=0
for i in range(len(s)-3):
    for j in range(i+3,len(s)):
        if int(s[i:j+1])%2019==0:
            c+=1
print(c)

Submission status: Time Limit Exceeded

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


def order(N):
    ans = []
    for i in range(N-1):
        for j in range(i+1,N):
            ans.append([i,j])
    return ans

c = 0
for o in order(N):
    if int(S[o[0]:(o[1]+1)])%2019 == 0:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import heapq
S = input()
cum = []
dict = {}
for i in range(len(S)):
    n = int(S[i:])
    cum.append(n % 2019)
    dict[n % 2019] = 0


for c in cum:
    dict[c] += 1
ans = 0
for k, v in dict.items():
    if k == 0:
        ans += v
    ans += v * (v-1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    n=int(S)
    for i in range(len(S)):
        if i==0:
            pass
        else:
            n-=int(S[i-1])*10**(len(S)-i)
        li[n%2019]+=1

    res=li[0]
    for i in range(2019):
        res+=li[i]*(li[i]-1)//2
    print(res)
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    ans = 0
    s = input()
    for i in range(20001):
        t = (2019*i)
        if t > int(s):
          break
        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()