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
p03222
u211160392
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
["H,W,K = map(int,input().split())\nmove= [0]*(W-1)\ncount = 0\nMOD = 10**9+7\n\nif W == 1:\n print(1)\n exit()\n\nfor i in range(2**(W-1),2**W):\n b = bin(i)[3:]\n flag = True\n for j in range(W-2):\n if b[j] == '1' and b[j+1] == '1':\n flag = False\n if flag :\n count += 1\n for j in range(W-1):\n move[j] += int(b[j])\n\nprint(move,count)\n\nDP = [[0]*W for i in range(H+1)]\nDP[0][0] = 1\nfor i in range(H):\n for j in range(W):\n if j == 0:\n DP[i+1][j] = (DP[i][j]*(count - move[0]) + DP[i][j+1]*move[0])%MOD\n elif j == W-1:\n DP[i+1][j] = (DP[i][j-1] * move[j-1] + DP[i][j]*(count - move[j-1])) % MOD\n else:\n DP[i+1][j] = (DP[i][j-1] * move[j-1] + DP[i][j]*(count - move[j] - move[j-1]) + DP[i][j+1]*move[0]) % MOD\nprint(DP[-1][K-1])", "H,W,K = map(int,input().split())\nmove= [0]*(W-1)\ncount = 0\nMOD = 10**9+7\n\nif W == 1:\n print(1)\n exit()\n\nfor i in range(2**(W-1),2**W):\n b = bin(i)[3:]\n flag = True\n for j in range(W-2):\n if b[j] == '1' and b[j+1] == '1':\n flag = False\n if flag :\n count += 1\n for j in range(W-1):\n move[j] += int(b[j])\n\nDP = [[0]*W for i in range(H+1)]\nDP[0][0] = 1\nfor i in range(H):\n for j in range(W):\n if j == 0:\n DP[i+1][j] = (DP[i][j]*(count - move[0]) + DP[i][j+1]*move[0])%MOD\n elif j == W-1:\n DP[i+1][j] = (DP[i][j-1] * move[j-1] + DP[i][j]*(count - move[j-1])) % MOD\n else:\n DP[i+1][j] = (DP[i][j-1] * move[j-1] + DP[i][j]*(count - move[j] - move[j-1]) + DP[i][j+1]*move[j]) % MOD\nprint(DP[-1][K-1])"]
['Wrong Answer', 'Accepted']
['s632681784', 's721527780']
[3064.0, 3064.0]
[19.0, 19.0]
[829, 810]
p03222
u253209284
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['def memorize(func):\n memo = {}\n def wrapper(*args):\n if args not in memo:\n memo[args] = func(*args)\n return memo[args]\n return wrapper\n\n@memorize\ndef amida(W): \n if W<2:\n return 1\n else:\n return amida(W-1)+amida(W-2)\n\n@memorize\ndef amida2(W, H, x, y=1):\n if H==0:\n return 1 if x==y else 0\n a = 0 if x==1 else amida(x-2)*amida(W-x)*amida2(W, H-1, x-1, y)\n b = amida(x-1)*amida(W-x)*amida2(W, H-1, x, y)\n c = 0 if x==W else amida(x-1)*amida(W-x-1)*amida2(W, H-1, x+1, y)\n return (a+b+c)%1000000007', 'def memorize(func):\n memo = {}\n def wrapper(*args):\n if args not in memo:\n memo[args] = func(*args)\n return memo[args]\n return wrapper\n\n@memorize\ndef amida(W): \n if W<2:\n return 1\n else:\n return amida(W-1)+amida(W-2)\n\n@memorize\ndef amida2(H, W, x):\n if H==0:\n return 1 if x==1 else 0\n a = 0 if x==1 else amida(x-2)*amida(W-x)*amida2(H-1, W, x-1)\n b = amida(x-1)*amida(W-x)*amida2(H-1, W, x, y)\n c = 0 if x==W else amida(x-1)*amida(W-x-1)*amida2(H-1, W, x+1)\n return (a+b+c)%1000000007\nprint(amida2(*map(int, input().split())))', 'def memorize(func):\n memo = {}\n def wrapper(*args):\n if args not in memo:\n memo[args] = func(*args)\n return memo[args]\n return wrapper\n\n@memorize\ndef amida(W): \n if W<2:\n return 1\n else:\n return amida(W-1)+amida(W-2)\n\n@memorize\ndef amida2(H, W, x, y=1):\n if H==0:\n return 1 if x==y else 0\n a = 0 if x==1 else amida(x-2)*amida(W-x)*amida2(W, H-1, x-1, y)\n b = amida(x-1)*amida(W-x)*amida2(W, H-1, x, y)\n c = 0 if x==W else amida(x-1)*amida(W-x-1)*amida2(W, H-1, x+1, y)\n return (a+b+c)%1000000007\nprint(amida2(*map(int, input().split())))', 'def memorize(func):\n memo = {}\n def wrapper(*args):\n if args not in memo:\n memo[args] = func(*args)\n return memo[args]\n return wrapper\n\n@memorize\ndef amida(W): \n if W<2:\n return 1\n else:\n return amida(W-1)+amida(W-2)\n\n@memorize\ndef amida2(H, W, x):\n if H==0:\n return 1 if x==1 else 0\n a = 0 if x==1 else amida(x-2)*amida(W-x)*amida2(H-1, W, x-1)\n b = amida(x-1)*amida(W-x)*amida2(H-1, W, x)\n c = 0 if x==W else amida(x-1)*amida(W-x-1)*amida2(H-1, W, x+1)\n return (a+b+c)%1000000007\nprint(amida2(*map(int, input().split())))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s061952662', 's446081938', 's610624454', 's537733581']
[3064.0, 3064.0, 3188.0, 3316.0]
[17.0, 18.0, 18.0, 20.0]
[622, 653, 664, 650]
p03222
u268181283
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['H,W,K = map(int, input().split())\n\ndp = [[0]*W for _ in range(H+1)]\ndp[0][0] = 1\nif W==1:\n print(1)\nelse:\n for i in range(H):\n for j in range(2**(W-1)):\n flag = True\n for k in range(W-1):\n if k != W-2:\n \n if (((j >> k) & 1)&((j >> k+1) & 1)):\n flag = False\n break\n if flag:\n #print(bin(j)[2:].zfill(W-1))\n for l in range(W-1):\n if ((j >> l) & 1):\n dp[i+1][l] += dp[i][l+1]\n dp[i+1][l+1] += dp[i][l]\n else:\n dp[i+1][l] += dp[i][l]\n #print(dp[i+1])\n\n print(dp[-1][K-1]%(1000000007)', "H,W,K = map(int, input().split())\n\ndp = [[0]*W for _ in range(H+1)]\ndp[0][0] = 1\nif W==1:\n print('Ans=',1)\nelse:\n for i in range(H):\n for j in range(2**(W-1)):\n flag = True\n for k in range(W-1):\n if k != W-2:\n \n if (((j >> k) & 1)&((j >> k+1) & 1)):\n flag = False\n break\n if flag:\n #print(bin(j)[2:].zfill(W-1))\n l = 0\n while l < W:\n if ((j >> l) & 1):\n dp[i+1][l] += dp[i][l+1]\n dp[i+1][l+1] += dp[i][l]\n l += 1\n else:\n dp[i+1][l] += dp[i][l]\n l += 1\n #print('pre',dp[i])\n #print(dp[i+1])\n\n print('Ans=',dp[-1][K-1]%(1000000007))\n\n \n \n ", "H,W,K = map(int, input().split())\n\ndp = [[0]*W for _ in range(H+1)]\ndp[0][0] = 1\nif W==1:\n print(1)\nelse:\n for i in range(H):\n for j in range(2**(W-1)):\n flag = True\n for k in range(W-1):\n if k != W-2:\n \n if (((j >> k) & 1)&((j >> k+1) & 1)):\n flag = False\n break\n if flag:\n #print(bin(j)[2:].zfill(W-1))\n l = 0\n while l < W:\n if ((j >> l) & 1):\n dp[i+1][l] += dp[i][l+1]\n dp[i+1][l+1] += dp[i][l]\n l += 1\n else:\n dp[i+1][l] += dp[i][l]\n l += 1\n #print('pre',dp[i])\n #print(dp[i+1])\n\n print(dp[-1][K-1]%(1000000007))\n\n \n \n "]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s532407828', 's927946879', 's834755145']
[3064.0, 3064.0, 3064.0]
[18.0, 55.0, 53.0]
[692, 807, 793]
p03222
u268210555
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['h, w, k = map(int, input().split())\na = [0]*(w-1) + [1,1]\nfor i in range(w-1):\n a[i] = a[i-1] + a[i-2]\ndp = [0]*(w+1)\ntmp = [0]*(w+1)\ndp[0] = 1\nfor _ in range(1, h+1):\n for i in range(w):\n tmp[i] = (dp[i]*a[i-1]*a[w-i-2]\n + dp[i+1]*a[i-1]*a[w-i-3]\n + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)\n dp, tmp = tmp, dp\nprint(dp[k-1])', 'h, w, k = map(int, input().split())\na = [0]*(w-1) + [1]\nfor i in range(w-1):\n a[i] = a[i-1] + a[i-2]\ndp = [0]*(w+1)\ntmp = [0]*(w+1)\ndp[0] = 1\nfor _ in range(1, h+1):\n for i in range(w):\n tmp[i] = (dp[i]*a[i-1]*a[w-i-2]\n + dp[i+1]*a[i-1]*a[w-i-3]\n + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)\n tmp[i] %= m\n dp, tmp = tmp, dp\nprint(dp[k-1])', 'h, w, k = map(int, input().split())\na = [0]*(w-1) + [0,1]\nfor i in range(w-1):\n a[i] = a[i-1] + a[i-2]\ndp = [0]*(w+1)\ntmp = [0]*(w+1)\ndp[0] = 1\nfor _ in range(1, h+1):\n for i in range(w):\n tmp[i] = (dp[i]*a[i-1]*a[w-i-2]\n + dp[i+1]*a[i-1]*a[w-i-3]\n + dp[i-1]*a[i-2]*a[w-i-2]) % (10**9+7)\n dp, tmp = tmp, dp\nprint(dp[k-1])']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s305300062', 's410257503', 's966611835']
[3064.0, 3064.0, 3064.0]
[19.0, 23.0, 19.0]
[359, 377, 359]
p03222
u360116509
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
["def main():\n H, W, K = list(map(int, input().split()))\n dp = [[0 for _ in range(W)] for _ in range(H + 1)]\n dp[0][0] = 1\n\n for i in range(H):\n for j in range(1 << (W - 1)):\n if '11' in bin(j):\n continue\n j <<= 1\n for w in range(W):\n if j & (1 << w):\n dp[i + 1][w] += dp[i][w - 1]\n elif j & (1 << (w + 1)):\n dp[i + 1][w] += dp[i][w + 1]\n else:\n dp[i + 1][w] += dp[i][w]\n dp[i + 1][w] %= (10 ** 9 + 7)\n\n for a in dp:\n print(a)\n print(dp[H][K - 1])\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n H, W, K = list(map(int, input().split()))\n dp = [[0 for _ in range(W)] for _ in range(H + 1)]\n dp[0][0] = 1\n\n for i in range(H):\n for j in range(1 << (W - 1)):\n if '11' in bin(j):\n continue\n j <<= 1\n for w in range(W):\n if j & (1 << w):\n dp[i + 1][w] += dp[i][w - 1]\n elif j & (1 << (w + 1)):\n dp[i + 1][w] += dp[i][w + 1]\n else:\n dp[i + 1][w] += dp[i][w]\n dp[i + 1][w] %= (10 ** 9 + 7)\n\n print(dp[H][K - 1])\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s262488563', 's881970645']
[3064.0, 3064.0]
[36.0, 35.0]
[683, 649]
p03222
u375616706
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['h,w,k = list(map(int,input().split()))\n\nmat = [[0 for i in range(w+1)] for j in range(h+1)]\nmat[0][0]=1\n\nfor i in range(1,h+1):\n for j in range(w):\n if j==0:\n mat[i][j]=mat[i-1][j]+mat[i-1][j+1]\n elif j==w-1:\n mat[i][j]=mat[i-1][j]+mat[i-1][j-1]\n else:\n mat[i][j]=mat[i-1][j]+mat[i-1][j-1]+mat[i-1][j+1]\n\nprint(mat[h-1][k-1] % 1000000007)\n', 'h,w,k = list(map(int,input().split()))\n\nmat = [[0 for i in range(w)] for j in range(h)]\nmat[0][0]=1\n\nfor i in range(1,h):\n for j in range(w):\n if j==0:\n mat[i][j]=mat[i-1][j]+mat[i-1][j+1]\n elif j==w-1:\n mat[i][j]=mat[i-1][j]+mat[i-1][j-1]\n else:\n mat[i][j]=mat[i-1][j]+mat[i-1][j-1]+mat[i-1][j+1]\n\nprint(mat[h-1][k-1] % 1000000007)\n', "h, w, k = (list)(map(int, input().split()))\n\nmat = [[0 for _ in range(w)] for __ in range(h+1)]\nmat[0][0] = 1\n\n\ndef num(n):\n ret = 0\n if n == 0:\n return 1\n for i in range(2**(n-1)):\n dig = format(i, 'b')\n if not '11' in dig:\n ret += 1\n\n return ret\n\n\nif w == 1:\n print('1')\n exit()\n\nfor col in range(1, h+1):\n for row in range(w):\n if row == 0:\n mat[col][row] = mat[col-1][row] * \\\n num(w-1) + mat[col-1][row+1]*num(w-2)\n elif row == w-1:\n mat[col][row] = mat[col-1][row] * \\\n num(w-1) + mat[col-1][row-1]*num(w-2)\n else:\n mat[col][row] = mat[col-1][row] * (num(row)*num(w-row-1)) \\\n + mat[col-1][row-1]*(num(row-1)*num(w-row-1))\\\n + mat[col-1][row+1]*(num(row)*num(w-row-2))\nprint(mat[h][k-1] % 1000000007)"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s247799891', 's731705226', 's906743352']
[3064.0, 3064.0, 3064.0]
[18.0, 18.0, 41.0]
[396, 390, 873]
p03222
u480300350
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['h, w, k = map(int, input().split())\nmod = 10 ** 9 + 7\n\ndp = [[0] * (w + 1) for _ in range(h + 1)]\nfor i in range(w + 1):\n dp[0][i] = 1 if i == 1 else 0\n\n\ndef calc_pow(from_col, to_col):\n assert(1<=from_col<=w and 1<=to_col<=w)\n if from_col == 1 or to_col == 1 or from_col == w or to_col == w:\n return pow(2, max(w-1-2, 0), mod)\n else:\n return pow(2, max(w-1-3, 0), mod)\n\n\nfor t in range(1, h + 1):\n for i in range(1, w + 1):\n pattern_1 = dp[t-1][i-1] * calc_pow(i-1, i) if i > 1 else 0\n pattern_2 = dp[t-1][i+1] * calc_pow(i+1, i) if i < w else 0\n pattern_3 = dp[t-1][i] * (pow(2, max(w-1-2, 0), mod) if 1 < i < w else pow(2, max(w-1-1, 0), mod))\n dp[t][i] = (pattern_1 + pattern_2 + pattern_3) % mod\n\nfor line in dp:\n print(*line)\n# print(dp[h][k])\n', 'from itertools import product\n\nh, w, k = map(int, input().split())\nmod = 10 ** 9 + 7\n\ndp = [[0] * (w + 1) for _ in range(h + 1)]\nfor i in range(w + 1):\n dp[0][i] = 1 if i == 1 else 0\n\n\ndef check_valid_bridge(bridge):\n for i in range(1, w-1):\n if bridge[i-1] and bridge[i]:\n return False\n return True\n\nfor t in range(1, h + 1):\n for i in range(1, w + 1):\n X, Y, Z = 0, 0, 0\n if w != 1:\n p = product([True, False], repeat=w-1) \n for bridge in p:\n if check_valid_bridge(bridge):\n if i > 1 and bridge[i-2]:\n X += 1\n elif i < w and bridge[i-1]:\n Y += 1\n elif (i == 1 and not bridge[i-1]) or (i == w and not bridge[i-2]) or (1 < i < w and not bridge[i-2] and not bridge[i-1]):\n Z += 1\n else:\n Z = 1\n # print(f"{X} {Y} {Z}")\n pattern_1 = dp[t-1][i-1] * X if i > 1 else 0\n pattern_2 = dp[t-1][i+1] * Y if i < w else 0\n pattern_3 = dp[t-1][i] * Z\n dp[t][i] = (pattern_1 + pattern_2 + pattern_3) % mod\n\n# for line in dp:\n# print(*line)\nprint(dp[h][k])\n']
['Wrong Answer', 'Accepted']
['s901753842', 's624453921']
[3188.0, 3188.0]
[22.0, 95.0]
[774, 1217]
p03222
u506858457
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['\nh, w, k = map(int, input().split())\nmemo = defaultdict(lambda:defaultdict(int))\ndef dfs(x, y):\n if y == h:\n if x == k - 1:\n return 1\n else:\n return 0\n if y in memo[x]:\n return memo[x][y]\n\n ans = 0\n for i in range(1 << w - 1):\n flg = True\n for j in range(w - 2):\n if i & (1 << j) and i & (1 << j + 1):\n flg = False\n break\n if flg:\n nx = x\n if x > 0 and i & (1 << x - 1):\n nx = x - 1\n elif i & (1 << x):\n nx = x + 1\n ans += dfs(nx, y + 1)\n ans %= 1000000000 + 7\n memo[x][y] = ans\n return ans\nprint(dfs(0, 0))', '\nfrom collections import defaultdict\nh, w, k = map(int, input().split())\nmemo = defaultdict(lambda:defaultdict(int))\ndef dfs(x, y):\n if y == h:\n if x == k - 1:\n return 1\n else:\n return 0\n if y in memo[x]:\n return memo[x][y]\n ans = 0\n for i in range(1 << w - 1):\n flg = True\n for j in range(w - 2):\n if i & (1 << j) and i & (1 << j + 1):\n flg = False\n break\n if flg:\n nx = x\n if x > 0 and i & (1 << x - 1):\n nx = x - 1\n elif i & (1 << x):\n nx = x + 1\n ans += dfs(nx, y + 1)\n ans %= 1000000000 + 7\n memo[x][y] = ans\n return ans\nprint(dfs(0, 0))']
['Runtime Error', 'Accepted']
['s202280536', 's762451553']
[3064.0, 3436.0]
[18.0, 115.0]
[1323, 1358]
p03222
u512007680
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['MOD = 10 ** 9 +7\nh, w, k = map(int,input().split())\n\nif w == 1:\n print(1)\nelse:\n acr = []\n for p in range(2**(w-1)):\n det = 0\n pp = p\n exist = [0] * (w-1)\n for i in range(w-1):\n exist[i] = pp % 2\n pp = pp // 2\n for ii in range(w-2):\n if exist[ii] == 1 and exist[ii+1] == 1:\n det = 1\n if det == 0:\n acr.append(exist)\n\n cur = [0] * w\n cur[0] = 1\n n = [0] * w\n\n for x in range(len(acr)):\n n[0] = cur[1] * acr[x][0] + cur[0] * (1-acr[x][0])\n for j in range(1,w-1):\n n[j] = cur[j-1] * acr[x][j-1] + cur[j+1] * acr[x][j] + cur[j] * (1-acr[x][j-1])(1-acr[x][j])\n n[w-1] = cur[w-2] * acr[x][w-2] + cur[w-1] * (1-acr[x][w-1])\n cur = n[:]\n print(cur[k-1])', 'MOD = 10 ** 9 +7\nh, w, k = map(int,input().split())\n\nif w == 1:\n print(1)\nelse:\n acr = []\n for p in range(2**(w-1)):\n det = 0\n pp = p\n exist = [0] * (w-1)\n for i in range(w-1):\n exist[i] = pp % 2\n pp = pp // 2\n for ii in range(w-2):\n if exist[ii] == 1 and exist[ii+1] == 1:\n det = 1\n if det == 0:\n acr.append(exist[:])\n #print(acr)\n\n cur = [0] * w\n cur[0] = 1\n \n\n for t in range(h):\n n = [0] * w\n for x in range(len(acr)):\n n[0] = (n[0] + cur[1] * acr[x][0] + cur[0] * (1-acr[x][0]))%MOD\n for j in range(1,w-1):\n n[j] = (n[j] + cur[j-1] * acr[x][j-1] + cur[j+1] * acr[x][j] + cur[j] * (1-acr[x][j-1])*(1-acr[x][j]))%MOD\n n[w-1] = (n[w-1] + cur[w-2] * acr[x][w-2] + cur[w-1] * (1-acr[x][w-2])) % MOD\n \n cur = n[:]\n \n print(cur[k-1])']
['Runtime Error', 'Accepted']
['s135568696', 's701719563']
[3064.0, 3064.0]
[18.0, 45.0]
[809, 942]
p03222
u545314527
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['import itertools\n\nH,W,K = map(int, input().split())\np = 1000000007\n\nif K - 1 > H:\n print(0)\n exit(0)\n\nR = []\nfor r in itertools.product( [0,1], repeat=(W-1) ):\n if 1 not in list(map(lambda i : r[i]*r[i+1], range(len(r)-1)) ):\n R.append(r)\n\n\nM = [ (\n len( list( filter( lambda r:r[0]==0, R) ) ),\n len( list( filter( lambda r:r[0]==1, R) ) ),\n 0\n) ]\nfor c in range(1,W-1):\n M.append((\n len( list( filter( lambda r:r[c]==0 and r[c-1]==0, R) ) ),\n len( list( filter( lambda r:r[c]==1, R) ) ),\n len( list( filter( lambda r:r[c-1]==1, R) ) )\n ))\nM.append((\n len( list( filter( lambda r:r[W-2]==0, R) ) ),\n 0,\n len( list( filter( lambda r:r[W-2]==1, R) ) )\n))\n\nprint(R)\nprint(M)\n\ncount = [1] + [0]*(W-1)\nfor h in range(H):\n count_ = [0] * W\n for num,c in zip(count, range(len(count))):\n for m,n in zip(M[c], [0,+1,-1]):\n if c+n >= 0 and c+n < W:\n count_[c+n] += num * m\n count = count_\n \nprint(count_[K-1]%p) \n \n', 'import itertools\n\nH,W,K = map(int, input().split())\np = 1000000007\n\nif K - 1 > H:\n print(0)\n exit(0)\nif W == 1:\n print(1)\n exit(0)\n\nR = []\nfor r in itertools.product( [0,1], repeat=(W-1) ):\n if 1 not in list(map(lambda i : r[i]*r[i+1], range(len(r)-1)) ):\n R.append(r)\n\n\nM = [ (\n len( list( filter( lambda r:r[0]==0, R) ) ),\n len( list( filter( lambda r:r[0]==1, R) ) ),\n 0\n) ]\nfor c in range(1,W-1):\n M.append((\n len( list( filter( lambda r:r[c]==0 and r[c-1]==0, R) ) ),\n len( list( filter( lambda r:r[c]==1, R) ) ),\n len( list( filter( lambda r:r[c-1]==1, R) ) )\n ))\nM.append((\n len( list( filter( lambda r:r[W-2]==0, R) ) ),\n 0,\n len( list( filter( lambda r:r[W-2]==1, R) ) )\n))\n\ncount = [1] + [0]*(W-1)\nfor h in range(H):\n count_ = [0] * W\n for num,c in zip(count, range(len(count))):\n for m,n in zip(M[c], [0,+1,-1]):\n if c+n >= 0 and c+n < W:\n count_[c+n] += num * m\n count = count_\n \nprint(count_[K-1]%p) \n \n']
['Runtime Error', 'Accepted']
['s906948590', 's311685712']
[3188.0, 3188.0]
[21.0, 20.0]
[1021, 1038]
p03222
u606045429
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['mod = 10 ** 9 + 7\nfib = [1, 1, 2, 3, 5, 8, 13, 21, 34]\n\nH, W, K = map(int, input().split())\n\ndp = [0] * W\ndp[0] = 1\n\nfor _ in range(H):\n\n T = [0] * W\n\n for i in range(W):\n if 0 < i:\n T[i] += T[i - 1] * fib[i - 1] * fib[W - i - 1]\n\n T[i] += T[i] * fib[i] * fib[W - i - 1]\n\n if i < W - 1:\n T[i] += dp[i + 1] * fib[i] * fib[W - i - 2]\n\n T[i] %= mod\n\n dp = T\n\nprint(dp[K - 1])', 'mod = 10 ** 9 + 7\nfib = [1, 1, 2, 3, 5, 8, 13, 21, 34]\n\nH, W, K = map(int, input().split())\n\ndp = [0] * W\ndp[0] = 1\n\nfor _ in range(H):\n\n T = [0] * W\n\n for i in range(W):\n if 0 < i:\n T[i] += dp[i - 1] * fib[i - 1] * fib[W - i - 1]\n\n T[i] += dp[i] * fib[i] * fib[W - i - 1]\n\n if i < W - 1:\n T[i] += dp[i + 1] * fib[i] * fib[W - i - 2]\n\n T[i] %= mod\n\n dp = T\n\nprint(dp[K - 1])']
['Wrong Answer', 'Accepted']
['s900885606', 's478862453']
[3064.0, 3064.0]
[18.0, 18.0]
[431, 433]
p03222
u608088992
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['H, W, K = map(int, input().split())\nmod = 7 + 10**9\nNo = [1 for i in range(7)] \nNo[1], No[2], No[3], No[4] = 2, 3, 5, 8\nNo[5], No[6]= 13, 21\n\nif W == 1:\n print(1)\nelse:\n DP = [[0 for w in range(W)] for h in range(H)]\n DP[0][0], DP[0][1] = No[max(0, W-2)], No[max(0, W-3)]\n for h in range(1, H):\n for w in range(W):\n if w == 0:\n left = 0\n up = DP[h-1][0] * No[max(0, W-2)] % mod\n right = DP[h-1][1] * No[max(0, W-3)] % mod\n elif w == W-1:\n left = DP[h-1][W-2] * No[max(0, W-3)] % mod\n up = DP[h-1][W-1] * No[max(0,W-2)] % mod\n right = 0\n else:\n left = DP[h-1][w-1] * No[max(0, w-2)] * No[max(0, W-w-2)] % mod\n up = DP[h-1][w] * No[max(0, w-1)] * No[max(0, W-w-2)] % mod\n right = DP[h-1][w+1] * No[max(0, w-1)] * No[max(0, W-w-3)] % mod\n DP[h][w] = (left+up+right) % mod\n print(DP)\n print(DP[H-1][K-1])', 'import sys\nmod = 7 + 10 ** 9\n\ndef solve():\n input = sys.stdin.readline\n H, W, K = map(int, input().split())\n DP = [[0] * W for _ in range(H + 1)]\n pattern = [1, 2, 3, 5, 8, 13, 21]\n DP[0][0] = 1\n for h in range(H):\n for w in range(W):\n if w == 0:\n DP[h+1][w] += (DP[h][w] * pattern[max(0, W - 2)]) % mod\n if W > 1: DP[h+1][w] += (DP[h][w+1] * pattern[max(0, W - 3)]) % mod\n elif w == W - 1:\n DP[h+1][w] += (DP[h][w] * pattern[max(0, W - 2)]) % mod\n if W > 1: DP[h+1][w] += (DP[h][w-1] * pattern[max(0, W - 3)]) % mod\n else:\n DP[h+1][w] += (DP[h][w] * pattern[max(0, w - 1)] * pattern[max(0, W - w - 2)]) % mod\n DP[h+1][w] += (DP[h][w+1] * pattern[max(0, w - 1)] * pattern[max(0, W - w - 3)]) % mod\n DP[h+1][w] += (DP[h][w-1] * pattern[max(0, w - 2)] * pattern[max(0, W - w - 2)]) % mod\n DP[h+1][w] %= mod\n print(DP[H][K - 1])\n\n return 0\n\nif __name__ == "__main__":\n solve()']
['Wrong Answer', 'Accepted']
['s700939195', 's893473204']
[3188.0, 3188.0]
[19.0, 21.0]
[1035, 1057]
p03222
u619819312
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['a,b,c=map(int,input().split())\ns=[[0]*b for i in range(a+1)]\ns[0][0]=1\nprint(s)\nk=[[1,1,1],[2,1,1,1,2],[3,2,2,1,2,2,3],[5,3,3,2,4,2,3,3,5],[8,5,5,3,6,4,6,3,5,5,8],[13,8,8,5,10,6,9,6,10,5,8,8,13],[21,13,13,8,16,10,15,9,15,10,16,8,13,13,21]]\nif b==1:\n print(1)\nelif c-a>=2:\n print(0) \nelse:\n d=k[b-2]\n for i in range(1,a+1):\n s[i][b-1]=s[i-1][b-1]*d[2*(b-1)]+s[i-1][b-2]*d[2*(b-1)-1]\n for j in range(0,b-1):\n if j==0:\n s[i][0]=s[i-1][0]*d[0]+s[i-1][1]*d[1]\n else: \n s[i][j]=s[i-1][j-1]*d[2*j-1]+s[i-1][j]*d[2*j]+s[i-1][j+1]*d[2*j+1]\nprint(s[a][c-1]%(10**9+7)) ', 'a,b,c=map(int,input().split())\ns=[[0]*b for i in range(a+1)]\ns[0][0]=1\nk=[[1,1,1],[2,1,1,1,2],[3,2,2,1,2,2,3],[5,3,3,2,4,2,3,3,5],[8,5,5,3,6,4,6,3,5,5,8],[13,8,8,5,10,6,9,6,10,5,8,8,13],[21,13,13,8,16,10,15,9,15,10,16,8,13,13,21]]\nif b==1:\n print(1)\nelif c-a>=2:\n print(0) \nelse:\n d=k[b-2]\n for i in range(1,a+1):\n s[i][b-1]=s[i-1][b-1]*d[2*(b-1)]+s[i-1][b-2]*d[2*(b-1)-1]\n for j in range(0,b-1):\n if j==0:\n s[i][0]=s[i-1][0]*d[0]+s[i-1][1]*d[1]\n else: \n s[i][j]=s[i-1][j-1]*d[2*j-1]+s[i-1][j]*d[2*j]+s[i-1][j+1]*d[2*j+1]\n print(s[a][c-1]%(10**9+7)) ']
['Wrong Answer', 'Accepted']
['s753057310', 's966505984']
[3188.0, 3188.0]
[18.0, 18.0]
[642, 637]
p03222
u725578977
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['# -*- coding: utf-8 -*-\n\nh, w, k = map(int, input().split())\n\n\ndef f(x):\n lst = [1, 2, 3, 5, 7, 13, 19]\n if 0 <= x < 7:\n return lst[x]\n else:\n return 1\n\n\nptn = [[0] * (w + 2) for _ in range(w + 2)]\nfor i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w+1 or j == 0 or j == w+1:\n continue\n elif i == j:\n ptn[i][j] = f(i-2)*f(w-i-1)\n elif i == j + 1:\n ptn[i][j] = f(i-3)*f(w-i-1)\n elif i == j -1:\n ptn[i][j] = f(i-2)*f(w-i-2)\nprint(ptn)\n\n\nfor _ in range(h - 1):\n temp = [[0] * (w + 2) for _ in range(w + 2)]\n for i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w+1 or j == 0 or j == w+1:\n continue\n else:\n temp[i][j] = ptn[i-1][j]*f(i-3)*f(w-i-1) + ptn[i][j]*f(i-2)*f(w-i-1) + ptn[i+1][j]*f(i-2)*f(w-i-2)\n\n ptn = temp; print(ptn)\n\nprint(ptn[1][k] % 1000000007)\n', '# -*- coding: utf-8 -*-\n\nh, w, k = map(int, input().split())\n\n\ndef f(x):\n lst = [1, 2, 3, 5, 8, 13, 21]\n if 0 <= x < 7:\n return lst[x]\n else:\n return 1\n\n\nptn = [[0] * (w + 2) for _ in range(w + 2)]\nfor i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w + 1 or j == 0 or j == w + 1:\n continue\n elif i == j:\n ptn[i][j] = f(i-2)*f(w-i-1)\n elif i == j + 1:\n ptn[i][j] = f(i-3)*f(w-i-1)\n elif i == j - 1:\n ptn[i][j] = f(i-2)*f(w-i-2)\nprint(ptn)\n\n\nfor _ in range(h - 1):\n temp = [[0] * (w + 2) for _ in range(w + 2)]\n for i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w + 1 or j == 0 or j == w + 1:\n continue\n else:\n temp[i][j] = ptn[i-1][j]*f(i-3)*f(w-i-1) + ptn[i][j]*f(i-2)*f(w-i-1) + ptn[i+1][j]*f(i-2)*f(w-i-2)\n\n ptn = temp; print(ptn)\n\nprint(ptn[1][k] % 1000000007)\n', '# -*- coding: utf-8 -*-\n\nh, w, k = map(int, input().split())\n\n\ndef f(x):\n lst = [1, 2, 3, 5, 8, 13, 21]\n if 0 <= x < 7:\n return lst[x]\n else:\n return 1\n\n\nptn = [[0] * (w + 2) for _ in range(w + 2)]\nfor i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w + 1 or j == 0 or j == w + 1:\n continue\n elif i == j:\n ptn[i][j] = f(i-2)*f(w-i-1)\n elif i == j + 1:\n ptn[i][j] = f(i-3)*f(w-i-1)\n elif i == j - 1:\n ptn[i][j] = f(i-2)*f(w-i-2)\n\nfor _ in range(h - 1):\n temp = [[0] * (w + 2) for _ in range(w + 2)]\n for i in range(w + 2):\n for j in range(w + 2):\n if i == 0 or i == w + 1 or j == 0 or j == w + 1:\n continue\n else:\n temp[i][j] = ptn[i-1][j]*f(i-3)*f(w-i-1) + ptn[i][j]*f(i-2)*f(w-i-1) + ptn[i+1][j]*f(i-2)*f(w-i-2)\n\n ptn = temp\n\nprint(ptn[1][k] % 1000000007)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s013138480', 's067514444', 's680731766']
[3572.0, 3572.0, 3064.0]
[41.0, 41.0, 37.0]
[952, 961, 937]
p03222
u729008627
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['import numpy as np\nH, W, K = map(int, input().split())\np = 10**9 + 7\nr = [1, 1, 2, 3, 5, 8, 13, 21, 34]\ndp = np.zeros([H + 1, W], dtype=int)\ndp[0, 0] = 1\nfor h in range(H):\n for w in range(W):\n if w != 0:\n dp[h+1, w] += ((dp[h, w-1] * r[w-1])%p * r[W-1-w])%p\n dp[h+1, w] = ((dp[h, w] * r[w])%p * r[W-1-w])%p\n if w != W-1:\n dp[h+1, w] += ((dp[h, w+1] * r[w])%p * r[W-2-w])%p\n dp[h+1, w] = dp[h+1, w]%p\nprint(dp[H, K-1])', 'import numpy as np\nH, W, K = map(int, input().split())\np = 10**9 + 7\nr = [1, 1, 2, 3, 5, 8, 13, 21, 34]\ndp = np.zeros([H + 1, W], dtype=int)\ndp[0, 0] = 1\nfor h in range(H):\n for w in range(W):\n if w != 0:\n dp[h+1, w] += ((dp[h, w-1] * r[w-1])%p * r[W-1-w])%p\n dp[h+1, w] += ((dp[h, w] * r[w])%p * r[W-1-w])%p\n if w != W-1:\n dp[h+1, w] += ((dp[h, w+1] * r[w])%p * r[W-2-w])%p\n dp[h+1, w] = dp[h+1, w]%p\nprint(dp[H, K-1])']
['Wrong Answer', 'Accepted']
['s876626017', 's731328352']
[12516.0, 12508.0]
[160.0, 162.0]
[471, 472]
p03222
u762557532
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['from collections import deque\nfrom copy import deepcopy\n\nH, W, K = map(int, input().split())\n\nmod = int(1e9+7)\n\n\nperm_lst = []\ndef bfs():\n dq = deque() \n dq.append(([],0))\n while dq:\n post, line = dq.popleft()\n if line < W: \n post_tmp = deepcopy(post) \n post_tmp.append((line,line))\n dq.append( (post_tmp,line+1) )\n if line < W-1: \n post_tmp = deepcopy(post) \n post_tmp.append((line,line+1))\n dq.append( (post_tmp,line+2) )\n if line == W:\n perm_lst.append(post)\nbfs()\nprint(perm_lst)\n\n\ndp = [[0 for j in range(W)] for i in range(H+1)]\ndp[0][0] = 1\nfor i in range(1,H+1):\n for perm in perm_lst:\n for j in range(len(perm)):\n if perm[j][0] != perm[j][1]:\n dp[i][perm[j][0]] += dp[i-1][perm[j][1]]\n dp[i][perm[j][1]] += dp[i-1][perm[j][0]]\n else:\n dp[i][perm[j][0]] += dp[i-1][perm[j][0]]\n \nprint(dp)\n\nprint(dp[H][K-1] % mod)', 'from collections import deque\nfrom copy import deepcopy\n\nH, W, K = map(int, input().split())\n\nmod = int(1e9+7)\n\n\nperm_lst = []\ndef bfs():\n dq = deque() \n dq.append(([],0))\n while dq:\n post, line = dq.popleft()\n if line < W: \n post_tmp = deepcopy(post) \n post_tmp.append((line,line))\n dq.append( (post_tmp,line+1) )\n if line < W-1: \n post_tmp = deepcopy(post) \n post_tmp.append((line,line+1))\n dq.append( (post_tmp,line+2) )\n if line == W:\n perm_lst.append(post)\nbfs()\n#print(perm_lst)\n\n\ndp = [[0 for j in range(W)] for i in range(H+1)]\ndp[0][0] = 1\nfor i in range(1,H+1):\n for perm in perm_lst:\n for j in range(len(perm)):\n if perm[j][0] != perm[j][1]:\n dp[i][perm[j][0]] += dp[i-1][perm[j][1]]\n dp[i][perm[j][1]] += dp[i-1][perm[j][0]]\n else:\n dp[i][perm[j][0]] += dp[i-1][perm[j][0]]\n \n#print(dp)\n\nprint(dp[H][K-1] % mod)']
['Wrong Answer', 'Accepted']
['s867071417', 's278567607']
[3824.0, 3572.0]
[39.0, 40.0]
[1244, 1246]
p03222
u782098901
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['MOD = 1000000007\n\n\ndef main():\n H, W, K = map(int, input().split())\n dp = [[0] * W] * (H + 1)\n dp[0][0] = 1\n for i in range(H):\n for j in range(W):\n for k in range(1 << (W - 1)):\n ok = True\n for l in range(W - 2):\n \n if (k >> l) & 1 and (k >> (l + 1)) & 1:\n ok = False\n\n if (ok):\n if 1 <= j and (k >> (j - 1)) & 1:\n dp[i + 1][j - 1] = dp[i + 1][j - 1] + dp[i][j] % MOD\n elif j <= W and (k >> (j + 1)) & 1:\n dp[i + 1][j + 1] = dp[i + 1][j + 1] + dp[i][j] % MOD\n else:\n dp[i + 1][j] = dp[i + 1][j] + dp[i][j] % MOD\n\n print(dp[H][K - 1])\n\nmain()\n', 'MOD = 1000000007\n\n\ndef main():\n H, W, K = map(int, input().split())\n dp = [[0 for _ in range(W)] for _ in range(H + 1)]\n dp[0][0] = 1\n for i in range(H):\n for j in range(W):\n for k in range(1 << (W - 1)):\n ok = True\n for l in range(W - 2):\n \n if (k >> l) & 1 and (k >> (l + 1)) & 1:\n ok = False\n\n if (ok):\n if 1 <= j and (k >> (j - 1)) & 1:\n dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MOD\n elif j <= W - 2 and (k >> j) & 1:\n dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD\n else:\n dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD\n\n print(dp[H][K - 1])\n\nmain()\n']
['Wrong Answer', 'Accepted']
['s822165738', 's206622103']
[3064.0, 3064.0]
[152.0, 146.0]
[861, 891]
p03222
u790905630
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['import itertools\n\ndef fibonacci(n):\n if (n == 0):\n f_n = 1\n elif (n == 1):\n f_n = 1\n else:\n f_n = fibonacci(n-1) + fibonacci(n-2)\n\n return f_n\n\ndef X_amida_number(W, W_i):\n x_amida = "0" * (W - 1)\n left_x_amida = x_amida[:(W_i-2)] if(W_i-2 >= 0) else ""\n right_x_amida = x_amida[(W_i+1):]\n\n return fibonacci(len(left_x_amida) + 1) * fibonacci(len(right_x_amida) + 1)\n\ndef Y_amida_number(W, W_i):\n y_amida = "0" * (W - 1)\n left_y_amida = y_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_y_amida = y_amida[W_i+1:]\n\n return fibonacci(len(left_y_amida) + 1) * fibonacci(len(right_y_amida) + 1)\n\ndef Z_amida_number(W, W_i):\n z_amida = "0" * (W - 1)\n left_z_amida = z_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_z_amida = z_amida[W_i+2:]\n\n return fibonacci(len(left_z_amida) + 1) * fibonacci(len(right_z_amida) + 1)\n\ndef amida_all(amida_list, W):\n for i, j in itertools.product(range(W), range(3)):\n if(j == 0):\n amida_list[i][j] = X_amida_number(W, i)\n elif(j == 1):\n amida_list[i][j] = Y_amida_number(W, i)\n else:\n amida_list[i][j] = Z_amida_number(W, i)\n\n return amida_list\n\nH, W, K = map(int, input().split())\namida_list = [[0]*3 for i in range(W)]\namida_list = amida_all(amida_list, W)\nprint(amida_list)\n\nseed_dp_array = [0 for i in range(W)]\ndp_array = [list(seed_dp_array) for i in range(H + 1)]\ndp_array[0][0] = 1\n\nfor H_i, W_i in itertools.product(range(1, H + 1), range(W)):\n if (W_i == 0):\n if(W == 1):\n dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1]\n else:\n dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]\n elif (W_i == (W - 1)):\n dp_array[H_i][W - 1] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1]\n else:\n dp_array[H_i][W_i] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]\n\nprint(dp_array[H][K - 1] % 1000000007)', 'import itertools\n\ndef fibonacci(n):\n if (n == 0):\n f_n = 1\n elif (n == 1):\n f_n = 1\n else:\n f_n = fibonacci(n-1) + fibonacci(n-2)\n\n return f_n\n\ndef X_amida_number(W, W_i):\n x_amida = "0" * (W - 1)\n left_x_amida = x_amida[:(W_i-2)] if(W_i-2 >= 0) else ""\n right_x_amida = x_amida[(W_i+1):]\n\n return fibonacci(len(left_x_amida) + 1) * fibonacci(len(right_x_amida) + 1)\n\ndef Y_amida_number(W, W_i):\n y_amida = "0" * (W - 1)\n left_y_amida = y_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_y_amida = y_amida[W_i+1:]\n\n return fibonacci(len(left_y_amida) + 1) * fibonacci(len(right_y_amida) + 1)\n\ndef Z_amida_number(W, W_i):\n z_amida = "0" * (W - 1)\n left_z_amida = z_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_z_amida = z_amida[W_i+2:]\n\n return fibonacci(len(left_z_amida) + 1) * fibonacci(len(right_z_amida) + 1)\n\ndef amida_all(amida_list, W):\n for i, j in itertools.product(range(W), range(3)):\n if(j == 0):\n amida_list[i][j] = X_amida_number(W, i)\n elif(j == 1):\n amida_list[i][j] = Y_amida_number(W, i)\n else:\n amida_list[i][j] = Z_amida_number(W, i)\n\n return amida_list\n\nH, W, K = map(int, input().split())\namida_list = [[0]*3 for i in range(W)]\namida_list = amida_all(amida_list, W)\nprint(amida_list)\n\nseed_dp_array = [0 for i in range(W)]\ndp_array = [list(seed_dp_array) for i in range(H + 1)]\ndp_array[0][0] = 1\n\nfor H_i, W_i in itertools.product(range(1, H + 1), range(W)):\n if (W_i == 0):\n if(W == 1):\n dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1]\n else:\n dp_array[H_i][0] = dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]\n elif (W_i == (W - 1)):\n dp_array[H_i][W - 1] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1]\n else:\n dp_array[H_i][W_i] = dp_array[H_i - 1][W_i - 1] * amida_list[W_i][0] + dp_array[H_i - 1][W_i] * amida_list[W_i][1] + dp_array[H_i - 1][W_i + 1] * amida_list[W_i][2]\n\nprint(dp_array[H][K - 1] % 1000000007)', 'import itertools\n\ndef fibonacci(n):\n if (n == 0):\n f_n = 1\n elif (n == 1):\n f_n = 1\n else:\n f_n = fibonacci(n-1) + fibonacci(n-2)\n\n return f_n\n\ndef X_amida_number(W, W_i):\n x_amida = "0" * (W - 1)\n left_x_amida = x_amida[:(W_i-2)] if(W_i-2 >= 0) else ""\n right_x_amida = x_amida[(W_i+1):]\n\n return fibonacci(len(left_x_amida) + 1) * fibonacci(len(right_x_amida) + 1)\n\ndef Y_amida_number(W, W_i):\n y_amida = "0" * (W - 1)\n left_y_amida = y_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_y_amida = y_amida[W_i+1:]\n\n return fibonacci(len(left_y_amida) + 1) * fibonacci(len(right_y_amida) + 1)\n\ndef Z_amida_number(W, W_i):\n z_amida = "0" * (W - 1)\n left_z_amida = z_amida[:W_i-1] if(W_i-1 >= 0) else ""\n right_z_amida = z_amida[W_i+2:]\n\n return fibonacci(len(left_z_amida) + 1) * fibonacci(len(right_z_amida) + 1)\n\ndef amida_all(amida_list, W):\n for i, j in itertools.product(range(W), range(3)):\n if(j == 0):\n amida_list[i][j] = X_amida_number(W, i)\n elif(j == 1):\n amida_list[i][j] = Y_amida_number(W, i)\n else:\n amida_list[i][j] = Z_amida_number(W, i)\n\n return amida_list\n\nH, W, K = map(int, input().split())\namida_list = [[0]*3 for i in range(W)]\namida_list = amida_all(amida_list, W)\n\ndp_array = [0 for i in range(W)]\ndp_array[0] = 1\n\nfor H_i in range(1, H + 1):\n new_dp_array = [0 for i in range(W)]\n for W_i in range(W):\n if (W_i == 0):\n if(W == 1):\n new_dp_array[0] = dp_array[0] * amida_list[0][1]\n else:\n new_dp_array[0] = dp_array[0] * amida_list[0][1] + dp_array[1] * amida_list[0][2]\n elif (W_i == (W - 1)):\n new_dp_array[W - 1] = dp_array[W_i - 1] * amida_list[W_i][0] + dp_array[W_i] * amida_list[W_i][1]\n else:\n new_dp_array[W_i] = dp_array[W_i - 1] * amida_list[W_i][0] + dp_array[W_i] * amida_list[W_i][1] + dp_array[W_i + 1] * amida_list[W_i][2]\n dp_array = list(new_dp_array)\n\nprint(dp_array[K - 1] % 1000000007)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s143784212', 's233306591', 's076359549']
[3192.0, 3192.0, 3192.0]
[19.0, 20.0, 19.0]
[2132, 2132, 2059]
p03222
u797994565
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['H,W,K = map(int,input().split())\nmod = 10**9+7\ndp = [[0 for i in range(W)] for j in range(H+1)]\ndp[0][0] = 1\ndp_x = [[0,0] for i in range(W)]\ndp_o = [[0,0] for i in range(W)]\ndp_x[0][0] = 1\ndp_x[0][1] = 1\nfor i in range(W-1):\n dp_x[i+1][0] = dp_x[i][0]+dp_x[i][1]\n dp_x[i+1][1] =dp_x[i][0]\ndp_o[0][0] = 1\ndp_o[0][1] = 0\nfor i in range(W-1):\n dp_o[i+1][0] = dp_o[i][0] + dp_o[i][1]\n dp_o[i+1][1] =dp_o[i][0]\ndp_o = [sum(e) for e in dp_o]\ndp_x = [sum(e) for e in dp_x]\ndp_o = [1]+dp_o\ndp_x = [1]+dp_x\nif W == 1:\n print(1)\n exit()\nfor h in range(0,H):\n print(dp)\n for w in range(W):\n if w == 0:\n dp[h+1][0] += dp[h][0]*dp_x[W-1-1]%mod\n dp[h+1][0] += dp[h][1]*dp_o[W-1-1]%mod\n elif w == W-1:\n dp[h+1][w] += dp[h][w]*dp_x[W-1-1]%mod\n dp[h+1][w] += dp[h][w-1]*dp_o[W-1-1]%mod\n else:\n \n dp[h+1][w] += dp[h][w]*dp_x[w-1]*dp_x[W-w-2]%mod\n #right connection\n dp[h+1][w] += dp[h][w+1]*dp_x[w-1]*dp_o[W-w-2]%mod\n #left connection\n dp[h+1][w] += dp[h][w-1]*dp_o[w-1]*dp_x[W-w-2]%mod\nprint(dp[H][K-1]%mod)\n', 'H,W,K = map(int,input().split())\nmod = 10**9+7\ndp = [[0 for i in range(W)] for j in range(H+1)]\ndp[0][0] = 1\ndp_x = [[0,0] for i in range(W)]\ndp_o = [[0,0] for i in range(W)]\ndp_x[0][0] = 1\ndp_x[0][1] = 1\nfor i in range(W-1):\n dp_x[i+1][0] = dp_x[i][0]+dp_x[i][1]\n dp_x[i+1][1] =dp_x[i][0]\ndp_o[0][0] = 1\ndp_o[0][1] = 0\nfor i in range(W-1):\n dp_o[i+1][0] = dp_o[i][0] + dp_o[i][1]\n dp_o[i+1][1] =dp_o[i][0]\ndp_o = [sum(e) for e in dp_o]\ndp_x = [sum(e) for e in dp_x]\ndp_o = [1]+dp_o\ndp_x = [1]+dp_x\nif W == 1:\n print(1)\n exit()\nfor h in range(0,H):\n for w in range(W):\n if w == 0:\n dp[h+1][0] += dp[h][0]*dp_x[W-1-1]%mod\n dp[h+1][0] += dp[h][1]*dp_o[W-1-1]%mod\n elif w == W-1:\n dp[h+1][w] += dp[h][w]*dp_x[W-1-1]%mod\n dp[h+1][w] += dp[h][w-1]*dp_o[W-1-1]%mod\n else:\n \n dp[h+1][w] += dp[h][w]*dp_x[w-1]*dp_x[W-w-2]%mod\n #right connection\n dp[h+1][w] += dp[h][w+1]*dp_x[w-1]*dp_o[W-w-2]%mod\n #left connection\n dp[h+1][w] += dp[h][w-1]*dp_o[w-1]*dp_x[W-w-2]%mod\nprint(dp[H][K-1]%mod)\n']
['Wrong Answer', 'Accepted']
['s556987285', 's514094365']
[3828.0, 3192.0]
[29.0, 19.0]
[1161, 1147]
p03222
u909643606
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['def comb(n):\n if n % 2 == 0:\n N = n / 2\n num = 2 ** N + 2 ** N - 1\n else:\n N = ( n + 1 ) / 2\n num = 2 ** N + 2 ** ( N - 1 ) - 1\n return int(num)\n\nd = 1000000007\n\nh, w, k = [int(i) for i in input().split()]\nkuji = [0 for i in range(w)]\nkuji[0] = 1\nprint(kuji)\nfor i in range(h):\n\n kuji2 = [0 for i in range(w)]\n for j in range(w):\n kuji2[j] = kuji[j] * max(comb(w-(j+1)-1), 1) * max(comb(j-1), 1)\n if j >= 1:\n kuji2[j] += kuji[j-1] * max(comb(w-(j+1)-1), 1) * max(comb(j-2), 1)\n if j <= w-2:\n kuji2[j] += kuji[j+1] * max(comb(w-(j+1)-2), 1) * max(comb(j-1), 1)\n for j in range(w):\n kuji[j] = kuji2[j] \n# print(kuji)\nprint(kuji[k-1] % d)', 'import itertools\n\nh, w, k = [int(i) for i in input().split()]\n\ndp = [[0 for i in range(w)] for j in range(h+1)]\ndp[0][0] = 1\n\nif w == 1:\n print(1)\n exit()\n\nfor i in range(1, h + 1):\n for kuji_list in itertools.product([0, 1], repeat = w - 1):\n for l in range(len(kuji_list)-1):\n if kuji_list[l] == 1 and kuji_list[l+1] == 1:\n break\n else:\n for j in range(w):\n\n if j == 0:\n if kuji_list[j] == 1:\n dp[i][j] += dp[i - 1][j + 1]\n else:\n dp[i][j] += dp[i - 1][j]\n\n elif j == w - 1:\n if kuji_list[j-1] == 1:\n dp[i][j] += dp[i - 1][j - 1]\n else:\n dp[i][j] += dp[i - 1][j]\n\n else:\n if kuji_list[j-1] == 1:\n dp[i][j] += dp[i - 1][j - 1]\n elif kuji_list[j] == 1:\n dp[i][j] += dp[i - 1][j + 1]\n else:\n dp[i][j] += dp[i - 1][j]\n\n dp[i][j] %= (10 ** 9 + 7)\n\nans = dp[-1][k - 1] % (10 ** 9 + 7)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s625456981', 's299005119']
[3064.0, 3064.0]
[23.0, 50.0]
[678, 1206]
p03222
u955251526
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['h, w, k = map(int, input().split())\ndp = [[0 for _ in range(w)] for _ in range(h+1)]\nperm = [1, 2, 3, 5, 8, 13, 21, 34]\nfor row in range(h+1):\n for col in range(w):\n if row == 0:\n dp[row][col] = int(col == 0)\n else:\n if col > 0:\n dp[row][col] += dp[row-1][col-1] * perm[max(0,col-2)] * perm[max(0, w-col-2)]\n if col < w - 1:\n dp[row][col] += dp[row-1][col+1] * perm[max(0,col-1)] * perm[max(0, w-col-3)]\n dp[row][col] += dp[row-1][col] * perm[max(0,col-1)] * perm[max(0,w-col-2)]\nprint(dp)\n', 'h, w, k = map(int, input().split())\ndp = [[0 for _ in range(w)] for _ in range(h+1)]\nperm = [1, 2, 3, 5, 8, 13, 21, 34]\nlaw = 1000000007\nfor row in range(h+1):\n for col in range(w):\n if row == 0:\n dp[row][col] = int(col == 0)\n else:\n if col > 0:\n dp[row][col] = (dp[row][col] + dp[row-1][col-1] * perm[max(0,col-2)] * perm[max(0, w-col-2)]) % law\n if col < w - 1:\n dp[row][col] = (dp[row][col] + dp[row-1][col+1] * perm[max(0,col-1)] * perm[max(0, w-col-3)]) % law\n dp[row][col] = (dp[row][col] + dp[row-1][col] * perm[max(0,col-1)] * perm[max(0,w-col-2)]) % law\nprint(dp[h][k-1])\n']
['Wrong Answer', 'Accepted']
['s421214634', 's158849835']
[3188.0, 3064.0]
[20.0, 20.0]
[581, 672]
p03222
u968846084
2,000
1,048,576
Amidakuji is a traditional method of lottery in Japan. To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left. For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.
['h,w,k=map(int,input().split())\nmod=10**9+7\nfib=[1,1]\nfor i in range(6):\n fib.append(fib[-2]+fib[-1])\nprint(fib)\ndp=[[0]*w for i in range(h+1)]\ndp[0][0]=1\nfor i in range(h):\n for j in range(w):\n if j==0:\n dp[i+1][j]=(dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)\n elif j==w-1:\n dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1])%(mod)\n else:\n dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)\nprint(dp[h][k-1])', 'h,w,k=map(int,input().split())\nmod=10**9+7\nfib=[1,1]\nfor i in range(6):\n fib.append(fib[-2]+fib[-1])\ndp=[[0]*w for i in range(h+1)]\ndp[0][0]=1\nfor i in range(h):\n for j in range(w):\n if w==1:\n dp[i+1][j]=dp[i][j]\n elif j==0:\n dp[i+1][j]=(dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)\n elif j==w-1:\n dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1])%(mod)\n else:\n dp[i+1][j]=(dp[i][j-1]*fib[j-1]*fib[w-j-1]+dp[i][j]*fib[j]*fib[w-j-1]+dp[i][j+1]*fib[j]*fib[w-j-2])%(mod)\nprint(dp[h][k-1])']
['Runtime Error', 'Accepted']
['s296248642', 's069631922']
[3064.0, 3064.0]
[19.0, 18.0]
[528, 558]
p03231
u027253287
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n, x = map(int, input().split())\na = sorted(list(map(int, input().split())))\nfor i in range(n) :\n x -= a[i]\n if(x == 0) : \n print(i+1)\n exit()\n elif(a[i] > x) : print(i)', 'def gcm(a, b) :\n while(b) :\n a, b = b, a%b\n return a\ndef lcm(a, b) :\n return int(a*b/gcm(a, b))\n\nn, m = map(int, input().split())\ns = list(str(input()))\nt = list(str(input()))\ns_out = []\nt_out = []\nfor i in range(int(gcm(n, m))) :\n s_out.append(s[i*int(n/gcm(n, m))])\nfor i in range(int(gcm(n, m))) :\n t_out.append(t[i*int(m/gcm(n, m))])\n \nif(s_out == t_out) : print(lcm(n, m))\nelse : print(-1)']
['Runtime Error', 'Accepted']
['s526362464', 's121167396']
[3316.0, 4824.0]
[18.0, 49.0]
[178, 403]
p03231
u030726788
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(m,n):\n while (m % n != 0):\n n,m = m%n,n\n return(n)\n\ndef lcm(m,n):\n return(m * n // gcd(m,n))\n\nn,m = map(int,input().split())\n\ns = input()\nt = input()\n\n\ng = gcd(m,n)\n\nif(g in [n,m]):\n print(-1)\nelse:\n x = lcm(m,n)\n a = x // n\n b = x // m\n for i in range(x//n):\n ai = 1 + a * i\n bi = 1 + b * i\n if(s[ai] != t[bi]):\n print(-1)\n exit()\n print(lcm(m,n))', 'def gcd(m,n):\n while (m % n != 0):\n n,m = m%n,n\n return(n)\n\ndef lcm(m,n):\n return(m * n // gcd(m,n))\n\nn,m = map(int,input().split())\n\ns = input()\nt = input()\n\n\ng = gcd(m,n)\n\nif(g in [n,m]):\n print(-1)\nelse:\n x = lcm(m,n)\n a = x // n\n b = x // m\n for i in range(n//b):\n ai = b * i\n bi = a * i\n if(s[ai] != t[bi]):\n print(-1)\n exit()\n print(lcm(m,n))']
['Runtime Error', 'Accepted']
['s805898739', 's675119975']
[3316.0, 3316.0]
[17.0, 19.0]
[433, 425]
p03231
u038676814
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m = (int(i) for i in input().split())\ns = input()\nt = input()\ndef gcd(a,b):\n\tif a%b: return gcd(b,a%b)\n\telse: return b\ng = gcd(n,m)\nprint(g)', 'n,m = (int(i) for i in input().split())\ns = input()\nt = input()\ndef gcd(a,b):\n\tif a%b: return gcd(b,a%b)\n\telse: return b\ng = gcd(n,m)\nng, mg = n//g, m//g\nif all(s[i*ng] == t[i*mg] for i in range(g)) :\n print(n*m//g)\nelse :\n print(-1)']
['Wrong Answer', 'Accepted']
['s957792095', 's024563217']
[3316.0, 3316.0]
[18.0, 18.0]
[142, 239]
p03231
u067983636
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nR = np.zeros(N + 1, dtype="int32")\nP = np.ones(N + 1, dtype="int32")\nmod = 10 ** 9 + 7\n\ndef rev(a):\n return pow(a, mod - 2, mod)\n \nfor n in range(N + 1):\n R[n] = (R[n - 1] + rev(n)) % mod\n if n != 0:\n P[n] = P[n - 1] * n\n \nC = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]\n\nprint(sum([a * c for a, c in zip(C, A)]) * P[N] % mod)\n', 'import numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nR = np.zeros(N + 1, dtype=int)\nP = np.ones(N + 1, dtype=int)\nmod = 10 ** 9 + 7\n\ndef rev(a):\n return pow(a, mod - 2, mod)\n \nfor n in range(N + 1):\n R[n] = (R[n - 1] + rev(n)) % mod\n if n != 0:\n P[n] = P[n - 1] * n\n \nC = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]\n\nprint(sum([a * c for a, c in zip(C, A)]) * P[N] % mod)\n', 'N, M = map(int, input().split())\nS = input()\nT = input()\n\ndef f(a, b):\n if b < a:\n a, b = b, a\n \n while b % a != 0:\n a, b = b % a, a\n return a\n\nif S[0] != T[0]:\n print(-1)\n\nelse:\n p = f(N, M)\n k = N // p\n l = M // p\n\n for n in range(p):\n if S[n * k] != T[n * l]:\n print(-1)\n break\n else:\n print(N * M // p)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s726240007', 's901755156', 's079852448']
[13368.0, 14416.0, 3316.0]
[163.0, 149.0, 19.0]
[436, 428, 386]
p03231
u077291787
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['# AGC028\nfrom fractions import gcd\n\n\ndef main():\n n, m = tuple(map(int, input().rstrip().split()))\n S, T = tuple(input().rstrip() for _ in range(2))\n l = n // gcd(n, m) * m\n x = [""] * l\n for i in range(n): # place S in x\n j = (l // n) * i\n x[j] = S[i]\n\n for i in range(m): # check T adapts to x or not\n j = (l // m) * i\n if x[j] not in ("", T[i]):\n print(-1)\n break\n else:\n print(l)\n\n\nif __name__ == "__main__":\n main()', '# AGC028A - Two Abbreviations\ndef gcd(a, b):\n while b > 0:\n a, b = b, a % b\n return a\n\n\ndef main():\n n, m = tuple(map(int, input().rstrip().split()))\n S, T = tuple(input().rstrip() for _ in range(2))\n g = gcd(n, m)\n flg = S[:: n // g] == T[:: m // g]\n print(n // g * m if flg else -1)\n\n\nif __name__ == "__main__":\n main()']
['Runtime Error', 'Accepted']
['s479046608', 's495529374']
[189788.0, 3316.0]
[180.0, 17.0]
[503, 352]
p03231
u088863512
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['# -*- coding: utf-8 -*-\nimport sys\nfrom collections import deque, defaultdict\nfrom math import sqrt, factorial, gcd\n# def input(): return sys.stdin.readline()[:-1] # warning not \\n\n\n\n\n\ndef solve():\n n, m = [int(x) for x in input().split()]\n s = input()\n t = input()\n g = gcd(n, m)\n ans = n * m // g\n a, b = n // g, m // g\n x, y = 0, 0\n for i in range(g):\n if s[x] != x[y]:\n print(-1)\n return\n x += a\n y += b\n print(ans)\n \nt = 1\n# t = int(input())\nfor case in range(1,t+1):\n ans = solve()\n\n\n"""\n\n2 2 2 2 2\n\n"""\n', '# -*- coding: utf-8 -*-\nimport sys\nfrom collections import deque, defaultdict\nfrom math import sqrt, factorial, gcd\n# def input(): return sys.stdin.readline()[:-1] # warning not \\n\n\n\n\n\ndef solve():\n n, m = [int(x) for x in input().split()]\n s = input()\n t = input()\n g = gcd(n, m)\n ans = n * m // g\n a, b = n // g, m // g\n x, y = 0, 0\n for i in range(g):\n if s[x] != t[y]:\n print(-1)\n return\n x += a\n y += b\n print(ans)\n \nt = 1\n# t = int(input())\nfor case in range(1,t+1):\n ans = solve()\n\n\n"""\n\n2 2 2 2 2\n\n"""\n']
['Runtime Error', 'Accepted']
['s267656103', 's342900034']
[9616.0, 9584.0]
[30.0, 34.0]
[724, 724]
p03231
u092781267
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['input_lines = input().split()\nN = int(input_lines[0])\nM = int(input_lines[1])\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b > 0:\n a, b = b, a%b\n return a\n\ndef lcm(a, b):\n return a*b/gcd(a, b)\n\nL = int(lcm(N,M))\nx = 1\ncount = 0\nif N >= M:\n big = N\n small = M\nelse:\n big = M\n small = N\n \nwhile True:\n k = L*x\n flag = 1\n for j in range(small):\n left = 0\n right = big - 1\n while left <= right:\n mid = (left+right)/2\n if((mid-1)*k/big+1 == (j-1)*k/small+1):\n if(S[mid-1] != T[j-1]):\n flag = 0\n count += 1\n break\n else:\n break\n elif((mid-1)*k/big+1 > (j-1)*k/small+1):\n right = mid - 1\n else:\n left = mid + 1\n if(flag == 1):\n print(k)\n break\n if(count == 2):\n print(-1)\n break\n x += 1\n', 'input_lines = input().split()\nN = int(input_lines[0])\nM = int(input_lines[1])\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b > 0:\n a, b = b, a%b\n return a\n\ndef lcm(a, b):\n return a*b/gcd(a, b)\n\nL = int(lcm(N,M))\nx = 1\ncount = 0\nwhile True:\n k = L*x\n flag = 1\n starti = 0\n startj = 0\n for i in range(starti, N):\n for j in range(startj, M):\n hoge = i*k/N+1\n fuga = j*k/M+1\n if(hoge < fuga):\n startj = j - 1\n break\n elif(hoge == fuga):\n if(S[i] != T[j]):\n flag = 0\n count += 1\n break\n if(flag == 0):\n break\n if(flag == 1):\n print(k)\n break\n if(count == 2):\n print(-1)\n break\n x += 1\n']
['Runtime Error', 'Accepted']
['s819476007', 's731798163']
[3316.0, 3444.0]
[1805.0, 203.0]
[950, 811]
p03231
u124498235
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['from collections import defaultdict\nimport math\nn,m = map(int, input().split())\ns = input()\nt = input()\n\nans = int((n*m)/math.gcd(n,m))\ng = math.gcd(n,m)\nfor i in range(g):\n print (i*(n//g),i*(m//g))\n if s[i*(n//g)] != t[i*(m//g)]:\n print (-1)\n exit()\nprint (ans)', 'import math\nn,m = map(int, input().split())\ns = input()\nt = input()\n\nans = int((n*m)/math.gcd(n,m))\ng = math.gcd(n,m)\nfor i in range(g):\n if s[i*(n//g)] != t[i*(m//g)]:\n print (-1)\n exit()\nprint (ans)']
['Wrong Answer', 'Accepted']
['s667156472', 's641192478']
[9400.0, 9224.0]
[34.0, 29.0]
[271, 207]
p03231
u125205981
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import platform\nver = platform.python_version_tuple()\nif int(ver[1]) < 5:\n from fractions import gcd\nelse:\n from math import gcd\nfrom sys import stdin\n\ndef main():\n N, M = map(int, input().split())\n S = input()\n T = input()\n\n L = lcm(N, M)\n ans = [None] * 10000000000\n for i in range(N):\n j = i * (L // N)\n if ans[j] is None or ans[j] == S[i]:\n ans[j] = S[i]\n else:\n print(-1)\n return\n for i in range(M):\n j = i * (L // M)\n if ans[j] is None or ans[j] == T[i]:\n ans[j] = T[i]\n else:\n print(-1)\n return\n print(L)\n\ninput = lambda: stdin.readline().rstrip()\nlcm = lambda x, y: x * y // gcd(x, y)\nmain()\n', 'import platform\nver = platform.python_version_tuple()\nif int(ver[1]) < 5:\n from fractions import gcd\nelse:\n from math import gcd\n\nfrom sys import stdin\nfrom bisect import bisect\n\ndef main():\n N, M = map(int, input().split())\n S = input()\n T = input()\n\n L = lcm(N, M)\n s = [i * (L // N) + 1 for i in range(N)]\n t = [i * (L // M) + 1 for i in range(M)]\n for i, x in enumerate(s):\n n = bisect(t, x)\n if t[n-1] == x:\n if T[n-1] != S[i]:\n print(-1)\n return\n print(L)\n\ninput = lambda: stdin.readline().rstrip()\nlcm = lambda x, y: x * y // gcd(x, y)\nmain()\n']
['Runtime Error', 'Accepted']
['s863498458', 's336932938']
[5712.0, 13376.0]
[46.0, 109.0]
[738, 635]
p03231
u130037310
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N,M = map(int,input().split())\nS = input()\nT = input()\nans = 0\na = 2\n\nif S[0] != T[0]:ans = -1\n\nelif N % M != 0 and M % N != 0:\n if N >= M:\n while True:\n if N * a % M == 0:\n ans = N * a\n b = int(N*a/M)\n for i in range(M):\n if T[i] != S[b*i]:\n ans = -1\n break\n break\n else:\n a += 1\n elif N < M:\n while True:\n if M * a % N == 0:\n ans = M * a\n b = int(M*a/N)\n for i in range(N):\n if S[i] != T[b*i]:\n ans = -1\n break\n break\n else:\n a += 1\n\nelif N % M == 0:\n b = int(N/M)\n ans = N\n for i in range(M):\n if T[i] != S[b*i]:\n ans = -1\n break \n\nelif M % N == 0:\n b = int(M/N)\n ans = M\n for i in range(N):\n if S[i] != T[b*i]:\n ans = -1\n break \n\nprint(ans)\n', 'N,M = map(int,input().split())\nS = input()\nT = input()\nans = 0\na = 2\n\nif S[0] != T[0]:ans = -1\n\nelif N % M != 0 and M % N != 0:\n if N >= M:\n while True:\n if N * a % M == 0:\n ans = N * a\n b = int(N*a/M)\n for i in range(int(N/b)):\n if T[a*i] != S[b*i]:\n ans = -1\n break\n break\n else:\n a += 1\n elif N < M:\n while True:\n if M * a % N == 0:\n ans = M * a\n b = int(M*a/N)\n for i in range(int(M/b)):\n if T[b*i] != S[a*i]:\n ans = -1\n break\n break\n else:\n a += 1\n\nelif N % M == 0:\n b = int(N/M)\n ans = N\n for i in range(M):\n if T[i] != S[b*i]:\n ans = -1\n break \n\nelif M % N == 0:\n b = int(M/N)\n ans = M\n for i in range(N):\n if S[i] != T[b*i]:\n ans = -1\n break \n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s595788977', 's801972659']
[3444.0, 3444.0]
[33.0, 32.0]
[1069, 1087]
p03231
u131881594
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m=map(int,input().split())\ns=input()\nt=input()\n\ndef gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nG=gcd(n,m)\na,b = n//G,m//G\ns=s[1::a]\nt=t[1::b]\nif s==t: print(a*b*G)\nelse: print(-1)', 'n,m=map(int,input().split())\ns=input()\nt=input()\n\ndef gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nG=gcd(n,m)\na,b = n//G,m//G\ns=s[0::a]\nt=t[0::b]\nif s==t: print(a*b*G)\nelse: print(-1)']
['Wrong Answer', 'Accepted']
['s640752945', 's403917428']
[9284.0, 9380.0]
[26.0, 29.0]
[193, 193]
p03231
u134019875
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n if a < b:\n a, b = b, a\n while a % b != 0:\n a, b = b, a % b\n return b\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nn, m = map(int, input().split())\ns = str(input())\nt = str(input())\nl = lcc(n, m)\nL = [0] * l\nfor i in range(n):\n L[i*(l//n)] = s[i]\nfor j in range(m):\n if L[j*(l//m)] == 0:\n L[j*(l//m)] = t[j]\n elif L[j*(l//m)] == t[j]:\n pass\n else:\n print(-1)\n break\nelse:\n print(l)\n', 'def gcd(a, b):\n if a < b:\n a, b = b, a\n while a % b != 0:\n a, b = b, a % b\n return b\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nn, m = map(int, input().split())\ns = str(input())\nt = str(input())\ng = gcd(n, m)\nl = lcm(n, m)\nfor i in range(g):\n if s[i*n//g] != t[i*m//g]:\n print(-1)\n break\nelse:\n print(l)\n']
['Runtime Error', 'Accepted']
['s409913409', 's196290684']
[3316.0, 3316.0]
[18.0, 19.0]
[465, 351]
p03231
u136647933
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a,b):\n while b>0:\n a,b=b,a%b\n return a\n\nx,y=map(int,input().split())\nS=input()\nT=input()\nGCD=gcd(x,y)\nLCM=(x * y) // GCD\n\nx_new=x//GCD\ny_new=y//GCD\nfor i in range(0,GCD-1):\n if S[(x_new)*i]==T[(y_new)*i]:\n result=LCM\n else:\n result=-1\n break\nprint(result)', 'def gcd(a,b):\n while b>0:\n a,b=b,a%b\n return a\n\nx,y=map(int,input().split())\nS=input()\nT=input()\nGCD=gcd(x,y)\nLCM=(x * y) // GCD\n\nx_new=x//GCD\ny_new=y//GCD\nfor i in range(0,GCD):\n if S[(x_new)*i]==T[(y_new)*i]:\n result=LCM\n else:\n result=-1\n break\nprint(result)']
['Runtime Error', 'Accepted']
['s712298245', 's192829111']
[3316.0, 3316.0]
[20.0, 19.0]
[279, 277]
p03231
u151625340
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N,M = map(int,input().split())\nS = input()\nT = input()\nflag = True\ndef lcm(a, b): \n def gcd(a, b): \n while b:\n a, b = b, a % b\n return a\n return a * b // gcd(a, b)\nL = lcm(N,M)\n\nif S[0] == T[0 and S[N-1] == T[M-1]:\n flag = True\nelse:\n flag = False\nif flag:\n print(L)\nelse:\n print(-1)\n', 'N,M = map(int,input().split())\nS = input()\nT = input()\nflag = True\ndef lcm(a, b): \n def gcd(a, b): \n while b:\n a, b = b, a % b\n return a\n return a * b // gcd(a, b)\nL = lcm(N,M)\n\nif S[0] == T[0] and S[N-1] == T[M-1]:\n flag = True\nelse:\n flag = False\nif flag:\n print(L)\nelse:\n print(-1)\n', 'N,M = map(int,input().split())\nS = input()\nT = input()\nflag = True\ndef lcm(a, b): \n def gcd(a, b): \n while b:\n a, b = b, a % b\n return a\n return a * b // gcd(a, b)\nL = lcm(N,M)\ndef gcd(a, b): \n while b:\n a, b = b, a % b\n return a\n\nflag = True\nfor i in range(gcd(N,M)):\n if S[i*N//gcd(N,M)] == T[i*M//gcd(N,M)] and flag:\n pass\n else:\n flag = False\nif flag:\n print(L)\nelse:\n print(-1)\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s361027812', 's523684747', 's914907282']
[3060.0, 3316.0, 3316.0]
[18.0, 18.0, 39.0]
[599, 600, 504]
p03231
u166696759
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n if b > a:\n gcd(b, a)\n while b:\n\t a, b = b, a % b\n return a\n\nn,m = map(int, input().split())\ns = input()\nt = input()\n\nl = n * m // gcd(n, m)\na = l // n\nb = l // m\n#print(a, b)\n#a(i-1) = b(j-i) -> ai = bj + (a-b)\nres = False\nclear_all = True\nfor i in range(1,n+1):\n if (a*i - (a-b)) % b != 0:\n j = a * i - (a-b)\n if not s[i-1] == t[j-1]:\n clear_all = False\nif clear_all:\n res = True\nif res:\n print(l)\nelse:\n print(-1)\n ', 'def gcd(a, b):\n if b > a:\n gcd(b, a)\n while b:\n\t a, b = b, a % b\n return a\n\nn,m = map(int, input().split())\ns = input()\nt = input()\n\nl = n * m // gcd(n, m)\na = l // n\nb = l // m\n#print(a, b)\n#a(i-1) = b(j-i) -> ai = bj + (a-b)\nres = False\nclear_all = True\nfor i in range(1,n+1):\n if (a*i - (a-b)) % b == 0:\n j = (a * i - (a-b)) // b\n if not s[i-1] == t[j-1]:\n clear_all = False\nif clear_all:\n res = True\nif res:\n print(l)\nelse:\n print(-1)\n ']
['Runtime Error', 'Accepted']
['s619519123', 's449194811']
[3316.0, 3316.0]
[29.0, 46.0]
[496, 503]
p03231
u170201762
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['from math import gcd\nN,M = map(int,input().split())\ns = input()\nt = input()\ng = gcd(N,M)\nl = N*M//g\n\nn = N//g\nm = M//g\n\nans = l\n\nfor i in range(l):\n if s[i*n]!=t[i*m]:\n ans = -1\n break\nprint(ans)\n\n', 'import math\nN,M = map(int,input().split())\nS = input()\nT = input()\n\nflag = True\nfor n in range(N):\n if (M*n)%N==0:\n m = (M*n)//N\n flag = (S[n]==T[m])\n if !flag:\n break\nif flag:\n print(N*M//math.gcd(N,M))\nelse:\n print(-1)\n', 'def gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\n \nN,M = map(int,Input().split())\ns = input()\nt = input()\ng = gcd(N,M)\nl = N*M//g\n\nn = N//g\nm = M//g\n\nans = l\n\nfor i in range(g):\n if s[i*n]!=t[i*m]:\n ans = -1\n break\nprint(ans)', 'def gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\nN,M = map(int,input().split())\nS = input()\nT = input()\n \nflag = True\nfor n in range(N):\n if M*n%N==0:\n m = M*n//N\n flag = S[n]==T[m]\n if not flag:\n break\nif not flag:\n print(-1)\nelse:\n print(N*M//gcd(N,M))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s113870358', 's132291642', 's144805419', 's061658038']
[3060.0, 2940.0, 3064.0, 3316.0]
[17.0, 25.0, 19.0, 34.0]
[214, 262, 249, 291]
p03231
u177040005
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a,b):\n if b == 0:\n return abs(a)\n else:\n return gcd(b, a%b)\n\nN,M = map(int, input().split())\nS = input()\nT = input()\n\nprint(-1)\nexit()\n', 'import bisect\n\ndef gcd(a,b):\n if b == 0:\n return abs(a)\n else:\n return gcd(b, a%b)\n\nN,M = map(int, input().split())\nS = input()\nT = input()\n\n\nif S[0] != T[0]:\n print(-1)\n exit()\n\nif len(S) == len(T):\n if S == T:\n print(len(S))\n else:\n print(-1)\n exit()\n\ngcd1 = gcd(len(S), len(T))\nlcm = len(S)*len(T) // gcd1\n\nSS = []\nTT = []\ni = 0\nj = 0\nwhile i < N:\n SS.append(i*lcm//N + 1)\n i += 1\nwhile j < M:\n TT.append(j*lcm//M + 1)\n j += 1\n\nind = 0\nind_max = j-1\n\nfor i,v in enumerate(SS):\n ind = bisect.bisect_left(TT, v,ind, j)\n if ind == j:\n break\n# print(ind)\n if TT[ind] == v:\n if S[i] == T[ind]:\n continue\n else:\n print(-1)\n exit()\nprint(lcm)\n']
['Wrong Answer', 'Accepted']
['s277061772', 's592357057']
[3316.0, 11036.0]
[17.0, 137.0]
[163, 766]
p03231
u189575640
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import sys\nN,M = [int(n) for n in input().split()]\nS = str(input())\nT = str(input())\n\n# N < M\ndef gcd(N,M):\n if(N > M):\n tmp = N\n N = M\n M = tmp\n r = M % N\n while(r != 0):\n M = N\n N = r\n r = M%N\n return N\n\ndef lcm(N,M):\n return(N*M/gcd(N,M))\n\nif (N % M == 0):\n if S == T:\n print(M)\n else:\n p = int(N/M)\n for i in range(M):\n if T[i] != S[i*p]:\n print(-1)\n sys.exit()\n print(N)\nelif (M % N == 0):\n if S == T:\n print(M)\n else:\n p = int(M/N)\n for i in range(N):\n if S[i] != T[i*p]:\n print(-1)\n sys.exit()\n print(M)\nelse:\n\n print(-1)\n', 'import sys\nN,M = [int(n) for n in input().split()]\nS = str(input())\nT = str(input())\n\n# N < M\ndef gcd(N,M):\n if(N > M):\n tmp = N\n N = M\n M = tmp\n r = M % N\n while(r != 0):\n M = N\n N = r\n r = M%N\n return N\n\ndef lcm(N,M):\n return(N*M/gcd(N,M))\n\nif (N % M == 0):\n if S == T:\n print(M)\n else:\n p = int(N/M)\n for i in range(M):\n if T[i] != S[i*p]:\n print(-1)\n sys.exit()\n print(N)\nelif (M % N == 0):\n if S == T:\n print(M)\n else:\n p = int(M/N)\n for i in range(N):\n if S[i] != T[i*p]:\n print(-1)\n sys.exit()\n print(M)\nelse:\n mngcd = gcd(N,M)\n k = int(N/mngcd)\n m = int(M/mngcd)\n for i in range(mngcd):\n if S[i*k] != T[i*m]:\n print(-1)\n sys.exit()\n print(int(lcm(N,M)))\n']
['Wrong Answer', 'Accepted']
['s057186267', 's370467307']
[3444.0, 3444.0]
[18.0, 18.0]
[739, 913]
p03231
u193264896
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["import sys\nfrom fractions import gcd\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\ndef main():\n N, M = map(int, readline().split())\n S = readline().decode('utf-8')\n T = readline().decode('utf-8')\n lcm = N*M//gcd(N,M)\n if lcm==N or lcm==M:\n print(-1)\n else:\n print(lcm)\n\n\nif __name__ == '__main__':\n main()", "import sys\nimport math\nread = sys.stdin.read\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\ndef main():\n N, M = map(int, readline().split())\n S = readline().rstrip().decode('utf-8')\n T = readline().rstrip().decode('utf-8')\n\n G = math.gcd(N, M)\n\n A = ''.join(S[::N // G])\n B = ''.join(T[::M // G])\n\n if A == B:\n answer = N * M // G\n else:\n answer = -1\n print(answer)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s555289451', 's124364070']
[5244.0, 9448.0]
[36.0, 28.0]
[400, 506]
p03231
u197704813
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['print(-1)', 'def gcd(a, b):\n while b > 0:\n a, b = b, a%b\n return a\n\nN,M = map(int,input().split(" "))\nS = input()\nT = input()\nN = len(S)\nM = len(T)\nx = gcd(N,M)\ny = int(N*M/x)\n\nfor i in range(x):\n if S[int(i*y/M)] == T[int(i*y/N)]:\n continue\n else:\n print(-1)\n exit()\nprint(y)\n']
['Wrong Answer', 'Accepted']
['s764132567', 's002793207']
[2940.0, 3316.0]
[17.0, 19.0]
[9, 296]
p03231
u199295501
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import fraction\ndef lcm(x, y):\n return (x * y) // math.gcd(x, y)\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\nlcm_num = lcm(N,M)\n\nX_s = ["" for i in range(lcm_num)]\nX_t = ["" for i in range(lcm_num)]\n\n# print(X_s,X_t)\n\nfor i in range(N):\n tmp = i*lcm_num // N + 1\n X_s[tmp-1] = S[i]\n\n\nfor i in range(M):\n tmp = i*lcm_num // M + 1\n X_t[tmp-1] = T[i]\n\n# print(X_s,X_t)\n\nfor s,t in zip(X_s,X_t):\n if s == "" or t == "" :\n continue\n elif s == t:\n continue\n else:\n print(-1)\n exit()\n\nprint(lcm_num)\n', 'def gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\n\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\nlcm_num = lcm(N,M)\nlN = lcm_num // N\nlM = lcm_num // M\ngcd_num = lN * lM\n\nfor i in range(0,lcm_num,gcd_num):\n if S[i//lN] == T[i//lM]:\n continue\n else:\n print(-1)\n exit()\n\nprint(lcm_num)\n']
['Runtime Error', 'Accepted']
['s510276890', 's595555427']
[3188.0, 3316.0]
[19.0, 19.0]
[560, 374]
p03231
u213580455
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n c = a%b\n while(c != 0):\n a = b\n b = c\n c = a%b\n return b\n\ndef answer(s, t):\n a = len(s)\n b = len(t)\n if a[0] != b[0]:\n return -1\n if a < b:\n temp = a\n a = b\n b = temp\n gcdAB = gcd(a, b)\n if gcdAB == 1:\n return a*b\n else:\n stack = 0\n sl = (gcdAB * (a//gcdAB) * (b//gcdAB))\n aJump = sl//a\n bJump = sl//b\n for i in range(b):\n if stack%aJump == 0:\n if s[stack//aJump] != t[i]:\n return -1\n stack = bJump*(i+1)\n return sl\n \n\nsl, tl = map(int, input().split())\ns = input()\nt = input()\nprint(answer(s, t))\n', 'def gcd(a, b):\n c = a%b\n while(c != 0):\n a = b\n b = c\n c = a%b\n return b\n\ndef answer(s, t):\n a = len(s)\n b = len(t)\n if s[0] != t[0]:\n return -1\n if a < b:\n temp = a\n a = b\n b = temp\n temp = s\n s = t\n t = temp\n gcdAB = gcd(a, b)\n if gcdAB == 1:\n return a*b\n else:\n stack = 0\n sl = (gcdAB * (a//gcdAB) * (b//gcdAB))\n aJump = sl//a\n bJump = sl//b\n for i in range(b):\n if stack%aJump == 0:\n if s[stack//aJump] != t[i]:\n return -1\n stack = bJump*(i+1)\n return sl\n \n\nsl, tl = map(int, input().split())\ns = input()\nt = input()\nprint(answer(s, t))\n']
['Runtime Error', 'Accepted']
['s023511928', 's502669739']
[3444.0, 3444.0]
[17.0, 28.0]
[713, 761]
p03231
u242525751
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b): \n if b == 0: return a\n return gcd(b, a % b)\nn, m = map(int, input().split())\ng = gcd(n, m)\nl = n * m / g\nn = n/g\nm = m/g\ns = list(str(input()))[::int(n)]\nt = list(str(input()))[::int(m)]\nif s == t:\n print(l)\nelse:\n print("-1")', 'def gcd(a, b): \n if b == 0: return a\n return gcd(b, a % b)\nn, m = map(int, input().split())\ng = gcd(n, m)\nl = n * m / g\nn = n/g\nm = m/g\ns = list(str(input()))[::int(n)]\nt = list(str(input()))[::int(m)]\nif s == t:\n print(l)\nelse:\n print("-1")', 'def gcd(a, b): \n if b == 0: return a\n return gcd(b, a % b)\nn, m = map(int, input().split())\ng = gcd(n, m)\nl = n * m // g\nn = n//g\nm = m//g\ns = list(str(input()))[::int(n)]\nt = list(str(input()))[::int(m)]\nif s == t:\n print(l)\nelse:\n print("-1")']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s611609941', 's729376184', 's654486657']
[4160.0, 4160.0, 4160.0]
[20.0, 22.0, 20.0]
[247, 247, 250]
p03231
u254871849
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["# 2019-11-28 02:28:10(JST)\nimport sys\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef main():\n n, m = map(int, sys.stdin.readline().split())\n s, t = sys.stdin.read().split()\n\n g = gcd(n, m)\n l = lcm(n, m)\n\n if g == 1:\n if s[0] == s[1]:\n ans = l\n else:\n ans = -1\n else:\n for i in range(g):\n if s[i * n // g] == t[i * m // g]:\n continue\n else:\n ans = -1\n break\n else:\n ans = l\n \n print(ans)\n\nif __name__ == '__main__':\n main()\n", "# 2019-11-28 02:28:10(JST)\nimport sys\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef main():\n n, m = map(int, sys.stdin.readline().split())\n s, t = sys.stdin.read().split()\n\n g = gcd(n, m)\n l = lcm(n, m)\n\n if g == 1:\n if s[0] == s[1]:\n ans = l\n else:\n ans = -1\n else:\n for i in range(g):\n if s[i * n // g] == t[i * m // g]:\n continue\n else:\n ans = -1\n break\n else:\n ans = l\n \n print(ans)\n\nif __name__ == '__main__':\n main()\n", "# 2019-11-28 02:28:10(JST)\nimport sys\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef main():\n n, m = map(int, sys.stdin.readline().split())\n s, t = sys.stdin.read().split()\n\n g = gcd(n, m)\n l = lcm(n, m)\n\n if g == 1:\n if s[0] == s[1]:\n ans = l\n else:\n an = -1\n else:\n for i in range(g):\n if s[i * n // g] == t[i * m // g]:\n continue\n else:\n ans = -1\n break\n else:\n ans = l\n \n print(ans)\n\nif __name__ == '__main__':\n main()\n", "# 2019-11-28 02:28:10(JST)\nimport sys\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef main():\n n, m = map(int, sys.stdin.readline().split())\n s, t = sys.stdin.read().split()\n\n g = gcd(n, m)\n l = lcm(n, m)\n\n if g == 1:\n if s[0] == s[1]:\n ans = l\n else:\n for i in range(g):\n if s[i * n // g] == t[i * m // g]:\n continue\n else:\n ans = -1\n break\n else:\n ans = l\n \n print(ans)\n\nif __name__ == '__main__':\n main()\n", "# 2019-11-28 02:28:10(JST)\nimport sys\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\ndef main():\n n, m = map(int, sys.stdin.readline().split())\n s, t = sys.stdin.read().split()\n\n g = gcd(n, m)\n l = lcm(n, m)\n\n for i in range(g):\n if s[i * n // g] == t[i * m // g]:\n continue\n ans = -1\n break\n else:\n ans = l\n \n print(ans)\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s359728304', 's429076448', 's809669475', 's959743044', 's918182165']
[3444.0, 3444.0, 3444.0, 3444.0, 3444.0]
[18.0, 18.0, 19.0, 22.0, 18.0]
[649, 649, 648, 614, 490]
p03231
u257374434
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\nN,M= list(map(int,input().split()))\nS =input()\nT=input()\n\n\nL = N*M//math.gcd(N,M)\n\nd = dict()\n\nfor i in range(N):\n print(1+(L//N)*i)\n index = 1+(L//N)*i\n d[index] = S[i]\n\nfor j in range(M):\n index = (1+(L//M)*j)\n if index in d:\n if d[index]!=T[j]:\n print(-1)\n exit()\nprint(L)\n\n\n', 'import math\n\nN, M = list(map(int, input().split()))\nS = input()\nT = input()\ndef gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return a\n c = a % b\n return gcd(b, c)\n\nL = N * M // gcd(N, M)\n\nd = dict()\n\nfor i in range(N):\n index = 1 + (L // N) * i\n d[index] = S[i]\n\nfor j in range(M):\n index = (1 + (L // M) * j)\n if index in d:\n if d[index] != T[j]:\n print(-1)\n exit()\nprint(L)\n']
['Runtime Error', 'Accepted']
['s511395989', 's192308334']
[3316.0, 15396.0]
[18.0, 78.0]
[334, 446]
p03231
u305018585
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = map(int, input().split(\' \'))\nS = input()\nT = input()\nimport numpy as np\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n \nL = lcm(N,M)\n#max_n = max(N,M)\n\nx1 = [1] + [(i *(L/N)) +1for i in range(1, N)] \nx2 = [1]+ [(i *(L/M)) +1for i in range(1, M)] \nx3 = set(x1) & set(x2) \nif len(x3) ==1:\n print("a") \n print(L)\nelse :\n if all([S[int((i-1)/(L/N))] == T[int((i -1)/(L/M))] for i in x3 if i != 1]) :\n print(L)\n else :\n print(-1)', "N, M = map(int, input().split(' '))\ndef gcd(a, b):\n a, b = (a, b) if a >= b else (b, a)\n while b > 0:\n a, b = b, a % b\n return a\n\nS = input()\nT = input()\ng = gcd(N, M)\n#print('gcd',g)\n#print('',N//g,M//g)\n#print(S[0::N//g] ,T[0::M//g])\nif S[0::N//g] == T[0::M//g]:\n print(N*M//g)\nelse:\n print(-1)"]
['Wrong Answer', 'Accepted']
['s032745878', 's822324271']
[26408.0, 3316.0]
[499.0, 21.0]
[546, 319]
p03231
u328207927
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['\ndef gcd(a, b):\n while b:\n a,b=b,a%b\n return a\ndef lcm(x,y):\n return (x * y) // gcd(x, y)\n\ndef atwo(n,m,s,t):\n l=lcm(n,m)\n gc=gcd(n,m)\n if s[0::n//gc]==t[0::m//gc]:\n print(l)\n exit()\n else:\n print(-1)\n exit()', 'def gcd(a, b):\n while b:\n a,b = b,a%b\n return a\n\ndef lcm(x,y):\n return (x * y) // gcd(x, y)\n\ndef atwo(n,m,s,t):\n l=lcm(n,m)\n gc=gcd(n,m)\n if s[0::n//gc]==t[0::m//gc]:\n print(l)\n exit()\n else:\n print(-1)\n exit()\n\nn,m=map(int,input().split())\nprint(atwo(n,m,input(),input()))']
['Wrong Answer', 'Accepted']
['s435866753', 's973060273']
[3060.0, 3316.0]
[18.0, 18.0]
[268, 333]
p03231
u352558780
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\n\n \n\n \nN,M = map(int,input().split())\nS = input()\nT = input()\n\npair = {N:S,M:T}\n\n\ndef lcd(n,m):\n return int(n * m / gcd(n,m))\ndef gcd(n,m):\n if n % m == 0:\n return m\n else:\n return gcd(m,n % m)\n# return int(m*n/math.gcd(n,m))\n \ndef prove(n,m):\n if gcd(n,m)==1:\n return lcd(n,m)\n global pair\n n_i = int(n/gcd(n,m))\n m_i = int(m/gcd(n,m))\n n_list = pair[n][::n_i]\n m_list = pair[m][::m_i]\n# print(c)\n\n if n_list[0:len(m_list)]==m_list:\n return lcd(n,m)\n else:\n return -1\nn = max(pair.keys())\nm = min(pair.keys())\nif pair[N][0]!=pair[M][0]:\n print(-1)\nelif N==M:\n if S==T:\n print(N)\n else\n print(-1)\nelse:\n print(prove(n,m))\n\n', 'import math\n\n \n\n \nN,M = map(int,input().split())\nS = input()\nT = input()\n\n\ndef lcd(n,m):\n return int(n * m / gcd(n,m))\ndef gcd(n,m):\n if n % m == 0:\n return m\n else:\n return gcd(m,n % m)\n# return int(m*n/math.gcd(n,m))\n \ndef prove(n,m):\n n_i = int(lcd(n,m)/n)\n m_i = int(lcd(n,m)/m)\n n_list=[S[m_i*i] for i in range(gcd(n,m))]\n m_list=[T[n_i*i] for i in range(gcd(n,m))]\n# print(c)\n\n if n_list==m_list:\n return lcd(n,m)\n else:\n return -1\n\n\nprint(prove(N,M))\n\n']
['Runtime Error', 'Accepted']
['s519559400', 's289199847']
[3064.0, 3828.0]
[17.0, 22.0]
[756, 542]
p03231
u371763408
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m=map(int,input().split())\ns=input()\nt=input()\n\ndef gcd(x,y):\n r=x%y\n return gcd(y,r) if r else y\n\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\nL=lcm(n,m)\ng=gcd(n,m)\nif s[0]==t[0]:\n X=[""]*(L+1)\n print(X)\nelse:\n print(-1)\n exit()\nfor i in range(1,g):\n X[int(i*L/n)+1]=s[i]\nfor i in range(1,g):\n if X[int(i*L/m)+1] !="":\n if X[int(i*L/m)+1] !=t[i]:\n print(-1)\n exit()\nprint(L)', 'n,m=map(int,input().split())\ns=input()\nt=input()\n\ndef gcd(x,y):\n r=x%y\n return gcd(y,r) if r else y\n\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\nL=lcm(n,m)\nif s[0]==t[0]:\n X=[""]*L+1\nelse:\n print(-1)\n exit()\nfor i in range(1,n):\n X[int(i*L/n)+1]=s[i]\nfor i in range(1,m):\n if X[int(i*L/m)+1] !="":\n if X[int(i*L/m)+1] !=t[i]:\n print(-1)\n exit()\nprint(L)', 'n,m=map(int,input().split())\ns=input()\nt=input()\n\ndef gcd(x,y):\n r=x%y\n return gcd(y,r) if r else y\n\ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\nL=lcm(n,m)\ng=gcd(n,m)\nfor i in range(g):\n if s[int(i*n/g)]!=t[int(i*m/g)]:\n print(-1)\n exit()\nprint(L)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s897368850', 's925924396', 's484461775']
[464572.0, 187764.0, 3316.0]
[1508.0, 133.0, 19.0]
[417, 393, 276]
p03231
u388697579
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import numpy as np# your code goes here\ndef eucrid(a, b):\n\tif (a > b):\n\t\tbuf = a\n\t\ta = b\n\t\tb = buf\n\tif (b % a == 0):\n\t\treturn a\n\telse:\n\t\treturn eucrid(b%a, a)\n\t\t\ndef main():\n\tbuf = input().split()\n\ts = input()\n\tt = input()\n\tn = len(s)\n\tm = len(t)\n\t\n\tbig = n*m//eucrid(n, m)\n\tflag = big\n\tfor i in range(big):\n\t\tif (i%(big//n) == 0 and i%(big//m) == 0):\n\t\t\tprint(i, n, m)\n\t\t\tprint((i+1)//(big//n), (i+1)//(big//m))\n\t\t\tif(s[(i+1)//(big//n)] != t[(i+1)//(big//m)]):\n\t\t\t\tflag = -1\n\t\t\t\t\n\tprint(flag)\n\t#print(s, t, n, m)\n\t\n\t\nmain()', 'import numpy as np# your code goes here\ndef eucrid(a, b):\n\tif (a > b):\n\t\tbuf = a\n\t\ta = b\n\t\tb = buf\n\tif (b % a == 0):\n\t\treturn a\n\telse:\n\t\treturn eucrid(b%a, a)\n\t\t\ndef main():\n\tbuf = input().split()\n\ts = input()\n\tt = input()\n\tn = len(s)\n\tm = len(t)\n\t\n\tbig = n*m//eucrid(n, m)\n\tflag = big\n\t"""\n\tfor i in range(big):\n\t\tif (i%(big//n) == 0 and i%(big//m) == 0):\n\t\t\t#print(i, n, m)\n\t\t\t#print((i+1)//(big//n), (i+1)//(big//m))\n\t\t\tif(s[(i+1)//(big//n)] != t[(i+1)//(big//m)]):\n\t\t\t\tflag = -1\n\t"""\t\t\t\n\tfor i in range(n):\n\t\tif((i*(big//n))%(big//m) == 0):\n\t\t\tif(s[i] != t[(i*(big//n))//(big//m)]):\n\t\t\t\tflag = -1\n\n\tprint(flag)\n\t#print(s, t, n, m)\n\t\n\t\nmain()']
['Runtime Error', 'Accepted']
['s984431933', 's271557071']
[21232.0, 12712.0]
[2109.0, 179.0]
[524, 645]
p03231
u408620326
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["def main():\n import sys\n sys.setrecursionlimit(10**6)\n input = sys.stdin.readline\n\n def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n \n N, M = [int(x) for x in input().strip().split()]\n S = input().strip()\n T = input().strip()\n L = (N * M) // gcd(N, M)\n ans = ['0'] * L\n for n in range(L//N):\n ans[L//N*n] = S[n%N]\n for m in range(L//M):\n if ans[(L//M)*m] == '0':\n ans[(L//M)*m] = T[m%M]\n elif ans[(L//M)*m] == T[m%M]:\n continue\n else:\n print(-1)\n return\n print(L)\n\nif __name__ == '__main__':\n main()", "def main():\n import sys\n from collections import defaultdict\n sys.setrecursionlimit(10**6)\n input = sys.stdin.readline\n\n def gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n \n N, M = [int(x) for x in input().strip().split()]\n S = input().strip()\n T = input().strip()\n L = (N * M) // gcd(N, M)\n d = defaultdict(int)\n for n in range(N):\n d[L//N*n] = S[n]\n for m in range(M):\n if d[L//M*m] == 0 or d[L//M*m] == T[m]:\n continue\n else:\n print(-1)\n return\n print(L)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s114373662', 's919769192']
[187764.0, 15772.0]
[131.0, 71.0]
[649, 626]
p03231
u411923565
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['#66 A - Two Abbreviations\nimport math\nN,M = map(int,input().split())\nS = input()\nT = input()\n\nL = N*M//math.gcd(N,M)\n\ndist_N = L//N\ndist_M = L//M\nlis = [0]*L\n\ni = 0\nfor n in range(0,L,dist_N):\n lis[n] = S[i]\n i += 1\n print(lis)\n \nj = 0\nfor m in range(0,L,dist_M):\n if lis[m] == 0:\n j += 1\n else:\n if lis[m] == T[j]:\n j += 1\n else:\n ans = -1\n break\n print(lis)\nelse:\n ans = L\nprint(ans)', '#66 A - Two Abbreviations\nimport math\nN,M = map(int,input().split())\nS = input()\nT = input()\n\nGCD = math.gcd(N,M)\nL = N*M//GCD\n\ndist_N = L//N\ndist_M = L//M\n\n\nfor i in range(GCD):\n \n s = dist_M * i\n t = dist_N * i\n if S[s] != T[t]:\n ans = -1\n break\nelse:\n ans = L\nprint(ans)']
['Runtime Error', 'Accepted']
['s351931102', 's821704522']
[397852.0, 9304.0]
[2377.0, 26.0]
[463, 436]
p03231
u427344224
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = map(int, input().split())\nS = input()\nT = input()\n\n# if a < b:\n\n# else:\n# return a if b == 0 else gcd(b, a % b)\n\nimport fractions\ndef lcm(a, b):\n return a * b // fractions.gcd(b, a % b)\n\n\nL = lcm(N, M)\n\nr = ["*" for i in range(L)]\nf = False\n\ns_step = L // N\nt_step = L // M\nsL = lcm(s_step, t_step)\ns = 0\nt = 0\n\nfor i in range(0, L, sL):\n if i == 0:\n if S[i] == T[i]:\n continue\n else:\n f = True\n break\n else:\n s = i // s_step\n t = i // t_step\n if s > N - 1:\n break\n if t > M - 1:\n break\n if S[s] == T[t]:\n continue\n else:\n f = True\n break\n\nif f:\n print(-1)\nelse:\n print(L)\nN, M = map(int, input().split())\nS = input()\nT = input()\n\n\ndef gcd(a, b):\n if a < b:\n return gcd(b, a)\n else:\n return a if b == 0 else gcd(b, a % b)\n\n\ndef lcm(a, b):\n return a * b // gcd(b, a % b)\n\n\nL = lcm(N, M)\n\nf = False\n\ns_step = L // N\nt_step = L // M\nsL = lcm(s_step, t_step)\ns = 0\nt = 0\n\nfor i in range(0, L, sL):\n if i == 0:\n if S[i] == T[i]:\n continue\n else:\n f = True\n break\n else:\n s = i // s_step\n t = i // t_step\n if s > N - 1:\n break\n if t > M - 1:\n break\n if S[s] == T[t]:\n continue\n else:\n f = True\n break\n\nif f:\n print(-1)\nelse:\n print(L)\n', 'N, M = map(int, input().split())\nS = input()\nT = input()\ndef gcd(a, b):\n\n return a if b == 0 else gcd(b, a % b)\n\ndef lcm(a, b):\n return a * b // gcd(b, a % b)\n\n\nL = lcm(N, M)\n\nf = False\n\ns_step = L // N\nt_step = L // M\nsL = lcm(s_step, t_step)\ns = 0\nt = 0\n\nfor i in range(0, L, sL):\n if i == 0:\n if S[i] == T[i]:\n continue\n else:\n f = True\n break\n else:\n s = i // s_step\n t = i // t_step\n if s > N - 1:\n break\n if t > M - 1:\n break\n if S[s] == T[t]:\n continue\n else:\n f = True\n break\n\nif f:\n print(-1)\nelse:\n print(L)\n\n']
['Runtime Error', 'Accepted']
['s295411545', 's674696434']
[508500.0, 3444.0]
[2132.0, 19.0]
[1532, 681]
p03231
u488884575
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\nn,m=map(int,input().split())\ns=input()\nt=input()\ng = n * m // math.gcd(n, m)\n\nsnum=[i*g/n+1 for i in range(n)]\ntnum=[i*g/m+1 for i in range(m)]\nprint(snum,tnum)\n\nif n<m:\n s,t=t,s\n snum,tnum=tnum,snum\nfor i in range(len(snum)):\n if snum[i] in tnum:\n if s[i]!=t[tnum.index(snum[i])]:\n print(-1)\n exit()\nprint(g)', "import math\nn,m=map(int,input().split())\ns=input()\nt=input()\ng = n * m // math.gcd(n, m)\n\n'''if n<m:\n s,t=t,s\n snum,tnum=tnum,snum'''\n\nfor i in range(math.gcd(n,m)):\n #print(i, i*(g//m), s[i*(g//m)], i*(g//n), t[i*(g//n)])\n if s[i*(g//m)]!=t[i*(g//n)]:\n print(-1)\n exit()\nprint(g)"]
['Wrong Answer', 'Accepted']
['s957652270', 's403134234']
[18640.0, 9236.0]
[2208.0, 31.0]
[359, 306]
p03231
u495561847
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\n\nn, m = map(int, input().split())\ns = input()\nt = input()\n\ncnt = 1\nns = 1\nnt = 1\nss = 0\ntt = 0\nfail = False\n\nll = (n * m) // math.gcd(x, y)\nl = ll\n\nwhile l <= n * m:\n fail = False\n while not( ns >= l or nt >= l):\n while not(ns <= nt):\n nt += l / m \n tt += 1\n\n if(ns == nt) and (s[ss] != t[tt]):\n fail = True\n break\n\n ns += l / n\n ss += 1\n if not(fail): \n break\n cnt += 1\n l = ll * cnt\n\nif(fail):\n print(-1)\nelse:\n print(l)\n', '\nn, m = map(int, input().split())\ns = input()\nt = input()\n\ncnt = 1\nns = 1\nnt = 1\nss = 0\ntt = 0\nfail = False\n\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\n\nll = (n * m) // gcd(n, m)\nl = ll\n\nwhile l <= n * m:\n fail = False\n while not(ns > l or nt > l):\n while not(ns <= nt):\n nt += l / m\n tt += 1\n\n if(ns == nt) and (s[ss] != t[tt]):\n fail = True\n break\n\n ns += l / n\n ss += 1\n if not(fail):\n break\n cnt += 1\n l = ll * cnt\n\nif(fail):\n print(-1)\nelse:\n print(l)\n']
['Runtime Error', 'Accepted']
['s319320343', 's109531136']
[3316.0, 3316.0]
[18.0, 82.0]
[535, 581]
p03231
u513081876
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["N, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b!= 0:\n a, b = b, a%b\n return a\n\nif N == M:\n if S == T:\n print('N')\n else:\n print(-1)\n \nelse:\n if S[0] == T[0]:\n lcm = a*b//(gcd(a, b))\n print(lcm)\n \n \n \n \n else:\n print(-1)\n ", 'def gcd(a,b):\n while b>0:\n a,b=b,a%b\n return a\n \nx,y=map(int,input().split())\nS=input()\nT=input()\nGCD=gcd(x,y)\nLCM=(x * y) // GCD\n \nx_new=x//GCD\ny_new=y//GCD\nfor i in range(0,GCD):\n if S[(x_new)*i]==T[(y_new)*i]:\n result=LCM\n else:\n result=-1\n break\nprint(result)']
['Runtime Error', 'Accepted']
['s750177111', 's790914907']
[3316.0, 3316.0]
[19.0, 20.0]
[353, 279]
p03231
u513434790
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import sys\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b :\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nL = lcm(N, M)\nX = [["A"] for i in range(L)]\n\nfor i in range(N):\n index = i * (L // N)\n X[index] = S[i]\n\nfor i in range(M):\n index = i * (L // M) \n if X[index] != "A" and X[index] != T[i]:\n print(-1)\n sys.exit()\n \nprint(L)\n', 'import sys\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b :\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nL = lcm(N, M)\nX = ["A"] * L\n\n \nprint(-20)\nsys.exit()\n\n\nfor i in range(N):\n index = i * (L // N)\n X[index] = S[i]\n\nfor i in range(M):\n index = i * (L // M) \n if X[index] != "A" and X[index] != T[i]:\n print(-1)\n sys.exit()\n \nprint(L)\n', 'import sys\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b :\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nL = lcm(N, M)\nX = ["A"] * L\n\nfor i in range(N):\n index = i * (L // N)\n X[index] = S[i]\n \nprint(-20)\nsys.exit()\n\nfor i in range(M):\n index = i * (L // M) \n if X[index] != "A" and X[index] != T[i]:\n print(-1)\n sys.exit()\n \nprint(L)\n', 'N, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b :\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd(a, b)\n\nL = lcm(N, M)\ns = L // M\nt = L // N\n\nif S[::s] != T[::t]:\n L = -1\nprint(L)\n']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s038031956', 's246806906', 's355068609', 's814456180']
[594548.0, 187764.0, 187764.0, 3316.0]
[2142.0, 364.0, 373.0, 17.0]
[434, 447, 445, 249]
p03231
u540572789
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\ndef lcm(a, b):\n\treturn a * b // gcd (a, b)\nn, m = map(int,input().split())\ns = input()\nt = input()\nj = 0\na = gcd(n, m)\nfor i, c in enumerate(s):\n\tif i % a == 0:\n\t\tif c != t[i // a * m]:\n\t\t\tj = -1\n\t\t\tbreak\nif j >= 0:\n\tj = lcm(n, m)\nprint(j)', 'def gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\ndef lcm(a, b):\n\treturn a * b // gcd (a, b)\nn, m = map(int,input().split())\ns = input()\nt = input()\nj = 0\na = gcd(n, m)\nfor i, c in enumerate(s):\n\tif i % (n // a) == 0:\n\t\tif c != t[(i // (n // a)) * (m // a)]:\n\t\t\tj = -1\n\t\t\tbreak\nif j >= 0:\n\tj = lcm(n, m)\nprint(j)']
['Runtime Error', 'Accepted']
['s725971848', 's180090257']
[3316.0, 3316.0]
[21.0, 38.0]
[292, 315]
p03231
u554871639
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\ndef main():\n N, M = map(int, input().split())\n S = input()\n T = input()\n result = N * M / math.gcd(N, M)\n cand = (result / N) * (result / M) / math.gcd((result / N), (result / M))\n for i in range(0, result / cand):\n if S[(i * cand) / (result / N)] != T[(i * cand) / (result / M)]:\n return -1\n return result\nprint(main())', 'import math\n\nN, M = map(int, input().split())\nS = list(input())\nT = list(input())\n\ndef main(N, M, S, T):\n result = N * M // math.gcd(N, M)\n cand = (result // N) * (result // M) // math.gcd((result // N), (result // M))\n for i in range(0, result // cand):\n print(S[(i * cand + 3) // (result // N) - 1])\n print(T[(i * cand + 3) // (result // M) - 1])\n if S[(i * cand) // (result // N)] != T[(i * cand) // (result // M)]:\n return -1\n return result\nprint(main(N, M, S, T))', "def gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return a\n c = a % b\n return gcd(b, c)\n\ndef main():\n N, M = map(int, input().split())\n S = input()\n T = input()\n result = N * M / gcd(N, M)\n cand = (result / N) * (result / M) / gcd(int((result / N)), int((result / M)))\n for i in range(0, int(result / cand)):\n if S[int((i * cand) / (result / N))] != T[int((i * cand) / (result / M))]:\n return '-1'\n return int(result)\nprint(main())"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s616718381', 's648138250', 's887852746']
[3316.0, 4624.0, 3316.0]
[17.0, 30.0, 20.0]
[371, 512, 498]
p03231
u598229387
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import fractions\nn,m=map(int,input().split())\ns=input()\nt=input()\n\nf1=fractions.gcd(n,m)\nf1=n*m//f1\nif s[0]!=t[0]:\n print(-1)\n\nelif max(n,m)%min(n,m)!=0:\n print(f1)\nelif n==m:\n if s==t:\n print(n)\n else:\n print(-1)\nelif n>m:\n f1=fractions.gcd(n,m)\n f1=n*m//f1\n \n check1=f1//n\n check2=f1//m\n for i in range(1,m-check1+1):\n if t[check1*i] != s[check2*i]:\n print(-1)\n exit()\n\n print(f1)\nelif n<m:\n f1=fractions.gcd(n,m)\n f1=n*m//f1\n \n check1=f1//n\n check2=f1//m\n for i in range(1,n-check2+1):\n if t[check1*i] != s[check2*i]:\n print(-1)\n exit()\n\n print(f1)\n ', 'n,m=map(int,input().split())\ns=input()\nt=input()\n\nif s[0]!=t[0]:\n print(-1)\n exit()\n\ndef gcd(a,b):\n while b:\n a,b=b,a%b\n return a\n\nnum=gcd(n,m)\n\nif num==1:\n ans=n*m\n\nelse:\n ans=n*m//num\n check1=n//num\n check2=m//num\n for i in range(1,num):\n if s[i*check1]==t[i*check2]:\n continue\n else:\n print(-1)\n exit()\nprint(ans)']
['Wrong Answer', 'Accepted']
['s357356458', 's232157627']
[5432.0, 3316.0]
[36.0, 19.0]
[684, 397]
p03231
u603234915
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(A, B):\n while B != 0:\n A, B = B, A%B\n return A\n\nN, M = map(int, input().split())\nS = input()\nT = input()\ncan = True\nagc = N // gcd(N, M) * M\nL_N = agc // N\nL_M = agc // M\ni = 0\n\nwhile i*L_M < agc and i*L_N < agc:\n if S[i*L_M] != T[i*L_N]:\n can = False\n break\n i += 1\n\nif can:\n print(agc)\nelse:\n print(-1)', 'def gcd(A, B):\n while B != 0:\n A, B = B, A%B\n return A\n\nN, M = map(int, input().split())\nS = input()\nT = input()\ncan = True\nagc = N * M // gcd(N, M)\nL_N = agc // N\nL_M = agc // M\ni = 0\n\nwhile i*L_M < agc and i*L_N < agc:\n if S[i*L_M] != T[i*L_N]:\n can = False\n break\n i += 1\n\nif can:\n print(agc)\nelse:\n print(-1)', 'def gcd(A, B):\n while B != 0:\n A, B = B, A%B\n return A\n\nN, M = map(int, input().split())\nS = input()\nT = input()\nagc = N * M // gcd(N, M)\ncan = True\ni = 0\nwhile i*L_M < agc and i*L_N < agc:\n if S[i*L_M] != T[i*L_N]:\n can = False\n break\n i += 1\n if can:\n print(agc)\nelse:\n print(-1)', 'def gcb(A, B):\n while B != 0:\n A, B = B, A%B\n return A\n\nN, M = map(int, input().split())\nS = input()\nT = input()\ncan = True\nagc = N // gcb(N, M) * M\nL_N = agc // N\nL_M = agc // M\ni = 0\nwhile i*L_M < N and i*L_N < M:\n if S[i*L_M] != T[i*L_N]:\n can = False\n break\n i += 1\n\nif can:\n print(agc)\nelse:\n print(-1)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s477422778', 's756207510', 's967690585', 's333758596']
[3316.0, 3316.0, 2940.0, 3316.0]
[19.0, 19.0, 17.0, 19.0]
[351, 351, 323, 347]
p03231
u607865971
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = [int(x) for x in input().split(" ")]\nS = input()\nT = input()\n\nN = len(S)\nM = len(T)\n\n\ndef gcd(a, b):\n if (a < b):\n return gcd(b, a)\n if a % b == 0:\n return b\n else:\n return gcd(b, a % b)\n\n\ndef maxkobai(a, b):\n return a * b // gcd(a, b)\n\n\n#print(gcd(N, M))\n#print(maxkobai(N, M))\n\n\nL = maxkobai(N, M)\nret = L\n\nx = {}\n#x = [\'-\'] * (L*10)\n\nfor l in range(0, L + 1):\n x[l] = ord(\'-\')\n\n\nfor n in range(0, N):\n x[n * (L//N) + 1] = ord(S[n])\n\n# print(x)\n\nfor m in range(0, M):\n idx = m * (L // M) + 1\n x_idx = x[idx]\n if x_idx != ord(\'-\') and x_idx != ord(T[m]):\n ret = -1\n break\n', 'N, M = [int(x) for x in input().split(" ")]\nS = input()\nT = input()\n\nN = len(S)\nM = len(T)\n\n\nS = [ord(c) for c in S]\nT = [ord(c) for c in T]\n\n\ndef gcd(a, b):\n if a < b:\n a, b = b, a\n while b:\n a, b = b, a % b\n return a\n\n\ndef maxkobai(a, b):\n return a * b // gcd(a, b)\n\n\nL = maxkobai(N, M)\nret = L\nx = dict()\n\nfor n in range(0, N):\n x[n * (L//N) + 1] = S[n]\n\n\nfor m in range(0, M):\n idx = m * (L // M) + 1\n tmp = x.get(idx, 0)\n\n if tmp != T[m] and tmp != 0:\n ret = -1\n break\n\nprint(ret)\n']
['Wrong Answer', 'Accepted']
['s667485819', 's713007517']
[1538056.0, 16380.0]
[2130.0, 102.0]
[672, 538]
p03231
u610734676
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\n\nN, M = list(map(int, input().split()))\nS = input()\nT = input()\n\ndef lcm(x, y):\n return (x * y) // math.gcd(x, y)\n\nsuccess = False;\nans = 0\n_lcm = lcm(N, M)\nfor k in range(1, N*M//_lcm + 1):\n ans = k * _lcm\n s = [(i * ans)//N + 1 for i in range(N)]\n t = [(i * ans)//M + 1 for i in range(M)]\n\n pool = s + t\n\n double_st = [x for x in set(pool) if pool.count(x) > 1]\n isImpossible = False\n\n for st in double_st:\n s_i = s.index(st, -1)\n t_i = t.index(st, -1)\n if s_i == -1 or t_i == -1:\n continue\n if S[s_i] != T[t_i]:\n isImpossible = True\n \n if not isImpossible:\n success = True\n break\n\nif not success:\n print(-1)\nelse:\n print(ans)', '\nN, M = map(int, input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return a\n c = a % b\n return gcd(b, c)\n \ndef lcm(x, y):\n return (x * y) // gcd(x, y)\n\ndef my_index(l, x, default=False):\n if x in l:\n return l.index(x)\n else:\n return default\n\nsuccess = False\nfans = 0\n\n_lcm = lcm(len(S), len(T))\n\ndef isImpble(k, _lcm):\n global success\n global S\n global T\n global fans\n \n ans = k * _lcm\n double_st = []\n \n for i in range(len(S)):\n if (len(T)*i)%len(S) == 0 and (len(T) * i)//len(S) <len(T):\n double_st += [(i * ans)//len(S) + 1]\n isImpossible = False\n\n for st in double_st:\n s_i = ((st-1) * len(S))//ans\n t_i = ((st-1) * len(T))//ans\n if S[s_i] != T[t_i]:\n isImpossible = True\n break\n\n \n if isImpossible:\n return True\n else:\n success = True\n fans = k*_lcm\n return False\n \n\nimp = isImpble((len(S) * len(T))//_lcm, _lcm)\n\nif not imp:\n for k in range(1, (len(S) * len(T))//_lcm ):\n imp = isImpble(k, _lcm)\n if success:\n break\n \n\nif not success:\n print(-1)\nelse:\n print(fans)']
['Runtime Error', 'Accepted']
['s428347206', 's940354296']
[3444.0, 4328.0]
[18.0, 63.0]
[748, 1246]
p03231
u623819879
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m=map(int, input().split())\ns=input()\nt=input()\ndef euc(x,y):\n if x % y==0:\n return x\n else:\n return euc(max(x,y) % min (x,y),min(x,y))\nd=euc(n,m)\nans=int(n*m/d)\nif d==1:\n print(n*m)\nelse:\n for i in range(d):\n if s[i*int(n/d)]!=t[i*int(m/d)]:\n ans=-1\n print(ans)', 'n,m=map(int, input().split())\ns=input()\nt=input()\ndef euc(x,y):\n if x % y==0:\n return x\n else:\n return euc(max(x,y) % min (x,y),min(x,y))\nd=euc(n,m)\nans=n*m/d\nif d==1:\n print(n*m)\nelse:\n for i in range(d):\n if s[i*int(n/d)]!=t[i*int(m/d)]:\n ans=-1\n print(ans)', 'n,m=map(int, input().split())\ns=input()\nt=input()\ndef euc(x,y):\n if x % y==0:\n return x\n else:\n return euc(max(x,y) % min (x,y),min(x,y))\nd=euc(n,m)\nans=n*int(m/d)\nif d==1:\n print(n*m)\nelse:\n for i in range(d):\n if s[i*int(n/d)]!=t[i*int(m/d)]:\n ans=-1\n print(ans)', 'n,m=map(int, input().split())\ns=input()\nt=input()\ndef euc(x,y):\n if max(x,y) % min(x,y)==0:\n return min(x,y)\n else:\n return euc(max(x,y) % min (x,y),min(x,y))\nd=euc(n,m)\nans=n*int(m/d)\nif d==1:\n if s[0]==t[0]:\n print(n*m)\n else:\n print(-1)\nelse:\n for i in range(d):\n if s[i*int(n/d)]!=t[i*int(m/d)]:\n ans=-1\n print(ans)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s291219991', 's750718974', 's890481016', 's131040648']
[3316.0, 3316.0, 3316.0, 3316.0]
[18.0, 18.0, 18.0, 31.0]
[283, 278, 283, 346]
p03231
u668503853
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int, M: int, S: str, T: str):\n # from math import gcd\n from fractions import gcd\n\n def lcm(a: int, b: int):\n return (a * b) // gcd(a, b)\n\n l = lcm(N, M)\n\n x = [''] * l\n\n for i in range(N):\n x[i*(l//N)] = S[i]\n\n for i in range(M):\n if(x[i*(l//M)] != '' and x[i*(l//M)] != T[i]):\n print(-1)\n exit()\n else:\n x[i*(l//M)] = T[i]\n\n \n\n print(l)\n\n return\n\n\n# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n S = next(tokens) # type: str\n T = next(tokens) # type: str\n solve(N, M, S, T)\n\nif __name__ == '__main__':\n main()\n", 'N,M=map(int,input().split())\nS=input()\nT=input()\ndef gcd(a,b):\n while b:\n a,b=b,a%b\n return a\ng=gcd(N,M)\nL=N*M//g\nif all(S[i*N//g]==T[i*M//g]for i in range(g)):\n print(L)\nelse:\n print(-1)']
['Runtime Error', 'Accepted']
['s838009018', 's394809220']
[189776.0, 3316.0]
[188.0, 19.0]
[1026, 194]
p03231
u678167152
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = map(int, input().split())\nS = input()\nT = input()\n\nfrom collections import gcd\n\ndef solve(N,M,S,T):\n g = gcd(N,M)\n for i in range(g):\n if S[N//g*i]!=T[M//g*i]:\n return -1\n ans = N*M//g\n return ans\nprint(solve(N,M,S,T))', 'from math import gcd\ndef solve():\n N, M = map(int, input().split())\n S = input()\n T = input()\n g = gcd(N,M)\n ans = N*M//g\n for i in range(g):\n if S[N//g*i]!=T[M//g*i]:\n return -1\n return ans\nprint(solve())']
['Runtime Error', 'Accepted']
['s557944502', 's020568238']
[3572.0, 9224.0]
[21.0, 28.0]
[255, 220]
p03231
u687574784
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m = list(map(int, input().split()))\ns = input()\nt = input()\nimport math\n\n\ngcd = math.gcd(n, m)\nprint(s[::n//gcd] ,t[::m//gcd])\nif s[::n//gcd] == t[::m//gcd]:\n print(n * m // gcd)\nelse:\n print(-1)\n', 'n,m = list(map(int, input().split()))\ns = input()\nt = input()\nimport math\n\n\ngcd = math.gcd(n, m)\nif s[::n//gcd] == t[::m//gcd]:\n print(n * m // gcd)\nelse:\n print(-1)']
['Wrong Answer', 'Accepted']
['s583150817', 's537022676']
[9136.0, 9280.0]
[27.0, 26.0]
[269, 236]
p03231
u690781906
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n if a < b:\n a, b = b, a\n while a % b != 0:\n a, b = b, a % b\n return b\n\n\nN, M = map(int, input().split())\nS = input()\nT = input()\nx = gcd(N, M)\nn = N // x\nm = M // x\n\nfor i in range(3):\n if S[n*i] == T[m*i]:\n print(-1)\n break\nprint(N*M//x)\n', 'def gcd(a, b):\n if a < b:\n a, b = b, a\n while a % b != 0:\n a, b = b, a % b\n return b\n\n\nN, M = map(int, input().split())\nS = input()\nT = input()\nx = gcd(N, M)\nn = N // x\nm = M // x\n\nfor i in range(x):\n if S[n*i] != T[m*i]:\n print(-1)\n exit()\nprint(N*M//x)\n']
['Runtime Error', 'Accepted']
['s513704008', 's851460450']
[9352.0, 9264.0]
[30.0, 30.0]
[294, 295]
p03231
u704563784
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a // gcd (a, b) * b\n\nn, m = map(int, input().split())\ns = input()\nt = input()\n\nans = lcm(n, m)\n\nchk = {}\n\nfor i in range(n):\n d = ans//n\n chk[i*d] = s[i]\nfor i in range(m):\n d = ans//m\n if i*d in chk and chk[i*d] == t[i]:\n print(-1)\n exit()\nprint(ans)\n\n', 'def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a // gcd (a, b) * b\n\nn, m = map(int, input().split())\ns = input()\nt = input()\n\nans = lcm(n, m)\n\nchk = {}\n\nfor i in range(n):\n d = ans//n\n chk[i*d] = s[i]\nfor i in range(m):\n d = ans//m\n if i*d in chk and chk[i*d] != t[i]:\n print(-1)\n exit()\nprint(ans)\n\n']
['Wrong Answer', 'Accepted']
['s777188188', 's979499777']
[15396.0, 15396.0]
[62.0, 68.0]
[371, 371]
p03231
u749614185
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['from math import gcd\n \na,b=map(int, input().split())\nc=input()\nd=input()\n \ne=gcd(n,m)\n \nae=a//e\nbe=b//e\n \nfor i in range(0,e):\n if c[ae*i]!=d[be*i]:\n print(-1)\n exit()\nprint(ae*be*e)', 'from math import gcd\n \nn,m=map(int, input().split())\ns=input()\nt=input()\n \ng=gcd(n,m)\n \nng=n//g\nmg=m//g\n \nfor i in range(0,g):\n if s[ng*i]!=t[mg*i]:\n print(-1)\n exit()\nprint(ng*mg*g)']
['Runtime Error', 'Accepted']
['s383240450', 's486220513']
[9276.0, 9064.0]
[24.0, 32.0]
[199, 199]
p03231
u750651325
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn,m = I()\ns = v()\nt = v()\nl = lcm(n,m)\ng = gcd(n,m)\n\nfor i in range(g):\n if s[n//g*i] != t[m//g*i]:\n print(-1)\n sys.exit()\n\nprint(l)\n', 'import re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn,m = I()\ns = v()\nt = v()\nl = lcm(n,m)\ng = math.gcd(n,m)\n\nfor i in range(g):\n if s[n//g*i] != t[m//g*i]:\n print(-1)\n sys.exit()\n\nprint(l)\n']
['Runtime Error', 'Accepted']
['s938236375', 's333590429']
[10612.0, 10668.0]
[33.0, 40.0]
[681, 686]
p03231
u752767312
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return int(a)\n r = a % b\n return gcd(b, r)\n\ndef lcm(a,b):\n return int(a*b/gcd(a,b))\n \nN,M = map(int,input().split())\nS = input()\nT = input()\nL = lcm(N,M)\nflag = True\nmin_len = min(Na,M)\ns_index = int(int(L/M)/gcd(int(L/M),int(L/N)))\nt_index = int(int(L/N)/gcd(int(L/M),int(L/N)))\n\nif N == M:\n for i in range(N):\n if S[i] == T[i]:\n continue\n else:\n flag = False\n break\nelse:\n for i in range(min_len):\n if i * s_index < N-1 and i*t_index < M - 1:\n if S[i*s_index] == T[i*t_index]:\n continue\n else:\n flag = False\n break\n else:\n break\n \nif flag: \n print(L)\nelse:\n print(-1)', 'def gcd(a, b):\n if a < b:\n a, b = b, a\n if b == 0:\n return int(a)\n r = a % b\n return gcd(b, r)\n\ndef lcm(a,b):\n return int(a*b/gcd(a,b))\n \nN,M = map(int,input().split())\nS = input()\nT = input()\nL = lcm(N,M)\nflag = True\nmin_len = min(N,M)\ns_index = int(int(L/M)/gcd(int(L/M),int(L/N)))\nt_index = int(int(L/N)/gcd(int(L/M),int(L/N)))\n\nif N == M:\n for i in range(N):\n if S[i] == T[i]:\n continue\n else:\n flag = False\n break\nelse:\n for i in range(min_len):\n if i * s_index < N-1 and i*t_index < M - 1:\n if S[i*s_index] == T[i*t_index]:\n continue\n else:\n flag = False\n break\n else:\n break\n \nif flag: \n print(L)\nelse:\n print(-1)']
['Runtime Error', 'Accepted']
['s047384969', 's507001975']
[3444.0, 3444.0]
[18.0, 19.0]
[719, 718]
p03231
u782098901
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(a, b):\n if a < b:\n return gcd(b, a)\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\n\ndef main():\n N, M = map(int, input().split())\n S = input()\n T = input()\n\n g = gcd(N, M)\n for i in range(g):\n if S[i * N // g] != T[i * M // g]:\n print("-1")\n exit()\n print(N * M / g)\n\nmain()', 'def gcd(a, b):\n if a < b:\n return gcd(b, a)\n if b == 0:\n return a\n else:\n return gcd(b, a % b)\n\n\ndef main():\n N, M = map(int, input().split())\n S, T = input().split()\n\n g = gcd(N, M)\n for i in range(g):\n if S[i * N / g] == T[i * M / g]:\n print("-1")\n exit()\n print(N * M / g)\n\nmain()\n', 'N, M = map(int, input().split())\nS = input(); T = input()\n\ndef gcd(n, m):\n if n < m:\n return gcd(m, n)\n if m == 0:\n return n\n else:\n return gcd(m, n % m)\n\nnm_gcd = gcd(N, M)\nn, m = M // nm_gcd, N // nm_gcd\nans = N * M // nm_gcd\nfor i in range(nm_gcd):\n if S[i * m] != T[i * n]:\n ans = -1\n break\n\nprint(ans) ']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s250772611', 's505055877', 's446038218']
[3316.0, 3316.0, 3316.0]
[18.0, 18.0, 19.0]
[364, 358, 354]
p03231
u793460864
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = map(int, input().split())\nS = str(input())\nT = str(input())\n\ndef lcm(x, y):\n def gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n return (x * y) // gcd(x, y)\nX = lcm(N ,M)\n\nif S[0] != T[0]:\n print(-1)\nelif X == N*M:\n print(N*M)\nelse:\n for i in range(1,(N*M//X)+1):\n L = X * i\n counter = L\n y = L // N\n z = L // M\n match = lcm( y, z)\n for j in range(1, (L // match) ):\n if S[j * N * match // L] != T[l = j * M * match // L]:\n counter = -1\n break\n if counter == L:\n break\n print(counter)\n\n\n', 'N, M = map(int, input().split())\nS = str(input())\nT = str(input())\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\n \ndef lcm(x, y):\n return (x * y) // gcd(x, y)\nX = lcm(N ,M)\n \nif S[0] != T[0]:\n print(-1)\nelif X == N*M:\n print(N*M)\nelse:\n L = X\n match = lcm( L // N, L // M)\n for j in range(1, (L // match) ):\n if S[j * N * match // L] != T[ j * M * match // L]:\n L = -1\n break\n if L == X :\n print(L)\n else:\n print(-1)\n ']
['Runtime Error', 'Accepted']
['s930092029', 's698751568']
[3064.0, 3316.0]
[18.0, 19.0]
[639, 534]
p03231
u815763296
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\nN, M = map(int, input().split())\nS = list(input())\nT = list(input())\n\nlcm = (N * M) // math.gcd(N, M)\nans = lcm\nansS = ["0"]*lcm\nansT = ["0"]*lcm\nSp = lcm//N\nTp = lcm//M\n\n\nfor i in range(10000000000):\n if Sp*i > lcm:\n break\n if i > N:\n break\n ansS[Sp*i] = S[i]\n\nfor i in range(10000000000):\n if Tp*i > lcm:\n break\n if i > M:\n break\n ansT[Tp*i] = T[i]\n\nfor i in range(lcm):\n if ansS[i] == "0" or ansT[i] == "0":\n continue\n if ansS[i] != ansT[i]:\n ans = -1\n break\nprint(ans)\n', 'import math\nN, M = map(int, input().split())\nS = list(input())\nT = list(input())\nlcm = (N * M) // math.gcd(N, M)\nans = lcm\nSp = lcm//N\nTp = lcm//M\nlcmlcm = (Sp * Tp) // math.gcd(Sp, Tp)\nowari = min(Sp*N, M*Tp)\nfor i in range(0, owari, lcmlcm):\n if S[i//Sp] != T[i//Tp]:\n ans = -1\n break\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s043315444', 's409803358']
[379112.0, 10352.0]
[503.0, 31.0]
[558, 315]
p03231
u835283937
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['import math\ndef main5():\n N, M = map(int, input().split())\n S = input()\n T = input()\n\n G = math.gcd(N, M)\n L = (N * M) // G\n\n for i in range(G):\n if S[i * N // G] != T[i * M // G]:\n print(-1)\n exit()\n\n print(L)\n\nif __name__ == "__main__":\n main4()', 'import math\ndef main5():\n N, M = map(int, input().split())\n S = input()\n T = input()\n\n G = math.gcd(N, M)\n L = (N * M) // G\n\n for i in range(G):\n if S[i * N // G] != T[i * M // G]:\n print(-1)\n exit()\n\n print(L)\n\nif __name__ == "__main__":\n main5()']
['Runtime Error', 'Accepted']
['s768014979', 's602250876']
[9144.0, 9400.0]
[24.0, 31.0]
[300, 300]
p03231
u842170774
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["Jupyter Notebook\nAGC-n\nCurrent Kernel Logo\nPython 3 \n\n\n1\n#A\n2\nN=input()\n3\nA_list=list(map(int,input().split()))\n4\nn=0\n5\nfor i in range(len(A_list)-1):\n6\n if A_list[i]==A_list[i+1]:\n7\n A_list[i+1]+=10000\n8\n n+=1\n9\nprint(n)\n1\n2 3 4 5\n0\n\n1\n#B\n2\nimport math\n3\nT=int(input())\n4\nfor i in range(T):\n5\n check=0\n6\n A,B,C,D=map(int,input().split())\n7\n A_list=[]\n8\n if B>D:\n9\n print('No')\n10\n check=1\n11\n while check==0:\n12\n k=math.ceil((A-C)/B) if A>=C else 1\n13\n A-=k*B\n14\n if A<0:\n15\n print('No')\n16\n break\n17\n elif A<=C:\n18\n A+=D\n19\n if (A in A_list or A==0):\n20\n print('Yes')\n21\n break\n22\n A_list.append(A)\n1\n9 7 5 9\nNo\n\n1\n# B\n2\nimport math\n3\nT=int(input())\n4\nabcd=list(map(int,input().split()))\n5\nfor i in range(T):\n6\n sugoi='no'\n7\n A,B,C,D=abcd[4*i],abcd[4*i+1],abcd[4*i+2],abcd[4*i+3]\n8\n A_list=[]\n9\n if B>D:\n10\n print('No')\n11\n sugoi='yes'\n12\n while sugoi=='no':\n13\n k=math.ceil((A-C)/B) if A>=C else 1\n14\n A-=k*B\n15\n if A<0:\n16\n print('No')\n17\n break\n18\n elif A<=C:\n19\n A+=D\n20\n if A in A_list:\n21\n print('Yes')\n22\n break\n23\n A_list.append(A)\n\n1\nimport random\n2\nmoji=''\n3\nfor i in range(96*4):\n4\n k=random.randrange(10,100000)\n5\n moji+=str(k)+' '\n6\nprint(moji)\n49577 38748 51545 14229 66123 10159 13594 6667 75070 86954 43840 53738 39847 89585 9933 10129 70224 43454 45481 51487 54133 32286 78378 6497 73223 12189 87999 65011 43165 32546 8432 49737 43518 87213 90515 92099 74897 55565 46842 11081 84008 30991 44856 10305 72212 79367 86422 23049 34681 16096 93431 10032 78460 20377 44252 84334 98591 30972 75860 61883 48522 6988 85488 44798 39847 51447 49578 24157 69296 30493 8039 86315 33193 24243 23835 60725 99843 15788 27649 78531 7473 45213 58255 19078 63934 67284 38890 39155 25554 68632 65336 41502 97236 2317 93279 31025 60928 37625 44284 90314 42272 998 13481 53773 89382 98693 89134 76034 66399 95908 83397 9050 1185 9287 13075 22268 32701 95365 39540 3229 98603 59523 94096 44043 57083 6753 46555 1918 42947 8303 64854 37648 61525 98387 86705 38499 91181 48418 50920 29372 58029 24455 90742 14303 9907 73692 25233 34412 44743 33412 92719 94350 35737 16182 49794 25665 53330 47138 92539 696 54581 93518 36745 80424 59149 22790 697 72606 34502 94277 218 20114 81501 41453 44708 75123 25623 6222 51387 2561 47426 416 92800 23639 15666 47122 73472 99766 44914 48566 56201 71348 18268 93876 46551 35164 72609 59316 90756 20705 40484 12132 24345 21801 95572 69432 55858 73229 79945 68822 32966 73732 69373 7177 10817 53863 30883 46980 73951 88471 27314 53286 60991 14070 5757 23970 42978 55057 77030 64451 94209 19825 98049 89573 99554 23004 91677 11626 73234 26402 83987 76501 48311 50527 27379 8455 38923 86818 20238 67077 34259 22630 20689 60414 25516 61921 62161 31533 26844 6818 15493 19052 66511 77893 29455 21509 85070 90188 67693 61281 24487 86300 19230 90598 94835 64004 18362 57697 60707 19909 84171 95392 34820 63054 22243 90465 35761 45148 71903 58818 78033 45587 73626 13049 61152 46111 75380 88825 87574 34409 37390 62366 4025 68652 64514 86326 7689 80484 69780 15598 9697 54332 37388 45287 73660 41083 75293 55400 86645 99173 40831 29754 2975 9435 66198 66581 19149 73914 41325 25900 66326 93100 26224 45245 51190 80973 69280 75152 84285 24035 97505 46366 43162 56726 20367 86063 98812 64109 33949 3112 52584 22431 87110 59764 81415 66427 14112 79314 59522 60695 30091 22120 51701 90949 33273 75703 88454 54028 42622 18003 27609 80241 95556 35884 61115 91784 97200 60096 86929 94001 84670 81425 85365 34807 \n\n1\n#C\n2\nfrom itertools import permutations\n3\nN=int(input())\n4\nS=input()\n5\nS0=S\n6\nways=-1\n7\n\n14\nif ways!=0:\n15\n ways=0\n16\n nums=[0,]*(N-1)+[1,]*N\n17\n color=list(set(permutations(nums,2*N-1)))\n18\n color.sort()\n19\n for j in range(len(color)):\n20\n S=S0\n21\n s1,s2='',''\n22\n j_color=(0,)+color[j]\n23\n for i in range(2*N):\n24\n if j_color[i]==0:\n25\n s1+=S[i]\n26\n S=S[:i]+'0'+S[i+1:]\n27\n s2=(S.replace('0',''))[::-1]\n28\n print(j_color,s1,s2,s1==s2)\n29\n if s1==s2:ways+=1\n30\nprint(2*ways)\n11\nmippiisssisssiipsspiim\n\n1\nmoji='abcdefg'\n2\ni=3\n3\nmoji=moji[:i]+'0'+moji[i+1:]\n4\nmoji\n'abc0efg'\n\n1\n#027A\n2\nN,x=map(int,input().split())\n3\nchildren=list(map(int,input().split()))\n4\nchildren.sort()\n5\nfun=0 if x!=sum(children) else N\n6\nif fun==0:\n7\n for i in range(N):\n8\n x-=children[i]\n9\n if x>=0:fun+=1\n10\n else: break\n11\n if fun==N:fun-=1\n12\nprint(fun)\n2 10\n20 20\n0\n\n1\n#027B\n2\nN,X=map(int,input().split())\n3\ngomi=list(map(int,input().split()))\n4\n\u200b\n\n-1\n1\nN,M=map(int,input().split())\n2\nS=input()\n3\nT=input()\n4\n\u200b\n5\ndef gcd(a,b):\n6\n if a<b:a,b=b,a\n7\n c=a%b\n8\n while c>0:\n9\n a,b=b,c\n10\n c=a%b\n11\n return b\n12\n\u200b\n13\ndef enstr(A):\n14\n S=''\n15\n for i in A:\n16\n S+=i\n17\n return S\n18\n \n19\nif S[0]==T[0]:\n20\n gcd=gcd(N,M)\n21\n if N<M:\n22\n N,M=M,N\n23\n S,T=T,S\n24\n if gcd==M:\n25\n if S==T*(N//M):\n26\n print(N)\n27\n else:\n28\n print('-1')\n29\n else:\n30\n gcm=N*M//gcd\n31\n print(gcm)\n32\nprint(-1)\n3 2\na\nc\n-1\n\n15 9\n1\n15 9\n", "N,M=map(int,input().split())\nS=input()\nT=input()\n\ndef gcd(a,b):\n if a<b:a,b=b,a\n c=a%b\n while c>0:\n a,b=b,c\n c=a%b\n return b\n\ndef enstr(A,g):\n m=''\n for i in range(len(A)//g):\n m+=A[g*i]\n return m\n \nif S[0]==T[0]:\n gcd=gcd(N,M)\n n,m=N//gcd,M//gcd\n s,t=enstr(S,n),enstr(T,m)\n if s==t:\n print(N*M//gcd)\n else:\n print(-1)\nelse:\n print(-1)"]
['Runtime Error', 'Accepted']
['s516210602', 's961687743']
[2940.0, 3316.0]
[18.0, 24.0]
[5563, 412]
p03231
u871841829
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N, M = map(int, input().split())\nS = input()\nT = input()\n\nimport sys\n\ndef gcd(a, b):\n if a == 0:\n return b\n else:\n gcd(b%a, a)\n\ng = gcd(N, M)\nsn = N/g\nsm = M/g\n\nok = True\nfor k in range(0, g):\n a = k * sn\n b = k * sm\n if S[a] != T[b]:\n ok = False\n break\n\nif ok:\n print(N*M/g)\nelse:\n print(-1)', 'N, M = map(int, input().split())\nS = input()\nT = input()\n\nimport sys\n\nif S == T:\n print(N)\n sys.exit()\nprint(N)', 'N, M = map(int, input().split())\nS = input()\nT = input()\n\nimport sys\n\ndef gcd(a, b):\n if a == 0:\n return b\n else:\n return gcd(b%a, a)\n\n\ng = gcd(N, M)\nsn = N//g\nsm = M//g\n\nok = True\nfor k in range(0, g):\n a = k * sn\n b = k * sm\n if S[a] != T[b]:\n ok = False\n break\n\nif ok:\n print(N*M//g)\nelse:\n print(-1)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s143917580', 's908759684', 's040200832']
[3316.0, 3316.0, 3316.0]
[18.0, 18.0, 19.0]
[341, 117, 352]
p03231
u879870653
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def gcd(m,n) :\n x = max(m,n)\n y = min(m,n)\n if x%y == 0 :\n return y\n else :\n while x%y != 0 :\n z = x%y\n x = y\n y = z\n else :\n return z\n\ndef lcm(m,n) :\n return int(m*n/gcd(m,n))\n\nN,M = map(int,input().split())\nS = list(input())\nT = list(input())\nL = lcm(N,M)\nA = []\nB = []\nflag = 0\ncounter = 0\nfor i in range(N) :\n A.append(i*L//N+1)\nfor j in range(M) :\n b = j*L//M+1\n if j % (N//M) == 0 :\n index = N*j//M\n if S[index] == T[j] :\n counter += 1\n else :\n flag = 1\n break\n else :\n counter += 1\nif flag == 1 :\n print(-1)\nelse :\n if counter == M :\n print(L)\n#print(A)\n#print(counter)\n#print(flag)', 'def gcd(m,n) :\n x = max(m,n)\n y = min(m,n)\n if x%y == 0 :\n return y\n else :\n while x%y != 0 :\n z = x%y\n x = y\n y = z\n else :\n return z\n\ndef lcm(m,n) :\n return int(m*n/gcd(m,n))\n\nN,M = map(int,input().split())\nS = list(input())\nT = list(input())\nL = lcm(N,M)\nA = []\nB = []\nflag = 0\ncounter = 0\nif N >= M :\n for i in range(N) :\n A.append(i*L//N+1)\n for j in range(M) :\n b = j*L//M+1\n if j*N % M == 0 :\n index = N*j//M\n if S[index] == T[j] :\n counter += 1\n else :\n flag = 1\n break\n else :\n counter += 1\n if flag == 1 :\n print(-1)\n else :\n if counter == M :\n print(L)\nelse :\n for i in range(M) :\n A.append(i*L//M+1)\n for j in range(N) :\n b = j*L//N+1\n if j*M % N == 0 :\n index = M*j//N\n if T[index] == S[j] :\n counter += 1\n else :\n flag = 1\n break\n else :\n counter += 1\n if flag == 1 :\n print(-1)\n else :\n if counter == N :\n print(L)\n\n ']
['Runtime Error', 'Accepted']
['s534998746', 's489146907']
[7988.0, 8664.0]
[46.0, 80.0]
[755, 1227]
p03231
u888337853
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["import sys\nimport re\nimport math\nimport collections\nimport decimal\nimport bisect\nimport itertools\nimport fractions\n\nimport copy\n\n# import heapq\n# from collections import deque\n\n\n\nINF = sys.maxsize\nMOD = 10 ** 9 + 7\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n n, m = ns()\n s = list(input())\n t = list(input())\n\n gcd = n * m // fractions.gcd(n, m)\n\n s_idx = [gcd // n * i for i in range(n)]\n t_idx = [gcd // m * i for i in range(m)]\n\n ans = [-1] * (gcd + 1)\n for i, si in enumerate(s_idx):\n ans[si] = s[i]\n for i, ti in enumerate(t_idx):\n if ans[ti] != -1 and ans[ti] != t[i]:\n print(-1)\n exit(0)\n print(gcd)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nimport re\nimport math\nimport collections\nimport decimal\nimport bisect\nimport itertools\nimport fractions\n\nimport copy\n\n# import heapq\n# from collections import deque\n\n\n\nINF = sys.maxsize\nMOD = 10 ** 9 + 7\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n n, m = ns()\n s = list(input())\n t = list(input())\n\n gcd = n * m // fractions.gcd(n, m)\n\n s_idx = [gcd // n * i for i in range(n)]\n t_idx = [gcd // m * i for i in range(m)]\n\n ans = [-1] * (gcd + 1)\n for i, si in enumerate(s_idx):\n ans[si] = s[i]\n for i, ti in enumerate(t_idx):\n if ans[ti] != -1 and ans[ti] != t[i]:\n print(-1)\n exit(0)\n print(gcd)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\nimport re\nimport math\nimport collections\nimport decimal\nimport bisect\nimport itertools\nimport fractions\n\nimport copy\n\n# import heapq\n# from collections import deque\n\n\nsys.setrecursionlimit(10000001)\nINF = sys.maxsize\nMOD = 10 ** 9 + 7\n\nni = lambda: int(sys.stdin.readline())\nns = lambda: map(int, sys.stdin.readline().split())\nna = lambda: list(map(int, sys.stdin.readline().split()))\n\n\n# ===CODE===\n\n\ndef main():\n def euclid(a, b):\n if b == 0:\n return a\n else:\n return euclid(b, a % b)\n\n def multiple(a, b):\n return a * b // euclid(a, b)\n\n n, m = ns()\n s = list(input())\n t = list(input())\n\n gcd = multiple(n, m)\n\n s_idx = [gcd // n * i for i in range(n)]\n t_idx = [gcd // m * i for i in range(m)]\n t_set = set(t_idx)\n\n for idx in s_idx:\n if idx in t_set:\n if s[idx * n // gcd] != t[idx * m // gcd]:\n print(-1)\n exit(0)\n\n print(gcd)\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s066234550', 's948278807', 's571066223']
[195628.0, 195628.0, 19372.0]
[185.0, 184.0, 73.0]
[896, 896, 1025]
p03231
u896726004
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['from fractions import gcd\n\ndef lcm(m, n):\n return (m * n) // gcd(m, n)\n\ndef lcm_list(a):\n x = a[0]\n for i in range(1, len(a)):\n x = (x * a[i]) // gcd(x, a[i])\n return x\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\nl = lcm(N, M)\n\nif l==N or l==M:\n print(-1)\nelse:\n print(l)', 'from fractions import gcd\n\ndef lcm(m, n):\n return (m * n) // gcd(m, n)\n\ndef lcm_list(a):\n x = a[0]\n for i in range(1, len(a)):\n x = (x * a[i]) // gcd(x, a[i])\n return x\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\nl = lcm(N, M)\n\nif l==N or l==M or S[0]!=T[0]:\n print(-1)\nelse:\n print(l)', 'from fractions import gcd\n\ndef lcm(m, n):\n return (m * n) // gcd(m, n)\n\ndef lcm_list(a):\n x = a[0]\n for i in range(1, len(a)):\n x = (x * a[i]) // gcd(x, a[i])\n return x\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\nl = lcm(N, M)\n\nif l==N or l==M or N[0]!=M[0]:\n print(-1)\nelse:\n print(l)', 'from math import gcd\n\nN, M = map(int, input().split())\nS = input()\nT = input()\n\ndef lcm(m, n):\n return (m * n) // gcd(m, n)\n\nlc = lcm(N, M)\n\nss = lc//N\ntt = lc//M\n\nfor i in range(1, lc+1, ss*tt):\n s_tmp = (i - 1) // ss\n t_tmp = (i - 1) // tt\n\n if S[s_tmp] != T[t_tmp]:\n print(-1)\n exit()\n\nprint(lc)']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s304536648', 's859830823', 's915960853', 's714345206']
[5340.0, 5688.0, 5340.0, 9316.0]
[36.0, 54.0, 36.0, 30.0]
[311, 325, 325, 324]
p03231
u924406834
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['n,m = map(int,input().split())\ns = str(input())\nt = str(input())\na = 0\ndef get_gcd(a, b):\n if a < b:\n a, b = b, a\n if a % b == 0:\n return b\n else:\n return get_gcd(b, a % b)\ndef get_lcm(a, b, gcd):\n lcm = a * b // gcd\n return lcm\nsaisyou = get_lcm(n,m,get_gcd(n,m))\nans = 0\nif saisyou == n or saisyou == m:\n print(-1)\nelse:\n for l in range(saisyou,100000,saisyou):\n num = 0\n xlis = []\n ylis = []\n for i in range(min(n,m)):\n xlis.append(1+(l/n)*i+1)\n ylis.append(1+(l/m)*i+1)\n yset = set(ylis)\n xset = set(xlis)\n renketu = set(yset + xset)\n if len(yset) + len(xset) == renketu:\n ans = l\n break\n print(ans) ', 'n,m = map(int,input().split())\ns = str(input())\nt = str(input())\na = 0\ndef get_gcd(a, b):\n if a < b:\n a, b = b, a\n if a % b == 0:\n return b\n else:\n return get_gcd(b, a % b)\ndef get_lcm(a, b, gcd):\n lcm = a * b // gcd\n return lcm\nsaisyou = get_lcm(n,m,get_gcd(n,m))\nans = 0\nif saisyou == n or saisyou == m:\n print(-1)\nelse:\n for l in range(saisyou,100000,saisyou):\n num = 0\n xlis = []\n ylis = []\n for i in range(min(n,m)):\n xlis.append(1+(l/n)*i+1)\n ylis.append(1+(l/m)*i+1)\n yset = set(ylis)\n xset = set(xlis)\n for i in yset:\n hanntei = 0\n for j in xset:\n if i == j:\n if s[j] == t[i]:\n break\n else:\n hanntei += 1\n break\n if hanntei >= 1:\n break\n num += 1\n ans = l\n break \n if num == 1:\n print(ans) \n else:\n print(-1)', 'n,m = map(int,input().split())\ns = str(input())\nt = str(input())\nif n > m:\n bigg = n\n summoo = m\ndef get_gcd(a, b):\n if a < b:\n a, b = b, a\n if a % b == 0:\n return b\n else:\n return get_gcd(b, a % b)\ndef get_lcm(a, b, gcd):\n lcm = a * b // gcd\n return lcm\nsaisyou = get_lcm(n,m,get_gcd(n,m))\nunti = max(saisyou,n,m)\nunti = saisyou((unti//saisyou)*saisyou + saisyou)\nans = 0\nif bigg%summoo != 0:\n for l in range(unti,100000,saisyou):\n num = 0\n for i in range(min(n,m)):\n if 1+(l/n)*i+1 == 1+(l/m)*i+1:\n if s[i] == t[i]:\n pass\n else:\n num += 1\n break\n if num == 0:\n ans = l\n break\n print(ans)\nelse:\n print(-1)', 'n,m = map(int,input().split())\ns = str(input())\nt = str(input())\na = 0\ndef get_gcd(a, b):\n if a < b:\n a, b = b, a\n if a % b == 0:\n return b\n else:\n return get_gcd(b, a % b)\ndef get_lcm(a, b, gcd):\n lcm = a * b // gcd\n return lcm\nsaisyou = get_lcm(n,m,get_gcd(n,m))\nans = 0\nif saisyou == n or saisyou == m:\n print(-1)\nelse:\n for l in range(saisyou,100000,saisyou):\n num = 0\n xlis = []\n ylis = []\n for i in range(min(n,m)):\n xlis.append(1+(l/n)*i+1)\n ylis.append(1+(l/m)*i+1)\n yset = set(ylis)\n xset = set(xlis)\n for i in yset:\n hanntei = 0\n for j in xset:\n if i == j:\n if s[j-1] == t[i-1]:\n break\n else:\n hanntei += 1\n break\n if hanntei >= 1:\n break\n num += 1\n ans = l\n break \n if num == 1:\n print(ans) \n else:\n print(-1)', 'n,m = map(int,input().split())\ns = str(input())\nt = str(input())\ndef get_gcd(a, b): \n if a < b:\n a, b = b, a\n if a % b == 0:\n return b\n else:\n return get_gcd(b, a % b)\ndef get_lcm(a, b, gcd): \n lcm = a * b // gcd\n return lcm\nlcm = get_lcm(n,m,get_gcd(n,m)) \nlcm2 = get_lcm(lcm/n,lcm/m,get_gcd(lcm/n,lcm/m)) \nans = 0\nfor i in range(int(lcm//lcm2)):\n if s[int(i*lcm2//(lcm/n))] == t[int(i*lcm2//(lcm/m))]:\n pass\n else:\n ans = 1\n break\nif ans == 1:\n print(-1)\nelse:\n print(lcm)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s347894583', 's548558643', 's752001512', 's985357040', 's792176136']
[3444.0, 3444.0, 3316.0, 3444.0, 3444.0]
[19.0, 18.0, 18.0, 21.0, 21.0]
[752, 1043, 798, 1047, 683]
p03231
u932913455
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['def main28():\n import sys\n N, M = (int(x) for x in input().split())\n\n if N >= M:\n S = input()\n T = input()\n else:\n T = input()\n S = input()\n\n def lcm(n, m):\n gcd = 0\n for i in range(1, min(n, m)):\n if n % i == 0 and m % i == 0:\n gcd = i\n\n return int(n * m / gcd)\n\n LCM = lcm(N, M)\n a = int(LCM / max(N, M))\n b = int(LCM / min(N, M))\n\n for i in range(b):\n small_index = i * b\n if small_index % a == 0 and S[int(small_index / a)] != T[i]:\n print("-1")\n sys.exit()\n print(LCM)\n\nmain28()', 'def main28():\n import sys\n N, M = (int(x) for x in input().split())\n\n if N >= M:\n S = input()\n T = input()\n else:\n T = input()\n S = input()\n\n def lcm(n, m):\n gcd = 0\n for i in range(1, min(n, m) + 1):\n if n % i == 0 and m % i == 0:\n gcd = i\n\n return int(n * m / gcd)\n\n LCM = lcm(N, M)\n\n a = int(LCM / max(N, M))\n b = int(LCM / min(N, M))\n\n for i in range(min(N, M)):\n small_index = i * b\n if int(small_index % a) == 0:\n if S[int(small_index / a)] != T[i]:\n print("-1")\n sys.exit()\n print(LCM)\n\nmain28()']
['Runtime Error', 'Accepted']
['s836933869', 's215091041']
[3316.0, 3316.0]
[35.0, 41.0]
[624, 662]
p03231
u939552576
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
["import math\nimport numpy as np\nN,M = map(int,input().split())\nS = input()\nT = input()\n\nL = N*M // math.gcd(N,M)\n\nX = np.zeros(L, dtype=np.str)\n\nfor i in range(N):\n X[i*(L//N)] = S[i]\n\nfor i in range(M):\n if X[i*(L//M)] == '':\n X[i*(L//M)] = T[i]\n elif X[i*(L//M)] != T[i]:\n print('-1')\n exit()\n\nprint(L)", "import numpy as np\nN,M = map(int,input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n\twhile b:\n\t\ta, b = b, a % b\n\treturn a\n \n\ndef lcm(a, b):\n\treturn a * b // gcd (a, b)\n\nL = N*M // gcd(N,M)\n\nX = np.zeros(L, dtype=np.str)\n\nfor i in range(N):\n X[i*(L//N)] = S[i]\n\nfor i in range(M):\n if X[i*(L//M)] == '':\n X[i*(L//M)] = T[i]\n elif X[i*(L//M)] != T[i]:\n print('-1')\n exit()\n\nprint(L)", "N,M = map(int,input().split())\nS = input()\nT = input()\n\ndef gcd(a, b):\n while b:\n a, b = b, a % b\n return a\n\ndef lcm(a, b):\n return a * b // gcd (a, b)\n\nL = N*M // gcd(N,M)\n\nn = L // N\nm = L // M\n\nlist_n = [i for i in range(0,L,n)]\nlist_m = [i for i in range(0,L,m)]\n\nlist_common = sorted(list(set(list_n) & set(list_m)))\n\nfor i in list_common:\n if i == 0:\n if S[0] != T[0]:\n print('-1')\n exit()\n elif S[i//n] != T[i//m]:\n print('-1')\n exit()\n\nprint(L)"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s299519384', 's938140165', 's264263459']
[21096.0, 104904.0, 18672.0]
[832.0, 708.0, 40.0]
[333, 416, 517]
p03231
u941438707
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['print(-1)', 'from math import *\na,b=map(int,input().split())\ns=input()\nt=input()\ng=gcd(a,b)\nfor i in range(g):\n if s[a//g*i]!=t[b//g*i]:\n print(-1)\n exit()\nprint(a*b//g)']
['Wrong Answer', 'Accepted']
['s464261625', 's826200987']
[8920.0, 9156.0]
[29.0, 29.0]
[9, 173]
p03231
u941753895
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['# GCD\ndef gcd(x,y):\n while y:\n x,y=y,x%y\n return x\n\n# LCM\ndef lcm(x,y):\n return x*y/gcd(x,y)\n\na,b=map(int,input().split())\nif a%b==0 or b%a==0:\n print(-1)\nelse:\n print(lcm(a,b))', '# GCD\ndef gcd(x,y):\n while y:\n x,y=y,x%y\n return x\n\n# LCM\ndef lcm(x,y):\n return x*y/gcd(x,y)\n\na,b=map(int,input().split())\ninput()\ninput()\nprint(-1)', "import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\n# GCD -- START --\ndef gcd(x,y):\n while y:\n x,y=y,x%y\n return x\n# GCD --- END ---\n\n# LCM -- START --\ndef lcm(x,y):\n return x*y//gcd(x,y)\n# LCM --- END ---\n\ndef main():\n n,m=LI()\n s=S()\n t=S()\n a=lcm(n,m)\n\n y=['a']*(10**10)\n\n x=['.']*a\n for i in range(n):\n x[i*(a//n)]=s[i]\n\n # print(x)\n\n for i in range(m):\n if x[i*(a//m)]!='.' and x[i*(a//m)]!=t[i]:\n return -1\n\n return a\n\n# main()\nprint(main())\n", 'import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\n# GCD -- START --\ndef gcd(x,y):\n while y:\n x,y=y,x%y\n return x\n# GCD --- END ---\n\n# LCM -- START --\ndef lcm(x,y):\n return x*y//gcd(x,y)\n# LCM --- END ---\n\ndef main():\n n,m=LI()\n s=S()\n t=S()\n a=lcm(n,m)\n\n x={}\n for i in range(n):\n x[i*(a//n)]=s[i]\n\n # print(x)\n\n for i in range(m):\n if i*(a//m) in x:\n if t[i]!=x[i*(a//m)]:\n return -1\n\n return a\n\n# main()\nprint(main())\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s229995223', 's435835719', 's872471001', 's807762264']
[3060.0, 3308.0, 5416.0, 17408.0]
[18.0, 18.0, 39.0, 67.0]
[185, 154, 929, 909]
p03231
u970738863
2,000
1,048,576
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a **good string** when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \frac{L}{N}+1)-th, ..., ((N-1)\times\frac{L}{N}+1)-th characters of X, without changing the order, results in S. * Concatenating the 1-st, (\frac{L}{M}+1)-th, (2 \times \frac{L}{M}+1)-th, ..., ((M-1)\times\frac{L}{M}+1)-th characters of X, without changing the order, results in T. Determine if there exists a good string. If it exists, find the length of the shortest such string.
['N,M = map(int,input().split())\nS = input()\nT = input()\n\ndef gcd(a,b):\n while b>0:\n a,b = b,a%b\n return a\n\ndef lcm(a,b):\n return a*b//gcd(a,b)\n\nL = lcm(N,M)\nG = gcd(N,M)\nn = L//N\nm = L//M\n\ns = [S[i*m] for i in range(G)]\nt = [T[i*n] for i in range(G)]\n\nif s == t or (G == 1 and S[0]==T[0}]):\n print(L)\nelse:\n print(-1)\n', 'N,M = map(int,input().split())\nS = input()\nT = input()\n\ndef gcd(a,b):\n while b>0:\n a,b = b,a%b\n return a\n\ndef lcm(a,b):\n return a*b//gcd(a,b)\n\nL = lcm(N,M)\nG = gcd(N,M)\nn = L//N\nm = L//M\n\ns = [S[i*m] for i in range(G)]\nt = [T[i*n] for i in range(G)]\n\nif s == t or (G == 1 and S[0]==T[0]):\n print(L)\nelse:\n print(-1)\n']
['Runtime Error', 'Accepted']
['s988032624', 's983559229']
[3188.0, 3700.0]
[18.0, 23.0]
[339, 338]
p03232
u013408661
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['import math\nN=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\np=10**9 +7\n\nx=math.factorial(N)%p\n\nfor i in range(1,N+1):\n \n k=pow(i,p-2,p)\n sum+= (x*k)%p\n sum= sum%p\n SUM.append(sum)\n\n\n\nfor i in range(N):\n ans+= (number[i]*(SUM[i]+SUM[N-i-1]-x))%p\n ans= ans%p\n\nprint(ans)', 'import math\nn=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\nfor i in range(1,n+1):\n sum+= 1/i\n sum= sum//(10**9 +7)\n SUM.append(sum)\nans=0\nx=math.factorial(n)%(10**9 +7)\nfor i in range(n):\n ans+= number[i]*x*(SUM[n-1-i]+SUM[i]-1)\n ans=ans//(10**9 +7)\nprint(ans)', 'import math\nn=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\nfor i in range(1,n+1):\n sum+= fraction(1,i)\n sum= sum%(10**9 +7)\n SUM.append(sum)\nans=0\nx=math.factorial(n)%(10**9 +7)\nfor i in range(n):\n ans+= number[i]*(x*int(SUM[n-1-i]+SUM[i]-1))\n ans=ans%(10**9 +7)\nprint(ans)', 'import math\nn=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\nfor i in range(1,n+1):\n sum+= 1/i\n sum= sum%(10**9 +7)\n SUM.append(sum)\nans=0\nx=math.factorial(n)%(10**9 +7)\nfor i in range(n):\n ans+= number[i]*(x*int((SUM[n-1-i]+SUM[i]-1)+0.99))\n ans=ans%(10**9 +7)\nprint(ans)', 'import math\nN=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\np=10**9 +7\n\nx=math.factorial(N)%p\n\nfor i in range(1,N+1):\n \n k=pow(i,p-2,p)\n sum+= (x*k)%p\n SUM.append(sum)\n\n\n\nfor i in range(N):\n ans+= (number[i]*(SUM[i]+SUM[N-i]-x))%p\n ans= ans%p\n\nprint(ans)', 'import math\nn=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\np=10**9 +7\nx=math.factorial(n)%(10**9 +7)\nfor i in range(1,n+1):\n k=pow(i,p-2,p)\n sum+= (x*k)%p\n sum= sum%(10**9 +7)\n SUM.append(sum)\nans=0\nfor i in range(n):\n ans+= number[i]*x*(SUM[n-1-i]+SUM[i]-1)\n ans=ans%(p)\nprint(ans)\n', 'import math\nN=int(input())\nnumber=list(map(int,input().split()))\nSUM=[]\nsum=0\np=10**9 +7\n\nx=math.factorial(N)%p\n\nfor i in range(1,N+1):\n \n k=pow(i,p-2,p)\n sum+= (x*k)%p\n sum= sum%p\n SUM.append(sum)\nans=0\n\n\n\nfor i in range(N):\n ans+= (number[i]*(SUM[i]+SUM[N-i-1]-x))%p\n ans= ans%p\n\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s169479322', 's212355888', 's502853036', 's538405482', 's540664093', 's642549655', 's957565099']
[15020.0, 15020.0, 15020.0, 15020.0, 15148.0, 15020.0, 15020.0]
[654.0, 398.0, 43.0, 376.0, 647.0, 721.0, 713.0]
[495, 284, 297, 294, 480, 308, 501]
p03232
u067983636
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['N = int(input())\nA = list(map(int, input().split()))\nR = [0] * (N + 1)\nP = [1] * (N + 1)\nmod = 10 ** 9 + 7\n\ndef power(x, y):\n if y == 0:\n return 1\n elif y == 1: \n return x % mod\n elif y % 2 == 0: \n return power(x, y//2)**2 % mod\n else: \n return power(x, y//2)**2 * x % mod\n\ndef rev(a):\n return power(a, mod - 2)\n \nfor n in range(N + 1):\n R[n] = R[n - 1] + rev(n)\n if n != 0:\n P[n] = P[n - 1] * n\n \nC = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]\n\nprint(C)\nprint(sum([a * c for a, c in zip(C, A)]) * P[N] % mod)', 'import numpy as np\nN = int(input())\nA = list(map(int, input().split()))\nR = np.zeros(N + 1, dtype="int64")\nP = np.ones(N + 1, dtype="int64")\nmod = 10 ** 9 + 7\n\ndef rev(a):\n return pow(a, mod - 2, mod)\n \nfor n in range(N + 1):\n r = rev(n)\n R[n] = (R[n - 1] + r) % mod\n if n != 0:\n P[n] = (P[n - 1] * n) % mod\n\nC = [(R[j] + R[N - j + 1] - 1) % mod for j in range(1, N + 1)]\n\nres = 0\nfor i in range(N):\n res = (res + (A[i] * C[i]) % mod) % mod\n\nprint(res * P[N] % mod)\n#print((sum([a * c % mod for a, c in zip(C, A)]) * P[N]) % mod)\n']
['Wrong Answer', 'Accepted']
['s700713108', 's485599383']
[1620640.0, 24340.0]
[2206.0, 1620.0]
[587, 555]
p03232
u089032001
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['ef multiply(x, y):\n return (x * y) % mod\n\n\ndef power(x, y):\n if y == 0:\n return 1\n elif y == 1:\n return x\n elif x == 1:\n return 1\n elif x == 0:\n return 0\n else:\n # print(mod)\n tmp = power(x, y // 2)\n return (multiply(tmp, tmp) * [1, x][y % 2]) % mod\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\nplist = [0]\nnfact = 1\nN\ntmp = 0\nfor i in range(1, N):\n tmp = (tmp + power(i + 1, mod - 2)) % mod\n nfact = (nfact * (i + 1)) % mod\n plist.append(tmp)\n\nans = 0\n# print(plist)\n# print(nfact)\nfor i, a in enumerate(A):\n \n tmp = (1 + plist[i] + plist[N - i - 1]) % mod\n ans = (ans + multiply(multiply(a, tmp), nfact)) % mod\n\nprint(ans)', 'def multiply(x, y):\n return (x * y) % mod\n\n\ndef power(x, y):\n if y == 0:\n return 1\n elif y == 1:\n return x\n elif x == 1:\n return 1\n elif x == 0:\n return 0\n else:\n # print(mod)\n tmp = power(x, y // 2)\n return (multiply(tmp, tmp) * [1, x][y % 2]) % mod\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\nmod = 10 ** 9 + 7\n\nplist = [0]\nnfact = 1\nN\ntmp = 0\nfor i in range(1, N):\n tmp = (tmp + power(i + 1, mod - 2)) % mod\n nfact = (nfact * (i + 1)) % mod\n plist.append(tmp)\n\nans = 0\n# print(plist)\n# print(nfact)\nfor i, a in enumerate(A):\n \n tmp = (1 + plist[i] + plist[N - i - 1]) % mod\n ans = (ans + multiply(multiply(a, tmp), nfact)) % mod\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s828102766', 's152777587']
[2940.0, 14480.0]
[17.0, 1994.0]
[763, 764]
p03232
u218843509
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['import sys\nsys.setrecursionlimit(10**7)\n\nn = int(input())\n#a = list(map(int, input().split()))\nMOD = 10 ** 9 + 7\n\ndef extended_euclid(x, y):\n c0, c1 = x, y\n a0, a1 = 1, 0\n b0, b1 = 0, 1\n\n while c1 != 0:\n m = c0 % c1\n q = c0 // c1\n\n c0, c1 = c1, m\n a0, a1 = a1, (a0 - q * a1)\n b0, b1 = b1, (b0 - q * b1)\n\n # return c0, a0, b0\n return a0\n\ndef quotient(p, q): \n\treturn (extended_euclid(q, MOD) * p) % MOD\n\ndef factorial(i):\n\tif i == 1:\n\t\treturn 1\n\telse:\n\t\treturn (factorial(i-1) * i) % MOD\n\ninv_list = [1]\nfor i in range(2, n+1):\n\tinv_list.append((inv_list[-1] + quotient(1, i)) % MOD)\n\n#print(inv_list[-1])\n#print(factorial(n))\n\nans = 0\nfor i in range(n):\n\tans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD\n\tans %= MOD\nans *= factorial(n)\nans %= MOD\nprint(ans)', 'import sys\nsys.setrecursionlimit(10**7)\n\nn = int(input())\na = list(map(int, input().split()))\nMOD = 10 ** 9 + 7\n\ndef extended_euclid(x, y):\n c0, c1 = x, y\n a0, a1 = 1, 0\n b0, b1 = 0, 1\n\n while c1 != 0:\n m = c0 % c1\n q = c0 // c1\n\n c0, c1 = c1, m\n a0, a1 = a1, (a0 - q * a1)\n b0, b1 = b1, (b0 - q * b1)\n\n # return c0, a0, b0\n return a0\n\ndef quotient(p, q): \n\treturn (extended_euclid(q, MOD) * p) % MOD\n\ndef factorial(i):\n\tif i == 1:\n\t\treturn 1\n\telse:\n\t\treturn (factorial(i-1) * i) % MOD\n\ninv_list = [1]\nfor i in range(2, n+1):\n\tinv_list.append((inv_list[-1] + quotient(1, i)) % MOD)\n\n#print(inv_list[-1])\n#print(factorial(n))\n\nans = 0\nfor i in range(n):\n\tans += ((inv_list[i] + inv_list[n-1-i] - 1) * a[i]) % MOD\n\tans %= MOD\nans *= factorial(n)\nans %= MOD\nprint(ans)']
['Runtime Error', 'Accepted']
['s181152208', 's800783014']
[7124.0, 91636.0]
[406.0, 598.0]
[840, 839]
p03232
u283869437
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['m=10**9+7\ninput()\ni=s=r=0\nf=1\na=map(int,input().split())\nfor _ in a:\n s+=pow(i+1,m-2,m)\n r+=a[i]*~-s+a[~i]*s\n i+=1\n f=f*i%m\nprint(r*f%m)', 'm=10**9+7\ninput()\ni=s=r=0\nf=1\na=input().split()\nfor _ in a:\n s+=pow(i+1,m-2,m);r+=int(a[i])*~-s+int(a[~i])*s;i+=1;f=f*i%m\nprint(r*f%m)']
['Runtime Error', 'Accepted']
['s047048093', 's233602815']
[11480.0, 11484.0]
[27.0, 500.0]
[136, 134]
p03232
u562016607
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
['N=int(input())\nA=[int(i) for i in input().split()]\nP=10**9+7\ndef egcd(a, b):\n (x, lastx) = (0, 1)\n (y, lasty) = (1, 0)\n while b != 0:\n q = a // b\n (a, b) = (b, a % b)\n (x, lastx) = (lastx - q * x, x)\n (y, lasty) = (lasty - q * y, y)\n return (lastx, lasty, a)\ndef inv(x):\n return egcd(x,P)[0]%P\nQ=[0 for i in range(N)]\nI=[inv(i) for i in range(1,N+2)]\nU=[0 for i in range(N+2)]\nfor i in range(N):\n U[i+1]=(U[i]+I[i])%P\nfor j in range(N):\n Q[j]=(U[j+1]+U[N-j-1]-1)%P\nans=0\nfor i in range(N):\n ans+=A[i]*Q[i]\n ans=ans%P\nprint(ans)\n', 'P=10**9+7\ndef egcd(a, b):\n (x, lastx) = (0, 1)\n (y, lasty) = (1, 0)\n while b != 0:\n q = a // b\n (a, b) = (b, a % b)\n (x, lastx) = (lastx - q * x, x)\n (y, lasty) = (lasty - q * y, y)\n return (lastx, lasty, a)\ndef inv(x):\n return egcd(x,P)[0]\nN=int(input())\nA=[int(i) for i in input().split()]\nF=[inv(i) for i in range(N)]\nFact=[0 for i in range(N+1)]\nFact[0]=1\nfor i in range(N):\n Fact[i+1]=(Fact[i]*(i+1))%P\nFB=[(Fact[N]*inv(i+1))%P for i in range(N)]\ntmp1=0\ntmp2=0\ntmp3=0\ntmp4=0\nfor i in range(N):\n tmp1+=A[i]\n tmp1=tmp1%P\n \n tmp2+=FB[N-i-1]*(i+1)\n tmp2=tmp2%P\n \n tmp3+=i*A[i]\n tmp3=tmp3%P\n \n tmp4+=FB[N-i-1]\n tmp4=tmp4%P\nans=(Fact[N]*tmp1)%P\nans=ans+(tmp1*tmp2)%P + (tmp3*tmp4)%P\nprint(ans%P)\n', 'N=int(input())\nA=[int(i) for i in input().split()]\nP=10**9+7\ndef egcd(a, b):\n (x, lastx) = (0, 1)\n (y, lasty) = (1, 0)\n while b != 0:\n q = a // b\n (a, b) = (b, a % b)\n (x, lastx) = (lastx - q * x, x)\n (y, lasty) = (lasty - q * y, y)\n return (lastx, lasty, a)\ndef inv(x):\n return egcd(x,P)[0]%P\nQ=[0 for i in range(N)]\nI=[inv(i) for i in range(1,N+2)]\nU=[0 for i in range(N+2)]\nFact=[0 for i in range(N+1)]\nFact[0]=1\nfor i in range(N):\n Fact[i+1]=((i+1)*Fact[i])%P\nfor i in range(N+1):\n U[i+1]=(U[i]+I[i])%P\nfor j in range(N):\n Q[j]=(U[j+1]+U[N-j]-1)%P\nans=0\nfor j in range(N):\n ans+=A[j]*Q[j]\n ans=ans%P\nprint((ans*Fact[N])%P)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s065326361', 's448006244', 's110702582']
[19068.0, 19212.0, 23168.0]
[526.0, 960.0, 563.0]
[583, 774, 685]
p03232
u745087332
2,000
1,048,576
There are N blocks arranged in a row, numbered 1 to N from left to right. Each block has a weight, and the weight of Block i is A_i. Snuke will perform the following operation on these blocks N times: * Choose one block that is still not removed, and remove it. The cost of this operation is the sum of the weights of the blocks that are connected to the block being removed (including itself). Here, two blocks x and y ( x \leq y ) are _connected_ when, for all z ( x \leq z \leq y ), Block z is still not removed. There are N! possible orders in which Snuke removes the blocks. For all of those N! orders, find the total cost of the N operations, and calculate the sum of those N! total costs. As the answer can be extremely large, compute the sum modulo 10^9+7.
["# coding:utf-8\n\nimport sys\n\n\ninput = sys.stdin.readline\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\n\ndef inpl(): return list(map(int, input().split()))\n\n\n\n\ndef pow_mod(a, p):\n if p == 0: return 1\n\n if p % 2 == 0:\n half_p = p // 2\n half = pow_mod(a, half_p)\n return half * half % MOD\n else:\n return a * pow_mod(a, p - 1) % MOD\n\n\ndef solve(N, A):\n \n inv_sum = [0]\n for i in range(N):\n inv_sum.append((inv_sum[-1] + pow_mod(i + 1, MOD - 2)) % MOD)\n del inv_sum[0]\n print(inv_sum)\n\n \n \n ans = 0\n for i in range(N):\n ans += + A[i] * (inv_sum[N - 1 - i] + inv_sum[i] - 1)\n ans %= MOD\n\n \n fact = 1\n for i in range(N):\n fact *= (i + 1)\n fact %= MOD\n\n return ans * fact % MOD\n\n\nN = int(input())\nA = inpl()\nprint(solve(N, A))\n", "# coding:utf-8\n\nimport sys\n\n\ninput = sys.stdin.readline\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\n\ndef inpl(): return list(map(int, input().split()))\n\n\n\n\ndef pow_mod(a, p):\n if p == 0: return 1\n\n if p % 2 == 0:\n half_p = p // 2\n half = pow_mod(a, half_p)\n return half * half % MOD\n else:\n return a * pow_mod(a, p - 1) % MOD\n\n\ndef solve(N, A):\n \n fact = [1] * N\n for i in range(1, N):\n fact[i] = fact[i - 1] * (i + 1) % MOD\n\n \n fact_inv = [1] * N\n fact_inv[-1] = pow_mod(fact[-1], MOD - 2)\n for i in range(N - 1, 0, -1):\n tmp = fact_inv[i] * (i + 1)\n tmp %= MOD\n fact_inv[i - 1] = tmp\n\n \n inv = [1]\n for i in range(1, N):\n inv.append((fact[i - 1] * fact_inv[i]) % MOD)\n\n \n inv_sum = [1]\n for i in range(1, N):\n inv_sum.append((inv_sum[-1] + inv[i]) % MOD)\n\n \n ans = 0\n for i in range(N):\n ans += A[i] * (inv_sum[i] + inv_sum[N - 1 - i] - 1)\n ans %= MOD\n\n \n return ans * fact[-1] % MOD\n\n\nN = int(input())\nA = inpl()\nprint(solve(N, A))\n"]
['Wrong Answer', 'Accepted']
['s026502307', 's535253599']
[15200.0, 23372.0]
[1575.0, 176.0]
[1069, 1323]
p03233
u170201762
2,000
1,048,576
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.
['N = int(input())\nC = [list(map(int,input().split())) for i in range(N)]\nC.sort()\nans0 = 0\nans1 = 0\nans2 = 0\nAM = []\nAm = []\nBM = []\nBm = []\nfor i in range(N):\n ans0 += C[i][0]\n ans1 += C[i][1]\n Min = min(C[i][0],C[i][1])\n Max = max(C[i][0],C[i][1])\n ans2 += Min\n if Min == C[i][0]:\n Am.append(C[i][0])\n BM.append(C[i][1])\n else:\n AM.append(C[i][0])\n Bm.append(C[i][1])\nans3 = sum(sorted(A+B)[:N])\nif ans3 == ans2:\n ans3 += min(min(AM)-max(Am),min(BM)-max(Bm))\n \nans = min(ans0,ans1,ans3)\nprint(ans)', 'N = int(input())\nA = []\nB = []\nSa = 0\nSb = 0\nfor i in range(N):\n a,b = map(int,input().split())\n A.append([a,i])\n B.append([b,i])\n Sa += a\n Sb += b\nC = sorted(A+B)\nind = []\nans = 0\nfor i in range(N):\n ind.append(C[i][1])\n ans += C[i][0]\nind = set(ind)\nif len(ind) == N:\n if C[N-1][1] != C[N][1]:\n ans += C[N][0]-C[N-1][0]\n else:\n ans += min(C[N][0]-C[N-2][0],C[N+1][0]-C[N-1][0])\nans = min(Sa,Sb,ans)\nprint(ans)']
['Runtime Error', 'Accepted']
['s034615879', 's796329243']
[29600.0, 42220.0]
[613.0, 784.0]
[553, 452]
p03233
u340781749
2,000
1,048,576
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.
['n = int(input())\naaa = [tuple(map(int, input().split())) for _ in range(n)]\nlo = [min(a) for a in aaa]\nhi = [max(a) for a in aaa]\nlo.sort(reverse=True)\nhi.sort()\nans = sum(lo)\n\nfor l, h in zip(lo, hi):\n if l <= h:\n break\n ans += h\n ans -= l\n\nprint(ans)\n', 'from operator import itemgetter\nfrom itertools import chain\n\nn = int(input())\naaa = [tuple(map(int, input().split())) for _ in range(n)]\nflatten = sorted(chain.from_iterable([(a, i), (b, i)] for i, (a, b) in enumerate(aaa)))\npicked = set()\nans = 0\n\nfor ab, i in flatten[:n]:\n picked.add(i)\n ans += ab\n\nif len(picked) == n:\n exclude = flatten[n - 1]\n include = flatten[n]\n if exclude[1] == include[1]:\n tmp1 = include[0] - flatten[n - 2][0]\n tmp2 = flatten[n + 1][0] - exclude[0]\n ans += min(tmp1, tmp2)\n else:\n ans -= exclude[0]\n ans += include[0]\n\nans = min(ans, sum(map(itemgetter(0), aaa)), sum(map(itemgetter(1), aaa)))\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s494471230', 's772781587']
[18580.0, 41644.0]
[438.0, 632.0]
[269, 689]
p03233
u816116805
2,000
1,048,576
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.
['#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n\n#\n\n"""\nAGC028 C\n"""\n\nimport itertools\nfrom operator import itemgetter\n\nn = int(input())\nabli0 = [tuple(map(int, input().split())) for i in range(n)]\neabli0 = enumerate(abli0)\nabli1 = list(map(lambda t: ((t[1][0], t[0], 0), (t[1][1], t[0], 1)), eabli0))\nabli = list(itertools.chain.from_iterable(abli1))\nabli.sort(key=itemgetter(1))\ntmpans0 = sum(map(lambda t: t[0], abli[:n]))\nalist = [i for x, i, aorb in abli[:n] if not aorb]\nblist = [i for x, i, aorb in abli[:n] if aorb]\nflag = bool([i for i in range(n) if i in alist and i in blist])\n\ny, j, arob2 = abli[n]\nz, k, arob3 = abli[n+1]\nif flag:\n tmpans = tmpans0\nelse:\n tmpans = 2**62\n for x, i, aorb in abli[:n]:\n if j != i:\n tmp = tmpans0-x+y\n else:\n tmp = tmpans0-x+z\n if tmpans > tmp:\n tmpans = tmp\n\nleftsum = sum(map(lambda x: x[0], abli0))\nrightsum = sum(map(lambda x: x[1], abli0))\n\nprint(min(leftsum, rightsum, tmpans))\n', '#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n\n#\n\n"""\nAGC028 C\n"""\n\nfrom operator import itemgetter\n\nn = int(input())\nabli = []\nfor i in range(n):\n a, b = map(int, input().split())\n abli.append((a, i, 0))\n abli.append((b, i, 1))\n\nabli.sort(key=itemgetter(0))\ntmpans0 = sum(map(itemgetter(0), abli[:n]))\naiset = set([i for x, i, aorb in abli[:n] if not aorb])\nbiset = set([i for x, i, aorb in abli[:n] if aorb])\nflag = bool(set.intersection(aiset, biset))\n\n\ny, j, arob2 = abli[n]\nz, k, arob3 = abli[n+1]\n\nif flag:\n tmpans = tmpans0\nelse:\n min1 = y-max([x for x, i, aorb in abli[:n] if j != i])\n min2 = z-max([x for x, i, aorb in abli[:n] if j == i])\n tmpans = tmpans0 + min(min1, min2)\n\nleftsum = sum([aa for aa, i, aorb in abli if not aorb])\nrightsum = sum([bb for bb, i, aorb in abli if aorb])\n\nprint(min(leftsum, rightsum, tmpans))\n']
['Wrong Answer', 'Accepted']
['s294780802', 's557510241']
[46664.0, 36164.0]
[2110.0, 651.0]
[1005, 872]
p03233
u834415466
2,000
1,048,576
We have a directed weighted graph with N vertices. Each vertex has two integers written on it, and the integers written on Vertex i are A_i and B_i. In this graph, there is an edge from Vertex x to Vertex y for all pairs 1 \leq x,y \leq N, and its weight is {\rm min}(A_x,B_y). We will consider a directed cycle in this graph that visits every vertex exactly once. Find the minimum total weight of the edges in such a cycle.
['n=int(input())\na=[]\nb=[]\nfor i in range(n):\n p,q=map(int,input().split())\n a.append(p)\n a.append(q)\na.sort()\nresult=0\nfor i in range(n):\n result+=a[i]\nprint(result)', 'n=int(input())\na=[]\nb=[]\nfor i in range(n):\n p,q=map(int,input().split())\n a.append((p,i,0))\n a.append((q,i,1))\na.sort(key=lambda x:x[0])\nresult=0\nl=[0]*n\nflag=0\nfor i in range(n):\n if l[a[i][1]]==1:\n flag=1\n break\n else:\n l[a[i][1]]=1\nt=a[0][2]\ns=0\nfor i in range(n):\n s+=a[i][2]-a[0][2]\nif s==0:\n flag=1\nif flag==1:\n\n for i in range(n):\n result+=a[i][0]\n print(result)\nelse:\n if a[n-1][1]==a[n][1]:\n for i in range(n):\n result+=a[i][0]\n result+=min(a[n+1][0]-a[n-1][0],a[n][0]-a[n-2][0])\n print(result)\n else:\n for i in range(n):\n result+=a[i][0]\n result+=a[n][0]-a[n-1][0]\n print(result)']
['Wrong Answer', 'Accepted']
['s222632415', 's988603380']
[11784.0, 31736.0]
[407.0, 563.0]
[176, 715]