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: Wrong Answer

Solution code:
def main():
    S = input()
    n = len(S)
    p = 2019 # 法p
    # (1) a≡b,c≡dならばa+c≡b+d
    # (2) aと法pが互いに素である時、ab≡acならばb≡c
    # ex).S=1817181712114(idxは最下位が0とする), n=len(S)
    # 4≡4%p <- modp[0]
    # 14=10+4≡10%p+modp[0] <- modp[1]
    # 114=100+14≡100%p+modp[1] <- modp[2]
    # 2114=2000+114≡2000%p+modp[2] <- modp[3]
    # ...
    # 1817181712114≡100000000000%p+modp[n-2] <- modp[n-1]
    # したがって、S[1:4]=21%pについては
    # 2100=2114-14≡modp[3]-modp[1]
    # ここでaとpが互いに素なので(a=100,p=7)
    # 2100≡21 が言える
    # よって21≡modp[3]-modp[1]
    # 一般化すると、
    # S[i:j+1]≡modp[j]-modp[i]
    # すなわちmodp[j]==modp[i]となるi,jを選んだ時、S[i:j+1]はpで割り切れるという事になる

    # Sをreverseする
    S = [S[i] for i in range(n-1,-1,-1)]
    # modpを作成
    modp_counter = [0 for _ in range(p)]
    modp_tmp = int(S[0])%p
    modp_counter[modp_tmp] = 1
    pair_count = 0
    for i in range(1,n):
        modp = (int(S[i])*pow(10,i)%p+modp_tmp)%p
        modp_tmp = modp
        pair_count += modp_counter[modp]
        modp_counter[modp] += 1
    print(pair_count)


main()

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
si=int(s)
mod=2019
from collections import defaultdict
t=defaultdict(lambda:0)
for i in range(n):
    si-=int(s[i])*pow(10,n-1-i,mod)
    t[si%mod]+=1
ans=0
for v in t.values():
    ans+=(v*(v-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
n=len(s)
si=int(s)
mod=2019
from collections import defaultdict
t=defaultdict(lambda:0)
for i in range(n):
    si-=int(s[i])*pow(10,n-1-i)
    t[si]+=1
ans=0
for v in t.values():
    ans+=(v*(v-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
res = 0
sum = 0
c = {}
c[0] = 1
p = 1
for i in range(n - 1, -1, -1):
    sum = (sum + int(s[i]) * p) % 2019
    if sum in c:
        res += 1
    p = (p * 10) % 2019
    c[sum] = 1

print(res)

Submission status: Wrong Answer

Solution code:
def function(S):
    S = S[::-1]
    mods = [0]*2019 # mod 2019の余り0~2018の数
    
    # MEMO : int(c) * 10^n % 2019 をまともに計算するとTLE
    # １つ前の桁のmodを利用する
    num = 0
    digit = 1
    for c in S:
        num = (int(c) * digit + num) % 2019
        digit = (digit * 10) % 2019
        mods[num] += 1
    
    result = 0
    for m in mods:
        result +=  m * (m-1) // 2

    return str(result)

if __name__ == '__main__':
    print(function(input()))

Submission status: Wrong Answer

Solution code:
def function(S):
    S_num = int(S)
    digit = len(S)
    multiple = 2019
    
    # make mod 2019 for each digit
    # 12114 -> 100
    # 2114 -> 2109
    # 114 -> 114
    mods = [0]*2019 # mod 2019の余り0~2018の数
    
    # MEMO : int(c) * 10^n % 2019 をまともに計算するとTLE
    # １つ前の桁のmodを利用する
    num = 0
    digit = 1
    for c in S:
        num = (int(c) * digit + num) % 2019
        digit = (digit * 10) % 2019
        mods[num] += 1
    
    result = 0
    for m in mods:
        result +=  m * (m-1) // 2

    return str(result)

if __name__ == '__main__':
    print(function(input()))

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = input()
ans = 0
for i in range(2019, 200000, 2019):
    if s.count(str(i)) >0:
        ans += len(re.findall("(?=(%d))" % i, s))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


ans = 0
for i in range(l - 3):
  for j in range(4 + i, l+1):
    b = ''
    a = s[i:j]
    print(a)
    if int(a) % 2019 == 0:
      ans = ans + 1
      print('ue')

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
S = (input())
A = deque([0])
cnt = deque([0]*2019)
n = 0
t = 1
for i in reversed(S):
    x = int(i)
    n += x*t
    A.append(n%2019)
    cnt[n%2019] += 1
    t *= 10
cnt2 = [i*(i-1)//2 for i in cnt]
print(sum(cnt2))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    return (10**(x%224))%2019
def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0 and i!=n-1:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return ((10**q)*mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return (mod10(q)*mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
s=input()
n=len(s)
def mod10(x):
    p=x//100
    q=x%100
    if p==0:
        return (10**q)%2019
    return (mod10(q)+mod10(p))%2019


def T(i):
    if i==n-1:
        return int(s[n-1])
    return T(i+1)+10**(n-1-i)*int(s[i])
dict={}
def modi(i,dict):
    if i in dict.keys():
        return dict[i]
    else:
        if i==n-1:
            dict[i]=int(s[i])
            return int(s[i])
        else:
           # c=modi(i+1,dict)+(10**(n-1-i)*int(s[i]))
            c=modi(i+1,dict)+(mod10(n-1-i)*int(s[i]))
            c=c%2019
            dict[i]=c
            return c

modnum={}
for i in range(n):
    #print(T(i))
    if int(s[i])==0:
        continue
    x=modi(i,dict)
 #   print(T(i),x)
    if x not in modnum.keys():
        modnum[x]=1
    else:
        modnum[x]+=1
sum=0
for md in modnum.keys():
    a=modnum[md]
    if md==0:
        sum+=a
        sum+=-(a*(a-1)//2)
   # print(a*(a-1)//2)
    sum+=a*(a-1)//2
#print(modnum)
print(sum)

Submission status: Wrong Answer

Solution code:
S = str(input())

Tmod = []

for i in range(len(S)):
    T = int(S[i:len(S)])
    Tmod.append(T % 2019)

out  = 0
for j in range(2019):
    count = 0
    for k in range(len(S)):
        if(Tmod[k] == j):
            count += 1
    out += (count*(count - 1))/2.0


print(int(out))

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
s = list(map(int,s))
s_mod =[0]
mod = 0
for i in range(len(s)):
    a = s[len(s) - 1- i]* (10**i)
    mod += a
    mod = mod % 2019
    s_mod.append(mod)
print(s_mod)
s_values = list(collections.Counter(s_mod).values())
print(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
s = list(map(int,s))
s_mod =[]
mod = 0
for i in range(len(s)):
    mod += s[len(s)-i-1]*(10**i)
    mod = mod % 2019
    s_mod.append(mod)
s_values = list(collections.Counter(s_mod).values())
print(s_mod)

print(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))

Submission status: Wrong Answer

Solution code:
import collections
s = list(input())
s = list(map(int,s))
s_mod =[]
for i in range(len(s)):
    mod = s[i]*10**i % 2019
    s_mod.append(mod)
s_values = list(collections.Counter(s_mod).values())
print(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))

Submission status: Wrong Answer

Solution code:
import collections
s_str = input()
s = [int(s_str[i]) for i in range(len(s_str))] #リスト型に文字列を格納します
n = len(s_str)
s_block = []
for k in range(n):
    a = sum(s[i]*10**(n-i-1) for i in range(k,n)) % 2019
    s_block.append(a)
s_dict = list(dict(collections.Counter(s_block)).values())
ans = sum(s_dict[i]*(s_dict[i]-1)/2 for i in range(len(s_dict)))
print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target += int(N_S[N_len-1-i])*tmp
  Target = Target % 2019
  tmp = tmp * 10 % 2019
  MOD_N[N_len-1-i] = Target 

c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target += (int(N_S[N_len-1-i])%2019)*tmp
  Target %= 2019
  tmp = tmp * 10 % 2019
  MOD_N[N_len-1-i] = Target 
  
c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target += int(N_S[N_len-1-i])*tmp
  Target %= 2019
  tmp = tmp * 10 % 2019
  MOD_N[N_len-1-i] = Target 
  
c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target += int(N_S[N_len-1-i])*tmp
  Target %= 2019
  tmp = tmp * 10 % 2019
  MOD_N[N_len-1-i] = Target 
  
print(MOD_N)
c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    input1 = input()
    S = str(input1)
    result = 0
    search = '0'
    for i in range(99):
        search = str(2019*(i+1))
        if len(S) < len(str(2019*(i+1))):
            break
        for j in range(len(S)-len(search)+1):
            if S[j:(j+(len(search)))] == search:
                result += 1
    
    print(result)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*N_len
Target = 0
tmp = 1

for i in range(N_len):
  Target = Target + int(N_S[N_len-1-i])*tmp 
  tmp = tmp * 10
  MOD_N[N_len-1-i] = Target % 2019 
  
c = collections.Counter(MOD_N)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N_S = input()
N = int(N_S)
N_len = len(N_S)
MOD_N = [0]*len(N_S)

for i in range(N_len):
  MOD_N[i] = int(N_S[i:N_len]) % 2019
  
c = collections.Counter(MOD_N)
print(c)

Key = list(c.keys())
Num = list(c.values())
M = len(Key)
ans = 0

for i in range(M):
  if Key[i] == 0:
    ans += Num[i]
  else:
    ans += Num[i] * (Num[i] - 1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
S = input()

mods = []
for i in range(len(S)):
    mod = int(S[i:]) % 2019
    mods.append(mod)

cnt = len(mods) - len(set(mods))
print(cnt)

Submission status: Wrong Answer

Solution code:
# 1 ~ 200000
s = input()

ans = 0
dp = []

for i in range(len(s)):
  # print(i, s[:i+1])
  dp.append(s[:i+1])

for end_ in range(len(dp)):
  for start_ in range(end_):
    # print("{}番目".format(start_ + 1), "~", "{}番目".format(end_ + 1))
    # print(str(dp[end_])[start_:end_])

    if int( str(dp[end_])[start_:end_] ) % 2019 == 0:
      ans += 1
      # print(start_, end_)

print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
dp = [0]*2019
dp[0]+=1

p=0
q=1
for i in reversed(range(len(S)-1)):
  p = (p+int(S[i])*q)%2019
  q = q*10%2019
  dp[p]+=1

c=0
for j in dp:
  c += j*(j-1)//2
print(c)

Submission status: Wrong Answer

Solution code:
import collections

S=input()
S_int = int(S)
mods_count = collections.Counter([int(S[i:])%2019 for i in range(len(S))])
count = 0
for mod in mods_count:
  c = mods_count[mod]
  if c > 1:
    count += c*(c-1)//2
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
S = int(input())

d = defaultdict(int)
d[0] = 1

for i in range(len(str(S))+1):
    print(S % (10**i))
#     t = int(S[-i:])
#     d[t % 2019] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

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

d = defaultdict(int)
d[0] = 1

for i in range(1, len(S)+1):
    print(i)
#     t = int(S[-i:])
#     d[t % 2019] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

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

d = defaultdict(int)
d[0] = 1

for i in range(1, len(S)+1):
    t = int(S[-i:])
#     d[t % 2019] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2
print(ans)

Submission status: Wrong Answer

Solution code:
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+9,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data) - 1):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())

data = []

count = 0
for i in range(len(S)):
    for j in range(i+4, min(i+7,len(S)+1)):
        if(int(S[i:j]) % 2019 == 0):
            count += 1
            data.append([i,j])

for i in range(len(data) - 1):
    if(data[i][1] == data[i+1][0]):
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
S = str(input())


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

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
src=[0]*2019
ans=0
pre=0
for s in range(len(S)):
  x=int(S[-(s+1)])*(10**s)+pre
  a=x%2019
  src[a]+=1
  pre+=x
  ans+=src[a]-1
print(ans+src[0])

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

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

M = 1
while 10 ** length > 2019 * M:
    M = M + 1
print(M)

#M2019 = []
#for i in range(1,M+1):
#    M2019.append(2019*i)
#print(M2019)

count = 0
for j in range(M):
    if str(2019 * (j + 1)) in S:
        count = count + 1
    else:
        continue

print(count)

Submission status: Wrong Answer

Solution code:
S=input()
ans=0
a=0
b=3
if len(S)<4:
  print(0)
else:
  while True:
    if S[a]==0:
      continue
    if int(S[a:b])%2019==0:
      ans+=1
    b+=1
    if b==len(S)+1:
      a+=1
      b=a+3
    if a==len(S)-3:
      break
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
ans=0
a=0
b=3
if len(S)<4:
  print(0)
else:
  while True:
    if int(S[a:b])%2019==0:
      ans+=1
    b+=1
    if b==len(S)+1:
      a+=1
      b=a+3
    if a==len(S)-3:
      break
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC164d
def main():
    s = input()
    MOD = 2019
    d = [ 0 for i in range(MOD)]
    # print(d)
    ans = 0
    k = 0
    d[0] = 1
    s = s[::-1]
    # print(s)
    p = 1
    for i in s:
        print(p,i,k)
        print('pnosiki')
        print(p * int(i) + k)
        k = (p * int(i) + k) % MOD
        print('k:')
        print(k)
        ans += d[k]
        d[k] += 1
        p = (p * 10) % MOD
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
counter=[0]*2019
for i in range(len(s)):
    num=int(s[i:])
    counter[num%2019]+=1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

t=0
x=1
ans=0
cnt=[0]*2019

for i in s:
    t += int(i)*x
    t %= 2019
    x *= 10
    x %= 2019
    cnt[t]+=1

for i in cnt:
    ans +=i*(i-1)//2

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n_list = [0]*(len(s)+1)
res, d = 0, 1
for i in range(len(s)-1, -1, -1):
    res = (res + int(s[i])*d)%2019
    d = (d*10)%2019
    n_list[len(s)-i-1] = res
n_list.sort()
res, ans, count = 0, 0, 1
for i in range(1, len(s)+1):
    if res == n_list[i]:
        count += 1
    else:
        if count >= 2: ans += count*(count-1)//2
        res, count = n_list[i], 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n_list = [0]*(len(s)+1)
res, d = 0, 1
for i in range(len(s)-1, -1, -1):
    res = (res + int(s[i])*d)%2019
    d = (d*10)%2019
    n_list[len(s)-i] = res
n_list.sort()
res, ans, count = 0, 0, 1
for i in range(1, len(s)+1):
    if res == n_list[i]:
        count += 1
    else:
        if count >= 2: ans += count*(count-1)//2
        res, count = n_list[i], 1
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n_list = [0]*(len(s)+1)
res, d = 0, 1
for i in range(len(s)-1, -1, -1):
    res = (res + int(s[i])*d)%2019
    d *= 10
    n_list[len(s)-i] = res
n_list.sort()
res, ans, count = 0, 0, 1
for i in range(1, len(s)+1):
    if res == n_list[i]:
        count += 1
    else:
        if count >= 2: ans += count*(count-1)//2
        res, count = n_list[i], 1
print(ans)

Submission status: Wrong Answer

Solution code:
cand_ls = [str(2019*(i+1)) for i in range(99)]
target_ls = [e for e in cand_ls if "0" not in e]
target_dic = {e: 1 for e in target_ls}

s = input()
cnt = 0
for i in [4,5,6]:
	for j in range(len(s)-i+1):
		search_s = s[j:j+i]
		if search_s in target_dic:
			cnt += 1
 
print(cnt)

Submission status: Wrong Answer

Solution code:
target_dic = {str(2019*(i+1)): 1 for i in range(99)}

s = input()
cnt = 0
for i in [4,5,6]:
	for j in range(len(s)-i+1):
		search_s = s[j:j+i]
		if search_s in target_dic:
			cnt += 1

print(cnt)

Submission status: Wrong Answer

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

ans = 0
mods = [0]
s = [int(a) for a in s[::-1]]
x = 0
for i in range(len(s)):
    x += s[i] * pow(10, i, 2019)
    mods.append(x%2019)

mods = Counter(mods)

for k in mods.keys():
    counts = mods[k]
    ans += counts // 2
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
mod_list = [0]*2019
for i in range(n-1, -1, -1):
  t = int(s[i:])
  mod_list[t%2019]+= 1
count = 0
for k in range(2019):
  count += mod_list[k] * (mod_list[k]-1)//2
print(k)

Submission status: Wrong Answer

Solution code:
N = input()
dic = {}
a = 0
bef = 0
ten = 1
for i in range(len(N)):
  num = int(N[len(N) - i -1]) % 2019#各桁取り出し
  bef = (num * ten + bef) % 2019
  #print(bef)
  dic.setdefault(bef, 0)
  dic[bef] += 1
  ten *= 10
  ten % 2019
"""for k, v in dic.items():
  if k != 0:
    if v != 1:
      a += v * (v - 1) / 2
  else:
    a += v * (v + 1) / 2"""
print(int(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S = input()
N = len(S)
rS = S[::-1]

cum = [0] * (N+1)
for i in range(N):
    cum[i+1] = (cum[i] + (int(rS[i]) * pow(10,i,2019)) % 2019) % 2019

ans = 0
from collections import Counter
c = Counter(cum)
for v in c.values(): ans += v-1

print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
ans = 0
for i in range(1,int(200000/2019)+1):
    if str(2019*i) in n:
        times = sum(1 for x in range(len(n)) if n[x:].startswith(str(2019*i)))
        ans += times
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) * math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) * math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current % 2019
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10 % 2019

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def comb_count(n, r):
    return math.factorial(n) // math.factorial(r) * math.factorial(n - r)

S = input()[::-1]
ans = 0

mods = [0] * 2019 #余りが0~2018
mods[0] = 1
current = 0
tmp = 1

for i in range(len(S)):
    current = int(S[i]) * tmp + current % 2019
    mod = current % 2019
    mods[mod] += 1
    tmp = tmp * 10

for mod in mods:
    if mod > 1:
        ans += comb_count(mod, 2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)


S = readChar()

res = [0]*len(S)
res[-1]=int(S[-1])

d = defaultdict(int)

for i in range(2,len(S)+1):
	re = int(S[i*-1])*pow(10,i-1,2019)
	res[i*-1] = (res[i*-1+1]+re)%2019
	d[res[i*-1]]+=1

ans = d[0]
for key in d:
	if d[key]>1:
		ans+=comb(d[key],2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)


S = readChar()

res = [0]*len(S)
res[-1]=int(S[-1])

d = defaultdict(int)

for i in range(2,len(S)+1):
	re = int(S[i*-1])*pow(10,i-1,2019)
	d[(res[i*-1+1]+re)%2019]+=1

ans = d[0]
for key in d:
	if d[key]>1:
		ans+=comb(d[key],2)

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = input()
moji = len(s)
count = 0
for i in range(moji):
    if i < 4 or i > 6: continue
    start = 0
    end = i
    while end < moji:
        end = end + 1
        num = int(s[start:end])
        if num % 2019 == 0:
            count += 1
        start = start + 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
from collections import defaultdict
import math
import copy
#input = sys.stdin.readline
sys.setrecursionlimit(20000000)
s = input()
s = s[::-1]
n = len(s)
dp = [0]*(n+1)
k = 1
a = defaultdict(int)
a[0]+=1
for i in range(n):
  dp[i] = (dp[i-1]+int(s[i])*k)%2019
  k*=10
  k%=2019
  a[dp[i]] += 1
ans = 0
for i in a.keys():
  ans += a[i]*(a[i]-1)/2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
count = 0
for i in range(0,round(len(s)/2)):
    for j in range(i+3,len(s)):
        #print(i, j, s[len(s)-j:len(s)-1])
        print(i, j, s[i:j+1])
        if int(s[i:j+1]) % 2019  == 0:
            count += 1
        if int(s[len(s)-j:len(s)-i]) % 2019  == 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
def main():

    #test()
    S = input()
    
    comb = count(S)
    print(len(comb))

def test():
    from datetime import datetime
    import numpy as np
    print(datetime.now())
    S = "".join((str(s[0]) for s in np.random.randint(0,9, [100000, 1])))
    print(S)
    a = count(S)
    print(datetime.now())
    print(a)

def count(S, div=2019):

    intS = int(S)
    divs = []
    i, x = 1, div

    length = len(str(div))
    while True:
        x = div * i
        if len(str(x)) >= length * 2:
            break
        divs.append(x) 
        i += 1
        
    pairs = set()

    for div in divs:
        sdiv = str(div)
        start = 0
        while True:
            i = S.find(sdiv, start)
            if i < 0:
                break
            j = i + len(sdiv)
            pairs.add((i, j))
            start = i + 1
    
    comb = pairs
    pre_result = 0
    while True:
        new_comb = set()
        for pair in pairs:
            i, j = pair
            k = 1
            while True:
                if j+k >= len(S):
                    break
                if S[j+k] == "0":
                    new_comb.add((i, j+k))
                    k += 1
                else:
                    break
            for div in divs:
                sdiv = str(div)
                if sdiv == S[j+1:j+1+length]:
                    new_comb.add((i,j+1+length))
                    
        comb |= new_comb
        result = len(comb)
        if pre_result == result:
            break
        pre_result = result
    
    return comb
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()

n = len(S)

medalist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * mods) % 2019
    medalist[num] = medalist[num] + 1
    mods = (mods * 10)

result = 0
if medalist[0] > 0:
    result += 1

for i in range(2019):
    m = medalist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))

Submission status: Wrong Answer

Solution code:
S = input()

n = len(S)

medalist = [0] * 2019
num = 0
mods = 1

for i in range(n):
    fig = int(S[n - i - 1])
    num = (num + fig * mods) % 2019
    medalist[num] = medalist[num] + 1
    mods = (mods * 10) % 2019

result = 0
if medalist[0] > 0:
    result += 1

for i in range(2019):
    m = medalist[i]
    if m != 0:
        result += m * (m - 1) / 2

print(int(result))