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
p03291
u102902647
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\ndp = [[1, 0, 0, 0]]\nfor s in S:\n tmp = [0, 0, 0, 0]\n if s == 'A' or s == '?':\n tmp[0] += dp[-1][0]\n tmp[1] += dp[-1][1]\n tmp[2] += dp[-1][2]\n tmp[3] += dp[-1][3]\n tmp[1] += dp[-1][0]\n if s == 'B' or s == '?':\n tmp[0] += dp[-1][0]\n tmp[1] += dp[-1][1]\n tmp[2] += dp[-1][2]\n tmp[3] += dp[-1][3]\n tmp[2] += dp[-1][1]\n if s == 'C' or s == '?':\n tmp[0] += dp[-1][0]\n tmp[1] += dp[-1][1]\n tmp[2] += dp[-1][2]\n tmp[3] += dp[-1][3]\n tmp[3] += dp[-1][2]\n dp.append(tmp)\nprint(dp[-1][-1]%(10**9+7))", "def main():\n S = input()\n mod = 10**9+7\n dp0 = 1\n dp1 = 0\n dp2 = 0\n dp3 = 0\n\n for s in S:\n tmp0 = dp0\n tmp1 = dp1\n tmp2 = dp2\n tmp3 = dp3\n\n if s == '?':\n tmp0 += 2*dp0 % mod\n tmp1 += (2*dp1 + dp0) % mod\n tmp2 += (2*dp2 + dp1) % mod\n tmp3 += (2*dp3 + dp2) % mod\n elif s == 'A':\n tmp1 += dp0 % mod\n elif s == 'B':\n tmp2 += dp1 % mod\n elif s == 'C':\n tmp3 += dp2 % mod\n dp0 = tmp0\n dp1 = tmp1\n dp2 = tmp2\n dp3 = tmp3\n\n print(dp3%(mod))\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s001514580', 's600867772']
[3316.0, 3188.0]
[18.0, 105.0]
[620, 655]
p03291
u102960641
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s = list(input())\nmod = 10**9 + 7\nabc = 0\nbc = 0\nc = 0\nq = 0\nprint(s[::-1])\nfor i in s[::-1]:\n if i == "A":\n abc = (abc + bc) % mod\n if i == "B":\n bc = (bc + c) % mod\n if i == "C":\n c = (3**q+c) % mod\n if i == "?":\n abc = (abc*3 + bc) % mod\n bc = (bc*3 + c) % mod \n c = (3**q + c*3) % mod\n q += 1\nprint(abc)', 's = input()\nmod = 10**9 + 7\nabc = 0\nbc = 0\nc = 0\nq = 0\nfor i in s[::-1]:\n if i == "A":\n abc = (abc + bc) % mod\n if i == "B":\n bc = (bc + c) % mod\n if i == "C":\n c = (pow(3,q,mod) + c) % mod\n if i == "?":\n abc = (abc*3 + bc) % mod\n bc = (bc*3 + c) % mod \n c = (pow(3,q,mod) + c*3) % mod\n q += 1\nprint(int(abc))\n']
['Wrong Answer', 'Accepted']
['s715592501', 's509903005']
[6184.0, 3316.0]
[2104.0, 276.0]
[332, 335]
p03291
u119714109
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['\nimport sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\nmod = 1000000007\n\ns = ns()\n\nnums = [0]*4\nnums[0] = 1\nfor c in s:\n if c == \'A\':\n nums[1] += nums[0]\n nums[1] %= mod\n elif c == "B":\n nums[2] += nums[1]\n nums[2] %= mod\n elif c == "C":\n nums[3] += nums[2]\n nums[3] %= mod\n else:\n nums[3] = nums[3]*3+nums[2]\n nums[2] = nums[2]*3+nums[1]\n nums[1] = nums[1]*3+nums[0]\n nums[0] = nums[0]*3\n for k in range(4):\n nums[k] %= mod\nprint(nums[3])\n\n', 'import sys\n\nstdin = sys.stdin\n\nni = lambda: int(ns())\nna = lambda: list(map(int, stdin.readline().split()))\nns = lambda: stdin.readline()\n\nmod = 1000000007\n\ns = ns().rstrip()\n\nnums = [0]*4\nnums[0] = 1\nfor c in s:\n if c == \'A\':\n nums[1] += nums[0]\n nums[1] %= mod\n elif c == "B":\n nums[2] += nums[1]\n nums[2] %= mod\n elif c == "C":\n nums[3] += nums[2]\n nums[3] %= mod\n else:\n nums[3] = nums[3]*3+nums[2]\n nums[2] = nums[2]*3+nums[1]\n nums[1] = nums[1]*3+nums[0]\n nums[0] = nums[0]*3\n for k in range(4):\n nums[k] %= mod\nprint(nums[3])\n\n']
['Wrong Answer', 'Accepted']
['s495558366', 's230226243']
[3188.0, 3188.0]
[195.0, 188.0]
[626, 634]
p03291
u138486156
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['from collections import Counter\nmod = 10**9+7\ns = input()\nn = len(s)\ndn = [0]*(n+1)\nda = [0]*(n+1)\ndx = [0]*(n+1)\ndh = [0]*(n+1)\nfor i in range(n):\n dn[i+1] = dn[i]%mod\n da[i+1] = da[i]%mod\n dx[i+1] = dx[i]%mod\n dh[i+1] = dh[i]%mod\n if s[i] == "A":\n da[i+1] += 1\n elif s[i] == "B":\n if dh[i]:\n dx[i+1] += (da[i] + 3**dh[i])%mod\n else:\n dx[i+1] += da[i]%mod\n elif s[i] == "C":\n dn[i+1] += (dn[i] + dx[i])%mod\n dx[i+1] = 0\n\'\'\'\n elif s[i] == "?":\n da[i+1] += 1\n dh[i+1] += 1\n dx[i+1] = da[i]*3**dh[i]\n dn[i+1] += dx[i]\n\'\'\'\nprint(dn[n]%mod)\n', 'from collections import Counter\nmod = 10**9+7\ns = input()\nk = 1\na = 0\nab = 0\nabc = 0\nfor c in s:\n if c == "A":\n a += k\n elif c == "B":\n ab += a\n elif c == "C":\n abc += ab\n else:\n abc = 3*abc + ab\n ab = 3*ab + a\n a = 3*a + k\n k *= 3\n a %= mod\n ab %= mod\n abc %= mod\n k %= mod\nprint(abc%mod)\n\n']
['Wrong Answer', 'Accepted']
['s361715012', 's200136922']
[9840.0, 3444.0]
[153.0, 123.0]
[646, 364]
p03291
u160244242
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["str_num = 1\na,b,c = 0, 0, 0\nfor i in s:\n if i == 'A':\n a += 1\n elif i == 'B':\n b += a\n elif i == 'C':\n c += b\n else:\n a,b,c = 3*a+str_num, a+3*b, b+3*c\n str_num *= 3\nprint(c)", "s = input()\n\nstr_num = 1\na,b,c = 0, 0, 0\nfor i in s:\n if i == 'A':\n a += str_num\n elif i == 'B':\n b += a\n elif i == 'C':\n c += b\n else:\n a,b,c = (3*a+str_num), (a+3*b), (b+3*c)\n str_num *= 3\n print(a,b,c, str_num)\nprint(c % (10**9+7))", "str_num, a,b,c = 1, 0, 0, 0\nfor i in input():\n if i == 'A':\n a += str_num\n elif i == 'B':\n b += a\n elif i == 'C':\n c += b\n else:\n str_num, a,b,c = (3*str_num) % (10**9+7), (3*a+str_num) % (10**9+7), (a+3*b) % (10**9+7), (b+3*c) % (10**9+7)\nprint(c % (10**9+7))"]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s366834322', 's503101548', 's139675333']
[2940.0, 110680.0, 3188.0]
[17.0, 2112.0, 105.0]
[221, 284, 300]
p03291
u197078193
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["S = input()*10000\nmemo = [[0,0,0,0] for i in range(len(S))]\nQ = 0\nmemo[0][0] = 1\nif S[0] == 'A':\n memo[0][1] = 1\nelif S[0] == '?':\n memo[0][0] = 3\n memo[0][1] = 1\nl = 1\nwhile l < len(S):\n s = S[l]\n if s == 'A':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1] + memo[l-1][0]\n memo[l][2] = memo[l-1][2]\n memo[l][3] = memo[l-1][3]\n elif s == 'B':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1]\n memo[l][2] = memo[l-1][2] + memo[l-1][0]\n memo[l][3] = memo[l-1][3]\n elif s == 'C':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1]\n memo[l][2] = memo[l-1][2]\n memo[l][3] = memo[l-1][3] + memo[l-1][1]\n else:\n memo[l][0] = memo[l-1][0]*3\n memo[l][1] = memo[l-1][1]*3 + memo[l-1][0]\n memo[l][2] = memo[l-1][2]*3 + memo[l-1][0]\n memo[l][3] = memo[l-1][3]*3 + memo[l-1][1]\n Q += 1\n memo[l] = [i%(10**9+7) for i in memo[l]]\n l += 1\nprint(int(memo[l-1][2]))", "S = input()\nmemo = [[0,0,0,0] for i in range(len(S))]\nQ = 0\nmemo[0][0] = 1\nif S[0] == 'A':\n memo[0][1] = 1\nelif S[0] == '?':\n memo[0][0] = 3\n memo[0][1] = 1\nl = 1\nwhile l < len(S):\n s = S[l]\n if s == 'A':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1] + memo[l-1][0]\n memo[l][2] = memo[l-1][2]\n memo[l][3] = memo[l-1][3]\n elif s == 'B':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1]\n memo[l][2] = memo[l-1][2] + memo[l-1][1]\n memo[l][3] = memo[l-1][3]\n elif s == 'C':\n memo[l][0] = memo[l-1][0]\n memo[l][1] = memo[l-1][1]\n memo[l][2] = memo[l-1][2]\n memo[l][3] = memo[l-1][3] + memo[l-1][2]\n else:\n memo[l][0] = memo[l-1][0]*3\n memo[l][1] = memo[l-1][1]*3 + memo[l-1][0]\n memo[l][2] = memo[l-1][2]*3 + memo[l-1][1]\n memo[l][3] = memo[l-1][3]*3 + memo[l-1][2]\n Q += 1\n memo[l] = [i%(10**9+7) for i in memo[l]]\n l += 1\nprint(int(memo[l-1][3]))"]
['Wrong Answer', 'Accepted']
['s938064555', 's576567243']
[1415372.0, 27608.0]
[2150.0, 295.0]
[923, 917]
p03291
u197955752
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\nn = len(s)\np = 10 ** 9 + 7\n\n\n\n\n\n\ndp = [[0 for j in range(4)] for i in range(n + 1)]\ndp[0][0] = 1 \nfor j in range(1, 4):\n dp[0][j] = 0 \n\nfor i in range(1, n + 1):\n m = 3 if s[i - 1] == '?' else 1\n\n for j in range(4):\n dp[i][j] = dp[i - 1][j] * m\n\n if s[i - 1] == 'A' or s[i - 1] == '?':\n dp[i][A] = (dp[i][A] + dp[i - 1][0]) % p\n if s[i - 1] == 'B' or s[i - 1] == '?':\n dp[i][AB] = (dp[i][AB] + dp[i - 1][A]) % p\n if s[i - 1] == 'C' or s[i - 1] == '?':\n dp[i][ABC] = (dp[i][ABC] + dp[i - 1][AB]) % p\n\nprint(dp[n][ABC])", "import sys\ninput = sys.stdin.readline\n\ns = input()\nn = len(s)\np = 10 ** 9 + 7\n\nq = s.count('?')\nl_a = [0] * n \nl_x = [0] * n \nr_c = [0] * n \nr_x = [0] * n \n\nfor i in range(1, n): \n l_a[i] = l_a[i - 1] + int(s[i - 1] == 'A')\n l_x[i] = l_x[i - 1] + int(s[i - 1] == '?')\n r_c[n - i - 1] = r_c[n - i] + int(s[n - i] == 'C')\n r_x[n - i - 1] = r_x[n - i] + int(s[n - i] == '?')\n\nans = 0\npow_q3 = max(1, 3 ** (q - 3) % p)\npow_q2 = max(1, pow_q3 * 3 % p)\npow_q1 = max(1, pow_q2 * 3 % p)\npow_q = max(1, pow_q1 * 3 % p)\n\nfor i in range(n):\n if s[i] == 'B':\n ans += (l_a[i] * r_c[i] % p) * pow_q % p # ABC\n ans += (l_x[i] * r_c[i] % p) * pow_q1 % p # ?BC\n ans += (l_a[i] * r_x[i] % p) * pow_q1 % p # AB?\n ans += (l_x[i] * r_x[i] % p) * pow_q2 % p # ?B?\n ans %= p\n elif s[i] == '?':\n ans += (l_a[i] * r_c[i] % p) * pow_q1 % p # A?C\n ans += (l_x[i] * r_c[i] % p) * pow_q2 % p # ??C\n ans += (l_a[i] * r_x[i] % p) * pow_q2 % p # A??\n ans += (l_x[i] * r_x[i] % p) * pow_q3 % p # ???\n ans %= p\n\nprint(ans)\n", 's = input()\nn = len(s)\np = 10 ** 9 + 7\n\n\n\n\n\n\ndp = [[0 for j in range(4)] for i in range(n + 1)]\ndp[0][0] = 1 \nfor j in range(1, 4):\n dp[0][j] = 0 \n\nprint("dp[0] = {}".format(dp[0]))\nfor i in range(1, n + 1):\n m = 3 if s[i - 1] == \'?\' else 1\n\n for j in range(4):\n dp[i][j] = dp[i - 1][j] * m\n\n if s[i - 1] == \'A\' or s[i - 1] == \'?\':\n dp[i][A] = (dp[i][A] + dp[i - 1][0]) % p\n if s[i - 1] == \'B\' or s[i - 1] == \'?\':\n dp[i][AB] = (dp[i][AB] + dp[i - 1][A]) % p\n if s[i - 1] == \'C\' or s[i - 1] == \'?\':\n dp[i][ABC] = (dp[i][ABC] + dp[i - 1][AB]) % p\n\nprint(dp[n][ABC])', "s = input()\nn = len(s)\np = 10 ** 9 + 7\n\n\n\n\n\n\ndp = [[0 for j in range(4)] for i in range(n + 1)]\ndp[0][0] = 1 \nfor j in range(1, 4):\n dp[0][j] = 0 \n\nfor i in range(1, n + 1):\n m = 3 if s[i - 1] == '?' else 1\n\n for j in range(4):\n dp[i][j] = dp[i - 1][j] * m % p\n\n if s[i - 1] == 'A' or s[i - 1] == '?':\n dp[i][1] = (dp[i][1] + dp[i - 1][0]) % p\n if s[i - 1] == 'B' or s[i - 1] == '?':\n dp[i][2] = (dp[i][2] + dp[i - 1][1]) % p\n if s[i - 1] == 'C' or s[i - 1] == '?':\n dp[i][3] = (dp[i][3] + dp[i - 1][2]) % p\n\nprint(dp[n][3])"]
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s436775301', 's545975076', 's605364533', 's307516380']
[14836.0, 18924.0, 14836.0, 27608.0]
[104.0, 356.0, 103.0, 459.0]
[963, 1256, 997, 958]
p03291
u237362582
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["def calc_ABC(a, c, bq, aq):\n ans = 0\n if aq != 0:\n if bq != 0:\n ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \\\n * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))\n else:\n ans = ans + (a*pow(3, bq, MOD)) \\\n * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))\n else:\n if bq != 0:\n ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \\\n * (c*pow(3, aq, MOD))\n else:\n ans = ans + (a*pow(3, bq, MOD)) \\\n * (c*pow(3, aq, MOD))\n return ans % MOD\n\n\nMOD = 10**9 + 7\nS = raw_input()\nans = 0\ncount_a = 0\ncount_c = S.count('C')\ncount_afterq = S.count('?')\ncount_beforeq = 0\n\nfor i in range(len(S)):\n if S[i] == 'A':\n count_a += 1\n elif S[i] == 'B':\n ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)\n ans = ans % MOD\n elif S[i] == 'C':\n count_c -= 1\n elif S[i] == '?':\n count_afterq -= 1\n ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)\n ans = ans % MOD\n count_beforeq += 1\nprint(ans)\n", "def calc_ABC(a, c, bq, aq):\n ans = 0\n if aq != 0:\n if bq != 0:\n ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \\\n * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))\n else:\n ans = ans + (a*pow(3, bq, MOD)) \\\n * (c*pow(3, aq, MOD) + aq*pow(3, (aq-1), MOD))\n else:\n if bq != 0:\n ans = ans + (a*pow(3, bq, MOD) + bq*pow(3, bq-1, MOD)) \\\n * (c*pow(3, aq, MOD))\n else:\n ans = ans + (a*pow(3, bq, MOD)) \\\n * (c*pow(3, aq, MOD))\n return ans % MOD\n\n\nMOD = 10**9 + 7\nS = input()\nans = 0\ncount_a = 0\ncount_c = S.count('C')\ncount_afterq = S.count('?')\ncount_beforeq = 0\n\nfor i in range(len(S)):\n if S[i] == 'A':\n count_a += 1\n elif S[i] == 'B':\n ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)\n ans = ans % MOD\n elif S[i] == 'C':\n count_c -= 1\n elif S[i] == '?':\n count_afterq -= 1\n ans += calc_ABC(count_a, count_c, count_beforeq, count_afterq)\n ans = ans % MOD\n count_beforeq += 1\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s945832600', 's942123318']
[3064.0, 3316.0]
[18.0, 848.0]
[1121, 1117]
p03291
u316386814
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["S = input()\nN = len(S)\nMOD = 10 ** 9 + 7\n\ndp = [0, 0, 0, 0]\ndp[0] = 1\n\nfor s in S:\n factor = 3 if s == '?' else 1\n for j, c in zip([2, 1, 0], 'CBA'):\n dp[j + 1] = dp[j + 1] * factor % MODE\n if s == c or s == '?':\n dp[j + 1] += dp[j]\n if s == '?':\n dp[0] = dp[0] % MOD\n\nans = dp[-1] % MOD\n\nprint(ans)", "S = input()\nN = len(S)\nMOD = 10 ** 9 + 7\n\nq = 3 if S[0] == '?' else 1\na = b = c = 0\nif S[0] in 'A?':\n a = 1\nfor s in S[1:]:\n if s == '?':\n c = c * 3 + b\n b = b * 3 + a\n a = a * 3 + q\n q *= 3\n elif s == 'A':\n a += q\n elif s == 'B':\n b += a\n elif s == 'C':\n c += b\n a, b, c = a % MOD, b % MOD, C % MOD\n\nans = c % MOD\nprint(ans)", "S = input()\nN = len(S)\nMOD = 10 ** 9 + 7\n\nq = 3 if S[0] == '?' else 1\na = b = c = 0\nif S[0] in 'A?':\n a = 1\nfor s in S:\n if s == '?':\n c = c * 3 + b\n b = b * 3 + a\n a = a * 3 + q\n q *= 3\n elif s == 'A':\n a += q\n elif s == 'B':\n b += a\n elif s == 'C':\n c += b\n\nans = c % MOD\nprint(ans)", "S = input()\nN = len(S)\nMOD = 10 ** 9 + 7\n\ndp = [0, 0, 0, 0]\ndp[0] = 1\n\nfor s in S:\n factor = 3 if s == '?' else 1\n for j, c in zip([2, 1, 0], 'CBA'):\n dp[j + 1] = dp[j + 1] * factor % MOD\n if s == c or s == '?':\n dp[j + 1] += dp[j]\n if s == '?':\n dp[0] = (dp[0] * 3) % MOD\n\nans = dp[-1] % MOD\n\nprint(ans)"]
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s141091929', 's471347942', 's595287598', 's927090554']
[3188.0, 3316.0, 3316.0, 3188.0]
[18.0, 17.0, 2103.0, 282.0]
[340, 392, 348, 345]
p03291
u319818856
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['S = \'\'\n\ndef we_love_abc()->int:\n global S\n ABC = \'ABC\'\n\n dp = [0, 0, 0, 0]\n dp[3] = 1\n\n for c in reversed(S):\n if c == \'?\':\n m, m1 = 3, 3\n else:\n m, m1 = 1, 1\n\n for j in range(3):\n m2 = 1 if c == \'?\' or c == ABC[j] else 0\n dp[j] = m1 * dp[j] + m2 * dp[j+1]\n dp[3] = m * dp[3]\n\n return dp[0] % 1000000007\n\n\nif __name__ == "__main__":\n S = input()\n ans = we_love_abc(S)\n print(ans)\n', 'def we_love_abc(S: str)->int:\n ABC = \'ABC\'\n MOD = 1000000007\n\n dp = [0, 0, 0, 0]\n dp[3] = 1\n\n for c in reversed(S):\n for j in range(3):\n m1 = 3 if c == \'?\' else 1\n m2 = 1 if c == \'?\' or c == ABC[j] else 0\n dp[j] = (m1 * dp[j] + m2 * dp[j+1]) % MOD\n dp[3] = (3 if c == \'?\' else 1) * dp[3]\n dp[3] %= MOD\n\n return dp[0] % MOD\n\n\nif __name__ == "__main__":\n S = input()\n ans = we_love_abc(S)\n print(ans)\n']
['Runtime Error', 'Accepted']
['s864165676', 's186440312']
[3188.0, 3188.0]
[18.0, 174.0]
[479, 480]
p03291
u367130284
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s=input()\nBcount=s[1:].count("?")+s[1:].count("B")-1\nCcount=s[2:].count("?")+s[2:].count("C")\nans=0\nAcount=0\nif s[0]=="A":\n Acount+=1\n ans+=(Bcount+1)*Bcount//2\n\nfor i in range(1,len(s)-1):\n if Ccount==0:\n break\n if s[i]=="B":\n ans+=Acount*Ccount\n elif s[i]=="?":\n ans+=Acount*Ccount\n Acount+=1\n Ccount-=1\n ans+=(Bcount+1)*Bcount//2\n elif s[i]=="A":\n Acount-=1\n ans+=(Bcount+1)*Bcount//2\n else:\n Ccount-=1\nprint(ans)\n ', 'mod=10**9+7\ns=input()\nn=len(s)\ndp=[[0]*4 for i in range(n+1)] # A B C ABC\ndp[0][0]=1\nfor i in range(1,n+1):\n if s[i-1]=="A":\n dp[i][0]=dp[i-1][0]\n dp[i][1]=(dp[i-1][1] + dp[i-1][0]) % mod\n dp[i][2]=dp[i-1][2]\n dp[i][3]=dp[i-1][3]\n elif s[i-1]=="B":\n dp[i][0]=dp[i-1][0]\n dp[i][1]=dp[i-1][1]\n dp[i][2]=(dp[i-1][2] + dp[i-1][1]) % mod\n dp[i][3]=dp[i-1][3]\n elif s[i-1]=="C":\n dp[i][0]=dp[i-1][0]\n dp[i][1]=dp[i-1][1]\n dp[i][2]=dp[i-1][2]\n dp[i][3]=(dp[i-1][3] + dp[i-1][2]) % mod\n else:\n dp[i][0]=dp[i-1][0]*3 % mod\n dp[i][1]=(dp[i-1][1]*3 + dp[i-1][0]) % mod\n dp[i][2]=(dp[i-1][2]*3 + dp[i-1][1]) % mod\n dp[i][3]=(dp[i-1][3]*3 + dp[i-1][2]) % mod\nprint(dp[-1][-1]% mod)']
['Wrong Answer', 'Accepted']
['s326854572', 's218984823']
[3188.0, 27612.0]
[87.0, 236.0]
[509, 792]
p03291
u389910364
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['import bisect\nimport cmath\nimport heapq\nimport itertools\nimport math\nimport operator\nimport os\nimport re\nimport string\nimport sys\nfrom collections import Counter, deque, defaultdict\nfrom copy import deepcopy\nfrom decimal import Decimal\nfrom fractions import gcd\nfrom functools import lru_cache, reduce\nfrom operator import itemgetter, mul, add, xor\n\nimport numpy as np\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(10 ** 9)\nINF = float("inf")\nIINF = 10 ** 18\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\n\nS = sys.stdin.buffer.readline().decode().rstrip()\n\na = 0\nab = 0\nabc = 0\nq = 0\nfor i, s in enumerate(S):\n if s == \'C\':\n abc += ab\n if s == \'B\':\n ab += a\n if s == \'A\':\n a += 3 ** q\n if s == \'?\':\n abc = abc * 3 + ab\n ab = ab * 3 + a\n a = a * 3 + 3 ** q\n q += 1\n a %= MOD\n ab %= MOD\n abc %= MOD\n \nprint(abc)\n', 'import os\nimport sys\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(10 ** 9)\nINF = float("inf")\nIINF = 10 ** 18\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\n\nS = sys.stdin.buffer.readline().decode().rstrip()\n\na = 0\nab = 0\nabc = 0\nq = 0\nfor i, s in enumerate(S):\n if s == \'C\':\n abc += ab\n if s == \'B\':\n ab += a\n if s == \'A\':\n a += pow(3, q, MOD)\n if s == \'?\':\n abc = abc * 3 + ab\n ab = ab * 3 + a\n a = a * 3 + pow(3, q, MOD)\n q += 1\n a %= MOD\n ab %= MOD\n abc %= MOD\n \nprint(abc)\n']
['Time Limit Exceeded', 'Accepted']
['s183707382', 's543148747']
[13364.0, 3316.0]
[2108.0, 292.0]
[934, 602]
p03291
u391731808
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['S=input()\nN = len(S)\nA = [0]*N\nC = [0]*N\nL = [0]*N\nR = [0]*N\nfor i in range(1,N):\n A[i] = A[i-1] + (S[i-1] == "A")\n L[i] = L[i-1] + (S[i-1] == "?")\n C[N-1-i] = C[N-i] + (S[N-i] == "C")\n R[N-1-i] = R[N-i] + (S[N-i] == "?")\nmod = 10**9+7\nd={0:1}\ndef pow_mod(x,n):\n if d.get(n,False) :return d[n]\n if n<0: return pow_mod(x,mod-2+n)\n if n%2 :\n d[n] = (x*pow_mod(x,n-1))%mod\n else:\n d[n] = (pow_mod(x,n//2)**2)%mod\n return d[n]\nans = 0\nfor i in range(1,N-1):\n if S[i] in "B?":\n ans += (3*A[i]+L[i])*(3*C[i]+R[i])*pow_mod(3,L[i]+R[i]-2)\n ans %= mod\nprint(ans)', 'S=input()\nN = len(S)\nA = [0]*N\nC = [0]*N\nL = [0]*N\nR = [0]*N\nfor i in range(1,N):\n A[i] = A[i-1] + (S[i-1] == "A")\n L[i] = L[i-1] + (S[i-1] == "?")\n C[N-1-i] = C[N-i] + (S[N-i] == "C")\n R[N-1-i] = R[N-i] + (S[N-i] == "?")\nmod = 10**9+7\nd={0:1}\ndef pow_mod(x,n):\n if d.get(n,False) :return d[n]\n if n<0: return pow_mod(x,mod-1+n)\n if n%2 :\n d[n] = (x*pow_mod(x,n-1))%mod\n else:\n d[n] = (pow_mod(x,n//2)**2)%mod\n return d[n]\nans = 0\nfor i in range(1,N-1):\n if S[i] in "B?":\n ans += (3*A[i]+L[i])*(3*C[i]+R[i])*pow_mod(3,L[i]+R[i]-2)\n ans %= mod\nprint(ans)']
['Wrong Answer', 'Accepted']
['s015551237', 's853642965']
[18924.0, 18924.0]
[272.0, 259.0]
[612, 612]
p03291
u415905784
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["S = input()\np = 10 ** 9 + 7\nDP = [0, 0, 0, 1]\ndp = [0] * 4\nfor i in range(len(S) - 1, -1, -1):\n for j in range(3, -1, -1):\n if j == 3:\n dp[j] = DP[3] * (3 if S[i] == '?' else 1) % p\n else:\n dp[j] += DP[j + 1] * (1 if S[i] == chr(65 + j) or S[i] == '?' else 0)\n dp[j] += DP[j] * (3 if S[i] == '?' else 1)\n dp[j] % p\n DP = [x for x in dp]\nprint(DP[0] % p)", "S = input()\np = 10 ** 9 + 7\nDP = [[0 for j in range(4)] for i in range(len(S) + 1)]\nDP[len(S)][3] = 1\nfor i in range(len(S) - 1, -1, -1):\n for j in range(3, -1, -1):\n if j == 3:\n DP[i][j] = DP[i + 1][3] * (3 if S[i] == '?' else 1)\n else:\n DP[i][j] += DP[i + 1][j + 1] * (1 if S[i] == chr(65 + j) or S[i] == '?' else 0)\n DP[i][j] += DP[i + 1][j] * (3 if S[i] == '?' else 1)\n DP[i][j] % p\nprint(DP[0][0] % p + 1)", "S = input()\nDP = [0, 0, 0, 1]\np = 10 ** 9 + 7\nfor s in S[::-1]:\n dp = [0, 0, 0, 0]\n dp[3] = DP[3] * (3 if s == '?' else 1) % p\n for i in range(2, -1, -1):\n dp[i] += DP[i] * (3 if s == '?' else 1)\n dp[i] += DP[i + 1] if s == chr(65 + i) or s == '?' else 0\n dp[i] %= p\n DP = dp\nprint(DP[0] % p)"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s550009264', 's621354014', 's575675317']
[3188.0, 477408.0, 3188.0]
[2104.0, 2135.0, 345.0]
[381, 437, 305]
p03291
u419686324
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["init_input()\n\nS = input()\nn = len(S)\nmod = (10**9 + 7)\n\nA = [0] * n\nC = [0] * n\nQ = [0] * n\nBi = []\nQi = []\n\nfor i, s in enumerate(S):\n if s == 'A':\n A[i] = 1\n elif s == 'B':\n Bi.append(i)\n elif s == 'C':\n C[i] = 1\n else:\n Q[i] = 1\n Qi.append(i)\n\nfor i in range(1, n):\n A[i] += A[i - 1]\n C[i] += C[i - 1]\n Q[i] += Q[i - 1]\n\ndef mod_pow(x, n, mod):\n if n == 0: return 1\n d, m = n >> 1, n & 1\n p = mod_pow(x, d, mod)\n return (p * p * (x if m else 1))\n\nfrom itertools import chain\nans = 0\nfor b in chain(Bi, Qi):\n if b == 0 or n - 1 <= b: continue\n ai = A[b - 1]\n qa = Q[b - 1]\n a = (ai * mod_pow(3, qa, mod))\n if qa > 0:\n a += (mod_pow(3, qa - 1, mod) * qa)\n\n lc = C[n - 1] - C[b]\n lqc = Q[n - 1] - Q[b]\n c = (lc * mod_pow(3, lqc, mod))\n if lqc > 0:\n c += (mod_pow(3, lqc - 1, mod) * lqc)\n \n ans += (a * c) % mod\n\nprint(ans % mod)", "S = input()\nn = len(S)\nmod = (10**9 + 7)\n\ndp = [[0] * 4 for _ in range(n + 1)]\n\ndp[n] = [0, 0, 0, 1]\nfor i in range(n-1, -1, -1):\n if S[i] == '?':\n dp[i][3] = dp[i+1][3] * 3 % mod\n dp[i][2] = (dp[i+1][2] * 3 + dp[i+1][3]) % mod\n dp[i][1] = (dp[i+1][1] * 3 + dp[i+1][2]) % mod\n dp[i][0] = (dp[i+1][0] * 3 + dp[i+1][1]) % mod\n elif S[i] == 'C':\n dp[i][3] = dp[i+1][3] % mod\n dp[i][2] = (dp[i+1][2] + dp[i+1][3]) % mod\n dp[i][1] = dp[i+1][1] % mod\n dp[i][0] = dp[i+1][0] % mod\n elif S[i] == 'B':\n dp[i][3] = dp[i+1][3] % mod\n dp[i][2] = dp[i+1][2] % mod\n dp[i][1] = (dp[i+1][1] + dp[i+1][2]) % mod\n dp[i][0] = dp[i+1][0] % mod\n elif S[i] == 'A':\n dp[i][3] = dp[i+1][3]\n dp[i][2] = dp[i+1][2]\n dp[i][1] = dp[i+1][1]\n dp[i][0] = (dp[i+1][0] + dp[i+1][2]) % mod\nprint(dp[0][0])", "S = input()\nn = len(S)\nmod = (10**9 + 7)\n\ndp = [[0] * 5 for _ in range(n + 1)]\n\ndp[n] = [0, 0, 0, 1, 0]\nfor i in range(n-1, -1, -1):\n m1 = 3 if S[i] == '?' else 1\n for j in range(4):\n m2 = 1 if S[i] == '?' or j == 'ABC'.find(S[i]) else 0\n dp[i][j] = (dp[i+1][j] * m1 + dp[i+1][j+1] * m2) % mod\nprint(dp[0][0])"]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s346649331', 's731819490', 's924513069']
[3064.0, 27612.0, 27600.0]
[17.0, 216.0, 468.0]
[943, 905, 329]
p03291
u439396449
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["from scipy.misc import comb\n\nS = input()\nN = len(S)\nmod = 10 ** 9 + 7\n\n\nca = [0] * N\ncq1 = [0] * N\nif S[0] == 'A':\n ca[0] = 1\nif S[0] == '?':\n cq1[0] = 1\nfor i in range(1, N):\n if S[i] == 'A':\n ca[i] = ca[i - 1] + 1\n else:\n ca[i] = ca[i - 1]\n if S[i] == '?':\n cq1[i] = cq1[i - 1] + 1\n else:\n cq1[i] = cq1[i - 1]\n\ncc = [0] * N\ncq2 = [0] * N\nif S[-1] == 'C':\n cc[0] = 1\nif S[-1] == '?':\n cq2[0] = 1\nfor i in range(1, N):\n if S[N - 1 - i] == 'C':\n cc[i] = cc[i - 1] + 1\n else:\n cc[i] = cc[i - 1]\n if S[N - 1 - i] == '?':\n cq2[i] = cq2[i - 1] + 1\n else:\n cq2[i] = cq2[i - 1]\ncc = cc[::-1]\ncq2 = cq2[::-1]\n\nmemo = {}\ndef f(q):\n if q in memo:\n return memo[q]\n x = [0] * (q + 1)\n for i in range(q + 1):\n x[i] = 2 ** (q - i) * comb(q, i, exact=True)\n memo[q] = x\n return x\n\n\nmemo2 = {}\ndef g(x, q):\n if (x, q) in memo2:\n return memo2[(x, q)]\n t = f(q)\n c = 0\n for i in range(q + 1):\n c += t[i] * (i + x)\n memo2[(x, q)] = c\n return c\n\n\nans = 0\nfor i in range(1, N - 1):\n if S[i] in ['B', '?']:\n ans += g(ca[i - 1], cq1[i - 1]) * g(cc[i + 1], cq2[i + 1])\nprint(ans % mod)\n", "from scipy.misc import comb\n\nS = input()\nN = len(S)\nmod = 10 ** 9 + 7\n\n\nca = [0] * N\ncq1 = [0] * N\nif S[0] == 'A':\n ca[0] = 1\nif S[0] == '?':\n cq1[0] = 1\nfor i in range(1, N):\n if S[i] == 'A':\n ca[i] = ca[i - 1] + 1\n else:\n ca[i] = ca[i - 1]\n if S[i] == '?':\n cq1[i] = cq1[i - 1] + 1\n else:\n cq1[i] = cq1[i - 1]\n\ncc = [0] * N\ncq2 = [0] * N\nif S[-1] == 'C':\n cc[0] = 1\nif S[-1] == '?':\n cq2[0] = 1\nfor i in range(1, N):\n if S[N - 1 - i] == 'C':\n cc[i] = cc[i - 1] + 1\n else:\n cc[i] = cc[i - 1]\n if S[N - 1 - i] == '?':\n cq2[i] = cq2[i - 1] + 1\n else:\n cq2[i] = cq2[i - 1]\ncc = cc[::-1]\ncq2 = cq2[::-1]\n\nmemo = {}\ndef f(q):\n if q in memo:\n return memo[q]\n x = [0] * (q + 1)\n for i in range(q + 1):\n x[i] = 2 ** (q - i) * comb(q, i, exact=True)\n memo[q] = x\n return x\n\n\ndef g(x, q):\n t = f(q)\n c = 0\n for i in range(q + 1):\n c += t[i] * (i + x)\n return c\n\n\nans = 0\nfor i in range(1, N - 1):\n if S[i] in ['B', '?']:\n ans += g(ca[i - 1], cq1[i - 1]) * g(cc[i + 1], cq2[i + 1])\nprint(ans % mod)\n", "S = input()\n\nN = len(S)\nmod = 10 ** 9 + 7\n\ndp = [[0 for _ in range(4)] for _ in range(N + 1)]\ndp [0][0] = 1\nfor i in range(N):\n if S[i] == 'A':\n for j in range(4):\n dp[i + 1][j] += dp[i][j]\n dp[i + 1][1] += dp[i][0]\n elif S[i] == 'B':\n for j in range(4):\n dp[i + 1][j] += dp[i][j]\n dp[i + 1][2] += dp[i][1]\n elif S[i] == 'C':\n for j in range(4):\n dp[i + 1][j] += dp[i][j]\n dp[i + 1][3] += dp[i][2]\n else:\n for j in range(4):\n dp[i + 1][j] += dp[i][j] * 3\n dp[i + 1][1] += dp[i][0]\n dp[i + 1][2] += dp[i][1]\n dp[i + 1][3] += dp[i][2]\n\n for j in range(4):\n dp[i + 1][j] %= mod\n\nprint(dp[N][3])"]
['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted']
['s326000239', 's980231518', 's667321213']
[39232.0, 39616.0, 27580.0]
[2112.0, 2110.0, 484.0]
[1225, 1139, 727]
p03291
u442581202
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s = input()\n\nA = [1,0]\nAB = 0\nABC = 0\nD = 10**9 + 7\nfor c in s:\n if c == \'A\':\n A[1] += A[0]\n elif c == \'B\':\n AB += A[1]\n elif c == \'C\':\n ABC += AB\n elif c == \'?\':\n ABC = ABC*3 + AB\n AB *= 3#AB + C and AB + B and AB + C\n AB += A[1] # AB + B\n A[1] = A[1]*3 + A[0]\n A[0] *= 3\n print(c+" " + str(A)+" " + str(AB) + " " + str(ABC))\n\nprint(ABC%D) \n', "s = input()\n\nA = [1,0]\nAB = 0\nABC = 0\nD = 10**9 + 7\nfor c in s:\n if c == 'A':\n A[1] += A[0]\n elif c == 'B':\n AB += A[1]\n elif c == 'C':\n ABC += AB\n elif c == '?':\n ABC = (((ABC%D) *3)%D + (AB)%D)%D\n AB = (((AB%D) *3)%D + (A[1])%D)%D\n A[1] = (((A[1]%D)*3)%D + A[0]%D)%D\n A[0] = ((A[0]%D) * 3)%D\n\nprint(ABC%D) \n"]
['Wrong Answer', 'Accepted']
['s276446821', 's949721113']
[110068.0, 3188.0]
[2103.0, 169.0]
[413, 370]
p03291
u451017206
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['????C?????B??????A???????', "S=input()\ns=len(S)\ndp=[[0,0,0,0]for i in range(s+1)]\ndp[s][3]=1\nfor i in range(s-1,-1,-1):\n for j in[3,2,1,0]:\n dp[i][j]=(3 if S[i]=='?'else 1)*dp[i+1][j]\n if j!=3:dp[i][j]+=(1 if S[i]=='?'or S[i]=='ABC'[j]else 0)*dp[i+1][j+1]\n dp[i][j]%=(10**9+7)\nprint(dp[0][0])\n"]
['Runtime Error', 'Accepted']
['s218078629', 's310899053']
[2940.0, 27588.0]
[17.0, 467.0]
[25, 288]
p03291
u466917094
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['import numpy as np\ns=input()\nwayA=np.array([0,0,0,0])\nwayB=np.array([0,0,0,0])\nwayC=np.array([0,0,0,0])\nhatena=0\nfor c in s:\n\tif c=="A":\n\t\twayA[0]+=1\n\tif c=="B":\n\t\twayB+=wayA\n\tif c==\'C\':\n\t\twayC+=wayB\n\tif c==\'?\':\n\t\twayC[1]+=wayB[0]\n\t\twayC[2]+=wayB[1]\n\t\twayC[3]+=wayB[2]\n\t\twayB[1]+=wayA[0]\n\t\twayB[2]+=wayA[1]\n\t\twayA[1]+=1\n\t\thatena+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,hatena-i)*wayC[i]\nprint(int(ans%MOD))', 'import numpy as np\ns=input()\nA=np.array([0,0,0,0])\nB=np.array([0,0,0,0])\nC=np.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\tC+=np.roll(B,1)\n\t\tB+=np.roll(A,1)\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(str(int(ans%1000000007))+".0")', 'import numpy as np\ns=input()\nA=np.array([0,0,0,0])\nB=np.array([0,0,0,0])\nC=np.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\tC+=np.roll(B,1)\n\t\tB+=np.roll(A,1)\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(ans%1000000007)', '#a,b=map(int,input().split())\ns=input()\nn=len(s)\nwayA=[0,0,0,0]\nwayB=[0,0,0,0]\nwayC=[0,0,0,0]\nhatena=0\nfor c in s:\n\tif c=="A":\n\t\twayA[0]=wayA[0]+1\n\tif c=="B":\n\t\twayB[0]=wayB[0]+wayA[0]\n\t\twayB[1]=wayB[1]+wayA[1]\n\tif c==\'C\':\n\t\twayC=wayC+wayB\n\t\twayC[0]=wayC[0]+wayB[0]\n\t\twayC[1]=wayC[1]+wayB[1]\n\t\twayC[2]=wayC[2]+wayB[2]\n\tif c==\'?\':\n\t\twayC[1]=wayC[1]+wayB[0]\n\t\twayC[2]=wayC[2]+wayB[1]\n\t\twayC[3]=wayC[3]+wayB[2]\n\t\twayB[1]=wayB[1]+wayA[0]\n\t\twayB[2]=wayB[2]+wayA[1]\n\t\twayA[1]=wayA[1]+1\n\t\thatena=hatena+1\nans=0\nfor i in range(0,4):\n\tans=ans+pow(3,hatena-i)*wayC[i]\nans = ans%1000000007\nprint(ans)', '#a,b=map(int,input().split())\nimport numpy as np\n\ns=input()\nn=len(s)\nwayA=np.array([0,0,0,0],dtype=np.int64)\nwayB=np.array([0,0,0,0],dtype=np.int64)\nwayC=np.array([0,0,0,0],dtype=np.int64)\nhatena=0\nMOD=1000000007\nfor c in s:\n\tif c=="A":\n\t\twayA[0]=wayA[0]+1\n\tif c=="B":\n\t\twayB[0]=wayB[0]+wayA[0]\n\t\twayB[1]=wayB[1]+wayA[1]\n\tif c==\'C\':\n\t\twayC=wayC+wayB\n\t\twayC[0]=wayC[0]+wayB[0]\n\t\twayC[1]=wayC[1]+wayB[1]\n\t\twayC[2]=wayC[2]+wayB[2]\n\tif c==\'?\':\n\t\twayC[1]=wayC[1]+wayB[0]\n\t\twayC[2]=wayC[2]+wayB[1]\n\t\twayC[3]=wayC[3]+wayB[2]\n\t\twayB[1]=wayB[1]+wayA[0]\n\t\twayB[2]=wayB[2]+wayA[1]\n\t\twayA[1]=wayA[1]+1\n\t\thatena=hatena+1\n\tfor z in range(0,4):\n\t\twayA[z]=wayA[z]%MOD\n\t\twayB[z]=wayB[z]%MOD\n\t\twayC[z]=wayC[z]%MOD\nans=0\nfor i in range(0,4):\n\tp3=1\n\twayC[i]=wayC[i]%MOD\n\tif wayC[i]<=0:\n\t\tcontinue\n\tfor k in range(0,hatena-i):\n\t\tp3=p3*3\n\t\tp3=p3%MOD\n\tans=ans+p3*wayC[i]\nans = ans%1000000007\nprint(int(ans))', 'import numpy as np\ns=input()\nA=np.array([0,0,0,0])\nB=np.array([0,0,0,0])\nC=np.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\tC[1]+=B[0]\n\t\tC[2]+=B[1]\n\t\tC[3]+=B[2]\n\t\tB[1]+=A[0]\n\t\tB[2]+=A[1]\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(ans%1000000007)', 'import numpy as p\ns=input()\nA=B=C=p.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\tC+=p.roll(B,1)\n\t\tB[1]+=A[0]\n\t\tB[2]+=A[1]\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(int(ans%1000000007))', 'import numpy as np\ns=input()\nwayA=np.array([0,0,0,0])\nwayB=np.array([0,0,0,0])\nwayC=np.array([0,0,0,0])\nhatena=0\nfor c in s:\n\tif c=="A":\n\t\twayA[0]+=1\n\tif c=="B":\n\t\twayB+=wayA\n\tif c==\'C\':\n\t\twayC+=wayB\n\tif c==\'?\':\n\t\twayC[1]=wayC[1]+wayB[0]\n\t\twayC[2]=wayC[2]+wayB[1]\n\t\twayC[3]=wayC[3]+wayB[2]\n\t\twayB[1]=wayB[1]+wayA[0]\n\t\twayB[2]=wayB[2]+wayA[1]\n\t\twayA[1]=wayA[1]+1\n\t\thatena+=1\nans=0\nfor i in range(0,4):\n\tans=ans+pow(3,hatena-i)*wayC[i]\nprint(ans%1000000007)', 'import numpy as np\ns=input()\nA=np.array([0,0,0,0])\nB=np.array([0,0,0,0])\nC=np.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\twayC+=np.roll(wayB,1)\n\t\tB[1]+=A[0]\n\t\tB[2]+=A[1]\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(int(ans%1000000007))', 'import numpy as np\ns=input()\nA=np.array([0,0,0,0])\nB=np.array([0,0,0,0])\nC=np.array([0,0,0,0])\nt=0\nfor c in s:\n\tif c=="A":\n\t\tA[0]+=1\n\tif c=="B":\n\t\tB+=A\n\tif c==\'C\':\n\t\tC+=B\n\tif c==\'?\':\n\t\tC+=np.roll(B,1)\n\t\tB[1]+=A[0]\n\t\tB[2]+=A[1]\n\t\tA[1]+=1\n\t\tt+=1\nans=0\nfor i in range(4):\n\tans+=pow(3,t-i)*C[i]\nprint(int(ans%1000000007))']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s045034256', 's108263142', 's251478746', 's301049842', 's576576648', 's647042059', 's653770318', 's847201610', 's857942143', 's407817383']
[12620.0, 21244.0, 21324.0, 5444.0, 14668.0, 21408.0, 21416.0, 12656.0, 12616.0, 18624.0]
[575.0, 2108.0, 2108.0, 2108.0, 2108.0, 1930.0, 1825.0, 569.0, 260.0, 1562.0]
[406, 319, 304, 589, 884, 333, 274, 455, 323, 317]
p03291
u474270503
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['MOD=10**9+7\ndef func(s):\n abc="ABC"\n n = len(s)\n dp=[[0 for _ in range(3+1)] for _ in range(n+1)]\n dp[n][3]=1\n\n for i in range(n-1,-1,-1):\n for j in range(3,-1,-1):\n if j==3:\n if s[i]==\'?\':\n dp[i][j]=(dp[i+1][j]*3)%MOD\n else:\n dp[i][j]=dp[i+1][j]\n else:\n m1=3 if s[i]==\'?\' else 1\n m2=1 if s[i]==\'?\' or s[i]==abc[j] else 0\n dp[i][j]=((m1*dp[i+1][j])%MOD +(m2*dp[i+1][j+1])%MOD)%MOD\n print(dp)\n return dp[0][0]\nprint(func(input()))\n', 'MOD=10**9+7\ndef func(s):\n abc="ABC"\n n = len(s)\n dp=[[0 for _ in range(3+1)] for _ in range(n+1)]\n dp[n][3]=1\n\n for i in range(n-1,-1,-1):\n for j in range(3,-1,-1):\n if j==3:\n if s[i]==\'?\':\n dp[i][j]=(dp[i+1][j]*3)%MOD\n else:\n dp[i][j]=dp[i+1][j]\n else:\n m1=3 if s[i]==\'?\' else 1\n m2=1 if s[i]==\'?\' or s[i]==abc[j] else 0\n dp[i][j]=((m1*dp[i+1][j])%MOD +(m2*dp[i+1][j+1])%MOD)%MOD\n return dp[0][0]\nprint(func(input()))\n']
['Wrong Answer', 'Accepted']
['s572397208', 's234515364']
[40868.0, 27572.0]
[462.0, 382.0]
[593, 579]
p03291
u498487134
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['S=input()\nN=len(S)', 'S=input()\nN=len(S)\ndp=[0,0,0]\n\nmod=10**9+7\n\np=[1]*(N+1)\nfor i in range(N):\n p[i+1]=p[i]*3', '\n\nS=input()\nN=len(S)\ndp=[0,0,0]\n\nmod=10**9+7\n\np=[1]*(N+1)\nfor i in range(N):\n p[i+1]=(p[i]*3)%mod\n\n\ncount=0\nfor i in range(N):\n if S[i]=="A":\n dp[0]=(dp[0]+p[count]) %mod\n elif S[i]=="B":\n dp[1]=(dp[1]+dp[0])%mod\n elif S[i]=="C":\n dp[2]=(dp[2]+dp[1])%mod\n else:\n dp[2]=(dp[2]*3+dp[1])%mod\n dp[1]=(dp[1]*3+dp[0])%mod\n dp[0]=(dp[0]*3+p[count])%mod\n count+=1\n \nprint(dp[2]%mod) \n\n\n\n\n\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s033625565', 's366659590', 's142672727']
[3192.0, 1039988.0, 7140.0]
[18.0, 967.0, 149.0]
[18, 92, 560]
p03291
u512007680
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['MOD = 10 ** 9 + 7\n\nS = list(input())\n\na = [0] * len(S)\nab = [0] * len(S)\nabc = [0] * len(S)\n\nif S[0] == "A" or S[0] == "?":\n a[0] = 1\n\nfor i in range(1,len(S)):\n if S[i] == "A":\n a[i] = a[i-1] + 1\n ab[i] = ab[i-1]\n abc[i] = abc[i-1]\n elif S[i] == "B":\n a[i] = a[i-1]\n ab[i] = (ab[i-1] + a[i-1]) % MOD\n abc[i] = abc[i-1]\n elif S[i] == "C":\n a[i] = a[i-1]\n ab[i] = ab[i-1]\n abc[i] = (abc[i-1] + ab[i-1]) % MOD\n else:\n a[i] = (a[i-1] * 3 + 1) % MOD\n ab[i] = (ab[i-1] * 3 + a[i-1]) % MOD\n abc[i] = (abc[i-1] * 3 + ab[i-1]) % MOD\n\nprint(a)\nprint(ab)\nprint(abc)\nprint(abc[-1])\n', 'MOD = 10 ** 9 + 7\n\nS = [0] + list(input())\nn = len(S) - 1\n\nyet = [0] * (n+1)\na = [0] * (n+1)\nab = [0] * (n+1)\nabc = [0] * (n+1)\n\n\nabc[n] = 1\n\nfor i in range(1,n+1):\n if S[n-i+1] == "A":\n yet[n-i] = (yet[n-i+1] + a[n-i+1]) % MOD\n a[n-i] = a[n-i+1]\n ab[n-i] = ab[n-i+1]\n abc[n-i] = abc[n-i+1]\n elif S[n-i+1] == "B":\n yet[n-i] = yet[n-i+1]\n a[n-i] = (ab[n-i+1] + a[n-i+1]) % MOD\n ab[n-i] = ab[n-i+1]\n abc[n-i] = abc[n-i+1]\n elif S[n-i+1] == "C":\n yet[n-i] = yet[n-i+1]\n a[n-i] = a[n-i+1]\n ab[n-i] = (ab[n-i+1] + abc[n-i+1]) % MOD\n abc[n-i] = abc[n-i+1]\n else:\n yet[n-i] = (yet[n-i+1] * 3 + a[n-i+1]) % MOD\n a[n-i] = (a[n-i+1] * 3 + ab[n-i+1]) % MOD\n ab[n-i] = (ab[n-i+1] * 3 + abc[n-i+1]) % MOD\n abc[n-i] = (abc[n-i+1] * 3) % MOD\n\nprint(yet[0])']
['Wrong Answer', 'Accepted']
['s355120779', 's206146442']
[21996.0, 19536.0]
[175.0, 236.0]
[670, 921]
p03291
u518378780
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\n\ndp3 = 1\ndp2 = 0\ndp1 = 0\ndp0 = 0\n\nfor i in reversed(range((len(s)))):\n m = 1\n m1 = 1\n m2 = 0\n m3 = 0\n m4 = 0\n if s[i] == '?':\n m = 3\n m1 = 3\n m2 = 1\n m3 = 1\n m4 = 1\n\n if s[i] == 'C':\n m2 = 1\n\n if s[i] == 'B':\n m3 = 1\n\n if ss[i] == 'A':\n m4 = 1\n\n t_dp3 = m * dp3\n t_dp2 = m1 * dp2 + m2 * dp3\n t_dp1 = m1 * dp1 + m3 * dp2\n t_dp0 = m1 * dp0 + m4 * dp1\n dp3 = t_dp3\n dp2 = t_dp2\n dp1 = t_dp1\n dp0 = t_dp0\n\nn = 10 ** 9 + 7\nans = dp0 % n\nprint(ans)", "s = input()\n\ndp3 = 1\ndp2 = 0\ndp1 = 0\ndp0 = 0\n\nn = 10 ** 9 + 7\n\nfor i in reversed(range((len(s)))):\n if s[i] == '?':\n m = 3\n else:\n m = 1\n\n if s[i] == '?':\n m1 = 3\n else:\n m1 = 1\n\n if s[i] == '?' or s[i] == 'C':\n m2 = 1\n else:\n m2 = 0\n\n if s[i] == '?' or s[i] == 'B':\n m3 = 1\n else:\n m3 = 0\n\n if s[i] == '?' or s[i] == 'A':\n m4 = 1\n else:\n m4 = 0\n\n t_dp3 = (m * dp3) % n\n t_dp2 = (m1 * dp2 + m2 * dp3) % n\n t_dp1 = (m1 * dp1 + m3 * dp2) % n\n t_dp0 = (m1 * dp0 + m4 * dp1) % n\n dp3 = t_dp3\n dp2 = t_dp2\n dp1 = t_dp1\n dp0 = t_dp0\n\nans = dp0\nprint(ans)"]
['Runtime Error', 'Accepted']
['s214016101', 's787504372']
[3188.0, 3188.0]
[17.0, 171.0]
[561, 672]
p03291
u536113865
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\nn = len(s)\nmod = 10**9+7\n\nmoji = [[0,0,0,0] for _ in range(n+1)]\n\nfor i in range(1,n+1):\n for k in range(4):\n moji[i][k] += moji[i-1][k]\n if s[i-1] == 'A':\n moji[i][0] += 1\n continue\n elif s[i-1] == 'B':\n moji[i][1] += 1\n continue\n elif s[i-1] == 'C':\n moji[i][2] += 1\n continue\n else:\n moji[i][3] += 1\n\nh = s.count('?')\nmt = [1]\nfor i in range(h+1):\n mt.append(mt[-1]*3 % mod)\n\nans = 0\nfor i in range(n):\n al,cr,hl,hr = moji[i][0], moji[n][2]-moji[i+1][2], moji[i][3], moji[n][3]-moji[i+1][3]\n if s[i] == 'B' or s[i] == '?':\n k = (al*3 + hl) * (cr*3 + hr) * mt[hr+hl-2]\n ans += k % mod\nprint(ans%mod)", "s = input()\nn = len(s)\nmod = 10**9+7\n\nmoji = [[0,0,0,0] for _ in range(n+1)]\n\nfor i in range(1,n+1):\n for k in range(4):\n moji[i][k] += moji[i-1][k]\n if s[i-1] == 'A':\n moji[i][0] += 1\n continue\n elif s[i-1] == 'B':\n moji[i][1] += 1\n continue\n elif s[i-1] == 'C':\n moji[i][2] += 1\n continue\n else:\n moji[i][3] += 1\n\nh = s.count('?')\nmt = [1]\nfor i in range(h+1):\n mt.append(mt[-1]*3 % mod)\nmt += [1/9,1/3]\nans = 0\nfor i in range(n):\n al,cr,hl,hr = moji[i][0], moji[n][2]-moji[i+1][2], moji[i][3], moji[n][3]-moji[i+1][3]\n if s[i] == 'B' or s[i] == '?':\n k = (al*3 + hl) * (cr*3 + hr) * mt[hr+hl-2]\n ans += int(k) % mod\nprint(ans%mod)"]
['Wrong Answer', 'Accepted']
['s788748621', 's454863205']
[29028.0, 29064.0]
[391.0, 407.0]
[707, 727]
p03291
u619379081
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\ncount = 0\nlen = len(s)\ndef isa(char):\n if char == 'A' or char == '?':\n return 1\n else:\n return 0\ndef isc(char):\n if char == 'C' or char == '?':\n return 1\n else:\n return 0\nq = 0\nfor i in range(len):\n if s[i] == '?':\n q += 1\n else:\n continue\nfor i in range(len):\n a, c = 0, 0\n if s[i] == 'A' or s[i] == 'C':\n continue\n else:\n for j in range(i):\n a += isa(s[j])\n for j in range(i+1, len):\n c += isc(s[j])\n if s[i] == 'B':\n count += a * c * pow(3, q)\n else:\n count += a * c * pow(3, q-1)\nprint(count % 1000000007)", "s = input()\ncount = 0\na = 0\nq = s.count('?')\nc = 3 * s.count('C') + q\np = pow(3, q-3)\nfor i in range(len(s)):\n if s[i] == 'A':\n a += 3\n elif s[i] == 'C':\n c -= 3\n elif s[i] == 'B':\n count += 3*a*c\n else:\n c -= 1\n count += a*c\n a += 1\nprint(int(count*p) % 1000000007)"]
['Wrong Answer', 'Accepted']
['s741234023', 's794135520']
[3192.0, 3188.0]
[2104.0, 71.0]
[653, 320]
p03291
u623687794
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s=input()\nmod=10**9+7\nretnum={"?":0,"A":1,"B":2,"C":3}\ncount=[[0 for i in range(len(s))] for j in range(4)]\nfor i in range(len(s)):\n for j in range(4):\n if retnum[s[i]] == j:\n count[j][i]=count[j][i-1]+1\n else:\n count[j][i]=count[j][i-1]\nans=0\nfor i in range(1,len(s)-1):\n if s[i]=="B" or s[i]=="?":\n ans+=((3**(count[0][i-1]-1))*count[0][i-1]+(3**count[0][i-1])*count[1][i-1])*(3**(count[0][-1]-count[0][i]-1)*(count[0][-1]-count[0][i])+(3**(count[0][-1]-count[0][i]))*(count[3][-1]-count[3][i]))\n ans%=mod\nprint(ans)', 's=input()\nmod=10**9+7\nretnum={"?":0,"A":1,"B":2,"C":3}\ncount=[[0 for i in range(len(s))] for j in range(4)]\nfor i in range(len(s)):\n for j in range(4):\n if retnum[s[i]] == j:\n count[j][i]=count[j][i-1]+1\n else:\n count[j][i]=count[j][i-1]\nans=0\ng=[1]*100002\nfor i in range(1,100002):\n g[i]=g[i-1]*3\n g[i]%=mod\nfor i in range(1,len(s)-1):\n if s[i]=="B" or s[i]=="?":\n ans+=(g[max(0,count[0][i-1]-1)]*count[0][i-1]+g[count[0][i-1]]*count[1][i-1])*(g[max(0,count[0][-1]-count[0][i]-1)]*(count[0][-1]-count[0][i])+g[count[0][-1]-count[0][i]]*(count[3][-1]-count[3][i]))\n ans%=mod\nprint(ans)']
['Runtime Error', 'Accepted']
['s456490693', 's611610846']
[9548.0, 13540.0]
[2104.0, 447.0]
[574, 647]
p03291
u623819879
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['a', 'a', "s=input()\n\nn=len(s)\ndc=dict()\ndc['A']=0\ndc['B']=1\ndc['C']=2\ndc['?']=3\ndp=[[0 for i in range(4)] for j in range(n+1)]\ndp[0][0]=1\nmo=10**9+7\nfor i in range(n):\n for t in range(4):\n ch=s[i]\n m = 1 if dc[ch]==t-1 or dc[ch]==3 else 0\n if t!=0:\n dp[i+1][t]+=(dp[i][t-1]*m)%mo\n dp[i+1][t]+=(dp[i][t]*(3 if dc[ch]==3 else 1))%mo\n\nans=dp[n][3]\nprint(ans%mo)\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s122439571', 's569579322', 's645816825']
[2940.0, 2940.0, 27616.0]
[17.0, 17.0, 580.0]
[1, 1, 391]
p03291
u627417051
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['\nm = (10 ** 9) + 7\nS = list(input())\nN = len(S)\ndp = [[0 for i in range(N + 2)] for j in range(3)]\nthree = [0 for i in range(10 ** 5 + 1)]\nthree[0] = 1\nfor i in range(1, 10 ** 5 + 1):\n\tthree[i] = (three[i - 1] * 3) % m\n\n#DP\nque = 0\nfor i in range(N):\n\tif S[i] == "A":\n\t\tdp[0][i + 1] = dp[0][i] + three[que]\n\t\tdp[1][i + 1] = dp[1][i]\n\t\tdp[2][i + 1] = dp[2][i]\n\telif S[i] == "B":\n\t\tdp[0][i + 1] = dp[0][i]\n\t\tdp[1][i + 1] = dp[0][i] + dp[1][i]\n\t\tdp[2][i + 1] = dp[2][i]\n\telif S[i] == "C":\n\t\tdp[0][i + 1] = dp[0][i]\n\t\tdp[1][i + 1] = dp[1][i]\n\t\tdp[2][i + 1] = dp[1][i] + dp[2][i]\n\telse:\n\t\tdp[0][i + 1] = 3 * dp[0][i] + three[que]\n\t\tdp[1][i + 1] = 3 * dp[1][i] + dp[0][i]\n\t\tdp[2][i + 1] = 3 * dp[2][i] + dp[1][i]\n\t\tque += 1\n\tdp[0][i + 1], dp[1][i + 1], dp[2][i + 1] = dp[0][i + 1] % m, dp[1][i + 1] % m, dp[2][i + 1] % m\n\nprint(dp)\nprint(dp[2][N])', '\nm = (10 ** 9) + 7\nS = list(input())\nN = len(S)\ndp = [[0 for i in range(N + 2)] for j in range(3)]\nthree = [0 for i in range(10 ** 5 + 1)]\nthree[0] = 1\nfor i in range(1, 10 ** 5 + 1):\n\tthree[i] = (three[i - 1] * 3) % m\n\n#DP\nque = 0\nfor i in range(N):\n\tif S[i] == "A":\n\t\tdp[0][i + 1] = dp[0][i] + three[que]\n\t\tdp[1][i + 1] = dp[1][i]\n\t\tdp[2][i + 1] = dp[2][i]\n\telif S[i] == "B":\n\t\tdp[0][i + 1] = dp[0][i]\n\t\tdp[1][i + 1] = dp[0][i] + dp[1][i]\n\t\tdp[2][i + 1] = dp[2][i]\n\telif S[i] == "C":\n\t\tdp[0][i + 1] = dp[0][i]\n\t\tdp[1][i + 1] = dp[1][i]\n\t\tdp[2][i + 1] = dp[1][i] + dp[2][i]\n\telse:\n\t\tdp[0][i + 1] = 3 * dp[0][i] + three[que]\n\t\tdp[1][i + 1] = 3 * dp[1][i] + dp[0][i]\n\t\tdp[2][i + 1] = 3 * dp[2][i] + dp[1][i]\n\t\tque += 1\n\tdp[0][i + 1], dp[1][i + 1], dp[2][i + 1] = dp[0][i + 1] % m, dp[1][i + 1] % m, dp[2][i + 1] % m\n\nprint(dp[2][N])']
['Wrong Answer', 'Accepted']
['s086385046', 's896429587']
[30024.0, 19792.0]
[303.0, 272.0]
[851, 841]
p03291
u631277801
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["import sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10**5)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nmod = 10**9+7\n\ns = lc()\nn = len(s)\n\na__ = [0]*(n+1)\nab_ = [0]*(n+1)\nabc = [0]*(n+1)\n\nfor i,si in enumerate(s):\n\n if si == 'A':\n a__[i+1] = (a__[i] + 1) % mod\n \n ab_[i+1] = ab_[i]\n abc[i+1] = abc[i]\n\n elif si == 'B':\n ab_[i+1] = (ab_[i] + a__[i]) % mod\n \n a__[i+1] = a__[i]\n abc[i+1] = abc[i]\n \n elif si == 'C':\n abc[i+1] = (abc[i] + ab_[i]) % mod\n \n a__[i+1] = a__[i]\n ab_[i+1] = ab_[i]\n \n \n else:\n a__[i+1] = (3*a__[i] + 1) % mod\n ab_[i+1] = (ab_[i] + a__[i]) % mod\n abc[i+1] = (abc[i] + ab_[i]) % mod\n \nprint(abc[n])", "# Input\nimport sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\ns = ns()\nt = len(s)\n\na__ = [0]*(t+1)\nab_ = [0]*(t+1)\nabc = [0]*(t+1)\n\nMOD = 10**9 + 7\nq = 0\nfor i, si in enumerate(s):\n if si == 'A':\n a__[i+1] = a__[i] + pow(3,q,MOD)\n ab_[i+1] = ab_[i]\n abc[i+1] = abc[i]\n\n elif si == 'B':\n a__[i+1] = a__[i]\n ab_[i+1] = ab_[i] + a__[i]\n abc[i+1] = abc[i]\n\n elif si == 'C':\n a__[i+1] = a__[i]\n ab_[i+1] = ab_[i]\n abc[i+1] = abc[i] + ab_[i]\n\n elif si == '?':\n a__[i+1] = 3 * a__[i] + pow(3,q,MOD)\n ab_[i+1] = 3 * ab_[i] + a__[i]\n abc[i+1] = 3 * abc[i] + ab_[i]\n\n q += 1\n\n\n a__[i + 1] %= MOD\n ab_[i + 1] %= MOD\n abc[i + 1] %= MOD\n\nprint(abc[t])"]
['Wrong Answer', 'Accepted']
['s541223615', 's421556522']
[15836.0, 15216.0]
[136.0, 373.0]
[1091, 1128]
p03291
u631914718
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['import sys\nsys.setrecursionlimit(10**7)\n\nmodulus = 10 ** 9 + 7\ns = input()\n\n\ndef dp(i, j):\n """\n dynamic programming for abc 104\n :param i: index of the given string\n :param j: count of letters of composed string (like \'ABC\')\n :return: the number of cases\n """\n if i == n:\n if j == 3:\n return 1\n else:\n return 0\n\n if i < n and j == 3:\n m = 3 if s[i] == \'?\' else 1\n return m * dp(i + 1, 3) % modulus\n\n if i < n and j < 3:\n m1 = 3 if s[i] == \'?\' else 1\n m2 = 1 if s[i] == \'?\' or s[i] == \'ABC\'[j] else 0\n\n _pass = m1 * dp(i + 1, j) % modulus\n _take = m2 * dp(i + 1, j + 1) % modulus\n\n return _pass + _take\n\n\nprint(dp(0, 0))\n', 'class ABC104:\n modulus = 10 ** 9 + 7\n\n def __init__(self, s):\n self.s = s\n self.n = len(s)\n\n def dp(self, i, j):\n """\n dynamic programming for abc 104\n :param i: index of the given string\n :param j: count of letters of composed string (like \'ABC\')\n :return: the number of cases\n """\n if i == self.n:\n if j == 3:\n return 1\n else:\n return 0\n\n if i < self.n and j == 3:\n m = 3 if self.s[i] == \'?\' else 1\n return m * self.dp(i + 1, 3) % self.modulus\n\n if i < self.n and j < 3:\n m1 = 3 if self.s[i] == \'?\' else 1\n m2 = 1 if self.s[i] == \'?\' or self.s[i] == \'ABC\'[j] else 0\n\n _pass = m1 * self.dp(i + 1, j) % self.modulus\n _take = m2 * self.dp(i + 1, j + 1) % self.modulus\n\n return _pass + _take\n\n\nif __name__ == \'__main__\':\n import sys\n sys.setrecursionlimit(10**15)\n\n abc = ABC104(input())\n print(abc.dp(0, 0))\n', 'if __name__ == "__main__":\n modulus = 10 ** 9 + 7\n s = input()\n n = len(s)\n dp = [[0] * 4 for _ in range(n + 1)]\n\n for i in range(n + 1)[::-1]:\n for j in range(4)[::-1]:\n if i == n:\n if j == 3:\n dp[i][j] = 1\n else:\n dp[i][j] = 0\n else:\n is_wildcard = s[i] == \'?\'\n if j == 3:\n m = 3 if is_wildcard else 1\n dp[i][j] = m * dp[i + 1][3] % modulus\n\n else:\n m1 = 3 if is_wildcard else 1\n m2 = 1 if is_wildcard or s[i] == \'ABC\'[j] else 0\n\n dp[i][j] = (m1 * dp[i + 1][j] + m2 * dp[i + 1][j + 1]) % modulus\n # print(i, j, dp[i][j])\n print(dp[0][0])\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s467310517', 's815756961', 's210103979']
[3188.0, 3188.0, 27588.0]
[19.0, 17.0, 504.0]
[733, 1034, 806]
p03291
u690536347
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['from itertools import accumulate as ac\ns=input()\nn=len(s)\nmod=int(1e9)+7\n\n*aca,=ac([0]+[1 if i=="A" else 0 for i in s])\n*acc,=ac([0]+[1 if i=="C" else 0 for i in s])\n*acq,=ac([0]+[1 if i=="?" else 0 for i in s])\n\nv=0\nfor i in range(1,n-1):\n if s[i]=="B" or s[i]=="?":\n a=aca[i]\n l=acq[i]\n c=acc[n]-acc[i+1]\n r=acq[n]-acq[i+1]\n v+=(a*c*pow(3,l+r,mod))\n if l+r-1>=0:\n v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))\n if l+r-2>=0:\n v+=(l*r*pow(3,l+r-2,mod))\n v%=mod', 'from itertools import accumulate as ac\ns=input()\nn=len(s)\nmod=int(1e9)+7\n\n*aca,=ac([0]+[1 if i=="A" else 0 for i in s])\n*acc,=ac([0]+[1 if i=="C" else 0 for i in s])\n*acq,=ac([0]+[1 if i=="?" else 0 for i in s])\n\nv=0\nfor i in range(1,n-1):\n if s[i]=="B" or s[i]=="?":\n a=aca[i]\n l=acq[i]\n c=acc[n]-acc[i+1]\n r=acq[n]-acq[i+1]\n v+=(a*c*pow(3,l+r,mod))\n if l+r-1>=0:\n v+=(a*r*pow(3,l+r-1,mod))+(l*c*pow(3,l+r-1,mod))\n if l+r-2>=0:\n v+=(l*r*pow(3,l+r-2,mod))\n v%=mod\nprint(v)']
['Wrong Answer', 'Accepted']
['s142570317', 's592796216']
[17220.0, 17220.0]
[971.0, 961.0]
[498, 507]
p03291
u726615467
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['import sys\n# input = sys.stdin.readline\nS = list(input())\np = 10 ** 9 + 7\n# p = 10 ** 18\n\nC = BC = ABC = 0\nfor Si in reversed(S):\n print("#", C, BC, ABC)\n if Si == \'C\':\n C = (C + 1) % p\n elif Si == \'B\':\n BC = (BC + C) % p\n elif Si == \'A\':\n ABC = (ABC + BC) % p\n else:\n C_prev, BC_prev, ABC_prev = C, BC, ABC\n C = BC = ABC = 0\n for Ti in (\'A\', \'B\', \'C\'):\n C_tmp, BC_tmp, ABC_tmp = C_prev, BC_prev, ABC_prev\n if Ti == \'C\':\n C_tmp = (C_tmp + 1) % p\n elif Ti == \'B\':\n BC_tmp = (BC_tmp + C_tmp) % p\n else:\n ABC_tmp = (ABC_tmp + BC_tmp) % p\n # print("##", C_tmp, BC_tmp, ABC_tmp)\n C = (C + C_tmp) % p\n BC = (BC + BC_tmp) % p\n ABC = (ABC + ABC_tmp) % p\n\nprint(ABC)', 'import sys\n# input = sys.stdin.readline\nS = list(input())\np = 10 ** 9 + 7\n# p = 10 ** 18\n\nA = AB = ABC = 0\npower = 1\nfor i, Si in enumerate(S):\n # print("#", A, AB, ABC)\n if Si == \'A\':\n A = (A + 1 * power) % p\n elif Si == \'B\':\n AB = (AB + A) % p\n elif Si == \'C\':\n ABC = (ABC + AB) % p\n else:\n ABC = (3 * ABC + AB) % p\n AB = (3 * AB + A) % p\n A = (3 * A + 1 * power) % p\n power = (power * 3) % p\n\nprint(ABC)']
['Wrong Answer', 'Accepted']
['s149083729', 's554728909']
[7136.0, 3956.0]
[479.0, 110.0]
[847, 470]
p03291
u745514010
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s=input()\ncount=0\nfor i in range(len(s)):\n if s[i]=="A" or s[i]=="?":\n for j in range(len(s)-1,i,-1):\n if s[j]=="C" or s[j]=="?":\n k=s[i+1:j]\n bb=k.count("B")\n dd=k.count("?")\n count=(count+bb*3**dd+dd*3**(dd-1))%(10**9+7)\nprint(count)', 's=input()\ncount=0\nfor i in range(len(s)):\n if s[i]=="A" or s[i]=="?":\n for j in range(len(s)-1,i+1,-1):\n if s[j]=="C" or s[j]=="?":\n k=s[i+1:j]\n bb=k.count("B")\n dd=k.count("?")\n count=((count+bb*3**dd+dd*3**(dd-1))/(10**9+7))\nprint(int(count))', 'import sys\ninput = sys.stdin.readline\nMOD = 10 ** 9 + 7\n\ndef main():\n string = input().strip()\n n = len(string)\n dp = [[0, 0, 0, 0] for _ in range(n + 1)]\n dp[0][0] = 1\n for i, s in enumerate(string):\n if s == "A":\n dp[i + 1][0] = dp[i][0]\n dp[i + 1][1] = dp[i][1] + dp[i][0]\n dp[i + 1][2] = dp[i][2]\n dp[i + 1][3] = dp[i][3]\n elif s == "B":\n dp[i + 1][0] = dp[i][0]\n dp[i + 1][1] = dp[i][1]\n dp[i + 1][2] = dp[i][2] + dp[i][1]\n dp[i + 1][3] = dp[i][3]\n elif s == "C":\n dp[i + 1][0] = dp[i][0]\n dp[i + 1][1] = dp[i][1]\n dp[i + 1][2] = dp[i][2]\n dp[i + 1][3] = dp[i][3] + dp[i][2]\n else:\n dp[i + 1][0] = 3 * dp[i][0]\n dp[i + 1][1] = 3 * dp[i][1] + dp[i][0]\n dp[i + 1][2] = 3 * dp[i][2] + dp[i][1]\n dp[i + 1][3] = 3 * dp[i][3] + dp[i][2]\n for j in range(4):\n dp[i + 1][j] %= MOD\n print(dp[-1][-1] % MOD)\n \nmain()']
['Runtime Error', 'Runtime Error', 'Accepted']
['s379915058', 's710953288', 's412851226']
[3316.0, 3316.0, 32040.0]
[2104.0, 2104.0, 198.0]
[316, 325, 1053]
p03291
u769852547
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["S = input()\nMOD = 10**9+7\nA = 0\nC = S.count('C')\nQ = 0\nQMAX = S.count('?')\n\nans = 0\n\nb = 3 ** (QMAX-2) % MOD\nq = 3 ** (QMAX-3) % MOD\n\nfor s in S:\n if s == 'A':\n A += 1\n elif s == 'C':\n C -= 1\n elif s == 'B':\n \n ans = (ans + (3*A+q) * (3*C+QMAX-q) * b)%MOD\n else:\n ans = (ans + (3*A+q) * (3*C+QMAX-q-1) * q)%MOD\n\nprint(ans)", "S = input()\nMOD = 10**9+7\nA = 0\nC = S.count('C')\nQ = 0\nQMAX = S.count('?')\n\nans = 0\n\nb = 3 ** (QMAX-2) % MOD\nq = 3 ** (QMAX-3) % MOD\n\nfor s in S:\n if s == 'A':\n A += 1\n elif s == 'C':\n C -= 1\n elif s == 'B':\n ans = (ans + (3*A+Q) * b * (3*C+QMAX-Q))%MOD\n else:\n ans = (ans + (3*A+Q) * q * (3*C+QMAX-Q-1))%MOD\n Q += 1\n\nprint(int(ans))"]
['Wrong Answer', 'Accepted']
['s770444506', 's360338344']
[3188.0, 3188.0]
[92.0, 87.0]
[426, 437]
p03291
u782098901
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["\n#include <string>\n\nusing namespace std;\n\nconst int MOD = 1000000007;\n\nint main() {\n string S;\n cin >> S;\n\n int len = S.size();\n ll a = 0, ab = 0, abc = 0, all_s = 1;\n\n for (int i = 0; i < len; i++) {\n if (S[i] == 'A')\n a = (a + all_s) % MOD;\n else if (S[i] == 'B')\n ab = (ab + a) % MOD;\n else if (S[i] == 'C')\n abc = (abc + ab) % MOD;\n else if (S[i] == '?') {\n abc = (abc * 3 + ab) % MOD;\n ab = (ab * 3 + a) % MOD;\n a = (a * 3 + all_s) % MOD;\n all_s = (all_s * 3) % MOD;\n }\n }\n cout << abc << endl;\n}", 'import sys\ninput = sys.stdin.readline\n\nMOD = 10 ** 9 + 7\n\nS = input()\n\na, ab, abc = [0] * 3\nc = 1\n\nfor s in S:\n if s == "A":\n a = (a + c) % MOD\n elif s == "B":\n ab = (ab + a) % MOD\n elif s == "C":\n abc = (abc + ab) % MOD\n elif s == "?":\n abc = (3 * abc + ab) % MOD\n ab = (3 * ab + a) % MOD\n a = (3 * a + c) % MOD\n c = (3 * c) % MOD\nprint(abc % MOD)\n']
['Runtime Error', 'Accepted']
['s661588540', 's598099797']
[2940.0, 3188.0]
[18.0, 109.0]
[606, 410]
p03291
u786607349
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['s = input()\ndp = [[0 for _ in range(0,4)] for _ in range(0,len(s)+1)]\ndp[len(s)][3] = 1\ndp[len(s)][0] = 0\ndp[len(s)][1] = 0\ndp[len(s)][2] = 0\nabc = ["A","B","C"]\nfor i in range(len(s)-1,-1,-1):\n m = 1\n if s[i] == "?":\n m=3\n dp[i][3] += m * dp[i+1][3]\n\nfor i in range(len(s)-1,-1,-1):\n for j in range(0,3):\n m1,m2 = 1,0\n if s[i] == "?":\n m1,m2 = 3,1\n if s[i] == abc[j]:\n m1,m2 = 1,1\n dp[i][j] += m1 * dp[i+1][j] + m2 * dp[i+1][j+1]\n dp[i][j] %= (10**9 + 7)\nfor i in range(len(s),-1,-1):\n print(dp[i])\nprint(dp[0][0] % (10**9 + 7))\n', 's = input()\ndp = [0 for _ in range(0,4)]\ndp[3] = 1\ndp[0] = 0\ndp[1] = 0\ndp[2] = 0\nabc = "ABC".index\nmod = 10**9 + 7\nfor i in range(len(s)-1,-1,-1):\n if s[i] == "?":\n dp = [\n (dp[0]*3+ dp[1])%mod\n ,(dp[1]*3+ dp[2])%mod\n ,(dp[2]*3 + dp[3])%mod\n ,(dp[3]*3)%mod\n ]\n else:\n num = abc(s[i])\n dp[i][num] += dp[i+1][num+1] % mod\n\n# print(dp[i])\nprint(dp[0][0] %mod)\n', 's = input()\ndp = [0 for _ in range(0,4)]\ndp[3] = 1\ndp[0] = 0\ndp[1] = 0\ndp[2] = 0\nabc = "ABC".index\nmod = 10**9 + 7\nfor i in range(len(s)-1,-1,-1):\n if s[i] == "?":\n dp = [\n (dp[0]*3+ dp[1])%mod\n ,(dp[1]*3+ dp[2])%mod\n ,(dp[2]*3 + dp[3])%mod\n ,(dp[3]*3)%mod\n ]\n else:\n num = abc(s[i])\n dp[num] += dp[num+1] % mod\nprint(dp[0] %mod)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s342999738', 's808633167', 's575681323']
[1068580.0, 3188.0, 3188.0]
[2170.0, 110.0, 107.0]
[610, 454, 392]
p03291
u807772568
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['a = list(input())\n\ndp = [[0]*3 for i in range(len(a)+1)]\n\nppp ~ 1\nfor i in range(len(a))[::-1]:\n\tif a[i] == "A":\n\t\tdp[i][0] += dp[i+1][0] + dp[i+1][1]\n\t\tdp[i][1] += dp[i+1][1]\n\t\tdp[i][2] += dp[i+1][2]\n\telif a[i] == "B":\n\t\tdp[i][0] += dp[i+1][0]\n\t\tdp[i][1] += dp[i+1][1] + dp[i+1][2]\n\t\tdp[i][2] += dp[i+1][2]\n\telif a[i] == "C":\n\t\tdp[i][0] += dp[i+1][0]\n\t\tdp[i][1] += dp[i+1][1]\n\t\tdp[i][2] += dp[i+1][2] + ppp\n\telse:\n\t\tdp[i][0] += 3 * dp[i+1][0] + dp[i+1][1]\n\t\tdp[i][1] += 3 * dp[i+1][1] + dp[i+1][2]\n\t\tdp[i][2] += 3 * dp[i+1][2] + ppp\n\t\tppp *= 3\n\t\tppp %= 10**9+7\n\tfor j in range(3):\n\t\tdp[i][j] %= (10**9 + 7)\nprint(dp[0][0] % (10**9 + 7))', 'a = list(input())\nsu = 0\n\ndp = [[0]*4 for i in range(len(a)+1)]\n\n\nfor i in range(len(a))[::-1]:\n\tif a[i] == "A":\n\t\tdp[i-1][0] += dp[i][0] + dp[i][1]\n\telif a[i] == "B":\n\t\tdp[i-1][1] += dp[i][1] + dp[i][2]\n\telif a[i] == "C":\n\t\tdp[i-1][2] += dp[i][2] + 1\n\telse:\n\t\tdp[i-1][0] += 3 * dp[i][0] + dp[i][1]\n\t\tdp[i-1][1] += 3 * dp[i][1] + dp[i][2]\n\t\tdp[i-1][2] += 3 * dp[i][2] + 1\n\tfor j in range(3):\n\t\tdp[i-1][j] %= 1000000007\nprint(dp[0][0] % 1000000007)\n', 'a = list(input())\nsu = 0\n\ndp = [[0]*4 for i in range(len(a)+1)]\n\n\nfor i in range(len(a))[::-1]:\n\tif a[i] == "A":\n\t\tdp[i-1][0] += dp[i][0] + dp[i][1]\n\telif a[i] == "B":\n\t\tdp[i-1][1] += dp[i][1] + dp[i][2]\n\telif a[i-1] == "C":\n\t\tdp[i-1][2] += dp[i][2] + 1\n\telse:\n\t\tdp[i-1][0] += 3 * dp[i][0] + dp[i][1]\n\t\tdp[i-1][1] += 3 * dp[i][1] + dp[i][2]\n\t\tdp[i-1][2] += 3 * dp[i][2] + 1\n\tfor j in range(3):\n\t\tdp[i-1][j] %= 1000000007\nprint(dp[0][0] % 1000000007)', 'a = list(input())\n\ndp = [[0]*3 for i in range(len(a)+1)]\n\nppp = 1\nfor i in range(len(a))[::-1]:\n\tif a[i] == "A":\n\t\tdp[i][0] += dp[i+1][0] + dp[i+1][1]\n\t\tdp[i][1] += dp[i+1][1]\n\t\tdp[i][2] += dp[i+1][2]\n\telif a[i] == "B":\n\t\tdp[i][0] += dp[i+1][0]\n\t\tdp[i][1] += dp[i+1][1] + dp[i+1][2]\n\t\tdp[i][2] += dp[i+1][2]\n\telif a[i] == "C":\n\t\tdp[i][0] += dp[i+1][0]\n\t\tdp[i][1] += dp[i+1][1]\n\t\tdp[i][2] += dp[i+1][2] + ppp\n\telse:\n\t\tdp[i][0] += 3 * dp[i+1][0] + dp[i+1][1]\n\t\tdp[i][1] += 3 * dp[i+1][1] + dp[i+1][2]\n\t\tdp[i][2] += 3 * dp[i+1][2] + ppp\n\t\tppp *= 3\n\t\tppp %= 10**9+7\n\tfor j in range(3):\n\t\tdp[i][j] %= (10**9 + 7)\nprint(dp[0][0] % (10**9 + 7))']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s042404060', 's197466155', 's524356780', 's617558070']
[2940.0, 25124.0, 25128.0, 23572.0]
[17.0, 282.0, 286.0, 293.0]
[637, 448, 449, 637]
p03291
u816116805
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["S=input()\n\nemp=1\nA=0\nAB=0\nABC=0\n\nbig = 10**9+7\n\n\n\nfor a in S:\n if a == 'A':\n (emp,A,AB,ABC)=(emp,emp+A,AB,ABC)\n if a == 'B':\n (emp,A,AB,ABC)=(emp,A,A+AB,ABC)\n if a == 'C':\n (emp,A,AB,ABC)=(emp,A,AB,AB + ABC)\n if a == '?':\n (emp,A,AB,ABC)=(3*emp%big, (emp+ 3*A) %big, (A+ 3*AB)%big,(AB + 3*ABC)%big)\n print(emp,A,AB,ABC)\n\nprint(ABC%big)\n", "S=input()\n\nemp=1\nA=0\nAB=0\nABC=0\n\nbig = 10**9+7\n\n\n\nfor a in S:\n if a == 'A':\n (emp,A,AB,ABC)=(emp,emp+A,AB,ABC)\n if a == 'B':\n (emp,A,AB,ABC)=(emp,A,A+AB,ABC)\n if a == 'C':\n (emp,A,AB,ABC)=(emp,A,AB,AB + ABC)\n if a == '?':\n (emp,A,AB,ABC)=(3*emp%big, (emp+ 3*A) %big, (A+ 3*AB)%big,(AB + 3*ABC)%big)\n\nprint(ABC%big)\n"]
['Wrong Answer', 'Accepted']
['s726533233', 's275901087']
[7372.0, 3188.0]
[318.0, 105.0]
[379, 355]
p03291
u833070958
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['inf = 1000000007\n\na = 0\nab = 0\nabc = 0\nr = 1\n \ns = input()\n \nfor c in s:\n if c == "A":\n a += r\n elif c == "B":\n ab += a\n elif c == "C":\n abc += ab\n else:\n abc = abc * 3 + ab\n ab = ab * 3 + a\n a = a * 3 + r\n r *= 3\n \n\ta %= inf\n\tab %= inf\n abc %= inf\n r %= inf\n\nprint(abc)', "\n#include <algorithm>\nusing namespace std;\n\ntypedef long long llint;\nllint inf = 1000000007;\n\nllint a = 0;\nllint b = 0;\nllint c = 0;\nllint r = 1;\n\nstring s;\n\nint main() {\n cin >> s;\n for (int i = 0; i < s.length(); i++) {\n switch (s[i]) {\n case 'A':\n a = (a + r) % inf;\n break;\n case 'B':\n b = (b + a) % inf;\n break;\n case 'C':\n c = (c + b) % inf;\n break;\n default:\n c = (c * 3 + b) % inf;\n b = (b * 3 + a) % inf;\n a = (a * 3 + r) % inf;\n r = (r * 3) % inf;\n }\n }\n cout << c << endl;\n return 0;\n}", 'inf = 1000000007\n \na = 0\nab = 0\nabc = 0\nr = 1\n \ns = input()\n \nfor c in s:\n if c == "A":\n a += r\n elif c == "B":\n ab += a\n elif c == "C":\n abc += ab\n else:\n abc = abc * 3 + ab\n ab = ab * 3 + a\n a = a * 3 + r\n r *= 3\n \n a %= inf\n ab %= inf\n abc %= inf\n r %= inf\n\nprint(abc)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s831835185', 's915926085', 's355538686']
[2940.0, 2940.0, 3188.0]
[18.0, 18.0, 118.0]
[337, 682, 351]
p03291
u834415466
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s=input()\nl=len(s)\na=[[0,0,0] for i in range(l)]\nnum=1\nfor i in range(l):\n if s[i]=='A':\n a[i][0]=a[i-1][0]+1*num\n a[i][1]=a[i-1][1]\n a[i][2]=a[i-1][2]\n if s[i]=='B':\n a[i][0]=a[i-1][0]\n a[i][1]=a[i-1][1]+a[i-1][0]\n a[i][2]=a[i-1][2]\n if s[i]=='C':\n a[i][0]=a[i-1][0]\n a[i][1]=a[i-1][1]\n a[i][2]=a[i-1][2]+a[i-1][1]\n if s[i]=='?':\n \n a[i][0]=a[i-1][0]*3+1*num\n a[i][1]=a[i-1][1]*3+a[i-1][0]\n a[i][2]=a[i-1][2]*3+a[i-1][1]\n \n num=(num*3)%1000000007\n\n\n a[i][0]=a[i][0]%1000000007\n a[i][1]=a[i][1]%1000000007\n a[i][2]=a[i][2]%1000000007\nprint(a)\n", "s=input()\nl=len(s)\na=[[0,0,0] for i in range(l)]\nnum=1\nfor i in range(l):\n if s[i]=='A':\n a[i][0]=a[i-1][0]+1*num\n a[i][1]=a[i-1][1]\n a[i][2]=a[i-1][2]\n elif s[i]=='B':\n a[i][0]=a[i-1][0]\n a[i][1]=a[i-1][1]+a[i-1][0]\n a[i][2]=a[i-1][2]\n elif s[i]=='C':\n a[i][0]=a[i-1][0]\n a[i][1]=a[i-1][1]\n a[i][2]=a[i-1][2]+a[i-1][1]\n elif s[i]=='?':\n \n a[i][0]=a[i-1][0]*3+1*num\n a[i][1]=a[i-1][1]*3+a[i-1][0]\n a[i][2]=a[i-1][2]*3+a[i-1][1]\n \n num=(num*3)%1000000007\n\n\n a[i][0]=a[i][0]%1000000007\n a[i][1]=a[i][1]%1000000007\n a[i][2]=a[i][2]%1000000007\nprint(a[-1][2])"]
['Wrong Answer', 'Accepted']
['s943481453', 's998214126']
[32968.0, 22860.0]
[305.0, 247.0]
[669, 681]
p03291
u875361824
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['def main():\n \n S = input()\n ans3 = cumsum(S)\n\n print(ans3)\n \n\ndef cumsum(S):\n \n n = len(S)\n q = [0 for _ in range(n+1)]\n abc = [[0] * 3 for _ in range(n+1)]\n for i in range(n):\n is_q = S[i] == "?"\n q[i+1] += q[i] + int(is_q)\n\n # for j, c in enumerate("ABC"):\n # add = int(is_q or S[i] == c)\n for j, c in enumerate("ABC"):\n if c == "B":\n add = int(is_q or S[i] == c)\n else:\n add = int(S[i] == c)\n abc[i+1][j] += abc[i][j] + add\n\n ans = 0\n MOD = 10 ** 9 + 7\n for i in range(1, n-1):\n a = abc[i][0]\n b = abc[i+1][1] - abc[i][1]\n c = abc[n][2] - abc[i+1][2]\n l = q[i]\n r = q[n] - q[i+1]\n\n \n # ans += a * b * c\n\n \n \n \n \n ac = a * b * c * (3 ** (l + r))\n aq = a * b * r * (3 ** (l + r - 1))\n qc = l * b * c * (3 ** (l + r - 1))\n qq = l * b * r * (3 ** (l + r - 2))\n ans += ac + aq + qc + qq\n ans %= MOD\n\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n', 'def main():\n \n S = input()\n ans3 = cumsum(S)\n print(ans3)\n\n\ndef cumsum(S):\n \n n = len(S)\n aa = [0 for _ in range(n+1)]\n cc = [0 for _ in range(n+1)]\n q = [0 for _ in range(n+1)]\n for i in range(n):\n aa[i+1] += aa[i] + int(S[i] == "A")\n cc[i+1] += cc[i] + int(S[i] == "C")\n q[i+1] += q[i] + int(S[i] == "?")\n\n ans = 0\n MOD = 10 ** 9 + 7\n for i in range(1, n-1):\n a = aa[i]\n c = cc[n] - cc[i+1]\n l = q[i]\n r = q[n] - q[i+1]\n \n \n \n \n if S[i] in ("B", "?"):\n ac = a * c * pow(3, l + r, MOD)\n aq, qc, qq = (0, 0, 0)\n if l + r - 1:\n p = pow(3, l + r - 1, MOD)\n aq = a * r * p\n qc = l * c * p\n if l + r - 1:\n qq = l * r * pow(3, l + r - 2, MOD)\n \n \n \n ans += ac + aq + qc + qq\n ans %= MOD\n\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n', 'def main():\n \n S = input()\n ans3 = cumsum(S)\n\n print(ans3)\n\ndef cumsum(S):\n \n n = len(S)\n q = [0 for _ in range(n+1)]\n abc = [[0] * 3 for _ in range(n+1)]\n for i in range(n):\n is_q = S[i] == "?"\n q[i+1] += q[i] + int(is_q)\n\n # for j, c in enumerate("ABC"):\n # add = int(is_q or S[i] == c)\n for j, c in enumerate("ABC"):\n if c == "B":\n add = int(is_q or S[i] == c)\n else:\n add = int(S[i] == c)\n abc[i+1][j] += abc[i][j] + add\n\n ans = 0\n MOD = 10 ** 9 + 7\n for i in range(1, n-1):\n a = abc[i][0]\n b = abc[i+1][1] - abc[i][1]\n c = abc[n][2] - abc[i+1][2]\n l = q[i]\n r = q[n] - q[i+1]\n\n \n # ans += a * b * c\n\n \n \n \n \n ac = a * b * c * (3 ** (l + r))\n aq = a * b * r * (3 ** (l + r - 1))\n qc = l * b * c * (3 ** (l + r - 1))\n qq = l * b * r * (3 ** (l + r - 2))\n ans += ac + aq + qc + qq\n ans %= MOD\n\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n', 'def main():\n \n S = input()\n ans3 = cumsum(S)\n print(ans3)\n\n\ndef cumsum(S):\n \n n = len(S)\n aa = [0 for _ in range(n+1)]\n cc = [0 for _ in range(n+1)]\n q = [0 for _ in range(n+1)]\n for i in range(n):\n aa[i+1] += aa[i] + int(S[i] == "A")\n cc[i+1] += cc[i] + int(S[i] == "C")\n q[i+1] += q[i] + int(S[i] == "?")\n\n ans = 0\n MOD = 10 ** 9 + 7\n for i in range(1, n-1):\n a = aa[i]\n c = cc[n] - cc[i+1]\n l = q[i]\n r = q[n] - q[i+1]\n \n \n \n \n if S[i] in ("B", "?"):\n ac = a * c * pow(3, l + r, MOD)\n aq, qc, qq = (0, 0, 0)\n if l + r - 1 >= 0:\n p = pow(3, l + r - 1, MOD)\n aq = a * r * p\n qc = l * c * p\n if l + r - 2 >= 0:\n qq = l * r * pow(3, l + r - 2, MOD)\n \n \n \n ans += ac + aq + qc + qq\n ans %= MOD\n\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s100158268', 's378404548', 's959852155', 's929935572']
[26748.0, 17012.0, 26740.0, 15000.0]
[2109.0, 801.0, 2109.0, 796.0]
[1895, 1989, 1890, 1999]
p03291
u886747123
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
['S = input()\nN = len(S)\nMOD = 10**9 + 7\n\ndef find_cumsum(X):\n output = [1] if S[0] == X else [0] \n for idx in range(1,N):\n if S[idx] == X:\n output.append(output[-1]+1)\n else:\n output.append(output[-1])\n return output\n\nq_count = S.count("?")\nA_cumsum = find_cumsum("A")\nq_cumsum = find_cumsum("?")\n \n\nlast_b = [[0] for _ in range(3)]\nfor idx in range(1,N):\n if S[idx] == "B":\n last_b[0].append(A_cumsum[idx-1]) # AB\n last_b[1].append(q_cumsum[idx-1]) # ?B\n last_b[2].append(0)\n elif S[idx] == "?":\n last_b[0].append(0)\n last_b[1].append(A_cumsum[idx-1]) # A?\n last_b[2].append(q_cumsum[idx-1]) # ??\n else:\n for i in [0,1,2]:\n last_b[i].append(0)\n\nlast_b_cumsum = [[last_b[0][0]], [last_b[1][0]], [last_b[2][0]]]\nfor i in range(3):\n for idx in range(1,N):\n last_b_cumsum[i].append((last_b[i][idx] + last_b_cumsum[i][-1]) % MOD)', '# D - We Love ABC\n\nS = list(input())\nMOD = 10**9 + 7\n\nn_possible = 1 \nA = 0 \nB = 0\nC = 0\n\nfor s in S:\n if s == "A":\n A += n_possible\n elif s == "B":\n B += A\n elif s == "C":\n C += B\n else:\n # X = 3*X + Y\n \n C = 3*C + B\n B = 3*B + A\n A = 3*A + n_possible\n n_possible *= 3\n n_possible %= MOD\n A %= MOD\n B %= MOD\n C %= MOD\n \nprint(C)']
['Wrong Answer', 'Accepted']
['s352783266', 's307688499']
[20952.0, 3956.0]
[243.0, 119.0]
[1098, 644]
p03291
u906428167
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["s = input()\nls = len(s)\n\ndp = [[0]*4 for _ in range(ls+1)]\n\ndp[0][0] = 1\n\nfor i in range(ls):\n if s[i] == 'A':\n for j in range(4):\n dp[i+1][j] += dp[i][j]\n dp[i+1][1] += dp[i][0]\n elif s[i] == 'B':\n for j in range(4):\n dp[i+1][j] += dp[i][j]\n dp[i+1][2] += dp[i][1]\n elif s[i] == 'C':\n for j in range(4):\n dp[i+1][j] += dp[i][j]\n dp[i+1][3] += dp[i][2]\n else:\n for j in range(4):\n dp[i+1][j] += dp[i][j]*3\n\nprint(dp[ls][3])\n\n \n ", "s = input()\nls = len(s)\nmod = 10**9+7\n\ndp = [[0]*5 for _ in range(ls+1)]\n\ndp[0][0] = 1\n\nfor i in range(ls):\n if s[i] == 'A':\n for j in range(4):\n dp[i+1][j] += dp[i][j] % mod\n dp[i+1][1] += dp[i][0] % mod\n elif s[i] == 'B':\n for j in range(4):\n dp[i+1][j] += dp[i][j] % mod\n dp[i+1][2] += dp[i][1] % mod\n elif s[i] == 'C':\n for j in range(4):\n dp[i+1][j] += dp[i][j] % mod\n dp[i+1][3] += dp[i][2] % mod\n else:\n for j in range(4):\n dp[i+1][j] += dp[i][j]*3 % mod\n dp[i+1][j+1] += dp[i][j]\n\nprint(dp[ls][3] % mod)\n\n \n "]
['Wrong Answer', 'Accepted']
['s221830739', 's357961653']
[1554804.0, 32440.0]
[1956.0, 405.0]
[543, 642]
p03291
u941407962
2,000
1,048,576
The _ABC number_ of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: * 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) * T_i = `A` (T_i is the i-th character of T from the beginning.) * T_j = `B` * T_k = `C` For example, when T = `ABCBC`, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3. You are given a string S. Each character of S is `A`, `B`, `C` or `?`. Let Q be the number of occurrences of `?` in S. We can make 3^Q strings by replacing each occurrence of `?` in S with `A`, `B` or `C`. Find the sum of the ABC numbers of all these strings. This sum can be extremely large, so print the sum modulo 10^9 + 7.
["string = '????C?????B??????A???????'\n#string = 'A??C'\nac = 0\nbc = 0\ncc = 0\nac2 = 0\nbc2 = 0\nbc3 = 0\nbc4 = 0\ncc2 = 0\ncc3 = 0\ncc4 = 0\ncc5 = 0\ncc6 = 0\ncc7 = 0\ncc8 = 0\nfor s in string:\n if s == 'A':\n ac += 1\n elif s == 'B':\n bc += ac\n bc2 += ac2\n elif s == 'C':\n cc += bc\n cc2 += bc2\n cc3 += bc3\n cc4 += bc4\n elif s == '?':\n cc5 += bc2\n cc6 += bc3\n cc7 += bc4\n cc8 += bc\n\n bc3 += ac\n bc4 += ac2\n\n ac2 += 1\n\n#print(cc)\n#print(cc3)\nresult = (cc7) + ((cc4+cc5+cc6) * 3) + ((cc2+cc3+cc8)*9) + (cc*27)\n#print(ac2)\nresult *= pow(3, ac2-3)\nprint(result%(pow(10,9)+7))", "string = input().strip()\nac = 0\nbc = 0\ncc = 0\nac2 = 0\nbc2 = 0\nbc3 = 0\nbc4 = 0\ncc2 = 0\ncc3 = 0\ncc4 = 0\ncc5 = 0\ncc6 = 0\ncc7 = 0\ncc8 = 0\nfor s in string:\n if s == 'A':\n ac += 1\n elif s == 'B':\n bc += ac\n bc2 += ac2\n elif s == 'C':\n cc += bc\n cc2 += bc2\n cc3 += bc3\n cc4 += bc4\n elif s == '?':\n cc5 += bc2\n cc6 += bc3\n cc7 += bc4\n cc8 += bc\n\n bc3 += ac\n bc4 += ac2\n\n ac2 += 1\n\n#print(cc)\n#print(cc3)\nresult = (cc7) + ((cc4+cc5+cc6) * 3) + ((cc2+cc3+cc8)*9) + (cc*27)\n#print(ac2)\nresult *= pow(3, ac2-3)\nprint(int(result%(pow(10,9)+7)))\n"]
['Wrong Answer', 'Accepted']
['s187367052', 's870753872']
[3064.0, 3188.0]
[18.0, 78.0]
[665, 642]
p03292
u004025573
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c=map(int,input().split())\n\nprint(abs(a-b)+abs(b-c))', 'a,b,c=map(int,input().split())\n\nans=[a,b,c]\nans.sort()\n\nprint(abs(ans(0)-ans(1))+abs(ans(1)-ans(2)))', '\na,b,c=map(int,input().split())\n\nans=[a,b,c]\nans.sort()\n\nprint(abs(ans[0]-ans[1])+abs(ans[1]-ans[2]))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s425854347', 's446951364', 's167498164']
[3064.0, 2940.0, 2940.0]
[20.0, 19.0, 17.0]
[56, 100, 101]
p03292
u020604402
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['L = list(map(int,input().split()))\nL = sorted(L)\nans += L[2]-L[1]\nans += L[1]-L[0]\nprint(ans)', 'L = list(map(int,input().split()))\nL = sorted(L)\nans = 0\nans += L[2]-L[1]\nans += L[1]-L[0]\nprint(ans)']
['Runtime Error', 'Accepted']
['s427694949', 's866883796']
[2940.0, 2940.0]
[18.0, 18.0]
[93, 101]
p03292
u023229441
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c=map(int(input().split())\nA=[a,b,c]\nA.sort()\nprint(abs(A[0]-A[1])+abs(A[1]-A[2]))\n\n \n', 'a,b,c=map(int(input().split())\nA=[a,b,c]\nsorted(A)\nprint(abs(A[0]-A[1])+abs(A[1]-A[2]))\n\n ', 'a,b,c=map(int,input().split())\nA=[a,b,c]\nsorted(A)\nprint(abs(A[0]-A[1])+abs(A[1]-A[2]))', 'import itertools\nA=list(map(int,input().split()))\nans=6373532642\nfor l in itertools.permutations(A):\n ans=min(ans,abs(l[0]-l[1])+abs(l[1]-l[2]))\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s438492641', 's519504041', 's932011176', 's834561018']
[2940.0, 2940.0, 2940.0, 3060.0]
[17.0, 17.0, 17.0, 17.0]
[99, 99, 87, 156]
p03292
u029000441
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['import math\nimport collections\nimport sys\n\n#input = sys.stdin.readline\ndef I(): return int(input())\ndef MI(): return map(int, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI2(): return [int(input()) for i in range(n)]\ndef MXI(): return [[LI()]for i in range(n)]\n\nAS=LI()\nAS=sorted(AS)\nans=AS[2]-AS[1]+AS[1]-AS[0]\nprint(AS)', 'import math\nimport collections\nimport sys\n \n#input = sys.stdin.readline\ndef I(): return int(input())\ndef MI(): return map(int, input().split())\ndef LI(): return list(map(int, input().split()))\ndef LI2(): return [int(input()) for i in range(n)]\ndef MXI(): return [[LI()]for i in range(n)]\n \nAS=LI()\nAS=sorted(AS)\nans=AS[2]-AS[0]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s841542273', 's907460397']
[3316.0, 3316.0]
[21.0, 21.0]
[347, 338]
p03292
u037221289
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['list_task = list(map(int, input().split()))\nN = len(list_task)\n\nlist_task.reverse()\n\ntotal_cost = 0\nlast_number = list_task[0]\nlist_task.pop(0)\nfor i in list_task:\n total_cost += last_number - i\n last_number = i \nprint(total_cost)\n\n', 'list_task = list(map(int, input().split()))\nN = len(list_task)\n\nlist_task.sort()\nlist_task.reverse()\n\n\ntotal_cost = 0\nlast_number = list_task[0]\nlist_task.pop(0)\nfor i in list_task:\n total_cost += abs(last_number - i)\n last_number = i \nprint(total_cost)\n\n']
['Wrong Answer', 'Accepted']
['s548624544', 's455267255']
[2940.0, 2940.0]
[20.0, 17.0]
[387, 410]
p03292
u039192119
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['*a=map(int,input().split())\nprint(max(a)-min(a))', '*a,=map(int,input().split())\nprint(max(a)-min(a))']
['Runtime Error', 'Accepted']
['s168894769', 's276748980']
[2940.0, 2940.0]
[17.0, 17.0]
[48, 49]
p03292
u047197186
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a1, a2, a3 = map(int, input().split())\nlst = sorted([a1, a2, a3])\nprint(abs(a2 - a1) + abs(a3 - a2))', 'a1, a2, a3 = map(int, input().split())\nelem1 = abs(a2 - a1) + abs(a3 - a2) \nelem2 = abs(a3 - a1) + abs(a2 - a3)\nelem3 = abs(a1 - a2) + abs(a3 - a1)\nelem4 = abs(a3 - a2) + abs(a1 - a3)\nelem5 = abs(a1 - a3) + abs(a2 - a1)\nelem6 = abs(a2 - a3) + abs(a1 - a2)\nlst = [elem1, elem2, elem3, elem4, elem5, elem6]\n\nprint(min(lst))']
['Wrong Answer', 'Accepted']
['s025513184', 's757790867']
[2940.0, 3064.0]
[17.0, 17.0]
[100, 321]
p03292
u050698451
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = list(map(int, input().split()))\nN = len(A)\nA = A.sort()\nsum = 0\n\nfor i in range(1,N):\n\tsum += A[i]-A[i-1]\nprint(sum)', 'a, b, c = map(int, input().split())\nA = []\nA.append(a)\nA.append(b)\nA.append(c)\nA = A.sort()\nsum = 0\nfor i in range(4):\n\tsum += int(A[i]) - int(A[i-1])\nprint(sum)', 'from sys import stdin\nA = [int(x) for x in stdin.readline().rstrip().split()]\n\nprint(max(A)-min(A))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s029191568', 's430362382', 's277587293']
[2940.0, 3060.0, 2940.0]
[18.0, 17.0, 20.0]
[120, 161, 100]
p03292
u052332717
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['li = list(input().split())\nli.sort()\n\nprint(li[2]-li[0])', 'li = list(map(int,input().split()))\nli.sort()\n\nprint(li[2]-li[0])']
['Runtime Error', 'Accepted']
['s719813953', 's376818954']
[2940.0, 2940.0]
[18.0, 17.0]
[56, 65]
p03292
u059262067
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a, b, c = (int(_) for _ in input().split()) \nprint(abs(a - b)+abs(b - c))\n\n\n\n', 'a = list(int(i) for i in input().split()) \na = sorted(a)\n\nprint(abs(a[0] - a[1]) + abs(a[1] - a[2]))\n\n\n\n']
['Wrong Answer', 'Accepted']
['s488785727', 's109001816']
[2940.0, 3060.0]
[17.0, 48.0]
[78, 105]
p03292
u059628848
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
["input()\na=list(map(int,input().split(' ')))\nsum=0\nfor i in a:\n sum+=i-1\nprint(sum)\n", "a=list(map(int,input().split(' ')))\nif a[0] < a[1]:\n if a[1] > a[2]:\n if a[0] < a[2]:\n temp = a[1]\n a[1] = a[2]\n a[2] = temp\n else:\n temp = a[0]\n a[0] = a[2]\n a[2] = a[1]\n a[1] = temp\n \nelse:\n if a[1] < a[2]:\n if a[0] < a[2]:\n temp = a[0]\n a[0] = a[1]\n a[1] = temp\n else:\n temp = a[0]\n a[0] = a[1]\n a[1] = a[2]\n a[2] = temp\n else:\n temp = a[0]\n a[0] = a[2]\n a[2] = temp\nprint(a[2]-a[0])"]
['Runtime Error', 'Accepted']
['s353490655', 's472575014']
[2940.0, 3064.0]
[17.0, 17.0]
[86, 601]
p03292
u063346608
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A1,A2,A3 = map(int,input().split())\n\nx = abs(A1 - A2)\ny = abs(A2 - A3)\nz = abs(A3 - A1)\n\nif x + y <= y + z and x <= z + x:\n\tprint(x + y )\nelif y + z <= x + y and y + Z <= z + x:\n\tprint(y + z )\nelse:\n\tprint(z + x)', 'A1,A2,A3 = map(int,input().split())\n \nx = abs(A1 - A2)\ny = abs(A2 - A3)\nz = abs(A3 - A1)\n \nif x + y <= y + z and x + y <= z + x:\n\tprint(x + y )\nelif y + z <= x + y and y + z <= z + x:\n\tprint(y + z )\nelse:\n\tprint(z + x)']
['Runtime Error', 'Accepted']
['s939977241', 's880383036']
[3060.0, 3064.0]
[18.0, 17.0]
[213, 219]
p03292
u064563749
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['1,A2,A3=map(int,input().split())\nA=[A1,A2,A3]\nA.append(A1)\ndef A_(i):\n if A[i]-A[i+1]>=0:\n return A[i]-A[i+1]\n else:\n return A[i+1]-A[i]\nB=[A_(i) for i in range(3)]\nB.append(A_(0))\nB.append(A_(1))\ndef sum(j):\n return B[j]+B[j+1]\nC=[sum(j) for j in range(3)]\nprint(min(C))\n', 'A1,A2,A3=map(int,input().split())\nA_1=abs(A1-A2)+abs(A2-A3)\nA_2=abs(A1-A3)+abs(A2-A3)\nA_3=abs(A1-A2)+abs(A1-A3)\nprint(min(A_1,A_2,A_3))']
['Runtime Error', 'Accepted']
['s010057394', 's778732723']
[3064.0, 2940.0]
[17.0, 17.0]
[295, 135]
p03292
u069533671
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['def main():\n cost_list = input().split()\n for i in range(len(cost_list)):\n cost_list[i] = int(cost_list[i])\n cost_list.sort()\n cost_list.reverse()\n counter = 0\n for i in range(len(cost_list) - 1):\n counter += cost_list[i+1] - cost_list[i]\n print(counter)\n\nmain()', 'def main():\n n = [int(i) for i in input().split()]\n bridge = [0 for i in range(n[0]-1)]\n reqs = [[int(j) for j in input().split()] for i in range(n[1])]\n reqs.sort(key=lambda x:(x[1]-x[0]))\n\n for req in reqs:\n if 1 not in bridge[req[0]-1:req[1]-1]:\n bridge[req[1] - 2] = 1\n print(bridge.count(1))\n\nmain()', 'def main():\n cost_list = input().split()\n for i in range(len(cost_list)):\n cost_list[i] = int(cost_list[i])\n cost_list.sort()\n print(cost_list)\n counter = 0\n for i in range(len(cost_list) - 1):\n counter += cost_list[i+1] - cost_list[i]\n print(counter)\n\nmain()', 'def main():\n cost_list = input().split()\n for i in range(len(cost_list)):\n cost_list[i] = int(cost_list[i])\n cost_list.sort()\n counter = 0\n for i in range(len(cost_list) - 1):\n counter += cost_list[i+1] - cost_list[i]\n print(counter)\n\nmain()']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s085102906', 's085195443', 's171150216', 's326438601']
[3060.0, 3064.0, 3060.0, 3060.0]
[17.0, 19.0, 17.0, 17.0]
[297, 340, 294, 273]
p03292
u069925317
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['moji_S=input()\nmoji_T=input()\n\nflag=0\nfor i in range(len(moji_S)):\n\tif moji_S==moji_T:\n\t\tflag =1\n\t\tbreak\n\tmoji_S=moji_S[-1]+moji_S[0:-1]\nif flag:\n\tprint("Yes")\nelse:\n\tprint("No")\n', "A=list(map(int,input().split(' ')))\nA.sort()\ncost=A[1]-A[0]\ncost+=A[2]-A[1]\nprint(cost)"]
['Runtime Error', 'Accepted']
['s415475432', 's668690774']
[2940.0, 2940.0]
[17.0, 17.0]
[179, 87]
p03292
u072717685
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A, B, C = map(int, input().split())\n\nr = abs(a-b) + abs(a-c) + abs(b-c)\nr = r - max(abs(a-b) , abs(a-c) , abs(b-c))\nprint(int(r))', 'a, b, c = map(int, input().split())\n \nr = abs(a-b) + abs(a-c) + abs(b-c)\nr = r - max(abs(a-b) , abs(a-c) , abs(b-c))\nprint(int(r))']
['Runtime Error', 'Accepted']
['s952231056', 's941292231']
[2940.0, 2940.0]
[17.0, 17.0]
[129, 130]
p03292
u073729602
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['import itertools\na1, a2, a3 = map(int, input().split())\nans = 10 ** 9\nfor v in itertools.permutations([a1, a2, a3]):\n d = 0\n for i in range(1, 3):\n d += abs(v[i]-v[i-1])\n ans = min(ans, d)\n print(v, d)\n\nprint(ans)\n', 'import itertools\na1, a2, a3 = map(int, input().split())\nans = 10 ** 9\nfor v in itertools.permutations([a1, a2, a3]):\n d = 0\n for i in range(1, 3):\n d += abs(v[i]-v[i-1])\n ans = min(ans, d)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s579046303', 's380405169']
[9108.0, 9092.0]
[27.0, 30.0]
[233, 217]
p03292
u075155299
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c = map(int,input().split())\n\ns=[abs(a-b),abs(a-c),abs(b-c)]\ns.sort()\nprint(abs(s[0]-s[1]))', 'a,b,c = map(int,input().split())\n\ns=[abs(a-b),abs(a-c),abs(b-c)]\ns.sort()\nprint(s[0]+s[1])']
['Wrong Answer', 'Accepted']
['s715165998', 's232020951']
[2940.0, 2940.0]
[17.0, 17.0]
[95, 90]
p03292
u094565093
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a=[int() for i in range(input().split())]\na.sort()\nprint(a[2]-a[0])', 'a = [int(i) for i in input().split()]\na.sort()\nprint(a[2]-a[0])']
['Runtime Error', 'Accepted']
['s843249485', 's916261176']
[2940.0, 2940.0]
[17.0, 18.0]
[67, 63]
p03292
u095426154
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['task=list(map(int,input().split(" ")))\nprint(task)\ntask.sort()\nprint(task)\ncost=0\n\nfor i in range(len(task)-1):\n cost+=task[i+1]-task[i]\nprint(cost)', 'task=list(map(int,input().split(" ")))\ntask.sort()\ncost=0\n\nfor i in range(len(task)-1):\n cost+=task[i+1]-task[i]\nprint(cost)']
['Wrong Answer', 'Accepted']
['s878622403', 's458202595']
[3064.0, 2940.0]
[18.0, 18.0]
[151, 127]
p03292
u096326554
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['S = list(input())\nT = list(input())\nS.sort()\nT.sort()\nif S == T:\n\tprint("Yes")\nelse:\n\tprint("No")', 'a_l = [int(a_v) for a_v in input().split()]\na_l.sort()\nprint(abs(a_l[0]-a_l[1])+abs(a_l[1]-a_l[2]))']
['Runtime Error', 'Accepted']
['s011079496', 's303155578']
[2940.0, 2940.0]
[17.0, 17.0]
[97, 99]
p03292
u102242691
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['\na = list(map(int,input().split()))\na.sort()\n\nprint(ans(a[3]-a[1]))\n', '\na = list(map(int,input().split()))\na.sort()\n\nprint(abs(a[2]-a[0]))\n']
['Runtime Error', 'Accepted']
['s158571426', 's520000127']
[2940.0, 2940.0]
[17.0, 17.0]
[68, 68]
p03292
u106103668
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c=map(int,input().split())\nprint(abs(a-b)+abs(b-c))', 'a=list(map(int,input().split()))\nprint(max(a)-min(a))']
['Wrong Answer', 'Accepted']
['s784148527', 's246478856']
[2940.0, 3316.0]
[17.0, 21.0]
[55, 53]
p03292
u107091170
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A,B,C=map(int, input().split())\nd = [0 0 0]\nd[0] = abs(A-B)\nd[1] = abs(A-C)\nd[2] = abs(C-B)\nd.sort()\nprint(d[0]+d[1])\n', 'A,B,C=map(int, input().split())\nd = [0,0,0]\nd[0] = abs(A-B)\nd[1] = abs(A-C)\nd[2] = abs(C-B)\nd.sort()\nprint(d[0]+d[1])\n']
['Runtime Error', 'Accepted']
['s708916545', 's895212188']
[2940.0, 3060.0]
[17.0, 17.0]
[118, 118]
p03292
u113971909
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = list(map(int,input()))\nprint(max(a)-min(a))', 'a = list(map(int,input().split()))\nprint(max(a)-min(a))']
['Runtime Error', 'Accepted']
['s323178629', 's196471423']
[2940.0, 2940.0]
[17.0, 17.0]
[47, 55]
p03292
u114366889
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = list(input())\nA.sort()\ncost =0\nfor i in range(len(A)-1):\n cost += abs(A[i]+A[i+1])\nprint(cost)', 'A = list(map(int,input().split()))\nA.sort()\nans = 0\nfor i in range(len(A)-1):\n\tans += abs(A[i]-A[i+1])\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s555531542', 's463091979']
[2940.0, 2940.0]
[18.0, 17.0]
[99, 114]
p03292
u118642796
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['N,M = map(int,input().split())\nrequests = []\nfor _ in range(M):\n a,b = map(int,input().split())\n requests.append([a,b])\n\nans = 1\nrequests = sorted(requests, key=lambda x:(x[1],x[0]))\nb = min(requests, key=lambda x:x[1])[1]\nfor i in range(M):\n if requests[i][0] < b:\n continue\n else:\n ans += 1\n b = min(requests[i:], key=lambda x:x[1])[1]\n\nprint(ans)', 'A = list(map(int,input().split()))\nB = [abs(A[0]-A[1]),abs(A[0]-A[2]),abs(A[1]-A[2])]\nB.sort()\nprint(B[0]+B[1])']
['Runtime Error', 'Accepted']
['s211086843', 's725684325']
[3064.0, 2940.0]
[19.0, 19.0]
[422, 111]
p03292
u119460590
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['N = int(input())\nprint(sum(list(map(int,input().split())))-N)', 'A = list(map(int, input().split())).sorted\nprint(A[2] - A[0])', 'A = list(map(int, input().split()).sorted\nprint(A[2] - A[0])', 'A = list(map(int, input().split()))\nA.sort()\nprint(A[2] - A[0])']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s212785495', 's672256480', 's744068575', 's756689219']
[2940.0, 2940.0, 2940.0, 2940.0]
[17.0, 18.0, 17.0, 18.0]
[61, 61, 60, 63]
p03292
u121732701
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = list(map(int, input().split()))\ncount = 1000\nnum = 0\n\n\nfor i in a:\n for j in a:\n for k in a:\n num = abs(j-i)+abs(k-j)\n if count>num:\n count = num\n\nprint(num)', 'a = list(map(int, input().split()))\ncount = 1000\nnum = 0\n\n\nfor i in a:\n for j in a:\n for k in a:\n num = abs(j-i)+abs(k-j)\n if count>num:\n count = num\n\nprint(count)', 'a,b,c = sorted(map(int,input().split()))\nprint(c-a)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s476998849', 's982366397', 's288743628']
[2940.0, 2940.0, 2940.0]
[17.0, 18.0, 17.0]
[208, 210, 51]
p03292
u122195031
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = [map(int,input().split())]\na.sort()\nprint(abs(a[0]-a[1])+abs(a[1]-a[2])', 'a = list(map(int,input().split()))\na.sort()\nprint(abs(a[0]-a[1])+abs(a[1]-a[2]))']
['Runtime Error', 'Accepted']
['s138714009', 's784384244']
[2940.0, 3060.0]
[17.0, 19.0]
[75, 80]
p03292
u127499732
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['l=list(map(int,input().split()))\nl.sort()\nprint(l[1]+abs(l[1]-l[2]))\n', 'l=list(map(int,input().split()))\nl.sort()\nprint(abs(l[0]-l[1])+abs(l[1]-l[2]))\n']
['Wrong Answer', 'Accepted']
['s816055155', 's300952661']
[2940.0, 2940.0]
[17.0, 17.0]
[69, 79]
p03292
u128740947
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a, b, c = map(int,input().split())\nA = []\nA.append(a)\nA.append(b)\nA.append(c)\nA.sort()\nprint(A)\nprint((A[1]-A[0])+(A[2]-A[1]))', 'a, b, c = map(int,input().split())\nA = []\nA.append(a)\nA.append(b)\nA.append(c)\nA.sort()\nprint((A[1]-A[0])+(A[2]-A[1]))']
['Wrong Answer', 'Accepted']
['s392025461', 's679046380']
[3060.0, 3060.0]
[18.0, 18.0]
[126, 117]
p03292
u129978636
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = list(map( int, input().split()))\nA = sorted(A)\n\nA1 = int(A[1]-A[0])\nA2 = int(A[2]-A1)\n\nprint(A1+A2)\n\n', 'A = list(map( int, input().split()))\nA = sorted(A)\n \nA1 = int(A[1]-A[0])\nA2 = int(A[2]-A[1])\n \nprint(A1 + A2)']
['Wrong Answer', 'Accepted']
['s003914587', 's511796034']
[2940.0, 2940.0]
[19.0, 18.0]
[105, 109]
p03292
u131406572
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['L=list(map(int,input().split()))\nL.sort()\na=0\nfor i in range(len(L)-1):\n a+=L[i]-L[i-1]\n #print(i)\nprint(a)', 'L=list(map(int,input().split()))\nL.sort()\na=0\nfor i in range(1,len(L)):\n a=a+(L[i]-L[i-1])\n #print(L[i]-L[i-1])\nprint(a)']
['Wrong Answer', 'Accepted']
['s699753844', 's384290533']
[2940.0, 2940.0]
[17.0, 17.0]
[113, 126]
p03292
u131625544
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = list(map(int, input().split()))\nA.sort()\n\nans = 0\nfor i in range(1,3):\n ans += a[i] - a[i-1]\nprint(ans)', 'A = list(map(int, input().split()))\nA.sort()\n\nans = 0\nfor i in range(1,3):\n ans += A[i] - A[i-1]\nprint(ans)']
['Runtime Error', 'Accepted']
['s102411477', 's406156609']
[2940.0, 2940.0]
[18.0, 17.0]
[108, 108]
p03292
u141410514
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['import itertools\na=map(int,input().split())\nans=999\nl=[0,1,2]\nfor x in itertools(l,3):\n tmp=abs(a[x[0]]-a[x[1]])+abs(a[x[1]]-a[x[2]])\n if tmp <=ans:\n ans =tmp\nprint(ans)', 'import itertools\na=list(map(int,input().split()))\nans=999\nl=[0,1,2]\nfor x in itertools.permutations(l,3):\n tmp=abs(a[x[0]]-a[x[1]])+abs(a[x[1]]-a[x[2]])\n if tmp <=ans:\n ans =tmp\nprint(ans)']
['Runtime Error', 'Accepted']
['s373303907', 's731616508']
[3060.0, 3060.0]
[18.0, 18.0]
[174, 193]
p03292
u143318682
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['# -*- coding: utf-8 -*-\nA = map(int, input().split())\nA = sorted(A)\nprint(A[1] - A[0] + A[2] - A[0])', '# -*- coding: utf-8 -*-\nA = map(int, input().split())\nA = sorted(A)\nprint(A[1] - A[0] + A[2] - A[1])']
['Wrong Answer', 'Accepted']
['s260888427', 's118997451']
[2940.0, 2940.0]
[19.0, 17.0]
[100, 100]
p03292
u145600939
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = mlist(map(int,input().split()))\na.sort()\nprint(a[2] - a[0])', 'a = list(map(int,input().split()))\na.sort()\nprint(a[2] - a[0])\n']
['Runtime Error', 'Accepted']
['s144858273', 's254557608']
[2940.0, 3064.0]
[18.0, 18.0]
[63, 63]
p03292
u146346223
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['arr = map(int, input().split())\nprint(max(arr) - min(arr))', 'arr, =map(int, input().split())\nprint(max(arr) - min(arr))', 'arr = list(map(int, input().split()))\nprint(max(arr) - min(arr))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s500989568', 's514629756', 's610536344']
[2940.0, 3060.0, 2940.0]
[17.0, 19.0, 17.0]
[58, 58, 64]
p03292
u151171672
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = [int(x) for x in input().split()]\n\na.sort(reverse=True)\n\nprint(a[2] - a[0])', 'a = [int(x) for x in input().split()]\n\na.sort(reverse=True)\n\nprint(abs(a[2] - a[1]) + abs(a[1] - a[0]))']
['Wrong Answer', 'Accepted']
['s471010518', 's210998941']
[3064.0, 2940.0]
[17.0, 18.0]
[79, 103]
p03292
u151625340
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = list(map(int,input().split()))\ns = sum(a)\nans = 1000\nfor i in range(3):\n for j in range(3):\n if i == j:\n continue\n b = abs(A[i]-A[j])+abs(A[j]-(a-(A[i]+A[j])))\n ans = min(ans,b)\nprint(ans)', 'A = list(map(int,input().split()))\ns = sum(A)\nans = 1000\nfor i in range(3):\n for j in range(3):\n if i == j:\n continue\n b = abs(A[i]-A[j])+abs(A[j]-(s-(A[i]+A[j])))\n ans = min(ans,b)\nprint(ans)']
['Runtime Error', 'Accepted']
['s809742399', 's573512820']
[3060.0, 3060.0]
[18.0, 17.0]
[227, 227]
p03292
u154979004
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['*a = map(int, input().split())\nprint(max(a) - min(a))', '*a = map(int, input().split())\nprint(max(a) - min(a))', '*a, = map(int, input().split())\nprint(max(a) - min(a))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s248693486', 's657205609', 's962332688']
[2940.0, 2940.0, 2940.0]
[17.0, 18.0, 17.0]
[53, 53, 54]
p03292
u155687575
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['lst = list(map(int, input().split()))\nsor = sorted(lst)\ncost = 0\nfor i in range(len(sor)):\n if i == 0:\n continue\n else:\n cost = abs(sor[i]-sor[i-1])\nprint(cost)', '# A\nlst = list(map(int, input().split()))\nsor = sorted(lst)\ncost = 0\nfor i in range(len(sor)):\n if i == 0:\n continue\n else:\n cost += abs(sor[i]-sor[i-1])\nprint(cost)']
['Wrong Answer', 'Accepted']
['s667939449', 's161970673']
[3060.0, 3060.0]
[17.0, 17.0]
[180, 185]
p03292
u160861278
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
["// B103.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。\n//\n\n\n#include <algorithm>\n\nusing namespace std;\n\nint main()\n{\n\tint a[3];\n\tcin >> a[2] >> a[1] >> a[0];\n\tsort(a, a + 3);\n\tcout << abs(a[0] - a[1]) + abs(a[1] - a[2]) << endl;\n\n\treturn 0;\n}\n", 'import math\nA = list(map(int, input().split()))\n\nA.sort()\nprint(abs(A[1]-A[0])+ abs(A[2]-A[1]))']
['Runtime Error', 'Accepted']
['s614369755', 's078317745']
[2940.0, 3060.0]
[17.0, 17.0]
[356, 95]
p03292
u163320134
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c=map(int,input().split())\ns=abs(a-b)+abs(b-c)+abs(c-a)\nmn=max(abs(a-b)+abs(b-c)+abs(c-a))\nprint(s-mn)', 'a,b,c=map(int,input().split())\ns=abs(a-b)+abs(b-c)+abs(c-a)\nm=max(abs(a-b),abs(b-c),abs(c-a))\nprint(s-m)']
['Runtime Error', 'Accepted']
['s384898762', 's386220029']
[3064.0, 2940.0]
[17.0, 17.0]
[106, 104]
p03292
u163449343
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a,b,c = map(int, input().split())\nprint(c-a)', 'a,b,c = sorted(map(int, input().split()))\nprint(c-a)']
['Wrong Answer', 'Accepted']
['s564050426', 's249028819']
[2940.0, 2940.0]
[17.0, 17.0]
[44, 52]
p03292
u167161639
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['from statistics import median\n\ntask=[0,0,0]\n\nfor i in range(3):\n a=input()\n task[i]=int(a)\n \nb=median(task)\nsum=0\n\nfor i in range(3):\n sum+=abs(b-task[i])\n \nsum', 'from statistics import median\n\ntask=[int(i) for i in input().split()]\n \nb=median(task)\nsum=0\n\nfor i in range(3):\n sum+=abs(b-task[i])\n \nsum', 'from statistics import median\n\ntask=[int(i) for i in input().split()]\n \nb=median(task)\nsum=0\n\nfor i in range(3):\n sum+=abs(b-task[i])\n \nprint(sum)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s181102811', 's852924670', 's942402033']
[5660.0, 5400.0, 5080.0]
[50.0, 41.0, 37.0]
[175, 148, 155]
p03292
u168416324
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['l=list(map(int,input().split()))\nl.sort(reverse=True)\nans=0\nbef=l[0]\nfor i in l:\n ans+=abs(bef-i)\nprint(ans)', 'l=list(map(int,input().split()))\nl.sort(reverse=True)\nans=0\nbef=l[0]\nfor i in l:\n ans+=abs(bef-i)\n bef=i\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s109377668', 's554472208']
[9116.0, 9116.0]
[26.0, 27.0]
[109, 118]
p03292
u170324846
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = [int(x) for x in input()split()]\nA.sort()\nprint(A[2] - A[0])', 'A = [int(x) for x in input().split()]\nA.sort()\nprint(A[2] - A[0])']
['Runtime Error', 'Accepted']
['s885230327', 's003357310']
[2940.0, 2940.0]
[18.0, 18.0]
[64, 65]
p03292
u181195295
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['*a = map(int, input().split())\n\nprint(max(a)-min(a))', '*a ,= map(int, input().split())\n\nprint(max(a)-min(a))\n']
['Runtime Error', 'Accepted']
['s748326758', 's761033690']
[2940.0, 3064.0]
[17.0, 17.0]
[52, 54]
p03292
u181949308
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['inp = [input() for _ in range(2)]\ns = inp[0]\nt = inp[1]\n\ns = list(s)\nt = list(t)\ncheck = []\nfor i in t:\n if i in s:\n s[s.index(i)] = 0\n check.append(0)\n\nif s == check:\n print("Yes")\nelse:\n print("No")', 'task = input().split()\nfor i, j in enumerate(task):\n task[i] = int(j)\ntask.sort()\nscore = int(task[2]) - int(task[0])\nprint(score)']
['Runtime Error', 'Accepted']
['s113717827', 's543595125']
[3060.0, 2940.0]
[17.0, 17.0]
[219, 134]
p03292
u183896397
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A = [ int(i) for i in input().split()]\n\nX = [ abs(A[0] - A[1]),abs(A[1] - A[2]),abs(A[0] -A[2])]\n\nX = X.sort()\nans = X[1] + X[2]\nprint(ans)', 'A1,A2,A3 =(int(i) for i in input().split())\n\nx = abs(A1-A2)\ny = abs(A2-A3)\nz = abs(A3-A1)\n\nN = [x,y,z]\nN.sort()\nans = N[0] + N[1]\nprint(ans)']
['Runtime Error', 'Accepted']
['s037137899', 's589038991']
[3060.0, 3060.0]
[17.0, 19.0]
[139, 140]
p03292
u185806788
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['ns=list(map(int,input().split()))\nns.sort()\nprint(ns[2]-ns[1])\n', 'ns=list(map(int,input().split()))\nns.sort()\nprint(ns[2]-ns[0])\n']
['Wrong Answer', 'Accepted']
['s516922483', 's407795896']
[2940.0, 2940.0]
[17.0, 18.0]
[63, 63]
p03292
u190907730
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a = list(map(int, input().split()))\na.sort\nprint(a[2]-a[0])', 'a = list(map(int, input().split()))\na.sort()\nprint(a[2]-a[0])\n']
['Wrong Answer', 'Accepted']
['s500726915', 's326228865']
[2940.0, 2940.0]
[17.0, 17.0]
[59, 62]
p03292
u195396655
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['a, b, c = map(int, input().split())\n\nif a > max(b, c):\n print(a - max(b,c))\nelif a < max(b, c):\n print(max(b, c))\n', '*a, = map(int, input().split())\nprint(max(a) - min(a))']
['Wrong Answer', 'Accepted']
['s593354782', 's506278098']
[2940.0, 2940.0]
[17.0, 17.0]
[120, 54]
p03292
u197078193
2,000
1,048,576
You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the minimum total cost required to complete all the task.
['A=[int(i) for i ininput().split()]\nA.sort()\nprint(A[2]-A[0])', 'A=[int(i) for i input().split()]\nA.sort()\nprint(A[2]-A[0])', 'A=[int(i) for i in input().split()]\nA.sort()\nprint(A[2]-A[0])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s046909148', 's095356292', 's718192140']
[2940.0, 2940.0, 2940.0]
[17.0, 17.0, 17.0]
[60, 58, 61]