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()
ans = 0
for i in range(6, int(S)//2019 + 1):
  d = str(2019*i)
  if "0" in d:
    continue
  ans += S.count(d)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    si = int(input())
    s = list(str(si))
    if '0' in s:
        print(0)
        return
    

    sm = []
    for i, ss in enumerate(s):
        ssi = int(ss)
        if i == 0:
            sm.append(ssi)
        else:
            sm.append(ssi + sm[-1])
    ans = 0
    for i in range(len(s)):
        if i == 0:
            tmp = 0
        else:
            tmp = sm[i-1]

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

            if (sm[j] - tmp) % 3 != 0:
                continue
            a = ''
            for k, aa in enumerate(s[i:j+1]):
                a += aa
            if int(a) % 673 == 0:
                ans += 1

    print(ans)
    # print(sm)
if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def s0():return input()

s=s0()

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
S = str(S)
long = len(S)
count = 0
for i in range(1,long):
  for j in range(i+1,long-1):
    judge = 0
    cut = S[(i-1):(j+2)]
    judge = "".join(cut)
    if int(judge)%2019 == 0:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    S = list(str(input()))
    A = [k * 2019 for k in range(1,100)]
    cnt = 0
    if len(S) >= 4: # ToDo 4桁でカウント
        for keta in range(4,len(S)):
            for i in range(0,len(S)-keta+1):    # i ＝ idxの場所
                NUM = ''.join(S[i:keta+i])
                if int(NUM) in A: cnt+=1

    print(cnt)


main()

Submission status: Time Limit Exceeded

Solution code:
s = input()
dp = [-1 for _ in range(200000)]

dp[0] = 0 
dp[1] = 0 
dp[2] = 0 
dp[3] = 0 

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

print(dp[len(s)])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
num = str(N)
s=len(num)
ans=0
for i in range(4,s+2):
    for u in range(1,s-i+2):#hajimenobanngou
        a=int("".join((map(str,num[u-1:u+i-1]))))
        if  a%3==0 and a%673==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S=input()
n=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:
            n+=1
print(n)

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)
      i=j

print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
N = len(S)
MOD = 2019
dlist = dict()
for i in range(5):
    dlist[i] = (10**i) % MOD
if N > 5:
    for i in range(5,N):
        d = i
        l = list()
        while d > 0:
            l.append(d % 2)
            d //= 2
        num_N_ = 1
        for j in range(len(l)):
            
            if l[j] == 1:
                val = 2**j
                if val in dlist.keys():
                    num_N_ *= dlist[val] 
                    num_N_ = num_N_ % MOD
                else:
                    temp_ = (10**val) % MOD
                    num_N_ *= temp_
                    num_N_ = num_N_ % MOD
                    dlist[val] = temp_
        dlist[i] = num_N_
ret = 0
S_REV = ''
for i in range(N):
    S_REV += S[N - i - 1]
for i in range(N ):
    sums = 0
    for j in range(i ,N):
        sums += (int(S_REV[j]) * dlist[j-i]) 
        sums = sums % MOD
        if sums == 0:
            ret += 1
print(ret)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import heapq
S = input()
cum = []
dict = {}
for i in range(len(S)-1, -1, -1):
    n = int(S)
    n = n % 10**(i+1)
    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:
S=input()

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

Submission status: Time Limit Exceeded

Solution code:
mul2019 = []
for i in range(2, 100):
    if str(i*2019).count("0")>0:
        continue
    mul2019.append(str(i*2019))
n = str(input())
cnt = 0
for j in range(4, len(n)):
    for i in range(len(n)-j+1):
        for r in mul2019:
            if str(r)==n[i:i+j]:
                cnt += 1 
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
num = int(s)
cnt = 0
for i in range(n):
  for j in range(n-i+1):
    #if int(s[i:i+j]) % 2019 == 0:
    tmp = (num%(10**(n-i)))//(10**j)
    if tmp!=0 and tmp % 2019 == 0:
      cnt += 1
    #print(tmp)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
s = input() #sys.stdin.readlineは最後が改行
s = s[:-1]
n =len(s)

num=0
tmp=0

amari= [0]

for i in range(n):
    num = tmp + int(s[-1-i])*(10**(i))%2019
    tmp = num%2019
    amari.append(tmp)

from collections import Counter
ctr = Counter(amari)
ans = 0
for val in ctr.values():
        ans += val*(val-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
S = input()
R = []
for i in range(len(S)):
  if i == 0:
    R.append(int(S[i])%3)
  else:
    R.append((R[i-1]+int(S[i]))%3)
ans = 0
for i in range(len(S)):
  if i == 0:
    j = 3
    while j <len(S):
    	if R[j]==0 and int(S[:j+1])%2019 == 0:
    		#print(int(S[:j+1]))
            ans = ans + 1
    	j = j + 1
  else:
    j = i + 3
    while j < len(S):
    	if R[j]-R[i-1]==0 and int(S[i:j+1])%2019 == 0:
    		#print(int(S[i:j+1]))
            ans = ans + 1
    	j = j + 1
print(ans)

Submission status: Time Limit Exceeded

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

if n<5: ans = 0
else:
    ans = 0
    for i in range(n):
        for j in range(i+5, n+1):
            num = int(s[i:j])
            if int(num)%2019==0: ans += 1

print(ans)

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

print(len(li))

Submission status: Time Limit Exceeded

Solution code:
S= int(input())
Sstr=str(S)
n=0
for i in range(S//2019):
    y=2019*i
    if str(y) in Sstr:
        n+=1
print(n)

Submission status: Time Limit Exceeded

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

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 = l[-i]
            else:
                x = l[-i] - l[-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)
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-3,-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()
count = 0
for i in range(len(S)):
    if int(S[i:i+2]) % 2 == 0:
        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:
N = input().strip()
length = len(N)
l = length
r = []
while l >= 4:
  count = 0
  while count + l <= length:
    r.append(N[count:l+count])
    count = count + 1
  l = l - 1
  
r = [int(s) for s in r]
#print(r)
r = list(map(lambda x:x % 2019, r))
#print(r)
print(r.count(0))

Submission status: Time Limit Exceeded

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

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

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
s=input()

k=0

for i in range(len(s)):

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

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

Submission status: Time Limit Exceeded

Solution code:

S = input()
N = len(S)

cnt = 0
for i in range(N-1):
    pre_amari = "0"
    for j in range(i,N):
        if len(pre_amari) < 3:
            pre_amari += S[j]
            continue
        # print("@",pre_amari + S[j])
        # print("@@",int(pre_amari + S[j]) )
        pre_amari = str(int(pre_amari + S[j]) % 2019)
        # print("@@@",i,j,pre_amari)

        if pre_amari == "0":
            cnt += 1
print(cnt)

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    S=readline().strip()
    li=[0]*2019
    for i in range(len(S)):
        n=int(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:
str=input()
gap_len=4
flag=0
count=0
for gap_len in range(4,20000):
    for i in list(range(len(str)-gap_len+1)):
        sub_str=str[flag:flag+gap_len]

        num=int(sub_str)
        if(num%2019==0):
            count+=1
        flag+=1
    flag =0
print(count)

Submission status: Time Limit Exceeded

Solution code:
S = int(input())
total = 0
keta = len(str(S))
for i in range(keta):
  for j in range(i+3,keta):
    n = (S%10**(keta-i))//10**(keta-j-1)
    #print(n)
    if n % 2019 == 0:
      total += 1
print(total)

Submission status: Time Limit Exceeded

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

def main():
    S=list(input())
    count=0
    if len(S)<4:
        print(0)
        exit()
    for i in range(len(S)-4):
        s="".join(S[i:i+4])

        for j in range(len(S)-3-i):
            if int(s)%2019==0:
                count+=1
            if not i+4+j>=len(S):
                s+=S[i+4+j]

    print(count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a = [ord(c)-48 for c in input()]

n = len(a)

ans = 0
for i in range(n-3):
    cur = 0
    for j in range(i, i+4):
        cur += a[j]
        cur *= 10
    for j in range(i+4, n):
        cur += a[j]
        if (cur % 2019 == 0):
            ans += 1
        cur *= 10

print(ans)

Submission status: Time Limit Exceeded

Solution code:
si=input()
sa = []

for i in range(5,len(si)+1):
    for j in range(0,i-4):
        ss = int(si[j:i])
        if ss % 2019 == 0 and ss <= 200000:
            sa.append(i)

"""
for i in range(5,len(si)+1):
    ss = int(si[(i-5):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
    ss = int(si[(i-4):i])
    if ss % 2019 == 0 and ss <= 200000:
        sa.append(i)
    if i>=6:
        ss = int(si[(i-6):i])
        if ss % 2019 == 0 and ss <= 200000:
            sa.append(i)
"""
print(len(sa))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    count=np.zeros(2019,dtype=int)
    ans=0
    count_t=np.zeros(2019,dtype=int)
    for i in range(len(s)):
        count_t[int(s[i])]+=1
        for k in range(2019):
            a=count[k]
            if a==0:
                continue
            else: 
                t=(k*10+int(s[i]))%2019
                count_t[k]-=a
                count_t[t]+=a
                if t==0:
                    ans+=a
        #print(count[0:20])
        #print(count_t[0:20])
        count=count+count_t
        count_t-=count_t
    print(ans)
                
if __name__ == '__main__':
    do()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = len(s)
right = n-1
ans = 0
 
def count(s,i):
    counta = 0
    for left in range(n-i-3):
        k = int(s[left:n-i+1])
        if k%2019==0:
            counta += 1
    return counta
 
 
for i in range(2,n-2):
    ans += count(s,i-1)
print(ans)

Submission status: Time Limit Exceeded

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

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] < 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()
N = int(len(S))

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
S=str(input())
n=len(S)
l=[]
for s in S:
    l.append(s)
d=deque(l)
u=0
while n>0:
    a = ''
    for i in d:
        a+=i
        if int(a)%2019==0:
            u=u+1
    d.popleft()
    n=n-1
print(u)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
S = list(map(int,input().rstrip()))
result=0
for i in range(len(S)):
    for j in range(1,len(S)-i+1):
        n = reduce(lambda a,b:10*a+b, S[i:i+j])
        if n %2019==0:
            result+=1
print(result)

Submission status: Time Limit Exceeded

Solution code:
i = 0
count = 0
line = input()
size = len(line)
num = [int(x) for x in list(str(line))]
if int(line)==2019:
    print("1")
else:
    while i<size-4:
        j = i + 4
        while j<=size:
            x = num[i:j]
            s = ""
            for k in range(len(x)):
                s = s + str(x[k])
            if int(s)%2019 == 0:
                count = count+1
                j = j + 4
                break
            j = j + 1
        i = i + 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
S = input()

N = len(S)
japp = 0
ans = 0
for i in range(N,4,-1):
  for j in range(5,i+1):
    if i-j-japp < 0:
      japp = 0
      break
    Si = S[i-j-japp:i]
    if int(Si) % 2019 == 0:
      ans += 1
      japp = 4
      #print(Si)
    else:
      japp = 0 

print(ans)

Submission status: Time Limit Exceeded

Solution code:

S = input()

Len = len(S)
N = 0
for Num1 in range(0, Len-2):
    #0-> 3
    #Len-4 -> Len-1
    Sum = int(S[Num1]) + int(S[Num1+1]) + int(S[Num1+2])
    Remainder = int(S[Num1:Num1+3]) % 2019
    for Num2 in range(Num1+4, Len+1):
        Sum += int(S[Num2-1])
        Remainder = (10 * Remainder + int(S[Num2-1]) ) % 2019
        if(Remainder == 0):
            N+= 1
            Num2 += 3
print(N)

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**(1+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+=combinations_count(M[i][j],2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a=input()

#b=int(a)

b=len(a)
sum=0
for i in range(0,b-4):
    for j in range(i+5,b+1):

        if int(a[i:j])%2019==0:
            sum+=1
print(sum)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    s = input()
    r = 0
    lens = len(s)
    for i1 in range(lens - 3):
        tnum = sum(list(map(int, s[i1:i1 + 4])))
        tint = int(s[i1:i1+4])
        if tnum % 3 == 0:
            r += tint % 673 == 0
        for i2 in range(i1+4,lens):            
            es = int(s[i2])
            tnum += es
            tint = tint*10 + es
            if tnum % 3 == 0:
                r += tint % 673 == 0
    print(r)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
S = input()

l = len(S)

ans = 0
for s, e in itertools.combinations(range(l+1), 2):
  if int(S[s:e]) % 2019 == 0:
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

from collections import deque

def main():
  d_origin = [i for i in input()]
  ans = 0
  for i in range(len(d_origin)):
    if len(d_origin) < 3:
      print(ans)
      return
    if i != 0:
      d_origin.pop(0)
    while len(d_origin) > 2 and int(d_origin[1])%2 != 0:
      d_origin.pop(0)
    d = d_origin.copy()
    for j in range(len(d)):
      if int(''.join(d))%2019 == 0:
        ans = ans + 1
      d.pop()
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
S=input()
N=len(S)
cnt=0
begin=0
end=0
for i in range(0,N+1):
    begin=i
    end=i+4
    
    while begin<N-3 and end<=N:
        if int(S[begin:end])%2019==0:
            cnt+=1
            if begin==N-5 and end==N:
                print(cnt)
                exit()
            else:
                begin= end-1
                end+=4
        else:
            end+=1
            continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
S = list(input())
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
s = input()
n = 2019

c = 0
for i in range(1, 1000000):
    st = str(n*i)
    if '0' in st:
      continue
    j = 0
    while j <= (len(s)-len(st)+1):
        if st in s[j:]:
            ind = s[j:].index(st)
            c+=1
            j = ind+j+1
        else:
            break
      
print(c)

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)

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 >= j:
        j -= 1
        i = 0

print(count)

Submission status: Time Limit Exceeded

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

remainder=[0]*2019
val=0
for i in range(1,N+1):
  val+=S[-i]*(10**(i-1))
  remainder[val%2019]+=1

ans=remainder[0]
for i in range(2019):
  if remainder[i]<=1:
    continue
  else:
    ans+=remainder[i]*(remainder[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

		i+=1
	j+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
S=input()
lenS=len(S)
ans = 0
l = []
for i in range(lenS):
    l.append(int(S[i:])%673)
for k,v in Counter(l).items():
    if k==0:
        ans += v
    else:
        ans += v*(v-1)//2
print(ans)