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 |
|---|---|---|---|---|---|---|---|---|---|---|
p02756 | u955474478 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s = input()\nq = int(input())\nfor i in range(q):\n a = input()\n if " " in a:\n l = list(a.split())\n if l[1] == "1":\n s = l[2] + s\n else:\n s += l[2]\n else:\n s.reverse()\nprint(s)', 's = input()\nq = int(input())\ns1 = ""\ns2 = ""\nc = 1\nfor i in range(q):\n a = input()\n if " " in a:\n l = list(a.split())\n c2 = 3-2*int(l[1])\n if c*c2 == 1:\n s1 = s1 + l[2]\n else:\n s2 = s2 + l[2]\n else:\n c = -c\ns = s1[::-1] + s + s2\nif c == 1:\n print(s)\nelse:\n print(s[::-1])'] | ['Runtime Error', 'Accepted'] | ['s599243393', 's549394479'] | [9784.0, 10224.0] | [2205.0, 374.0] | [198, 301] |
p02756 | u958053648 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["import sys\nfrom collections import deque\n\tS=[input()]\n\tS=deque(S)\n\tQ=int(sys.stdin.readline())\n\tflag=0\n\tfor i in range(Q):\n\t\tqu=tuple(input().split())\n\t\tif qu[0]=='1':\n\t\t\tif flag==0:\n\t\t\t\tflag+=1\n\t\t\telse:\n\t\t\t\tflag=0\n\t\telse:\n\t\t\tif qu[1]=='1' and flag==0:\n\t\t\t\tS.appendleft(qu[2])\n\t\t\telif qu[1]=='1' and flag==1:\n\t\t\t\tS.append(qu[2])\n\t\t\telif qu[1]=='2' and flag==0:\n\t\t\t\tS.append(qu[2])\n\t\t\telif qu[1]=='2' and flag==1:\n\t\t\t\tS.appendleft(qu[2])\n\tif flag==1:\n\t\tS.reverse()\n\tprint(''.join(S))", "import sys\nfrom collections import deque\nS=[input()]\nS=deque(S)\nQ=int(sys.stdin.readline())\nflag=0\nfor i in range(Q):\n\tqu=tuple(input().split())\n\tif qu[0]=='1':\n\t\tif flag==0:\n\t\t\tflag+=1\n\t\telse:\n\t\t\tflag=0\n\telse:\n\t\tif qu[1]=='1' and flag==0:\n\t\t\tS.appendleft(qu[2])\n\t\telif qu[1]=='1' and flag==1:\n\t\t\tS.append(qu[2])\n\t\telif qu[1]=='2' and flag==0:\n\t\t\tS.append(qu[2])\n\t\telif qu[1]=='2' and flag==1:\n\t\t\tS.appendleft(qu[2])\nif flag==1:\n\tS=''.join(S)\n\tS=S[::-1]\n\tprint(S)\n\texit()\nprint(''.join(S))"] | ['Runtime Error', 'Accepted'] | ['s669764499', 's364868418'] | [2940.0, 7028.0] | [17.0, 469.0] | [482, 489] |
p02756 | u963164554 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["S = input()\nQ = int(input())\nfor _ in range(Q):\n q = list(map(str, input().split()))\n if q[0]=='1':\n list(S).reverse()\n S = ''.join(S)\n else:\n if q[1]=='1':\n S = q[2] + S\n else:\n S = S + q[2]\n\nprint(S)", "S = input()\nQ = int(input())\nfor _ in range(Q):\n query = list(map(str, input().split()))\n if query[0]=='1':\n ''.join(reversed(list(S)))\n else:\n if query[1]=='1':\n S = query[2] + S\n else:\n S = S + query[2]\n\nprint(S)", "S = input()\nQ = int(input())\nhanten = 1\nfront = []\nback = []\nfor _ in range(Q):\n q = list(map(str, input().split()))\n if q[0]=='1':\n hanten *= -1\n else:\n if hanten==1:\n if q[1]=='1':\n front.append(q[2])\n else:\n back.append(q[2])\n else:\n if q[1]=='1':\n back.append(q[2])\n else:\n front.append(q[2])\n\n\nif hanten==1:\n print(''.join(list(reversed(front)) + list(S) + back))\nelse:\n print(''.join(list(reversed(list(S)+back))+front))"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s023828920', 's966003442', 's709702188'] | [6112.0, 7996.0, 9440.0] | [2104.0, 2108.0, 633.0] | [260, 266, 566] |
p02756 | u963764813 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s = input()\nq_number = int(input())\nreverse_flag = 1\nfor i in range(q_number):\n temp = input().split()\n if temp[0] == "1": \n reverse_flag = reverse_flag * -1\n else:\n if int(temp[1]) == 1 or -2:\n s = temp[2] + s\n elif int(temp[1]) == -1 or 2:\n s = s + temp[2] \n\nif reverse_flag = -1:\n s = s[::-1]\n \nprint(s)', 's = input()\nq_number = int(input())\n \nqueries = [input().split() for dummy in range(q_number)]\nflag = 1\ncount = 0\nfor i in range(q_number):\n if queries[i][0] == "1": \n flag = flag * -1\n count += 1\n else:\n if int(queries[i][1])*flag == 1 or -2:\n s = queries[i][2] + s\n else:\n s = s + queries[i][2] \n\n \ns = s[::-1]\n\nprint(s)', 's = input()\nq_number = int(input())\nreverse_flag = 1\nhead = ""\ntail = ""\nfor i in range(q_number):\n temp = input().split()\n if temp[0] == "1": \n reverse_flag = reverse_flag * -1\n else:\n headstails = int(temp[1])*reverse_flag \n if headstails == 1 or headstails == -2:\n head = temp[2] + head\n else:\n tail = tail + temp[2]\n \nif reverse_flag == 1:\n print(head+s+tail)\nelse:\n print(tail[::-1]+s[::-1]+head[::-1])\n \n '] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s475550593', 's716824205', 's650707988'] | [2940.0, 41712.0, 4548.0] | [18.0, 2106.0, 1650.0] | [335, 356, 456] |
p02756 | u966207392 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["from collections import deque\nS = input()\nQ = int(input())\nrev = 0\n\nfor i in range(Q):\n T = input().split()\n if T[0] == '1':\n rev += 1\n else:\n if T[1] == '1':\n if rev % 2 == 0:\n S.insert(0, T[2])\n else:\n S.append(T[2])\n else:\n if rev % 2 == 0:\n S.append(T[2])\n else:\n S.insert(0,T[2])\nans = ''.join(S)\nif rev % 2 ==0:\n print(ans)\nelse:\n print(ans[::-1])", "from collections import deque\nS = input()\nQ = int(input())\nrev = 0\n\nfor i in range(Q):\n T = input().split()\n if T[0] == '1':\n rev += 1\n else:\n if T[1] == '1':\n if rev % 2 == 0:\n S.appendleft(T[2])\n else:\n S.append(T[2])\n else:\n if rev % 2 == 0:\n S.append(T[2])\n else:\n S.appendleft(T[2])\nans = ''.join(S)\nif rev % 2 ==0:\n print(ans)\nelse:\n print(ans[::-1])", "from collections import deque\nS = input()\nQ = int(input())\nR = deque(S)\nrev = 0\n\nfor i in range(Q):\n T = input().split()\n if T[0] == '1':\n rev += 1\n else:\n if T[1] == '1':\n if rev % 2 == 0:\n R.append(T[2])\n else:\n R.appendleft(T[2])\n else:\n if rev % 2 == 0:\n R.appendleft(T[2])\n else:\n R.append(T[2])\nans = ''.join(R)\nif rev % 2 ==0:\n print(ans)\nelse:\n print(ans[::1])", "from collections import deque\nS = input()\nQ = int(input())\nR = deque(S)\nrev = 0\n\nfor i in range(Q):\n T = input().split()\n if T[0] == '1':\n rev += 1\n else:\n if T[1] == '1':\n if rev % 2 == 0:\n R.appendleft(T[2])\n else:\n R.append(T[2])\n else:\n if rev % 2 == 0:\n R.append(T[2])\n else:\n R.appendleft(T[2])\nans = ''.join(R)\nif rev % 2 ==0:\n print(ans)\nelse:\n print(ans[::-1])"] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s098921681', 's186516265', 's321567373', 's856344292'] | [9572.0, 9580.0, 14280.0, 14512.0] | [27.0, 29.0, 305.0, 302.0] | [493, 496, 508, 509] |
p02756 | u968404618 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["s = input()\nt = ''\nq = int(input())\nQ = [list(map(str, input().split())) for _ in range(q)]\n\nfor qi in Q:\n if int(qi[0]) == 1:\n s, t = t, s\n else:\n if int(qi[1]) == 1:\n t += qi[2]\n else:\n s += qi[2]\nt[::-1]\nt += s\nprint(t)\n", 'from collections import deque\nS = deque(input())\nn = int(input())\nQ = [list(map(str, input().split())) for _ in range(n)]\n\nflg = True\nfor q in Q:\n if q[0] == "1":\n flg = not flg\n else:\n F = int(q[1])\n if not flg:\n F = 3 - F\n if F == 1:\n S.appendleft(q[2])\n if F == 2:\n S.append(q[2])\n\nif not flg:\n S.reverse()\nprint("".join(S))'] | ['Wrong Answer', 'Accepted'] | ['s922069026', 's083486045'] | [40400.0, 37964.0] | [707.0, 474.0] | [273, 404] |
p02756 | u968649733 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["S = input()\nQ = int(input())\n\ncnt=0\nfor i in range(Q):\n T = input().split()\n if T[0] == '1':\n if i >0:\n \tcnt += 1\n elif T[0] == '2':\n #normal\n if cnt % 2 == 0:\n if T[1] == '1':\n S = T[2] + S \n elif T[1] == '2':\n S = S + T[2] \n #reverse\n elif cnt % 2 == 1:\n if T[1] == '1':\n S = S + T[2] \n elif T[1] == '2':\n S = T[2] + S\nprint(cnt) \nif cnt % 2 == 1:\n S = S[::-1]\nprint(S)", 'from collections import deque\n\nS = input()\nQ = int(input())\nqueue = deque(S)\n\nrev_cnt = 0\nfor i in range(Q):\n query = input().split()\n if query[0]=="1":\n rev_cnt += 1\n elif query[0]=="2":\n #print(query)\n rev = rev_cnt % 2\n s=query[2]\n if query[1] == "1" and rev == 0:\n queue.appendleft(s)\n elif query[1] == "1" and rev == 1:\n queue.append(s)\n elif query[1] == "2" and rev == 0:\n queue.append(s)\n elif query[1] == "2" and rev == 1:\n queue.appendleft(s)\nif rev == 0:\n print(\'\'.join(list(queue)))\nelse:\n print(\'\'.join(reversed(list(queue))))', 'from collections import deque\n\nS = input()\nQ = int(input())\nqueue = deque(S)\n\nrev_cnt = 0\nrev = 0\nfor i in range(Q):\n query = input().split()\n if query[0]=="1":\n rev_cnt += 1\n rev = rev_cnt % 2\n elif query[0]=="2":\n #print(query)\n s=query[2]\n if query[1] == "1" and rev == 0:\n queue.appendleft(s)\n elif query[1] == "1" and rev == 1:\n queue.append(s)\n elif query[1] == "2" and rev == 0:\n queue.append(s)\n elif query[1] == "2" and rev == 1:\n queue.appendleft(s)\nif rev == 0:\n print(\'\'.join(list(queue)))\nelse:\n print(\'\'.join(reversed(list(queue))))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s095474072', 's814632582', 's044104608'] | [3956.0, 10100.0, 10228.0] | [2104.0, 460.0, 447.0] | [453, 587, 595] |
p02756 | u969133463 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["import math\n\ns = list(input())\nq = int(input())\n\nmae = []\nusi = []\nk = 0\nm = 0\nfor i in range(q):\n a = input().split()\n if(a[0] == '1'):\n k += 1\n if(a[0] == '2'):\n if(k %2 == 0):\n if(a[1] == '1'):\n mae.appendleft(a[2])\n else:\n usi.append(a[2])\n else:\n if(a[1] == '1'):\n usi.append(a[2])\n else:\n mae.appendleft(a[2])\n\nif(k % 2 == 1):\n mae = mae[::-1]\n usi = usi[::-1]\n s = s[::-1]\n s = ''.join(usi+s+mae)\nelse:\n s = ''.join(mae+s+usi)\nprint(s)\n\n\n", "import math\n\ns = input()\nq = int(input())\n\nl = [s]\n\nfor i in range(q):\n a = input().split()\n if(a[0] == '1'):\n l = l[::-1]\n if(a[0] == '2'):\n if(a[1] == '1'):\n l.insert(0,a[2])\n else:\n l.append(a[2])\n\n\nfor i in range(len(l)):\n print(l[i],end = '')\n\n", "from collections import deque\n\ns = list(input())\nq = int(input())\n\nmae = deque()\nusi = deque()\nk = 0\nm = 0\nfor i in range(q):\n a = input().split()\n if(a[0] == '1'):\n k += 1\n if(a[0] == '2'):\n if(k %2 == 0):\n if(a[1] == '1'):\n mae.appendleft(a[2])\n else:\n usi.append(a[2])\n else:\n if(a[1] == '1'):\n usi.append(a[2])\n else:\n mae.appendleft(a[2])\nmae = list(mae)\nusi = list(usi)\n\nif(k % 2 == 1):\n mae = mae[::-1]\n usi=usi[::-1]\n s = s[::-1]\n s = ''.join(usi+s+mae)\nelse:\n s = ''.join(mae+s+usi)\nprint(s)\n\n\n"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s180025470', 's283481750', 's986184964'] | [4084.0, 4992.0, 11812.0] | [20.0, 2104.0, 440.0] | [594, 304, 652] |
p02756 | u969190727 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['import sys\ninput=sys.stdin.readline\ns=input()\nq=int(input())\nsign=1\nfor i in range(q):\n Q=[str(i) for i in input().split()]\n if Q[0]=="1":\n sign*=-1\n else:\n f,c=Q[1:]\n if f=="1" and sign==1:\n s=c+s\n elif f=="2" and sign==-1:\n s=c+s\n else:\n s=s+c\nprint(s if sign==1 else s[::-1])', 'import sys\ninput=sys.stdin.readline\ns=input()\nq=int(input())\nsign=1\nF,B="",""\nfor i in range(q):\n Q=[str(i) for i in input().split()]\n if Q[0]=="1":\n sign*=-1\n else:\n f,c=Q[1:]\n if f=="1" and sign==1:\n F=c+F\n elif f=="2" and sign==-1:\n F=c+F\n else:\n B=B+c\nans=F+s+B\nprint(ans if sign==1 else ans[::-1])', 'import sys\ninput = lambda: sys.stdin.readline().rstrip()\ns=input()\nq=int(input())\nsign=1\nF,B="",""\nfor i in range(q):\n Q=[str(i) for i in input().split()]\n if Q[0]=="1":\n sign*=-1\n else:\n f,c=Q[1:]\n if f=="1" and sign==1:\n F=c+F\n elif f=="2" and sign==-1:\n F=c+F\n else:\n B=B+c\nans=F+s+B\nprint(ans if sign==1 else ans[::-1])\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s592536499', 's700891653', 's685291853'] | [3968.0, 4684.0, 4568.0] | [2104.0, 1453.0, 1452.0] | [311, 335, 357] |
p02756 | u969236097 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["import sys\na = sys.stdin.read().split('\\n')[:-1]\ns = list(a[0])\nq = int(a[1])\nf = 1\nfor i in range(2, q + 2):\n if a[i][0] == '1':\n f = 1 - f\n else:\n l = len(s)\n s.insert(a[i][2] == '21'[f] ? 0 : l, a[i][4])\nif f == 1:\n print(''.join(s))\nelse:\n print(''.join(reversed(s)))", "import sys\ni = sys.stdin.read().split('\\n')[:-1]\ns = i[0]\na = ['', '']\nr = 0\nfor l in i[2:]:\n if l[0] == '1':\n r ^= 1\n else:\n t, f, c = l.split()\n a[0 if f == '21'[r] else 1] += c \nif r:\n print(a[0][::-1] + s[::-1] + a[1])\nelse:\n print(a[1][::-1] + s + a[0])"] | ['Runtime Error', 'Accepted'] | ['s117551741', 's625254640'] | [2940.0, 18516.0] | [19.0, 1002.0] | [304, 291] |
p02756 | u970082363 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['import sys\ninput = sys.stdin.readline\n\ns = input()\nq = int(input())\n\ndef addflont(s,c):\n return c+s\ndef addback(s,c):\n return s+c\n\nreverse = 0\n\nfor i in range(q):\n t = list(map(str,input().split()))\n if t[0]=="1":\n reverse += 1\n if t[0]=="2":\n if t[1]=="1":\n if reverse%2==0:\n s = addflont(s,t[2])\n else:\n s = addback(s,t[2])\n elif t[1]=="2":\n if reverse%2==0:\n s = addback(s,t[2])\n else:\n s = addflont(s,t[2])\n\nif reverse%2==1:\n print(s[::-1])\nelse:\n print(s)\n', '\n\ns = input()\nq = int(input())\n\ndef addflont(s,c):\n return c+s\ndef addback(s,c):\n return s+c\n\nreverse = 0\n\nfor i in range(q):\n t = input()\n if t[0]=="1":\n reverse = reverse^1\n if t[0]=="2":\n if t[2]=="1":\n if reverse==0:\n s = c+s\n else:\n s = s+c\n elif t[2]=="2":\n if reverse==0:\n s = s+c\n else:\n s = c+s\n\nif reverse==1:\n print(s[::-1])\nelse:\n print(s)\n', '\n\ns = input()\nq = int(input())\n\ndef addflont(s,c):\n text = "".join([c,s])\n return text\ndef addback(s,c):\n text = "".join([s,c])\n return text\n\nreverse = 0\nr = "";u = ""\nfor i in range(q):\n t = input()\n if t[0]=="1":\n reverse = reverse^1\n if t[0]=="2":\n if t[2]=="1":\n if reverse==0:\n r = addflont(r,t[4])\n else:\n u = addback(u,t[4])\n elif t[2]=="2":\n if reverse==0:\n u = addback(u,t[4])\n else:\n r = addflont(r,t[4])\n\ns = r + s + u\nif reverse==1:\n print(s[::-1])\nelse:\n print(s)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s537971728', 's541166846', 's635656325'] | [3756.0, 3188.0, 4648.0] | [2104.0, 18.0, 1784.0] | [607, 498, 629] |
p02756 | u970133396 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['from collections import deque\ns=input()\nQ=int(input())\n\nans=deque()\nans.append(s)\nrev=False\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n ans.appendleft(query[2])\n else:\n ans.append(query[2])\n\nif not rev:\n for i in range(len(ans)):\n print(i,end="")\nelse:\n for i in range(len(ans)-1,-1,-1):\n print(ans[i],end="")', 's=[input()]\nQ=int(input())\n\nrev=-1\nfor i in range(Q):\n que=input().split()\n if que[0]=="1":\n rev*=-1\n else:\n if que[1]=="1":\n if rev>0:\n s.append(que[2])\n else:\n s=[que[2]]+s\n else:\n if rev<0:\n s.append(que[2])\n else:\n s=[que[2]]+s\nif rev<0:\n print(*s)\nelse:\n print(*s[::-1])', 'from collections import deque\ns=input()\nQ=int(input())\n\nans=deque()\nans.append(s)\nrev=False\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n ans.appendleft(query[2])\n else:\n ans.append(query[2])\n\nif not rev:\n for si in ans:\n print(si,end="")\nelse:\n for i in range(len(ans),0,-1):\n print(ans[i],end="")', 's=[input()]\nQ=int(input())\n\nrev=-1\nfor i in range(Q):\n que=input().split()\n if que[0]=="1":\n rev*=-1\n else:\n if que[1]=="1":\n if rev>0:\n s.append(que[2])\n else:\n s=[que[2]]+s\n else:\n if rev<0:\n s.append(que[2])\n else:\n s=[que[2]]+s\nif rev<0:\n for si in s:\n print(si,end="")\nelse:\n for i in range(len(s),0,-1):\n print(s[i],end="")', 'from collections import deque\nS=input()\nQ=int(input())\n\nans=deque()\nfor s in S:\n ans.append(s)\nrev=False\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n ans.appendleft(query[2])\n else:\n ans.append(query[2])\n # print(ans)\nif not rev:\n for i in range(len(ans)):\n print(ans[i],end="")\nelse:\n for i in range(len(ans)-1,-1,-1):\n print(ans[i],end="")', 'from collections import deque\ns=input()\nQ=int(input())\n\nans=deque()\nans.append(s)\nrev=False\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n ans.appendleft(query[2])\n else:\n ans.append(query[2])\n\nif not rev:\n for si in ans:\n print(si,end="")\nelse:\n for i in range(len(ans)-1,-1,-1):\n print(ans[i],end="")\n', 'from collections import deque\ns=input()\nQ=int(input())\n\nans=deque()\nans.append(s)\nrev=False\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n ans.appendleft(query[2])\n else:\n ans.append(query[2])\n\nif not rev:\n for i in range(len(ans)):\n print(ans[i],end="")\nelse:\n for i in range(len(ans)-1,-1,-1):\n print(ans[i],end="")', 'S=input()\nQ=int(input())\n\n\n# for s in S:\n\n\nrev=False\nfront=""\nlast=""\n# ans+=S\n\nfor _ in range(Q):\n query=input().split()\n if query[0]=="1":\n rev = not rev\n # print(rev)\n else:\n if rev:\n query[1]=str(3-int(query[1]))\n if query[1]=="1":\n \n front="".join([query[2],front])\n else:\n \n last="".join([last,query[2]])\n\n# if rev:\n\n# # ans=""\n\n# ans+=deq[i]\n\nif not rev:\n print(front+S+last)\nelse:\n print(last[::-1]+S[::-1]+front[::-1])'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Time Limit Exceeded', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s003302015', 's177903910', 's483551696', 's680478657', 's718916482', 's721751895', 's949653508', 's704893020'] | [8432.0, 4332.0, 6768.0, 4424.0, 9584.0, 6768.0, 8688.0, 4552.0] | [1260.0, 2104.0, 622.0, 2104.0, 2104.0, 1299.0, 1507.0, 1768.0] | [499, 415, 486, 483, 536, 490, 504, 662] |
p02756 | u970267139 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["s = input()\nQ = int(input())\nquery = [input().split() for _ in range(Q)]\n\ncnt = 0\nfor q in query:\n if q[0] == '1':\n cnt += 1\n else:\n reverse = cnt % 2\n if q[1] == '1':\n if reverse == 0:\n s = q[2] + s\n else:\n s = s + q[2]\n else:\n if reverse == 0:\n s = s + q[2]\n else:\n s = q[2] + s\n print(s)\nif cnt % 2 == 0:\n print(s)\nelse:\n print(s[::-1])\n", "from collections import deque\ns = input()\nQ = int(input())\nque = deque(s)\ncnt = 0\nfor i in range(Q):\n q = input().split()\n if q[0] == '1':\n cnt += 1\n else:\n reverse = cnt % 2\n if q[1] == '1':\n if reverse == 0:\n s = que.appendleft(q[2])\n else:\n s = que.append(q[2])\n else:\n if reverse == 0:\n s = que.append(q[2])\n else:\n s = que.appendleft(q[2])\n\nans = ''.join(que)\nif cnt % 2 == 0:\n print(ans)\nelse:\n print(ans[::-1])"] | ['Runtime Error', 'Accepted'] | ['s022850919', 's229515701'] | [171324.0, 14184.0] | [563.0, 310.0] | [487, 564] |
p02756 | u970809473 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s=list(input())\ntop=bool()\nt=[]\nu=[]\nn=int(input())\nfor i in range(n):\n q=list(map(str,input().split()))\n if q[0]==\'1\':\n top=not top\n else:\n if (q[1]=="1") ^ top:\n t.insert(0,q[2])\n else:\n u.append(q[2])\ns=t+s+u\nif top:\n print(*list(reversed(s)),sep=\'\')\nelse:\n print(s)\n', 's=list(input())\ntop=bool()\nt=[]\nu=[]\nn=int(input())\nfor i in range(n):\n q=list(map(str,input().split()))\n if q[0]==\'1\':\n top=not top\n else:\n if (q[1]=="1") ^ top:\n t.append(q[2])\n else:\n u.append(q[2])\ns=list(reversed(t))+s+u\nif top:\n print(*list(reversed(s)),sep=\'\')\nelse:\n print(*s,sep=\'\')'] | ['Wrong Answer', 'Accepted'] | ['s503360048', 's143437764'] | [16792.0, 17640.0] | [2206.0, 458.0] | [294, 315] |
p02756 | u971719367 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["true_letter = input()\nprint(true_letter)\nQ= int(input())\nletter = ['*']\nreversed = False\nfor i in range(Q):\n query = input().split()\n if len(query)==1:\n reversed = not bool(reversed)\n else:\n if int(query[1])==1: \n if reversed == False:\n letter.insert(0,query[2])\n else:\n letter.append(query[2])\n else:\n if reversed == False:\n letter.append(query[2])\n else:\n letter.insert(0,query[2])\nif reversed==True:\n letter.reverse()\n\noutput = ''.join(letter)\noutput = output.replace('*',true_letter)\nprint(output)\n", "\n\nfrom collections import deque\ntrue_letter = input()\nQ= int(input())\nletter = deque(['*'])\nreversed = False\nfor i in range(Q):\n query = input().split()\n if len(query)==1:\n reversed = not bool(reversed)\n else:\n if int(query[1])==1: \n if reversed == False:\n letter.appendleft(query[2])\n else:\n letter.append(query[2])\n else:\n if reversed == False:\n letter.append(query[2])\n else:\n letter.appendleft(query[2])\nif reversed==True:\n letter.reverse()\n true_letter = true_letter[::-1]\n\noutput = ''.join(letter)\noutput = output.replace('*',true_letter)\nprint(output)\n"] | ['Wrong Answer', 'Accepted'] | ['s388245720', 's808804756'] | [4084.0, 6900.0] | [2104.0, 480.0] | [655, 1360] |
p02756 | u973055892 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["import sys\nfrom collections import deque\n\ndef main():\n input = sys.stdin.readline\n\n s = input()[:-1]\n q = int(input())\n tmp = [input().split() for _ in range(q)]\n\n flag = 0\n ans = deque([s])\n for t in tmp:\n if len(t) == 1:\n flag = ~flag \n else:\n f = int(t[1])\n c = t[2]\n if (f == 1 and flag == 0) or (f ==2 and fag == -1):\n ans.appendleft(c)\n else:\n ans.append(c)\n if flag == 0:\n print(''.join(ans))\n else:\n print(''.join(ans[::0]))\n\nif __name__ == '__main__':\n main()", "import sys\ninput = sys.stdin.readline\n\ndef main():\n s = input()\n q = int(input())\n tmp = [input().split() for _ in range(q)]\n\n for t in tmp:\n if len(t) == 1:\n s = s[::-1]\n else:\n f = int(t[1])\n c = t[2]\n if f == 1:\n s = c + s\n else:\n s = s + c\n\n print(s)\n\nif __name__ == '__main__':\n main()", "import sys\nfrom collections import deque\n\ndef main():\n input = sys.stdin.readline\n\n s = input()[:-1]\n q = int(input())\n tmp = [input().split() for _ in range(q)]\n\n flag = 0\n ans = deque([s])\n for t in tmp:\n if len(t) == 1:\n flag = ~flag \n else:\n f = int(t[1])\n c = t[2]\n if (f == 1 and flag == 0) or (f ==2 and flag == -1):\n ans.appendleft(c)\n else:\n ans.append(c)\n if flag == 0:\n print(''.join(ans))\n else:\n print(''.join(ans)[::-1])\n\nif __name__ == '__main__':\n main()"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s537967402', 's811228756', 's448497568'] | [39540.0, 41740.0, 42996.0] | [147.0, 2106.0, 209.0] | [611, 407, 613] |
p02756 | u974792613 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s = input()\nq = int(input())\n\nt = [0] * q\nf = [0] * q\nc = [""] * q\n\nfor i in range(q):\n lis = list(input().split())\n t[i] = int(lis[0])\n if t[i] == 2:\n f[i] = int(lis[1])\n c[i] = lis[2]\n\nidx = 0\nchs = ""\nflip = False\nins = 0\nwhile idx < q:\n if t[idx] == 1:\n flip = not flip\n while idx + 1 < q and t[idx + 1] == 1:\n idx += 1\n flip = not flip\n if flip:\n chs = chs[::-1]\n ins = len(chs) - ins\n else:\n if f[idx] == 1:\n ch = c[idx]\n while idx + 1 < q and t[idx + 1] == 2 and f[idx + 1] == 1:\n idx += 1\n ch = c[idx] + ch\n chs = ch + chs\n ins += len(ch)\n else:\n ch = c[idx]\n while idx + 1 < q and t[idx + 1] == 2 and f[idx + 1] == 2:\n idx += 1\n ch = ch + c[idx]\n chs = chs + ch\n idx += 1\n\nans = chs[:ins]\nans += s[::-1] if flip else s\nans += chs[ins:]\nprint(ans)\n\n', 's = input()\nq = int(input())\n\nt = [0] * q\nf = [0] * q\nc = [""] * q\n\nfor i in range(q):\n lis = list(input().split())\n t[i] = int(lis[0])\n if t[i] == 2:\n f[i] = int(lis[1])\n c[i] = lis[2]\n\nidx = 0\nchs = ""\nflip = False\nins = 0\nwhile idx < q:\n if t[idx] == 1:\n while idx + 1 < q and t[idx + 1] == 1:\n idx += 1\n flip = not flip\n if flip:\n chs = chs[::-1]\n ins = len(chs) - ins\n else:\n if f[idx] == 1:\n ch = c[idx]\n while idx + 1 < q and t[idx + 1] == 2 and f[idx + 1] == 1:\n idx += 1\n ch = c[idx] + ch\n chs = ch + chs\n ins += len(ch)\n else:\n ch = c[idx]\n while idx + 1 < q and t[idx + 1] == 2 and f[idx + 1] == 2:\n idx += 1\n ch = ch + c[idx]\n chs = chs + ch\n idx += 1\n\nans = chs[:ins]\nans += s[::-1] if flip else s\nans += chs[ins:]\nprint(ans)\n\n', 's = input()\nq = int(input())\n\nt = [0] * q\nf = [0] * q\nc = [""] * q\n\nfor i in range(q):\n lis = list(input().split())\n t[i] = int(lis[0])\n if t[i] == 2:\n f[i] = int(lis[1])\n c[i] = lis[2]\n\nidx = 0\n\np = ""\nwhile idx < q:\n if t[idx] == 1:\n s, p = p, s\n else:\n if f[idx] == 1:\n p += c[idx]\n else:\n s += c[idx]\n idx += 1\n\np = p[::-1]\ns = p + s\nprint(s)\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s154783718', 's720015318', 's270538541'] | [10300.0, 10100.0, 9076.0] | [2104.0, 2104.0, 690.0] | [1005, 981, 423] |
p02756 | u975039852 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s = input()\nq = int(input)\nrev = False\nfor i in range(q):\n inp = input()\n if int(inp[0]) == 1:\n rev = not rev\n else:\n t, f, c = inp.split()\n if (int(f) == 1 and rev) or (int(f) == 2 and not rev):\n s += c\n else:\n s = c + s\nprint(reversed(s) if rev else s)', "s = input()\nq = int(input())\nrev = False\npre = ''\nfor i in range(q):\n inp = input()\n if int(inp[0]) == 1:\n rev = not rev\n else:\n t, f, c = inp.split()\n if (int(f) == 1 and rev) or (int(f) == 2 and not rev):\n s += c\n else:\n pre += c\nprint(s[::-1] + pre if rev else pre[::-1] + s)\n"] | ['Runtime Error', 'Accepted'] | ['s104467536', 's167198221'] | [3188.0, 4480.0] | [17.0, 579.0] | [279, 304] |
p02756 | u979362546 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["s = input()\nq = int(input())\nfor i in range(q):\n\tt, f, c = map(str, input().split())\n\tif t == '1':\n\t\ts = s[::-1]\n\telif f == '1':\n\t\t\ts = c + s\n\telse:\n\t\t\ts += c\nprint(s)", "s = input()\nq = int(input())\nfor i in range(q):\n\tt, f, c = map(str, input().split())\n\tif t == '1':\n\t\ts = s[::-1]\n\telif f == '1':\n\t\t\ts = c + s\n\telse:\n\t\t\ts += c\nprint(s)", "from collections import deque\n\ns = input()\nq = int(input())\nrevflag = 1\nd = deque(s)\nfor i in range(q):\n\ttfc = list(map(str, input().split()))\n\tif tfc[0] == '1':\n\t\trevflag *= -1\n\telif tfc[1] == '1':\n\t\tif revflag > 0:\n\t\t\td.appendleft(tfc[2])\n\t\telse:\n\t\t\td.append(tfc[2])\n\telse:\n\t\tif revflag > 0:\n\t\t\td.append(tfc[2])\n\t\telse:\n\t\t\td.appendleft(tfc[2])\nif revflag > 0:\n\tprint(''.join(d))\nelse:\n\tprint(''.join(reversed(d)))"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s012326761', 's895750550', 's553845593'] | [3884.0, 3848.0, 8692.0] | [2104.0, 2104.0, 676.0] | [167, 167, 415] |
p02756 | u980641911 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ["from collections import deque\n\n\nreverse = False\n\nstring = deque(input().rstrip())\noperate_times = int(input().rstrip())\n\nfor i in range(operate_times):\n row = input().rstrip()\n if row[0]=='1':\n if reverse:\n reverse = False\n else:\n reverse = True\n \n if row[0]=='2':\n row = row.split()\n head_or_tail = row[1]\n add_string = row[2]\n\n if reverse:\n if head_or_tail==1:\n string.append(add_string)\n else:\n string.appendleft(add_string)\n \n else:\n if head_or_tail==2:\n string.append(add_string)\n else:\n string.appendleft(add_string)\n\n\nanswer_string = ''\nif reverse:\n for _ in range(len(string)):\n right = string.pop()\n answer_string+=right\n\n\nprint(answer_string)", "from collections import deque\n\n\nreverse = False\n\nstring = deque(input().rstrip())\noperate_times = int(input().rstrip())\n\nfor i in range(operate_times):\n row = input().rstrip()\n if row[0]=='1':\n if reverse:\n reverse = False\n else:\n reverse = True\n \n if row[0]=='2':\n row = row.split()\n head_or_tail = int(row[1])\n add_string = row[2]\n\n if reverse:\n if head_or_tail==1:\n string.append(add_string)\n else:\n string.appendleft(add_string)\n \n else:\n if head_or_tail==2:\n string.append(add_string)\n else:\n string.appendleft(add_string)\n\n\nanswer_string = ''\nif reverse:\n for _ in range(len(string)):\n right = string.pop()\n answer_string+=right\n print(answer_string)\nelse:\n print(''.join(string))"] | ['Wrong Answer', 'Accepted'] | ['s497323251', 's342977394'] | [6004.0, 8436.0] | [511.0, 589.0] | [863, 903] |
p02756 | u983181637 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['s = list(input())\nq = int(input())\n\nfor _ in range(q):\n Q = [x for x in input().split()]\n if Q[0] == \'1\':\n s = s[::-1]\n else:\n if Q[1] == \'1\':\n s.insert(0, Q[2])\n else:\n s.append(Q[2])\n\nfor i in s:\n print(i, end ="")', "from collections import deque\n\ns = deque(input())\nq = int(input())\nflg = 0\n\nfor _ in range(q):\n Q = [x for x in input().split()]\n if Q[0] == '1':\n flg += 1\n else:\n if (Q[1] == '1' and flg%2==0) or (Q[1] == '2' and flg%2==1):\n s.appendleft(Q[2])\n else:\n s.append(Q[2])\nif flg%2==1:\n s.reverse()\n\nprint('' . join(s))"] | ['Time Limit Exceeded', 'Accepted'] | ['s911279444', 's944237289'] | [7112.0, 8436.0] | [2104.0, 547.0] | [239, 337] |
p02756 | u985041094 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['def change_fb(str_list):\n tmp = str_list[0]\n str_list[0] = str_list[-1]\n str_list[-1] = tmp\n\ns = str(input())\nq = int(input())\nw = [input() for i in range(q)]\n\nchange = False\nstr_list = list(s)\nfor data in w:\n if int(data[0]) == 1:\n change = not change\n else:\n if change:\n change = False\n change_fb(str_list)\n t,f,c = data.split()\n if int(f) == 1:\n str_list.insert(0, c)\n else:\n str_list.append(c)\n print(str_list)\n\nif change:\n change_fb(str_list)\n\nprint("".join(str_list))', 's = list(str(input()))\nq = int(input())\nw = [list(map(str,input().split())) for i in range(q)]\n\nreverse = False\nfront_list = []\nend_list = []\n\nfor data in w:\n if int(data[0]) == 1:\n reverse = not reverse\n else:\n if (int(data[1]) == 1 and not reverse) or (int(data[1]) == 2 and reverse):\n front_list.append(data[2])\n else:\n end_list.append(data[2])\nif not reverse:\n front_list.reverse()\n print("".join(front_list + s + end_list))\nelse:\n end_list.reverse()\n s.reverse()\n print("".join(end_list + s + front_list))'] | ['Runtime Error', 'Accepted'] | ['s248670885', 's735275506'] | [149116.0, 45976.0] | [1885.0, 727.0] | [573, 574] |
p02756 | u987170100 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['S = input()\nfor _ in range(int(input())):\n l = input().split()\n print(l)\n if len(l) == 1:\n S = S[::-1]\n else:\n if l[1] == "1":\n S = l[2] + S\n else:\n S = S + l[2]\nprint(S)\n', 'S = input()\nl1 = []\nl2 = []\nrev = False\nfor _ in range(int(input())):\n l = [s for s in input().split()]\n if l[0] == "1":\n rev = not rev\n elif l[1] == "1":\n if rev:\n l2.append(l[2])\n else:\n l1.append(l[2])\n else:\n if rev:\n l1.append(l[2])\n else:\n l2.append(l[2])\n\nif rev:\n ret = "".join(l2)[::-1] + S[::-1] + "".join(l1)\nelse:\n ret = "".join(l1)[::-1] + S + "".join(l2)\n\nprint(ret)\n'] | ['Wrong Answer', 'Accepted'] | ['s247481261', 's877650149'] | [4984.0, 5724.0] | [2104.0, 508.0] | [226, 478] |
p02756 | u995323427 | 2,000 | 1,048,576 | Takahashi has a string S consisting of lowercase English letters. Starting with this string, he will produce a new one in the procedure given as follows. The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following: * If T_i = 1: reverse the string S. * If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided. * If F_i = 1 : Add C_i to the beginning of the string S. * If F_i = 2 : Add C_i to the end of the string S. Help Takahashi by finding the final string that results from the procedure. | ['S = input()\nNQ = int(input())\n\nreverseFlag = False\n\nfor i in range(NQ):\n query = input().split()\n if (int(query[0]) == 1):\n reverseFlag = not reverseFlag\n else:\n if (reverseFlag):\n if (int(query[1]) == 1):\n S = query[2] + S\n else:\n S = S + query[2]\n else:\n if (int(query[1]) == 1):\n S = S + query[2]\n else:\n S = query[2] + S\n\nif (reverseFlag):\n print(S[::-1])\nelse:\n print(S)\n\n', 'S = input()\nNQ = int(input())\n\nreverseFlag = False\nprefix = ""\nsuffix = ""\n\nfor i in range(NQ):\n query = input().split()\n if (int(query[0]) == 1):\n reverseFlag = not reverseFlag\n else:\n if (reverseFlag):\n if (int(query[1]) == 1):\n suffix = suffix + query[2]\n else:\n prefix = query[2] + prefix\n else:\n if (int(query[1]) == 1):\n prefix = query[2] + prefix\n else:\n suffix = suffix + query[2]\n\nif (reverseFlag):\n print(suffix[::-1] + S[::-1] + prefix[::-1])\nelse:\n print(prefix + S + suffix)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s960877773', 's468902907'] | [3956.0, 4556.0] | [2104.0, 1658.0] | [517, 629] |
p02757 | u021019433 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['p = int(input().split()[1])\ns = input()\nif 10 % p:\n s = reversed(s)\na = enumerate(s, 1)\nif 10 % p == 0:\n r = sum(i for i, x in a if x % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n t, y = 0, 1\n for i, x in a:\n t = (t + x * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) // 2 for i in d)\nprint(r)\n', 'p = int(input().split()[1])\na = list(map(int, input())\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(a, 1) if x % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n t, y = 0, 1\n for i, x in enumerate(reversed(a), 1):\n t = (t + x * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) // 2 for i in d)\nprint(r)\n', 'p = int(input().split()[1])\ns = input()\n#if 10 % p:\n\na = enumerate(s, 1)\nif 10 % p == 0:\n r = sum(i for i, x in a if x % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n t, y = 0, 1\n for i, x in a:\n t = (t + x * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) // 2 for i in d)\nprint(r)\n', 'p = int(input().split()[1])\ns = input()\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n t = 0\n for x in reversed(s):\n t = (t + int(x) * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) for i in d) // 2\nprint(r)', 'p = int(input().split()[1])\ns = input()\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n s, y = 0, 1\n for x in reversed(s):\n s = (s + int(x) * y) % p\n d[s] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) // 2 for i in d)\nprint(r)', 'from itertools import accumulate\nfrom collections import Counter\n\nI = lambda s:map(int, s)\n\np = int(input().split()[1])\ns = input()\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(I(s), 1) if x % p == 0)\nelse:\n c = Counter()\n c[0] = 1\n y = 1\n for i, x in enumerate(I(reversed(s)), 1):\n c[x * y % p] += 1\n r = sum(i * (i - 1) // 2 for i in c.values())\nprint(r)\n', 'from itertools import accumulate\nfrom collections import Counter\n\np = int(input().split()[1])\na = map(int, input())\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(a, 1) if x % p == 0)\nelse:\n a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))\n c = Counter(x % p for x in a) \n c[0] += 1\n r = sum(i * (i - 1) // 2 for i in c.values())\nprint(r)\n', 'p = int(input().split()[1])\ns = input()\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n s, y = 0, 1\n for x in reversed(s):\n t = (t + int(x) * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) // 2 for i in d)\nprint(r)', 'from itertools import accumulate\nfrom collections import Counter\n\np = int(input().split()[1])\na = list(map(int, input())\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(a, 1) if x % p == 0)\nelse:\n a = accumulate(x * pow(10, i, p) for i, x in enumerate(reversed(a), 1))\n c = Counter(x % p for x in a) \n c[0] += 1\n r = sum(i * (i - 1) // 2 for i in c.values())\nprint(r)\n', 'p = int(input().split()[1])\ns = input()\nif 10 % p == 0:\n r = sum(i for i, x in enumerate(s, 1) if int(x) % p == 0)\nelse:\n d = [1] + [0] * (p - 1)\n t, y = 0, 1\n for x in reversed(s):\n t = (t + int(x) * y) % p\n d[t] += 1\n y = y * 10 % p;\n r = sum(i * (i - 1) for i in d) // 2\nprint(r)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s014281962', 's046146205', 's083909553', 's141601907', 's306002984', 's886051623', 's899445391', 's909228915', 's958019944', 's638600229'] | [3500.0, 2940.0, 3500.0, 3500.0, 3500.0, 3876.0, 3876.0, 3500.0, 2940.0, 3628.0] | [18.0, 19.0, 18.0, 74.0, 77.0, 169.0, 75.0, 76.0, 17.0, 142.0] | [315, 319, 317, 290, 296, 370, 369, 296, 374, 296] |
p02757 | u023229441 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p=map(int,input().split())\ns=input()\ndef U(x):\n return int(s[x:])\nif p in [2,5]:\n keta=0\n ans=0\n for i in range(n):\n keta+=1\n if int(s[i])%p==0:\n ans+=keta\n print(ans)\n exit()\n\n\nikeru=[0 for i in range(p)]\nfor i in range(n):\n a=U(i) % p\n ikeru[a]+=1\nans=0\nfor t in ikeru:\n if t in [0,1]:continue\n ans+= t*(t-1)//2\nprint(ans)\nprint(1)', 'n,p=map(int,input().split())\ns=input()\ndef U(x):\n return int(s[x:])\nif p in [2,5]:\n keta=0\n ans=0\n for i in range(n):\n keta+=1\n if int(s[i])%p==0:\n ans+=keta\n print(ans)\n exit()\n\n\nikeru=[0 for i in range(p)\nfor i in range(n):\n a=U(i) % p\n ikeru[a]+=1\nans=0\nfor t in ikeru:\n if t in [0,1]:continue\n ans+= t*(t-1)//2\nprint(ans)', 'from collections import Counter\nn,p=map(int,input().split())\ns=input()\ndef U(x):\n return int(s[x:])\nif p in [2,5]:\n keta=0\n ans=0\n for i in range(n):\n keta+=1\n if int(s[i])%p==0:\n ans+=keta\n print(ans)\n exit()\n\n\nikeru=[U(x)%p for x in range(n)]\nans=0\nC=Counter(ikeru)\nfor t in ikeru:\n if t ==0:continue\n ans+= t*(t-1)//2\nprint(ans)', 'n,p=map(int,input().split())\ns=input()\ndef U(x):\n return int(s[x:])\nif p in [2,5]:\n keta=0\n ans=0\n for i in range(n):\n keta+=1\n if int(s[i])%p==0:\n ans+=keta\n print(ans)\n exit()\n\n\nikeru=[0 for i in range(p)]\nfor i in range(n):\n a=U(i) % p\n ikeru[a]+=1\nans=0\nfor t in ikeru:\n if t in [0,1]:continue\n ans+= t*(t-1)//2\nprint(ans)', 'from collections import Counter\nn,p=map(int,input().split())\nA=list(map(int,input()))\ndef U(x):\n return int(A[x:])\nif p in [2,5]:\n keta=0\n ans=0\n for i in range(n):\n keta+=1\n if int(A[i])%p==0:\n ans+=keta\n print(ans)\n exit()\n \nacc = [0 for i in range(n)] \ncur = A[-1] % p\nacc[-1] = cur\nk = 1\nfor i in range(n-2, -1, -1):\n cur += pow(10, k, p) * A[i]\n cur %= p\n acc[i] = cur\n k += 1\nacc = acc + [0]\n \nC = Counter(acc)\nans = 0\nfor v in C.values():\n ans += v * (v-1) // 2\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s164952512', 's287066863', 's313782683', 's480511048', 's481191407'] | [3560.0, 2940.0, 3828.0, 3560.0, 14536.0] | [2104.0, 17.0, 2104.0, 2104.0, 530.0] | [390, 380, 380, 381, 540] |
p02757 | u023540496 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p = (int(num) for num in input().split())\ns = input()\ns = s[::-1]\n\ndec = [1] * n\nfor i in range(1,n):\n dec[i] = (dec[i - 1] * 10) % p\ns_mod = [0] * n\nfor i in range(n):\n s_mod[i] = (int(s[i]) * dec[i]) % p\n \nprint(dec)\nprint(s_mod)\n \ncumsum = [0] * (n + 1)\ncnt = [1] + [0] * (p - 1)\nfor i in range(n):\n cumsum[i + 1] = (cumsum[i] + s_mod[i]) % p\n cnt[cumsum[i + 1]] += 1\nprint(cumsum)\nprint(cnt)\n \nans = 0\nfor i in range(p):\n ans += (cnt[i] * (cnt[i] - 1)) // 2\nprint(ans)', 'n,p = (int(num) for num in input().split())\ns = input()\ns = s[::-1]\n\nif p != 2 and p != 5:\n dec = [1] * n\n for i in range(1,n):\n dec[i] = (dec[i - 1] * 10) % p\n s_mod = [0] * n\n for i in range(n):\n s_mod[i] = (int(s[i]) * dec[i]) % p\n\n #print(dec)\n #print(s_mod)\n\n cumsum = [0] * (n + 1)\n cnt = [1] + [0] * (p - 1)\n for i in range(n):\n cumsum[i + 1] = (cumsum[i] + s_mod[i]) % p\n cnt[cumsum[i + 1]] += 1\n #print(cumsum)\n #print(cnt)\n\n ans = 0\n for i in range(p):\n ans += (cnt[i] * (cnt[i] - 1)) // 2\n print(ans)\nelif p == 2:\n ans = 0\n for i in range(n):\n if int(s[i]) % 2 == 0:\n ans += n - i\n print(ans)\nelif p == 5:\n ans = 0\n for i in range(n):\n if int(s[i]) % 5 == 0:\n ans += n - i\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s131331282', 's231270570'] | [32716.0, 25940.0] | [326.0, 289.0] | [499, 827] |
p02757 | u023958502 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, P = map(int, input().split())\nS = input()\nans = 0\n#----------------------------------------------\n# 1.\n\n\n# S = 1234\n\n# 23 = (234 - 4) // 10 ** (4 - 3)\n# = 230 // 10\n# = 23\n#\n# 2.\n\n\n#\n# 3.\n\n# int(S[a: b]) * 10 ** (n - b) == (int(S[a: n]) - int(S[b: n]))\n\n\n\n\n\n#\n\n\n\n#----------------------------------------------\n\nremain = [0] * P\nremain[0] += 1\nd = 1\nleft = 0\nfor i in range(n):\n print(left)\n left = (left + int(S[n - i - 1]) * d) % P\n remain[left] += 1\n d = d * 10 % P\n# print(remain)\nfor r in remain:\n ans += r * (r - 1) // 2\n#----------------------------------------------\n\n\n\n\n# S[h:i] % 2 == 0 (0 <= h <= i)\n\n#----------------------------------------------\nif P == 2:\n ans = 0\n for i in range(n):\n if int(S[i]) % 2 == 0:\n ans += i + 1\n print(ans)\n#----------------------------------------------\n \n#----------------------------------------------\nif P == 5:\n ans = 0\n for i in range(n):\n if int(S[i]) % 5 == 0:\n ans += i + 1\n print(ans)\nif P != 2 and P != 5:\n print(ans)\n', 'n, P = map(int, input().split())\nS = input()\nans = 0\n#----------------------------------------------\n# 1.\n\n\n# S = 1234\n\n# 23 = (234 - 4) // 10 ** (4 - 3)\n# = 230 // 10\n# = 23\n#\n# 2.\n\n\n#\n# 3.\n\n# int(S[a: b]) * 10 ** (n - b) == (int(S[a: n]) - int(S[b: n]))\n\n\n\n\n\n#\n\n\n\n#----------------------------------------------\n\nremain = [0] * P\nremain[0] += 1\nd = 1\nleft = 0\nfor i in range(n):\n # print(left)\n left = (left + int(S[n - i - 1]) * d) % P\n remain[left] += 1\n d = d * 10 % P\n# print(remain)\nfor r in remain:\n ans += r * (r - 1) // 2\n#----------------------------------------------\n\n\n\n\n# S[h:i] % 2 == 0 (0 <= h <= i)\n\n#----------------------------------------------\nif P == 2:\n ans = 0\n for i in range(n):\n if int(S[i]) % 2 == 0:\n ans += i + 1\n print(ans)\n#----------------------------------------------\n \n#----------------------------------------------\nif P == 5:\n ans = 0\n for i in range(n):\n if int(S[i]) % 5 == 0:\n ans += i + 1\n print(ans)\nif P != 2 and P != 5:\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s639737708', 's222955602'] | [4576.0, 3500.0] | [402.0, 251.0] | [2295, 2297] |
p02757 | u034128150 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N, P = map(int, input().split())\nS = input()\n\nif P == 2:\n ans = 0\n for i, d in enumerate(map(int, S)):\n if d % 2 == 0:\n ans += i+1\n print(ans)\nelif P == 5:\n ans = 0\n for i, d in enumerate(map(int, S)):\n if d % 5 == 0:\n ans += i+1\n print(ans)\nelse:\n mods = [0] * P\n mods[0] = 1\n cur_mod = 0\n for i, digit in enumerate(map(int, S)):\n cur_mod += pow(10, N-i-1, P) * digit\n cur_mod %= P\n mods[cur_mod] += 1\n\n print(mods)\n\n ans = 0\n for count in mods:\n ans += count * (count - 1) // 2\n\n print(ans)', 'N, P = map(int, input().split())\nS = input()\n\nif P == 2:\n ans = 0\n for i, d in enumerate(map(int, S)):\n if d % 2 == 0:\n ans += i+1\n print(ans)\nelif P == 5:\n ans = 0\n for i, d in enumerate(map(int, S)):\n if d % 5 == 0:\n ans += i+1\n print(ans)\nelse:\n mods = [0] * P\n mods[0] = 1\n cur_mod = 0\n for i, digit in enumerate(map(int, S)):\n cur_mod += pow(10, N-i-1, P) * digit\n cur_mod %= P\n mods[cur_mod] += 1\n\n ans = 0\n for count in mods:\n ans += count * (count - 1) // 2\n\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s730992608', 's247777173'] | [9452.0, 9440.0] | [325.0, 325.0] | [598, 581] |
p02757 | u037430802 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['\n\n\nN,P = map(int, input().split())\nS = input()\n\nans = 0\nmod_P = [0] * P\nmod_P[0] += 1\n\nif P in [2,5]:\n \n for i in range(N):\n ans += mod_P[0]\n mod_P[int(S[N-1-i]) % P] += 1\n \n print(ans)\n\nelse:\n \n curr = 0\n for i in range(N):\n curr = int(S[N-1-i]) * pow(10, i) + curr\n print(i,curr, mod_P, curr%P)\n #curr %= P\n ans += mod_P[curr%P]\n mod_P[curr%P] += 1\n print(ans)\n', '\n\n\n\nfrom collections import defaultdict\n\n\nN,P = map(int, input().split())\nS = input()\n\n\n\nans = 0\n\nif P in [2,5]:\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i+1\n\n\nelse:\n mod_P = defaultdict(int)\n mod_P[0] += 1 \n tmp = 0\n\n for i in range(N):\n tmp = int(S[N-1-i]) * pow(10, i, P) + tmp\n tmp %= P\n ans += mod_P[tmp]\n mod_P[tmp] += 1\n\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s543446238', 's525230261'] | [96360.0, 4452.0] | [2104.0, 571.0] | [1595, 816] |
p02757 | u044220565 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["# coding: utf-8\nimport numpy as np\nN,P = list(map(int, input().split()))\nS = '0'+input()\n\n#N=200000\n#P=9893\n#S= '0'+'1234567890' * 20000\n\nif (P==2)|(P==5):\n sum=0\n for i in range(N, 0, -1):\n if int(S[i]) % P == 0:\n sum+= i\n print(sum)\n\n\nelse:\n dp1 = np.zeros(N + 1)\n dp2 = np.zeros(N + 1)\n dp3 = np.zeros(P)\n dp1[N] = int(S[N]) % P\n dp3[int(dp1[N])] += 1\n k = 1\n for i in range(N - 1, 0, -1):\n dp1[i] = (dp1[i + 1] + (int(S[i]) * 10 * k)) % P\n dp3[int(dp1[i])] += 1\n k = (k * 10) % P\n\n sum = 0\n\n for i in range(P):\n if i == 0:\n sum += (dp3[i] * (dp3[i] - 1)) // 2 + dp3[i]\n continue\n if dp3[i] == 0: continue\n sum += (dp3[i] * (dp3[i] - 1)) // 2\n print(dp1)\n print(dp3)\n print(int(sum))\n", "# coding: utf-8\nimport numpy as np\nN,P = list(map(int, input().split()))\nS = '0'+input()\n\ndp1 = np.zeros(N+1)\ndp2 = np.zeros(N+1)\ndp3 = np.zeros(P)\nzero_count = 0\ndp1[N] = int(S[N]) % P\ndp3[int(dp1[N])] += 1\nk = 1\nfor i in range(N-1, 0, -1):\n dp1[i] = (dp1[i+1] + ((int(S[i]) * 10 * k) % P)) % P\n dp3[int(dp1[i])] += 1\n k = (k * 10) % P\n if int(S[i]) % P == 0:\n zero_count += 1\n\nsum = 0\nfor i in range(P):\n if i == 0:\n sum += (dp3[i] * dp3[i] - 1) // 2 + dp3[i]\n continue\n sum += (dp3[i] * dp3[i] - 1) // 2\n\nprint(int(sum)-zero_count)", "# coding: utf-8\n\nN,P = list(map(int, input().split()))\nS = '0'+input()\n\n#N=200000\n#P=9893\n#S= '0'+'1234567890' * 20000\n\nif (P==2)|(P==5):\n sum=0\n for i in range(N, 0, -1):\n if int(S[i]) % P == 0:\n sum+= i\n print(sum)\n\n\nelse:\n dp1 = [0] * (N+1)\n dp2 = [0] * (N+1)\n dp3 = [0] * P\n dp1[N] = int(S[N]) % P\n dp3[int(dp1[N])] += 1\n k = 1\n for i in range(N - 1, 0, -1):\n dp1[i] = (dp1[i + 1] + (int(S[i]) * 10 * k)) % P\n dp3[int(dp1[i])] += 1\n k = (k * 10) % P\n\n sum = 0\n\n for i in range(P):\n if i == 0:\n sum += (dp3[i] * (dp3[i] - 1)) // 2 + dp3[i]\n continue\n if dp3[i] == 0: continue\n sum += (dp3[i] * (dp3[i] - 1)) // 2\n print(int(sum))\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s114336098', 's219761048', 's279672612'] | [15724.0, 14348.0, 12564.0] | [1255.0, 1317.0, 229.0] | [814, 573, 754] |
p02757 | u062655521 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["n, p = map(int, input().split(' '))\ns = input()\np_len = len(str(p))\nans = 0\n\nfor i in range(len(s), len(s) + 1 - p_len):\n for j in range(i + p_len, len(s) + 1):\n n_ss = int(s[i:j])\n if n_ss % p == 0:\n ans += 1\n\nprint(ans)", "n, p = map(int, input().split(' '))\ns = input()\n\nif 10 % p == 0:\n ans = 0\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i + 1\n print(ans)\nelse:\n ans = 0\n d = [0 for _ in range(n + 1)]\n ten = 1\n for i in range(n - 1, -1, -1):\n a = int(s[i]) * ten % p\n d[i] = (d[i + 1] + a) % p\n ten *= 10\n ten %= p\n cnt = [0 for _ in range(p)]\n for i in range(n, -1, -1):\n ans += cnt[d[i]]\n cnt[d[i]] += 1\n print(ans)"] | ['Wrong Answer', 'Accepted'] | ['s864837100', 's120193942'] | [3500.0, 11208.0] | [17.0, 253.0] | [249, 496] |
p02757 | u073852194 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["from collections import Counter\nimport sys\nif sys.platform == 'ios' or 'darwin':\n sys.stdin = open('input_file.txt')\n\nN, P = map(int, input().split())\nS = input()\n\nans = 0\n\nif P == 2 or P == 5:\n for i in range(N):\n if int(S[-1 - i]) % 2 == 0:\n ans += N - i\nelse:\n M = []\n cum = [0]\n\n for i in range(N):\n M.append(pow(10, i, P) * int(S[-1 - i]) % P)\n\n for i in range(N):\n cum.append((cum[-1] + M[i]) % P)\n\n C = Counter(cum)\n\n for v in C.values():\n ans += v * (v - 1) // 2\n\nprint(ans)", 'from collections import Counter\n\nN, P = map(int, input().split())\nS = input()\n\nans = 0\n\nif P == 2 or P == 5:\n for i in range(N):\n if int(S[-1 - i]) % P == 0:\n ans += N - i\nelse:\n M = []\n cum = [0]\n\n for i in range(N):\n M.append(pow(10, i, P) * int(S[-1 - i]) % P)\n\n for i in range(N):\n cum.append((cum[-1] + M[i]) % P)\n\n C = Counter(cum)\n\n for v in C.values():\n ans += v * (v - 1) // 2\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s042231545', 's990922706'] | [3316.0, 19236.0] | [20.0, 557.0] | [545, 457] |
p02757 | u075012704 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import Counter\nN, P = map(int, input().split())\nS = input()\n\nif 10 % P == 0:\n ans = 0\n for i, s in enumerate(S, start=1):\n if int(s) % P != 0:\n continue\n ans += i\n print(ans)\n\nelse:\n X = [0]\n for i, s in enumerate(S[::-1]):\n X.append((X[-1] + pow(10, i, P) * int(s)) % P)\n\n C = Counter(X)\n ans = 0\n for v in C.values():\n ans += v * (v - 1) // 2\n print(ans // 2)\n', 'from collections import Counter\nN, P = map(int, input().split())\nS = input()\n\nif 10 % P == 0:\n ans = 0\n for i, s in enumerate(S, start=1):\n if int(s) % P != 0:\n continue\n ans += i\n print(ans)\n\nelse:\n X = [0]\n for i, s in enumerate(S[::-1]):\n X.append((X[-1] + pow(10, i, P) * int(s)) % P)\n\n C = Counter(X)\n ans = 0\n for v in C.values():\n ans += v * (v - 1) // 2\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s843981108', 's475142216'] | [12048.0, 12052.0] | [517.0, 526.0] | [445, 440] |
p02757 | u078181689 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import sys\n\nn,p = list(map(int,input().split())); s = input()\n\nans = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i])%p == 0:\n ans += i+1\n print(ans)\n sys.exit()\n \nres = [0] * p\narr = [int(s[i:])%p for i in range(n)]\nfor i in arr:\n res[i] += 1\nfor i in res:\n ans += i*(i-1)\n ans //= 2\nans += res[0]\n \nprint(ans)', 'n,p = list(map(int,input().split())); s = [int(i) for i in input()]\n\nans = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if s[i]%p == 0:\n ans += i+1\n print(ans)\n \nelse:\n s = s[::-1]\n res = [0] * p\n arr = [0] * n\n tmp = 0\n for i in range(n):\n tmp += s[i]*pow(10,i,p)\n tmp %= p\n arr[i] = tmp\n for i in arr:\n res[i] += 1\n for i in res:\n ans += i*(i-1)\n ans //= 2\n ans += res[0]\n \n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s076404999', 's274039481'] | [3560.0, 12364.0] | [2104.0, 525.0] | [362, 486] |
p02757 | u111473084 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import Counter\n\nn, p = map(int, input().split(" "))\ns = list(map(int, input()))\ns = s[::-1]\n\nans = 0\nif 10 % p == 0: # p = 2, 5\n for i, num in enumerate(s, 1):\n if num % p == 0:\n ans += i\n print(ans)\n exit()\n\npower = 1\nt = [0] * len(s)\nt[0] = s[0] % p\nfor i in range(1, len(s)):\n power = power * 10 % p\n t[i] = (t[i-1] + s[i] * power) % p\n\n# counter = Counter(t)\n\n\n# ans += counter[0]\n# print(ans)\n# print(counter)\n# print(t)\ncount = [0] * p\ncount[0] = 1\nfor i in t:\n print(count)\n ans += count[i]\n count[i] += 1\n\nprint(ans)\n', 'from collections import Counter\n\nn, p = map(int, input().split(" "))\ns = list(map(int, input()))\n\nans = 0\nif 10 % p == 0: # p = 2, 5\n for i, num in enumerate(s, 1):\n if num % p == 0:\n ans += i\n print(ans)\n exit()\n\ns = s[::-1]\npower = 1\nt = [0] * len(s)\nt[0] = s[0] % p\nfor i in range(1, len(s)):\n power = power * 10 % p\n t[i] = (t[i-1] + s[i] * power) % p\n\n# counter = Counter(t)\n\n\n# ans += counter[0]\n# print(ans)\n\ncount = [0] * p\ncount[0] = 1\nfor i in t:\n ans += count[i]\n count[i] += 1\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s741696498', 's507894002'] | [110172.0, 12668.0] | [2104.0, 198.0] | [639, 594] |
p02757 | u123525541 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | [' n, p = map(int, input().split())\n s = input()\n\n\n def solve1(s, p):\n v = 0\n pow10 = 1\n ans = 0\n cnt = [0] * p\n cnt[0] = 1\n\n for i in range(n - 1, -1, -1):\n v = (pow10 * int(s[i]) + v) % p\n pow10 = (pow10 * 10) % p\n ans += cnt[v]\n cnt[v] += 1\n return ans\n\n\n def solve25(s, p):\n cnt = 0\n ans = 0\n for i in range(len(s) - 1, -1, -1):\n if int(s[i]) % p == 0:\n cnt += 1\n ans += cnt\n return ans\n\n\n\n if p in (2,5):\n print(solve25(s, p))\n else:\n print(solve1(s, p))', 'n, p = map(int, input().split())\ns = input()\n\n\ndef solve1(s, p):\n v = 0\n pow10 = 1\n ans = 0\n cnt = [0] * p\n cnt[0] = 1\n\n for i in range(n - 1, -1, -1):\n v = (pow10 * int(s[i]) + v) % p\n pow10 = (pow10 * 10) % p\n ans += cnt[v]\n cnt[v] += 1\n return ans\n\n\ndef solve25(s, p):\n cnt = 0\n ans = 0\n for i in range(len(s) - 1, -1, -1):\n if int(s[i]) % p == 0:\n cnt += 1\n ans += cnt\n return ans\n\n\n\nif p in (2,5):\n print(solve25(s, p))\nelse:\n print(solve1(s, p))\n'] | ['Runtime Error', 'Accepted'] | ['s820979600', 's400767176'] | [2940.0, 3500.0] | [17.0, 124.0] | [595, 544] |
p02757 | u123872895 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import Counter\n\nn, p = list(map(int, input().split()))\n\ns = input()\n\n\na = 0\nt = list(map(int, list(s)))\nt.reverse()\n\n\nif p == 2:\n for i in range(n):\n if t[i] % 2 == 0:\n a += len(t) - i \nelif p == 5:\n for i in range(n):\n if t[i] % 5 == 0:\n a += len(t) - i \n\nelse:\n u = []\n k = 1\n for i in t:\n l = 0\n if i == 0:\n l = i*k % p\n u.append(k)\n else:\n l = (l + i*k) % p\n u.append(l)\n k = k * 10 % p\n\n c = Counter(u)\n a += c[0]\n for i in c.values():\n if i > 1:\n a += i * (i-1) // 2\n\n\nprint(a)\n\n\n', 'from collections import Counter\n\nn, p = list(map(int, input().split()))\n\ns = input()\n\n\na = 0\nt = list(map(int, list(s)))\nt.reverse()\n\n\nif p == 2:\n for i in range(n):\n if t[i] % 2 == 0:\n a += len(t) - i \nelif p == 5:\n for i in range(n):\n if t[i] % 5 == 0:\n a += len(t) - i \n\nelse:\n u = []\n k = 1\n l = 0\n for i in t:\n l = (l + i*k) % p\n u.append(l)\n k = k * 10 % p\n\n c = Counter(u)\n a += c[0]\n for i in c.values():\n if i > 1:\n a += i * (i-1) // 2\n\n\nprint(a)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s661196798', 's833611289'] | [13520.0, 13612.0] | [167.0, 157.0] | [653, 560] |
p02757 | u139112865 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['#E\nfrom collections import Counter\nn,p=map(int,input().split())\ns=input()\ncnt=0\n\nif p==2 or p==5:\n for i in range(n):\n if int(s[i])%p==0:\n cnt+=i+1\nelse:\n U=[0]\n for i in range(n):\n x=n-1-i\n U.append((U[i]+int(s[x])*10**(i))%p)\n print(U)\n C=Counter(U)\n for c in C.values():\n cnt+=c*(c-1)//2\n\nprint(cnt)', '#E\nfrom collections import Counter\nn,p=map(int,input().split())\ns=input()\ncnt=0\n\nif p==2 or p==5:\n for i in range(n):\n if int(s[i])%p==0:\n cnt+=i+1\nelse:\n U=[0]*(n+1)\n for i in range(n,0,-1):\n U[i-1]=(int(s[i-1])*10**(n-i)+U[i])%p\n print(U)\n C=Counter(U)\n for c in C.values():\n cnt+=c*(c-1)//2\n\nprint(cnt)', '#E\nfrom collections import Counter\nn,p=map(int,input().split())\ns=input()\ncnt=0\n\nif p==2 or p==5:\n for i in range(n):\n if int(s[i])%p==0:\n cnt+=i+1\nelse:\n U=[0]*(n+1)\n for i in range(n,0,-1):\n U[i-1]=(int(s[i-1])*pow(10,n-i,p)+U[i])%p\n #print(U)\n C=Counter(U)\n for c in C.values():\n cnt+=c*(c-1)//2\n\nprint(cnt)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s500085725', 's676676181', 's055121250'] | [4100.0, 5692.0, 12080.0] | [2104.0, 2104.0, 534.0] | [359, 355, 360] |
p02757 | u145600939 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p = map(int,input().split())\ns = list(map(int,list(input())))\nans = 0\ncnt = [0]*p\ncnt[0] = 1\n\nif p == 2:\n for i in range(n):\n if s[i] in [0,2,4,6,8] :\n ans += i + 1\nelif p == 5:\n for i in range(n):\n if s[i] in [0,5]:\n ans += i + 1\nelse:\n sp = [0]*n\n sp[n-1] = s[n-1]%p\n cnt[sp[n-1]] += 1\n for i in range(1,n):\n sp[n-i-1] = (sp[n-i]+s[n-i-1]*(10**i%p))%p\n cnt[sp[n-i-1]] += 1\n for j in range(p):\n cj = cnt[j]\n ans += cj * (cj-1)//2\nprint(cnt)\nprint(ans)', 'n,p = map(int,input().split())\ns = list(map(int,list(input())))\nans = 0\ncnt = [0]*p\ncnt[0] = 1\n\nif p == 2:\n for i in range(n):\n if s[i] in [0,2,4,6,8] :\n ans += i + 1\nelif p == 5:\n for i in range(n):\n if s[i] in [0,5]:\n ans += i + 1\nelse:\n sum = 0\n for i in range(n):\n sum = (sum+s[n-i-1]*pow(10,i,p))%p\n cnt[sum] += 1\n for j in range(p):\n cj = cnt[j]\n ans += cj * (cj-1)//2\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s600748638', 's395467209'] | [8500.0, 6560.0] | [2104.0, 485.0] | [489, 419] |
p02757 | u150821332 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import numpy as np\n\ndef a():\n n, p = list(map(int, input().split()))\n s = input()\n if(p==2 or p==5):\n count=0\n for i in range(1,n+1):\n if(int(s[-i])%p == 0):\n count += n-i+1\n print(count)\n return\n\n num = np.array([int(s[i:]) for i in range(n)]) % p\n print(num)\n c = sum(num == 0)\n count = c*(c+1)//2\n for i in range(1,p):\n c = sum(num == i)\n count += c*(c-1)//2\n print(count)\n return\na()', 'import numpy as np\n\ndef a():\n n, p = list(map(int, input().split()))\n s = input()\n if(p==2 or p==5):\n print("im here")\n count=0\n for i in range(1,n+1):\n if(int(s[-i])%p == 0):\n count += n-i+1\n print(count)\n return\n\n num = np.array([int(s[i:]) for i in range(n)]) % p\n print(num)\n c = sum(num == 0)\n count = c*(c+1)//2\n for i in range(1,p):\n c = sum(num == i)\n count += c*(c-1)//2\n print(count)\n return\na()', 'import numpy as np\n\ndef a():\n n, p = list(map(int, input().split()))\n num = [int(s) for s in input()]\n \n if(p==2 or p==5):\n count=0\n for i in range(1,n+1):\n if(num[-i]%p == 0):\n count += n-i+1\n print(count)\n return\n \n counts = np.zeros(p)\n tmp = 0\n tens = 1\n for i in range(1,n+1):\n tmp = (tens*num[-i] + tmp) % p\n counts[tmp] += 1\n tens = (tens*10)%p\n ret = int(counts[0] + sum(counts*(counts-1)//2))\n print(ret)\n return\na()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s303964416', 's811760712', 's753228728'] | [20628.0, 19820.0, 14560.0] | [2109.0, 2109.0, 571.0] | [427, 448, 470] |
p02757 | u181644161 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P=map(int,input().split())\nS=str(input())\nans=0\n\nif 10%P==0:\n for i in range(N):\n if int(S[i])%P==0:\n ans+=i+1\nelse:\n rem = [0]*P\n mod = 0\n ten = 1\n rem[mod]=1\n for i in range(N):\n mod=(mod+S[N-i-1]*ten)%P\n ten=ten*10%P\n rem[mod]+=1\n for j in rem:\n ans+=(j*(j-1))//2\nprint(ans)', 'N,P=map(int,input().split())\nS=str(input())\nans=0\n\nif 10%P==0:\n for i in range(N):\n if int(S[i])%P==0:\n ans+=i+1\nelse:\n rem = [0]*P\n mod = 0\n ten = 1\n rem[mod]=1\n for i in range(N):\n mod=(mod+int(S[N-i-1])*ten)%P\n ten=ten*10%P\n rem[mod]+=1\n for j in rem:\n ans+=(j*(j-1))//2\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s095780468', 's303457524'] | [3500.0, 3500.0] | [129.0, 158.0] | [346, 352] |
p02757 | u195054737 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, p = map(int, input().split())\ns = input()\n\nans = 0\nif p in (2, 5):\n for i, j in enumerate(s):\n if int(j) % p == 0:\n ans += i + 1\n\nelse:\n cnt = [0] * p\n cnt[0] = 1\n now = 0\n for i, j in enumerate(reversed(s)):\n now = (int(s) * pow(10, i, p) + now) % p\n ans += cnt[now]\n cnt[now] += 1\n\nprint(ans)', 'n, p = map(int, input().split())\ns = input()\n\nans = 0\nif p in (2, 5):\n for i, j in enumerate(s):\n if int(j) % p == 0:\n ans += i + 1\n\nelse:\n cnt = [0] * p\n cnt[0] = 1\n now = 0\n for i, j in enumerate(reversed(s)):\n now = (int(j) * pow(10, i, p) + now) % p\n ans += cnt[now]\n cnt[now] += 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s699131168', 's597751223'] | [3560.0, 3500.0] | [2104.0, 506.0] | [351, 351] |
p02757 | u201234972 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["def main():\n N, P = map( int ,input().split())\n S = [ int(s) for s in list(input())][::-1]\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if S[i]%P == 0:\n ans += N-i\n print(ans)\n return\n\n \n L = [0]*P\n L[0] = 1\n t = 0\n for i in range(N):\n t = (S[i]*pow(10,i,P)+t)%P\n print(t)\n L[t] += 1\n ans = 0\n for l in L:\n ans += l*(l-1)//2\n print(ans)\n \nif __name__ == '__main__':\n main()\n", "def main():\n N, P = map( int ,input().split())\n S = [ int(s) for s in list(input())][::-1]\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if S[i]%P == 0:\n ans += N-i\n print(ans)\n return\n L = [0]*P\n L[0] = 1\n t = 0\n s = 1\n for i in range(N):\n t = (S[i]*s+t)%P\n L[t] += 1\n s *= 10\n s %= 10\n ans = 0\n for l in L:\n ans += l*(l-1)//2\n print(ans)\n \nif __name__ == '__main__':\n main()\n", "import sys\ninput = sys.stdin.readline\ndef main():\n N, P = map( int ,input().split())\n S = [ int(s) for s in list(input())][::-1]\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if S[i]%P == 0:\n ans += N-i\n print(ans)\n return\n L = [0]*P\n L[0] = 1\n t = 0\n s = 1\n for i in range(N):\n t = (S[i]*s+t)%P\n L[t] += 1\n s = s*10%P\n ans = 0\n for l in L:\n ans += l*(l-1)//2\n print(ans)\n \nif __name__ == '__main__':\n main()\n", "def main():\n N, P = map( int ,input().split())\n S = [ int(s) for s in list(input().strip())][::-1]\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if S[i]%P == 0:\n ans += N-i\n print(ans)\n return\n L = [0]*P\n L[0] = 1\n t = 0\n s = 1\n for z in S:\n t = (z*s+t)%P\n L[t] += 1\n s = s*10%P\n ans = 0\n for l in L:\n ans += l*(l-1)//2\n print(ans)\n \nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s240803708', 's336602470', 's641699632', 's908687796'] | [6436.0, 6564.0, 6504.0, 6436.0] | [614.0, 96.0, 60.0, 112.0] | [502, 511, 536, 496] |
p02757 | u203382704 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N, P = map(int, input().split())\nd = list(map(int, input()))\nans =0\nfor k in range(0,N):\n for l in range(k+1,N+1):\n num = int("".join(map(str,d[k:l])))\n \n if num == 0:\n break\n elif num % P == 0:\n ans += 1\n print(num)\n\nprint(ans)\n', 'N, P = map(int, input().split())\nS = list(map(int, input()))\nans = 0\nif P == 2:\n for i in range(N):\n if S[i]%2 == 0:\n ans +=i+1\n print(ans)\n\nelif P ==5:\n for i in range(N):\n if S[i]%5 == 0:\n ans +=i+1\n print(ans)\nelse:\n data =[0]*P\n tens = 1\n k = 0\n for i in range(N-1,-1,-1):\n k += S[i] *tens %P\n k = k%P\n data[k] += 1\n tens *=10\n tens %=P\n\n for i in data:\n ans += i*(i-1)/2\n ans +=data[0]\n print(int(ans))'] | ['Wrong Answer', 'Accepted'] | ['s174965776', 's446904723'] | [14828.0, 5220.0] | [2104.0, 176.0] | [293, 518] |
p02757 | u212786022 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['dp = [[0 for i in range(N-j)] for j in range(N)]\ndp\nfor j in range(N):\n dp[j][0]=(int(S[j])%mod)\n for i in range(1,N-j):\n dp[j][i]=((dp[j][i-1]*10+int(S[j+i]))%mod)\nans = 0\nfor i in range(N):\n ans += dp[i].count(0)\n \nprint(ans)', 'N, P = map(int, input().split())\nS = list(map(int,list(input())))\nmod = P\nCum = []\nS.reverse()\n\nif 10%P!=0: \n temp = 0\n power = 1\n for i in range(N):\n temp += (S[i]*power)%mod\n temp %= mod\n power *= 10\n power %= mod\n Cum.append(temp)\n\n from collections import Counter\n\n counter=Counter(Cum)\n\n counter[0]+=1\n\n ans = 0\n for i in counter:\n ans += int(counter[i]*(counter[i]-1)/2)\n print(ans) \n\nelse:\n ans = 0\n S.reverse()\n for i in range(N):\n if S[i]%P==0:\n ans += (i+1) \n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s846871981', 's532054848'] | [3064.0, 13632.0] | [18.0, 210.0] | [246, 592] |
p02757 | u268554510 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P = map(int,input().split())\nS = list(map(int,list(input())))\nS=S[::-1]\nans = 0\nfrom collections import Counter\nif P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nelif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\n\nelse:\n l = [0]*(N+2)\n for i in range(N):\n l[i+1]=l[i]\n l[i+1]+=(S[i]*10**i)%P\n l[i+1]%=P\n \n c = Counter(l)\n l = list(c.values())\n l = sorted(l)\n for i in l:\n if l==1:\n continue\n else:\n ans+=c*(c-1)//2\n \nprint(ans)', 'N,P = map(int,input().split())\nS = list(map(int,list(input())))\nS=S[::-1]\nans = 0\n\nif P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nelif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nprint(ans)', 'N,P = map(int,input().split())\nS = list(map(int,input().split()))\nans = 0\n\nif P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nelif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\n \nprint(ans)', 'N,P = map(int,input().split())\nS = list(map(int,list(input())))\nS=S[::-1]\nans = 0\nfrom collections import Counter\nif P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nelif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\n\nelse:\n l = [0]*(N+2)\n for i in range(N):\n l[i+1]=l[i]\n l[i+1]+=(S[i]*10**i)%P\n l[i+1]%=P\n \n c = Counter(l)\n l = list(c.values())\n l = sorted(l)\n for i in l:\n if l==1:\n continue\n else:\n ans+=i*(i-1)//2\n \nprint(ans)', 'N,P = map(int,input().split())\nS = list(map(int,input().split()))\nS=S[::-1]\nans = 0\n\nif P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nelif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\nprint(ans)', 'def main():\n N,P = map(int,input().split())\n S = list(map(int,list(input())))\n S=S[::-1]\n ans = 0\n if P==2:\n l = [0,2,4,6,8]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\n elif P==5:\n l=[0,5]\n for i,s in enumerate(S):\n if s in l:\n ans+=N-i\n\n else:\n l = [0]*P\n a=0\n for i in range(N):\n b = pow(10,i,P)\n b *= S[i]\n b %= P\n a+=b\n a%=P\n l[a]+=1\n ans+=l[0]\n for i in l:\n ans+=i*(i-1)//2\n\n print(ans)\n \nmain()'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s154791260', 's215805683', 's298095936', 's580552935', 's679380877', 's282866633'] | [7004.0, 6436.0, 3500.0, 6948.0, 3624.0, 6560.0] | [2104.0, 101.0, 288.0, 2104.0, 288.0, 461.0] | [529, 255, 254, 529, 257, 500] |
p02757 | u312025627 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['def main():\n N, P = (int(i) for i in input().split())\n S = input()\n\n ans = 0\n if P == 5:\n for i in range(1):\n for j in range(1, N-i+1):\n num = int(S[i:i+j])\n if num % P == 0:\n # print("!", end=" ")\n ans += len(S[i:i+j])\n # print(num)\n else #if P == 2:\n for i in range(1):\n for j in range(1, N-i+1):\n num = int(S[i:i+j])\n if num % P == 0:\n # print("!", end=" ")\n ans += len(S[i:i+j])\n # print(num)\n """\n A = [int(s) for s in S]\n from itertools import accumulate\n acc = accumulate([0] + A)\n right = N\n for left in range(N):\n while left\n\n print()\n """\n print(ans)\n\n\nif __name__ == \'__main__\':\n main()\n', "def main():\n from collections import Counter\n N, P = (int(i) for i in input().split())\n S = [int(s) for s in input()]\n\n ans = 0\n if P == 5 or P == 2:\n for i, s in enumerate(S, start=1):\n \n if s % P == 0:\n ans += i\n else:\n acc = [0]*(N+1)\n d = 1\n for i, s in enumerate(S[::-1], start=1):\n # print(i, s)\n acc[i] = (s * d + acc[i-1]) % P\n d *= 10\n d %= P\n c = Counter(acc)\n # print(acc, c)\n ans = sum(v*(v-1)//2 for v in c.values())\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s865414864', 's075166184'] | [3064.0, 14488.0] | [17.0, 143.0] | [852, 648] |
p02757 | u318384266 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["N, P = map(int, input().split())\nS = input()\ncounter=0\ndef power_func(a,b,p):\n\tif b==0:\n\t\treturn 1\n if b%2==0:\n\t\td=power_func(a,b//2,p)\n\t\treturn d*d %p\n\tif b%2==1:\n\t\treturn (a*power_func(a,b-1,p ))%p\nif P==2:\n counter = 0\n for i in range(len(S)):\n if S[i] in ['2','4','6','8','0']:\n counter+=i+1\nelif P==5:\n counter = 0\n for i in range(len(S)):\n if S[i] in ['5','0']:\n counter+=i+1\nelse:\n list_a=[0]*P\n list_a[0]+=1\n temp=0\n for i in range(N):\n \tM = power_func(10,N-i,P)\n temp=(int(S[i])*M+temp)%P\n counter+=list_a[temp]\n list_a[temp]+=1\nprint(counter)", "N, P = map(int, input().split())\nS = input()\n\ncounter=0\ndef power_func(a,b,p):\n if b==0:\n return 1\n elif b%2==0:\n d=power_func(a,b//2,p)\n return d*d %p\n elif b%2==1:\n return (a*power_func(a,b-1,p ))%p\nif P==2:\n counter = 0\n for i in range(len(S)):\n if S[i] in ['2','4','6','8','0']:\n counter+=i+1\nelif P==5:\n counter = 0\n for i in range(len(S)):\n if S[i] in ['5','0']:\n counter+=i+1\nelse:\n list_a=[0]*P\n list_a[0]+=1\n temp=0\n for i in range(N):\n M = power_func(10,N-i,P)\n temp=(int(S[i])*M+temp)%P\n counter+=list_a[temp]\n list_a[temp]+=1\nprint(counter)"] | ['Runtime Error', 'Accepted'] | ['s452817789', 's424923975'] | [2940.0, 3628.0] | [17.0, 1795.0] | [641, 677] |
p02757 | u328364772 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, p = map(int, input().split())\ns = input()\n\nans = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i+1\nelse:\n \tmod = [-1 for i in range(p)]\n\tmod[0] = 0\n mp = 0\n m10 = 1\n for i in range(n-1, -1, -1):\n mp = (mp + int(s[i]) * m10) % p\n mod[mp] += 1\n m10 = (10 * m10) % p\n\n for m in mod:\n ans += m*(m+1)//2\n\nprint(ans)\n', 'n, p = map(int, input().split())\ns = input()\n\nans = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i+1\nelse:\n mod = [-1 for i in range(p)]\n mod[0] = 0\n mp = 0\n m10 = 1\n \n for i in range(n-1, -1, -1):\n mp = (mp + int(s[i]) * m10) % p\n mod[mp] += 1\n m10 = (10 * m10) % p\n\n for m in mod:\n ans += m*(m+1)//2\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s273000883', 's608949479'] | [2940.0, 3500.0] | [17.0, 169.0] | [406, 414] |
p02757 | u338824669 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import defaultdict\n\nN,P=map(int,input().split())\nS=input()\n\ndef solMin():\n dp=[[0]*P for i in range(N+1)]\n \n for i,s in enumerate(map(int,S), start=1):\n dp[i][s%P]+=1\n for p in range(P):\n dp[i][(p*10+s)]+=dp[i-1][p]\n \n return sum(dp[i][0] for i in range(N+1))\n\ndef solLarge():\n cnt=defaultdict(int)\n ret=0\n now=0\n \n for d,s in enumerate(map(int, S[::-1])):\n now+=pow(10,d,P)*s\n now%=P\n ret+=cnt[(now-P)%P]\n if now==0:\n ret +=1\n cnt[now]+=1\n \n return ret\n\nprint(solMin() if P*N<=10**6 else solLarge()) ', 'from collections import defaultdict\n\nN,P=map(int,input().split())\nS=input()\n\ndef solMin():\n dp=[[0]*P for i in range(N+1)]\n \n for i,s in enumerate(map(int,S), start=1):\n dp[i][s%P]+=1\n for p in range(P):\n dp[i][(p*10+s)%P]+=dp[i-1][p]\n \n return sum(dp[i][0] for i in range(N+1))\n\ndef solLarge():\n cnt=defaultdict(int)\n ret=0\n now=0\n \n for d,s in enumerate(map(int, S[::-1])):\n now+=pow(10,d,P)*s\n now%=P\n ret+=cnt[(now-P)%P]\n if now==0:\n ret +=1\n cnt[now]+=1\n \n return ret\n\nprint(solMin() if P*N<=10**6 else solLarge()) '] | ['Runtime Error', 'Accepted'] | ['s478451338', 's664359295'] | [27104.0, 42928.0] | [534.0, 544.0] | [562, 564] |
p02757 | u346812984 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import sys\n\nsys.setrecursionlimit(10 ** 6)\nINF = float("inf")\nMOD = 10 ** 9 + 7\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N, P = map(int, input().split())\n S = input()\n\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n else:\n val = [0] * P\n cur = 0\n tenfactor = 1\n val[cur] += 1\n for i in range(N):\n cur = (cur + int(S[N - i - 1]) * tenfactor) % P\n tenfactor *= 10\n tenfactor %= 10\n val[cur] += 1\n\n ans = 0\n for v in val:\n ans += v * (v - 1) // 2\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\n\nsys.setrecursionlimit(10 ** 6)\nINF = float("inf")\nMOD = 10 ** 9 + 7\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N, P = map(int, input().split())\n S = input()\n\n if P == 2 or P == 5:\n ans = 0\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n else:\n val = [0] * P\n cur = 0\n tenfactor = 1\n val[cur] += 1\n for i in range(N):\n cur = (cur + int(S[N - i - 1]) * tenfactor) % P\n tenfactor *= 10\n tenfactor %= P\n val[cur] += 1\n\n ans = 0\n for v in val:\n ans += v * (v - 1) // 2\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s403243407', 's293749603'] | [3628.0, 3500.0] | [122.0, 130.0] | [727, 726] |
p02757 | u350248178 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p=map(int,input().split())\ns=[int(j) for j in input()][::-1]\n\nif p==2:\n ans=0\n for i,j in enumerate(s):\n if j%2==0:\n ans+=(n-i)\n print(ans)\n exit()\nif p==5:\n ans=0\n for i,j in enumerate(s):\n if j%5==0:\n ans+=(n-i)\n print(ans)\n exit()\n\nc=[0]*p\ntmp=0\nc[0]+=1\nt=1\nimport numpy as np\nfor i in s:\n tmp+=t*i\n print(tmp)\n c[tmp%p]+=1\n t=(t*10)%p\nc=np.array(c)\nprint(c)\nans=c*(c-1)//2\nprint(ans.sum())\n', 'n,p=map(int,input().split())\ns=[int(j) for j in input()][::-1]\n\nif p==2:\n ans=0\n for i,j in enumerate(s):\n if j%2==0:\n ans+=(n-i)\n print(ans)\n exit()\nif p==5:\n ans=0\n for i,j in enumerate(s):\n if j%5==0:\n ans+=(n-i)\n print(ans)\n exit()\n\nc=[0]*p\ntmp=0\nc[0]+=1\nt=1\nimport numpy as np\nfor i in s:\n tmp+=t*i\n c[tmp%p]+=1\n t=(t*10)%p\nc=np.array(c)\nans=c*(c-1)//2\nprint(ans.sum())'] | ['Wrong Answer', 'Accepted'] | ['s768671682', 's621123270'] | [16256.0, 14456.0] | [442.0, 276.0] | [468, 443] |
p02757 | u353797797 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import Counter\nimport sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep="\\n")\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef SI(): return sys.stdin.readline()[:-1]\n\ndef main():\n n,p=MI()\n s=SI()\n if p==2 or p==5:\n ans=0\n for i,c in enumerate(s):\n if int(c)%p==0:ans+=i+1\n print(ans)\n exit()\n aa=[int(c) for c in s[::-1]]\n cc=[0]\n ten=1\n for a in aa:\n cc.append((cc[-1]+a*ten)%p)\n ten=ten*10%p\n cnt=Counter(cc)\n print(cc)\n print(cnt)\n ans=0\n for v in cnt.values():\n ans+=v*(v-1)//2\n print(v,ans)\n print(ans)\n\nmain()', 'from collections import Counter\nimport sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep="\\n")\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef SI(): return sys.stdin.readline()[:-1]\n\ndef main():\n n,p=MI()\n s=SI()\n if p==2 or p==5:\n ans=0\n for i,c in enumerate(s):\n if int(c)%p==0:ans+=i+1\n print(ans)\n exit()\n aa=[int(c) for c in s[::-1]]\n cc=[0]\n ten=1\n for a in aa:\n cc.append((cc[-1]+a*ten)%p)\n ten=ten*10%p\n cnt=Counter(cc)\n ans=0\n for v in cnt.values():\n ans+=v*(v-1)//2\n print(ans)\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s458852705', 's613906017'] | [16828.0, 13620.0] | [173.0, 149.0] | [863, 813] |
p02757 | u454472984 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, p = map(int, input().split())\n \ns = list(input())\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i + 1\nelse:\n d = [0] * (n + 1)\n ten = 1\n for i in range(n - 1, -1, -1):\n a = int(s[i]) * ten % p\n sum+=a\n ten *= 10\n ten %= p\n d[i]= sum % p\n cnt = [0] * p\n for i in range(n, -1, -1):\n cnt[d[i]] += 1\n for i in cnt:\n ans+=i*(i-1)/2\nprint(d)\nprint(int(ans))', 'n, p = map(int, input().split())\n \ns = list(input())\nans = 0\nsum=0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i + 1\nelse:\n d = [0] * (n + 1)\n ten = 1\n for i in range(n - 1, -1, -1):\n a = int(s[i]) * ten % p\n sum+=a\n ten *= 10\n ten %= p\n d[i]= sum % p\n cnt = [0] * p\n for i in range(n, -1, -1):\n cnt[d[i]] += 1\n for i in cnt:\n ans+=i*(i-1)/2\nprint(d)\nprint(int(ans))', 'n, p = map(int, input().split())\n \ns = list(input())\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i + 1\nelse:\n d = [0] * (n + 1)\n ten = 1\n for i in range(n - 1, -1, -1):\n a = int(s[i]) * ten % p\n ten *= 10\n ten %= p\n d[i - 1] = (d[i] + a) % p\n cnt = [0] * p\n for i in range(n, -1, -1):\n cnt[d[i]] += 1\n for i in cnt:\n ans+=i*(i-1)/2\n\nprint(int(ans))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s000874702', 's596362628', 's112623710'] | [6308.0, 15852.0, 12412.0] | [109.0, 239.0, 209.0] | [478, 484, 467] |
p02757 | u471641802 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['# from collections import Counter\nn, p = map(int, input().split())\ns = [int(i) for i in input()]\np_cnt = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if s[i] % p == 0:\n p_cnt += i+1\nelse:\n s = s[::-1]\n div_dic = dict(zip(range(p), [0] * p))\n tmp = 0\n\n for i in range(n):\n tmp += s[i] * pow(10, i, p)\n tmp %= p\n div_dic[tmp] += 1\n\n print(div_dic)\n for v in div_dic.values():\n p_cnt += v * (v - 1)\n p_cnt //= 2\n p_cnt += div_dic.get(0)\n\nprint(p_cnt)', 'n, p = map(int, input().split())\ns = [int(i) for i in input()]\np_cnt = 0\n\nif p == 2 or p == 5:\n for i in range(n):\n if s[i] % p == 0:\n p_cnt += i+1\n \nelse:\n s = s[::-1]\n div_dic = dict(zip(range(p), [0] * p))\n tmp = 0\n\n for i in range(n):\n tmp += s[i] * pow(10, i, p)\n tmp %= p\n div_dic[tmp] += 1\n\n for v in div_dic.values():\n p_cnt += v * (v - 1)\n p_cnt //= 2\n p_cnt += div_dic.get(0)\n\nprint(p_cnt)'] | ['Wrong Answer', 'Accepted'] | ['s895904237', 's440604430'] | [6560.0, 6436.0] | [502.0, 506.0] | [520, 476] |
p02757 | u497952650 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P = map(int,input().split())\nS = input()\n\nif P%2 == 0 or P%5 == 0:\n ans = 0\n S = S[::-1]\n for i,j in enumerate(S):\n if int(j)%P == 0:\n ans += i+1\n print(ans)\nelse:\n tmp = 0\n mod = [0]*P\n ##mod[0] = 1\n S = S[::-1]\n for i,j in enumerate(S):\n tmp = (tmp + int(j)*pow(10,i,P))%P\n mod[tmp] += 1 \n print(sum([i*(i-1)//2 for i in mod]))', 'N,P = map(int,input().split())\nS = input()\n\nif P%2 == 0 or P%5 == 0:\n ans = 0\n ##S = S[::-1]\n for i,j in enumerate(S):\n if int(j)%P == 0:\n ans += i+1\n print(ans)\nelse:\n tmp = 0\n mod = [0]*P\n mod[0] = 1\n S = S[::-1]\n for i,j in enumerate(S):\n tmp = (tmp + int(j)*pow(10,i,P))%P\n mod[tmp] += 1 \n print(sum([i*(i-1)//2 for i in mod]))'] | ['Wrong Answer', 'Accepted'] | ['s306386823', 's875146871'] | [3500.0, 3500.0] | [497.0, 492.0] | [396, 396] |
p02757 | u517152997 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['#\nimport sys\nimport math\n#import numpy as np\nimport itertools\nfrom collections import Counter\n\nn,p = (int(i) for i in input().split())\n\ns = [int(i) for i in list(input())] \n\nanswer = 0\n#print(s)\nq=0\nx=[]\nif p == 2 or p == 5:\n for i in range(n-1,-1,-1):\n if s[i]%p == 0:\n answer += i+1\nelse:\n for i in range(n-1,-1,-1):\n q=(q+s[i])%p\n x.append(q)\n q = (q * 10)%p\n #print(x)\n counter = Counter(x)\n #print(counter)\n\n for k in counter:\n # print(k)\n\n answer += counter[k] * (counter[k]-1) // 2\n\nprint(answer)\n\n', '#\nimport sys\nimport math\n#import numpy as np\nimport itertools\nfrom collections import Counter\n\nn,p = (int(i) for i in input().split())\n\ns = [int(i) for i in list(input())] \n\nanswer = 0\n#print(s)\nq=0\nx=[]\nif p == 2 or p == 5:\n for i in range(n-1,-1,-1):\n if s[i]%p == 0:\n answer += i+1\nelse:\n d=1\n for i in range(n-1,-1,-1):\n q = (d*s[i]+q)%p\n x.append(q)\n d = (d * 10)%p\n #print(x)\n counter = Counter(x)\n #print(counter)\n\n for k in counter:\n # print(k)\n if k==0:\n answer += counter[k] * (counter[k]+1) // 2\n else:\n answer += counter[k] * (counter[k]-1) // 2\n\nprint(answer)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s942756534', 's827075367'] | [13408.0, 13436.0] | [159.0, 176.0] | [642, 743] |
p02757 | u532966492 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['def main():\n n, p = map(int, input().split())\n s = list(map(int, list(input())))\n now = 1\n now2 = 0\n\n dp = [0]*p\n cnt = 0\n if p != 5:\n for i in s:\n now2 = (now2*10+i) % p\n dp[((i-now2) % p)*pow(now, p-2, p) % p] += 1\n cnt += dp[((-now2) % p)*pow(now, p-2, p) % p]\n now = (now*10) % p\n print(dp)\n else:\n for j, i in enumerate(s):\n if i in [0, 5]:\n cnt += j+1\n print(cnt)\n\n\nmain()', 'n,p=map(int,input().split());s,n,N,c,d=map(int,list(input())),1,0,0,[0]*p\nif p!=5:\n for i in s:N,a=(N*10+i)%p,pow(n,p-2,p);d[(i-N)*a%p]+=1;c+=d[-N*a%p];n=n*10%p\nelse:c=sum([j+1 for j,i in enumerate(s)if i%5==0])\nprint(c)'] | ['Wrong Answer', 'Accepted'] | ['s031123856', 's463688619'] | [103568.0, 12740.0] | [2104.0, 631.0] | [500, 220] |
p02757 | u535803878 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['input = _input().__next__\nn, p = [int(c) for c in input().split()]\ns = input() \n\nif p in (2,5):\n a = tuple(int(c)%p for c in s)\n out = 0\n for i,x in enumerate(a):\n if x==0:\n out += (i + 1)\nelse:\n a = [0]*n\n tmp = 0\n for i in reversed(range(n)):\n tmp = (tmp * 10 + int(s[i])) % p\n a[i] = tmp\n d = {i: 0 for i in range(p)}\n d[0] = 1\n out = 0\n for x in a[::-1]:\n out += d[x]\n d[x] += 1\nprint(out)', '\ndef hoge():\n\n n, p = [int(c) for c in input().split()]\n s = input() \n\n if p in (2,5):\n a = tuple(int(c)%p for c in s)\n out = 0\n for i,x in enumerate(a):\n if x==0:\n out += (i + 1)\n else:\n a = [0]*n\n tmp = 0\n for i in reversed(range(n)):\n tmp = (tmp + pow(10, n-i-1, p) * int(s[i])) % p\n # tmp = (tmp + 10**(n-i-1) * int(s[i])) % p\n a[i] = tmp\n d = {i: 0 for i in range(p)}\n d[0] = 1\n out = 0\n for x in a[::-1]:\n out += d[x]\n d[x] += 1\n print(out)\nhoge()'] | ['Runtime Error', 'Accepted'] | ['s763759954', 's532746864'] | [3064.0, 13328.0] | [17.0, 496.0] | [472, 622] |
p02757 | u543954314 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p = map(int, input().split())\ns = list(map(int, list(ns())))\nif p in (2, 5):\n print(sum(i+1 for i in range(n) if s[i]%p == 0))\n exit(0)\n \nans = g = 0\nd = [0]*p\nd[0] = 1\nt = 1\nfor i in range(n-1,-1,-1):\n g = (g + s[i]*t)%p\n ans += d[g]\n d[g] += 1\n t = (t*10)%p\nprint(ans)', 'n,p = map(int, input().split())\ns = list(map(int, list(input())))\nif p in (2, 5):\n print(sum(i+1 for i in range(n) if s[i]%p == 0))\n exit(0) \nans = g = 0\nd = [0]*p\nd[0] = 1\nt = 1\nfor i in range(n-1,-1,-1):\n g = (g + s[i]*t)%p\n ans += d[g]\n d[g] += 1\n t = (t*10)%p\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s514681009', 's397640649'] | [3064.0, 6560.0] | [18.0, 174.0] | [288, 288] |
p02757 | u577170763 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["class Solution:\n\n def solve(self, N: int, P: int, S: str):\n\n if P == 2 or P == 5:\n answer = 0\n for idx, s in enumerate(S):\n if int(s) % P == 0:\n answer += idx + 1\n\n else:\n answer = 0\n U = [0] * P # int(S[i,N] mod P\n U[0] += 1\n for i in range(N):\n U[int(S[i:N]) % P] += 1\n\n for u in U:\n answer += u * (u-1) // 2\n\n print(U)\n\n return answer\n\n\nif __name__ == '__main__':\n\n # standard input\n N, P = map(int, input().split())\n S = input()\n\n # solve\n solution = Solution()\n answer = solution.solve(N, P, S)\n print(answer)\n", "class Solution:\n\n def solve(self, N: int, P: int, S: str):\n\n if P == 2 or P == 5:\n answer = 0\n for idx, s in enumerate(S):\n if int(s) % P == 0:\n answer += idx + 1\n\n else:\n answer = 0\n U = [0] * P # int(S[i,N] mod P\n U[0] += 1\n\n num = 0\n base10_mod_p = 1\n for i in range(N):\n num = (num + int(S[N-i-1]) * base10_mod_p) % P\n base10_mod_p = (base10_mod_p * 10) % P\n\n U[num] += 1\n\n for u in U:\n answer += u * (u-1) // 2\n\n return answer\n\n\nif __name__ == '__main__':\n\n # standard input\n N, P = map(int, input().split())\n S = input()\n\n # solve\n solution = Solution()\n answer = solution.solve(N, P, S)\n print(answer)\n"] | ['Wrong Answer', 'Accepted'] | ['s749369024', 's154640207'] | [3560.0, 3500.0] | [2104.0, 135.0] | [713, 848] |
p02757 | u595064211 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N, P = map(int, input().split())\nS = input()\nans = 0\n\nd = [0]*(N+1)\n# d[N-1] = 1\n\nif 10%P == 0:\n ans = 0\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n print(ans)\nelse:\n \n ten = 1\n \n for i in range(N-1,-1,-1):\n a = int(S[i]) * ten % P\n d[i] = (d[i+1]+a)%P\n ten *= 10\n ten %= P\n\n \n counter = [0]*P\n print(d)\n for j in range(N, -1, -1):\n ans += counter[d[j]]\n print(ans)\n counter[d[j]] += 1\n\n print(ans)\n', 'N, P = map(int, input().split())\nS = input()\nans = 0\n\nd = [0]*(N+1)\n# d[N-1] = 1\n\nif 10%P == 0:\n ans = 0\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n print(ans)\nelse:\n \n ten = 1\n \n for i in range(N-1,-1,-1):\n a = int(S[i]) * ten % P\n d[i] = (d[i+1]+a)%P\n ten *= 10\n ten %= P\n\n \n counter = [0]*P\n# print(d)\n for j in range(N, -1, -1):\n ans += counter[d[j]]\n# print(ans)\n counter[d[j]] += 1\n\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s148746687', 's775180610'] | [14536.0, 11088.0] | [414.0, 257.0] | [614, 618] |
p02757 | u595856802 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['def main():\n n, p = map(int, input().split())\n s = input()\n\n TF = 2, 5\n if p in TF:\n answer = 0\n for i, char in enumerate(s):\n if int(char) % p == 0:\n answer += i + 1\n print(answer)\n return\n\n u = [int(s[i:]) for i in range(n)]\n u.append(0)\n # The numbers to consider are int(s[i:j]) (0 <= i < j <= n)\n # u[i] := int(s[i:]) (u[n] = 0 for convenience)\n # int(s[i:j]) and u[i] - u[j] are congruent (unless p == 2 or 5)\n remainders = [number % p for number in u]\n d = {}\n return\n for remainder in remainders:\n if remainder not in d:\n d[remainder] = 1\n else:\n d[remainder] += 1\n answer = 0\n for count in d.values():\n if count > 1:\n answer += count * (count - 1) // 2\n print(answer)\n\nmain()\n', 'def main():\n n, p = map(int, input().split())\n s = input()\n\n TF = 2, 5\n if p in TF:\n answer = 0\n for i, char in enumerate(s):\n if int(char) % p == 0:\n answer += i + 1\n print(answer)\n return\n\n \n u = []\n t = 0\n for i, char in enumerate(s[::-1]):\n t += 10 ** i * int(char)\n u.append(t)\n u = u[::-1]\n u.append(0)\n # The numbers to consider are int(s[i:j]) (0 <= i < j <= n)\n # u[i] := int(s[i:]) (u[n] = 0 for convenience)\n # int(s[i:j]) and u[i] - u[j] are congruent (unless p == 2 or 5)\n remainders = [number % p for number in u]\n d = {}\n return\n for remainder in remainders:\n if remainder not in d:\n d[remainder] = 1\n else:\n d[remainder] += 1\n answer = 0\n for count in d.values():\n if count > 1:\n answer += count * (count - 1) // 2\n print(answer)\n\nmain()\n', 'def main():\n n, p = map(int, input().split())\n s = input()\n\n TF = 2, 5\n if p in TF:\n answer = 0\n for i, char in enumerate(s):\n if int(char) % p == 0:\n answer += i + 1\n print(answer)\n return\n\n \n remainders = []\n t = 0\n for i, char in enumerate(s[::-1]):\n t += pow(10, i, p) * int(char)\n remainders.append(t % p)\n remainders = remainders[::-1]\n remainders.append(0)\n # The numbers to consider are int(s[i:j]) (0 <= i < j <= n)\n # u[i] := int(s[i:]) (u[n] = 0 for convenience)\n # int(s[i:j]) and u[i] - u[j] are congruent (unless p == 2 or 5)\n d = {}\n for remainder in remainders:\n if remainder not in d:\n d[remainder] = 1\n else:\n d[remainder] += 1\n answer = 0\n for count in d.values():\n if count > 1:\n answer += count * (count - 1) // 2\n print(answer)\n\nmain()\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s589494635', 's994123078', 's661455886'] | [8820.0, 57192.0, 12928.0] | [2104.0, 2110.0, 505.0] | [841, 972, 970] |
p02757 | u608088992 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import sys\nfrom collections import defaultdict\n\ndef solve():\n input = sys.stdin.readline\n N, P = map(int, input().split())\n S = input().strip("\\n")\n modSum = 0\n modSum = int(S[0]) % P\n modDict = defaultdict(int)\n ans = 0\n\n if P == 2 or P == 5:\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n \n else:\n modDict[modSum[0]] += 1\n for i in range(1, N):\n modSum = ((modSum * 10) + int(S[i])) % P\n modDict[modSum] += 1\n\n for key in modDict:\n v = modDict[key]\n if key > 0: ans += v * (v - 1) // 2\n else: ans += v + (v * (v - 1) // 2)\n \n print(ans)\n\n return 0\n\nif __name__ == "__main__":\n solve()', 'import sys\nfrom collections import defaultdict\n\ndef solve():\n input = sys.stdin.readline\n N, P = map(int, input().split())\n S = input().strip("\\n")\n modSum = 0\n modDict = defaultdict(int)\n modDict[0] += 1\n ans = 0\n\n if P == 2 or P == 5:\n for i in range(N):\n if int(S[i]) % P == 0:\n ans += i + 1\n \n else:\n for i in range(N):\n modSum += int(S[N-i-1]) * pow(10, i, P)\n modSum %= P\n modDict[modSum] += 1\n\n for key in modDict:\n v = modDict[key]\n ans += v * (v - 1) // 2\n \n print(ans)\n\n return 0\n\nif __name__ == "__main__":\n solve()'] | ['Runtime Error', 'Accepted'] | ['s062591936', 's428087632'] | [9780.0, 10040.0] | [69.0, 327.0] | [753, 674] |
p02757 | u671455949 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import deque\n\nimport numpy as np\n\nn, p = map(int, input().split())\nd = deque(input())\n\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n k = int(d.popleft())\n if n % p == 0:\n ans += i + 1\nelse:\n sub = [0 for i in range(n)]\n wk = 0\n for i in range(n):\n k = int(d.pop())\n wk = (wk + k * pow(10, i, p)) % p\n sub[i] = wk\n print(sub)\n ans = 0\n dic = {}\n for i in range(n):\n if sub[i] == 0:\n ans += 1\n if sub[i] in dic.keys():\n ans += dic[sub[i]]\n dic[sub[i]] = dic[sub[i]] + 1\n else:\n dic[sub[i]] = 1\n\nprint(ans)', 'from collections import deque\n\nimport numpy as np\n\nn, p = map(int, input().split())\nd = deque(input())\n\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n k = int(d.popleft())\n if k % p == 0:\n ans += i + 1\nelse:\n sub = [0 for i in range(n)]\n wk = 0\n for i in range(n):\n k = int(d.pop())\n wk = (wk + k * pow(10, i, p)) % p\n sub[i] = wk\n ans = 0\n dic = {}\n for i in range(n):\n if sub[i] == 0:\n ans += 1\n if sub[i] in dic.keys():\n ans += dic[sub[i]]\n dic[sub[i]] = dic[sub[i]] + 1\n else:\n dic[sub[i]] = 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s919518603', 's408816924'] | [23892.0, 21496.0] | [799.0, 770.0] | [581, 568] |
p02757 | u685983477 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import defaultdict\ndd = defaultdict(int)\nn,p=map(int, input().split())\nS = list(input().rstrip())\ntmp = 0\nr=1\nsu=0\n\nif p==2 or p==5:\n c=n\n for s in S[::-1]:\n if int(s)%p==0:\n su+=c\n c-=1\n print(su)\nelse:\n for s in S[::-1]:\n tmp+=int(s)*r\n r*=10\n tmp%=p\n r%=p\n dd[tmp]+=1\n for i in dd.values():\n su+=(i*(i-1))//2\n print(su)\n', 'from collections import defaultdict\ndd = defaultdict(int)\nn,p=map(int, input().split())\nS = list(input().rstrip())\ntmp = 0\nr=1\nsu=0\ndd[0]=1\nif p==2 or p==5:\n c=n\n for s in S[::-1]:\n if int(s)%p==0:\n su+=c\n c-=1\n print(su)\nelse:\n for s in S[::-1]:\n tmp+=int(s)*r\n tmp%=p\n dd[tmp]+=1\n r*=10\n r%=p\n for i in dd.values():\n su += (i*(i-1))//2\n print(su)\n'] | ['Wrong Answer', 'Accepted'] | ['s689225180', 's474070434'] | [7320.0, 7328.0] | [180.0, 180.0] | [425, 434] |
p02757 | u686230543 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import numpy as np\n\nn, p = map(int, input().split())\ns = np.array([int(i) % p for i in input()])\nmod = np.zeros((n, p), dtype=np.int)\nfor i in range(n):\n mod[i, s[i]] = 1\ncount = mod[0, 0]\nfor i in range(1, n):\n idx = s[i]\n for j in range(p):\n mod[i, idx] += mod[i-1, j]\n idx = (idx + 10) % p\nprint(mod[:, 0].sum())', 'n, p = map(int, input().split())\ns = input()\ncount = 0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n count += i + 1\n print(count)\nelse:\n mod = [0] * p\n mod[0] = 1\n tmp = 0\n ten = 1\n for i in s[::-1]:\n ten = ten * 10 % p\n tmp = (tmp + int(i) * ten) % p\n mod[tmp] += 1\n for m in mod:\n count += m * (m - 1) // 2\n print(count)'] | ['Runtime Error', 'Accepted'] | ['s394885137', 's801800335'] | [1561444.0, 3500.0] | [2118.0, 153.0] | [324, 371] |
p02757 | u698176039 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['import sys\ninput = sys.stdin.readline\n\nN,P = map(int,input().split())\nS = list(input())\n\nA = [0]*(N)\nA[-1] = int(S[-1])\nA[-1] %= P\nbase = 10\nfor i in reversed(range(N-1)):\n A[i] = A[i+1] + base*int(S[i])\n A[i] %= P\n base *= 10\n\n\nans = 0\nif P==2 or P==5:\n for i in reversed(range(N)):\n if int(S[i])%P==0:\n ans += i+1\nelse:\n nums = {}\n for a in A:\n nums[a] = 0\n for a in A:\n nums[a] += 1\n \n for n in nums.keys():\n k = nums[n]\n if n==0:\n ans += k*(k+1)//2\n else:\n ans += k*(k-1)//2\n \nprint(ans) \n\n', '\nimport sys\ninput = sys.stdin.readline\n\nN,P = map(int,input().split())\nS = list(input())\n\nA = [0]*(N)\nA[-1] = int(S[-1])\nA[-1] %= P\nbase = 10\nfor i in reversed(range(N-1)):\n A[i] = A[i+1] + base*int(S[i])\n A[i] %= P\n base *= 10\n\n\nans = 0\nif P==2 or P==5:\n for i in reversed(range(N)):\n if int(S[i])%P==0:\n ans += i+1\nelse:\n nums = {}\n for a in A:\n nums[a] = 0\n for a in A:\n nums[a] += 1\n \n for n in nums.keys():\n k = nums[n]\n if n==0:\n ans += k*(k+1)//2\n else:\n ans += k*(k-1)//2\n \nprint(ans) \n\n', 'import sys\n\n\nN,P = map(int,input().split())\nS = list(input())\n\nA = [0]*(N)\nA[-1] = int(S[-1])\nA[-1] %= P\nbase = 10 % P\nfor i in reversed(range(N-1)):\n A[i] = A[i+1] + base*int(S[i])\n A[i] %= P\n base *= 10\n base %= P\n\n\nans = 0\nif P==2 or P==5:\n for i in reversed(range(N)):\n if int(S[i])%P==0:\n ans += i+1\nelse:\n nums = {}\n for a in A:\n if not (a in nums):\n nums[a] = 1\n else:\n nums[a] += 1\n \n for n in nums.keys():\n k = nums[n]\n if n==0:\n ans += k*(k+1)//2\n else:\n ans += k*(k-1)//2\n \nprint(ans) \n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s136464149', 's642295800', 's944766695'] | [6372.0, 6248.0, 13088.0] | [23.0, 23.0, 262.0] | [602, 603, 628] |
p02757 | u698919163 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P = map(int,input().split())\nS = input()\n\ndef solve(S,N,P):\n if P == 2:\n ans = 0\n for i in range(N):\n if int(S[i])%P == 0:\n ans += i+1\n return ans\n if P == 5:\n ans = 0\n for i in range(N):\n if int(S[i])%P == 0:\n ans += i+1\n return ans\n \n S = S[::-1]\n mod_list = [0]*P\n mod_list[0] = 1\n\n mod = P\n tmp = 0\n\n for i in range(N):\n tmp = (tmp + int(S[i])*pow(10,i,mod))%mod\n mod_list[tmp] += 1\n \n ans = 0\n for i in mod_list:\n ans += i*(i-1)//2\n \n return ans\n\nsolve(S,N,P)', 'N,P = map(int,input().split())\nS = input()\n\ndef solve(S,N,P):\n if P == 2:\n ans = 0\n for i in range(N):\n if int(S[i])%P == 0:\n ans += i+1\n return ans\n if P == 5:\n ans = 0\n for i in range(N):\n if int(S[i])%P == 0:\n ans += i+1\n return ans\n \n S = S[::-1]\n mod_list = [0]*P\n mod_list[0] = 1\n\n mod = P\n tmp = 0\n\n for i in range(N):\n tmp = (tmp + int(S[i])*pow(10,i,mod))%mod\n mod_list[tmp] += 1\n \n ans = 0\n for i in mod_list:\n ans += i*(i-1)//2\n \n return ans\n\nprint(solve(S,N,P))'] | ['Wrong Answer', 'Accepted'] | ['s796703758', 's079583197'] | [3500.0, 3560.0] | [438.0, 459.0] | [627, 634] |
p02757 | u723792785 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, mod = map(int, input().split())\ns = input()\n\ntotal = 0\nif mod == 2 or mod == 5:\n\tfor i, q in enumerate(s):\n\t\tif int(q)%mod == 0:\n\t\t\ttotal += i+1\nelse:\n\tcounts = [0]*mod\n\tcounts[0] = 1\n\th = 0\n\t\n\td = 1\n\tfor t in reversed(s):\n\t\tm = int(s)*d%mod\n\t\th = (h+m)%mod\n\t\ttotal += counts[h]\n\t\tcounts[h] += 1\n\t\td = (d*10)%mod\n\nprint(total)', 'n, mod = map(int, input().split())\nS = input()\n\ntotal = 0\nif mod == 2 or mod == 5:\n\tfor i, q in enumerate(S):\n\t\tif int(q)%mod == 0:\n\t\t\ttotal += i+1\nelse:\n\tcounts = [0]*mod\n\tcounts[0] = 1\n\th = 0\n\t\n\td = 1\n\tfor s in reversed(S):\n\t\tm = int(s)*d%mod\n\t\th = (h+m)%mod\n\t\ttotal += counts[h]\n\t\tcounts[h] += 1\n\t\td = (d*10)%mod\n\nprint(total)'] | ['Wrong Answer', 'Accepted'] | ['s431267680', 's673314741'] | [3500.0, 3500.0] | [2104.0, 187.0] | [329, 329] |
p02757 | u785573018 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, p = map(int, input().split())\ns = input()\na = []\nc = 0\nif p == 2:\n b = [0]*n\n for i in range(n):\n if int(s[i])%2 == 0:\n b[i] += 1\n for i in range(n):\n if b[i] == 1:\n c += i+1\nelif p == 5:\n b = [0]*n\n for i in range(n):\n if int(s[i])%5 == 0:\n b[i] += 1\n for i in range(n):\n if b[i] == 1:\n c += i+1\nelse:\n b = [0]*p\n b[0] = 1\n d = [1]\n print(d)\n a.append(int(s[-1])%p)\n for i in range(n-1):\n d.append(d[-1]*10%p)\n for i in range(1, n):\n a.append((int(s[-i-1])*d[i]+a[i-1])%p)\n for i in range(n):\n b[a[i]] += 1\n for i in range(p):\n c += int(b[i]*(b[i]-1)/2)\nprint(c)', 'n, p = map(int, input().split())\ns = input()\na = []\nc = 0\nif p == 2:\n b = [0]*n\n for i in range(n):\n if int(s[i])%2 == 0:\n b[i] += 1\n for i in range(n):\n if b[i] == 1:\n c += i+1\nelif p == 5:\n b = [0]*n\n for i in range(n):\n if int(s[i])%5 == 0:\n b[i] += 1\n for i in range(n):\n if b[i] == 1:\n c += i+1\nelse:\n b = [0]*p\n b[0] = 1\n d = [1]\n a.append(int(s[-1])%p)\n for i in range(n-1):\n d.append(d[-1]*10%p)\n for i in range(1, n):\n a.append((int(s[-i-1])*d[i]+a[i-1])%p)\n for i in range(n):\n b[a[i]] += 1\n for i in range(p):\n c += int(b[i]*(b[i]-1)/2)\nprint(c)'] | ['Wrong Answer', 'Accepted'] | ['s851895977', 's242874109'] | [18884.0, 18888.0] | [243.0, 235.0] | [711, 698] |
p02757 | u788703383 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p = map(int,input().split())\ns = input()\nnum = 0\ns1 = [0]*(n+1)\nans = 0\nif p == 2 or p == 5:\n\tfor i in range(len(s)):\n\t\tif int(s[i])%p == 0:\n\t\t\tans += i+1\t\n\tprint(ans)\n\texit()\nans = 0\narr = [0]*p\ns = s[::-1]\nz = 1\nfor i in range(n):\n\ts1[i+1] = s1[i] + int(s[i])*z\n\tz *=10 %p\n\ts1[i+1] %=p\n\tarr[s1[i]] += 1\narr[s1[n]]+=1\nprint(s1)\nfor i in range(p):\n\tans += arr[i] * (arr[i] - 1) // 2\nprint(ans)\n', 'n,p = map(int,input().split())\n\nans = 0\ns = input()\nif p == 2 or p == 5:\n for i in range(len(s)):\n n = int(s[i])\n if n%p == 0:\n ans += i+1\n print(ans)\n exit()\n\nr = [0]*p\nr[0] = 1\nt = 1\nz = 0\nfor i in reversed(s):\n z = int(i) * t + z\n t *= 10\n t %= p\n z %= p\n r[z] += 1\n\nans = sum(i*(i-1)//2 for i in r)\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s501777202', 's836718373'] | [8560.0, 3500.0] | [2104.0, 167.0] | [396, 363] |
p02757 | u836311327 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from math import factorial\nimport collections\n\ndef permutations_count(n, r):\n \n return factorial(n) // factorial(n - r)\n\n\ndef combinations_count(n, r):\n \n return factorial(n) // (factorial(n - r) * factorial(r))\n\n\nn,p = map(int, input().split())\nS = input()\nsu = 0\n\nif p > 6 or p == 3:\n\n lis = []\n amari = 1\n lis.append(int(S[-1]))\n\n for i in range(2, len(S)+1):\n amari = (amari * 10) % p\n lis.append((int(S[-1*i]) * amari + lis[i-2]) % p)\n\n c = collections.Counter(lis)\n\n for k in c:\n if c[k] > 1:\n su += combinations_count(c[k], 2)\n\n su += c[0]\n\n print(su)\n\nelse:\n S = S[::-1]\n for i in range(len(S)):\n if int(S[i]) % p == 0:\n su += len(S)-i\n print(su)', 'from math import factorial\nimport collections\n\ndef permutations_count(n, r):\n \n return factorial(n) // factorial(n - r)\n\n\ndef combinations_count(n, r):\n \n return factorial(n) // (factorial(n - r) * factorial(r))\n\n\nn,p = map(int, input().split())\nS = input()\nsu = 0\n\nif p > 6:\n\n lis = []\n amari = 1\n lis.append(int(S[-1]))\n\n for i in range(2, len(S)+1):\n amari = (amari * 10) % p\n lis.append((int(S[-1*i]) * amari + lis[i-2]) % p)\n\n c = collections.Counter(lis)\n\n for k in c:\n if c[k] > 1:\n su += combinations_count(c[k], 2)\n\n su += c[0]\n\n print(su)\n\nelse:\n S = S[::-1]\n for i in range(len(S)):\n if int(S[i]) % p == 0:\n su += len(S)-i\n print(su)', 'from math import factorial\nimport collections\n\ndef permutations_count(n, r):\n \n return factorial(n) // factorial(n - r)\n\n\ndef combinations_count(n, r):\n \n return factorial(n) // (factorial(n - r) * factorial(r))\n\n\nn,p = map(int, input().split())\nS = input()\nsu = 0\n\nif p > 6 or p == 3:\n\n lis = []\n amari = 1\n lis.append(int(S[-1]) % p)\n\n for i in range(2, len(S)+1):\n amari = (amari * 10) % p\n lis.append((int(S[-1*i]) * amari + lis[i-2]) % p)\n\n c = collections.Counter(lis)\n\n for k in c:\n if c[k] > 1:\n su += combinations_count(c[k], 2)\n print(c)\n\n su += c[0]\n\n print(su)', 'from math import factorial\nimport collections\n\ndef permutations_count(n, r):\n \n return factorial(n) // factorial(n - r)\n\n\ndef combinations_count(n, r):\n \n return factorial(n) // (factorial(n - r) * factorial(r))\n\n\nn,p = map(int, input().split())\nS = input()\nsu = 0\n\nif p > 6 or p == 3:\n\n lis = []\n amari = 1\n lis.append(int(S[-1]) % p)\n\n for i in range(2, len(S)+1):\n amari = (amari * 10) % p\n lis.append((int(S[-1*i]) * amari + lis[i-2]) % p)\n\n c = collections.Counter(lis)\n\n for k in c:\n if c[k] > 1:\n su += combinations_count(c[k], 2)\n\n su += c[0]\n\n print(su)\n\nelse:\n S = S[::-1]\n for i in range(len(S)):\n if int(S[i]) % p == 0:\n su += len(S)-i\n print(su)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s047233761', 's371305271', 's788778201', 's997707301'] | [17808.0, 17632.0, 18868.0, 17728.0] | [505.0, 312.0, 516.0, 503.0] | [786, 776, 680, 790] |
p02757 | u866746776 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n, p = map(int, input().rstrip().split())\ns = input().rstrip()\n\nif p == 2 or p == 5:\n ans = 0\n s = map(int, s)\n for i, c in enumerate(s):\n if c % p == 0:\n ans += i + 1\n print(ans)\nelse:\n s = s[::-1]\n cnt = [0] * p\n k = 0\n cnt[k] = 1\n for i, c in enumerate(map(int(s))):\n k = (c * (10**i) + k) % p\n cnt[k] += 1\n\n ans = 0\n for i in range(p):\n ans += cnt[i] * (cnt[i] - 1) // 2\n print(ans)\n', 'n, p = map(int, input().rstrip().split())\ns = input().rstrip()\n\nif p == 2 or p == 5:\n ans = 0\n s = map(int, s)\n for i, c in enumerate(s):\n if c % p == 0:\n ans += i + 1\n print(ans)\nelse:\n s = s[::-1]\n cnt = [0] * p\n k = 0\n cnt[k] = 1\n w = 1\n for i, c in enumerate(map(int, s)):\n k = c * w + k\n w *= 10\n while k >= p:\n k -= p\n while w >= p:\n w -= p\n cnt[k] += 1\n\n ans = 0\n for i in range(p):\n ans += cnt[i] * (cnt[i] - 1) // 2\n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s488838375', 's814447499'] | [3500.0, 3500.0] | [289.0, 388.0] | [462, 558] |
p02757 | u872887731 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['ii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn,p = mi()\ns = input().strip()\nsrev = s[-1]\n\nif p == 2 or p == 5:\n ans = 0\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i +1\n print(ans)\n exit()\n\nacum = []\nfrom collections import defaultdict\nd = defaultdict(lambda :0)\nfor i in range(1,n+1):\n a = int(srev[:i])\n modd = a % p\n d[modd] += 1\n acum.append((modd,d[modd]))\nans = d[0]\nfor i in range(n):\n ans += d[acum[i][0]] - acum[i][1]\nprint(ans)\n\n\n', 'ii = lambda : int(input())\nmi = lambda : map(int,input().split())\nli = lambda : list(map(int,input().split()))\n\nn,p = mi()\ns = input()\nsrev = s[::-1]\n\nif p == 2 or p == 5:\n ans = 0\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += i +1\n print(ans)\n exit()\n\nacum = []\nfrom collections import defaultdict\nd = defaultdict(lambda :0)\nd = [0] * p\nnum = 0\ntenpow = 1\nfor i in range(0,n):\n a = int(srev[i])\n a = num + a *tenpow \n tenpow = tenpow * 10 % p\n modd = a % p\n num = modd\n d[modd] += 1\n acum.append((modd,d[modd]))\nans = d[0]\nfor i in range(n):\n ans += d[acum[i][0]] - acum[i][1]\nprint(ans)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s594737940', 's169253948'] | [26344.0, 24544.0] | [250.0, 299.0] | [560, 650] |
p02757 | u873927631 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, P: int, S: int):\n if N == 1:\n print(1 if S[0]%P == 0 else 0)\n arr = [[int(S[i])%P for i in range(N)]]\n for i in range(2,N):\n prevArr = arr[-1]\n arr.append([0]*(N-i+1))\n for j in range(N-i+1):\n sum = 0\n for k in range(j):\n arr[-1][j] =(arr[-1][j]+prevArr[k])%P\n print(arr)\n\n\n \n \n # sDiv = 0\n # coeff = 1\n # for j in range(i,N):\n # sDiv= (sDiv*coeff + arr[j])%P\n # coeff*=10\n # if sDiv == 0:\n # sum+=1\n # print(sum)\n return\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n P = int(next(tokens)) # type: int\n S = next(tokens) # type: int\n solve(N, P, S)\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\n\ndef solve(N: int, P: int, S: str):\n if 10%P == 0:\n sum = 0\n for i in range(1,N+1):\n if int(S[-i]) % P == 0:\n sum += (N-i)+1\n print(sum)\n return\n else:\n current = 0\n C = 1\n counts = defaultdict(int)\n for i in range(1,N+1):\n if i == 1:\n current = int(S[-1])%P\n else:\n current = (int(S[-i])*C + current)%P\n counts[current]+=1\n C=C*10%P\n sum = 0\n for k in counts:\n c = counts[k]\n sum += int((c*(c-1)/2))\n sum += counts[0]\n print(sum)\n\n \n \n # sDiv = 0\n # coeff = 1\n # for j in range(i,N):\n # sDiv= (sDiv*coeff + arr[j])%P\n # coeff*=10\n # if sDiv == 0:\n # sum+=1\n # print(sum)\n return\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n P = int(next(tokens)) # type: int\n S = next(tokens) # type: int\n solve(N, P, S)\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s756585091', 's940597791'] | [6844.0, 4612.0] | [2104.0, 148.0] | [1165, 1474] |
p02757 | u888092736 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import defaultdict\n\nn, p = map(int, input(). split())\ns = input()\n\ncnt = 0\nif 10 % p == 0:\n for i, c in enumerate(s, 1):\n if int(c) % p == 0:\n cnt += 1\nelse:\n rem_dic = defaultdict(int)\n rem_dic[0] = 1\n for i in range(1, n + 1):\n rem_dic[int(s[n - 1:]) % p] += 1\n for rem_cnt in rem_dic.values():\n cnt += rem_cnt * (rem_cnt - 1) // 2\n\nprint(cnt)', 'n, p = map(int, input(). split())\ns = list(map(int, input()[::-1]))\n\ncnt = 0\nif 10 % p == 0:\n for i, c in enumerate(s):\n if int(c) % p == 0:\n cnt += n - i\nelse:\n accmod = [0] * p\n accmod[0] = 1\n num = 0\n for i in range(n):\n num = (num + s[i] * pow(10, i, p)) % p\n accmod[num] += 1\n for v in accmod:\n if v > 1:\n cnt += v * (v - 1) // 2\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s061702474', 's411497540'] | [3876.0, 5156.0] | [113.0, 470.0] | [409, 414] |
p02757 | u898967808 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['from collections import Counter\n\nn,p = map(int,input().split())\ns = input()\n\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += (i+1)\n\nprint(ans) ', 'from collections import Counter\n\nn,p = map(int,input().split())\ns = input()\n\nans = 0\nif p == 2 or p == 5:\n for i in range(n):\n if int(s[i]) % p == 0:\n ans += (i+1)\n\nelse: \n mods = [0]*p\n mods[0] = 1\n m = 0\n d = 1 \n for i in range(n):\n m = (m + int(s[-i-1])*d) % p\n d = (d * 10) % p \n mods[m] += 1\n \n for i in range(p):\n ans += mods[i]*(mods[i]-1)//2\n\nprint(ans) '] | ['Wrong Answer', 'Accepted'] | ['s215676369', 's834295488'] | [3872.0, 3752.0] | [133.0, 174.0] | [418, 404] |
p02757 | u899308536 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P = list(map(int,input().split()))\nS = input()\n\nU = [0]\na = 0\n\nfor i in range(N):\n a += int(S[-i-1])*(pow(10,i)%P)\n a %= P\n U.append(a)\nprint(U)\n\nc = 0\nfor i in range(P):\n\n m = U.count(i)\n c += m*(m-1)//2\nprint(c)', '\n\nN,P = list(map(int,input().split()))\nS = input()\n\nif P == 2:\n c = 0\n for i in range(N):\n u = int(S[i])\n if u % 2 == 0:\n c += i+1\n print(c)\n \nelif P == 5:\n c = 0\n for i in range(N):\n u = int(S[i])\n if u % 5 == 0:\n c += i+1\n print(c)\n\nelse:\n U = [0]\n a = 0\n t = 1\n \n for i in range(N):\n t %= P\n a += int(S[-i-1])*t\n a %= P\n t *= 10\n U.append(a)\n U.append(10001)\n # print(U)\n \n # t3 = time.time()\n \n c = 0\n \n \n U.sort()\n # print(U)\n idx = 0\n q = -1\n for i in range(N+2):\n if q != U[i]:\n q = U[i]\n m = i - idx\n idx = i\n c += m*(m-1)//2\n print(c)\n # t4 = time.time()\n # print(t4-t3)\n \n # 10032'] | ['Wrong Answer', 'Accepted'] | ['s508696687', 's130926315'] | [3812.0, 11900.0] | [2108.0, 267.0] | [230, 927] |
p02757 | u918601425 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P=[int(s) for s in input().split()]\nS=list(input())\nif P!=2 and P!=5:\n ls=[0 for _ in range(N)]\n mod=[0 for _ in range(P)]\n d=10\n ls[0]=int(S[-1])\n mod[ls[0]]+=1\n for i in range(1,N):\n ls[i]=(ls[i-1]+d*int(S[-1-i]))%2019\n d=(d*10)%2019\n mod[ls[i]]+=1\n #print(ls)\n #print(mod) \n ans=mod[0]\n for i in range(N):\n m=ls[i]\n mod[ls[i]]-=1\n ans+=mod[ls[i]]\nelse:\n ans=0\n for i in range(N):\n if int(S[i])%P==0:\n ans+=i+1\nprint(ans)\n \n', 'N,P=[int(s) for s in input().split()]\nS=list(input())\nif P!=2 and P!=5:\n ls=[0 for _ in range(N)]\n mod=[0 for _ in range(P)]\n d=10\n ls[0]=int(S[-1])%P\n mod[ls[0]]+=1\n for i in range(1,N):\n ls[i]=(ls[i-1]+d*int(S[-1-i]))%P\n d=(d*10)%P\n mod[ls[i]]+=1\n #print(ls)\n #print(mod) \n ans=mod[0]\n for i in range(N):\n m=ls[i]\n mod[ls[i]]-=1\n ans+=mod[ls[i]]\nelse:\n ans=0\n for i in range(N):\n if int(S[i])%P==0:\n ans+=i+1\nprint(ans)\n \n'] | ['Runtime Error', 'Accepted'] | ['s080255039', 's761559674'] | [12056.0, 12576.0] | [270.0, 269.0] | [469, 465] |
p02757 | u969190727 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p=map(int,input().split())\ns=input()[::-1]\nA=[0]*n\nA[0]=int(s[0])\nt=1\nfor i in range(1,n):\n A[i]=(int(s[i])*t+A[i-1])%p\n t=(t*10)%p\nans=0\nimport collections\nD=collections.defaultdict(int)\nD[0]=1\nif p!=2 and p!=5:\n for i in range(n):\n ans+=D[A[i]]\n D[A[i]]+=1\n print(ans)\nelse:\n s=s[::-1]\n ans=0\n for i in range(n):\n if int(s[i])%p==0:\n ans+=i+1\n print(ans)\n\n\n\n', 'n,p=map(int,input().split())\ns=input()[::-1]\nA=[0]*n\nA[0]=int(s[0])\nt=1\nfor i in range(1,n):\n A[i]=(int(s[i])*t+A[i-1])%p\n t=(t*10)%p\nans=0\nimport collections\nD=collections.defaultdict(int)\nD[0]=1\nif p!=2 and p!=5:\n for i in range(n):\n ans+=D[p-A[i]]\n D[A[i]]+=1\n print(ans)\nelse:\n s=s[::-1]\n ans=0\n for i in range(n):\n if int(s[i])%p==0:\n ans+=i+1\n print(ans)', 'n,p=map(int,input().split())\ns=input()[::-1]\nA=[0]*n\nA[0]=int(s[0])%p\nt=10\nfor i in range(1,n):\n A[i]=(int(s[i])*t+A[i-1])%p\n t=(t*10)%p\nans=0\nimport collections\nD=collections.defaultdict(int)\nD[0]=1\nif p!=2 and p!=5:\n for i in range(n):\n ans+=D[A[i]]\n D[A[i]]+=1\n print(ans)\nelse:\n s=s[::-1]\n ans=0\n for i in range(n):\n if int(s[i])%p==0:\n ans+=i+1\n print(ans)\n\n\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s134189595', 's979271280', 's620641610'] | [12040.0, 12056.0, 12044.0] | [270.0, 260.0, 260.0] | [384, 382, 387] |
p02757 | u971124021 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p = list(map(int,input().split()))\nS = input()\n\nif p == 2 or p == 5:\n ans = 0\n for i,s in enumerate(S):\n if int(s)%p == 0:\n ans += i+1\n print(ans)\n exit()\n\nM = [0]*p\npre = 0\nans = 0\ni = 1\nfor s in S[::-1]:\n pre += s*i\n pre %= p\n M[pre] += 1\n i *= 10\n\nM[0] += 1\nans = sum(map(lambda m:(m*(m-1))//2, M))\nprint(ans)\n\n', 'n,p = list(map(int,input().split()))\nS = input()\n\nif p == 2 or p == 5:\n ans = 0\n for i,s in enumerate(S):\n if int(s)%p == 0:\n ans += i+1\n print(ans)\n exit()\n\ndef MS(i,s,pre):\n return (s*i +pre)%p\n \nM = [0]*p\nM[0] = 1\nt = 1\npre = 0\nfor s in S[::-1]:\n pre += (int(s)*t)%p\n M[pre] += 1\n t *= 10\n\nans = sum(map(lambda m:(m*(m-1))//2, M))\nprint(ans)\n\n', 'n,p = list(map(int,input().split()))\nS = input()\n\nif p == 2 or p == 5:\n ans = 0\n for i,s in enumerate(S):\n if int(s)%p == 0:\n ans += i+1\n print(ans)\n exit()\n\ndef MS(i,s,pre):\n return (int(s)*i+pre)%p\n \nM = [0]*p\nM[0] = 1\ni = 1\npre = 0\nfor s in S[::-1]:\n \n pre = pre + int(s)*i\n pre = pre%p\n M[pre] += 1\n i = i*10%p\n\nans = sum(map(lambda m:(m*(m-1))//2, M))\nprint(ans)\n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s028145719', 's802759772', 's858043336'] | [3500.0, 3500.0, 3500.0] | [106.0, 101.0, 148.0] | [332, 362, 410] |
p02757 | u994521204 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['n,p=map(int,input().split())\nS=input()\ns=int(s)\nans=0\nif p==5:\n for i in range(n):\n if int(S[i])==5 or int(S[i])==0:\n ans+=i+1\nelif p==2:\n for i in range(n):\n if int(S[i])%2==0:\n ans+=i+1\nelse:\n kouho=[0]*p\n for i in range(n):\n a=int(S[-i:])\n a%=p\n kouho[a]+=1\n for j in range(p):\n z=kouho[j]\n ans+=z*(z-1)//2\n ans+=kouho[0]\nprint(ans)', 'from collections import defaultdict\nn,p=map(int,input().split())\nS=input()\nans=0\nif p==5:\n for i in range(n):\n if int(S[i])==5 or int(S[i])==0:\n ans+=i+1\nelif p==2:\n for i in range(n):\n if int(S[i])%2==0:\n ans+=i+1\nelse:\n kouho=defaultdict(int)\n s=0\n ruijo=1\n for i in range(n):\n ruijo%=p\n s+=int(S[-(i+1)])*(ruijo)\n a=s%p\n kouho[a]+=1\n ruijo*=10\n for j in range(p):\n z=kouho[j]\n ans+=z*(z-1)//2\n ans+=kouho[0]\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s848430166', 's001043253'] | [3500.0, 4452.0] | [18.0, 208.0] | [424, 530] |
p02757 | u996731299 | 2,000 | 1,048,576 | Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S \- there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0` also count, and substrings originated from different positions in S are distinguished, even if they are equal as strings or integers. Compute this count to help Takahashi. | ['N,P=map(int,input().split())\nS=list(map(int,list(input())))\ncount=0\n\nif P!=2 and P!=5:\n for i in range(0,N):\n chec=S[i]\n j=0\n while i+j<N:\n \u3000\u3000\u3000chec%=P\n if chec==0:\n count+=1\n j+=1\n if i+j<N:\n chec=chec*10+S[i+j]\nif P==2:\n for i in range(N):\n if S[i]%2==0:\n count+=i+1\nif P==5:\n for i in range(N):\n if S[i]==0 or S[i]==5:\n count+=i+1\nprint(count)\n\n\n \n\n\n', '#E\nN,P=map(int,input().split())\nS=input()\nans=0\nif P in (2,5):\n for i,s in enumerate(S):\n if int(s)%P==0:\n ans+=i+1\nelse:\n cnt=[0 for _ in range(P)]\n CS=0\n PLC=1\n for s in S[::-1]:\n tmp=(int(s)*PLC)%P\n CS=(CS+tmp)%P\n cnt[CS]+=1\n PLC=(PLC*10)%P\n # print(CS)\n # print(cnt)\n for c in cnt:\n ans+=c*(c-1)//2\n ans+=cnt[0]\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s292252055', 's966841428'] | [2940.0, 3500.0] | [17.0, 176.0] | [527, 415] |
p02758 | u535803878 | 2,000 | 1,048,576 | There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous. | ['\nimport numpy as np\n\nM = 998244353\n\nn = int(input())\nxs = [0] * n\nds = [0] * n\nfor i in range(n):\n x, d = (int(c) for c in input().split())\n ds[i] = d\n xs[i] = x\nxs = np.array(xs)\nds = np.array(ds)\n\nimport sys\nsys.setrecursionlimit(n)\n\nindex = xs.argsort()\nxs = xs[index]\nds = ds[index]\n\ndef _sub(i):\n \n if i==n-1:\n return 2, n\n res = 1\n ind = i+1\n while True:\n if (xs[i]+ds[i] <= xs[ind]):\n break\n o, ind = _sub(ind)\n res *= o\n res %= M\n if ind>=n:\n break\n return res+1, ind\nout = []\ndone = 0\nwhile True:\n o, done = _sub(done)\n out.append(o)\n if done>=n:\n break\nresult = 1\nfor o in out:\n result *= o\n result %= M\nprint(result)', '! cp answer/F/in/03.txt tmp_in\n\nimport numpy as np\n\nM = 998244353\n\nn = int(input())\nxs = [0] * n\nds = [0] * n\nfor i in range(n):\n x, d = (int(c) for c in input().split())\n ds[i] = d\n xs[i] = x\nxs = np.array(xs)\nds = np.array(ds)\n\nimport sys\nsys.setrecursionlimit(max(1000,n))\n\nindex = xs.argsort()\nxs = xs[index]\nds = ds[index]\n\ndef _sub(i):\n \n if i==n-1:\n return 2, n\n res = 1\n ind = i+1\n while True:\n if (xs[i]+ds[i] <= xs[ind]):\n break\n o, ind = _sub(ind)\n res *= o\n res %= M\n if ind>=n:\n break\n return res+1, ind\nout = []\ndone = 0\nwhile True:\n o, done = _sub(done)\n out.append(o)\n if done>=n:\n break\nresult = 1\nfor o in out:\n result *= o\n result %= M\nprint(result)', 'import sys\ninput = lambda : sys.stdin.readline().rstrip()\n\nM = 998244353\n\nn = int(input())\nxs = [0] * n\nds = [0] * n\nfor i in range(n):\n x, d = (int(c) for c in input().split())\n ds[i] = d\n xs[i] = (x,i)\n\nimport sys\nsys.setrecursionlimit(max(1000,n))\n\nxs.sort()\nindex = [x[1] for x in xs]\nxs = [x[0] for x in xs]\nds = [ds[ind] for ind in index]\n\ndef _sub(i):\n \n if i==n-1:\n return 2, n\n res = 1\n ind = i+1\n while True:\n if (xs[i]+ds[i] <= xs[ind]):\n break\n o, ind = _sub(ind)\n res *= o\n res %= M\n if ind>=n:\n break\n return res+1, ind\nout = []\ndone = 0\nwhile True:\n o, done = _sub(done)\n out.append(o)\n if done>=n:\n break\nresult = 1\nfor o in out:\n result *= o\n result %= M\nprint(result)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s616474777', 's672777796', 's895799702'] | [190092.0, 2940.0, 198700.0] | [1270.0, 17.0, 1417.0] | [845, 886, 903] |
p02758 | u593567568 | 2,000 | 1,048,576 | There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous. | ['import sys\nimport bisect\nsys.setrecursionlimit(10 ** 7)\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n\nclass SegmentTree:\n \n\n def __init__(self, N, operator, unit, a=None):\n self.op = operator\n self.UNIT = unit\n\n self.N0 = 2**(N-1).bit_length()\n self.tree = [self.UNIT]*(2*self.N0)\n if a != None:\n self.tree[self.N0:self.N0+N] = a[:]\n for k in range(self.N0-1, 0, -1):\n self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])\n\n \n def update(self, k, x):\n k += self.N0\n self.tree[k] = x\n k //= 2\n while k:\n self.tree[k] = self.op(self.tree[2*k], self.tree[2*k+1])\n k //= 2\n\n \n def query(self, l, r):\n L = l + self.N0\n R = r + self.N0\n s = self.UNIT\n while L < R:\n if R & 1:\n R -= 1\n s = self.op(self.tree[R], s)\n if L & 1:\n s = self.op(s, self.tree[L])\n L += 1\n L >>= 1\n R >>= 1\n return s\n\n def get(self, k): \n return self.tree[k + self.N0]\n\n def all(self):\n return self.tree[1]\n\n\nN = int(readline())\nMOD = 998244353\n\nXD = [[int(x) for x in readline().split()] for _ in range(N)]\nXD.sort()\nX = [x for x, _ in XD]\n\nB = [bisect.bisect_left(X, x + d) for x, d in XD] + [0]\nseg = SegmentTree(N+1, max, 0, B)\n\n\n# print(X)\n\nCNT = [0] * (N)\nfor i in range(N-1, -1, -1):\n m = seg.query(i, B[i])\n c = max(B[i], m)\n CNT[i] = c - i\n seg.update(i, c)\n\n\n# print(CNT)\nprint(0)\nexit()\n\ns = 0\nfor c in CNT:\n m = pow(2, c - 1, MOD) - 1\n m %= MOD\n s += m\n s %= MOD\n\nal = pow(2, N, MOD)\nans = al - s\nans %= MOD\n\nprint(ans)\n', 'import sys\nimport bisect\nfrom collections import deque\nsys.setrecursionlimit(10 ** 7)\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n\nN = int(readline())\nMOD = 998244353\n\nXD = [[int(x) for x in readline().split()] for _ in range(N)]\nXD.sort()\n#X = [x for x, _ in XD]\n\nNXT = deque()\nE = [[] for _ in range(N)]\n\nfor i in range(N - 1, -1, -1):\n x, d = XD[i]\n\n while NXT:\n j, nx = NXT.pop()\n\n if nx < x + d:\n E[i].append(j)\n else:\n NXT.append((j, nx))\n break\n\n NXT.append((i, x))\n\n\ndef dfs(i):\n rtn = 1\n for v in E[i]:\n rtn *= dfs(v)\n rtn %= MOD\n return rtn + 1\n\n\nans = 1\nfor i, x in NXT:\n ans *= dfs(i)\n ans %= MOD\n\nprint(ans % MOD)\n'] | ['Wrong Answer', 'Accepted'] | ['s246259488', 's062392987'] | [59796.0, 246348.0] | [2111.0, 1424.0] | [2233, 782] |
p02758 | u686230543 | 2,000 | 1,048,576 | There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous. | ['import heapq\n\nmod = 998244353\n\nn = int(input())\nrobot = [tuple(map(int, input().split())) for _ in range(n)]\nrobot.sort(reverse=True)\nparent = list(range(n))\n\nroot = []\nfor i in range(n):\n x, d = robot[i]\n while root:\n r = heapq.heappop(root)\n if r[0] < x + d:\n parent[r[1]] = i\n else:\n heapq.heappush(root, r)\n break\n heapq.heappush(root, (x, i))\n \ncount = 1\ndp = [1] * n\nfor i in range(n):\n p = parent[i]\n if p == i:\n count = count * dp[i] % mod\n else:\n dp[p] = dp[p] * (dp[i] + 1) % mod\nprint(count)', 'import heapq\n\nmod = 998244353\n\ndef dfs(v: int, child) -> int:\n res = 1\n for u in child[v]:\n res = res * dfs(u) % mod\n return res + 1\n\nn = int(input())\nrobot = [tuple(map(int, input().split())) for _ in range(n)]\nrobot.sort()\nchild = [[] for _ in range(n)]\n\nroot = []\nfor i in range(n-1, -1, -1):\n x, d = robot[i]\n while root:\n r = heapq.heappop(root)\n if r[0] < x + d:\n child[i].append(r[1])\n else:\n heapq.heappush(root, r)\n break\n heapq.heappush(root, (x, i))\n \ncount = 1\nfor r in root:\n count = count * dfs(r[1], child) % mod\nprint(count)', 'import heapq\n\nmod = 998244353\n\nn = int(input())\nrobot = [tuple(map(int, input().split())) for _ in range(n)]\nrobot.sort(reverse=True)\nparent = list(range(n))\n\nroot = []\nfor i in range(n):\n x, d = robot[i]\n while root:\n r = heapq.heappop(root)\n if r[0] < x + d:\n parent[r[1]] = i\n else:\n heapq.heappush(root, r)\n break\n heapq.heappush(root, (x, i))\n \ncount = 1\ndp = [1] * n\nfor i in range(n):\n p = parent[i]\n if p == i:\n count = count * (dp[i] + 1) % mod\n else:\n dp[p] = dp[p] * (dp[i] + 1) % mod\nprint(count)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s640641144', 's851041776', 's774933345'] | [47916.0, 62520.0, 47916.0] | [1603.0, 1572.0, 1549.0] | [539, 575, 545] |
p02758 | u716530146 | 2,000 | 1,048,576 | There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous. | [" import sys, math, itertools, collections, bisect\ninput = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')\ninf = float('inf') ;mod = 998244353\nmans = 998244353 ;ans = 0 ;count = 0 ;pro = 1\nsys.setrecursionlimit(10**6)\n\nn = int(input())\nXD = [tuple(map(int,input().split())) for i in range(n)]\nXD.append((-10**10,inf))\nXD.sort()\n\nnow = 0\nvisited1 = [] \ndef dfs(node):\n visited1.append(node)\n\n global now\n pro = 1\n while now < n :\n if XD[now+1][0] < XD[node][0] + XD[node][1]:\n now += 1\n pro *= dfs(now)\n pro %= mod\n else:break\n return pro + 1\nans = dfs(0)\nprint((ans-1)%mod)\n\n\n", "import sys, math, itertools, collections, bisect\ninput = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')\ninf = float('inf') ;mod = 998244353\nmans = 998244353 ;ans = 0 ;count = 0 ;pro = 1\nsys.setrecursionlimit(10**6)\n\nn = int(input())\nXD = [tuple(map(int,input().split())) for i in range(n)]\nXD.append((-10**10,inf))\nXD.sort()\n\nnow = 0\ndef dfs(node):\n global now\n pro = 1\n while now < n :\n if XD[now+1][0] < XD[node][0] + XD[node][1]:\n now += 1\n pro *= dfs(now)\n pro %= mod\n else:break\n return pro + 1\nans = dfs(0)\nprint((ans-1)%mod)\n"] | ['Runtime Error', 'Accepted'] | ['s721038050', 's592084967'] | [2940.0, 202376.0] | [17.0, 1023.0] | [614, 571] |
p02760 | u000540018 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ["import sys\nimport numpy as np\n\nlines = sys.stdin.readlines()\nbingo_card = np.zeros([3,3])\nfor i, l in enumerate(input()):\n if i <= 2:\n bingo_card[i] = [int(num) for num in l.split()]\n else:\n bingo_card[bingo_card == int(l)] = None\n \ncheck_arr = np.isnan(bingo_card)\nif check_arr[0].sum() == 3 or check_arr[1].sum() == 3 or check_arr[2].sum() == 3:\n print('Yes')\nelif check_arr[:, 0].sum() == 3 or check_arr[:, 1].sum() == 3 or check_arr[:, 2].sum() == 3:\n print('Yes')\nelif check_arr[0,0] and check_arr[1,1] and check_arr[2,2]:\n print('Yes')\nelif check_arr[0,2] and check_arr[1,1] and check_arr[2,0]:\n print('Yes')\nelse:\n print('No')", "import sys\nimport numpy as np\n\nlines = sys.stdin.readlines()\nbingo_card = np.zeros([3,3])\nfor i, l in enumerate(lines):\n if i <= 2:\n bingo_card[i] = [int(num) for num in l.split()]\n else:\n bingo_card[bingo_card == int(l)] = None\n \ncheck_arr = np.isnan(bingo_card)\nif check_arr[0].sum() == 3 or check_arr[1].sum() == 3 or check_arr[2].sum() == 3:\n print('Yes')\nelif check_arr[:, 0].sum() == 3 or check_arr[:, 1].sum() == 3 or check_arr[:, 2].sum() == 3:\n print('Yes')\nelif check_arr[0,0] and check_arr[1,1] and check_arr[2,2]:\n print('Yes')\nelif check_arr[0,2] and check_arr[1,1] and check_arr[2,0]:\n print('Yes')\nelse:\n print('No')\n"] | ['Runtime Error', 'Accepted'] | ['s100274923', 's369984807'] | [12500.0, 12528.0] | [154.0, 156.0] | [675, 674] |
p02760 | u004482945 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['60 88 34\n92 41 43\n65 73 48\n10\n60\n43\n88\n11\n48\n73\n65\n41\n92\n34', "a = [list(map(int, input().split())) for i in range(3)]\nn = int(input())\n\nfor _ in range(n):\n b = int(input())\n for y in range(3):\n for x in range(3):\n if a[y][x] == b:\n a[y][x] = -1\n\nfor y in range(3):\n f = True\n for x in range(3):\n if a[y][x] != -1:\n f = False\n if f:\n print('Yes')\n exit()\n \nfor x in range(3):\n f = True\n for y in range(3):\n if a[y][x] != -1:\n f = False\n if f:\n print('Yes')\n exit()\n \nf = True\nfor x in range(3):\n if a[x][x] != -1:\n f = False\nif f:\n print('Yes')\n exit()\n \nf = True\nfor x in range(3):\n if a[x][2-x] != -1:\n f = False\nif f:\n print('Yes')\n exit()\n \nprint('No')"] | ['Runtime Error', 'Accepted'] | ['s199950847', 's595977660'] | [9008.0, 9176.0] | [24.0, 30.0] | [59, 664] |
p02760 | u007018214 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['import sys\n#n=int(input())\n#l = list(map(int,input().split()))\n#a,b,c = map(int,input().split())\n\nly = []\n\nfor i in range(3):\n ly.append(list(map(int,input().split())))\n\nlt = []\n\nfor i in range(3):\n l = []\n for j in range(3):\n l.append(ly[j][i])\n lt.append(l)\n\nl = ly+lt + [[ly[0][0],ly[1][1],lt[2][2]]] + [[ly[0][2],ly[1][1],ly[2][0]]]\nprint(l)\n\nn = int(input())\nnm = []\nfor i in range(n):\n s = int(input())\n nm.append(s)\n\nfor i in l:\n t = [0,0,0]\n if i [0] in nm:\n t[0] = 1\n if i [1] in nm:\n t[1] = 1\n if i [2] in nm:\n t[2] = 1\n if sum(t) == 3:\n print("Yes")\n sys.exit()\nprint("No")', 'import sys\n#n=int(input())\n#l = list(map(int,input().split()))\n#a,b,c = map(int,input().split())\n\nly = []\n\nfor i in range(3):\n ly.append(list(map(int,input().split())))\n\nlt = []\n\nfor i in range(3):\n l = []\n for j in range(3):\n l.append(ly[j][i])\n lt.append(l)\n\nl = ly+lt + [[ly[0][0],ly[1][1],lt[2][2]]] + [[ly[0][2],ly[1][1],ly[2][0]]]\n\nn = int(input())\nnm = []\nfor i in range(n):\n s = int(input())\n nm.append(s)\n\nfor i in l:\n t = [0,0,0]\n if i [0] in nm:\n t[0] = 1\n if i [1] in nm:\n t[1] = 1\n if i [2] in nm:\n t[2] = 1\n if sum(t) == 3:\n print("Yes")\n sys.exit()\nprint("No")'] | ['Wrong Answer', 'Accepted'] | ['s818850944', 's741135004'] | [3064.0, 3064.0] | [17.0, 17.0] | [659, 650] |
p02760 | u008079810 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ["A=[]\nfor i in range(3):\n A.append(list(map(int,input().split())))\nN=int(input())\nfor i in range(N):\n b=int(input())\n for ii in range(3):\n for iii in range(3):\n if A[ii][iii]==b:\n A[ii][iii]=0\nprint(A)\nflag=False\nfor i in range(3):\n if A[i][:]==[0,0,0]:\n flag=True\n elif A[0][i]==0:\n if A[1][i]==0 and A[2][i]==0:\n flag=True\n elif A[1][1]==0:\n if A[0][2]==0 and A[2][0]==0:\n flag=True\n elif A[0][0]==0 and A[2][2]==0:\n flag=True\nif flag:\n print('Yes')\nelse:\n print('No')", "A=[]\nfor i in range(3):\n A.append(list(map(int,input().split())))\nN=int(input())\nfor i in range(N):\n b=int(input())\n for ii in range(3):\n for iii in range(3):\n if A[ii][iii]==b:\n A[ii][iii]=0\nprint(A)\nflag=False\nfor i in range(3):\n if A[i][:]==[0,0,0]:\n flag=True\n elif A[0][i]==0 and A[1][i]==0 and A[2][i]==0:\n flag=True\n elif A[1][1]==0:\n if A[0][2]==0 and A[2][0]==0:\n flag=True\n elif A[0][0]==0 and A[2][2]==0:\n flag=True\nif flag:\n print('Yes')\nelse:\n print('No')", "A=[]\nfor i in range(3):\n A.append(list(map(int,input().split())))\nN=int(input())\nfor i in range(N):\n b=int(input())\n for ii in range(3):\n for iii in range(3):\n if A[ii][iii]==b:\n A[ii][iii]=0\n\nflag=False\nfor i in range(3):\n if A[i][:]==[0,0,0]:\n flag=True\n elif A[0][i]==0 and A[1][i]==0 and A[2][i]==0:\n flag=True\n elif A[1][1]==0:\n if A[0][2]==0 and A[2][0]==0:\n flag=True\n elif A[0][0]==0 and A[2][2]==0:\n flag=True\nif flag:\n print('Yes')\nelse:\n print('No')"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s063863335', 's988831317', 's449038182'] | [3064.0, 3064.0, 3064.0] | [17.0, 17.0, 17.0] | [587, 579, 567] |
p02760 | u013292712 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['l=[]\nfor i in range(3):\n l.append(list(map(int,input().split())))\nn=int(input())\nl1=[]\nfor i in range(n):\n l1.append(int(input())\nfor i in range(len(l)):\n for j in range(len(l)):\n if(l[i][j] in l1):\n l[i][j]=0\nf=0\nif((l[0][0]==0 and l[0][1]==0 and l[0][2]==0) or (l[1][0]==0 and l[1][1]==0 and l[1][2]==0) or (l[2][0]==0 and l[2][1]==0 and l[2][2]==0))\n f=1\nelif((l[0][0]==0 and l[1][0]==0 and l[2][0]==0) or (l[0][1]==0 and l[1][1]==0 and l[2][1]==0) or (l[0][2]==0 and l[1][2]==0 and l[2][2]==0))\n f=1\nelif((l[0][0]==0 and l[1][1]==0 and l[2][2]==0) or (l[0][2]==0 and l[1][1]==0 and l[2][0]==0)):\n f=1\nif(f==1):\n print("Yes")\nelse:\n print("No")', 'l=[]\nfor i in range(3):\n l.append(list(map(int,input().split())))\nn=int(input())\nl1=[]\nfor i in range(n):\n l1.append(int(input()))\nfor i in range(len(l)):\n for j in range(len(l)):\n if(l[i][j] in l1):\n l[i][j]=0\nf=0\nif((l[0][0]==0 and l[0][1]==0 and l[0][2]==0) or (l[1][0]==0 and l[1][1]==0 and l[1][2]==0) or (l[2][0]==0 and l[2][1]==0 and l[2][2]==0)):\n f=1\nelif((l[0][0]==0 and l[1][0]==0 and l[2][0]==0) or (l[0][1]==0 and l[1][1]==0 and l[2][1]==0) or (l[0][2]==0 and l[1][2]==0 and l[2][2]==0)):\n f=1\nelif((l[0][0]==0 and l[1][1]==0 and l[2][2]==0) or (l[0][2]==0 and l[1][1]==0 and l[2][0]==0)):\n f=1\nif(f==1):\n print("Yes")\nelse:\n print("No")'] | ['Runtime Error', 'Accepted'] | ['s612960093', 's798053602'] | [3064.0, 3188.0] | [17.0, 17.0] | [685, 688] |
p02760 | u015993380 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['card = [[int(x) for x in input().split()] for y in range(3)]\nbools = [[0,0,0],[0,0,0],[0,0,0]]\nn = int(input())\nfor _ in range(n):\n x = int(input())\n for i in range(3):\n for j in range(3):\n if x == card[i][j]:\n bools[i][j] = 1\nok = False\nfor i in range(3):\n if (bools[i][0], bools[i][1], bools[i][2]) == (1,1,1) or \n (bools[0][i], bools[1][i], bools[2][i]) == (1,1,1):\n ok = True\nif (bools[0][0],bools[1][1],bools[2][2]) == (1,1,1) or (bools[0][2], bools[1][1], bools[2][0]) == (1,1,1):\n ok = True\nprint("Yes" if ok else "No")', 'card = [[int(x) for x in input().split()] for y in range(3)]\nbools = [[0,0,0],[0,0,0],[0,0,0]]\nn = int(input())\nfor _ in range(n):\n x = int(input())\n for i in range(3):\n for j in range(3):\n if x == card[i][j]:\n bools[i][j] = 1\nok = False\nfor i in range(3):\n if (bools[i][0], bools[i][1], bools[i][2]) == (1,1,1) or (bools[0][i], bools[1][i], bools[2][i]) == (1,1,1):\n ok = True\nif (bools[0][0],bools[1][1],bools[2][2]) == (1,1,1) or (bools[0][2], bools[1][1], bools[2][0]) == (1,1,1):\n ok = True\nprint("Yes" if ok else "No")'] | ['Runtime Error', 'Accepted'] | ['s032567316', 's132662372'] | [3064.0, 3064.0] | [17.0, 17.0] | [549, 546] |
p02760 | u016323272 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ["#ABC157.B\nA = list(map(int,input().split()))\nN = int(input())\nb = list(map(int,input().split()))\n\nfor i in b:\n if i in A:\n A[A.index(i)]=0\nif A[0]==0 and A[1]==0 and A[2]==0:\n print('Yes')\nelif A[3]==0 and A[4]==0 and A[5]==0:\n print('Yes')\nelif A[6]==0 and A[7]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[3]==0 and A[6]==0:\n print('Yes')\nelif A[1]==0 and A[4]==0 and A[7]==0:\n print('Yes')\nelif A[2]==0 and A[5]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[4]==0 and A[8]==0:\n print('Yes')\nelif A[2]==0 and A[4]==0 and A[6]==0:\n print('Yes')\nelse:\n print('No')", "#ABC157.B\nA = [input().split()for i in range(3)]\nN = int(input())\nb = [int(input())for _ in range(N)]\nif (A[0][0] in b)and (A[0][1]in b)and (A[0][2] in b):\n print('Yes')\nelif (A[1][0]in b)and(A[1][1] in b)and(A[1][2]in b):\n print('Yes')\nelif (A[2][0]in b)and(A[2][1]in b)and (A[2][2]in b):\n print('Yes')\nelif (A[0][0]in b)and(A[1][0]in b)and(A[2][0]in b):\n print('Yes')\nelif (A[0][1]in b)and (A[1][1]in b)and(A[2][1]in b):\n print('Yes')\nelif (A[0][2] in b)and (A[1][2]in b)and(A[2][2]in b):\n print('Yes')\nelif (A[0][0]in b)and (A[1][1]in b)and(A[2][2]in b):\n print('Yes')\nelif (A[0][2]in b)and (A[1][1]in b)and(A[2][0]in b):\n print('Yes')\nelse:\n print('No')", "#ABC157.B\nA = list(input().split()for l in range(3))\nN = int(input())\nb = [int(input())for _ in range(N)]\nfor i in b:\n if i in A:\n A[A.index(i)]=0\nif A[0]==0 and A[1]==0 and A[2]==0:\n print('Yes')\nelif A[3]==0 and A[4]==0 and A[5]==0:\n print('Yes')\nelif A[6]==0 and A[7]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[3]==0 and A[6]==0:\n print('Yes')\nelif A[1]==0 and A[4]==0 and A[7]==0:\n print('Yes')\nelif A[2]==0 and A[5]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[4]==0 and A[8]==0:\n print('Yes')\nelif A[2]==0 and A[4]==0 and A[6]==0:\n print('Yes')\nelse:\n print('No')", "#ABC157.B\nA = list(map(int,input().split()))\nN = int(input())\nb = [int(input())for _ in range(N)]\nfor i in b:\n if i in A:\n A[A.index(i)]=0\nif A[0]==0 and A[1]==0 and A[2]==0:\n print('Yes')\nelif A[3]==0 and A[4]==0 and A[5]==0:\n print('Yes')\nelif A[6]==0 and A[7]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[3]==0 and A[6]==0:\n print('Yes')\nelif A[1]==0 and A[4]==0 and A[7]==0:\n print('Yes')\nelif A[2]==0 and A[5]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[4]==0 and A[8]==0:\n print('Yes')\nelif A[2]==0 and A[4]==0 and A[6]==0:\n print('Yes')\nelse:\n print('No')", "#ABC159.B\nA = list(map(int,input().split()))\nN = int(input())\nb = list(map(int,input().split()))\n\nfor i in b:\n if i in A:\n A[A.index(i)]=0\nif A[0]==0 and A[1]==0 and A[2]==0:\n print('Yes')\nelif A[3]==0 and A[4]==0 and A[5]==0:\n print('Yes')\nelif A[6]==0 and A[7]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[3]==0 and A[6]==0:\n print('Yes')\nelif A[1]==0 and A[4]==0 and A[7]==0:\n print('Yes')\nelif A[2]==0 and A[5]==0 and A[8]==0:\n print('Yes')\n\nelif A[0]==0 and A[4]==0 and A[8]==0:\n print('Yes')\nelif A[2]==0 and A[4]==0 and A[6]==0:\n print('Yes')\nelse:\n print('No')", "#ABC157.B\nA1 = list(map(int,input().split()))\nA2 = list(map(int,input().split()))\nA3 = list(map(int,input().split()))\nN = int(input())\nb = [int(input())for _ in range(N)]\nif (A1[0] in b)and (A1[1]in b)and (A1[2] in b):\n print('Yes')\nelif (A2[0]in b)and(A2[1] in b)and(A2[2]in b):\n print('Yes')\nelif (A3[0]in b)and(A3[1]in b)and (A3[2]in b):\n print('Yes')\nelif (A1[0]in b)and(A2[0]in b)and(A3[0]in b):\n print('Yes')\nelif (A1[1]in b)and (A2[1]in b)and(A3[1]in b):\n print('Yes')\nelif (A1[2] in b)and (A2[2]in b)and(A3[2]in b):\n print('Yes')\nelif (A1[0]in b)and (A2[1]in b)and(A3[2]in b):\n print('Yes')\nelif (A1[2]in b)and (A2[1]in b)and(A3[0]in b):\n print('Yes')\nelse:\n print('No')"] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s241249680', 's338489127', 's351193316', 's443644399', 's936561835', 's563945604'] | [3064.0, 3064.0, 3192.0, 3188.0, 3192.0, 3064.0] | [19.0, 17.0, 20.0, 19.0, 18.0, 17.0] | [610, 684, 618, 610, 610, 705] |
p02760 | u016901717 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['a1=input().split()\na2=input().split()\na3=input().split()\nA=[a1,a2,a3]\nb=[int(input()) for i in range(int(input()))]\nif a1[0] and a1[1] and a1[2] in b:\n print("Yes")\nelif a2[0] and a2[1] and a2[2] in b:\n print("Yes")\nelif a3[0] and a3[1] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[0] and a3[0] in b:\n print("Yes")\nelif a1[1] and a2[1] and a3[1] in b:\n print("Yes")\nelif a1[2] and a2[2] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[1] and a3[2] in b:\n print("Yes")\nelif a1[2] and a2[1] and a3[0] in b:\n print("Yes")\nelse:\n print("No")\n', 'a1=input().split()\na2=input().split()\na3=input().split()\nA=[a1,a2,a3]\nb=[int(input()) for i in range(int(input()))]\nif a1[0] and a1[1] and a1[2] in b:\n print("Yes")\nelif a2[0] and a2[1] and a2[2] in b:\n print("Yes")\nelif a3[0] and a3[1] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[0] and a3[0] in b:\n print("Yes")\nelif a1[1] and a2[1] and a3[1] in b:\n print("Yes")\nelif a1[2] and a2[2] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[1] and a3[2] in b:\n print("Yes")\nelif a1[2] and a2[1] and a3[0] in b:\n print("Yes")\nelse:\n print("No")\n', 'a1=input().split()\na2=input().split()\na3=input().split()\nA=[a1,a2,a3]\nb=int(input()) for i in range(int(input()))\nif a1[0] and a1[1] and a1[2] in b:\n print("Yes")\nelif a2[0] and a2[1] and a2[2] in b:\n print("Yes")\nelif a3[0] and a3[1] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[0] and a3[0] in b:\n print("Yes")\nelif a1[1] and a2[1] and a3[1] in b:\n print("Yes")\nelif a1[2] and a2[2] and a3[2] in b:\n print("Yes")\nelif a1[0] and a2[1] and a3[2] in b:\n print("Yes")\nelif a1[2] and a2[1] and a3[0] in b:\n print("Yes")\nelse:\n print("No")', "def main():\n a = [input().split() for _ in range(3)]\n ans = [[0] * 3 for _ in range(3)]\n n = int(input())\n b = [input() for _ in range(n)]\n\n for bi in b:\n for y in range(3):\n for x in range(3):\n if bi == a[y][x]:\n ans[y][x] = 1\n\n if ans[0][0] == ans[0][1] == ans[0][2] == 1:\n print('Yes')\n elif ans[1][0] == ans[1][1] == ans[1][2] == 1:\n print('Yes')\n elif ans[2][0] == ans[2][1] == ans[2][2] == 1:\n print('Yes')\n elif ans[0][0] == ans[1][0] == ans[2][0] == 1:\n print('Yes')\n elif ans[0][1] == ans[1][1] == ans[2][1] == 1:\n print('Yes')\n elif ans[0][2] == ans[1][2] == ans[2][2] == 1:\n print('Yes')\n elif ans[0][0] == ans[1][1] == ans[2][2] == 1:\n print('Yes')\n elif ans[0][2] == ans[1][1] == ans[2][0] == 1:\n print('Yes')\n else:\n print('No')\n\n\nif __name__ == '__main__':\n main()\n\n"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s094630825', 's368879257', 's946027064', 's176483040'] | [3064.0, 3064.0, 2940.0, 3064.0] | [17.0, 18.0, 17.0, 18.0] | [568, 568, 565, 941] |
p02760 | u017050982 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['A = [[0 for i in range(3)]for i2 in range(3)]\nc = [[False for i in range(3)]for i2 in range(3)]\nA[0] = list(map(int,input().rstrip().split(" ")))\nA[1] = list(map(int,input().rstrip().split(" ")))\nA[2] = list(map(int,input().rstrip().split(" ")))\nint_inp = int(input())\ns = 0\nfor i in range(int_inp):\n s = int(input())\n for i2 in range(9):\n for A[int(i2 / 3)][i2 % 3] == s:\n c[int(i2 / 3)][i2 % 3] == True\nans = False\nfor i in range(3):\n if c[i][0] and c[i][1] and c[i][2]:ans = True\nfor i in range(3):\n if c[0][i] and c[1][i] and c[2][i]:ans = True\nif c[0][0] and c[1][1] and c[2][2]:ans = True\nif c[2][0] and c[1][1] and c[0][2]:ans = True\nif ans:\n print(\'Yes\')\nelse:\n print(\'No\')', 'A = [[0 for i in range(3)]for i2 in range(3)]\nc = [[False for i in range(3)]for i2 in range(3)]\nA[0] = list(map(int,input().rstrip().split(" ")))\nA[1] = list(map(int,input().rstrip().split(" ")))\nA[2] = list(map(int,input().rstrip().split(" ")))\nint_inp = int(input())\ns = 0\nfor i in range(int_inp):\n s = int(input())\n for i2 in range(9):\n if A[int(i2 / 3)][i2 % 3] == s:\n c[int(i2 / 3)][i2 % 3] = True\nans = False\nfor i in range(3):\n if c[i][0] and c[i][1] and c[i][2]:ans = True\nfor i in range(3):\n if c[0][i] and c[1][i] and c[2][i]:ans = True\nif c[0][0] and c[1][1] and c[2][2]:ans = True\nif c[2][0] and c[1][1] and c[0][2]:ans = True\nif ans:\n print(\'Yes\')\nelse:\n print(\'No\')'] | ['Runtime Error', 'Accepted'] | ['s291262290', 's937720693'] | [3064.0, 3064.0] | [17.0, 17.0] | [695, 693] |
p02760 | u018771977 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ["#! env/bin/local python3\n# -*- coding: utf-8 -*-\n\nimport numpy as np\n\na_1 = list(map(int, input().split()))\na_2 = list(map(int, input().split()))\na_3 = list(map(int, input().split()))\n_ = input()\npickup_number = []\nwhile True:\n try:\n pickup_number.append(int(input()))\n except EOFError:\n break\n\na = np.array([a_1, a_2, a_3])\nprint(pickup_number)\nprint(a)\n\nfor pn in pickup_number:\n a[a == pn] = -1\n\nprint(a)\n\nflag = False\nif np.sum(a, axis=0)[0] == -3 or np.sum(a, axis=1)[0] == -3:\n flag = True\nif np.sum(a.diagonal()) == -3 or np.sum(a[0][2] + a[1][1] + a[2][2]) == -3:\n flag = True\n\nprint('Yes' if flag else 'No')\n", "#! env/bin/local python3\n# -*- coding: utf-8 -*-\n\nimport numpy as np\n\na_1 = list(map(int, input().split()))\na_2 = list(map(int, input().split()))\na_3 = list(map(int, input().split()))\n_ = input()\npickup_number = []\nwhile True:\n try:\n pickup_number.append(int(input()))\n except EOFError:\n break\n\na = np.array([a_1, a_2, a_3])\nprint(pickup_number)\nprint(a)\n\nfor pn in pickup_number:\n a[a == pn] = -1\n\nprint(a)\n\nflag = False\nif np.sum(a, axis=0)[0] == -3 or np.sum(a, axis=1)[0] == -3:\n flag = True\nif np.sum(a.diagonal()) == -3 or np.sum(a[0][2] + a[1][1] + a[2][0]) == -3:\n flag = True\n\nprint('Yes' if flag else 'No')\n", "#! env/bin/local python3\n# -*- coding: utf-8 -*-\n\nimport numpy as np\n\na_1 = list(map(int, input().split()))\na_2 = list(map(int, input().split()))\na_3 = list(map(int, input().split()))\n_ = input()\npickup_number = []\nwhile True:\n try:\n pickup_number.append(int(input()))\n except EOFError:\n break\n\na = np.array([a_1, a_2, a_3])\n\nfor pn in pickup_number:\n a[a == pn] = -1\n\nflag = False\nif -3 in np.sum(a, axis=0) or -3 in np.sum(a, axis=1):\n flag = True\nif np.sum(a.diagonal()) == -3 or a[0][2] + a[1][1] + a[2][0] == -3:\n flag = True\n\nprint('Yes' if flag else 'No')\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s511000596', 's830586532', 's708745010'] | [21004.0, 12496.0, 12508.0] | [309.0, 157.0, 154.0] | [646, 646, 592] |
p02760 | u019113646 | 2,000 | 1,048,576 | We have a bingo card with a 3\times3 grid. The square at the i-th row from the top and the j-th column from the left contains the number A_{i, j}. The MC will choose N numbers, b_1, b_2, \cdots, b_N. If our bingo sheet contains some of those numbers, we will mark them on our sheet. Determine whether we will have a bingo when the N numbers are chosen, that is, the sheet will contain three marked numbers in a row, column, or diagonal. | ['x1 = list(map(int, input().split()))\nx2 = list(map(int, input().split()))\nx3 = list(map(int, input().split()))\ncard = [x1, x2, x3]\n\nnumLen = int(input())\nnumList = [int(input()) for _ in range(numLen)]\nans = "No"\nfor x in range(3):\n for y in range(3):\n for numList_i in range(numLen):\n if card[x][y] == numList[numList_i]:\n print(numList[numList_i])\n card[x][y] = "x"\n\nfor i in range(3):\n if card[i][0] == "x" and card[i][1] == "x" and card[i][2] == "x":\n ans = "Yes"\n if card[0][i] == "x" and card[1][i] == "x" and card[2][i] == "x":\n ans = "Yes"\n\nif card[0][0] == "x" and card[1][1] == "x" and card[2][2] == "x":\n ans = "Yes"\nif card[0][2] == "x" and card[1][1] == "x" and card[2][0] == "x":\n ans = "Yes"\nprint(ans)\n\n\n', 'x1 = list(map(int, input().split()))\nx2 = list(map(int, input().split()))\nx3 = list(map(int, input().split()))\ncard = [x1, x2, x3]\n\nnumLen = int(input())\nnumList = [int(input()) for _ in range(numLen)]\nans = "No"\nfor x in range(3):\n for y in range(3):\n for numList_i in range(numLen):\n if card[x][y] == numList[numList_i]:\n card[x][y] = "x"\n\nfor i in range(3):\n if card[i][0] == "x" and card[i][1] == "x" and card[i][2] == "x":\n ans = "Yes"\n if card[0][i] == "x" and card[1][i] == "x" and card[2][i] == "x":\n ans = "Yes"\n\nif card[0][0] == "x" and card[1][1] == "x" and card[2][2] == "x":\n ans = "Yes"\nif card[0][2] == "x" and card[1][1] == "x" and card[2][0] == "x":\n ans = "Yes"\nprint(ans)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s378055722', 's590808146'] | [3064.0, 3064.0] | [18.0, 18.0] | [804, 762] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.