problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p02702 | u597455618 | 2,000 | 1,048,576 | 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. | ['import sys\n\ns = str(sys.stdin.buffer.readline().rstrip())\nc = [2019*i for i in range(1, 100)]\nans = 0\n\nfor i in range(99):\n if str(c[i]) in s:\n ans += s.count(str(c[i]))\n\nprint(ans)', 'import re\nimport sys\n\ns = sys.stdin.buffer.readline().rstrip().decode()\nans = 0\n\nfor i in range(len(s) - 3):\n for j in range(i, len(s)):\n if int(s[i: j+i])%2019 == 0:\n ans += 1\nprint(ans)\n', 'import sys\n\ns = sys.stdin.buffer.readline().rstrip().decode()\nMOD = 2019\nans = [1] + [0 for i in range(MOD)]\nt = 1\nr = 0\nfor i in reversed(s):\n r = (r + int(i)*t) % MOD\n t = t*10%2019\n ans[r] += 1\nprint(sum([m*(m-1)//2 for m in ans]))\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s380111478', 's625280864', 's928899318'] | [8948.0, 10156.0, 9344.0] | [51.0, 30.0, 104.0] | [191, 209, 244] |
p02702 | u597622207 | 2,000 | 1,048,576 | 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. | ['s = input()\nresult = 0\n\nfor i in range(int(s)//2019):\n b = (i+1) * 2019\n result += s.count(str(b))\n\nprint(result)', 's = input()[::-1]\n\n\ncnts = [0] * 2019\ncnts[0] = 1\nmod_num = 0\nd = 1\n\nfor c in s:\n t = d * int(c)\n mod_num += t\n mod_num %= 2019\n cnts[mod_num] += 1\n d *= 10\n d %= 2019\n\nresult = 0\nfor cnt in cnts:\n result += cnt * (cnt - 1) // 2\n\nprint(result)'] | ['Time Limit Exceeded', 'Accepted'] | ['s886576177', 's128492207'] | [9520.0, 9268.0] | [2206.0, 120.0] | [115, 305] |
p02702 | u609061751 | 2,000 | 1,048,576 | 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. | ['import sys\ninput = sys.stdin.readline\nmod = 2019\ns = input().rstrip()\nn = len(s)\nmod_list = [0]\nfor i in range(n - 1, -1, -1):\n print(s[i])\n mod_list.append((mod_list[-1] + int(s[i]) * 10**(n - 1 - i) ) % mod)\nfrom collections import Counter\nc = Counter(mod_list)\nans = 0\nfor i in c.keys():\n ans += c[i] * (c[i] - 1) // 2\nprint(ans)\n\n\n\n', 'import sys\ninput = sys.stdin.readline\nmod = 2019\ns = input().rstrip()\nn = len(s)\nmod_list = [0]\nfor i in range(n - 1, -1, -1):\n mod_list.append((mod_list[-1] + int(s[i]) * pow(10, n - 1 - i, mod)) % mod)\nfrom collections import Counter\nc = Counter(mod_list)\nans = 0\nfor i in c.keys():\n ans += c[i] * (c[i] - 1) // 2\nprint(ans)\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s687452555', 's273474616'] | [9980.0, 16716.0] | [2206.0, 348.0] | [345, 336] |
p02702 | u612223903 | 2,000 | 1,048,576 | 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. | ['import collections\ns = list(input())\ns = list(map(int,s))\ns_mod =[]\nfor i in range(len(s)):\n mod = s[i]*10**i % 2019\n s_mod.append(mod)\ns_values = list(collections.Counter(s_mod).values())\nprint(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))', 'import collections\ns = list(input())\ns = list(map(int,s))\ns_mod =[]\nmod = 0\nfor i in range(len(s)):\n mod += s[len(s)-i-1]*(10**i)\n mod = mod % 2019\n s_mod.append(mod)\ns_values = list(collections.Counter(s_mod).values())\nprint(s_mod)\n\nprint(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))', 'import collections\ns = list(input())\ns = list(map(int,s))\ns_mod =[0]\nmod = 0\nfor i in range(len(s)):\n a = s[len(s) - 1- i]* (10**i)\n mod += a\n mod = mod % 2019\n s_mod.append(mod)\nprint(s_mod)\ns_values = list(collections.Counter(s_mod).values())\nprint(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))', 'import collections\ns_str = input()\ns = [int(s_str[i]) for i in range(len(s_str))] \nn = len(s_str)\ns_block = []\nfor k in range(n):\n a = sum(s[i]*10**(n-i-1) for i in range(k,n)) % 2019\n s_block.append(a)\ns_dict = list(dict(collections.Counter(s_block)).values())\nans = sum(s_dict[i]*(s_dict[i]-1)/2 for i in range(len(s_dict)))\nprint(int(ans))', 'S = input()\nn = len(S)\ndp = {0:1}\nq = 1\np = 0\nfor i in range(n):\n p += int(S[n-1-i])*q\n q *= 10\n q = q % 2019\n p = p % 2019\n if p not in dp:\n dp[p] = 1\n else:\n dp[p] += 1\nprint(sum(dp[i]*(dp[i]-1)//2 for i in dp))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s159648083', 's728352517', 's896722271', 's934917951', 's546083583'] | [12372.0, 12456.0, 12528.0, 11620.0, 9316.0] | [2206.0, 2206.0, 2206.0, 2206.0, 156.0] | [271, 319, 333, 391, 245] |
p02702 | u614162316 | 2,000 | 1,048,576 | 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. | ['s=input()\ns=s[::-1]\na=1\nb=0\nt=[0]*2019\nans=0\nfor i in range(len(s)):\n b+=int(s[i])*a\n b%=2019\n ans+=t[b]\n t[b]+=1\n a*=10\n a%=2019\n\nprint(ans)', 's=input()\ns=s[::-1]\na=1\nb=0\nt=[0]*2019\nt[0]=1\nans=0\nfor i in range(len(s)):\n b+=int(s[i])*a\n b%=2019\n a*=10\n ans+=t[b]\n t[b]+=1\n a%=2019\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s029313806', 's106990625'] | [9340.0, 9340.0] | [135.0, 136.0] | [159, 166] |
p02702 | u616117610 | 2,000 | 1,048,576 | 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. | ['s = list(str(input()))\na = [0]\nb = [0]*2019\nfor num,i in enumerate(reversed(s)):\n a.append(a[num]+int(i)*10**num)\n b[(a[num]+int(i)*10**num)%2019] += 1\nans = 0\nfor i in b:\n ans += i*(i-1)//2\nprint(ans)', 's = list(str(input()))\nb = {}\nb[0] = 1\nc_ = 0\ns = s.reverse()\nfor i in s:\n c = (c_+int(i)*10**num)%2019\n if c in b:\n b[c] += 1\n else:\n b[c] = 1\n c_ = c\nans = 0\nfor i in b.values():\n ans += i*(i-1)//2\nprint(ans)', 's = input()\ns.reverse()\nMOD = 2019\na =[0]*MOD\na[0] = 1\nc_ = 0\nans = 0\nt = 1\nfor i in s:\n c = (c_+int(i)*t)%MOD\n a[c] += 1\n t *= 10\n t %= MOD\n c_ = c\nfor i in a:\n ans += i*(i-1)//2\nprint(ans)\n', 's = list(str(input()))\nb = {}\nb[0] = 1\nc_ = 0\nans = 0\ns.reverse()\nfor i in s:\n c = (c_+int(i))%2019\n if c in b:\n ans += b[c]\n b[c] += 1\n ans += \n else:\n b[c] = 1\n c_ = c\nprint(ans)', 's = input()\ns.reverse()\nMOD = 2019\nb = {}\na =[0]*MOD\na[0] = 1\nc_ = 0\nans = 0\nt = 1\nfor i in s:\n c = (c_+int(i)*t)%MOD\n b[c] += 1\n t *= 10\n t %= MOD\n c_ = c\nfor i in a:\n ans += i*(i-1)//2\nprint(ans)', 's = list(str(input()))\nb = {}\nb[0] = 1\nc_ = 0\nans = 0\ns.reverse()\nfor i in s:\n c = (c_+int(i))%2019\n if c in b:\n ans += b[c]\n b[c] += 1\n else:\n b[c] = 1\n c_ = c\nprint(ans)\n', 's = input()\nMOD = 2019\na =[0]*MOD\na[0] = 1\nc_ = 0\nans = 0\nt = 1\nfor i in reversed(s):\n c = (c_+int(i)*t)%MOD\n a[c] += 1\n t *= 10\n t %= MOD\n c_ = c\nfor i in a:\n ans += i*(i-1)//2\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s045839379', 's116847667', 's553124572', 's717839513', 's808639447', 's904843200', 's249292317'] | [53804.0, 10520.0, 9360.0, 9056.0, 9092.0, 10584.0, 9184.0] | [2207.0, 21.0, 23.0, 23.0, 23.0, 125.0, 114.0] | [204, 221, 197, 196, 203, 185, 194] |
p02702 | u616534089 | 2,000 | 1,048,576 | 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. | ['n = input()\nl = len(n)\nmod = [0]*2019\nmod[0] += 1\n\nfor i in range(l):\n a = int(n[i:]) % 2019\n mod[a] += 1\n\nres = 0 \nfor m in mod:\n res += m*(m-1)/2\nprint(res)\n', 'n = input()\nl = len(n)\nmod = [0]*2019\nmod[0] += 1\nT = 0\nd = 1 \nfor i, s in enumerate(Sr):\n T += int(s) * d\n T %= 2019\n d = (d * 10) % 2019\n \nres = 0 \nfor m in mod:\n res += m*(m-1)/2\nprint(int(res))\n', 'l = len(n)\ncount = 0\nfor i in range(l-3):\n x = 0\n for j in range(i+3, l):\n if j == i+3:\n x = int(n[i]) + int(n[i+1]) + int(n[i+2]) + int(n[i+3])\n else:\n x += int(n[j])\n \n if x % 3 != 0:\n continue\n else:\n integer = int(n[i:j+1])\n if integer % 2019 == 0:\n count += 1\nprint(count)\n', 's = input()\nsr = s[::-1]\nmod = [0]*2019\nmod[0] += 1\nT = 0\nd = 1 \nfor s in sr:\n T = T + int(s) * d\n T %= 2019\n mod[T] += 1\n d = (d * 10) % 2019\n \nres = [m*(m-1)//2 for m in mod]\nprint(sum(res))\n\n \n\n \n\n '] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s455459856', 's744469129', 's822208935', 's724702691'] | [9256.0, 9360.0, 8984.0, 9292.0] | [2206.0, 24.0, 24.0, 109.0] | [163, 212, 327, 211] |
p02702 | u620868411 | 2,000 | 1,048,576 | 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. | ['def f(s):\n pl = [str(2019*i) for i in range(1,51000)]\n res = 0\n for p in pl:\n res += s.count(p)\n # start = 0\n \n # while pos>=0:\n # res += 1\n \n \n return res\n\nif __name__ == "__main__":\n print(f(input()))', 'from collections import defaultdict\ns = input()\nn = len(s)\n\nd = defaultdict(int)\nd[0] = 1\nx = 0\nb = 1\nfor i in range(n-1,-1,-1):\n x += b*int(s[i])\n x %= 2019\n d[x] += 1\n\n b *= 10\n b %= 2019\n\nres = 0\nfor k in d:\n c = d[k]\n res += c*(c-1)//2\nprint(res)\n'] | ['Wrong Answer', 'Accepted'] | ['s676450898', 's700722946'] | [13036.0, 9648.0] | [2206.0, 128.0] | [343, 272] |
p02702 | u624617831 | 2,000 | 1,048,576 | 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. | ['s = str(input())[::-1]\n\ntmp_amari = [0]*2019\n\n#amari = 0\nnum = 0\norder = 1\nfor i in s:\n num += int(i)*order\n num %= 2019\n #print(num)\n tmp_amari[num] += 1\n order *= 10\n\n\n#print(tmp_print)\n\nans = 0\nans += tmp_amari[0]\n\nfor i in tmp_print:\n ans += (i*(i-1))//2\n\nprint(ans)\n', 's = str(input())[::-1]\n\ntmp_amari = [0]*2019\n\n#amari = 0\nnum = 0\norder = 1\nfor i in s:\n num += int(i)*order\n num %= 2019\n #print(num)\n tmp_amari[num] += 1\n order *= 10\n order %= 2019\n #print(order)\n\ntmp_print = [i for i in tmp_amari if i > 0]\n#print(tmp_print)\n\nans = 0\nans += tmp_amari[0]\n\nfor i in tmp_print:\n ans += (i*(i-1))//2\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s836069222', 's902505699'] | [9372.0, 9352.0] | [2206.0, 111.0] | [333, 368] |
p02702 | u629454253 | 2,000 | 1,048,576 | 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. | ['import collections\ns = input()\n\nl = [int(s[-1])]\nd = 1\nfor i in range(len(s)-1, -1, -1):\n print(i)\n l.append((l[-1] + int(s[i])*d) % 2019)\n d *= 10\n d %= 2019\n\nd = collections.Counter(l)\ncount = 0 \nfor i in d:\n count += d[i]*(d[i]-1)//2\n\ncount += d[0]\n\nprint(count)', 's = input()\ncount = 0\n\nl = [int(s[i:]) % 2019 for i in range(len(s))]\nd = {}\n\nfor i in l:\n d[i] = d.get(i, 0) + 1\n \nfor i in d:\n count += d[i]*(d[i]-1)//2\n\nprint(count)', 'import collections\ns = input()\n\nl = [int(s[-1])]\nd = 10\nfor i in range(len(s)-2, -1, -1):\n l.append((l[-1] + int(s[i])*d) % 2019)\n d *= 10\n d %= 2019\nc = collections.Counter(l)\nans = 0 \nfor i in c.values():\n ans += i*(i-1)//2\n\nans += c[0]\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s430646949', 's472501647', 's789092858'] | [16980.0, 9528.0, 16580.0] | [200.0, 2205.0, 132.0] | [271, 171, 255] |
p02702 | u638033979 | 2,000 | 1,048,576 | 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. | ['from collections import deque\ns = deque(input())\nn = len(s)\n\ntemp = [0]*2019\nt = 1\nnum = 0\nfor i in range(n):\n num += int(s.pop())*t % 2019\n temp[num] += 1\n t *= 10\n\nans = temp[0]\nfor t in temp:\n if t > 1:\n ans += t*(t-1)/2\n\nprint(int(ans))', 'from collections import deque\ns = deque(input())\nn = len(s)\n\ntemp = [0]*2019\nt = 1\nnum = 0\nfor i in range(n):\n num += int(s.pop())*t \n temp[num % 2019] += 1\n t = t*10 % 2019 \n\nans = temp[0]\nfor t in temp:\n if t > 1:\n ans += t*(t-1)/2\n\nprint(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s027286594', 's002085092'] | [11096.0, 10920.0] | [24.0, 119.0] | [259, 269] |
p02702 | u638282348 | 2,000 | 1,048,576 | 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. | ['from math import log10\nfrom collections import Counter\nS = int(input())\nl = int(log10(S)) + 1\nprint(sum(n * (n - 1) // 2 for n in Counter((S := S % 10 ** (l - i)) % 2019 for i in range(l + 1)).values()))\n', 'from collections import Counter\nl = len(S := input())\ncounts = Counter((n := (n + (d := d * 10 % 2019) * int(S[-i])) % 2019 if i else (n := 0 * (d := 202)) for i in range(l + 1)))\nprint(sum(n * (n - 1) // 2 for n in counts.values()))\n'] | ['Runtime Error', 'Accepted'] | ['s971329433', 's265947482'] | [8908.0, 9652.0] | [25.0, 115.0] | [204, 234] |
p02702 | u642668851 | 2,000 | 1,048,576 | 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. | ['s=input()\na=0\nm={}\nfor i in range(len(s)):\n b=int(s[len(s)-1-i])*10**i+a\n b=b%2019\n a=b\n if b in m:\n m[b]+=1\n else:\n m[b]=1\nsum=0\nfor i in m:\n sum+=m[i]*(m[i]-1)/2\nprint(int(sum))', 's=input()\na=0\nm={}\nd=1\nfor i in range(len(s)):\n b=int(s[len(s)-1-i])*d+a\n b=b%2019\n a=b\n d=d*10%2019\n if b in m:\n m[b]+=1\n else:\n m[b]=1\nif 0 in m:\n sum=m[0]\nelse:\n sum=0\nfor i in m:\n sum+=m[i]*(m[i]-1)/2\nprint(int(sum))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s830085587', 's948714279'] | [9312.0, 9380.0] | [2205.0, 169.0] | [191, 237] |
p02702 | u645487439 | 2,000 | 1,048,576 | 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. | ['s = input()[::-1]\nd = 1\nnum = 0\nmod_list = [0] * 2019\n\nfor char in s:\n num += int(char) * d\n num %= 2019\n d *= 10\n d%= 2019\n counts[num] += 1\n\nans = mod_list[0]\nfor cnt in range(1, 2019):\n ans += mod_list[cnt] * (mod_list[cnt] - 1) // 2\n\nprint(ans)\n', 's = input()[::-1]\nd = 1\nnum = 0\nans = 0\nmod_list = [0] * 2019\nmod_list[0] = 1\n\nfor char in s:\n num += int(char) * d\n mod_list[num % 2019] += 1\n d *= 10\n d %= 2019\n\nfor i in range(2019):\n ans += mod_list[i] * (mod_list[i] - 1) //2\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s464515124', 's705913698'] | [9336.0, 9212.0] | [20.0, 108.0] | [267, 257] |
p02702 | u646412443 | 2,000 | 1,048,576 | 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. | ['s = input()[::-1]\nm = 2019\nans = 0\nx = 1\ntot = 0\ncnt = [0] * m\nfor s in s:\n cnt[tot] += 1\n tot += int(s) * x\n tot %= m\n \n x *= 10\n x %= m\n\nprint(sum(i*(i-1)//2 for i in cnt))\n', 's = input()[::-1]\nmod = 2019\ncnt = [0] * mod\nx = 1\ncnt[0] = 1\ntotal = 0\nfor s in s:\n total = int(s) * x\n total %= mod\n cnt[total] += 1\n x *= 10\n\nans = sum(i*(i-1)//2 for i in cnt)\nprint(ans)\n', "s = input()\nnum = ['2019', '4038', '6057', '8076', '10095', '12114', '14133', '16152', '18171']\nans = 0\nfor n in num:\n a += s.count(n)\nprint(ans)\n", 's = input()[::-1]\nmod = 2019\ncnt = [0] * mod\nx = 1\ncnt[0] = 1\ntotal = 0\nfor s in s:\n total += int(s) * x\n total %= mod\n cnt[total] += 1\n x *= 10\n x %= mod\n\n\nans = sum(i*(i-1)//2 for i in cnt)\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s394865991', 's724649930', 's781034898', 's571114423'] | [9364.0, 9412.0, 9280.0, 9200.0] | [114.0, 2206.0, 22.0, 119.0] | [209, 203, 149, 218] |
p02702 | u652656291 | 2,000 | 1,048,576 | 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. | ['s = input()\nans = 0\nif int(s) < 2019 :\n print(0)\nelse:\n for i in range(len(s)-3):\n for j in range(4,len(s)):\n a =s[i:j+1]\n if int(a) % 2019 == 0:\n ans += 1\n \nprint(ans)', 's = input()\nL = [s[i] for i in range(len(s))]\nans = 0\n\nfor j in range(0,len(L)-3):\n for k in range(3,len(L)):\n a = int(L[j:k+1])\n if a % 2019 == 0:\n ans += 1\nprint(ans)\n \n', 's = input()\nans = 0\nS =[]\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n S.append(a)\nsa = set(S)\nfor i in range(len(se)):\n if int(sa[i]) % 2019 == 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\nfor i in range(0,len(s)-3):\n for j in range(3,len(s)):\n a = int(s[i:j+1])\n if a % 2019 == 0:\n ans += 1\nprint(ans)\n \n', 's = input()\nans = 0\n\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n if int(a) % 2019 == 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\nsss = []\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n sss.append(a)\n \nsssss = set(sss)\nfor i in sssss:\n if int(sssss[i]) % 2019 == 0:\n ans += 1\n \n \nprint(ans)\n', 's = input()\nans = 0\nL = [2019*k for k in range(10*10)]\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n if int(a) in L and int(a) != 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\n\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j]\n if int(a) % 2019 == 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j]\n if int(a) % 2019 == 0:\n ans += 1\n\nprint(ans)', 's = input()\nans = 0\n\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j]\n if int(a) % 2019 == 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\naf = 0\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+3]\n if len(a) <= 200000:\n af = 0\n else int(a) % 2019 == 0:\n ans += 1\n\nprint(ans)\n', 's = input()\nans = 0\nif int(s) < 2019:\n print(0)\nelse:\n for i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n if int(a) % 2019 == 0:\n ans += 1\n print(ans)\n\n', 's = input()\nans = 0\nfor i in range(0,len(s)-2):\n for j in range(3,len(s)+1):\n a = s[i:j+1]\n if a%2019 == 0:\n ans += 1\nprint(ans)\n \n', 's = input()\nans = 0\n\nfor i in range(len(s)):\n for j in range(len(s)):\n a = s[i:i+j+2]\n if int(a) % 2019 == 0 and len(a) >= 4:\n ans += 1\n\nprint(ans)\n', 'def main():\n S = input()\n u = 0\n H = [0] * 2019\n H[0] = 1\n m = 1\n r = 0\n for s in reversed(S):\n u = (u + m * int(s)) % 2019\n r += H[u]\n H[u] += 1\n m = (m * 10) % 2019\n return r\n\n\nprint(main())\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s147767563', 's159617446', 's245738840', 's376879182', 's379153641', 's475145632', 's551871829', 's563925802', 's624435385', 's646955261', 's682844133', 's880227944', 's900254917', 's958763450', 's339648654'] | [9264.0, 10688.0, 3567520.0, 9224.0, 9204.0, 3568232.0, 9332.0, 9232.0, 9016.0, 9104.0, 9036.0, 9212.0, 9336.0, 9388.0, 9040.0] | [2206.0, 31.0, 2095.0, 2206.0, 2205.0, 2083.0, 2205.0, 20.0, 19.0, 20.0, 18.0, 2205.0, 23.0, 2206.0, 89.0] | [197, 197, 202, 162, 144, 224, 187, 142, 134, 142, 190, 190, 157, 160, 245] |
p02702 | u653837719 | 2,000 | 1,048,576 | 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. | ['s = input()\nl = len(s)\nd = [[0] * 2020 for i in range(l + 1)]\n\nfor i in range(0, l):\n d[i + 1] = d[i][int(s[i]):] + d[i][:int(s[i])]\n d[i + 1][int(s[i])] += 1\n d[i + 1][2019] += d[i][2019] + d[i + 1][0]\n\nprint(d[l][2019])', 's = input()\nl = len(s)\nt = [0] * l\nt[l - 1] = int(s[l - 1])\nm = [0] * 2019\nten = 10\nans = 0\n\nfor i in range(l - 1, 0, -1):\n t[i - 1] = (t[i] + int(s[i - 1]) * ten) % 2019\n ten = ten * 10 % 2019\n ans += m[t[i - 1]]\n m[t[i - 1]] += 1\n if t[i - 1] == 0:\n ans += 1\n\nprint(t, ans)', 's = input()[::-1]\nc = [0] * 2019\nc[0] = 1\nmod = 0\nten = 1\nans = 0\n\nfor i in s:\n mod = (mod + int(i) * ten) % 2019\n ten = ten * 10 % 2019\n c[mod] += 1\n\nfor i in c:\n ans += i * (i - 1) // 2\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s783367741', 's792926553', 's794197403'] | [1382352.0, 18592.0, 9236.0] | [2244.0, 196.0, 101.0] | [230, 297, 211] |
p02702 | u657994700 | 2,000 | 1,048,576 | 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. | ["from collections import Counter\n\n# print('input >>')\n\nS = input()\nS = S[::-1]\n\nmods = [0] * (len(S)+1)\nmods[0] = int(S[0]) % 2019\n\nfor i in range(len(mods)-1-1):\n mods[i+1] = (int(S[i+1]) * 10 ** (i+1) + mods[i]) % 2019\n\n# print(mods)\n\n# ans = 0\n\n# counter = Counter(mods)\n\n# for n in counter.values():\n# if n > 1:\n# ans += (n * (n-1)) // 2\n\n# print('-----output-----')\n\nprint(ans)", "from collections import Counter\n\n# print('input >>')\n\nS = input()\nS = S[::-1]\n\nmods = [0] * (len(S)+1)\nmods[0] = int(S[0]) % 2019\n\nfor i in range(len(mods)-1-1):\n mods[i+1] = (int(S[i+1]) * 10 ** (i+1) % 2019 + mods[i]) % 2019\n\nprint(mods)\n\nans = 0\n\ncounter = Counter(mods)\n\nfor c, n in counter.most_common():\n if n > 1:\n ans += (n * (n-1)) // 2\n\n# print('-----output-----')\n\nprint(ans)", "from collections import Counter\n\n# print('input >>')\n\nS = input()\nS = S[::-1] + '0'\n\nmod = 0\nmods = [0] * 2019\nmods[0] += 1\n\ni_mod = 1\n\nfor i in range(len(S)-1):\n # mods[i+1] = (int(S[i+1]) * 10 ** (i+1) + mods[i]) % 2019\n i_mod %= 2019\n mod = (int(S[i]) * i_mod + mod) % 2019\n # print(mod)\n mods[mod]+=1\n i_mod *= 10\n\n# print(mods)\n\nans = 0\n\n# counter = Counter(mods)\n\n# for n in counter.values():\n# if n > 1:\n# ans += (n * (n-1)) // 2\n\n# print('-----output-----')\n\nfor m in mods:\n if m > 1:\n ans += (m * (m-1)) // 2\n\nprint(ans)"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s198136086', 's501714641', 's750917938'] | [11496.0, 11588.0, 9584.0] | [2206.0, 2206.0, 117.0] | [396, 399, 569] |
p02702 | u658447090 | 2,000 | 1,048,576 | 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. | ['S = input()[::-1]\n\n\ncounts = [0]*2019\n\ncounts[0] = 1\n\nnum, d = 0, 1\n\nfor c in s:\n \n num += int(c) * d\n num %= 2019\n \n \n d *= 10\n #d %= 2019\n \n counts[num] += 1\n \nans = 0\nfor cnt in counts:\n \n ans += cnt * (cnt-1) //2\n \nprint(ans)', 'S = input()[::-1]\n \n\ncounts = [0]*2019\n\ncounts[0] = 1\n \nnum, d = 0, 1\n \nfor c in S:\n \n num += int(c) * d\n num %= 2019\n \n \n d *= 10\n d %= 2019\n \n counts[num] += 1\n \nans = 0\nfor cnt in counts:\n \n ans += cnt * (cnt-1) //2\n \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s470915437', 's032035241'] | [9292.0, 9264.0] | [22.0, 109.0] | [347, 349] |
p02702 | u673922428 | 2,000 | 1,048,576 | 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. | ['#A,B,C,D=map(int,input().split(" "))\n\nimport collections\n\nmod=2019\na=input()\n\nN=len(a)\nt=[]\nans=0\n\nfor i in range(N):\n u=int(a[i::])\n v=u % mod\n t.append(v)\n \ntt = collections.Counter(t)\nfor i in tt.values():\n #print(i)\n if i==0:\n ans+=1\n else:\n ans += (i-1)*i//2\nprint(ans)', '#A,B,C,D=map(int,input().split(" "))\n\nmod=2019\na=input()\n\nN=len(a)\nt=[]\nans=0\n\nfor i in range(N-2):\n for j in range(i+3,N+1):\n u=int(a[i:j])\n print(u)\n if (u % mod)==0:\n ans+=1\n #print(i+1,j)\n break\nprint(ans)\n', 'mod=2019\na=input()\n\nN=len(a)\nt=[0]*mod\nt[0]=1\n\nw=1\nu=0\n\nfor i in range(N):\n u=int(a[N-1-i]) * w + u\n v=u % mod\n t[v] += 1\n w *=10\n w %= mod\n\nans=0\nfor i in t:\n ans += (i-1)*i//2\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s051679963', 's721847195', 's283350587'] | [9888.0, 134644.0, 9376.0] | [2206.0, 2302.0, 138.0] | [287, 235, 195] |
p02702 | u674052742 | 2,000 | 1,048,576 | 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. | ['# -*- coding: utf-8 -*-\n"""\nCreated on Sun Apr 26 22:28:26 2020\n\n@author: Kanaru Sato\n"""\n\ns = input()\nn = len(s)\ndic = {}\nmod = 2019\ncount = 0\n\nfor i in range(1,n+1):\n num = int(s[n-i:n])\n num %= mod\n if num in dic:\n dic[num] += 1\n if num not in dic:\n dic[num] = 1\n\nans = 0\nfor fact in dic:\n ans += dic[fact]*(dic[fact]-1)/2\n\nprint(int(ans))', 's = input()\nn = len(s)\n\ncountdic = {}\nmod = 2019\n\nfor i in range(1,n+1):\n num = int(s[n-i:n])\n remainder = num\n if remainder in countdic:\n countdic[remainder] += 1\n if remainder not in countdic:\n countdic[remainder] = 1\n\nans = 0\nfor key in countdic:\n ans += countdic[key]*(countdic[key]-1)//2\n\nif 0 in countdic:\n ans += countdic[0]\n\nprint(ans)', 's = input()\nn = len(s)\ns = int(s)\n\ncountdic = {}\nmod = 2019\n\nfor i in range(1,n+1):\n num = s[n-i:n]\n remainder = num%mod\n if remainder in countdic:\n countdic[remainder] += 1\n if remainder not in countdic:\n countdic[remainder] = 1\n\nans = 0\nfor key in countdic:\n ans += countdic[key]*(countdic[key]-1)//2\n\nif 0 in countdic:\n ans += countdic[0]\n\nprint(ans)', 's = list(map(int, list(input())))\nn = len(s)\n\ncountdic = {}\nmod = 2019\n\nnum = 0\nfor i in range(1,n+1):\n num += s[n-i]*(10**(i-1))\n if num in countdic:\n countdic[num] += 1\n if num not in countdic:\n countdic[num] = 1\n\nans = 0\nfor key in countdic:\n ans += countdic[key]*(countdic[key]-1)//2\n\nif 0 in countdic:\n ans += countdic[0]\n\nprint(ans)', 's = input()\nn = len(s)\n\ncountdic = {}\nmod = 2019\n\nfor i in range(1,n+1):\n num = int(s[n-i:n])\n remainder = num%mod\n if remainder in countdic:\n countdic[remainder] += 1\n if remainder not in countdic:\n countdic[remainder] = 1\n\nans = 0\nfor key in countdic:\n ans += countdic[key]*(countdic[key]-1)//2\n if 0 in countdic:\n ans += countdic[0]\n\nprint(ans)', '# -*- coding: utf-8 -*-\n"""\nCreated on Sun Apr 26 22:28:26 2020\n\n@author: Kanaru Sato\n"""\n\ns = input()\nn = len(s)\ns = list(s)\ndic = {}\nmod = 2019\ncount = 0\n\nfor i in range(1,n+1):\n num = int(s[n-i:n])\n num %= mod\n if num in dic:\n count += 1\n if num not in dic:\n dic[num] = 1\n\nif 0 in dic:\n count += 1\n\nprint(count)', 's = list(map(int, list(input())))\nn = len(s)\n\ncountdic = {}\nmod = 2019\n\nnum = 0\nd = 1\nfor i in range(1,n+1):\n num += s[n-i]*d\n num %= mod\n if num in countdic:\n countdic[num] += 1\n if num not in countdic:\n countdic[num] = 1\n d = (10*d)%mod\n\nans = 0\nfor key in countdic:\n ans += countdic[key]*(countdic[key]-1)//2\n\nif 0 in countdic:\n ans += countdic[0]\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s037265435', 's287188708', 's358008534', 's558333385', 's625418201', 's626838773', 's757053527'] | [9264.0, 35868.0, 9284.0, 84480.0, 9324.0, 10468.0, 12268.0] | [2206.0, 2206.0, 203.0, 2208.0, 2206.0, 25.0, 152.0] | [371, 375, 385, 367, 386, 343, 397] |
p02702 | u678505520 | 2,000 | 1,048,576 | 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. | ['S = str(input())\ns = int(S)\nn = len(S)\ncount = 0\nfor i in range(1,n+1):\n for j in range(i+4,n+1):\n si = s%10**(n-i+1)\n sij = si//10**(n-j)\n if sij % 2019 == 0:\n count+=1\n i+=4\n j+=4\n\nprint(count)', 'S = str(input())\ns = int(S)\nn = len(S)\ncount = 0\nfor i in range(1,n+1):\n for j in range(i+4,n+1):\n si = s%10**(n-i+1)\n sij = si//10**(n-j)\n print(sij)\n if sij!= 0 and sij % 2019 == 0:\n count+=1\n\nprint(count)', 'S = str(input())\ns = int(S)\nn = len(S)\ncount = 0\nfor i in range(1,n+1):\n for j in range(i+4,n+1):\n si = s%10**(n-i+1)\n sij = si//10**(n-j)\n print(sij)\n if sij % 2019 == 0:\n count+=1\n i+=4\n j+=4\n\nprint(count)', 'from collections import Counter\n\ns = input()\na = [0]\nmod = 2019\n\nfor i,j in enumerate(s[::-1]):\n a.append(a[-1] + int(j)*pow(10,i,mod))\n a[-1] %= mod\nb = Counter(a)\n\nans = 0\nfor i in b.values():\n ans += i*(i-1)//2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s053989425', 's448045302', 's816745076', 's733468556'] | [9600.0, 9504.0, 9596.0, 16804.0] | [2206.0, 2206.0, 2206.0, 343.0] | [252, 249, 271, 233] |
p02702 | u679390859 | 2,000 | 1,048,576 | 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. | ['S = input()\nS = S[::-1]\nL = [0]\ni = 0\nfor x in S:\n tmp = L[-1] + 10 ** i * int(x) % 2019\n # print(tmp % 2019)\n L.append(tmp % 2019)\n i += 1\nL = sorted(L[1::])\ndef counter(array):\n from collections import Counter\n return list(Counter(array).most_common())\nc = counter(L)\nfrom math import factorial\ndef comb(n,r):\n if n == 1: return 0\n return return n * (n - 1) // \nans = 0\nfor x in c:\n if x[0] == 0: ans += x[1]\n ans += comb(x[1],2)\n#print(L,c)\nprint(int(ans))', 'S = input()\nS = S[::-1]\nL = [0]\ni = 0\nfor x in S:\n tmp = L[-1] + 10 ** i * int(x) % 2019\n # print(tmp % 2019)\n L.append(tmp % 2019)\n i += 1\nL = sorted(L[1::])\ndef counter(array):\n from collections import Counter\n return list(Counter(array).most_common())\nc = counter(L)\nfrom math import factorial\ndef comb(n,r):\n if n == 1: return 0\n return return n * (n - 1) // 2\nans = 0\nfor x in c:\n if x[0] == 0: ans += x[1]\n ans += comb(x[1],2)\n#print(L,c)\nprint(int(ans))', 'S = input()\nS = S[::-1]\nL = [0]\ni = 0\nfor x in S:\n tmp = L[-1] + pow(10, i , 2019) * int(x) \n L.append(tmp % 2019)\n i += 1\nL = sorted(L[1::])\ndef counter(array):\n from collections import Counter\n return list(Counter(array).most_common())\nc = counter(L)\nfrom math import factorial\ndef comb(n,r):\n if n == 1: return 0\n return n * (n - 1) // 2\nans = 0\nfor x in c:\n if x[0] == 0: ans += x[1]\n ans += comb(x[1],2)\nprint(int(ans))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s314518819', 's807232104', 's954526779'] | [9028.0, 8984.0, 20176.0] | [22.0, 21.0, 383.0] | [489, 490, 453] |
p02702 | u680851063 | 2,000 | 1,048,576 | 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. | ['s = input()\nnum = len(s)\nl = []\nfrom collections import deque\nl = deque(l) \n\nfor _ in range(1, 20190000):\n if _%2019 == 0:\n l.append(str(_))\nl = set(l)\n#print(l)\n\ndef aaa(s, num):\n x = 0\n for i in range(4,num+1):\n for j in range(num - i + 1):\n if s[j:j+i] in l:\n x += 1\n print(x)\n\naaa(s, num)', "from numba import jit\nimport numpy as np\n\n@jit\ndef solve():\n \n s = np.array(list(input())[::-1])\n num = len(s)\n #print(s, num)\n \n l = []\n for i in range(1,num+1):\n l.append(int(''.join(s[:i][::-1])))\n #print(l)\n l = np.array(l)\n mod = []\n for j in range(num):\n mod.append(l[j] % 2019)\n mod = np.array(mod)\n \n ans = 0\n for p in range(num):\n if mod[p] == 0:\n ans += 1\n tmp = 1\n for q in range(p+1,num):\n if mod[p] == mod[q]:\n tmp += 1\n ans += (tmp-1)*tmp//2\n \n print(ans)\n\nsolve()", "s = input()\nnum = len(s)\nl = []\nfrom collections import deque\nl = deque(l) \n\nfor _ in range(1, 20190000):\n if _%2019 == 0 and '0' not in str(_) :\n l.append(str(_))\nl = set(l)\n#print(l)\n\ndef aaa(s, num):\n x = 0\n for i in range(4,num+1):\n for j in range(num - i + 1):\n if s[j:j+i] in l:\n x += 1\n print(x)\n\naaa(s, num)", "from numba import jit\n\n@jit\ndef solve():\n \n s = list(input())[::-1]\n num = len(s)\n #print(s, num)\n \n l = []\n for i in range(1,num+1):\n l.append(int(''.join(s[:i][::-1])))\n #print(l)\n \n mod = []\n for j in range(num):\n mod.append(l[j] % 2019)\n #print(mod)\n \n ans = 0\n for p in range(num):\n if mod[p] == 0:\n ans += 1\n tmp = 1\n for q in range(p+1,num):\n if mod[p] == mod[q]:\n tmp += 1\n ans += (tmp-1)*tmp//2\n \n print(ans)\n\nsolve()", "from numba import jit\nimport numpy as np\n\n@jit\ndef solve():\n \n s = np.array(list(input())[::-1])\n num = len(s)\n #print(s, num)\n \n l = np.array([])\n for i in range(1,num+1):\n l.append(int(''.join(s[:i][::-1])))\n #print(l)\n \n mod = []\n for j in range(num):\n mod.append(l[j] % 2019)\n mod = np.array(mod)\n \n ans = 0\n for p in range(num):\n if mod[p] == 0:\n ans += 1\n tmp = 1\n for q in range(p+1,num):\n if mod[p] == mod[q]:\n tmp += 1\n ans += (tmp-1)*tmp//2\n \n print(ans)\n\nsolve()", 's = input()\nnum = len(s)\nl = []\nfrom collections import deque\nl = deque(l) \n\nfor _ in range(1, 20190000):\n if _%2019 == 0:\n l.append(_)\nl = set(l)\n#print(l)\n\ndef aaa(s, num):\n x = 0\n for i in range(4,num+1):\n for j in range(num - i + 1):\n if int(s[j:j+i]) in l:\n x += 1\n print(x)\n\naaa(s, num)', 's = input()\nnum = len(s)\n\nl = []\nfor _ in range(1, 20190000):\n if _%2019 == 0:\n l.append(_)\nl = set(l)\n#print(l)\n\ndef aaa(s, num):\n x = 0\n for i in range(4,num+1):\n for j in range(num - i + 1):\n if int(s[j:j+i]) in l:\n x += 1\n print(x)\n\naaa(s, num)', 's = input()[::-1]\n\ncnts = [1] + [0] * (2019 - 1)\ntmp = 0\nd = 1\n\nfor i in s:\n tmp += int(i) * d\n cnts[tmp % 2019] += 1\n d = d * 10 % 2019 \n\nans = 0\nfor cnt in cnts:\n ans += (cnt - 1) * cnt // 2\n\nprint(ans)'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s029042536', 's404528394', 's421934964', 's522261944', 's609376695', 's710830195', 's838409174', 's569935562'] | [10760.0, 124920.0, 10428.0, 128800.0, 120664.0, 10632.0, 10680.0, 9296.0] | [2206.0, 2209.0, 2206.0, 2209.0, 1209.0, 2206.0, 2206.0, 100.0] | [381, 608, 404, 556, 603, 381, 300, 358] |
p02702 | u684267998 | 2,000 | 1,048,576 | 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. | ["def main():\n S = input()[::-1]\n ans = 0\n mods = [0] * 2019\n mods[0] = 1\n current = 0\n x = 1\n for s in S:\n current = (current + x * int(s)) % 2019\n mods[current % 2019] += 1\n x = x * 10 % 2019\n \n for i in len(mods):\n ans += mods[i] * (mods[i]-1)//2\n print(ans)\nif __name__ == '__main__':\n main()", "def main():\n S = input()[::-1]\n ans = 0\n mods = [0] * 2019\n mods[0] = 1\n current = 0\n x = 1\n for s in S:\n current = (current + x * int(s)) % 2019\n mods[current % 2019] += 1\n x = x * 10 %2019\n \n for i in len(mods):\n ans += mods[i] * (mods[i]-1)//2\nprint(ans)\nif __name__ == '__main__':\n main()", "def main():\n S = input()[::-1]\n ans = 0\n mods = [0] * 2019\n mods[0] = 1\n current = 0\n x = 1\n for s in S:\n current = (current + x * int(s)) % 2019\n mods[current % 2019] += 1\n x = x * 10 %2019\n \n for i in len(mods):\n ans += mods[i] * (mods[i]-1)//2\n \nif __name__ == '__main__':\n main()", "def main():\n S = input()[::-1]\n ans = 0\n mods = [0] * 2019\n mods[0] = 1\n current = 0\n x = 1\n for s in S:\n current = (current + x * int(s)) % 2019\n mods[current % 2019] += 1\n x = x * 10 %2019\n \n for i in mods:\n ans += i*(i-1)//2\n print(ans)\nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s220349311', 's753543969', 's985071344', 's010109354'] | [9248.0, 9132.0, 9396.0, 9260.0] | [87.0, 22.0, 88.0, 87.0] | [355, 350, 341, 335] |
p02702 | u685983477 | 2,000 | 1,048,576 | 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. | ['from itertools import accumulate\nfrom collections import defaultdict\nS = list(input().rstrip())\nr = 1\ni=len(S)\nacc=0\ndd = defaultdict(int)\nfor s in S[::-1]:\n acc+=r*int(s)\n acc%=2019\n r%=2019\n r*=10\n dd[acc]+=1\n i-=1\nans=0\nfor i in dd.values():\n ans+=(i*(i-1))/2\nprint(ans)\n', 'from itertools import accumulate\nfrom collections import defaultdict\nS = list(input().rstrip())\nr = 1\ni=len(S)\nacc=0\ndd = defaultdict(int)\nfor s in S[::-1]:\n acc+=r*int(s)\n acc%=2019\n r%=2019\n r*=10\n dd[acc]+=1\n i-=1\nans=0\nfor i in dd.values():\n ans+=(i*(i-1))//2\nprint(ans)\n', 'from itertools import accumulate\nfrom collections import defaultdict\nS = list(input().rstrip())\nr = 1\ni=len(S)\nacc=0\ndd = defaultdict(int)\ndd[0]+=1\nfor s in S[::-1]:\n acc+=r*int(s)\n acc%=2019\n r*=10\n r%=2019\n\n dd[acc]+=1\nans=0\nfor i in dd.values():\n ans+=(i*(i-1))//2\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s478953558', 's641513353', 's350499569'] | [12600.0, 12448.0, 12440.0] | [143.0, 138.0, 128.0] | [295, 296, 297] |
p02702 | u696499790 | 2,000 | 1,048,576 | 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. | ["def function(S):\n S = S[::-1]\n mods = [0]*2019 \n \n \n \n num = 0\n digit = 1\n for c in S:\n num = (int(c) * digit + num) % 2019\n digit = (digit * 10) % 2019\n mods[num] += 1\n \n result = 0\n for m in mods:\n result += m * (m-1) // 2\n\n return str(result)\n\nif __name__ == '__main__':\n print(function(input()))\n", "def function(S):\n S_num = int(S)\n digit = len(S)\n multiple = 2019\n \n # make mod 2019 for each digit\n # 12114 -> 100\n # 2114 -> 2109\n # 114 -> 114\n mods = [0]*2019 \n \n \n \n num = 0\n digit = 1\n for c in S:\n num = (int(c) * digit + num) % 2019\n digit = (digit * 10) % 2019\n mods[num] += 1\n \n result = 0\n for m in mods:\n result += m * (m-1) // 2\n\n return str(result)\n\nif __name__ == '__main__':\n print(function(input()))\n", "def function(S):\n S = S[::-1]\n mods = [0]*2019 \n mods[0] += 1 \n \n \n num = 0\n digit = 1\n for c in S:\n num = (int(c) * digit + num) % 2019\n digit = (digit * 10) % 2019\n mods[num] += 1\n \n result = 0\n for m in mods:\n result += m * (m-1) // 2\n\n return str(result)\n\nif __name__ == '__main__':\n print(function(input()))\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s434414566', 's849663530', 's739744981'] | [9252.0, 9184.0, 9372.0] | [78.0, 262.0, 84.0] | [500, 637, 539] |
p02702 | u706330549 | 2,000 | 1,048,576 | 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. | ['s = input()\n\nmod = [0] * 2019\nmod[0] = 1\nd = 1\nn = 0\nans = 0\n\nfor i in reversed(s):\n n += int(i) * d\n n %= 2019\n d *= 10\n d %= 2019\n mod[n % 2019] += 1\n\nfor i in mod:\n ans += sum(i*(i-1) // 2)\n\nprint(ans)\n', 's = input()\n\nmod = [0] * 2019\nmod[0] = 1\nd = 1\nn = 0\nans = 0\n\nfor i in reversed(s):\n n += int(i) * d\n n %= 2019\n d *= 10\n d %= 2019\n mod[n % 2019] += 1\n\nfor x in range(2019):\n ans += mod[x] * (mod[x]-1) // 2\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s795861772', 's205444791'] | [9168.0, 9040.0] | [120.0, 119.0] | [223, 238] |
p02702 | u707124227 | 2,000 | 1,048,576 | 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. | ['s=input()\nn=len(s)\nsi=int(s)\nmod=2019\nfrom collections import defaultdict\nt=defaultdict(lambda:0)\nfor i in range(n):\n si-=int(s[i])*pow(10,n-1-i)\n t[si]+=1\nans=0\nfor v in t.values():\n ans+=(v*(v-1))//2\nprint(ans)', 's=input()\nn=len(s)\nsi=int(s)\nmod=2019\nfrom collections import defaultdict\nt=defaultdict(lambda:0)\nfor i in range(n):\n si-=int(s[i])*pow(10,n-1-i,mod)\n t[si%mod]+=1\nans=0\nfor v in t.values():\n ans+=(v*(v-1))//2\nprint(ans)', 's=input()\nn=len(s)\nmod=2019\nsum=0\np=1\nd={}\nd[0]=1\nfor i in range(n-1,-1,-1):\n sum=(sum+int(s[i])*p)%mod\n if sum in d:\n d[sum]+=1\n else:\n d[sum]=1\n p=(p*10)%mod\nans=0\nfor v in d.values():\n ans+=(v*(v-1))//2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s084949891', 's351507103', 's427087537'] | [49452.0, 9808.0, 9240.0] | [2207.0, 2206.0, 133.0] | [221, 229, 245] |
p02702 | u709304134 | 2,000 | 1,048,576 | 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. | ['S = input()\nMOD = 2019\ncnt = [0]*MOD\ncur = 0 \ncnt[cur] = 1 \nd = 1 \nfor s in for S[::-1]:\n cur += int(s)*d \n r %= MOD\n cnt[cur] += 1\n \n d *= 10 \n d %= MOD \nans = 0\nfor c in cnt:\n ans += c*(c-1)//2\nprint (ans)\n\n', 'S = input()\nMOD = 2019\ncnt = [0]*MOD\ncur = 0 \ncnt[cur] = 1 \nd = 1 \nfor s in S[::-1]:\n cur += int(s)*d \n cur %= MOD\n cnt[cur] += 1\n \n d *= 10 \n d %= MOD \nans = 0\nfor c in cnt:\n ans += c*(c-1)//2\nprint (ans)\n\n'] | ['Runtime Error', 'Accepted'] | ['s207241588', 's891725208'] | [8892.0, 9376.0] | [22.0, 116.0] | [433, 461] |
p02702 | u721316601 | 2,000 | 1,048,576 | 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. | ["import sys\ninput = sys.stdin.readline\nfrom collections import Counter\n\ndef main():\n MOD = 2019\n S = input()[::-1]\n n = 0\n x = 1\n c = Counter()\n ans = 0\n \n for s in S:\n c[n] += 1\n n += int(s) * x\n n %= MOD\n ans += c[n]\n x = x * 10 % MOD\n \n print(ans)\n \nif __name__ == '__main__':\n main() ", 'from collections import Counter\n\nMOD = 2019\nS = input()[::-1]\nn = 0\nx = 1\nc = Counter()\nans = 0\n\nfor s in S:\n c[n] += 1\n n += int(s) * x\n n %= MOD\n ans += c[n]\n x = x * 10 % MOD\n \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s963070117', 's034069856'] | [9600.0, 9684.0] | [24.0, 168.0] | [375, 208] |
p02702 | u722148122 | 2,000 | 1,048,576 | 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. | ['S = input()\ncnt = 0\nis_end = [False] * (len(S) + 1)\nfor i in range(len(S)):\n if is_end[i]:\n continue\n is_end[i] = True\n bingo = [i]\n s = 0\n for j in range(i+1, len(S)+1):\n if is_end[j]:\n continue\n s += int(S[j-1])\n if s % 3 != 0:\n continue\n if int(S[i:j]) % 673 == 0:\n is_end[j] = True\n bingo.append(j)\n l = len(bingo)\n if l >= 2:\n cnt += int(l*(l-1)/2)\nprint(cnt)\n', 'S = input()\nmod_bucket = [0] * 2019\nmod_bucket[0] += 1\n\n_S = S[::-1]\nmod = 0\np = 1\nfor i in range(len(S)):\n mod = (p * int(_S[i]) + mod) % 2019\n mod_bucket[mod] += 1\n p *= 10\n p %= 2019\n\nans = sum([mod*(mod-1)/2 for mod in mod_bucket])\nprint(int(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s263970850', 's802819726'] | [10924.0, 9372.0] | [2206.0, 111.0] | [472, 264] |
p02702 | u726285999 | 2,000 | 1,048,576 | 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. | ['S = input()\n\nA = []\nprint(len(S))\nfor i in range(len(S)):\n for j in range(i+1,len(S)+1):\n if int(S[i:j]) % 2019 == 0:\n A.append((i+1,j))\n\nprint(len(A))', 'from collections import Counter\nimport sys\n\n# input = lambda : sys.stdin.readline().rstrip()\n\nS = input()\nn = len(S)\n\nM = []\nm = 0\n\nfor i in range(len(S)-1,-1, -1):\n \n m = (pow(10, n-i, 2019) * int(S[i]) + m) % 2019\n M.append(m)\n \n # print(S[i:n], m)\n\nM.append(0) \n\nc = Counter(M)\n\nsum = 0\nfor i in c.values():\n sum += i * (i - 1) / 2\n\nprint(int(sum))'] | ['Wrong Answer', 'Accepted'] | ['s447288093', 's455855504'] | [9344.0, 16812.0] | [2206.0, 347.0] | [172, 424] |
p02702 | u727148417 | 2,000 | 1,048,576 | 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. | ['from scipy.special import comb\nfrom collections import Counter, deque\n\nD = deque(map(int, list(input())))\na = {}\nvalue = 0\n\nfor i in range(len(D)):\n value = value + D.pop() * 10**i\n modulo = value % 2019\n # print(modulo)\n if modulo in a.keys():\n a[modulo] += 1\n else:\n a[modulo] = 1\n\n\nb = [comb(i, 2, exact=True) for i in a.values() if i > 1]\n#print(b)\nprint(sum(b))\n', 'from scipy.special import comb\nfrom collections import Counter, deque\n\nS = list(map(int, list(input())))\nD = deque(S)\na = {}\nvalue = 0\nten_mod = 1\n\nfor i in range(len(S)):\n value = value + D.pop() * ten_mod % 2019\n ten_mod = ten_mod * 10 % 2019\n if value % 2019 in a.keys():\n a[value % 2019] += 1\n else:\n a[value % 2019] = 1\n\nb = [comb(i, 2, exact=True) for i in a.values() if i > 1]\nprint(sum(b))\n', 'import sys\ndef input():\n return sys.stdin.readline()[:-1]\n\nS = list(map(int, list(input())))\nnum = 0\ndict = [0 for i in range(2019)]\ndict[0] = 1\nans = 0\n\nfor i , n in enumerate(S[::-1]):\n num += n * pow(10,i,2019)\n dict[num % 2019] += 1\n\nfor i in range(2019):\n ans += dict[i] * (dict[i] - 1) // 2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s227079534', 's649130777', 's390038472'] | [45176.0, 45360.0, 12004.0] | [2207.0, 302.0, 327.0] | [395, 424, 319] |
p02702 | u729133443 | 2,000 | 1,048,576 | 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. | ['def resolve():\n s = input()\n n = len(s)\n counter = [0] * 2019\n counter[0] += 1\n temp = ""\n for i, c in enumeate(s[::-1], 1):\n temp = c + temp\n counter[int(temp) % 2019] += 1\n\n ans = 0\n for i in counter:\n ans += (i * (i - 1)) // 2\n\n print(ans)\nresolve()', 'M=2019\na=i=0\nd=[0]*M\np=1\nfor j in input()[::-1]:d[i%M]+=1;i-=int(j)*p;a+=d[i%M];p=p*10%M\nprint(a)'] | ['Runtime Error', 'Accepted'] | ['s492315522', 's035102469'] | [9348.0, 9220.0] | [20.0, 134.0] | [300, 97] |
p02702 | u729417323 | 2,000 | 1,048,576 | 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. | ["S = input()\n\nX = [0]*2019\nX[0] = 1\nd = 1\na = 0\n\nfor s in reversed(S):\n a = ((ord(s) - ord('0'))*d + a)%2019\n d = d*10%2019\n print(a)\n X[a] += 1\n\nans = sum(x*(x-1)//2 for x in X)\nprint(ans)\n\n \n", "S = input()\n\nX = [0]*2019\nX[0] = 1\nd = 1\na = 0\n\nfor s in reversed(S):\n a = ((ord(s) - ord('0'))*d + a)%2019\n d = d*10%2019\n X[a] += 1\n\nans = sum(x*(x-1)//2 for x in X)\nprint(ans)\n\n \n"] | ['Wrong Answer', 'Accepted'] | ['s877748706', 's248901157'] | [9228.0, 9284.0] | [162.0, 101.0] | [207, 194] |
p02702 | u734423776 | 2,000 | 1,048,576 | 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. | ['S = str(input())\nN = len(h)\na = [0] * 2019\na[0] = 1\nT = 0\nr = 1\nc = 0\nfor i in range(N-1, -1, -1):\n T = T + int(S[i]) * r\n r = r * 10\n c += a[T%2019]\n a[T%2019] += 1\nprint(c)', 'S = input()\nN = len(h)\na = [0] * 2019\na[0] = 1\nT = 0\nr = 1\nc = 0\nfor i in range(N-1, -1, -1):\n T = T + int(S[i]) * r\n r = r * 10\n c += a[T%2019]\n a[T%2019] += 1\nprint(c)', 'S = str(input())\nh = [int(x) for x in list(S)]\nN = len(h)\na = []\nT = 0\nr = 1\nfor i in range(N-1, -1, -1):\n T = T + h[i] * r\n r = r * 10\n a.append(T%2019)\nb = []\nfor j in range(0, N):\n if a[j] not in b:\n b.append(a[j])\nc = 0\nfor k in range(0, len(b)):\n d = a.count(b[k])\n c += d * (d-1) /2\nc += a.count(0)\nprint(c)', 'S = input()\nN = len(h)\na = [0] * 2019\na[0] = 1\nT = 0\nr = 1\nc = 0\nfor i in range(N-1, -1, -1):\n T = T + int(S[i]) * r\n r = r * 10\n c += a[T%2019]\n a[T%2019] += 1\nprint(c)', 'S = str(input())\nh = [int(x) for x in list(S)]\nN = len(h)\na = [0] * 2019\na[0] = 1\nT = 0\nr = 1\nc = 0\nfor i in range(N-1, -1, -1):\n T = (T + h[i] * r) % 2019\n r = r * 10\n r = r % 2019\n c += a[T]\n a[T] += 1\nprint(c)'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s119745040', 's233601176', 's579530962', 's952671078', 's315120373'] | [9144.0, 9160.0, 12616.0, 9232.0, 12372.0] | [20.0, 22.0, 2206.0, 22.0, 128.0] | [186, 181, 338, 181, 227] |
p02702 | u736470924 | 2,000 | 1,048,576 | 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. | ['s = input()\nl = len(s)\nA = [i for i in range(2019, int(s) + 2019, 2019)]\nans = 0\nfor a in A:\n di = len(str(a))\n for i in range(l - di + 1):\n # print(s[i:i + di], a)\n if s[i:i + di] == str(a):\n ans +=1\nprint(ans)', 's = input()\nl = len(s)\ndp = [0 for i in range(2019)]\ndp[0] = 1\nr = 0\nfor i in range(1, l + 1):\n r += int(s[-i]) * pow(10, i - 1, 2019)\n r %= 2019\n dp[r] += 1\n \nprint(sum([(i * (i - 1)) // 2 for i in dp]))'] | ['Time Limit Exceeded', 'Accepted'] | ['s283794405', 's563990213'] | [2059008.0, 9248.0] | [2272.0, 324.0] | [242, 216] |
p02702 | u739959951 | 2,000 | 1,048,576 | 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. | ['s=(input())\nn=len(s)\n\nans=0\n\nfor i in range(n):\n for j in range(i+3,n):\n s_ans=s[i:j+1]\n s_ans=int("".join(s_ans))\n print(s_ans)\n if s_ans%2019==0:\n ans+=1\n \nprint(ans)', 'S=input()[::-1]\nl=[0]*2019\na=1\nd=0\n\nfor s in S:\n d=d+int(s)*a\n l[d%2019]+=1\n a*=10\n a%=2019\n \nans=l[0]\nfor i in l:\n if i>=2:\n ans+=i*(i-1)//2\n \nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s550285626', 's581109268'] | [25408.0, 9224.0] | [2252.0, 107.0] | [191, 166] |
p02702 | u745514010 | 2,000 | 1,048,576 | 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. | ['s = input()[::-1]\n\nlst = []\nnum = 1\npow10 = [1]\nfor _ in range(len(s) - 1):\n num = num * 10 % 2019\n pow10.append(num)\n\nnum = 0\nfor s_num, p10 in zip(s, pow10):\n num = (num + (int(s_num) * p10)) % 2019\n lst.append(num)\nlst.sort()', 's = input()[::-1]\n\nlst = []\nnum = 1\npow10 = [1]\nfor _ in range(len(s) - 1):\n num = num * 10 % 2019\n pow10.append(num)\n\nnum = 0\nfor s_num, p10 in zip(s, pow10):\n num = (num + (int(s_num) * p10)) % 2019\n lst.append(num)\nlst.sort()\n\ntotal = 0\ncnt = 1\nbefore = 0\nfor num in lst:\n if before == num:\n cnt += 1\n else:\n total += cnt * (cnt - 1) // 2\n cnt = 1\n before = num\ntotal += cnt * (cnt - 1) // 2\nprint(total)'] | ['Wrong Answer', 'Accepted'] | ['s639345506', 's561986455'] | [24384.0, 24376.0] | [166.0, 211.0] | [240, 449] |
p02702 | u747391638 | 2,000 | 1,048,576 | 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. | ['s=input()\nn=len(s)\n\nmodlist=[]\n\nfor i in range(n):\n modlist.append(int(s[i:])%2019)\n\nmodlist.append(0)\n \nresult = 0\n \nfor i in range(2019):\n c = modlist.count(i)\n if c<=1:\n result += 0\n else:\n result += c*(c-1)/2\n\nprint(result)', 's=input()\nn=len(s)\n\nmodlist=[]\n\nfor i in range(n):\n modlist.append(int(s[i:])%2019)\n \nresult = 0\n \nfor i in range(2019):\n c = modlist.count(i)\n if c<=1:\n result += 0\n else:\n result += c*(c-1)/2\n\nprint(result)\n ', 's=input()\nn=len(s)\n\nmodlist=[]\n\nfor i in range(n):\n modlist.append(int(s[i:])%2019)\n\nmodlist.append(0)\n \nresult = 0\n \nfor i in range(2019):\n c = modlist.count(i)\n result += c*(c-1)/2\n\nprint(result)', 's = input()[::-1]\n\ndp = [0]*2019\ndp[0]=1\ntotal = 0\na = 1\n\nfor i in list(s):\n total += int(i)*a\n total %= 2019\n dp[total] += 1\n a *= 10\n a %= 2019\ncount=0\n \nfor i in range(2019):\n count += dp[i]*(dp[i]-1)//2\n \nprint(count)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s108657519', 's467332240', 's588526024', 's928758389'] | [9424.0, 9396.0, 9424.0, 10596.0] | [2206.0, 2206.0, 2206.0, 119.0] | [238, 225, 201, 230] |
p02702 | u749742659 | 2,000 | 1,048,576 | 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. | ['s = int(input())\nss = len(str(s))\n\ncount = 0\nfor i in range(ss):\n for j in range(i,ss):\n sa = s // (10**i)\n sb = sa % (10**(j+1-i))\n if (sb % 2019 == 0):\n count += 1\n print(i,j,sb)\n\nprint(count)', 's = input()[::-1]\n\ndataset = [0]*2019\ndataset[0] = 1\n\nn = 0\nd = 1\n\nfor i in s:\n n += int(i) * d\n a = n % 2019\n dataset[a] += 1\n d *= 10\n d %= 2019\n\ncount = 0\nfor i in dataset:\n count += i * (i-1) // 2\n\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s129573248', 's115015863'] | [9164.0, 9300.0] | [2205.0, 113.0] | [240, 232] |
p02702 | u752907966 | 2,000 | 1,048,576 | 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. | ['s=input()\nans = 0\ndp = [[0 for i in range(len(s)+3)]for j in range(len(s)+3)]\ndef rec(i,j,num):\n global ans\n if dp[i][j] == 1:\n return\n dp[i][j] = 1\n if int(num) % 2019 == 0:\n ans += 1\n else:\n if j < len(s):\n rec(i,j+1,num+s[j])\n if len(num) >= 5:\n rec(i+1,j,num[1::])\n\nrec(0,1,s[0])\nprint(ans)\n', 's=input()\nans = 0\ndp = [[0 for i in range(len(s)+3)]for j in range(len(s)+3)]\ndef rec(i,j,num):\n global ans\n if dp[i][j] == 1:\n return\n dp[i][j] = 1\n if int(len(num)) < 2019:\n return\n if int(num) % 2019 == 0:\n ans += 1\n else:\n if j < len(s):\n rec(i,j+1,num+s[j])\n if len(num) >= 2:\n rec(i+1,j,num[1::])\n\nrec(0,1,s[0])\nprint(ans)\n', 's = str(input())\ncnt = [0]*2019\ncnt[0] += 1\n\nsi = [0] * (len(s)+1) \ntmp = 0\nfor i in range(1,len(s)+1): \n tmp += int(s[-i])%2019 * pow(10,i-1,2019)\n si[i] = tmp % 2019\n cnt[si[i]] += 1\n\nans = 0\nfor b in cnt:\n ans += b*(b-1)//2\n\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s188240197', 's555750922', 's267381517'] | [594416.0, 557472.0, 16332.0] | [2222.0, 2222.0, 348.0] | [442, 486, 360] |
p02702 | u755989869 | 2,000 | 1,048,576 | 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. | ['s = input()\nn = len(s)\n\na = [0]*2019\ncount = 0\nval = 10\nfor i in range(n):\n tmp = int(s[n-i-1,n]) % 2019\n count = count + a[tmp]\n a[tmp] = a[tmp] + 1\n if(tmp == 0):\n count = count + 1\n val = val * 10\n\nprint(count)', 's = input()[::-1]\nn = len(s)\n\na = [0]*2019\na[0] = 1\ncount = 0\nval = 1\ncurrent = 0\nfor c in s:\n current = (current + val * int(c)) % 2019\n count += a[current%2019]\n a[current%2019] += 1\n val = val * 10 % 2019\n\nprint(count)'] | ['Runtime Error', 'Accepted'] | ['s904948120', 's437524835'] | [9288.0, 9316.0] | [20.0, 124.0] | [235, 233] |
p02702 | u756420279 | 2,000 | 1,048,576 | 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. | ['#!/usr/bin/env python3\n\nS = input()\nlis_2019 = [2019 * i for i in range(1, 99)]\ncnt = 0\nS_len = len(S)\ncnt_1 = 0\nS_lis = [S]\n\nfor i in range(4, S_len):\n while cnt_1 != S_len - i + 1:\n for j in lis_2019:\n if j == S[cnt_1:cnt_1+i]:\n cnt += 1\n cnt_1 += 1\n cnt_1 = 0\n\nprint(cnt)', '#!/usr/bin/env python3\n\nS = input()[::-1]\n\ncounts = [0] * 2019\ncounts[0] = 1\n\nnum, d = 0, 1\n\nfor i in S:\n num += int(i) * d\n num %= 2019\n d *= 10\n d %= 2019\n counts[num] += 1\n\nans = 0\nfor i in counts:\n ans += i * (i - 1) // 2\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s756368458', 's662730255'] | [9140.0, 9240.0] | [2206.0, 110.0] | [320, 255] |
p02702 | u760256928 | 2,000 | 1,048,576 | 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. | ['import collections\n\ns = input()\ns_len = len(s)\nn = 2019\nmod_list = [0] * n\n\nfor i in range(s_len):\n t = s[i:]\n t_i = int(t)\n m = t_i % n\n #mod_list.append(m)\n mod_list[m] += 1\n\n#c = collections.Counter(mod_list)\n\nresult = sum(i * (i - 1) // 2 for i in mod_list)\nprint(result)', 's = input()\ns_len = len(s)\nn = 2019\nmod_list = [0] * n\nmod_list[0] = 1\n\np = 1\nd = 0\nfor t in reversed(s):\n d += int(t) * p\n m = d % n\n mod_list[m] += 1\n p *= 10\n p %= 2019\n\nresult = sum(i * (i - 1) // 2 for i in mod_list)\nprint(result)'] | ['Wrong Answer', 'Accepted'] | ['s725893145', 's358892132'] | [10004.0, 9176.0] | [2206.0, 114.0] | [341, 250] |
p02702 | u764215612 | 2,000 | 1,048,576 | 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. | ['def main():\n n, d, mods = 0, 1, [1]+[0]*2019\n \n # n = (n+int(i)*d)%2019\n # d = d*10%2019\n # mods[n] += 1\n for i, j in enumerate(reversed(s)):\n n = (n+int(j)*10**i%2019)%2019\n mods[n] += 1\n print(sum([i*(i-1)//2 for i in mods]))\nmain()', 's = input()\nn = 0\nans = 0\nmods = [0]*p\nmods[0] = 1\nfor i, j in enumerate(reversed(s)):\n n += int(j)*pow(10, i, 2019)\n n %= 2019\n mods[n] += 1\nfor i in mods:\n ans += i*(i-1)//2\nprint(ans)', 'def main():\n n, d, mods = 0, 1, [1]+[0]*2019\n for i in reversed(input()):\n n = (n+int(i)*d)%2019\n d = d*10%2019\n mods[n] += 1\n print(sum([int(i*(i-1)/2) for i in mods]))\nmain()'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s662982323', 's689161997', 's615708777'] | [9016.0, 9220.0, 9308.0] | [21.0, 22.0, 81.0] | [278, 190, 188] |
p02702 | u773865844 | 2,000 | 1,048,576 | 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. | ['import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-int(a/2019)*2019\n X.append(c)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\n \nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\n', 'import sys\n\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-int(a/2019)*2019\n X.append(c)\n\nX.sort()\nprint(X)\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag = flag +1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\n \nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\na = 0\nfor i in range(len(S)):\n a += int(S[len(S)-1-i])*10**i %2019\nprint(X)\n', 'import sys\nimport math\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-(a//2019)*2019\n X.append(c)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\n \nprint(n)\n', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\n \nprint(n)\n \n\n', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n', 'a = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\n\n \n\n', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-(a//2019)*2019\n X.append(c)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\n \nprint(n)\n', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = input()\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)', 'S = str(input())\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)/2\n flag = 1\nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-(a//2019)*2019\n X.append(c)\nprint(c)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)\n \n\n', 'a = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\n \n\n', 'S = str(input())\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\nif X[len(X)-1]==0:\n n +=1\nprint(n)\n', 'import sys\n\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\n\nfor i in range(len(S)):\n a = int(S[i:])\n c = a-int(a/2019)*2019\n X.append(c)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag = flag +1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\n \nprint(n)', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\nX = []\nA =[]\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\n \nprint(n)\n \n\n', '\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\n\nX.sort()\nflag =1\nn = 0\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)\n \n\n', 'import sys\nlines = sys.stdin.readlines()\n\nS = str(lines[0])\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-1])*A[i]) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += flag*(flag-1)//2\n flag = 1\nprint(n)', 'S = str(input())\n\n\nA = []\np =1\nfor i in range(len(S)):\n A.append(p)\n p = p*10%2019\n\n\nX = []\na = 0\nfor i in range(len(S)):\n a = (a + int(S[len(S)-i-1])*A[i]) %2019\n X.append(a)\nX.sort()\nflag =1\nn = 0\n\n\nfor i in range(len(X)-1):\n if X[i]==0:\n n +=1\n if X[i]==X[i+1]:\n flag += 1\n else:\n n += int(flag*(flag-1)/2)\n flag = 1\nn += int(flag*(flag-1)/2)\nif X[len(X)-1]==0:\n n +=1\nprint(n)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s037881059', 's082665599', 's083492780', 's088894845', 's154960544', 's175858306', 's191185514', 's227832217', 's241253575', 's241623164', 's411508293', 's458943373', 's471765493', 's478718618', 's514383588', 's579362092', 's608189248', 's699869786', 's715021547', 's783849171', 's890962467', 's137397724'] | [9328.0, 16380.0, 16220.0, 9268.0, 9288.0, 9432.0, 16348.0, 16180.0, 8976.0, 9512.0, 16440.0, 9160.0, 24396.0, 9500.0, 16312.0, 8936.0, 24416.0, 9208.0, 16416.0, 9012.0, 16240.0, 24284.0] | [206.0, 61.0, 59.0, 204.0, 22.0, 2206.0, 61.0, 58.0, 19.0, 2206.0, 60.0, 23.0, 241.0, 2205.0, 58.0, 23.0, 239.0, 205.0, 58.0, 23.0, 58.0, 235.0] | [316, 562, 230, 331, 145, 327, 391, 206, 117, 311, 556, 555, 517, 154, 389, 246, 548, 322, 390, 256, 559, 576] |
p02702 | u785573018 | 2,000 | 1,048,576 | 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. | ['S = input()\na = []\nb = [0]*2019\nc = 0\nd = 0\nfor n in range(len(S)):\n c += 10*n*int(S[-n-1])\n a.append(c%2019)\nfor n in range(len(S)):\n b[a[n]] += 1\nfor n in range(2019):\n d += int(b[n]*(b[n]-1)/2)\nprint(d)', 'S = input()\nl = len(S)\na = [0]\nb = [0]*2019\nc = [1]\nd = 0\ne = 0\nfor n in range(l-1):\n c.append(c[n]*10%2019)\nfor n in range(l):\n d += int(S[-n-1])*c[n]\n a.append(d%2019)\nfor n in range(l+1):\n b[a[n]] += 1\nfor n in range(2019):\n e += int(b[n]*(b[n]-1)/2)\nprint(e)'] | ['Wrong Answer', 'Accepted'] | ['s180098761', 's192358315'] | [16344.0, 23544.0] | [146.0, 173.0] | [217, 277] |
p02702 | u788703383 | 2,000 | 1,048,576 | 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. | ['s = input()\nMOD = 2019\nr = [0]*MOD\nr[0] = 1\nz = 0\nt = 0\nfor i in reversed(s):\n z = int(i) * pow(10,t,m) + z\n z %= MOD\n r[z] += 1\n t += 1\nprint(sum(i*(i-1)//2 for i in r))\n', 's = input()\nn = len(s)\nm = 2019\na = 0\nr = [0 for _ in range(m+1)]\nr[0] = 1\nfor i in range(0,n):\n z = (int(s[n-i-1])*pow(10,i,m) + z)%m\n a += r[z]\n r[z] += 1\nprint(a)\n', "def main():\n s = input()\n MOD = 2019\n r = [0]*MOD\n r[0] = 1\n z = 0\n t = 1\n for i in reversed(s):\n z = int(i) * t + z\n z %= MOD\n t *= 10\n t %= MOD\n r[z] += 1\n print(sum(i*(i-1)//2 for i in r))\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s206527916', 's660265702', 's641570248'] | [9324.0, 9168.0, 9260.0] | [21.0, 19.0, 84.0] | [183, 175, 291] |
p02702 | u789199177 | 2,000 | 1,048,576 | 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. | ['import collections\ns = input()\nn = len(s)\nmod_list = [0]\n\nT = 0\nfor i in range(n):\n T += int(s[-1-i])*pow(10, i, 2019)%2019\n T = T%2019\n mod_list.append(T)\n\nres = collections.Counter(mod_list)\ncnt = 0\nfor d in res.values:\n cnt += int(d*(d-1)/2)\nprint(cnt)', "s = input()\nn = len(s)\n\nskip_num = []\n\nif n < 4:\n print('0')\nelse:\n cnt = 0\n i = 3\n while i < n:\n for j in range(n-i):\n step = int(s[j:j+i])\n if step%2019 == 0:\n cnt += 1\n i += 1\n print(cnt)", 'import collections\ns = input()\nn = len(s)\nmod_list = [0]\n\nT = 0\nfor i in range(n):\n T += int(s[-1-i])*pow(10, i, 2019)%2019\n T = T%2019\n mod_list.append(T)\n\nres = collections.Counter(mod_list)\ncnt = 0\nfor d in res.values():\n cnt += int(d*(d-1)/2)\nprint(cnt)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s391441901', 's860538587', 's981708138'] | [16628.0, 9328.0, 16760.0] | [358.0, 2205.0, 356.0] | [267, 256, 269] |
p02702 | u801570811 | 2,000 | 1,048,576 | 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. | ["def d164(n):\n res = 0\n for i in range(1, 200000):\n count = 2019*i\n if n.count(str(count)) != 0:\n res += n.count(str(count))\n return res\n\ndef main():\n n = str(input())\n print(d164(n))\nif __name__ == '__main__':\n main()", "if __name__ == '__main__':\n n = str(input())\n ans = 0\n for i in range(1, 200000):\n count = 2019*i\n if n.count(str(count)) != 0:\n ans += n.count(str(count))\n print(ans)", 'S=list(input())\nS.reverse()\nN=len(S)\nR=[0]*N\nR10=[0]*N\nm=2019\nK=0\n\nR10[0]=1\nR[0]=int(S[0])%m\nfor i in range(1,N):\n R10[i]=(R10[i-1]*10)%m\n R[i]=(R[i-1]+int(S[i])*R10[i])%m\nd={}\nfor i in range(2019):\n d[i]=0\n\nfor i in range(N):\n d[R[i]]+=1\nans=0\nfor i in range(2019):\n if i == 0:\n ans += d[i]\n ans +=d[i]*(d[i]-1)//2\n else:\n ans +=d[i]*(d[i]-1)//2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s113559191', 's124055719', 's978577069'] | [9148.0, 9344.0, 24756.0] | [2205.0, 2206.0, 176.0] | [260, 204, 396] |
p02702 | u802234211 | 2,000 | 1,048,576 | 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. | ['\ns = list(str(10**200000))\nn = len(s)\nans = 0\ns.reverse()\n# print(s)\nx = 1\ntot = 0\ncount = [0]*2019\nfor i in range(n):\n count[tot]+=1\n tot += int(s[i])*x\n # print(tot)\n tot %= 2019\n ans += count[tot]\n x = x*10%2019\nprint(ans)', 'from math import factorial\nS=list(map(int,input()))\nS.reverse()\n# print(S)\ncount2019 = [0]*2019\ncount2019[0]=1\n\nfor i in range(len(S)):\n mod2019 =(mod2019+S[i]*10**i)%2019\n count2019[mod2019] +=1\n\nans =0\nfor i in count2019:\n if(i>=2):\n ans += factorial(i) // factorial(i) // factorial(i - 2)\nprint(ans)\n# print(count2019)', '\ns = list(str(10**200000))\nn = len(s)\nans = 0\ns.reverse()\nprint(s)\nx = 1\ntot = 0\ncount = [0]*2019\nfor i in range(n):\n count[tot]+=1\n tot += int(s[i])*x\n # print(tot)\n tot %= 2019\n ans += count[tot]\n x = x*10%2019\nprint(ans)', 's = list(input())\n\nn = len(s)\nans = 0\ns.reverse()\n# print(s)\nx = 1\ntot = 0\ncount = [0]*2019\nfor i in range(n):\n count[tot]+=1\n tot += int(s[i])*x\n # print(tot)\n tot %= 2019\n ans += count[tot]\n x = x*10%2019\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s004271479', 's233101795', 's360588856', 's191928189'] | [10564.0, 10756.0, 12404.0, 10424.0] | [625.0, 41.0, 635.0, 141.0] | [262, 337, 260, 262] |
p02702 | u802963389 | 2,000 | 1,048,576 | 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. | ['S = input()\n\nmods = [0 for _ in range(2019)]\n\nnum = 0\nfor itr, s in enumerate(S[::-1]):\n num = int(s) * 10 ** itr + num\n mo = num % 2019\n mods[mo] += 1\n\nans = 0\nfor m in mods:\n ans += m * (m - 1) // 2\n\nprint(ans)\n', 'S = list(map(int, list(input())))\n\nMOD = 2019\n\nmods = [0 for _ in range(2019)]\nmods[0] = 1\n\nnum = 0\ndigit = 1\nfor s in S[::-1]:\n num = s * digit + num\n num %= MOD\n mods[num] += 1\n digit = (digit * 10) % MOD\n \nans = 0\nfor m in mods:\n ans += m * (m - 1) // 2\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s455996927', 's360051641'] | [9384.0, 12004.0] | [2206.0, 109.0] | [217, 275] |
p02702 | u809816772 | 2,000 | 1,048,576 | 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. | ['S = str(input())\nans = 0\n\nif len(S) <= 3:\n print(0)\nelse: \n for i in range(len(S)-3):\n if int(S[i:i+3]) % 2019 == 0:\n ans+=1\n print(ans)', 'S = str(input())\nans = 0\n\nif len(S) <= 3:\n print(ans)\nelse: \n for i in range(0,len(S)-2):\n for j in range(i+3,len(S)-2):\n if int(S[i:j]) % 2019 == 0:\n ans+=1\n print(ans)', 'S = str(input())\nans = 0\n\nif len(S) <= 3:\n print(0)\nelse: \n for i in range(len(S)-3):\n if S[i:i+3] % 2019 == 0:\n ans+=1\n print(ans)', 'S = input()[::-1]\n\ncnts = [0]*2019\ncnts[0] = 1\nnum = 0\nd = 1\nans = 0\n\nfor i in S:\n num += int(i) * d\n d *= 10\n num %= 2019\n d %= 2019\n cnts[num] += 1\n\nfor j in cnts:\n ans += j * (j-1) // 2 \n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s337309316', 's477033617', 's527703879', 's118976160'] | [9184.0, 9396.0, 9140.0, 9348.0] | [80.0, 2206.0, 24.0, 115.0] | [165, 213, 160, 219] |
p02702 | u814986259 | 2,000 | 1,048,576 | 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. | ["S = list(map(int, list(input())))\nN = len(S)\n\ndp = [[0]*N for i in range(N)]\nif N < 4:\n print(0)\n exit(0)\n\nD = [[0]*N for i in range(9)]\nfor i in range(9):\n D[i][i] = (i+1)\n for j in range(i+1, N):\n D[i][j] = D[i][j-1]*10 % 2019\n\n\nprint(D)\nans = 0\n\ndp[0] = S[0]\nfor i in range(1, N):\n dp[i] = (dp[i-1]*10 + S[i]) % 2019\n if dp[i] == 0:\n ans += 1\n\nfor i in range(1, N):\n for j in range(i+1, N):\n dp[i] -= D[S[i-1]][j]\n dp[i] %= 2019\n if dp[i] == 0:\n ans += 1\n\n# print(N)\n# print(*dp, sep='\\n')\nprint(ans)\n", "import collections\nS = list(map(int, list(input())))\nN = len(S)\n\ndp = [0]*N\nif N < 4:\n print(0)\n exit(0)\n\nans = 0\n\nD = [0]*N\nD[0] = 1\nfor i in range(1, N):\n D[i] = D[i-1]*10 % 2019\nt = collections.defaultdict(int)\ntmp = 0\n\nt[0] += 1\nfor i in range(N):\n tmp += S[N-1-i]*D[i]\n tmp %= 2019\n t[tmp] += 1\n\nfor x in t:\n ans += t[x]*(t[x]-1) // 2\n\n# print(N)\n# print(*dp, sep='\\n')\n\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s645958149', 's412487113'] | [2690312.0, 19468.0] | [2275.0, 161.0] | [571, 408] |
p02702 | u816265237 | 2,000 | 1,048,576 | 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. | ['# multiple\nline = input()\nln = [0]\ncounts=[0]*2019\nfor i in range(1,len(line) + 1):\n ti1 = (ln[-1] +(int(line[-1*i])*10**(i-1))%2019)%2019\n counts[ti1] += 1\n ln.append(ti1)\ntotal = 0\ncounts[0] +=1\nfor i in range(len(counts)):\n total += counts[i]*(counts[i] - 1)/2\nprint(total)', '# multiple\nline = input()\nln = 0\nd = 1\ncounts=[0]*2019\nfor i in range(1,len(line) + 1):\n ti1 = (ln +(int(line[-1*i])*d))%2019\n counts[ti1] += 1\n ln = ti1\n d *= 10\n d %= 2019\ntotal = 0\ncounts[0] +=1\nfor i in range(len(counts)):\n total += counts[i]*(counts[i] - 1)/2\nprint(int(total))'] | ['Wrong Answer', 'Accepted'] | ['s765411769', 's572359859'] | [9808.0, 9092.0] | [2206.0, 125.0] | [288, 300] |
p02702 | u829249049 | 2,000 | 1,048,576 | 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. | ['S=list(input())\nN=len(S)\nmod=[0 for i in range(2019)]\ns=0\nans=0\nfor i in range(2019):\n k=mod[i]\n if i==0:\n if k>=2:\n ans+=k*(k-1)//2+k\n else:\n ans+=k\n else:\n if k>=2:\n ans+=k*(k-1)//2\nprint(ans) ', 'from scipy.special import comb\nS=input()\nN=len(S)\nmod=[0 for i in range(2019)]\nfor i in range(N):\n s=S[i:N+1]\n mod2=int(s)%2019\n mod[mod2]+=1\nans=0\nfor i in range(2019):\n k=mod[i]\n if i==0:\n if k>=2:\n ans+=comb(k,2)+k\n else:\n ans+=k\n else:\n if k>=2:\n ans+=comb(k,2)\nprint(ans) ', 'S=list(input())\nN=len(S)\nmod=[0 for i in range(2019)]\ns=0\nfor i in range(N-1,-1,-1): \n s+=int(S[i])*(10**(N-1-i))\n mod2=s%2019\n mod[mod2]+=1\nans=0\nprint(ans) ', 'S=input()\nN=len(S)\nmod=[0 for i in range(2019)]\ns=0\nten=1\nfor i in range(N-1,-1,-1): \n s+=int(S[i])*ten\n mod2=s%2019\n mod[mod2]+=1\n ten=(ten*10)%2019\nans=0\nfor i in range(2019):\n k=mod[i]\n if i==0:\n if k>=2:\n ans+=k*(k-1)//2+k\n else:\n ans+=k\n else:\n if k>=2:\n ans+=k*(k-1)//2\nprint(ans) '] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s590982300', 's904954564', 's927170416', 's942020484'] | [10468.0, 42836.0, 10632.0, 9336.0] | [26.0, 2207.0, 2206.0, 112.0] | [227, 312, 166, 318] |
p02702 | u840579553 | 2,000 | 1,048,576 | 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. | ['"""\nimport random\nimport functools\nimport copy\nimport bisect\nimport array\nimport re\nimport collections\nimport heapq\nimport fractions\nimport itertools\nimport string\nimport math\nfrom operator import itemgetter as ig\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom itertools import permutations, combinations, product, accumulate, groupby\nfrom heapq import heappush, heappop\nfrom collections import deque, defaultdict, Counter\nimport sys\nsys.setrecursionlimit(10 ** 7)\n# import numpy as np\n\ninf = 10 ** 20\nINF = float("INF")\nmod = 10 ** 9 + 7\ndd = [(-1, 0), (0, 1), (1, 0), (0, -1)]\nddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]\nddn9 = ddn + [(0, 0)]\n\'\'\'for dx, dy in dd:\n nx = j + dx; ny = i + dy\n if 0 <= nx < w and 0 <= ny < h:\'\'\'\n\nfrom collections import deque, defaultdict, Counter\nimport math\nimport sys\nsys.setrecursionlimit(10 ** 7)\n\n\ndef wi(): return list(map(int, sys.stdin.readline().split()))\n# WideIntPoint\n\n\ndef wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]\n\n\ndef ws(): return sys.stdin.readline().split()\n\n\ndef si(): return int(sys.stdin.readline()) # SingleInt\n\n\ndef ss(): return input()\n\n\ndef hi(n): return [si() for _ in range(n)]\n\n\ndef hs(n): return [ss() for _ in range(n)] # HeightString\n\n\ndef s_list(): return list(input())\n\n\ndef mi(n): return [wi() for _ in range(n)] # MatrixInt\n\n\ndef mip(n): return [wip() for _ in range(n)]\n\n\ndef ms(n): return [ws() for _ in range(n)]\n\n\ndef num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[\n 0]] for _ in range(n)] # NumberGrid\n\n\ndef grid(n): return [s_list() for _ in range(n)]\n\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\n# a/b の切り上げ\n\n\ndef round_up(a, b):\n """ a/b の切り上げ """\n c = (a + b - 1) / b\n return c\n\n\ndef lcm(a, b):\n """a,bの最小公倍数"""\n return a * b // gcd(a, b)\n"""\n\ndef main():\n s = input()\n\n cnt = [0] * 2019\n # print(cnt)\n cnt[0] = 1\n ans = 0\n b = 0\n t = 1\n for i in s:\n b = b + int(i) * t\n amari = b % 2019\n cnt[amari] += 1\n t *= 10 % 2019\n\n for i in cnt:\n ans += i * (i - 1) // 2\n print(ans)\n\n\nif __name__ == \'__main__\':\n main()\n', 's = input()\n\ncnt = [0] * 2019\n# print(cnt)\ncnt[0] = 1\nans = 0\nb = 0\nt = 1\nfor i in s:\n b = b + int(i) * t\n amari = b % 2019\n cnt[amari] += 1\n t *= 10 % 2019\n\nfor i in cnt:\n ans += i * (i - 1) // 2\nprint(ans)\n', 's = input()[::-1]\n\nsum_of_digits = 0\n\ncnts = [0] * 2019\n\ncnts[0] = 1\n\nd = 1\n\nfor c in s:\n sum_of_digits += int(c) * d\n sum_of_digits %= 2019\n d *= 10\n d %= 2019\n cnts[sum_of_digits] += 1\n\nans = 0\n\nfor cnt in cnts:\n ans += cnt * (cnt - 1) // 2\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s073581686', 's845034043', 's083336382'] | [8832.0, 9496.0, 9272.0] | [22.0, 2206.0, 113.0] | [2229, 223, 273] |
p02702 | u841856382 | 2,000 | 1,048,576 | 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. | ['S = input()\nans = 0\nnd = 1\nmod2 = 0\nlistmod = [0]*2019\nfor i in S[::-1]:\n mod1 = (int(i)*nd + mod2)%2019\n listmod[mod1] += 1\n mod2 = mod1\n nd = (nd*10)%2019\nfor i in range(2019):\n n = listmod[i]\n if(i == 0):\n ans += int(n*(n+1))/2\n else:\n ans += int((n-1)*n/2)\nprint(ans)', 'S = input()\nans = 0\nnd = 1\nmod1 = 0\nlistmod = [0]*2019\nfor i in S[::-1]:\n mod1 = (int(i)*nd + mod1)%2019\n listmod[mod1] += 1\n nd = (nd*10)%2019\nfor i in range(2019):\n n = listmod[i]\n if(n>0):\n ans += ((n-1)*n)//2\nprint(ans)', 'S = input()\nans = 0\nnd = 1\nmod1 = 0\nlistmod = [0]*2019\nfor i in S[::-1]:\n mod1 = (int(i)*nd + mod1)%2019\n listmod[mod1] += 1\n nd = (nd*10)%2019\nfor i in range(2019):\n n = listmod[i]\n ans += int((n-1)*n/2)\nprint(ans)', 'S = input()\nans = 0\nnd = 1\nmod1 = 0\nlistmod = [0]*2019\nfor i in S[::-1]:\n mod1 = (int(i)*nd + mod1)%2019\n listmod[mod1] += 1\n nd = (nd*10)%2019\nfor i in range(2019):\n n = listmod[i]\n if(i == 0):\n if(n == 1):\n ans += 1\n elif(n >= 2):\n ans += ((n+1)*n)//2\n else:\n if(n > 1):\n ans += ((n-1)*n)//2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s786083307', 's893415491', 's934914024', 's885873436'] | [9324.0, 9232.0, 9264.0, 9088.0] | [107.0, 101.0, 101.0, 105.0] | [306, 245, 230, 376] |
p02702 | u857428111 | 2,000 | 1,048,576 | 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. | ['s = input()\nn = len(s)\ns_cu = [0] * n\ncounter = [0] * 2019\n\nfor i in range(1, n+1):\n s_cu[i-1] = int(s[n-i:]) \n counter[int(s[n-i-1:]) % 2019] += 1\nprint(s_cu)\n\n#diff\ncounter[0]+=1\n#diff end\n\n\nans = 0\nfor i in counter:\n ans += (i * (i - 1)) // 2\n\n\n#print(counter[0])\n\nprint(ans)', '\nimport sys\ninput= lambda: sys.stdin.readline().rstrip()\ndef pin(type=int):return map(type,input().split())\ndef tupin(t=int):return tuple(pin(t))\n#%%code\ndef resolve():\n S=input()\n n=len(S)\n \n S2=[0]*n\n digit=0\n for i in range(n-1,-1,-1):\n s=int(S[i])\n S2[i]=(s*pow(10,digit,2019))%2019\n digit+=1\n #print(S2)\n\n S3=[0]*n;subsum=0\n for j,s2 in enumerate(S2):\n subsum+=s2;subsum%=2019;S3[j]=subsum\n S3.append(0)\n #print(S3)\n\n from collections import Counter\n c=Counter(S3).values()\n ans=0\n for k in c:\n if k>1:\n ans+=(k*(k-1))//2\n print(ans)\n#%%submit!\nresolve()'] | ['Wrong Answer', 'Accepted'] | ['s553482396', 's411091415'] | [26960.0, 23936.0] | [2206.0, 343.0] | [322, 682] |
p02702 | u857759499 | 2,000 | 1,048,576 | 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. | ['def main():\n s = input()[::-1]\n l = len(s)\n n = 2019\n dp = [0]*n\n wk = 0\n r = 1\n for i in range(l):\n wk += int(s[i])*r\n wk %= n\n dp[wk] += 1\n r*= 10\n r %= n\n print(sum([i*(i-1)//2 for i in dp]),dp)\nmain()', 'def main():\n s = input()[::-1]\n l = len(s)\n n = 2019\n dp = [0]*n\n wk = 0\n r = 1\n for i in range(l):\n wk += int(s[i])*r\n wk %= n\n dp[wk] += 1\n r*= 10\n r %= n\n print(sum([i*(i-1)//2 for i in dp]))\nmain()', 'def main():\n s = input()[::-1]\n l = len(s)\n n = 2019\n dp = [0]*n\n wk = 0\n r = 1\n for i in range(l):\n wk += int(s[i])*r\n wk %= n\n dp[wk] += 1\n r*= 10\n r %= n\n print(dp[0]+sum([i*(i-1)//2 for i in dp]))\nmain()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s360686262', 's704166538', 's249863481'] | [9416.0, 9352.0, 9188.0] | [86.0, 87.0, 85.0] | [227, 224, 230] |
p02702 | u860002137 | 2,000 | 1,048,576 | 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. | ['import numpy as np\nimport math\n\ns = input()[::-1]\nlength = len(s)\na = np.zeros(length, dtype=int)\nd = np.zeros(length, dtype=int)\nans = np.zeros(2019, dtype=int)\n\nfor i in range(length):\n if i == 0:\n a[i] = int(s[i])\n d[i] = a[i]\n else:\n a[i] = int(s[i]) * pow(10, i) % 2019\n d[i] = (d[i-1] + a[i]) % 2019\n ans[d[i]] += 1\n\nprint(int(sum([ans[i] * (ans[i]-1) for i in range(1, ans.shape[0])]) // 2))', 'import numpy as np\nimport math\n\ns = input()[::-1]\nlength = len(s)\na = np.zeros(length, dtype=int)\nd = np.zeros(length, dtype=int)\nans = np.zeros(2019+1)\n\nfor i in range(length):\n a[i] = int(s[i]) * pow(10, i) % 2019\nd[0] = a[0]\n\nfor i in range(length-1):\n d[i+1] = (d[i] + a[i+1]) % 2019\n ans[d[i+1]] += 1\n\nx = ans[np.where(ans > 1)]\n\nprint(int(sum([math.factorial(x[i]) for i in range(x.shape[0])]) / 2) + d.shape[0] - np.count_nonzero(d))', 'from itertools import accumulate\nfrom collections import Counter\n\n\ndef solve(n):\n return n * (n - 1) // 2\n\n\ns = input()[::-1]\nMOD = 2019\n\n\nrest = []\nfor i, x in enumerate(s):\n \n if i == 0:\n tmp = 1\n else:\n tmp = tmp * 10 % MOD\n rest.append(int(x) * tmp % MOD)\n\nresult = [x % MOD for x in list(accumulate(rest))]\n\n\nzero = result.count(0)\n\n\nc = Counter(result)\nc = list(c.values())\n\n\nprint(sum([solve(x) for x in c if x >= 2]) + zero)'] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s473732932', 's844125956', 's690738690'] | [27472.0, 27432.0, 31900.0] | [2206.0, 2206.0, 165.0] | [439, 449, 642] |
p02702 | u861471387 | 2,000 | 1,048,576 | 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. | ['S = input()\nB = defaultdict(int)\nB[0]=1\nans=0\n\nfor i in range(len(S)):\n m=int(S[-i-1:])%2019\n ans+=B[m]\n B[m]+=1\n\nprint(int(ans))', 'from collections import defaultdict\n\nS = input()\nB = defaultdict(int)\nB[0]=1\nans=0\nprev=0\n\nfor i in range(len(S)):\n m=(prev+int(S[-i-1])*pow(10,i,2019))%2019\n ans+=B[m]\n B[m]+=1\n prev=m\n\nprint(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s988198229', 's998811403'] | [9164.0, 9644.0] | [22.0, 365.0] | [138, 214] |
p02702 | u861886710 | 2,000 | 1,048,576 | 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. | ['S = int(input())\nS = str(S)\nn = len(str(S))\nj = 0\nif n > 4:\n for i in range(n-3):\n for j in range(i+4, n+1):\n nn = int(S[i:j])\n print(nn)\n if nn % 2019 == 0:\n j += 1\nprint(j)', 'S = int(input())\nS = str(S)\nn = len(str(S))\n\nj = 0\nif n > 4:\n for i in range(n-3):\n nn = int(S[i:i+4])\n if nn%2019 == 0:\n j += 1\nprint(j)', 'from collections import Counter\nS = input()[::-1]\nMOD = 2019\n\nX = [0]\n\nfor i, s in enumerate(S):\n X.append((X[-1] + int(s) * pow(10, i, MOD)) %MOD)\n print(X)\n\nC = Counter(X)\nans = 0\n\nfor v in C.values():\n ans += v * (v-1) // 2\n\nprint(ans)', 'S = int(input())\nS = str(S)\nn = len(str(S))\nnnn = 0\n \nfor i in range(n-3):\n for j in range(i+3, n):\n nn = int(S[i:j+1])\n print(nn)\n if nn % 2019 == 0:\n nnn += 1\nprint(nnn)', 'from collections import Counter\nS = input()[::-1]\nMOD = 2019\n\nX = [0]\nfor i, s in enumerate(S):\n X.append((X[-1] + int(s) * pow(10, i, MOD)) % MOD)\n\nC = Counter(X)\nans = 0\nfor v in C.values():\n ans += v * (v - 1) // 2\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s134511662', 's628018027', 's949068370', 's951142006', 's468150753'] | [27120.0, 9216.0, 137328.0, 27172.0, 16776.0] | [2250.0, 781.0, 2013.0, 2248.0, 336.0] | [232, 165, 247, 208, 234] |
p02702 | u863433366 | 2,000 | 1,048,576 | 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. | ['S = input()\ns = S[::-1]\n\ncnt = [0]*2019\ns[0] = 1\nnumber = 0\nd = 1\n\nfor i in s:\n number += int(i)*d\n cnt[number % 2019] += 1\n d *= 10\n d = d % 2019\n\nans = 0\nfor i in cnt:\nans += i*(i-1) // 2\n\nprint(ans)', 'S = input()\ns = S[::-1]\n\ncnt = [0]*2019\ncnt[0] = 1\nnumber = 0\nd = 1\n\nfor i in s:\n number += int(i)*d\n cnt[number % 2019] += 1\n d *= 10\n d = d % 2019\n\nans = 0\nfor i in cnt:\n ans += i*(i-1) // 2\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s373164489', 's038855406'] | [9032.0, 9284.0] | [21.0, 105.0] | [205, 209] |
p02702 | u863964720 | 2,000 | 1,048,576 | 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. | ['import collections\n\ndef ConZ(i):\n z_num = i+int(i*(i-1)/2)\n return z_num\ndef ConN(i):\n n_num = int(i*(i-1)/2)\n return n_num\n\nS = input()[::-1]\nketa = 1\nA_num = 0\nx = 0\nmod = [0]*2019\nmodcount = []\nfor i in range(len(S)):\n A_num += (int(S[i:i+1])*keta)%2019\n if A_num >= 2019:\n A_num = A_num%2019\n mod[A_num] +=1\n keta*=10\nprint(mod[0])\nx += ConZ(mod[0])\ndel mod[0]\nc = collections.Counter(mod)\nprint(mod)\nmodcount = list(c.items())\nprint(modcount)\nfor j in range(len(modcount)):\n if modcount[j][0]>=2:\n x+=ConN(modcount[j][0])*modcount[j][1]\nprint(x)', 'import collections\n\ndef ConZ(i):\n z_num = i+int(i*(i-1)/2)\n return z_num\ndef ConN(i):\n n_num = int(i*(i-1)/2)\n return n_num\n\nS = input()[::-1]\nketa = 1\nA_num = 0\nx = 0\nmod = [] \nmodcount=[]\nfor i in range(len(S)):\n A_num += (int(S[i:i+1])*keta)%2019\n if A_num >= 2019:\n A_num = A_num%2019\n mod.append(A_num) \n keta*=10\n\nc = collections.Counter(mod)\nx += ConZ(mod.count(0))\nmodcount=list(c.values())\nprint(mod)\nprint(modcount)\nk = 0\n\nfor j in range(len(modcount)):\n if modcount[j] >=2:\n x+=ConN(modcount[j])\nprint(x)', 'from operator import mul\nfrom functools import reduce\nimport numpy as np\n#def ConZ(i):\n \n \n#def ConN(i):\n \n #return n_num\n\ndef cmb(n):\n over = reduce(mul, range(n, n - 2, -1))\n under = reduce(mul, range(1,2 + 1))\n return over // under\n\n\nS = input()[::-1]\nketa = 1\nA_num = 0\nx = 0\nmod = np.array([0]*2019)\nmod[0] += 1\nfor i in range(len(S)):\n A_num += int(S[i:i+1])*keta\n if A_num >= 2019:\n A_num = A_num%2019\n mod[A_num] +=1\n #keta*=10\n keta = keta * 10 % 2019\nprint(mod)\n#x += ConZ(mod[0])\n\n\n#for j in range(len(mod)):\n #x+=cmb(mod[j])\n#print(x)\nprint(int(np.sum(mod* (mod - 1) /2)))\n', 'from operator import mul\nfrom functools import reduce\nimport numpy as np\ndef ConZ(i):\n z_num = i+int(i*(i-1)/2)\n return z_num\n#def ConN(i):\n \n #return n_num\ndef cmb(n):\n over = reduce(mul, range(n, n - 2, -1))\n under = reduce(mul, range(1,2 + 1))\n return over // under\n\n\nS = input()[::-1]\nketa = 1\nA_num = 0\nx = 0\nmod = np.array([0]*2019)\nfor i in range(len(S)):\n A_num += int(S[i:i+1])*keta\n if A_num >= 2019:\n A_num = A_num%2019\n mod[A_num] +=1\n #keta*=10\n keta = keta * 10 % 2019\n#print(mod)\nx += ConZ(mod[0])\n\n\nfor j in range(1,len(mod)):\n x+=cmb(mod[j])\nprint(x)\n#print(int(np.sum(mod* (mod - 1) /2)))\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s245793933', 's284510156', 's739280832', 's378519219'] | [9632.0, 11900.0, 27288.0, 27176.0] | [2206.0, 2206.0, 279.0, 289.0] | [591, 556, 703, 687] |
p02702 | u871934301 | 2,000 | 1,048,576 | 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. | ['import collections\nS=input()\nl=len(S)\nT=0\nA=[0]*2019\nA[0]=1\nfor i in range(l):\n T+=int(S[l-i-1])*(10**i)\n A[T%2019]+=1\nans = 0\nfor cnt in A:\n ans += cnt * (cnt - 1) // 2\nprint(cnt)\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', 'import collections\nS=input()\nl=len(S)\nT,d=0,1\nA=[0]*2019\nA[0]=1\nfor i in range(l):\n T+=int(S[l-i-1])*d\n d*=10\n T%=2019\n d%=2019\n A[T]+=1\nB=map(lambda x: x*(x-1)//2,A)\nprint(sum(B))\n\n\n\n\n\n\n\n\n\n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s947856669', 's187068575'] | [9748.0, 9592.0] | [2206.0, 134.0] | [204, 208] |
p02702 | u872538555 | 2,000 | 1,048,576 | 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. | [' = input()[::-1]\n\ncounts = [0] * 2019\ncounts[0] = 1\n\nnum, d = 0, 1\n\nfor char in s:\n num += int(char) * d\n num %= 2019\n counts[num] += 1\n d *= 10\n\nans = 0\nfor cnt in counts:\n ans += cnt * (cnt - 1) // 2\n \nprint(ans)', 's = input()[::-1]\n\ncounts = [0] * 2019\ncounts[0] = 1\n\nnum, d = 0, 1\n\nfor char in s:\n num += int(char) * d\n num %= 2019\n d *= 10\n d %= 2019\n counts[num] += 1\n \nans = 0\nfor cnt in counts:\n ans += cnt * (cnt - 1) // 2\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s526475269', 's448201986'] | [8936.0, 9380.0] | [21.0, 110.0] | [232, 247] |
p02702 | u875291233 | 2,000 | 1,048,576 | 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. | ['print(len(set(open(0).read().split()))-1)', '# coding: utf-8\n# Your code here!\nimport sys\nreadline = sys.stdin.readline\nread = sys.stdin.read\n\n\ns = input()\n\nMOD = 2019\nd = [0]*MOD\nd[0] = 1\nr = 0\nt = 1\nfor i in reversed(s):\n r += int(i)*t\n r %= MOD\n t *= 10\n t %= MOD\n d[r] += 1\n \nprint(sum(i*(i-1)//2 for i in d))\n\n \n\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s061495743', 's854057820'] | [9200.0, 9360.0] | [23.0, 116.0] | [41, 296] |
p02702 | u875541136 | 2,000 | 1,048,576 | 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. | ["import collections\nS = input()\nN = len(S)\nM = [0]\nfor i in range(N):\n M.append(int(S[:i+1] + '0' * (N-1-i)) % 2019)\ncount = collections.Counter(M)\nprint(count)\nprint(sum([c*(c-1)//2 for c in count.values()]))", 'import collections\nS = input()\nN = len(S)\nM = [0]\nmod = 0\nten = 1\nfor s in S[::-1]:\n mod += (int(s) * ten) % 2019\n mod %= 2019\n M.append(mod)\n ten *= 10\n ten %= 2019 \ncount = collections.Counter(M)\nprint(sum([c*(c-1)//2 for c in count.values()]))'] | ['Wrong Answer', 'Accepted'] | ['s017973924', 's861868119'] | [9856.0, 16652.0] | [2206.0, 139.0] | [209, 251] |
p02702 | u876438858 | 2,000 | 1,048,576 | 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. | ['import sys\nfrom math import sqrt\nfrom collections import Counter, defaultdict, deque\n\ninput = sys.stdin.readline\nsys.setrecursionlimit(10 ** 6)\n\n\ndef I():\n return int(input())\n\n\ndef MI():\n return map(int, input().split())\n\n\ndef LI():\n return list(MI())\n\n\ndef LIN(n: int):\n return [I() for _ in range(n)]\n\n\ninf = float("inf")\nmod = 10 ** 9 + 7\n\n\ndef main():\n s = input().rstrip()\n\n li = {}\n for i in range(6, 1000):\n n = str(19 * i)[-3:]\n if not ("0" in n):\n li[i] = n\n\n print(li)\n lens = len(s)\n c = 0\n for k, v in li.items():\n for pos in range(lens + 1):\n if s[:pos].endswith(v):\n if s[:pos].endswith(str(2019 * k)):\n c += 1\n\n print(c)\n\n\nif __name__ == "__main__":\n main()\n', '#!/usr/bin/env python3\nimport sys\nimport numpy as np\n\ninput = sys.stdin.readline\n\n\ndef ST():\n return input().rstrip()\n\n\ndef I():\n return int(input())\n\n\ndef MI():\n return map(int, input().split())\n\n\ndef LI():\n return list(MI())\n\n\nS = ST()\n\ncnt = np.zeros(2019)\ncnt[0] = 1\nres = 0\ntmp = 1\nfor s in S[::-1]:\n res += int(s) * tmp\n res %= 2019\n cnt[res] += 1\n tmp *= 10\n tmp %= 2019\n\nans = 0\nfor c in cnt[cnt >= 2]:\n ans += c * (c - 1) // 2\n\nprint(int(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s137686478', 's155442152'] | [9648.0, 27308.0] | [2206.0, 278.0] | [790, 483] |
p02702 | u878129968 | 2,000 | 1,048,576 | 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. | ['s = input()\nn = len(s)\nsums_from_first_mod = [0] * (n+1)\nfor i in range(1,n+1):\n sums_from_first_mod[i] = (sums_from_first_mod[i-1] + int(s[i-1])) % 3\n# print(sums_from_first_mod)\nind0 = [i for i, x in enumerate(sums_from_first_mod) if x == 0]\nind1 = [i for i, x in enumerate(sums_from_first_mod) if x == 1]\nind2 = [i for i, x in enumerate(sums_from_first_mod) if x == 2]\nindices = [ind0, ind1, ind2] \nprint(indices)\ncnt = 0\nfor num in range(3):\n for i in indices[num]:\n for j in indices[num]:\n if j >= i+4:\n if int(s[i:j]) % 673 == 0:\n cnt += 1\nprint(cnt)', 's = input()\nn = len(s)\np = 2019\nans = 0\n\nnum_rem = [0] * p\nt = 1\nmod = 0\nnum_rem[mod] = 1\nfor i in range(n):\n mod = (mod + int(s[-i-1])*t)%p\n num_rem[mod] += 1\n t = (10*t)%p\nfor m in num_rem:\n ans += (m*(m-1))//2\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s684179899', 's797090407'] | [21780.0, 9200.0] | [2206.0, 124.0] | [617, 235] |
p02702 | u884601206 | 2,000 | 1,048,576 | 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. | ['s=input()\ns=s[::-1]\nn=len(s)\ncount=[0]*2019\nnum,d=0,1\n\nfor i in s:\n num+=int(i)*d\n num%=2019\n d*=10\n d%=2019\n count[num]+=1\n\nans=0\nfor i in count:\n ans+=i*(i-1)//2\n \nprint(ans)\n\n ', 's=input()\ns=s[::-1]\nn=len(s)\ncount=[0]*2019\ncount[0]=1\nnum,d=0,1\n\nfor i in s:\n num+=int(i)*d\n num%=2019\n d*=10\n d%=2019\n count[num]+=1\n\nans=0\nfor i in count:\n ans+=i*(i-1)//2\n \nprint(ans)\n\n '] | ['Wrong Answer', 'Accepted'] | ['s075757994', 's428679828'] | [9256.0, 9276.0] | [116.0, 112.0] | [187, 198] |
p02702 | u884982181 | 2,000 | 1,048,576 | 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. | ['import sys\nfrom collections import deque\nfrom collections import defaultdict\nimport math\nimport copy\n#input = sys.stdin.readline\nsys.setrecursionlimit(20000000)\ns = input()\ns = s[::-1]\nn = len(s)\ndp = [0]*(n+1)\nk = 1\na = defaultdict(int)\na[0]+=1\nfor i in range(n):\n dp[i] = (dp[i-1]+int(s[i])*k)%2019\n k*=10\n k%=2019\n a[dp[i]] += 1\nans = 0\nfor i in a.keys():\n ans += a[i]*(a[i]-1)/2\nprint(ans)\n', 'import sys\nfrom collections import deque\nfrom collections import defaultdict\nimport math\nimport copy\n#input = sys.stdin.readline\nsys.setrecursionlimit(20000000)\ns = input()\ns = s[::-1]\nn = len(s)\ndp = [0]*(n+1)\nk = 1\na = defaultdict(int)\na[0]+=1\nfor i in range(n):\n dp[i] = (dp[i-1]+int(s[i])*k)%2019\n k*=10\n k%=2019\n a[dp[i]] += 1\nans = 0\nfor i in a.keys():\n ans += a[i]*(a[i]-1)/2\nprint(int(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s647434729', 's228050397'] | [16896.0, 16864.0] | [165.0, 149.0] | [399, 404] |
p02702 | u888092736 | 2,000 | 1,048,576 | 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. | ['from collections import Counter\nfrom operator import mul\nfrom functools import reduce\n\n\ndef cmb(n, r):\n r = min(n - r, r)\n if r == 0:\n return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1, r + 1))\n return over // under\n\n\ns = input()[::-1]\nacc = [int(s[0])]\nfor i, c in enumerate(s[1:], 1):\n print(10 ** i)\n acc.append((acc[-1] + pow(10, i, 2019) * int(c)) % 2019)\n\nans = 0\nfor k, v in Counter(acc).items():\n if k == 0:\n ans += v\n elif v > 1:\n ans += cmb(v, 2)\nprint(ans)\n', 'from collections import defaultdict\n\n\ndef solve(li):\n cnt = defaultdict(int)\n cnt[0] = 1\n rem = 0\n ans = 0\n for k, i in enumerate(li):\n rem = (rem + i * pow(10, k, 2019)) % 2019\n ans += cnt[rem]\n cnt[rem] += 1\n return ans\n\n\nprint(solve(map(int, input()[::-1])))\n'] | ['Wrong Answer', 'Accepted'] | ['s653442968', 's487772746'] | [32548.0, 9736.0] | [2275.0, 315.0] | [545, 301] |
p02702 | u888337853 | 2,000 | 1,048,576 | 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. | ["import sys\n\n# import re\nimport math\nimport collections\n\nimport bisect\nimport itertools\nimport fractions\n# import functools\nimport copy\nimport heapq\nimport decimal\n# import statistics\nimport queue\n\n# import numpy as np\n\nsys.setrecursionlimit(10000001)\nINF = 10 ** 16\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n s = input()\n\n cnt = [0 for _ in range(2019)]\n cnt[0] += 1\n dec = 1\n num = 0\n for i in reversed(s):\n num += int(i) * dec\n num %= 2019\n dec *= 10\n dec %= 10\n cnt[num] += 1\n\n ans = 0\n for c in cnt:\n ans += c * (c - 1) // 2\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\n\n# import re\nimport math\nimport collections\n\nimport bisect\nimport itertools\nimport fractions\n# import functools\nimport copy\nimport heapq\nimport decimal\n# import statistics\nimport queue\n\n# import numpy as np\n\nsys.setrecursionlimit(10000001)\nINF = 10 ** 16\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n s = sys.stdin.readline()\n\n cnt = [0 for _ in range(2019)]\n cnt[0] += 1\n dec = 1\n num = 0\n for i in reversed(s):\n num += int(i) * dec\n num %= 2019\n dec *= 10\n cnt[num] += 1\n\n ans = 0\n for c in cnt:\n ans += c * (c - 1) // 2\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\n\n# import re\nimport math\nimport collections\n\nimport bisect\nimport itertools\nimport fractions\n# import functools\nimport copy\nimport heapq\nimport decimal\n# import statistics\nimport queue\n\n# import numpy as np\n\nsys.setrecursionlimit(10000001)\nINF = 10 ** 16\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n s = input()\n\n cnt = [0 for _ in range(2019)]\n cnt[0] += 1\n dec = 1\n num = 0\n for i in reversed(s):\n num += int(i) * dec\n num %= 2019\n dec *= 10\n dec %= 2019\n cnt[num] += 1\n\n ans = 0\n for c in cnt:\n ans += c * (c - 1) // 2\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s010194503', 's124494033', 's368577298'] | [10888.0, 10848.0, 10876.0] | [86.0, 33.0, 95.0] | [840, 835, 842] |
p02702 | u892305365 | 2,000 | 1,048,576 | 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. | ['s = list(input())\nmods = [0]*(len(s))\ncountRemainder = [0] * 2019\ncnt = 0\n\nfor i in range(len(s)):\n if i == 0:\n mods[0] = int(s[-1])\n else:\n mods[i] = mods[i-1] + (10**i % 2019) * int(s[len(s) - i - 1])\n countRemainder[mods[i]] += 1\n\ncountRemainder[0] += 1\n\nfor i in range(2019):\n cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)\n\nprint(cnt)\n\n', 's = list(input())\nmods = [0]*(len(s))\ncountRemainder = [0] * 2019\ncnt = 0\n\n\nm = 1\nmod = 0\nfor i in range(len(s)):\n mod += int(s[len(s) - i - 1]) * m\n\n mod %= 2019\n m *= 10\n m %= 2019\n\n countRemainder[mod] += 1\n\ncountRemainder[0] += 1\n\nfor i in range(2019):\n cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)\n\nprint(cnt)\n\n'] | ['Runtime Error', 'Accepted'] | ['s450178980', 's160171658'] | [11620.0, 11884.0] | [26.0, 148.0] | [380, 349] |
p02702 | u896741788 | 2,000 | 1,048,576 | 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. | ['s=input()\na=0\nl=[0]*2019\nfor i in list(s):\n a=(a*10+int(i))%2019\n l[a]+=1\nans=0\nfor i in l:\n ans+=(i-1)*i//2\nprint(ans+l[0])\n', 's=input()\na=0\nnow=1\nl=[0]*2019\nfor i in list(s)[::-1]:\n a=(a+now*int(i))%2019\n l[a]+=1\n\n now*=10\n now%=2019\nans=0\nfor i in l:\n ans+=(i-1)*i//2\nprint(ans+l[0])'] | ['Wrong Answer', 'Accepted'] | ['s964854534', 's715884989'] | [10344.0, 12172.0] | [83.0, 104.0] | [134, 173] |
p02702 | u901582103 | 2,000 | 1,048,576 | 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. | ['s=input()\nn=len(s)\nc=0\nd=0\nfor i in range(n):\n for j in range(i+1,n+1):\n if int(s[i:j])%2019==0:\n c+=1\n print(s[i:j])\n d+=1\nprint(c)', 'from collections import Counter\ns=input()\nn=len(s)\nMOD=2019\nL=[0]\nfor i in range(n):\n l=(int(s[n-1-i])*pow(10,i,MOD)+L[i])%MOD\n L.append(l)\nLC=Counter(L)\nr=0\nfor v in LC.values():\n r+=v*(v-1)//2\nprint(r)'] | ['Wrong Answer', 'Accepted'] | ['s466562197', 's186930651'] | [12128.0, 16740.0] | [2221.0, 354.0] | [171, 212] |
p02702 | u908763441 | 2,000 | 1,048,576 | 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. | ['\nimport numpy as np\n\ns = input()[::-1]\nlength = len(s)\na = np.zeros(length, dtype=int)\nd = np.zeros(length, dtype=int)\nans = np.zeros(2019, dtype=int)\nx = 1\n\na[0] = int(s[0])\nd[0] = a[0]\nans[0] = 1\nans[d[0]] += 1\n\nfor i in range(1, length):\n a[i] = int(s[i]) * x % 2019\n d[i] = (d[i-1] + a[i]) % 2019\n ans[d[i]] += 1\n x = x * 10 % 2019\n\nprint(int(sum([ans[i] * (ans[i]-1) for i in range(2019)]) / 2))', '#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3\n\nS = input()\nsize = len(S)\nL = [0] * 2019\n\ntmp = int(S[size-1]) \nL[0] = 1\nL[tmp] += 1\n\nfor i in reversed(range(size - 1)): の一つ手前からループを回す\n d = size - i \n n = int(S[i]) \n r = (n * (10 ** (d - 1))) % 2019 \n tmp = (tmp + r) % 2019\n \n L[tmp] += 1\n\nans = 0\nfor i in range(2019):\n tmp = L[i]\n if (tmp > 1):\n ans += tmp * (tmp - 1) // 2\n\nprint(ans)\n', '\n\n\nS = input()\nsize = len(S)\nL = [0] * 2019 \n\n\ntmp = int(S[size - 1]) \ntmp_r = 1 \nL[0] += 1 \n\nL[tmp] += 1\n\n\nfor i in reversed(range(size - 1)): \n n = int(S[i]) \n \n tmp_r = (tmp_r * 10) % 2019\n r = (n * tmp_r) % 2019 \n \n tmp = (tmp + r) % 2019\n L[tmp] += 1 \n\nans = 0\nfor i in range(2019):\n tmp = L[i]\n if (tmp > 1):\n ans += tmp * (tmp - 1) // 2\n \n\nprint(ans)\n'] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s340711073', 's616621925', 's999157309'] | [30328.0, 9268.0, 9312.0] | [439.0, 2206.0, 128.0] | [471, 612, 1692] |
p02702 | u909616675 | 2,000 | 1,048,576 | 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. | ['s=int(input())\nn=len(str(s))\na=[0]*2019\nans=0\nk=s%2019\na[k]+=1\nfor i in range(n):\n s=int(s*0.1)\n k=s%2019\n a[k]+=1\nfor i in range(2019):\n ans+=a[i]*(a[i]-1)/2\n\nprint(int(ans))', 's=input()\nn=len(s)\na=[0]*2019\na[0]=1\nk=0\nans=0\nmod=1\nfor i in range(n-1,-1,-1):\n k=(k+int(s[i])*mod)%2019\n mod=(mod*10)%2019\n a[k]+=1\nfor i in a:\n ans+=i*(i-1)*0.5\n\nprint(int(ans))'] | ['Runtime Error', 'Accepted'] | ['s959635390', 's766837278'] | [9276.0, 9288.0] | [717.0, 109.0] | [179, 184] |
p02702 | u914802579 | 2,000 | 1,048,576 | 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. | ['a=2019\nfor i in range(int(a**0.5)):\n if a%i==0:\n print(i)\n break', 's = input()\np=2019;n=len(s)\ndigit_rm = [0 for _ in range(n)]\nfor i in range(n):\n\tdigit_rm[i] = (int(s[n-1-i]) * pow(10, i, p) ) % p\n\nremain = [0 for _ in range(n)]\nfor i in range(n):\n\tif i == 0:\n\t\tremain[i] = digit_rm[i]\n\telse:\n\t\tremain[i] = (remain[i-1] + digit_rm[i]) % p\npcnt = [0 for _ in range(p)]\nfor i in remain:\n\tpcnt[i] += 1\nans = pcnt[0]\nfor num in pcnt:\n\tif num != 0:\n\t\tans += num * (num - 1) // 2\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s323270630', 's530963677'] | [9408.0, 23816.0] | [21.0, 418.0] | [71, 419] |
p02702 | u922952729 | 2,000 | 1,048,576 | 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. | ['S=input()\nlength=len(S)\nS=int(S)\nprint(0)', "from functools import lru_cache\n\n\n\nS=input()\ncount=[0 for i in range(2019)]\nlength=len(S)\n#S=int(S)\nS=S+'0'\nS=S[::-1]\n_S=0\n\nbase=1\nfor i,s in enumerate(S):\n _S=base*int(s)+_S\n count[_S%2019]+=1\n base*=10\n base=base%2019\n _S=_S%2019\n\n\n\nretval=0\nfor key in range(2019):\n retval+=count[key]*(count[key]-1)//2\n\n\nprint(retval)\n"] | ['Wrong Answer', 'Accepted'] | ['s490691718', 's932204149'] | [9240.0, 9748.0] | [205.0, 132.0] | [41, 340] |
p02702 | u935642171 | 2,000 | 1,048,576 | 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. | ['s = input()\nmul = set(str(2019*i) for i in range(1,100))\nans = 0\nfor m in mul:\n ans += s.count(m)\nprint(ans)', 'S = input()[::-1]\nans = 0\nmods = [0] * 2019\nmods[0] = 1\ncurrent = 0\nx = 1\nfor s in S:\n current = (current + x * int(s)) % 2019\n ans += mods[current % 2019]\n mods[current % 2019] += 1\n x = x * 10 % 2019\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s625077708', 's758635406'] | [9120.0, 9124.0] | [55.0, 141.0] | [109, 216] |
p02702 | u961674365 | 2,000 | 1,048,576 | 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. | ['s=input()\nn=len(s)\nrst=[0 for j in range(2019)]\nx=0\nans=0\nfor i in range(n):\n y=(int(s[n-1-i])*(10**i))%2019\n x+=y\n if x>=2019:\n x%=2019\n print(x,y)\n ans+=rst[x]\n rst[x]+=1\nif rst[0]==1:\n ans+=1\n\nprint(ans)', 's=input()\nn=len(s)\nrst=[0 for j in range(2019)]\nrst[0]=1\nx=0\nans=0\ndrst=1\nfor i in range(n):\n y=(int(s[n-1-i])*drst)%2019\n drst=(drst*10)%2019\n x+=y\n if x>=2019:\n x%=2019\n #print(x,y,drst)\n ans+=rst[x]\n rst[x]+=1\n#if rst[0]==1:\n #ans+=0\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s801753575', 's419202249'] | [9516.0, 9364.0] | [2206.0, 158.0] | [234, 279] |
p02702 | u969708690 | 2,000 | 1,048,576 | 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. | ['a=0\nS=int(input())\nfor i in range(N-3):\n for j in range(i+3,N+1):\n A=int(float(S[i:j+1]))\n if A%2019==0:\n a=a+1\nprint(a)', 'ans=0\nS=input()\na=len(S)\nk=0\nc=dict()\nmod=2019\ns=1\nc[0]=1\nfor i in range(a):\n k+=(s*int(S[a-i-1]))\n k%=mod\n s*=10\n s%=mod\n if k in c:\n c[k]+=1\n else:\n c[k]=1\nfor i in c:\n ans+=c[i]*(c[i]-1)//2\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s130629809', 's359002708'] | [9148.0, 9192.0] | [203.0, 157.0] | [132, 216] |
p02702 | u971124021 | 2,000 | 1,048,576 | 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. | ["from collections import Counter\nS = input()\nS = S + '0'\nmod = 2019\np = [-1] * len(S)\nr = 0\nd = 1\nfor i,s in enumerate(S[::-1]):\n t = int(s)%mod\n r += t*d\n r %= mod\n d = d*10%mod\n p[i] = r\n\nans = 0\nc = Counter(p)\nfor k,n in c.most_common():\n if n > 1 ans n%2 == 0:\n ans += n//2\n else:break\nprint(ans)", 's = input()\nn = (int(s)//2019) + 1\nans = 0\np = [0] * (n+1)\nfor i in range(n+1):\n p[i] = (2019 * i)\n\nfor j in p:\n ss = s\n while len(ss) > 0:\n idx = ss.find(str(j))\n if idx == -1:\n break\n else:\n ans += 1\n ss = ss[idx+1:]\n\n\nprint(ans)\n', 's = input()\nn = (int(s)//2019) + 1\nans = 0\np = [0] * (n+1)\nfor i in range(1,n+1):\n p[i] = (2019 * i)\n\nfor j in p:\n ss = s\n while len(ss) > 0:\n idx = ss.find(str(j))\n if idx == -1:\n break\n else:\n ans += 1\n ss = ss[idx+1:]\n\nprint(ans)\n', 's = input()\nn = len(s)\nN = (int(s)//2019) + 1\nans = 0\nP = [0] * N\nfor i in range(N):\n P[i] = str(i*2019)\n\nfor p in P:\n k = s.find(p)\n if k != -1:\n ans += 1\n while k >= 0:\n k = s[k+1:].find(p)\n if k != -1:ans += 1\n\nprint(ans)', "from collections import Counter\nS = input()\nS = S + '0'\nmod = 2019\np = [-1] * len(S)\nr = 0\nd = 1\nfor i,s in enumerate(S[::-1]):\n t = int(s)%mod\n r += t*d\n r %= mod\n d = d*10%mod\n p[i] = r\n\nans = 0\nc = Counter(p)\nfor k,n in c.most_common():\n if n > 1:\n ans += n*(n-1)//2\n else:break\nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s380879729', 's479262528', 's829488064', 's854730207', 's160607426'] | [8872.0, 288820.0, 288524.0, 513300.0, 16604.0] | [25.0, 2213.0, 2216.0, 2220.0, 151.0] | [309, 259, 260, 243, 302] |
p02702 | u975445930 | 2,000 | 1,048,576 | 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. | ['S = input()\nT = [0]*2019\nT[0]=1\nt = 0\nans = 0\ndig = 1\nfor i in range(n):\n t = (t + (int(S[-i-1]))*dig)%2019\n dig = dig*10%2019\n T[t] += 1\nfor j in T:\n ans +=int(j*(j-1)/2)\nprint(ans)', 'S = input()\nT = [0]*2019\nT[0]=1\nt = 0\nans = 0\ndig = 1\nfor i in range(n):\n t = (t + (int(S[-i-1]))*dig)%2019\n dig = (dig*10)%2019\n T[t] += 1\nfor j in T:\n ans +=int(j*(j-1)/2)\nprint(ans)', 'S = input()\nT = [0]*2019\nT[0]=1\nt = 0\nans = 0\ndig = 1\nfor i in range(len(S)):\n t = (t + (int(S[-i-1]))*dig)%2019\n dig = (dig*10)%2019\n T[t] += 1\nfor j in T:\n ans +=int(j*(j-1)/2)\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s272032781', 's749327407', 's707802946'] | [9280.0, 9300.0, 9236.0] | [22.0, 23.0, 114.0] | [194, 196, 201] |
p02702 | u977490411 | 2,000 | 1,048,576 | 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. | ['S = input()\n\nc = [0] * 2019\nfor i in range(len(S)):\n c[int(S[i:])%2019] += 1\n\nans = 0\nfor m in c:\n ans += m * (m - 1) / 2\n\nprint(int(ans)) ', 'S = input()\n\nmod = [0] * 2019\nmod[0] = 1\ndigit = 1\ntemp = 0\n \nfor i in S[::-1]:\n temp = (temp + digit * int(i)) % 2019\n mod[temp] += 1\n digit = (digit * 10) % 2019\n\nans = 0\nfor m in mod:\n ans += m * (m - 1) // 2\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s641856364', 's107571120'] | [9388.0, 9236.0] | [2206.0, 97.0] | [145, 235] |
p02702 | u988661952 | 2,000 | 1,048,576 | 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. | ['S=input()\nn=len(S)\ndef T(i):\n if i == 0:\n return 0\n else:\n i-=1\n return T(i)+(10**i)*int(S[n-1-i])\ns=[0]*2018\nfor j in range(1,n+1):\n print(T(j))\n m=T(j)%2019\n s[m]+=1\n\nc=s[0]\n\nfor m in s:\n c += m*(m-1)/2\n\nprint(int(c))', 'S=input()\nn=len(S)\ndef T(i):\n if i == 0:\n return 0\n else:\n i-=1\n return T(i)+(10**i)*int(S[n-1-i])\ns=[0]*2019\nfor j in range(1,n+1):\n print(T(j))\n m=T(j)%2019\n s[m]+=1\n\nc=s[0]\n\nfor m in s:\n c += m*(m-1)/2\n\nprint(int(c))\n', 'S=input()\nn=len(S)\ndef T(i):\n if i == 0:\n return 0\n else:\n i-=1\n return T(i)+(10**i)*int(S[n-1-i])\ns=[0]*2018\nfor j in range(1,n+1):\n print(T(j))\n m=T(j)%2019\n s[m]+=1\n\nc=s[0]\n\nfor m in s:\n c += m*(m-1)/2\n\nprint(int(c))', 's = input()\np = 2019\nn = 0\nans = 0\nmods = [0]*p\nmods[0] = 1\nfor i, j in enumerate(reversed(s)):\n n += int(j)*pow(10, i, p)\n n %= p\n mods[n] += 1\nfor i in mods:\n ans += i*(i-1)//2\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s268376842', 's609818135', 's768194390', 's674820330'] | [9972.0, 10144.0, 10136.0, 9148.0] | [1460.0, 1461.0, 1466.0, 327.0] | [258, 259, 258, 193] |
p02702 | u990653216 | 2,000 | 1,048,576 | 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. | ['import collections\nimport sys\nS = input()[::-1]\n \nMOD=2019\nX = [0]\nfor i, s in enumerate(S):\n X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)\n \nc = collections.Counter(X)\nans = 0\nfor v in C.values():\n ans += v * (v - 1) // 2\nprint(ans)', 'import collections\nimport sys\nS = input()[::-1]\nif len(S)<=4:\n print(0)\n sys.exit()\n \nMOD=2019\nX = [0]\nfor i, s in enumerate(S):\n X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)\n \nc = collections.Counter(X)\nans = 0\nfor v in C.values():\n ans += v * (v - 1) // 2\nprint(ans)', 'import collections\nimport sys\nS = input()[::-1]\n \nMOD=2019\nX = [0]\nfor i, s in enumerate(S):\n X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)\n \nc = collections.Counter(X)\nans = 0\nfor v in c.values():\n ans += v * (v - 1) // 2\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s865880277', 's968882006', 's202990742'] | [16580.0, 16556.0, 16608.0] | [326.0, 336.0, 329.0] | [242, 284, 242] |
p02702 | u996665352 | 2,000 | 1,048,576 | 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. | ['s = input()\nc = 0\nfor i in range(len(s)):\n for j in range(i+4,len(s)+1):\n a = int(s[i:j])\n if a>=2019 and a%3==0 a%673==0:\n c += 1\nprint(c)', 's = input()\nc = 0\nfor i in range(len(s)):\n for j in range(i+4,len(s)+1):\n a = int(s[i:j])\n print(a)\n if a>2019:\n if a%2019==0:\n c+=1\nprint(c)', 's = input()\nlen_s = len(s)\npre = 0\nmod = [0]*2019\nmod[0]=1\nx = 1\nfor i in range(len_s):\n pre = (x*int(s[len_s-i-1])+pre)%2019\n mod[pre] += 1\n x *= 10\n x %= 2019\nprint(sum([m*(m-1)//2 for m in mod]))'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s053064859', 's526342367', 's659512377'] | [9028.0, 27496.0, 9280.0] | [26.0, 2325.0, 122.0] | [167, 191, 210] |
p02703 | u075595666 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ['import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nfrom heapq import heappush, heappop\n\nN,M,S = map(int,readline().split())\nABC = [list(map(int,readline().split())) for _ in range(M)]\nm = map(int,read().split())\nCD = list(zip(m,m))\n\ngraph = [[] for _ in range(N)]\nfor u,v,a,b in ABC:\n graph[u-1].append((v-1,a,b))\n graph[v-1].append((u-1,a,b))\n\ndef f():\n INF = 10 ** 18\n arrive = [False]*n\n ans = []\n qq = 2500\n dist = [[INF] * qq for _ in range(N)]\n dist[0][min(qq-1,S)] = 0\n q = [(0,min(qq-1,S),0)]\n while q:\n st,ss,v = heappop(q) \n if dist[v][ss] < st:\n continue\n if not arrive[v]:\n arrive[v] = True\n ans.append((v,st))\n if all(arrive):\n break\n c,d = CD[v]\n \n if ss < qq-1:\n ns = min(ss + c, qq-1)\n nt = st + d\n if dist[v][ns] > nt:\n dist[v][ns] = nt\n heappush(q,(nt,ns,v))\n \n for nex,g,tt in graph[v]:\n if ss-g < 0:\n continue\n dt = st + tt\n if dist[nex][ss-g] <= dt:\n continue\n dist[nex][ss-g] = dt\n heappush(q,(dt,ss-g,nex))\n return ans\n\nab = f()\nfrom operator import itemgetter\nab = sorted(ab,key=itemgetter(0))\nfor i in range(N-1):\n print(ab[i][1])', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nfrom heapq import heappush, heappop\n\nN,M,S = map(int,readline().split())\nABC = [list(map(int,readline().split())) for _ in range(M)]\nm = map(int,read().split())\nCD = list(zip(m,m))\n\ngraph = [[] for _ in range(N)]\nfor u,v,a,b in ABC:\n graph[u-1].append((v-1,a,b))\n graph[v-1].append((u-1,a,b))\n\ndef f():\n INF = 10 ** 18\n arrive = [False]*N\n ans = []\n qq = 2500\n dist = [[INF] * qq for _ in range(N)]\n dist[0][min(qq-1,S)] = 0\n q = [(0,min(qq-1,S),0)]\n while q:\n st,ss,v = heappop(q) \n if dist[v][ss] < st:\n continue\n if not arrive[v]:\n arrive[v] = True\n ans.append((v,st))\n if all(arrive):\n break\n c,d = CD[v]\n \n if ss < qq-1:\n ns = min(ss + c, qq-1)\n nt = st + d\n if dist[v][ns] > nt:\n dist[v][ns] = nt\n heappush(q,(nt,ns,v))\n \n for nex,g,tt in graph[v]:\n if ss-g < 0:\n continue\n dt = st + tt\n if dist[nex][ss-g] <= dt:\n continue\n dist[nex][ss-g] = dt\n heappush(q,(dt,ss-g,nex))\n return ans\n\nab = f()\nfrom operator import itemgetter\nab = sorted(ab,key=itemgetter(0))\nfor i in range(1,N):\n print(ab[i][1])'] | ['Runtime Error', 'Accepted'] | ['s383353538', 's222431402'] | [9368.0, 24304.0] | [21.0, 491.0] | [1401, 1401] |
p02703 | u375616706 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ['from collections import defaultdict\nimport heapq\nN,M,S = map(int,input().split())\nE=[list(map(int,input().split())) for _ in range(M)]\n\nC=[list(map(int,input().split())) for _ in range(N)]\n\nA_max=max([a for _,_,a,_ in E])\n\nD=defaultdict(lambda :[])\n\nfor u,v,a,b in E:\n u-=1;v-=1\n for from_a in range(A_max+1):\n if from_a-a<0:\n continue\n to_state_v=(v,from_a-a)\n from_state_u=(u,from_a)\n D[from_state_u].append((b,to_state_v))\n to_state_u=(u,from_a-a)\n from_state_v=(v,from_a)\n D[from_state_v].append((b,to_state_u))\n\nfor c,d in C:\n for n in range(N):\n for a in range(A_max+1):\n if a+c>A_max:\n continue\n to_state=(n,a+c)\n from_state=(n,a)\n D[from_state].append((d,to_state))\n\n\nstart=(0,max(A_max,S))\nQ=[(0,start)]\n\nDist=defaultdict(lambda :float(\'inf\'))\n\nDist[start]=0\n\nwhile Q:\n q = heapq.heappop(Q)\n cur_time,cur_state=q\n\n if Dist[cur_state]<cur_time:\n continue\n for cost,next_state in D[cur_state]:\n next_time = cost+cur_time\n\n if Dist[next_state]>next_time:\n Dist[next_state]=next_time\n heapq.heappush(Q,(next_time,next_state))\n\nfor dest in range(1,N):\n ans=float("inf")\n for a in range(A_max+1):\n state=(dest,a)\n ans=min(ans,Dist[state])\n print(ans)\n', 'from collections import defaultdict\nimport heapq\nN,M,S = map(int,input().split())\nE=[list(map(int,input().split())) for _ in range(M)]\n\nC=[list(map(int,input().split())) for _ in range(M)]\n\nA_max=max([a for _,_,a,_ in E])\n\nD=defaultdict(lambda :[])\n\nfor u,v,a,b in E:\n u-=1;v-=1\n for from_a in range(A_max+1):\n if from_a-a<0:\n continue\n to_state_v=(v,from_a-a)\n from_state_u=(u,from_a)\n D[from_state_u].append((b,to_state_v))\n to_state_u=(u,from_a-a)\n from_state_v=(v,from_a)\n D[from_state_v].append((b,to_state_u))\n\nfor c,d in C:\n for n in range(N):\n for a in range(A_max+1):\n if a+c>A_max:\n continue\n to_state=(n,a+c)\n from_state=(n,a)\n D[from_state].append((d,to_state))\n\n\nstart=(0,max(A_max,S))\nQ=[(0,start)]\n\nDist=defaultdict(lambda :float(\'inf\'))\n\nDist[start]=0\n\nwhile Q:\n q = heapq.heappop(Q)\n cur_time,cur_state=q\n\n if Dist[cur_state]<cur_time:\n continue\n for cost,next_state in D[cur_state]:\n next_time = cost+cur_time\n\n if Dist[next_state]>next_time:\n Dist[next_state]=next_time\n heapq.heappush(Q,(next_time,next_state))\n\nfor dest in range(1,N):\n ans=float("inf")\n for a in range(A_max+1):\n state=(dest,a)\n ans=min(ans,Dist[state])\n print(ans)\n', 'from collections import defaultdict\nimport heapq\nN,M,S = map(int,input().split())\nE=[list(map(int,input().split())) for _ in range(M)]\n\nC=[list(map(int,input().split())) for _ in range(M)]\n\nA_max=max([a for _,_,a,_ in E])\n\nD=defaultdict(lambda :[])\n\nfor u,v,a,b in E:\n u-=1;v-=1\n for from_a in range(a,A_max+1):\n state=(v,from_a-a)\n D[(u,from_a)].append((b,state))\n\nfor c,d in C:\n for i in range(N):\n if i+c>A_max:\n continue\n state=(u,i+c)\n D[(u,i)].append((d,state))\n\n\nstart=(0,max(A_max,S))\nQ=[(0,state)]\n\nDist=defaultdict(lambda :float(\'inf\'))\n\nDist[state]=0\n\nwhile Q:\n q = heapq.heappop(Q)\n cur_time,cur_state=q\n\n if Dist[cur_state]<cur_time:\n continue\n for cost,next_state in D[cur_state]:\n next_time = cost+cur_time\n\n if Dist[next_state]>next_time:\n Dist[next_state]=next_time\n heapq.heappush(Q,(next_time,next_state))\n\nfor dest in range(1,N):\n ans=float("inf")\n for a in range(A_max+1):\n state=(dest,a)\n ans=min(ans,Dist[state])\n print(ans)\n', 'from collections import defaultdict\nimport heapq\nN,M,S = map(int,input().split())\nE=[list(map(int,input().split())) for _ in range(M)]\n\nC=[list(map(int,input().split())) for _ in range(M)]\n\nA_max=max([a for _,_,a,_ in E])\n\nD=defaultdict(lambda :[])\n\nfor u,v,a,b in E:\n u-=1;v-=1\n for from_a in range(a,A_max+1):\n state=(v,from_a-a)\n D[(u,from_a)].append((b,state))\n\nfor c,d in C:\n for i in range(N):\n if i+c>A_max:\n continue\n state=(u,i+c)\n D[(u,i)].append((d,state))\n\n\nstart=(0,max(A_max,S))\nQ=[(0,state)]\n\nDist=defaultdict(lambda :float(\'inf\'))\n\nDist[state]=0\n\nwhile Q:\n q = heapq.heappop(Q)\n cur_time,cur_state=q\n\n if Dist[cur_state]<cur_time:\n continue\n for cost,next_state in D[cur_state]:\n next_time = cost+cur_time\n\n if Dist[next_state]>next_time:\n Dist[next_state]=next_time\n heapq.heappush(Q,(next_time,next_state))\n\nfor dest in range(1,N):\n ans=float("inf")\n for a in range(A_max+1):\n state=(dest,a)\n ans=min(ans,Dist[state])\n print(ans)\n', 'from collections import defaultdict\nimport heapq\nN,M,S = map(int,input().split())\nE=[list(map(int,input().split())) for _ in range(M)]\n\nC=[list(map(int,input().split())) for _ in range(N)]\n\nA_max=max([a for _,_,a,_ in E])*N\n\nD=defaultdict(lambda :[])\n\nfor u,v,a,b in E:\n u-=1;v-=1\n for from_a in range(A_max+1):\n if from_a-a<0:\n continue\n from_state_u=(u,from_a)\n to_state_v=(v,from_a-a)\n D[from_state_u].append((b,to_state_v))\n\n from_state_v=(v,from_a)\n to_state_u=(u,from_a-a)\n D[from_state_v].append((b,to_state_u))\n\nfor n,[c,d] in enumerate(C):\n for a in range(A_max+1):\n a_after=min(A_max,a+c)\n from_state=(n,a)\n to_state=(n,a_after)\n D[from_state].append((d,to_state))\n\n\nstart=(0,min(A_max,S))\nQ=[(0,start)]\n\nDist=defaultdict(lambda :float(\'inf\'))\n\nDist[start]=0\n\nwhile Q:\n q = heapq.heappop(Q)\n cur_time,cur_state=q\n\n if Dist[cur_state]<cur_time:\n continue\n for cost,next_state in D[cur_state]:\n next_time = cost+cur_time\n\n if Dist[next_state]>next_time:\n Dist[next_state]=next_time\n heapq.heappush(Q,(next_time,next_state))\n\nfor dest in range(1,N):\n ans=float("inf")\n for a in range(A_max+1):\n state=(dest,a)\n ans=min(ans,Dist[state])\n print(ans)\n'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s170953917', 's750393969', 's947580581', 's988503838', 's782233828'] | [27004.0, 26668.0, 9708.0, 9884.0, 155688.0] | [157.0, 154.0, 26.0, 29.0, 1947.0] | [1367, 1367, 1081, 1081, 1330] |
p02703 | u380524497 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ["def main(): \n import heapq\n \n n, m, s = map(int, input().split())\n if s >= 2500:\n s = 2499\n \n edges = [[] for _ in range(n)]\n for _ in range(m):\n from_, to, cost, time = map(int, input().split())\n edges[from_-1].append((to-1, cost, time))\n edges[to-1].append((from_-1, cost, time))\n \n banks = []\n for i in range(n):\n coin, time = map(int, input().split())\n banks.append((coin, time))\n \n INF = float('INF')\n DP = [[INF] * 2500 for _ in range(n)]\n DP[0][s] = 0\n ans = [INF] * n\n \n def push_todo(node, coin, time):\n if coin < 0:\n return\n if time >= DP[node][coin]:\n return\n heapq.heappush(todo, (time, node, coin))\n DP[node][coin] = time\n \n def charge(node, current_coin, current_time):\n coin, time = banks[node]\n new_coin = current_coin + coin\n if new_coin >= 2500:\n new_coin = 2499\n push_todo(node, new_coin, current_time+time)\n \n todo = [(0, 0, s)] # time, node, coin\n while todo:\n current_time, node, current_coin = heapq.heappop(todo)\n if current_time >= DP[node][current_coin]:\n continue\n \n if current_time < ans[node]:\n ans[node] = current_time\n \n charge(node, current_coin, current_time)\n \n for to, cost, time in edges[node]:\n push_todo(to, current_coin-cost, current_time+time)\n \n for a in ans[1:]:\n print(a)\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n import heapq\n\n n, m, s = map(int, input().split())\n\n edges = [[] for _ in range(n)]\n max_cost = 0\n for _ in range(m):\n from_, to, cost, time = map(int, input().split())\n edges[from_-1].append((to-1, cost, time))\n edges[to-1].append((from_-1, cost, time))\n if cost > max_cost:\n max_cost = cost\n\n banks = []\n for i in range(n):\n coin, time = map(int, input().split())\n banks.append((coin, time))\n\n max_coin = max_cost * (n-1)\n if s > max_coin:\n s = max_coin\n\n INF = float('INF')\n DP = [[INF] * (max_coin+1) for _ in range(n)]\n DP[0][s] = 0\n\n def push_todo(node, coin, time):\n if coin < 0:\n return\n if time >= DP[node][coin]:\n return\n heapq.heappush(todo, (time, node, coin))\n DP[node][coin] = time\n\n def charge(node, current_coin, current_time):\n coin, time = banks[node]\n new_coin = current_coin + coin\n if new_coin > max_coin:\n new_coin = max_coin\n push_todo(node, new_coin, current_time+time)\n\n todo = [(0, 0, s)] # time, node, coin\n while todo:\n current_time, node, current_coin = heapq.heappop(todo)\n if current_time > DP[node][current_coin]:\n continue\n\n charge(node, current_coin, current_time)\n\n for to, cost, time in edges[node]:\n push_todo(to, current_coin-cost, current_time+time)\n\n for node in range(1, n):\n print(min(DP[node]))\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s788140344', 's703572133'] | [10192.0, 23840.0] | [25.0, 494.0] | [1546, 1548] |
p02703 | u581187895 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ['\nfrom heapq import heappush, heappop\ndef resolve():\n INF = float(\'inf\')\n maxMoney = 2502\n\n def Dijkstra(g):\n ans = {}\n \n dp = [[INF] * (maxMoney + 1) for _ in range(N)]\n # (time, node, silver)\n hq = []\n heappush(hq, (0, 0, min(S, maxMoney)))\n while hq:\n t, v, s = heappop(hq)\n if t > dp[v][s]:\n continue\n if v not in ans:\n ans[v] = t\n if len(ans) == N:\n break\n\n # buy\n if s < maxMoney:\n c, d = CD[v]\n new_s = min(s + c, maxMoney)\n new_t = t + d\n if new_t < dp[v][new_s]:\n dp[v][new_s] = new_t\n heappush(hq, (new_t, v, new_s))\n\n # move\n for nv, cost, time in G[v]:\n \n if s < cost:\n continue\n \n new_s = s - cost\n new_t = t + time\n if new_t < dp[nv][new_s]:\n dp[nv][new_s] = new_t\n heappush(hq, (new_t, nv, new_s))\n return ans\n\n N, M, S = map(int, input().split())\n G = [[] for _ in range(N)]\n for _ in range(M):\n u, v, coin, tm = map(int, input().split())\n u, v = u - 1, v - 1\n G[u].append((v, coin, tm))\n G[v].append((u, coin, tm))\n CD = [list(map(int, input().split())) for _ in range(N)]\n\n ans = Dijkstra(G)\n for i in range(1, N):\n print(ans[i])\n\n\nif __name__ == "__main__":\n resolve(\n', '\nfrom heapq import heappush, heappop\ndef resolve():\n INF = float(\'inf\')\n maxMoney = 2502\n\n def Dijkstra(g):\n ans = {}\n \n dp = [[INF] * (maxMoney + 1) for _ in range(N)]\n # (time, node, silver)\n hq = []\n heappush(hq, (0, 0, min(S, maxMoney)))\n while hq:\n t, v, s = heappop(hq)\n if t > dp[v][s]:\n continue\n if v not in ans:\n ans[v] = t\n if len(ans) == N:\n break\n\n # buy\n if s < maxMoney:\n c, d = CD[v]\n new_s = min(s + c, maxMoney)\n new_t = t + d\n if new_t < dp[v][new_s]:\n dp[v][new_s] = new_t\n heappush(hq, (new_t, v, new_s))\n\n # move\n for nv, cost, time in G[v]:\n \n if s < cost:\n continue\n \n new_s = s - cost\n new_t = t + time\n if new_t < dp[nv][new_s]:\n dp[nv][new_s] = new_t\n heappush(hq, (new_t, nv, new_s))\n return ans\n\n N, M, S = map(int, input().split())\n G = [[] for _ in range(N)]\n for _ in range(M):\n u, v, coin, tm = map(int, input().split())\n u, v = u - 1, v - 1\n G[u].append((v, coin, tm))\n G[v].append((u, coin, tm))\n CD = [list(map(int, input().split())) for _ in range(N)]\n\n ans = Dijkstra(G)\n for i in range(1, N):\n print(ans[i])\n\n\nif __name__ == "__main__":\n resolve()\n'] | ['Runtime Error', 'Accepted'] | ['s108486968', 's915475374'] | [9132.0, 24404.0] | [24.0, 494.0] | [1776, 1777] |
p02703 | u678167152 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ["N, M, S = map(int, input().split()) \n\n# U = [0]*M \n# V = [0]*M\n\n\ntrain = [[] for _ in range(N)]\nfor i in range(M):\n u,v,a,b = map(int, input().split())\n train[u-1].append([v-1,a,b])\n train[v-1].append([u-1,a,b])\n\n\n\nfor i in range(N):\n c,d = map(int, input().split())\n train[i].append([i,d,c])\n\n \n\nfrom collections import deque\n\nans = []\nfor i in range(2,N):\n d = deque()\n d.append([0,S,0]) \n\n while len(d)>0:\n v,m,t = d.popleft()\n for vertex,money,time in train[v]:\n if vertex==v:\n m += money\n elif m<money:\n continue\n else:\n m -= money\n v = vertex\n d.append([v,m,t])\n if v == i:\n ans.append(t)\n break\nprint(*ans, sep='\\n')", "import heapq\ndef dijkstra_heap(N,S,Smax,edge):\n d = [float('inf')]*(10**4*N) \n used = [False]*(10**4*N)\n d[S] = 0\n used[S] = True\n edgelist = []\n \n \n for w,a in edge[0]:\n v,sil = a//10**4,a%10**4\n if v==0 and S+sil<=Smax:\n heapq.heappush(edgelist,[w,a+S]) \n elif v>0 and S-sil>=0:\n heapq.heappush(edgelist,[w,v*10**4+(S-sil)]) \n while len(edgelist):\n \n min_w,min_a = heapq.heappop(edgelist)\n min_v,min_sil = min_a//10**4,min_a%10**4\n \n if used[min_a]:\n continue\n d[min_a] = min_w\n used[min_a] = True\n for w,a in edge[min_v]:\n v,sil = a//10**4,a%10**4\n if v==min_v and min_sil+sil<=Smax and not used[a+min_sil]:\n heapq.heappush(edgelist,[min_w+w,a+min_sil])\n elif v!=min_v and min_sil-sil>=0 and not used[v*10**4+(min_sil-sil)]:\n heapq.heappush(edgelist,[min_w+w,v*10**4+(min_sil-sil)])\n return d\n\ndef solve():\n N, M, S = map(int, input().split())\n edge = [[] for _ in range(N)]\n amax = 0\n for i in range(M):\n u,v,a,b = map(int, input().split())\n amax = max(amax,a)\n edge[u-1].append([b,(v-1)*10**4+a])\n edge[v-1].append([b,(u-1)*10**4+a])\n Smax = (N-1)*amax\n S = min(S,Smax)\n for i in range(N):\n c,d = map(int, input().split())\n edge[i].append([d,i*10**4+c])\n D = dijkstra_heap(N,S,Smax,edge)\n ans = [0]*N\n for i in range(1,N):\n ans[i] = min(D[i*10**4:(i+1)*10**4])\n return ans[1:]\nprint(*solve(),sep='\\n')"] | ['Wrong Answer', 'Accepted'] | ['s229747432', 's162144215'] | [348928.0, 44744.0] | [2215.0, 1115.0] | [923, 1945] |
p02703 | u707498674 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ['from heapq import heappop, heappush\n\nimport sys\ndef input():return sys.stdin.readline().strip()\n\ndef main():\n N, M, S = map(int, input().split())\n to = [{} for _ in range(N)]\n for _ in range(M):\n u, v, a, b = map(int, input().split())\n u -= 1\n v -= 1\n to[u][v] = (a, b)\n to[v][u] = (a, b)\n info = tuple(tuple(map(int, input().split())) for _ in range(N))\n\n MAX_SILVER = 50 * (N-1)\n INF = 10 ** 18\n \n visited = [[False]*(MAX_SILVER+1) for _ in range(N)]\n cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]\n q = []\n S = min(S, MAX_SILVER)\n heappush(q, (0, 0, S)) \n\n while q:\n t, now, s = heappop(q)\n if visited[now][s]:continue\n visited[now][s] = True\n cost[now][s] = t\n\n # next node\n for nv, (a, b) in to[now].items():\n nt = t + b\n rest = s - a\n if rest >= 0:\n if cost[nv][rest] <= nt : continue \n heappush(q, (nt, nv, rest))\n \n # exchange gold with silver\n rate, time = info[now]\n nt = t + time\n ns = min(s+rate, MAX_SILVER)\n if cost[nv][ns] <= nt : continue\n heappush(q, (nt, now, ns))\n \n \n for i in range(1, N):\n print(min(cost[i]))\n\nif __name__ == "__main__":\n main()', 'from heapq import heappop, heappush\n\nimport sys\ndef input():return sys.stdin.readline().strip()\n\ndef main():\n N, M, S = map(int, input().split())\n to = [{} for _ in range(N)]\n for _ in range(M):\n u, v, a, b = map(int, input().split())\n u -= 1\n v -= 1\n to[u][v] = (a, b)\n to[v][u] = (a, b)\n info = tuple(tuple(map(int, input().split())) for _ in range(N))\n\n MAX_SILVER = 50 * (N-1)\n INF = 10 ** 18\n \n visited = [[False]*(MAX_SILVER+1) for _ in range(N)]\n cost = [[INF]*(MAX_SILVER+1) for _ in range(N)]\n q = []\n S = min(S, MAX_SILVER)\n heappush(q, (0, 0, S)) \n\n while q:\n t, now, s = heappop(q)\n if visited[now][s]:continue\n visited[now][s] = True\n cost[now][s] = t\n\n # next node\n for nv, (a, b) in to[now].items():\n nt = t + b\n rest = s - a\n if rest >= 0:\n if cost[nv][rest] <= nt : continue \n heappush(q, (nt, nv, rest))\n \n # exchange gold with silver\n rate, time = info[now]\n nt = t + time\n ns = min(s+rate, MAX_SILVER)\n if cost[now][ns] <= nt : continue\n heappush(q, (nt, now, ns))\n \n \n for i in range(1, N):\n print(min(cost[i]))\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s398595714', 's578317329'] | [35952.0, 36544.0] | [779.0, 1028.0] | [1375, 1376] |
p02703 | u729133443 | 2,000 | 1,048,576 | There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one- way trip costs A_i silver coins and takes B_i minutes. You cannot use gold coins to pay the fare. There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin. The transaction takes D_i minutes for each gold coin you give. You can exchange any number of gold coins at each exchange counter. For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains. | ['from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nR,C=[],[]\nx=51\nr=range(x*x)\nfor u,v,a,b in t[:m]:\n for i in r:k=(i+a)*x;R+=k+u,k+v;C+=i*x+v,i*x+u;D+=b,b\ni=0\nfor c,d in t[m:]:\n i+=1\n for j in r:R+=j*x+i,;C+=(j+c)*x+i,;D+=d,\nd=csgraph.dijkstra(csr_matrix((D,(R,C)),[x*j]*2),1,min(j,s)*x+1)\nfor i in range(2,n+1):print(int(min(d[i::x])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nR,C=[],[]\nr=range(2501)\nfor u,v,a,b in t[:m]:\n for i in r:k=(i+a)*51;R+=k+u,k+v;C+=i*51+v,i*51+u;D+=b,b\ni=0\nfor c,d t[m:]:\n i+=1\n for j in r:R+=j*51+i,;C+=(j+c)*51+i,;D+=d,\nd=csgraph.dijkstra(csr_matrix((D,(R,C))),1,min(2500,s)*51+1)\nfor i in range(2,n+1):print(int(min(d[i::51])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nx=51\nr=range(0,x**3,x)\nfor u,v,a,b in t[:m]:\n for i in r:D+=i+a*x+u,i+v,b,i+a*x+v,i+u,b\ni=0\nfor c,d in t[m:]:\n i+=1\n for j in r:D+=j+i,j+c*x+i,d\nd=csgraph.johnson(csr_matrix((D[2::3],(D[::3],D[1::3])),[j*2]*2),1,min(j,s*x)+1)\nfor i in range(2,n+1):print(int(min(d[i::x])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nR,C=[],[]\nr=range(2501)\nfor u,v,a,b in t[:m]:\n for i in r:k=(i+a)*51;R+=k+u,k+v;C+=i*51+v,i*51+u;D+=b,b\nfor i,(c,d)in enumerate(t[m:],1):\n for j in r:R+=j*51+i,;C+=(j+c)*51+i,;D+=d,\nd=csgraph.johnson(csr_matrix((D,(R,C))),1,min(2500,s)*51+1)\nfor i in range(2,n+1):print(int(min(d[i::51])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nR,C=[],[]\nr=range(2501)\nfor u,v,a,b in t[:m]:\n for i in r:k=(i+a)*51;R+=k+u,k+v;C+=i*51+v,i*51+u;D+=b,b\nfor i,(c,d)in enumerate(t[m:],1):\n for j in r:R+=j*51+i,;C+=(j+c)*51+i,;D+=d,\nd=csgraph.dijksta(csr_matrix((D,(R,C))),1,min(2500,s)*51+1)\nfor i in range(2,n+1):print(int(min(d[i::51])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nx=51\nr=range(0,x**3,x)\nfor u,v,a,b in t[:m]:\n for i in r:D+=i+a*x+u,i+v,b,i+a*x+v,i+u,b\ni=0\nfor c,d in t[m:]:\n i+=1\n for j in r:D+=j+i,j+c*x+i,d\nd=csgraph.johnson(csr_matrix((D[2::3],(D[::3],D[1::3])),[j*2]*2),1,min(j,s*x)+1)\nfor i in range(2,n+1):print(int(min(d[i::x])))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nR,C=[],[]\nfor u,v,a,b in t[:m]:\n for i in range(2501-a):\n R+=(i+a)*51+u,(i+a)*51+v\n C+=i*51+v,i*51+u\n D+=b,b\nfor i,(c,d)in enumerate(t[m:],1):\n for j in range(2501-c):\n R+=j*51+i,\n C+=(j+c)*51+i,\n D+=d,\nd=csgraph.dijkstra(csr_matrix((D,(R,C)),[8**6]*2),1,min(2500,s)*51+1)\nfor i in range(2,n+1):print(min(d[i::51]))', 'from scipy.sparse import*\n(n,m,s,*D),*t=[map(int,t.split())for t in open(0)]\nx=51\nr=range(0,x**3,x)\nfor u,v,a,b in t[:m]:\n for i in r:D+=i+a*x+u,i+v,b,i+a*x+v,i+u,b\ni=0\nfor c,d in t[m:]:\n i+=1\n for j in r:D+=j+i,j+c*x+i,d\nd=csgraph.dijkstra(csr_matrix((D[2::3],(D[::3],D[1::3])),[j*2]*2),1,min(j,s*x)+1)\nfor i in range(2,n+1):print(int(min(d[i::x])))'] | ['Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Wrong Answer', 'Accepted'] | ['s015007297', 's235924742', 's393219425', 's463032591', 's681834488', 's955474308', 's976870206', 's105773890'] | [103164.0, 9052.0, 126892.0, 108424.0, 91020.0, 126772.0, 122888.0, 126748.0] | [621.0, 20.0, 2209.0, 2207.0, 402.0, 2209.0, 782.0, 765.0] | [363, 358, 349, 366, 366, 349, 440, 350] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.