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: Runtime Error

Solution code:
def checker(s, n):
#    print(s)
    int_s = [int(c) for c in s]
    su = sum(int_s)
    if su%3 != 0:
        return False
    if n <= 10:
        i = int("".join(s))
        return i%673 == 0
    else:
        sub = int(s[-1])*2
        suba = int("".join(s[-4:-1]))
        subb = suba - sub
        new_s = s[:-4] + str(subb)
        checker(new_s, n-1)
    

def Main(S):
    le = len(S)
    if(0 <= le <= 3):
        return 0
    ans = 0
    for i in range(le-3):
        for j in range(i+4, le+1):
            s = S[i:j]
            lee = len(s)
            if checker(s, lee):
                ans += 1
    return ans
            


def main():
    S = str(input())
    print(Main(S))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from functools import reduce

def di(i, lst=[]):
    if i > 0:
        lst.append(i%10)
        return di(i//10, lst)
    else:
        lst.reverse()
        return lst
N=int(input())
N=di(N)
m=len(N)
q=0
if m<4:
  print(0)
if m==4:
  G=[]
  for j in range(4):
    G.append(N[j])
  a = reduce( lambda a,b:10*a+b, G)
  if a%2019==0:
    print(1) 
  else:
    print(0)
if m==5:
  Q=[]
  R=[]
  A=[]
  for i in range(4):
    Q.append(N[i])
  n = reduce( lambda a,b:10*a+b, Q)
  if n%2019==0:
    q=q+1
    
  for j in range(4):
    R.append(N[j+1])
  a = reduce( lambda a,b:10*a+b, R)
  if a%2019==0:
    q=q+1
  
  for i in range(5):
    A.append(N[i])
  n = reduce( lambda a,b:10*a+b, A)
  if n%2019==0:
    q=q+1    
  print(q)
  
if m==6:
  B1=[]
  B2=[]
  B3=[]
  B4=[]
  B5=[]
  B6=[]
  
  for i in range(4):
    B1.append(N[i])
  n = reduce( lambda a,b:10*a+b, B1)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B2.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B2)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B3.append(N[i+2])
  n = reduce( lambda a,b:10*a+b, B3)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B4.append(N[i])
  n = reduce( lambda a,b:10*a+b, B4)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B5.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B5)
  if n%2019==0:
    q=q+1 
  for i in range(6):
    B6.append(N[i])
  n = reduce( lambda a,b:10*a+b, B6)
  if n%2019==0:
    q=q+1   
  print(q)

Submission status: Runtime Error

Solution code:
def count1(st):
  if len(st)<3:
    return 0
  else:
    st2=st[:-1]
    co1=count1(st2)
    co2=count2(st)
    return co1+co2
  
def count2(st):
  if len(st)<3:
    return 0
  else:
    st3=st[1:]
    co3=count2(st3)
    if int(st)%2019==0:
      return co3+1
    else:
      return co3

a=input()
print(count1(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a=

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
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: Runtime Error

Solution code:
#include <iostream>

using namespace std;

int main()
{
    string str;
    int n,i,j,count=0,h;
    cin >> str;
    //cout << str;
    n = str.length();
    //cout << n;
    for(i=0;i<n;i++){
        h = str[i] - 48;
        //cout << str[i] << " " << h << " " <<i << endl;
        for(j=i+1;j<n;j++){
            h = h*10 + int(str[j]) - 48;
            //cout << h << endl;
            if(h%2019==0) count+=1;
        }
    }
   cout << count;
   return 0;
}

Submission status: Runtime Error

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])
        cnt += 1
#         if num % 2019 == 0:
#             cnt += 1
n_2019 = s_n[s_n % 2019 == 0]
print(len(n_2019))

Submission status: Runtime Error

Solution code:
s = input()
ans = 0
sss = []
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    sss.append(a)
    
sssss = set(sss)
for i in sssss:
  if int(sssss[i]) % 2019 == 0:
    ans += 1
      
      
print(ans)

Submission status: Runtime Error

Solution code:
import sys

def main():
    N=sys.stdin.readline()
    ans=0
    mathlen=len(str(N))
    strN=str(N)
    for i in range(mathlen):
        j=i+1
        while j<mathlen+1:
            if int(strN[i:j])%2019==0:
                ans+=1
            j+=1
        #i+=1
        #print(i)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s = input()

ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
s=sys.stdin.readline()
c=0
for i in range(0,len(s)-4):
    for j in range(i+3,len(s)):
        if int(s[i:j+1])%2019==0:
            c+=1
print(c

Submission status: Runtime Error

Solution code:
S = input()
l = [i*2019 for i in range(1,200000) if i*2019 <= 200000]
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: Runtime Error

Solution code:
from functools import reduce

def di(i, lst=[]):
    if i > 0:
        lst.append(i%10)
        return di(i//10, lst)
    else:
        lst.reverse()
        return lst
N=int(input())
N=di(N)
m=len(N)
q=0
if m<4:
  print(0)
if m==4:
  G=[]
  for j in range(4):
    G.append(N[j])
  a = reduce( lambda a,b:10*a+b, G)
  if a%2019==0:
    print(1) 
if m==5:
  Q=[]
  R=[]
  A=[]
  for i in range(4):
    Q.append(N[i])
  n = reduce( lambda a,b:10*a+b, Q)
  if n%2019==0:
    q=q+1
    
  for j in range(4):
    R.append(N[j+1])
  a = reduce( lambda a,b:10*a+b, R)
  if a%2019==0:
    q=q+1
  
  for i in range(5):
    A.append(N[i])
  n = reduce( lambda a,b:10*a+b, A)
  if n%2019==0:
    q=q+1    
  print(q)
  
if m==6:
  B1=[]
  B2=[]
  B3=[]
  B4=[]
  B5=[]
  B6=[]
  
  for i in range(4):
    B1.append(N[i])
  n = reduce( lambda a,b:10*a+b, B1)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B2.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B2)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B3.append(N[i+2])
  n = reduce( lambda a,b:10*a+b, B3)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B4.append(N[i])
  n = reduce( lambda a,b:10*a+b, B4)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B5.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B5)
  if n%2019==0:
    q=q+1 
  for i in range(6):
    B6.append(N[i])
  n = reduce( lambda a,b:10*a+b, B6)
  if n%2019==0:
    q=q+1   
  print(q)

Submission status: Runtime Error

Solution code:
def main():
  s = []
  s.append(int(input()))
  hui = len(s)
  
  counter = 0
  
  for i in range(hui):
    for j in range(hui):
      
      if int(''.join(map(str, s[i:j]))) % 2019 == 0:
        counter +=1
        break
        
  print(counter)
        
main()

Submission status: Runtime Error

Solution code:
s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


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

if 0 in ref:
    ans += ref_cnt[0]

print(ans)

Submission status: Runtime Error

Solution code:
s=list(input())
l=len(s)
ans=0
for i in range(l-3):
    sum_keta=int(s[i])
    num=s[i]
    index=i+1
    while sum_keta<=100:
        num+=s[i+j]
        if int(num)%2019==0:
            ans+=1
        index+=1
        sum_keta+=int(s[i+j])
        if l-1<index:
            break
print(ans)

Submission status: Runtime Error

Solution code:
S =input()
count =0
for i in range(len(S)):
    for j in range(len(S)):
        num= S[i]
        for k in range(i+1,j+1):
            num+=S[k]
        n=int(num)
        if n ==2019*int(n / 2019) :
            count=count+1
print(count)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
s = input()

m = []

for i in range(1,100):
	m.append(str(2019*i))


cnt = 0


for i in m:
	for k in range(len(s)):
		if s[k:K;1] == i[0:1]:
			if  i == s[k:k+len(i)]:
				# print(i,s[k:k+len(i)])
				cnt += 1

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s = input()
ans = 0
S =[]
for i in range(len(s)):
  for j in range(len(s)):
    a = s[i:i+j+2]
    S.append(a)
sa = set(S)
for i in range(len(se)):
  if int(sa[i]) % 2019 == 0:
    ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
moji = input()
suji = int(moji)
counter = 0
l4 = {2019,4038,6057,8076}
l5 = {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}
l6 = {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,201900,203919,205938,207957,209976,211995,214014,216033,218052,220071,222090,224109,226128,228147,230166,232185,234204,236223,238242,240261,242280,244299,246318,248337,250356,252375,254394,256413,258432,260451,262470,264489,266508,268527,270546,272565,274584,276603,278622,280641,282660,284679,286698,288717,290736,292755,294774,296793,298812,300831,302850,304869,306888,308907,310926,312945,314964,316983,319002,321021,323040,325059,327078,329097,331116,333135,335154,337173,339192,341211,343230,345249,347268,349287,351306,353325,355344,357363,359382,361401,363420,365439,367458,369477,371496,373515,375534,377553,379572,381591,383610,385629,387648,389667,391686,393705,395724,397743,399762,401781,403800,405819,407838,409857,411876,413895,415914,417933,419952,421971,423990,426009,428028,430047,432066,434085,436104,438123,440142,442161,444180,446199,448218,450237,452256,454275,456294,458313,460332,462351,464370,466389,468408,470427,472446,474465,476484,478503,480522,482541,484560,486579,488598,490617,492636,494655,496674,498693,500712,502731,504750,506769,508788,510807,512826,514845,516864,518883,520902,522921,524940,526959,528978,530997,533016,535035,537054,539073,541092,543111,545130,547149,549168,551187,553206,555225,557244,559263,561282,563301,565320,567339,569358,571377,573396,575415,577434,579453,581472,583491,585510,587529,589548,591567,593586,595605,597624,599643,601662,603681,605700,607719,609738,611757,613776,615795,617814,619833,621852,623871,625890,627909,629928,631947,633966,635985,638004,640023,642042,644061,646080,648099,650118,652137,654156,656175,658194,660213,662232,664251,666270,668289,670308,672327,674346,676365,678384,680403,682422,684441,686460,688479,690498,692517,694536,696555,698574,700593,702612,704631,706650,708669,710688,712707,714726,716745,718764,720783,722802,724821,726840,728859,730878,732897,734916,736935,738954,740973,742992,745011,747030,749049,751068,753087,755106,757125,759144,761163,763182,765201,767220,769239,771258,773277,775296,777315,779334,781353,783372,785391,787410,789429,791448,793467,795486,797505,799524,801543,803562,805581,807600,809619,811638,813657,815676,817695,819714,821733,823752,825771,827790,829809,831828,833847,835866,837885,839904,841923,843942,845961,847980,849999,852018,854037,856056,858075,860094,862113,864132,866151,868170,870189,872208,874227,876246,878265,880284,882303,884322,886341,888360,890379,892398,894417,896436,898455,900474,902493,904512,906531,908550,910569,912588,914607,916626,918645,920664,922683,924702,926721,928740,930759,932778,934797,936816,938835,940854,942873,944892,946911,948930,950949,952968,954987,957006,959025,961044,963063,965082,967101,969120,971139,973158,975177,977196,979215,981234,983253,985272,987291,989310,991329,993348,995367,997386,999405}

for l in range(0,len(moji)-4):
    if int(moji[l])*1000+int(moji[l+1])*100+int(moji[l+2])*10+int(moji[l+3]) in l4:
        counter += 1
    if int(moji[l])*10000+int(moji[l+1])*1000+int(moji[l+2])*100+int(moji[l+3])*10+int(moji[l+4]) in l5:
        counter += 1
    if int(moji[l])*100000+int(moji[l+1])*10000+int(moji[l+2])*1000+int(moji[l+3]) in l6:
        counter += 1
if int(moji[-5])*10000+int(moji[-4])*1000+int(moji[-3])*100+int(moji[-2])*10*int(moji[-1]) in l5:
  counter += 1
if int(moji[-4])*1000+int(moji[-3])*100+int(moji[-2])*10+int(moji[-1]) in l4:
  counter += 1
print(counter)

Submission status: Runtime Error

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

s = ns()
b = [0]
k = 0
n = 0
for i in range(len(s), reversed=True):
    n += s[i]*(10**k)
    n%=2019
    b.append(n)
    k+=1

import collections

c = collections.Counter(b)
ans = 0

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

print(ans)

Submission status: Runtime Error

Solution code:
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		long ans = 0;
		long[][] dp = new long[N+1][2019];
		for(int i = 1; i <= N; i++) {
			int s = Character.getNumericValue(S.charAt(i-1));
			dp[i][s] += 1;
			for(int j = 0; j < 2019; j++) {
				dp[i][(j*10+s)%2019] += dp[i-1][j];
			}
			ans += dp[i][0];
		}
		System.out.println(ans);
	}

}

Submission status: Runtime Error

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

skip_num = []

if n < 4:
    print('0')
else:
    cnt = 0
    for j in range(n-3):
        if j in skip_num:
            continue

        i = 0
        skip_add = 0
        while i < n-3-j:
            step = int(s[n-4-i-j:n-j])
            if step % 2019 == 0:
                skip_num.append(j+3)
                cnt += 1+skip_add
                skip_add += 1
                i += 3
            i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
S=input()
A=0
while len(S)>3:
    SL_sum=SL.copy()
    for i in range(1, len(SL_sum)):
        SL_sum[i] += SL_sum[i-1]
    for i in range(len(SL_sum)):
        if SL_sum[i]%3 == 0 :
            if int(S[:i+1])%673 ==0 :
                A+=1
    S=S[1:]
    SL=SL[1:]
print(A)

Submission status: Runtime Error

Solution code:
def mapint_inp():
    return map(int, input().split())

def intinp():
    return int(input())

S = input()
N = len(S) # 2*(10**5)


from collections import deque

ans = 0
fisrt_4cahr = S[:4]
rest_s = S[4:]
l = [fisrt_4cahr]

for c in rest_s:
    l.append(l[-1]+c)
Q = deque(l)
while Q:
    temp = Q.popleft()
    if not temp:
        break
    if int(temp)%2019==0:
        ans += 1
    if len(temp) != 4:
        Q.append(temp[1:])

print(ans)

Submission status: Runtime Error

Solution code:
def strToInt(s:list):
    l = len(s)
    tmp = ""
    for i in range(l):
        tmp += s[i]
    return int(tmp)

s = list(input())
l = len(s)
i = 0
j = 1
cnt=0
for i in range(l-1):
    for j in range(i,l):
        if int(strToInt(s[i:j]))%2019 == 0:
            cnt += 1

Submission status: Runtime Error

Solution code:
S = input()
count = 0
for i in range(len(S)-3):
    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: Runtime Error

Solution code:
s= int(input())

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

cnt =0
for i in List:
    b=int(i[0])
    e=int(i[1])
    
    if (int(s[b:e+1])%2019)==0:
        cnt +=1
  
    

print(cnt)

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    # si = tuple(int(c) for c in s)  # integers of one digit
    # ms = {2019 * x for x in range(10 ** 200000 - 1 // 2019)}
    ans = 0
    lg = len(si)
    # to slice till the last letter, +1 is needed.
    for i in range(lg + 1):
        for j in range(i + 4, lg + 1):
            j2 = j
            # 2019 = 673 * 3
            # if sum(si[i:j2]) % 3 != 0:
            #     continue
            if int(s[i:j2]) % 2019 == 0:
                ans += 1

    return ans


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

Submission status: Runtime Error

Solution code:
s = input()
n = 2019
ma = int(int(s)/n)

c = 0
for i in range(1, ma+1):
    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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    s = input()
    m = int(s) // 2019 / 10 ** 5
    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: Runtime Error

Solution code:
S = str(input())
n = len(S)

l = 0
r = 4
rem_div_3 = int(S[:r+1]) % 3
cnt = 0

while True:
    if rem_div_3 == 0:
        num = int(S[l:r+1])
        if num % 673 == 0:
            cnt += 1
    if r - l == 4: 
        if r == n - 1:
            break
        else:
            rem_div_3 = (rem_div_3 + int(S[r+1])) % 3
            r += 1
            
    else:
        rem_div_3 = (rem_div_3 - int(S[l])) % 3
        l += 1

print(cnt)

Submission status: Runtime Error

Solution code:
s=input()

ans=0
l=0
r=3
i=0
while True:
    if r>len(s):
        if ans==0:
            i+=1
            l=i
            r=i+3
        else:
            break
    a=int(s[l:r])
    if a%2019==0:
        ans+=1
        l=r-1
        r+=3
    else:
        r+=1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
f_can = itertools.combinations(range(len(str(N))+1),2)
s_can = [str(N)[int(f), int(b)] for f,b in f_can if int(b)-int(f)>3]
print(len([i for i in s_can if int(i)%2019==0]))

Submission status: Runtime Error

Solution code:
from functools import reduce

def di(i, lst=[]):
    if i > 0:
        lst.append(i%10)
        return di(i//10, lst)
    else:
        lst.reverse()
        return lst
N=int(input())
N=di(N)
m=len(N)
q=0
if m<5:
  print(0)
if m==5:
  Q=[]
  R=[]
  A=[]
  for i in range(4):
    Q.append(N[i])
  n = reduce( lambda a,b:10*a+b, Q)
  if n%2019==0:
    q=q+1
    
  for j in range(4):
    R.append(N[j+1])
  a = reduce( lambda a,b:10*a+b, R)
  if a%2019==0:
    q=q+1
  
  for i in range(5):
    A.append(N[i])
  n = reduce( lambda a,b:10*a+b, A)
  if n%2019==0:
    q=q+1    
  print(q)
  
if m==6:
  B1=[]
  B2=[]
  B3=[]
  B4=[]
  B5=[]
  B6=[]
  
  for i in range(4):
    B1.append(N[i])
  n = reduce( lambda a,b:10*a+b, B1)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B2.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B2)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B3.append(N[i+2])
  n = reduce( lambda a,b:10*a+b, B3)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B4.append(N[i])
  n = reduce( lambda a,b:10*a+b, B4)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B5.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B5)
  if n%2019==0:
    q=q+1 
  for i in range(6):
    B6.append(N[i])
  n = reduce( lambda a,b:10*a+b, B6)
  if n%2019==0:
    q=q+1   
  print(q)

Submission status: Runtime Error

Solution code:
s=list(input())
s.reverse()
sa=0
sum_2019=0
sum_2019_list=[]
for i in range(0,len(s),1):
    for j in range(i+3,len(s)):
        sum_2019=0
        for k in range(i,j+1):
            sa=k-i
            sum_2019+=int(s[k])*10**sa
            if(sum_2019%2019==0):
                sum_2019_list.append(sum_2019)
                
    if(len(s)==i+3):
        break
print(len(list(set(sum_2019_list)))

Submission status: Runtime Error

Solution code:
a=str(input())
ans=0
b=[]
for i in range(len(a)-3):
  for j in range(i+3,len(a)+1):
    b.append(a[i:j])
c=list(map(int,b))
for k in c:
  if k%2019==0:
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
cnt = 0

if len(s) > 4:
    for i in range(len(s)-4):
        for j in range(i+4, len(s)):
            s_a = s[i:j+1]

            if int(float(s_a))%2019 == 0:
                cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import sys
n = sys.stdin.readline().strip()
cnt = 0
def f(k):
  global cnt
  t = 1
  i = 0
  while i <= len(n)-k:
    temp = int(n[i:k]) 
    temp %= 2019
    if temp == 0:
      cnt += 1
    for c in range(len(n)-k-i):
      temp = (temp*t*10 + int(n[k+c])) % 2019
      if temp == 0:
        cnt += 1
      t += 1
    if (temp*10 + int(n[-1])) % 2019== 0:
      cnt += 1
    i += 1

a = 4
while a <= len(n):
  f(a)
  a += 1
print(cnt)

Submission status: Runtime Error

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

S = list(input())
tmp = 0
result = 0
for p in range(0, len(S) - 3):
    for q in range(p + 3, len(S)):
        if q == p + 3:
            tmp = int(''.join(S[p:q + 1]))
        else:
            tmp = tmp * 10 + int(S[q])
        if tmp % 2019 == 0:
            result += 1
            
print(result)

Submission status: Runtime Error

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

#n = int(input())
#l = list(map(int, input().split()))
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

s = input().rstrip("\n")
j=0
cnt=0
flg=True
if len(s)<=4:
    flg=False
    if int(s)%2019==0:
        print("1")
    else:
        print("0")
        
if flg:
    for i in range(len(s)):
        #print(s[-i-1:])
        if int(s[-i-1:])%2019==0:
            cnt+=1
            j-=i
            break
    #print(cnt)
    for i in range(-j,len(s)):
        #print(-i-1,j)
        if int(s[-i-1:j])%2019==0:
            cnt+=1
            j=-i
    print(cnt)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
package main
import "fmt"
import "strconv"
func main(){
	var n string
	fmt.Scan(&n)
	var count int = 0
	var n_len int = len(n)
	for cut_length:=3; cut_length <= n_len ;cut_length++{
		for first:=0 ; first < n_len - cut_length ;first++{
			var tem string = n[first:first + cut_length+1]
			var cuted_num int
			cuted_num, _ = strconv.Atoi(tem)
//			fmt.Println(tem)
			if cuted_num % 2019 == 0 {
				count++
			}
		}
	}  
	fmt.Println(count)
}

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
N = input()
count = 0
for i in range(len(N) - 3):
    for a in range(len(N)-3):
        if N[i:i+4+a][0:1] == "0":
            break
        print(int(N[i:i+4+a]))
        b = int(N[i:i+4+a]) / 2019
        if b.is_integer() and not b == 0.0:
            count += 1
        if i+4+a == len(N):
            break
print(count)

Submission status: Runtime Error

Solution code:
import sys
s=sys.stdin.readline
c=0
for i in range(0,len(s)-4):
    for j in range(i+3,len(s)):
        if int(s[i:j+1])%2019==0:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
s=input()
n=len(s)
N=[0]*2020
x=0
for i in reversed(range(n)):
    x+=int(s[i])*(10**(n-i-1))
    N[x%2019]+=1
ans+=N[0]
for j in N:
    ans+=j*(j-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import sys

n = [None]*100
s = input()
ans = 0

for i in range(1000000):
    n[i] = str(2019*(i))

for i in range(1000000):
    if n[i] in s:
        ans +=1
        print(n[i])

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
S=int(input())
K=len(str(S))
lst= [x for x in list(str(S))]
A=[[0 for v in range(2019)] for j in range(2019)]
A[int(lst[0])][0]+=1
for i in range(1,K):
 c=int(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: Runtime Error

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

Submission status: Runtime Error

Solution code:
from functools import reduce

def di(i, lst=[]):
    if i > 0:
        lst.append(i%10)
        return di(i//10, lst)
    else:
        lst.reverse()
        return lst
N=int(input())
N=di(N)
m=len(N)
q=0
if m<5:
  print(0)
if m==5:
  Q=[]
  R=[]
  A=[]
  for i in range(4):
    Q.append(N[i])
  n = reduce( lambda a,b:10*a+b, Q)
  if n%2019==0:
    q=q+1
    
  for j in range(4):
    R.append(N[j+1])
  a = reduce( lambda a,b:10*a+b, R)
  if a%2019==0:
    q=q+1
  
  for i in range(5):
    A.append(N[i])
  n = reduce( lambda a,b:10*a+b, Q)
  if n%2019==0:
    q=q+1    
  print(q)
  
if m==6:
  B1=[]
  B2=[]
  B3=[]
  B4=[]
  B5=[]
  B6=[]
  
  for i in range(4):
    B1.append(N[i])
  n = reduce( lambda a,b:10*a+b, B1)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B2.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B2)
  if n%2019==0:
    q=q+1    
  for i in range(4):
    B3.append(N[i+2])
  n = reduce( lambda a,b:10*a+b, B3)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B4.append(N[i])
  n = reduce( lambda a,b:10*a+b, B4)
  if n%2019==0:
    q=q+1 
  for i in range(5):
    B5.append(N[i+1])
  n = reduce( lambda a,b:10*a+b, B5)
  if n%2019==0:
    q=q+1 
  for i in range(6):
    B6.append(N[i])
  n = reduce( lambda a,b:10*a+b, B6)
  if n%2019==0:
    q=q+1   
  print(q)

Submission status: Runtime Error

Solution code:
import sys

n = [None]*100
s = input()
ans = 0

for i in range(1000000):
    n[i] = str(2019*(i+1))

for i in range(1000000):
    if n[i] in s:
        ans +=1
        print(n[i])

print(ans)

Submission status: Runtime Error

Solution code:
import os, sys, atexit
from io import BytesIO, StringIO
 
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
 
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def countSubStr(str, l, k): 
    count = 0
  
    for i in range(l): 
        n = 0
  
        # Take all sub-strings starting from i 
        for j in range(i, l, 1): 
            n = n * 10 + (ord(str[j]) - ord('0')) 
  
            # If current sub-string is divisible by k 
            if (n % k == 0): 
                count += 1
      
    # Return the required count 
    return count 
  
# Driver code 
if __name__ == '__main__': 
    str = input()
    l = len(str) 
    k = 2019
    print(countSubStr(str, l, k))

Submission status: Runtime Error

Solution code:
for i in range(len(a)):
    if int(a[-1])  in [1,4,5,6,8,9]:

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

    a = a[:-1]

print(count)

Submission status: Runtime Error

Solution code:
import sys

n = [None]*100
s = input()
ans = 0

for i in range(1000000000):
    n[i] = str(2019*(i+1))

for i in range(1000000000):
    if n[i] in s:
        ans +=1
        print(n[i])

print(ans)

Submission status: Runtime Error

Solution code:
import os, sys, atexit
from io import BytesIO, StringIO
 
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
 
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
    
def countSubStr(str, l, k): 
    count = 0
  
    for i in range(l): 
        n = 0
  
        # Take all sub-strings starting from i 
        for j in range(i, l, 1): 
            n = n * 10 + (ord(str[j]) - ord('0')) 
  
            # If current sub-string is divisible by k 
            if (n % k == 0): 
                count += 1
      
    # Return the required count 
    return count 
  
# Driver code 
if __name__ == '__main__': 
    str = input()
    l = len(str) 
    k = 2019
    print(countSubStr(str, l, k))