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
|
---|---|---|---|---|---|---|---|---|---|---|
p02549 | u407778590 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N, K = map(int, input().split())\n\nidou = set()\nfor i in range(0, K):\n L, R = map(int, input().split())\n idou = idou | set(range(L, R + 1))\n\nidou = list(idou)\n\nmoves = [0] * N\nmoves[0] = 1\nfor i in range(0, N):\n for j in range(0, len(idou)):\n if i + idou[j] < N:\n moves[i + idou[j]] += moves[i]\n\nprint(moves)\nprint(moves[N - 1] % 998244353)\n', 'N, K = map(int, input().split())\n\nL = [0] * K\nR = [0] * K\nfor i in range(0, K):\n L[i], R[i] = map(int, input().split())\n\nmoves = [0] * N\nmoves[0] = 1\n\nrui_wa = [0] * N\nrui_wa[0] = 1\n\nfor i in range(1, N):\n for j in range(0, K):\n l = max(i - L[j], 0)\n r = max(i - R[j], 0)\n if i - L[j] < 0:\n continue\n\n moves[i] += (rui_wa[l] - rui_wa[r - 1]) % 998244353\n\n rui_wa[i] = (moves[i] + rui_wa[i - 1]) % 998244353\n\n\n\nprint(moves[N - 1] % 998244353)\n'] | ['Wrong Answer', 'Accepted'] | ['s264836860', 's176160941'] | [38068.0, 26824.0] | [2207.0, 1433.0] | [367, 491] |
p02549 | u469254913 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['# import numpy as np\n# import math\n# import copy\n# from collections import deque\nimport sys\ninput = sys.stdin.readline\n\n# from numba import njit,i8\n\n\n\ndef give_dp(N,K,mod,LR,dp,l,r):\n for i in range(N):\n if i > 0:\n dp[i] += dp[i-1]\n dp[i] %= mod\n for k in range(K):\n l = LR[k][0]\n r = LR[k][1]\n if i + l < N:\n dp[i+l] += dp[i]\n dp[i+1] %= mod\n if i + r < N:\n dp[i+r+1] -= dp[i]\n dp[i+1] %= mod\n return dp[-1]\n\n\ndef main():\n N,K = map(int,input().split())\n LR = [list(map(int,input().split())) for i in range(K)]\n # LR = np.array(LR)\n\n mod = 998244353\n\n dp = [0 for i in range(N)]\n dp[0] = 1\n dp[1] = -1\n # dp = np.array(dp)\n\n res = give_dp(N,K,mod,LR,dp,0,0)\n res %= mod\n\n print(res)\n\n\n\nmain()\n', '# import numpy as np\n# import math\n# import copy\n# from collections import deque\nimport sys\ninput = sys.stdin.readline\n\n# from numba import njit,i8\n \n \n\ndef give_dp(N,K,mod,LR,dp,l,r):\n for i in range(N):\n if i > 0:\n dp[i] += dp[i-1]\n dp[i] %= mod\n for k in range(K):\n l = LR[k][0]\n r = LR[k][1]\n if i + l < N:\n dp[i+l] += dp[i]\n dp[i+1] %= mod\n if i + r + 1 < N:\n dp[i+r+1] -= dp[i]\n dp[i+1] %= mod\n return dp[-1]\n \n \ndef main():\n N,K = map(int,input().split())\n LR = [list(map(int,input().split())) for i in range(K)]\n # LR = np.array(LR)\n \n mod = 998244353\n \n dp = [0 for i in range(N)]\n dp[0] = 1\n dp[1] = -1\n # dp = np.array(dp)\n \n res = give_dp(N,K,mod,LR,dp,0,0)\n res %= mod\n \n print(res)\n \n \n \nmain()'] | ['Runtime Error', 'Accepted'] | ['s585078445', 's628128833'] | [16920.0, 17044.0] | [251.0, 882.0] | [944, 958] |
p02549 | u521866787 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['n,k =map(int,input().split())\ns =[]\nfor i in range(k):\n l,r=map(int,input().split())\n s+=(list(range(l,r+1)))\nS= set(s)\nprint(S)\n\nmod = 998244353\n\n# How many are there to climb\nstep = [0] * (n+1)\n\n\nfor i in range(1,n+1):\n for s in S:\n if i+s<=n:\n step[i+s]+=1\nprint(step[n])', 'mod = 998244353\nn,k =map(int,input().split())\nstep =[0]*(n+1)\n# step[0]=1\nstep[1]=1\nstepsum=[0]*(n+1)\nstepsum[1]=1\nl=[0]*k\nr=[0]*k\nfor i in range(k):\n l[i],r[i]=map(int,input().split())\n\nfor i in range(2,n+1):\n for j in range(k):\n li = i - r[j]\n ri = i - l[j]\n if ri <= 0:\n continue\n \n step[i] += stepsum[ri] - stepsum[max(0,li-1)]\n # step[i] %= mod\n # print(step)\n stepsum[i] = ( stepsum[i-1] + step[i] )%mod\n\n\nprint(step[n]%mod)'] | ['Wrong Answer', 'Accepted'] | ['s525698265', 's096764097'] | [29748.0, 25148.0] | [2207.0, 914.0] | [301, 515] |
p02549 | u539969758 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N,X,M = map(int,input().split())\n\nans = X\nA = X\nTF = True\nsrt = 1000000\nretu = dict()\nretu[X] = 1\nloop = X\nfor i in range(N-1):\n if TF:\n A = A**2 % M\n if retu.get(A) != None:\n srt = j\n goal = i\n TF = False\n break \n if TF:\n retu[A] = 1\n loop += A\n else:\n break\n \nif N-1 > srt:\n n = (N-srt)//(goal-srt+1)\n saisyo = sum(retu[:srt])\n loop -= saisyo\n print(saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)]))\n \nelse:\n print(sum(retu[:N]))\n', 'MOD = 998244353\nN, K = map(int, input().split())\nLR = [list(map(int, input().split())) for _ in range(K)]\n\ndp = [0]*(N+1)\nacc = [0]*(N+1) # acc[i] = dp[1] + ... dp[i]\n\ndp[1] = 1\nacc[1] = 1\nfor i in range(2, N+1):\n for lr in LR:\n l = lr[0]\n r = lr[1]\n\n dp[i] += (acc[max(0, i - l)] - acc[max(0, i - r - 1)] + MOD)\n dp[i] %= MOD\n acc[i] = (acc[i-1] + dp[i]) % MOD\n \n \n\nprint(dp[N])\n# print(acc)\n# print(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s870203673', 's997285547'] | [9184.0, 24488.0] | [26.0, 1517.0] | [544, 447] |
p02549 | u545368057 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['n, k = map(int, input().split())\nls = []\nrs = []\nps = []\nMOD = 998244353\ns = set()\nfor _ in range(k):\n l,r = map(int, input().split())\n for i in range(l,r+1):\n s.add(i)\ndp = [0] * (n+1)\ndp[0] = 1\nimos = [0]\nfor i in range(n):\n for d in sorted(list(s), reverse=True):\n if i - d >= 0:\n dp[i] += dp[i-d]\n dp[i-1] -= dp[i]\n dp[i] %= MOD\n\nprint(dp[n-1])', 'n, k = map(int, input().split())\nps = []\nMOD = 998244353\ns = set()\nfor _ in range(k):\n l,r = map(int, input().split())\n ps.append([l,r])\n\ndp = [0] * (n+1)\ndp[0] = 1\nacc = [0,1]\n\nfor i in range(1,n):\n for l, r in ps:\n dp[i] += acc[max(0,i-l+1)] - acc[max(0,i-r)]\n acc.append((acc[i] + dp[i])%MOD)\nprint(dp[n-1]%MOD)\n'] | ['Wrong Answer', 'Accepted'] | ['s140648310', 's448209820'] | [27936.0, 24756.0] | [2206.0, 1141.0] | [404, 334] |
p02549 | u632395989 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N, K = map(int, input().split())\nS = []\nfor j in range(K):\n S.append(list(map(int, input().split())))\n\nm = 998244353\n\nprint(S)\n\ndp = [0] * N\ndp[0] = 1\nsum_of_region = [0] * K\nfor i in range(1, N):\n for j in range(K):\n if i - S[j][0] >= 0:\n sum_of_region[j] += dp[i - S[j][0]]\n if i - S[j][1] - 1 >= 0:\n sum_of_region[j] -= dp[i - S[j][1] - 1]\n dp[i] += sum_of_region[j] % m\n dp[i] %= m\n print(i, dp, sum_of_region)\n\nans = dp[N - 1]\nprint(ans)\n', 'N, K = map(int, input().split())\nS = []\nfor j in range(K):\n S.append(list(map(int, input().split())))\n\nm = 998244353\n\n# print(S)\n\ndp = [0] * N\ndp[0] = 1\nsum_of_region = [0] * K\nfor i in range(1, N):\n for j in range(K):\n if i - S[j][0] >= 0:\n sum_of_region[j] += dp[i - S[j][0]]\n if i - S[j][1] - 1 >= 0:\n sum_of_region[j] -= dp[i - S[j][1] - 1]\n dp[i] += sum_of_region[j] % m\n dp[i] %= m\n # print(i, dp, sum_of_region)\n\nans = dp[N - 1]\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s663842231', 's156399991'] | [134228.0, 16856.0] | [2412.0, 1339.0] | [503, 507] |
p02549 | u686036872 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nS.sort()\n\nfor i in range(2, N+1):\n for l, r in S:\n DP[i] = (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])%998244353\n DP[i] += DP[i-1]\n\nprint(DP[N]%998244353)', 'N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nfor i in range(2, N+1):\n for l, r in S:\n DP[i] += (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])\n DP[i] += DP[i-1]\n DP[i] %= 998244353\n\nprint(DP[N]%998244353)', 'N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nfor i in range(2, N+1):\n for l, r in S:\n DP[i] += (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])%998244353\n DP[i] += DP[i-1]\n\nprint(DP[N]%998244353)', 'N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nfor i in range(2, N+1):\n for l, r in S:\n DP[i] += (DP[max(i-r, 0)] - DP[max(i-l-1, 0)])%998244353\n DP[i] += DP[i-1]\n\nprint(DP[N]%998244353)', 'N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nS.sort()\n\nfor i in range(2, N+1):\n for l, r in S:\n if 0 <= i - r <= N and 0 <= i - l - 1 <= N:\n DP[i] = (DP[i-r] - DP[i-l-1])%998244353\n DP[i] += DP[i-1]\n\nprint(DP[N]%998244353)', 'N, K = map(int, input().split())\n\nDP = [0]*(N+1)\nDP[1] = 1\n\nS = []\nfor i in range(K):\n S.append(list(map(int, input().split())))\n\nfor i in range(2, N+1):\n for l, r in S:\n DP[i] += (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])\n DP[i] += DP[i-1]\n DP[i] %= 998244353\n\nprint((DP[N] - DP[N-1])%998244353)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s045192540', 's187294529', 's247222194', 's291847586', 's303687949', 's990556771'] | [13768.0, 16840.0, 19732.0, 20024.0, 19400.0, 16900.0] | [1061.0, 1092.0, 1178.0, 1162.0, 724.0, 1121.0] | [298, 302, 289, 289, 334, 314] |
p02549 | u686230543 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['import numpy as np\n\nmod = 998244353\nn, k = map(int, input().split())\nleft = []\nright = []\nfor _ in range(k):\n l, r = map(int, input().split())\n left.append(l)\n right.append(r)\ndp = np.zeros(n+1, dtype=np.int)\ndp[1] = 1\nfor i in range(2, n+1):\n for j in range(k):\n dp[i] += dp[max(0, i - left[j])] - dp[max(0, i - right[j] - 1)]\n dp[i] %= mod\n dp[i] = (dp[i-1] + dp[i]) % mod\nprint((dp[n] - dp[n-1]) % mod)', 'import numpy as np\n\nmod = 998244353\nn, k = map(int, input().split())\nleft = []\nright = []\nfor _ in range(k):\n l, r = map(int, input().split())\n left.append(l)\n right.append(r)\ndp = np.zeros(n, dtype=np.int)\ndp[0] = 1\nfor i in range(n-1):\n for j in range(k):\n dp[i + left[j] : i + right[j] + 1] += dp[i]\n dp[i + left[j] : i + right[j] + 1] %= mod\nprint(dp[-1])', 'mod = 998244353\nn, k = map(int, input().split())\nleft = []\nright = []\nfor _ in range(k):\n l, r = map(int, input().split())\n left.append(l)\n right.append(r)\ndp = [0] * (n + 1)\ndp[1] = 1\nfor i in range(2, n+1):\n for j in range(k):\n dp[i] += dp[max(0, i - left[j])] - dp[max(0, i - right[j] - 1)]\n dp[i] %= mod\n dp[i] = (dp[i-1] + dp[i]) % mod\nprint((dp[n] - dp[n-1]) % mod)'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s407253943', 's834274718', 's703775323'] | [28236.0, 28388.0, 16780.0] | [2206.0, 2206.0, 1453.0] | [416, 369, 382] |
p02549 | u719840207 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['root=[]\nn,k = map(int,input().split())\nfor i in range(k):\n x,y = map(int,input().split())\n root.append([x,y])\n\ntoori=[0]*(2*10**5)+[0]*n+[0]*(2*10**5)\ntoori[2*10**5]=1\ncum=[0]*k\nfor a,i in enumerate (root):\n s=0\n for j in range (i[0],i[1]+1):\n s+=toori[2*10**5+1-j]\n cum[a]=s\naaa=sum(cum)\ntoori[2*10**5+1]+=aaa', 'root=[]\nn,k = map(int,input().split())\nfor i in range(k):\n x,y = map(int,input().split())\n root.append([x,y])\n\ntoori=[0]*(2*10**5)+[0]*n+[0]*(2*10**5)\ntoori[2*10**5]=1\ncum=[0]*k\nfor a,i in enumerate (root):\n s=0\n for j in range (i[0],i[1]+1):\n s+=toori[2*10**5+1-j]\n cum[a]=s\naaa=sum(cum)%998244353\ntoori[2*10**5+1]+=aaa\n\n\nfor now in range(2,n):\n hueru=0\n for a,i in enumerate (root):\n hueru+=(toori[2*10**5+now-i[0]] - toori[2*10**5+now-1-i[1]])\n aaa+=hueru\n aaa%=998244353\n toori[2*10**5+now]+=aaa\n toori[2*10**5+now]%=998244353\n \n\n\nprint(toori[2*10**5+n-1]%998244353)'] | ['Wrong Answer', 'Accepted'] | ['s550646818', 's944369894'] | [18236.0, 21516.0] | [61.0, 773.0] | [332, 639] |
p02549 | u736470924 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['def resolve():\n n, k = map(int, input().split())\n S = []\n for _ in range(k):\n l1, r1 = map(int, input().split())\n S.append(l1)\n S.append(r1)\n S = list(set(S))\n\n dp = [[0 for i in range(n + 1)] for j in range(len(S) + 1)]\n for i in range(len(S) + 1):\n dp[i][1] = 1\n for i in range(1, len(S) + 1):\n for j in range(2, n + 1):\n if j - S[i - 1] >= 0 and dp[i][j - S[i - 1]] > 0:\n dp[i][j] = dp[i][j - S[i - 1]] + dp[i - 1][j]\n else:\n dp[i][j] = dp[i - 1][j]\n\n print(dp[-1][n])\n\nresolve()', 'def resolve():\n n, k = map(int, input().split())\n S = []\n for _ in range(k):\n l1, r1 = map(int, input().split())\n S.append(l1)\n S.append(r1)\n S = list(set(S))\n\n dp = [[0 for i in range(n + 1)] for j in range(len(S) + 1)]\n for i in range(len(S) + 1):\n dp[i][1] = 1\n for i in range(1, len(S) + 1):\n for j in range(2, n + 1):\n if j - S[i - 1] >= 0 and dp[i][j - S[i - 1]] > 0:\n dp[i][j] = dp[i][j - S[i - 1]] + dp[i - 1][j]\n else:\n dp[i][j] = dp[i - 1][j]\n\n print(dp[-1][n] % 998244353)\n\nresolve()\n', 'def resolve():\n n, k = map(int, input().split())\n S = []\n L, R = [], []\n for _ in range(k):\n l1, r1 = map(int, input().split())\n L.append(l1)\n R.append(r1)\n\n dp = [0 for i in range(n + 1)]\n dpsum = [0 for i in range(n + 1)]\n dp[1] = 1\n dpsum[1] = 1\n for i in range(2, n + 1):\n for j in range(k):\n Li = i - R[j]\n Ri = i - L[j]\n if Ri < 0:\n continue\n Li = max(1, Li)\n dp[i] += dpsum[Ri] - dpsum[Li - 1] # dp[Li] ~ dp[Ri]\n dp[i] %= 998244353\n\n dpsum[i] = (dpsum[i - 1] + dp[i]) % 998244353\n\n print(dp[n])\n\nresolve()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s598533061', 's866113129', 's064404608'] | [58604.0, 58792.0, 24412.0] | [1077.0, 1075.0, 667.0] | [593, 606, 660] |
p02549 | u759412327 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N,K = map(int,input().split())\nLR = [list(map(int,input().split())) for k in range(K)]\n\ndp = (3*N)*[0]\ndp[0] = 1\ndp[1] = -1\n\nfor n in range(N):\n for L,R in LR:\n dp[L+n]+=dp[n]\n dp[n+R+1]-=dp[n]\n dp[n+1] = (dp[n]+dp[n+1])%998244353\n\nprint(dp[N-1])', 'from numpy import *\nN,K = map(int,input().split())\nLR = [list(map(int,input().split())) for k in range(K)]\nD = (N+2)*[0]\ndp = (N+1)*[0]\ndp[1] = 1\nmod = 998244353\n\nfor L,R in LR:\n D[L]+=1\n D[R+1]-=1\n\nD = cumsum(D)\n\nfor i in range(1,N+1):\n for j in range(1,i):\n if D[j]==1:\n dp[i] = (dp[i]+dp[i-j])%mod\n\nprint(dp)', 'N,K = map(int,input().split())\nLR = [list(map(int,input().split())) for k in range(K)]\n\ndp = (3*N)*[0]\ndp[0] = 1\ndp[1] = -1\n\nfor n in range(N):\n for L,R in LR:\n dp[L+n]+=dp[n]\n dp[n+R+1]-=dp[n]\n dp[n+1] = (dp[n]+dp[n+1])%998244353\n\nprint(dp[N-1])'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s035350556', 's568123396', 's976971097'] | [26164.0, 32868.0, 26036.0] | [1375.0, 2207.0, 817.0] | [256, 322, 254] |
p02549 | u763550415 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N, K = map(int, input().split())\nS = []\n\nfor _ in range(K):\n L, R = map(int, input().split())\n S.extend(range(L,R+1))\n \nprint(S)\n\n\nDP =[0]*N\nDP[0] = 1\n\nfor i in range(1,N):\n for j in S:\n if i >= j:\n DP[i] += DP[i-j]\n \nprint(DP[-1]%998244353)', 'N, K = map(int, input().split())\n\nL = []\nR = []\n\nfor _ in range(K):\n l, r = map(int, input().split())\n L.append(l)\n R.append(r)\n \ndp = [0]*(N+5)\ndp[1] = 1\n\nfor i in range(2, N+1):\n dp[i] = dp[i-1]\n for j in range(K):\n if i-L[j] >= 0:\n dp[i] += dp[i-L[j]]\n if i-R[j]-1 >= 0:\n dp[i] -= dp[i-R[j]-1]\n dp[i] %= 998244353\n \nprint((dp[N]-dp[N-1])%998244353)'] | ['Wrong Answer', 'Accepted'] | ['s749710979', 's058759485'] | [19488.0, 16848.0] | [2206.0, 1045.0] | [258, 379] |
p02549 | u802180430 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['n,k = tuple(map(int,input().split()))\nboolean = [False for _ in range(n+1)]\nfor _ in range(k):\n l,r = tuple(map(int,input().split()))\n for num in range(l,r+1):\n boolean[num] = True;\nFINAL = [i for i in range(len(boolean)) if boolean[i]]\ndp = [0 for _ in range(n+1)]\nfor i in range(2,n+1):\n for lower in FINAL: #optimized!\n if boolean[lower]: #start + lower\n start = i - lower\n if start >= 1:\n \tdp[i]+= dp[start]\nprint(dp[n]%998244353)', 'n,k = tuple(map(int,input().split()))\nboolean = [False for _ in range(n+1)]\nfor _ in range(k):\n l,r = tuple(map(int,input().split()))\n for num in range(l,r+1):\n boolean[num] = True;\ndp = [0 for _ in range(n+1)]\nfor i in range(2,n+1):\n for lower in range(1,i):\n if boolean[lower]: #start + lower\n start = i - lower\n dp[i]+= dp[start]\nprint(dp[n]%998244353)\n \n', "'''go to every index and then run a index - 1 to 1 for it and check whether the proposed number lies somewhere or not'''\nn,k = tuple(map(int,input().split()))\nboolean = [False]*n\nfor _ in range(k):\n l,r = tuple(map(int,input().split()))\n for num in range(l,r+1):\n boolean[num] = True;\ndp = [0 for _ in range(n+1)]\nboolean = [False for _ in range(n+1)]\nfor i in range(2,n+1):\n for lower in range(1,i):\n if boolean[lower]:\n \tstart = i - lower\n dp[i] += dp[start]\nprint(dp[n])\n ", 'MOD = 998244353\nN, K = map(int, input().split())\nLR = [tuple(map(int, input().split())) for i in range(K)]\n \ndp = [0] * (N+1)\ndp[1] = 1 #ok\nfor i in range(1, N):\n dp[i] += dp[i-1] #as min k = 1, so carry this on to the next\n dp[i] %= MOD\n for l, r in LR:\n ll = i + l\n rr = i + r\n if ll <= N:\n dp[ll] += dp[i] #yes ll is accesible\n dp[ll] %= MOD\n if rr < N:\n dp[rr+1] -= dp[i] #not accessible and will get cancelled out when we take prefix sum\n dp[rr+1] %= MOD\n \nprint(dp[-1])'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s186051921', 's314456877', 's921173046', 's910886078'] | [19840.0, 12212.0, 9060.0, 16808.0] | [2206.0, 2206.0, 31.0, 1129.0] | [460, 381, 497, 521] |
p02549 | u811436126 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['import numpy as np\n\nn, k = map(int, input().split())\ns = [list(map(int, input().split())) for _ in range(k)]\nmod = 998244353\n\ns.sort()\n\ndp = np.zeros(n * 2)\ndp[1] = 1\n\nfor i in range(1, n):\n for l, r in s:\n dp[i + l:i + r + 1] += dp[i]\n dp[i + l:i + r + 1] %= mod\n\nprint(dp[n] % mod)\n', 'n, k = map(int, input().split())\nmod = 998244353\nlr = [list(map(int, input().split())) for _ in range(k)]\n\ndp = [0] * (n + 10)\ndp[1] = 1\ncumsum = [0] * (n + 10)\ncumsum[1] = 1\n\nfor i in range(2, n + 1):\n for l, r in lr:\n if l >= i:\n continue\n\n ll = max(1, i - r)\n rr = i - l\n dp[i] += cumsum[rr] - cumsum[ll - 1]\n dp[i] %= mod\n cumsum[i] = cumsum[i - 1] + dp[i]\n cumsum[i] %= mod\n\nprint(dp[n] % mod)\n'] | ['Wrong Answer', 'Accepted'] | ['s453202053', 's804689381'] | [28404.0, 24556.0] | [2206.0, 836.0] | [301, 454] |
p02549 | u851125702 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N,K=map(int,input().split())\nx=998244353\nS=[]\nfor i in range(K):\n l,r=map(int,input().split())\n S.append(l)\n S.append(r)\nS=list(set(S))\ndp=[0 for i in range(N)]\nprint(S)\nfor i in range(N):\n for j in range(len(S)):\n if(i-S[j]>0):\n dp[i]+=dp[i-S[j]]\n dp[i]=dp[i]%x\n elif(i-S[j]==0):\n dp[i]+=1\n dp[i]=dp[i]%x\nprint(dp)', 'N,K=map(int,input().split())\nx=998244353\ndp=[0 for i in range(N)]\nsdp=[0 for i in range(N)]\nL=[]\nR=[]\ndp[0]=1\nsdp[0]=1\nfor i in range(K):\n l,r=map(int,input().split())\n L.append(l)\n R.append(r) \nfor i in range(1,N):\n for j in range(K):\n dp[i]+=(sdp[max(i-L[j],-1)]-sdp[max(i-R[j]-1,-1)])\n dp[i]%=x\n sdp[i]=(sdp[i-1]+dp[i])%x\nprint(dp[-1]%x)'] | ['Wrong Answer', 'Accepted'] | ['s795327876', 's309685160'] | [20488.0, 24592.0] | [1208.0, 1458.0] | [385, 369] |
p02549 | u860002137 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['n, k = map(int, input().split())\nMOD = 998244353\n\nlr = []\nfor _ in range(k):\n l, r = map(int, input().split())\n lr += (list(range(l, r + 1)))\n\nlr.sort()\nlr = np.array(lr)\n\ndp = np.zeros(n + n, dtype=np.int64)\ndp[0] = 1\ndp2 = dp.copy()\n\nfor i in range(n):\n idx = i + lr\n dp2[idx] += dp[i]\n dp2 %= MOD\n dp = dp2\n\nprint(dp[n - 1])', 'def solve(l, r, i):\n if i - l < 1:\n return 0\n return dp[i - l] - dp[max(i - r - 1, 0)]\n\n\nn, k = map(int, input().split())\nlr = [list(map(int, input().split())) for _ in range(k)]\nMOD = 998244353\n\ndp = [0] * (n + 1)\ndp[1] = 1\n\nfor i in range(2, n + 1):\n tmp = 0\n for l, r in lr:\n tmp += solve(l, r, i)\n tmp = tmp % MOD\n dp[i] = (dp[i - 1] + tmp) % MOD\n\nprint(tmp)'] | ['Runtime Error', 'Accepted'] | ['s585987516', 's192029489'] | [18272.0, 16712.0] | [34.0, 765.0] | [345, 394] |
p02549 | u894521144 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ["mod = 998244353\n\n\ndef main(N, S):\n dp = [0 if n != 0 else 1 for n in range(N)] \n A = [0 if n != 0 else 1 for n in range(N)] \n\n for i in range(1, N): \n for l, r in S: \n if i - l < 0: \n break\n else: \n dp[i] += A[i-l] - A[max(i-r-1, 0)] \n dp[i] %= mod\n A[i] = (A[i-1] + dp[i]) % mod\n print(dp, A)\n\nif __name__ == '__main__':\n N, K = list(map(int, input().split()))\n S = {tuple(map(int, input().split())) for k in range(K)}\n S = sorted(list(S), key = lambda x:x[0]) \n main(N, S)", "mod = 998244353\n\n\ndef main(N, S):\n dp = [0 if n != 0 else 1 for n in range(N)] \n A = [0 if n != 0 else 1 for n in range(N)] \n\n for i in range(1, N): \n for l, r in S: \n if i - l < 0: \n break\n else: \n dp[i] += A[i-l] - A[max(i-r-1, 0)] \n dp[i] %= mod\n A[i] = (A[i-1] + dp[i]) % mod\n print(dp[-1])\n\nif __name__ == '__main__':\n N, K = list(map(int, input().split()))\n S = {tuple(map(int, input().split())) for k in range(K)}\n S = sorted(list(S), key = lambda x:x[0]) \n main(N, S)", "mod = 998244353\n\n\n\n\ndef main(N, S):\n dp = [0 if n != 0 else 1 for n in range(N)] \n A = [0 if n != 0 else 1 for n in range(N)] \n\n for i in range(1, N): \n for l, r in S: \n if i - l < 0: \n break\n else: \n if i - r <= 0: \n dp[i] += A[i-l]\n else:\n dp[i] += A[i-l] - A[i-r-1]\n dp[i] %= mod\n A[i] = (A[i-1] + dp[i]) % mod\n print(dp[-1])\n\nif __name__ == '__main__':\n N, K = list(map(int, input().split()))\n S = {tuple(map(int, input().split())) for k in range(K)}\n S = sorted(list(S), key = lambda x:x[0]) \n main(N, S)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s329572017', 's996267709', 's963015996'] | [13416.0, 12228.0, 24652.0] | [478.0, 456.0, 425.0] | [1347, 1348, 1618] |
p02549 | u903005414 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ["from numba import jit\n\nimport sys\nsys.setrecursionlimit(10**9)\n\nN, K = map(int, input().split())\nS = set()\n\nMOD = 998244353\nfor _ in range(K):\n L, R = map(int, input().split())\n S |= set(range(L, R + 1))\n# print(f'{S=}')\n\nDP = [-1] * (N + 1)\nDP[0] = 0\nDP[1] = 1\n\n\n@njit\ndef f(idx):\n ans = 0\n for s in S:\n if idx - s < 0:\n continue\n if DP[idx - s] == -1:\n DP[idx - s] = f(idx - s)\n ans += DP[idx - s]\n return ans % MOD\n\n\nans = f(N)\n# print(f'{DP=}')\nprint(ans)\n", "from numba import njit\n\nimport sys\nsys.setrecursionlimit(10**9)\n\nN, K = map(int, input().split())\nS = set()\n\nMOD = 998244353\nfor _ in range(K):\n L, R = map(int, input().split())\n S |= set(range(L, R + 1))\n# print(f'{S=}')\n\nDP = [-1] * (N + 1)\nDP[0] = 0\nDP[1] = 1\n\n\n@njit\ndef f(idx):\n ans = 0\n for s in S:\n if idx - s < 0:\n continue\n if DP[idx - s] == -1:\n DP[idx - s] = f(idx - s)\n ans += DP[idx - s]\n return ans % MOD\n\n\nans = f(N)\n# print(f'{DP=}')\nprint(ans)\n", "N, K = map(int, input().split())\nMOD = 998244353\nLR = []\nfor _ in range(K):\n L, R = map(int, input().split())\n LR.append((L, R))\n# print(f'{LR=}')\n\nDP = [0] * (N + 1)\nDP[1] = 1\nS = [0] * (N + 1)\n\nfor i in range(1, len(DP)):\n for L, R in LR:\n v = S[max(i - L, 0)] - S[max(i - R - 1, 0)]\n DP[i] += v\n DP[i] %= MOD\n S[i] = (S[i - 1] + DP[i]) % MOD\n\n# print(f'{DP=}')\n# print(f'{S=}')\nprint(DP[-1])\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s418195130', 's563659136', 's638989403'] | [114756.0, 131344.0, 24592.0] | [435.0, 1734.0, 1197.0] | [518, 519, 424] |
p02549 | u923270446 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['mod = 998244353\nn, k = map(int, input().split())\nlr = [list(map(int, input().split())) for i in range(k)]\ndp = [0 for i in range(n + 1)]\ndp[0] = 1\ncum = [0, 1]\ncur = [0 for i in range(k)]\nfor i in range(1, n + 1):\n cnt = 0\n for j in range(k):\n r = (i - (lr[j][1] - lr[j][0] + 1))\n l = r - (lr[j][1] - lr[j][0])\n print(l, r, cum)\n if l <= 0:\n continue\n cnt += cum[r] - cum[l - 1]\n dp[i] = dp[i - 1] + cnt\n cum.append(cnt + cum[-1])\nprint(dp[n])', 'mod = 998244353\nn, k = map(int, input().split())\nlr = [list(map(int, input().split())) for i in range(k)]\nfor i in range(k):\n lr[i][1] += 1\ndp = [0] * n\ndp[0] = 1\nfor i in range(1, n):\n dp[i] += dp[i - 1]\n if i == 1:\n dp[1] = 0\n for l, r in lr:\n if i - l >= 0:\n dp[i] += dp[i - l]\n if i - r >= 0:\n dp[i] -= dp[i - r]\n dp[i] %= mod\nprint(dp[n - 1])'] | ['Runtime Error', 'Accepted'] | ['s265789382', 's636763265'] | [141908.0, 16880.0] | [2537.0, 658.0] | [501, 405] |
p02549 | u936985471 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['import sys\nreadline=sys.stdin.readline\n\nimport numpy as np\nfrom numba import njit,i8\n\nN,K=map(int,readline().split())\nDIV = 998244353\nsteps = []\nfor i in range(K):\n l,r = map(int,readline().split())\n for j in range(l, r + 1):\n steps.append(j)\n \nsteps = sorted(steps)\nsteps = np.array(steps, dtype = int)\n\n@njit(i8(i8[:]),cache = True)\ndef solve(steps):\n dp = np.zeros(N, dtype = int)\n dp[0] = 1\n for i in range(len(dp)):\n for s in steps:\n if i + s >= len(dp):\n break\n dp[i + s] += dp[i]\n dp[i + s] %= DIV\n \n return dp[-1]\n\nprint(solve())\n', 'import sys\nreadline = sys.stdin.readline\n\nN,K = map(int,readline().split())\nDIV = 998244353\n\nL = [None] * K\nR = [None] * K\nfor i in range(K):\n L[i],R[i] = map(int,readline().split())\n\ndp = [0] * (N + 1)\nsdp = [0] * (N + 1)\ndp[1] = 1\nsdp[1] = 1\n \nfor i in range(2, len(dp)):\n for j in range(K):\n li = max(i - R[j], 0)\n ri = i - L[j]\n if ri < 0:\n continue\n dp[i] += (sdp[ri] - sdp[li - 1])\n dp[i] %= DIV\n sdp[i] = sdp[i - 1] + dp[i]\n sdp[i] %= DIV\n \nprint(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s323945188', 's229097696'] | [108056.0, 24396.0] | [1919.0, 1032.0] | [580, 486] |
p02549 | u942051624 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['import collections\nimport math\nimport sys\nsys.setrecursionlimit(10**7)\ninf=998244353\n\n\nN,K=map(int,input().split())\nSS=[]\n\nfor i in range(K):\n s1,s2=map(int,input().split())\n for j in range(s1,s2+1):\n SS.append(j)\n\n# Driver program to test above function \n\ntable = [0 for k in range(N-1)] \n\nfor s in SS:\n if s<N-1:\n table[s-1]+=1\nfor i in range(0,N-1):\n for s in SS:\n if i+s<N-1:\n table[i+s]+=table[i]\n table[i+s]%=inf\nprint(table[-1]%inf)\n', 'inf=998244353\n\n\nN,K=map(int,input().split())\nSS=[list(map(int,input().split())) for i in range(K)]\n\nSS.sort()\n\ntable = [0 for k in range(N)] \ndiff = [0 for k in range(N-1)]\n\ntable[0]=1\ndiff[0]=-1\n\nfor i in range(N-1):\n if table[i]!=0:\n for s in SS:\n lef=s[0]\n rig=s[1]\n if i+lef-1<N-1:\n diff[i+lef-1]+=table[i]\n if i+rig<N-1:\n diff[i+rig]-=table[i]\n table[i+1]=table[i]+diff[i]\n table[i+1]%=inf\n\nprint(table[N-1])'] | ['Wrong Answer', 'Accepted'] | ['s098398357', 's942076593'] | [25140.0, 25180.0] | [2206.0, 982.0] | [495, 503] |
p02549 | u945228737 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ["# import sys\n\n\n# from collections import deque\n# from decorator import stop_watch\n# \n# \n# @stop_watch\ndef solve(N, K, LR):\n mod = 998244353\n S = []\n for lr in LR:\n S += [i for i in range(lr[0], lr[1] + 1)]\n S.sort()\n dp = [0] * (N + 1)\n dp[1] = 1\n for i in range(1, N + 1):\n for s in S:\n if i + s > N:\n break\n dp[i + s] = (dp[i + s] + dp[i]) % mod\n print(dp[N])\n\n\nif __name__ == '__main__':\n # N, K = map(int, input().split())\n # LR = [[int(i) for i in input().split()] for _ in range(K)]\n # solve(N,K,LR)\n\n # test\n from random import randint\n from func import random_str\n\n N, K = 2 * 10 ** 5, 1\n LR = [[1, N]]\n solve(N, K, LR)\n", "\n\n\n\n# import sys\n\n\n# from collections import deque\n# from decorator import stop_watch\n#\n#\n# @stop_watch\ndef solve(N, K, LR):\n mod = 998244353\n dp = [0] * (N + 1)\n dp[1] = 1\n \n \n \n \n dp[2] = 1 if 1 in [lr[0] for lr in LR] else 0\n for i in range(3, N + 1):\n x = 0\n for l, r in LR:\n x += dp[max(i - l, 0)] - dp[max(i - 1 - r, 0)]\n dp[i] = (dp[i - 1] + x) % mod\n print(dp[N])\n\n\nif __name__ == '__main__':\n N, K = map(int, input().split())\n LR = [[int(i) for i in input().split()] for _ in range(K)]\n solve(N, K, LR)\n\n # # test\n # from random import randint\n # from func import random_str\n # N, K = 2 * 10 ** 5, 1\n # LR = [[1, N]]\n # solve(N, K, LR)\n"] | ['Runtime Error', 'Accepted'] | ['s874144801', 's626452461'] | [9524.0, 16828.0] | [27.0, 818.0] | [777, 2056] |
p02549 | u960237860 | 2,000 | 1,048,576 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right. Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below. You are given an integer K that is less than or equal to 10, and K non- intersecting segments [L_1, R_1], [L_2, R_2], \ldots, [L_K, R_K]. Let S be the union of these K segments. Here, the segment [l, r] denotes the set consisting of all integers i that satisfy l \leq i \leq r. * When you are on Cell i, pick an integer d from S and move to Cell i + d. You cannot move out of the cells. To help Tak, find the number of ways to go to Cell N, modulo 998244353. | ['N, K = map(int, input().split())\nS = []\nfor i in range(K):\n L, R = map(int, input().split())\n S += list(range(L, R+1))\n\ndp = [0] * N\ndp[0] = 1\n\nS.sort()\n\nfor i in range(1, N):\n for s in S:\n if i - s < 0:break\n dp[i] = (dp[i] + dp[i - s]) % 998244353\n\nprint(dp)\n\nprint(dp[-1])', 'mod = 998244353\nN, K = map(int, input().split())\n\nS = []\nfor i in range(K):\n L, R = map(int, input().split())\n S.append((L, R))\n\ndp = [0] * (N+1)\ndpsum = [0] * (N+1)\ndp[1] = 1\ndpsum[1] = 1\n\nfor i in range(2, N+1):\n for s in S:\n l = i - s[1]\n r = i - s[0]\n if r < 1:continue\n l = max(1, l)\n\n dp[i] += dpsum[r] - dpsum[l-1]\n dp[i] %= mod\n\n dpsum[i] = (dpsum[i-1] + dp[i]) % mod\n\nprint(dp[-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s797528276', 's934468718'] | [18928.0, 24356.0] | [2206.0, 932.0] | [298, 445] |
p02550 | u056358163 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\n\nans = X\nx = X\n\nC = [0, x]\nXd = [-1] * (M+1)\nXd[x] = 0\nXl = [x]\n\nfor i in range(1, N):\n x = x**2 % M\n\n if Xd[x] > -1:\n break\n Xd[x] = i\n Xl.append(x)\n ans += x\n C.append(ans)', 'N, X, M = map(int, input().split())\n\nans = 0\nC = [0]\nXd = [-1] * (M+1)\n\nfor i in range(N):\n x = X if i==0 else x**2 % M\n \n if Xd[x] > -1:\n break\n Xd[x] = i\n ans += x\n C.append(ans)\n\nloop_len = i - Xd[x]\nif loop_len > 0:\n S = C[i] - C[Xd[x]]\n loop_num = (N - i) // loop_len\n ans += loop_num * S\n m = N - loop_num * loop_len - i\n ans += C[Xd[x]+m] - C[Xd[x]]\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s383852709', 's546406764'] | [15664.0, 13472.0] | [64.0, 61.0] | [235, 408] |
p02550 | u060793972 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m=map(int,input().split())\nl=[0 for i in range(m)]\nans=0\ny=[]\ni=1\nflag=0\nys=n\nwhile i<n:\n if flag==0:\n ans+=x\n l[x]+=1\n x=x*x%m\n i+=1\n if l[x]==2 and flag==0:\n flag=1\n ys=i\n if flag:\n if l[x]==3:\n break\n y.append(x)\nif len(y):\n p,pp=divmod(n-ys,len(y))\n print(ans+p*sum(y)+sum(y[:pp+1]))\n #print(ans,p*sum(y),sum(y[:pp+1]))\nelse:\n print(ans)', 'n,x,m=map(int,input().split())\nl=[0 for i in range(m)]\nans=0\ny=[]\ni=1\nflag=0\nys=n\nwhile i<n:\n if flag==0:\n ans+=x\n l[x]+=1\n x=x*x%m\n i+=1\n if l[x]==2 and flag==0:\n flag=1\n ys=i\n if flag:\n if l[x]==3:\n break\n y.append(x)\nif len(y):\n p,pp=divmod(n-ys,len(y))\n print(ans+p*sum(y)+sum(y[:pp+1]))\n print(ans,p*sum(y),sum(y[:pp+1]))\nelse:\n print(ans)', 'n,x,m=map(int,input().split())\nl=[0 for i in range(m)]\nans=0\ny=[]\ni=1\nflag=0\nys=n\nwhile i<n+1:\n if flag==0:\n ans+=x\n l[x]+=1\n x=x*x%m\n i+=1\n if l[x]==2 and flag==0:\n flag=1\n ys=i\n if flag:\n if l[x]==3:\n break\n y.append(x)\nif len(y):\n p,pp=divmod(n-ys,len(y))\n print(ans+p*sum(y)+sum(y[:pp+1]))\n #print(ans,p*sum(y),sum(y[:pp+1]))\nelse:\n print(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s530979778', 's625113116', 's020307746'] | [11784.0, 11792.0, 11872.0] | [107.0, 108.0, 107.0] | [421, 420, 423] |
p02550 | u095094246 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m=map(int,input().split())\n\na_i = x\nlog = [x]\napp=[-1]*m\napp[x]=0\nlast = x\nfor i in range(1,n):\n a_i = (a_i**2)%m\n if app[a_i] > -1:\n last = a_i\n break\n app[a_i] = i\n log.append(a_i)\n\n\nans = sum(log[:min(n, app[last])])\nif n > app[last]:\n \n ans += sum(log[app[last]:]) * ((n-app[last]) // (len(log) - app[last]))\n \n ans += sum(log[app[last]:app[last] + (n-app[last]) % (len(log) - app[last])])\nprint(ans)\nprint(*log)', 'n,x,m=map(int,input().split())\n\na_i = x\nlog = [x]\napp=[-1]*m\napp[x]=0\nlast = x\nfor i in range(1,n):\n a_i = (a_i**2)%m\n if app[a_i] > -1:\n last = a_i\n break\n app[a_i] = i\n log.append(a_i)\n\n\nans = sum(log[:min(n, app[last])])\nif n > app[last]:\n \n ans += sum(log[app[last]:]) * ((n-app[last]) // (len(log) - app[last]))\n \n ans += sum(log[app[last]:app[last] + (n-app[last]) % (len(log) - app[last])])\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s226560544', 's467751951'] | [13636.0, 13660.0] | [70.0, 57.0] | [593, 581] |
p02550 | u133936772 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m=map(int,input().split())\nl=[-1]*m\ns=[0]*m\nt=p=0\nwhile l[x]<0:\n t+=1\n l[x]=t\n s[x]=s[p]+x\n p=x\n x=pow(p,2,m)\n print(t,x,s[p])\nT=t+1-l[x]\nprint(T)\nS=s[p]+x-s[x]\nprint(S)\nif n<l[x]:\n print(s[l.index(n)])\nelse:\n print(S*((n-l[x])//T)+s[l.index(l[x]+(n-l[x])%T)])', 'n,x,m=map(int,input().split())\nl,s=[0]*m,[0]*m\nt=p=0\nwhile l[x]<1:\n t+=1\n l[x]=t\n s[x]=s[p]+x\n p=x\n x=p*p%m\nk=l[x]\nd,m=divmod(n-k,t+1-k)\nprint((s[p]+x-s[x])*d+s[l.index(k+m)])'] | ['Wrong Answer', 'Accepted'] | ['s726054782', 's148286258'] | [14028.0, 14052.0] | [123.0, 61.0] | [272, 180] |
p02550 | u135346354 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\ndp = [False]*(M+1)\ndp[X] = True\nS = [0]*(M+1)\nS[1] = X\ntmp = X\nfor i in range(2, M+1):\n tmp = pow(tmp, 2, M)\n if dp[tmp]:\n for j in range(i):\n if tmp == S[j]:\n break\n ans = 0\n for k in range(j, i):\n ans += S[k]\n ans *= (N-j-1)//(i-j)\n for k in range(1, j):\n ans += S[k]\n for k in range(j, j+(N-j-1)%(i-j)):\n ans += S[k]\n print(ans)\n break\n else:\n dp[tmp] = True\n S[i] = tmp\nelse:\n print(sum(S))', '\nN, X, M = map(int, input().split())\ndp = [False]*(M+1)\ndp[X] = True\nS = [0]*(M+1)\nS[1] = X\ntmp = X\nfor i in range(2, min(M+1, N+1)):\n tmp = pow(tmp, 2, M)\n if dp[tmp]:\n for j in range(1, i):\n if tmp == S[j]:\n break\n ans = 0\n for k in range(j, i):\n ans += S[k]\n ans *= (N-j+1)//(i-j)\n for k in range(1, j):\n ans += S[k]\n for k in range(j, j+(N-j+1)%(i-j)):\n ans += S[k]\n print(ans)\n break\n else:\n dp[tmp] = True\n S[i] = tmp\nelse:\n print(sum(S))'] | ['Wrong Answer', 'Accepted'] | ['s396719153', 's405049806'] | [11964.0, 11916.0] | [79.0, 90.0] | [571, 585] |
p02550 | u137542041 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\n\nnxt = X\nlst = []\ndic = {}\n\nfor i in range(M):\n if nxt in dic:\n loop_st = dic[nxt]\n loop_ed = i - 1\n break\n\n lst.append(nxt)\n dic[nxt] = i\n\n nxt = (nxt ** 2) % M\n\n\nv = N - loop_st\nq, r = divmod(v, loop_ed - loop_st + 1)\n\npre_sum = sum(lst[:loop_st])\nloop_sum = q * sum(lst[loop_st:])\npost_sum = sum(lst[loop_st:loop_st + r])\n', 'N, X, M = map(int, input().split())\n\nnxt = X\nlst = []\ndic = {}\n\nfor i in range(M + 1):\n if nxt in dic:\n loop_st = dic[nxt]\n loop_ed = i - 1\n break\n\n lst.append(nxt)\n dic[nxt] = i\n\n nxt = (nxt ** 2) % M\n\n\nv = N - loop_st\nq, r = divmod(v, loop_ed - loop_st + 1)\n\npre_sum = sum(lst[:loop_st])\nloop_sum = q * sum(lst[loop_st:])\npost_sum = sum(lst[loop_st:loop_st + r])\nprint(pre_sum + loop_sum + post_sum)\n'] | ['Runtime Error', 'Accepted'] | ['s422199072', 's533174953'] | [15704.0, 15728.0] | [58.0, 63.0] | [394, 435] |
p02550 | u156815136 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ["#from statistics import median\n#import collections\n\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product \n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n\n#\n\n\n\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nn,x,m = readInts()\nlis = []\nprv = None\ndic = defaultdict(int)\nfor i in range(m):\n if i == 0:\n A = x%m\n lis.append(A)\n dic[A] = 1\n else:\n A = (A*A)%m\n if dic[A]:\n prv = A\n break\n else:\n dic[A] = 1\n lis.append(A)\ncnt = None\nfor i in range(len(lis)):\n if lis[i] == prv:\n cnt = i\n break\nif cnt == None:\n cnt = len(lis)\n# front_arr = lis[:cnt]\n# print(lis)\n# loop_arr = lis[cnt:]\n# print(loop_arr)\nif x == 0:\n print(0)\n exit()\nlen_loop_arr = len(loop_arr)\nif n < cnt:\n ans = sum(front_arr[:n])\nelse:\n ans = sum(front_arr)\n sum_loop_arr = sum(loop_arr)\n n -= cnt\n\n loop = n//len_loop_arr\n rest = n - (loop*len_loop_arr)\n mid = loop * sum_loop_arr\n ans += mid\n ans += sum(loop_arr[:rest])\nprint(ans)\n", "#from statistics import median\n#import collections\n\nfrom math import gcd\nfrom itertools import combinations,permutations,accumulate, product \n#from collections import deque\nfrom collections import deque,defaultdict,Counter\nimport decimal\nimport re\nimport math\nimport bisect\nimport heapq\n#\n#\n#\n\n#\n#\n# my_round_int = lambda x:np.round((x*2 + 1)//2)\n\n#\n\n\n\n#\n#\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\n#mod = 998244353\nINF = float('inf')\nfrom sys import stdin\nreadline = stdin.readline\ndef readInts():\n return list(map(int,readline().split()))\ndef readTuples():\n return tuple(map(int,readline().split()))\ndef I():\n return int(readline())\nn,x,m = readInts()\nlis = []\nprv = None\ndic = defaultdict(int)\nfor i in range(m):\n if i == 0:\n A = x%m\n lis.append(A)\n dic[A] = 1\n else:\n A = (A*A)%m\n if dic[A]:\n prv = A\n break\n else:\n dic[A] = 1\n lis.append(A)\ncnt = None\nfor i in range(len(lis)):\n if lis[i] == prv:\n cnt = i\n break\nif cnt == None:\n cnt = len(lis)\nfront_arr = lis[:cnt]\nloop_arr = lis[cnt:]\nif x == 0:\n print(0)\n exit()\nlen_loop_arr = len(loop_arr)\nif n < cnt:\n ans = sum(front_arr[:n])\nelse:\n ans = sum(front_arr)\n sum_loop_arr = sum(loop_arr)\n n -= cnt\n\n loop = n//len_loop_arr\n rest = n - (loop*len_loop_arr)\n mid = loop * sum_loop_arr\n ans += mid\n ans += sum(loop_arr[:rest])\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s414962845', 's163659653'] | [15616.0, 15580.0] | [63.0, 68.0] | [1852, 1817] |
p02550 | u159723084 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['# -*- coding: utf-8 -*-\n\nN,X,M=map(int,input().split())\n\nA=[0]*M\nA[0]=X\nD=[0]*M\n\ns=N\nfor i in range(1,N):\n a=A[i-1]**2%M\n if D[a] == 1:\n s=A.index(a)\n break\n else:\n A[i]=a\n D[a]=1\n\nif s==N:\n ans=sum(A[:i])\nelse:\n A=A[:i]\n \n ans=0\n l=len(A)-s\n ans+=sum(A[:s])\n S=sum(A[s:])\n T=(N-s)//l\n ans+=T*S\n K=N-s-l*T\n ans+=sum(A[s:(s+K)])\n\n\nprint(ans)\n', '# -*- coding: utf-8 -*-\n\nN,X,M=map(int,input().split())\n\nA=[0]*(M+1)\nA[0]=X\nD=[0]*(M+1)\n\ns=N\nfor i in range(1,N):\n a=A[i-1]**2%M\n if D[a] == 1:\n s=A.index(a)\n break\n else:\n A[i]=a\n D[a]=1\n\nif s==N:\n ans=sum(A)\nelse:\n A=A[:i]\n \n ans=0\n l=len(A)-s\n ans+=sum(A[:s])\n S=sum(A[s:])\n T=(N-s)//l\n ans+=T*S\n K=N-s-l*T\n ans+=sum(A[s:(s+K)])\n\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s266576924', 's320327037'] | [12368.0, 12152.0] | [60.0, 55.0] | [411, 415] |
p02550 | u202560873 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = [int(x) for x in input().split()]\ncopy = M\n\nk = 0\nwhile M % 2 == 0:\n k += 1\n M = M // 2\nL = M\n\norder = 1\nif L != 1:\n e = 2 % L\n while e != 1:\n order += 1\n e = (2 * e) % L\n\nA = [0] * (k + order)\nA[1] = X\nfor i in range(2, k + order):\n A[i] = (A[i - 1] * A[i - 1]) % copy\n\nS = sum(A[k:])\nans = 0\nif N < k:\n ans = sum(A[1:N + 1])\nelse:\n q, r = (N - k - 1) // order, (N - k - 1) % order\n ans = sum(A[1:k]) + S * q + sum(A[k:k + r])\n\nprint(ans)', 'N, X, M = [int(x) for x in input().split()]\n\nA = [0] * (M + 1)\nfirstApearAt = {i:0 for i in range(M)}\nA[1] = X\nfirstApearAt[X] = 1\nl, r = 1\nfor i in range(2, M + 1):\n A[i] = (A[i - 1] * A[i - 1]) % M\n if firstApearAt[A[i]] > 0:\n r = i\n l = firstApearAt[A[i]]\n break\n firstApearAt[A[i]] = i\n\nans = 0\nif N <= l - 1:\n ans = sum(A[1:N + 1])\nelse:\n q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)\n ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])\n\nprint(ans)', 'N, X, M = [int(x) for x in input().split()]\ncopy = M\n\nk = 0\nwhile M % 2 == 0:\n k += 1\n M = M // 2\nL = M\n\norder = 1\nif L != 1:\n e = 2 % L\n while e != 1:\n order += 1\n e = (2 * e) % L\n\nA = [0] * (k + order)\nA[1] = X\nfor i in range(2, k + order + 1):\n A[i] = (A[i - 1] * A[i - 1]) % copy\n\nS = sum(A[k:])\nans = 0\nif N < k:\n ans = sum(A[1:N + 1])\nelse:\n q, r = (N - k - 1) // order, (N - k - 1) % order\n ans = sum(A[1:k]) + S * q + sum(A[k:k + r])\n\nprint(ans)', 'N, X, M = [int(x) for x in input().split()]\ncopy = M\n\nk = 0\nwhile M % 2 == 0:\n k += 1\n M = M // 2\nL = M\n\norder = 1\nif L != 1:\n e = 2 % L\n while e != 1:\n order += 1\n e = (2 * e) % L\n\nA = [None] * (k + order)\nA[1] = X\nfor i in range(2, k + order + 1):\n A[i] = (A[i - 1] * A[i - 1]) % copy\n\nS = sum(A[k:])\nans = 0\nif N < k:\n ans = sum(A[1:N + 1])\nelse:\n q, r = (N - k - 1) // order, (N - k - 1) % order\n ans = sum(A[1:k]) + S * q + sum(A[k:k + r])\n\nprint(ans)', 'N, X, M = [int(x) for x in input().split()]\ncopy = M\n\nk = 0\nwhile M % 2 == 0:\n k += 1\n M = M // 2\nL = M\n\norder = 1\nif L != 1:\n e = 2 % L\n while e != 1:\n order += 1\n e = (2 * e) % L\n\nA = [0] * (k + order)\nA[1] = X\nfor i in range(2, k + order):\n A[i] = (A[i - 1] * A[i - 1]) % copy\n\nS = sum(A[k:])\nans = 0\nif N < k:\n ans = sum(A[1:N + 1])\nelse:\n q, r = (N - k - 1) // order, (N - k - 1) % order\n ans = sum(A[1:k]) + S * q + sum(A[k:k + r])\n\nprint(ans)', 'N, X, M = [int(x) for x in input().split()]\n\nA = [0] * (M + 1)\nfirstApearAt = {i:0 for i in range(M)}\nA[1] = X\nfirstApearAt[X] = 1\nl, r = 1, 2\nfor i in range(2, M + 1):\n A[i] = (A[i - 1] * A[i - 1]) % M\n if firstApearAt[A[i]] > 0:\n r = i\n l = firstApearAt[A[i]]\n break\n firstApearAt[A[i]] = i\n\nans = 0\nif N <= l - 1:\n ans = sum(A[1:N + 1])\nelse:\n q, p = (N - l + 1) // (r - l), (N - l + 1) % (r - l)\n ans = sum(A[1:l]) + q * sum(A[l:r]) + sum(A[l:l + p])\n\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s063855579', 's313054417', 's517170041', 's552363375', 's888515710', 's319020630'] | [13508.0, 20148.0, 12800.0, 12636.0, 13428.0, 21304.0] | [78.0, 42.0, 81.0, 79.0, 87.0, 79.0] | [487, 503, 491, 494, 487, 506] |
p02550 | u207363774 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M = map(int,input().split())\n\nd = {X:0}\nl = [X]\ns = 0\n\nfor i in range(1,N):\n l+=[(l[i-1]**2)%M]\n if l[i] in d:\n dl = l[d[l[i]]+1:]\n s += sum(dl)*((N-i-1)//len(dl))\n if (N-i-1)%len(dl) != 0:\n s += sum(dl[0:(N-i-1)%len(dl)])\n break\n s += l[i]\n d[l[i]] = i\nprint(s)', 'N,X,M = map(int,input().split())\n\nd = {X:0}\nl = [X]\n\nfor i in range(1,N):\n l+=[(l[i-1]**2)%M]\n if l[i] in d:\n dl = l[d[l[i]]+1:]\n print(dl)\n l += dl*((N-i-1)//len(dl))\n if (N-i-1)%len(dl) != 0:\n l += dl[0:(N-i-1)%len(dl)]\n break\n d[l[i]] = i\nprint(l)\nprint(sum(l))', 'N,X,M = map(int,input().split())\n\nd = {X:0}\nl = [X]\ns = X\n\nfor i in range(1,N):\n l+=[(l[i-1]**2)%M]\n s += l[i]\n if l[i] in d:\n dl = l[d[l[i]]+1:]\n s += sum(dl)*((N-i-1)//len(dl))\n if (N-i-1)%len(dl) != 0:\n s += sum(dl[0:(N-i-1)%len(dl)])\n break\n d[l[i]] = i\nprint(s)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s425277555', 's561760447', 's892910438'] | [15760.0, 30372.0, 15628.0] | [70.0, 136.0, 70.0] | [287, 287, 287] |
p02550 | u221272125 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M = map(int,input().split())\nR = [X]\nm = min(N,M)\nfor i in range(m):\n r = R[-1]\n r = r**2%M\n if r in R:\n break\n R.append(r)\nfor i in range(len(R)):\n if r == R[i]:\n break', 'N,X,M = map(int,input().split())\nR = [X]\ndr = {}\nfor i in range(M):\n dr[i] = 0\nm = min(N,M)\nfor i in range(m):\n r = R[-1]\n r = r**2%M\n if dr[r] == 1:\n break\n R.append(r)\n dr[r] = 1\nfor i in range(len(R)):\n if r == R[i]:\n break', 'N,X,M = map(int,input().split())\nR = [X]\nm = min(X,M)\nfor i in range(m):\n r = R[-1]\n r = r**2%M\n if r in R:\n break\n R.append(r)\nfor i in range(len(R)):\n if r == R[i]:\n break\na = 0\nb = sum(R)\nfor j in range(i):\n a += R[j]\n b -= R[j]\nn = len(R) - i\nt = N - i\np = t // n\nq = t % n\nc = 0\nfor j in range(q):\n c += R[i+j]\nans = a + b*p + c\nprint(ans)', 'N,X,M = map(int,input().split())\nR = [X]\nm = min(X,M)\nfor i in range(m):\n r = R[-1]\n r = r**2%M\n if r in R:\n break\n R.append(r)\nfor i in range(len(R)):\n if r == R[i]:\n break\na = 0\nb = sum(R)\nfor j in range(i):\n a += R[j]\n b -= R[j]\nn = len(R) - i\nt = N - i\np = t // n\nq = t % n\nc = 0\nfor j in range(q):\n c += R[i+j]\nans = a + b*p + c\nprint(ans)', 'N,X,M = map(int,input().split())\nR = [X]\ndr = {}\nfor i in range(M):\n dr[i] = 0\nm = min(N,M)\nfor i in range(m):\n r = R[-1]\n r = r**2%M\n if dr[r] == 1:\n break\n R.append(r)\n dr[r] = 1\nfor i in range(len(R)):\n if r == R[i]:\n break\na = 0\nb = sum(R)\nfor j in range(i):\n a += R[j]\n b -= R[j]\nn = len(R) - i\nt = N - i\np = t // n\nq = t % n\nc = 0\nfor j in range(q):\n c += R[i+j]\nans = a + b*p + c\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s031976743', 's327220223', 's664668303', 's772495136', 's853676573'] | [9688.0, 19456.0, 9228.0, 9224.0, 19444.0] | [2206.0, 76.0, 28.0, 28.0, 95.0] | [202, 261, 382, 382, 441] |
p02550 | u288430479 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m = map(int,input().split())\nmod = m\nans = 0\nbit = [-1 for i in range(m)]\ncycle = False\nfor i in range(n):\n if i == 0 :\n a = x\n bit[a] = i\n ans += a\n else:\n a = (a**2)% mod\n if bit[a] != -1:\n cy_st = bit[a]\n cy_fi = i -1\n cycle = True\n break\n else:\n bit[a] = i\n ans += a\n\nif cycle:\n ans2 = x\n a = x\n for j in range(1,cy_st):\n a = (a**2)% mod\n ans2 += a\n cy_num = ans - ans2\n cy_repe = (n-cy_st) // (cy_fi - cy_st + 1)\n ans3 = cy_num * cy_repe\n cy_amari = (n-cy_st) % (cy_fi - cy_st + 1)\n for i in range(cy_amari):\n a = (a**2)% mod\n ans3 += a\n\nprint(ans2+ans3)\n', 'n,x,m = map(int,input().split())\nmod = m\nans = 0\nbit = [-1 for i in range(m)]\ncycle = False\nfor i in range(n):\n if i == 0 :\n a = x\n bit[a] = i\n ans += a\n else:\n a = (a**2)% mod\n if bit[a] != -1:\n cy_st = bit[a]\n cy_fi = i -1\n cycle = True\n break\n else:\n bit[a] = i\n ans += a\n\nif cycle:\n ans2 = 0\n b = -1\n for j in range(cy_st):\n if j == 0 :\n b = x\n ans2 += b\n else:\n b = (b**2)% mod\n ans2 += b\n cy_num = ans - ans2\n cy_repe = (n-cy_st) // (cy_fi - cy_st + 1)\n ans3 = cy_num * cy_repe\n cy_amari = (n-cy_st) % (cy_fi - cy_st + 1)\n \n if b == -1:\n for j in range(cy_amari):\n if j == 0 :\n b = x\n ans3 += b\n else:\n b = (b**2)% mod\n ans3 += b\n \n else:\n for i in range(cy_amari):\n b = (b**2)% mod\n ans3 += b\n\n print(ans2+ans3)\nelse:\n print(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s408257469', 's451912986'] | [11204.0, 11396.0] | [67.0, 69.0] | [730, 1071] |
p02550 | u326609687 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['import numpy as np\ni8 = np.int64\n\n\ndef solve(N, X, M):\n memo_val = np.zeros(M, i8)\n memo_i = np.zeros(M, i8)\n ret = 0\n a = X\n for i in range(1, N):\n ret += a\n if memo_i[a] > 0:\n u = (N - memo_i[a]) // (i - memo_i[a])\n v = (N - memo_i[a]) % (i - memo_i[a])\n ret = u * (ret - memo_val[a])\n nokori = v + memo_i[a]\n for j in range(M):\n if memo_i[j] == nokori:\n ret += memo_val[j]\n return ret\n memo_i[a] = i\n memo_val[a] = ret\n a = a ** 2 % M\n return ret\n\n\nN, X, M = [int(x) for x in input().split()]\nans = solve(N, X, M)\nprint(ans)', 'import numpy as np\ni8 = np.int64\n\n\ndef solve(N, X, M):\n memo_val = np.zeros(M, i8)\n memo_i = np.zeros(M, i8)\n ret = 0\n a = X\n for i in range(1, N):\n ret += a\n if memo_i[a] > 0:\n u = (N - memo_i[a]) // (i - memo_i[a])\n v = (N - memo_i[a]) % (i - memo_i[a])\n ret = u * (ret - memo_val[a])\n nokori = v + memo_i[a]\n for j in range(M):\n if memo_i[j] == nokori:\n ret += memo_val[j]\n return ret\n memo_i[a] = i\n memo_val[a] = ret\n a = a ** 2 % M\n ret += a\n return ret\n\ndef main():\n f = open(0)\n N, X, M = [int(x) for x in f.readline().split()]\n ans = solve(N, X, M)\n print(ans)\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s505742282', 's484207910'] | [27812.0, 28260.0] | [165.0, 163.0] | [680, 745] |
p02550 | u335406314 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M=map(int,input().split())\nA = [X,]\nsetA = {A,}\nalast=X\nflag=False\nfor i in range(min(N-1,M)):\n P=alast**2%M\n if P in setA:\n flag=True\n d = A.index(P)\n C=A[d:]\n alast=P\n break\n else:\n A.append(P)\n setA.add(P)\n alast=P\nif alast==0:\n print(sum(C))\nelif (flag==False) and (alast!=0):\n print(sum(A))\nelse:\n suma=sum(C)\n res = (N-d)%len(C)\n print(sum(A[:d])+((N-d)//len(C))*suma + sum(C[:res]))', 'N,X,M=map(int,input().split())\nA = [X,]\nsetA = {X,}\nalast=X\nflag=False\nfor i in range(min(N-1,M)):\n P=alast**2%M\n if P in setA:\n flag=True\n d = A.index(P)\n C=A[d:]\n alast=P\n break\n else:\n A.append(P)\n setA.add(P)\n alast=P\nif flag:\n if alast==0:\n ans = sum(A)\n else:\n res = (N-d)%len(C)\n ans = sum(A[:d])+((N-d)//len(C))*sum(C) + sum(C[:res])\nelse:\n ans = sum(A) \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s614691896', 's942207037'] | [9196.0, 13196.0] | [24.0, 59.0] | [473, 468] |
p02550 | u347502437 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | [' X, M = map(int, input().split())\nNN = N\nli = []\nwhile X not in li and N != 0:\n li = li + [X]\n X = X ** 2 % M\n N -= 1\n \nif N == 0:\n print(sum(x for x in li))\n\nelif N != 0 and X in li:\n l = len(li)\n s = li.index(X)\n T = l - s\n q = (NN - s) // T\n r = (NN - s) % T\n print(sum(li[i] for i in range(s)) + sum(li[i] for i in range(s, len(li))) * q\n + sum(li[i] for i in range(s, s + r)))', 'N, X, M = map(int, input().split())\nNN = N\nli = []\nisused = [False] * M\nwhile isused[X] == False and N != 0:\n li.append(X)\n isused[X] = True\n X = (X ** 2) % M\n N -= 1\n \nif N == 0:\n print(sum(li))\n\nelif N != 0 and X in li:\n l = len(li)\n s = li.index(X)\n T = l - s\n q = (NN - s) // T\n r = (NN - s) % T\n print(sum(li) + sum(li[i] for i in range(s, len(li))) * (q-1) + sum(li[i] for i in range(s, s + r)))'] | ['Runtime Error', 'Accepted'] | ['s872322016', 's109908584'] | [9000.0, 11516.0] | [30.0, 64.0] | [427, 437] |
p02550 | u348293370 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m = map(int, input().split()) \nans = 0\nx_list = []\n\nfor i in range(m):\n if i == n or x == 0:\n ans = sum(x_list)\n print(ans)\n exit()\n x_list.append(x)\n x = (x**2)%m\n \n if x_list.count(x) == 1:\n break\n\nfor i in range(len(x_list)):\n if x_list[i] == x:\n roop = list(x_list[i:])\n if n % len(roop) == 0:\n ans = sum(roop)*(n//len(roop) - 1) + sum(x_list)\n print(ans)\n else:\n ans = sum(roop)*(n//len(roop) - 1) + sum(x_list) + sum(roop[:(n//len(roop))])\n print(ans)\n exit()', 'N,x,M=map(int,input().split())\nk=x\nL=list()\nc=dict()\nfor i in range(M):\n if i==N:\n print(sum(L))\n exit()\n if x==0:\n print(sum(L))\n exit()\n L.append(x)\n x=(x*x)%M\n if x in c:\n q=x\n break\n c[x]=1\nmoto=sum(L)\nN-=len(L)\nfor i in range(len(L)):\n if L[i]==q:\n roop=list(L[i:])\nL=roop\na=len(L)\nif N%a==0:\n print(moto+(sum(L)*(N//a)))\nelse:\n s=N//a\n t=N%a\n ans=sum(L)*s\n ans+=sum(roop[:t])\n print(moto+ans)'] | ['Wrong Answer', 'Accepted'] | ['s528174457', 's349409200'] | [9616.0, 14340.0] | [2206.0, 59.0] | [587, 432] |
p02550 | u366886346 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m=map(int,input().split())\ncnt2=set()\ncnt2.add(x)\ncnt3=[x]\ncnt4=0\ncnt5=0\ncnt6=x\nfor i in range(1,m+10):\n num2=pow(cnt6,2,m)\n if num2 in cnt2:\n for j in range(len(cnt3)):\n if cnt3[j]==num2:\n cnt7=j\n break\n cnt10=len(cnt3)-cnt7\n num4=sum(cnt3[:cnt7])\n cnt4=len(cnt3)\n break\n cnt2.add(num2)\n cnt3.append(num2)\n cnt6=num2\n if num2==0:\n ans=sum(cnt3)\n cnt5=1\n break\nif cnt5==0:\n ans=num4\n n-=cnt7\n ans+=(n//cnt10)*sum(cnt3[cnt7:])\n ans+=sum(cnt3[cnt7:(n%cnt10)+cnt7])\nif cnt4>=n:\n ans=sum(cnt3[:n])\nprint(ans)\n', 'n,x,m=map(int,input().split())\ncnt2=set()\ncnt2.add(x)\ncnt3=[x]\ncnt4=0\ncnt5=0\ncnt6=x\nfor i in range(1,m+10):\n num2=pow(cnt6,2,m)\n if num2 in cnt2:\n for j in range(len(cnt3)):\n if cnt3[j]==num2:\n cnt7=j\n break\n cnt10=len(cnt3)-cnt7\n num4=sum(cnt3[:cnt7])\n cnt4=len(cnt3)\n break\n cnt2.add(num2)\n cnt3.append(num2)\n cnt6=num2\n if num2==0:\n ans=sum(cnt3)\n cnt5=1\n break\nif cnt5==0 and n>cnt4:\n ans=num4\n n-=cnt7\n ans+=(n//cnt10)*sum(cnt3[cnt7:])\n ans+=sum(cnt3[cnt7:(n%cnt10)+cnt7])\nif cnt4>=n:\n ans=sum(cnt3[:n])\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s003552454', 's076041530'] | [13268.0, 13264.0] | [82.0, 83.0] | [639, 650] |
p02550 | u414050834 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n,x,m=map(int,input().split())\nans=0\np=0\nl=[x]\nif x%m==0:\n print(x)\nelse:\n for i in range(1,n):\n s=(l[i-1]**2)%m\n if s==0:\n p=1\n break\n if s in l:\n break\n else:\n l.append(s)\n if p==0:\n t=sum(l[1:])\n k=n//(len(l)-1)\n j=n%(len(1)-1)\n ans=x+t*k+sum(l[1:j+1])\n print(ans)\n else:\n print(sum(l))', 'n,x,m=map(int,input().split())\norder=[-1 for i in range(m)] \nindex=0 \na=[] \nwhile order[x]==-1: \n order[x]=index \n a.append(x)\n x=(x**2)%m\n index+=1\ntmp=sum(a[order[x]:index]) \nt=index-order[x] \nif n-1<order[x]: \n print(sum(a[:n]))\nelse:\n sum1=sum(a[:order[x]]) \n x1=n-order[x] \n n1=x1//t \n n2=x1%t\n print(sum1+n1*tmp+sum(a[order[x]:order[x]+n2]))'] | ['Runtime Error', 'Accepted'] | ['s886467679', 's785215285'] | [9644.0, 13644.0] | [2206.0, 61.0] | [343, 716] |
p02550 | u416011173 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['# -*- coding: utf-8 -*-\n\nN, X, M = list(map(int, input().split()))\n\n\n\n\ndef f(x: int, m: int) -> int:\n return x**2 % m\n\n\nA = {X}\nloop_start_index = 0\nwhile True:\n A_next = f(A[-1], M)\n if A_next in A:\n loop_start_index = A.index(A_next)\n break\n else:\n A.add(A_next)\n\nloop_length = len(A) - loop_start_index\nloop_cnt = (N - loop_start_index) // loop_length\nloop_res = (N - loop_start_index) % loop_length\nans = sum(A[:loop_start_index]) + \\\n loop_cnt * sum(A[loop_start_index:]) + \\\n sum(A[loop_start_index: loop_start_index + loop_res])\n\n\nprint(ans)\n', '# -*- coding: utf-8 -*-\n\ndef get_input() -> tuple:\n \n \n N, X, M = list(map(int, input().split()))\n\n return N, X, M\n\n\ndef f(x: int, m: int) -> int:\n \n return x % m\n\n\ndef main(N: int, X: int, M: int) -> None:\n \n \n A = [X]\n s = {X}\n i = 0\n while True:\n A_next = f(A[-1], M)\n if A_next in s:\n i = A.index(A_next)\n break\n else:\n A.append(A_next)\n s.add(A_next)\n\n loop_length = len(A) - i\n loop_cnt = (N - i) // loop_length\n loop_res = (N - i) % loop_length\n ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i: i + loop_res])\n\n \n print(ans)\n\n\nif __name__ == "__main__":\n \n N, X, M = get_input()\n\n \n main(N, X, M)\n', '# -*- coding: utf-8 -*-\n\ndef get_input() -> tuple:\n \n \n N, X, M = list(map(int, input().split()))\n\n return N, X, M\n\n\ndef f(x: int, m: int) -> int:\n \n return x % m\n\n\ndef main(N: int, X: int, M: int) -> None:\n \n \n A = [X]\n s = {X}\n i = 0\n while True:\n A_next = f(A[-1]**2, M)\n if A_next in s:\n i = A.index(A_next)\n break\n else:\n A.append(A_next)\n s.add(A_next)\n\n loop_length = len(A) - i\n loop_cnt = (N - i) // loop_length\n loop_res = (N - i) % loop_length\n ans = sum(A[:i]) + loop_cnt * sum(A[i:]) + sum(A[i: i + loop_res])\n\n \n print(ans)\n\n\nif __name__ == "__main__":\n \n N, X, M = get_input()\n\n \n main(N, X, M)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s061351612', 's715283256', 's999216555'] | [9056.0, 9240.0, 13216.0] | [28.0, 33.0, 55.0] | [639, 1258, 1261] |
p02550 | u481187938 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ["#!usr/bin/env python3\n\ndef L(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef SL(): return list(sys.stdin.readline().rstrip())\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n\n\ndef main():\n N, X, M = LI()\n p = [0] * (M+10)\n p[1] = X\n for i in range(2, M+10):\n p[i] = pow(X, pow(2, i-1, M-1), M)\n s = 0\n for v in p:\n s = (s + v) % M\n\n tmp = 0\n for i in range(N % M):\n tmp = (tmp + p[i]) % M\n\n print((N // M * s % M + tmp) % M)\n\n\nif __name__ == '__main__':\n main()", '#!usr/bin/env python3\nfrom collections import defaultdict, deque, Counter, OrderedDict\nfrom bisect import bisect_left, bisect_right\nfrom functools import reduce, lru_cache\nfrom heapq import heappush, heappop, heapify\n\nimport itertools\nimport math, fractions\nimport sys, copy\n\n\ndef L(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline().rstrip())\ndef SL(): return list(sys.stdin.readline().rstrip())\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]\ndef LS(): return [list(x) for x in sys.stdin.readline().split()]\ndef R(n): return [sys.stdin.readline().strip() for _ in range(n)]\ndef LR(n): return [L() for _ in range(n)]\ndef IR(n): return [I() for _ in range(n)]\ndef LIR(n): return [LI() for _ in range(n)]\ndef LIR1(n): return [LI1() for _ in range(n)]\ndef SR(n): return [SL() for _ in range(n)]\ndef LSR(n): return [LS() for _ in range(n)]\n\ndef perm(n, r): return math.factorial(n) // math.factorial(r)\ndef comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))\n\ndef make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]\n\ndire = [[1, 0], [0, 1], [-1, 0], [0, -1]]\ndire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]\nalphabets = "abcdefghijklmnopqrstuvwxyz"\nALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"\nMOD = 1000000007\nINF = float("inf")\n\nsys.setrecursionlimit(1000000)\nclass ModInt:\n def __init__(self, x, MOD=1000000007): self.x, self.MOD = x % MOD, MOD\n def __str__(self): return str(self.x)\n def __add__(self, other): return ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other)\n def __sub__(self, other): return ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other)\n def __mul__(self, other): return ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other)\n def __truediv__(self, other): return ModInt(self.x * other.inverse()) if isinstance(other, ModInt) else ModInt(self.x * pow(other, self.MOD - 2, self.MOD))\n def __pow__(self, other): return ModInt(pow(self.x, other.x, self.MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, self.MOD))\n def __rsub__(self, other): return ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x)\n def __rtruediv__(self, other): return ModInt(other.x * other.inverse()) if isinstance(other, ModInt) else ModInt(other * pow(self.x, self.MOD - 2, self.MOD))\n def __rpow__(self, other): return ModInt(pow(other.x, self.x, self.MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, self.MOD))\n __repr__, __radd__, __rmul__ = __str__, __add__, __mul__\n def inverse(self): return pow(self.x, self.MOD - 2, self.MOD)\n\ndef main():\n N, X, M = LI()\n tmp = X\n s = set()\n while True:\n if tmp in s: break\n s.add(tmp)\n tmp = (tmp * tmp) % M\n\n f = len(s)\n s = set()\n\n while True:\n if tmp in s: break\n s.add(tmp)\n tmp = (tmp * tmp) % M\n\n mid = len(s)\n summid = sum(s)\n rest = (N - f + mid) % mid\n cnt = (N - f + mid) // mid\n\n first = f - mid\n tmp = X\n s = set()\n for _ in range(first):\n s.add(tmp)\n tmp = (tmp * tmp) % M\n first_res = sum(s)\n\n s = set()\n for _ in range(rest):\n s.add(tmp)\n tmp = (tmp * tmp) % M\n last_res = sum(s)\n\n print(first_res+ summid*cnt+ last_res)\n\n\n\n\nif __name__ == \'__main__\':\n main()'] | ['Runtime Error', 'Accepted'] | ['s425247408', 's524080567'] | [9056.0, 14508.0] | [30.0, 69.0] | [574, 3588] |
p02550 | u495667483 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['import sys, math, re\nfrom functools import lru_cache\nfrom collections import deque\nsys.setrecursionlimit(10**9)\nMOD = 10**9+7\n\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef mi():\n return map(int, input().split())\n\ndef ii():\n return int(input())\n\ndef i2(n):\n tmp = [list(mi()) for i in range(n)]\n return [list(i) for i in zip(*tmp)]\n\ndef main():\n N, X, M = mi()\n r = [-1]*M\n\n now = X\n cnt = 0\n while True:\n if r[now] != -1:\n break\n r[now] = cnt\n now = (now*now)%M\n cnt += 1\n\n d = [(r[i], i) for i in range(M) if r[i] != -1]\n d.sort()\n T = len(d)-r[now]\n\n s = list(v for k, v in d if k < len(d)-T)\n t = list(v for k, v in d if k >= len(d)-T)\n\n if N < len(s):\n ans = sum(s[:N])\n else:\n ans = sum(s) + sum(t)*((N-len(s))//M) + sum(t[:(N-len(s))%M])\n print(sum(s), sum(t)*((N-len(s))//M), sum(t[:(N-len(s))%M]))\n\n print(ans)\n\n\n\nif __name__ == "__main__":\n main()', 'import sys, math, re\nfrom functools import lru_cache\nfrom collections import deque\nsys.setrecursionlimit(10**9)\nMOD = 10**9+7\n\ndef input():\n return sys.stdin.readline()[:-1]\n\ndef mi():\n return map(int, input().split())\n\ndef ii():\n return int(input())\n\ndef i2(n):\n tmp = [list(mi()) for i in range(n)]\n return [list(i) for i in zip(*tmp)]\n\ndef main():\n N, X, M = mi()\n r = [-1]*M\n\n now = X\n cnt = 0\n while True:\n if r[now] != -1:\n break\n \n r[now] = cnt\n\n now = (now*now)%M\n cnt += 1\n \n d = [(r[i], i) for i in range(M) if r[i] != -1]\n d.sort()\n\n s = [v for k, v in d[:r[now]]]\n t = [v for k, v in d[r[now]:]]\n\n ns = len(s)\n nt = len(t)\n\n if N < ns:\n print(sum(s[:N]))\n return\n \n print(sum(s) + sum(t) * ((N-ns)//nt) + sum(t[:(N-ns)%nt]))\n\n\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s371075110', 's534152629'] | [17932.0, 18124.0] | [92.0, 96.0] | [980, 901] |
p02550 | u536034761 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\nflag = [False for _ in range(M)]\nrecord = list()\nrecord.append(X)\nflag[X] = 1\n\nAn = X\n\nfor i in range(M + 1):\n An = pow(An, 2, M)\n if flag[An]:\n start = flag[An]\n cnt = i + 2 - start\n cost = record[-1] - record[start - 2] if start > 1 else record[-1]\n break\n\n else:\n record.append(An + record[-1])\n flag[An] = i + 2\n\nif start >= N:\n print(record[N - 1])\nelse:\n print(((N - start) // cnt) * cost\n + record[(N - start) % cnt + start - 1])\n print(cost)\n', 'N, X, M = map(int, input().split())\nrecord_sum = [0, ]\nflag = [False for _ in range(M)]\nAn = X\n\n# n=1\nrecord_sum.append(An)\nflag[An] = 1\n\nfor i in range(2, M + 2):\n An = pow(An, 2, M) \n record_sum.append(record_sum[-1] + An)\n\n if flag[An]:\n start_index = flag[An]\n initial_cost = record_sum[start_index - 1]\n cycle_cost = record_sum[-1] - record_sum[start_index]\n cycle_length = i - start_index\n else:\n flag[An] = i\n\nif start_index >= N:\n print(record_sum[N])\n\nelse:\n ans = 0\n ans += ((N - start_index) // cycle_length) * cycle_cost\n ans += record_sum[(N - start_index) % cycle_length + start_index]\n\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s955259079', 's756357432'] | [13712.0, 16464.0] | [84.0, 152.0] | [561, 703] |
p02550 | u539969758 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M = map(int,input().split())\n\nans = X\nA = X\nTF = True\nsrt = 1000000\nretu = dict()\nretu[X] = 1\nloop = X\nfor i in range(N-1):\n if TF:\n A = A**2 % M\n if retu.get(A) != None:\n srt = j\n goal = i\n TF = False\n break \n if TF:\n retu[A] = 1\n loop += A\n else:\n break\n \nif N-1 > srt:\n n = (N-srt)//(goal-srt+1)\n saisyo = sum(retu[:srt])\n loop -= saisyo\n print(saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)]))\n \nelse:\n print(sum(retu[:N]))\n', 'N, X, M = map(int, input().split())\n\ncandicate = [pow(i, 2, M) for i in range(M)]\nans = 0\nnow = X\nA = [0]\nX2 = pow(X, 2, M)\n\nd = dict()\n\nflag = True\nfor i in range(1, N):\n if i == 1:\n A.append(X)\n \n else:\n nxt = candicate[A[i-1]]\n\n if d.get(nxt) == None:\n if nxt == 0:\n A.append(nxt)\n break\n else:\n A.append(nxt)\n d[nxt] = i\n\n else:\n flag = False\n break\n\n\nif flag:\n print(sum(A))\nelse:\n l = d[nxt]\n r = i - 1\n circle_total = 0\n for j in range(l, r+1):\n circle_total += A[j]\n \n for j in range(1, l):\n ans += A[j]\n\n width = r - l + 1\n N -= (l - 1)\n ans += circle_total * (N // width)\n\n for j in range(l, l + N % width):\n ans += A[j]\n\n print(ans)\n', 'N,X,M = map(int,input().split())\n\nans = X\nA = X\nTF = True\nsrt = 1000000\nretu = [X]\nd = dict()\nd[X] = 0\nloop = X\nflag = False\nfor i in range(N-1):\n if TF:\n A = A**2 % M\n if d.get(A) != None:\n srt = d[A]\n goal = i\n TF = False\n \n if TF:\n retu.append(A)\n d[A] = i + 1\n loop += A\n else:\n flag = True\n break\n \nif flag:\n n = (N-srt)//(goal-srt+1)\n saisyo = sum(retu[:srt])\n loop -= saisyo\n print(saisyo + loop*n + sum(retu[srt:N-n*(goal-srt+1)]))\n \nelse:\n print(sum(retu[:N]))\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s083305804', 's652685904', 's411434845'] | [13996.0, 18020.0, 15828.0] | [57.0, 144.0, 64.0] | [544, 842, 593] |
p02550 | u543000780 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\nls = [False]*M\nls_mod = []\nx = X\nfor m in range(M+1):\n if ls[x] == False:\n ls_mod.append(x)\n ls[x] = m\n x = (x**2)%M\n else:\n last = m\n fast = ls[x]\n diff = last - fast\n break\nif last >= N:\n print(sum(ls_mod[:N]))\nelse:\n shou = (N-fast) // diff\n amari = (N-fast) % diff\n print(sum(ls_mod[:fast])+sum([fast:])*shou+sum([fast:fast+amari]))', 'N, X, M = map(int, input().split())\nls = [False]*M\nls_mod = []\nx = X\nfor m in range(M+1):\n if ls[x] == False:\n ls_mod.append(x)\n ls[x] = m\n x = (x**2)%M\n else:\n last = m\n fast = ls[x]\n diff = last - fast\n break\nprint(last)\n"""if last >= N:\n print(sum(ls_mod[:N]))\nelse:\n shou = (N-fast) // diff\n amari = (N-fast) % diff\n print(sum(ls_mod[:fast])+sum(ls_mod[fast:])*shou+sum(ls_mod[fast:fast+amari]))\n"""\n', 'N, X, M = map(int, input().split())\nls = [False]*M\nls_mod = []\nx = X\nfor m in range(M+1):\n if ls[x] == False:\n ls_mod.append(x)\n ls[x] = m\n x = (x**2)%M\n else:\n last = m\n fast = ls[x]\n diff = last - fast\n break\n"""if last >= N:\n print(sum(ls_mod[:N]))\nelse:\n shou = (N-fast) // diff\n amari = (N-fast) % diff\n print(sum(ls_mod[:fast])+sum(ls_mod[fast:])*shou+sum(ls_mod[fast:fast+amari]))\n\n"""', 'N, X, M = map(int, input().split())\nls = [False]*M\nls_mod = []\nx = X\nfor m in range(M+1):\n if ls[x] == False:\n ls_mod.append(x)\n ls[x] = m\n x = (x**2)%M\n else:\n last = m\n fast = ls[x]\n diff = last - fast\n break\nif M == 1:\n print(0)\nelse:\n if last > N:\n print(sum(ls_mod[:N]))\n else:\n shou = (N-fast) // diff\n amari = (N-fast) % diff\n print(sum(ls_mod[:fast])+sum(ls_mod[fast:])*shou+sum(ls_mod[fast:fast+amari]))\n\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s246428901', 's289086282', 's796667232', 's372182947'] | [9076.0, 13260.0, 13116.0, 13572.0] | [27.0, 62.0, 53.0, 58.0] | [399, 431, 419, 452] |
p02550 | u607155447 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\n\nans = 0\nchck = 0\nflag = [0]*(10**5 +1)\nlst = [X]\n\nfor i in range(N):\n X = (X**2)%M\n\n if flag[X] == 1:\n break\n\n flag[X] = 1\n lst.append(X)\n\npreindex = lst.index(X)\n\npreloop = lst[:index]\nloop = lst[index:]\n\nloopnum = (N - len(preloop))//len(loop)\nloopafternum = (N - len(preloop))%len(loop)\n\nans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])\nprint(ans)', 'N, X, M = map(int, input().split())\n\nans = 0\nflag = [0]*(10**5 + 2)\nlst = [X]\n\nfor i in range(N):\n X = (X**2)%M\n\n if flag[X] == 1:\n break\n\n flag[X] = 1\n lst.append(X)\n\npreindex = lst.index(X)\n\npreloop = lst[:preindex]\nloop = lst[preindex:]\n\nloopnum = (N - len(preloop))//len(loop)\nloopafternum = (N - len(preloop))%len(loop)\n\nans = sum(preloop) + sum(loop)*loopnum + sum(loop[:loopafternum])\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s312055747', 's013318311'] | [11568.0, 12172.0] | [55.0, 56.0] | [423, 421] |
p02550 | u625864724 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n, x, m = map(int,input().split())\nlst = [0 for i in range(m)]\nlst2 = [x]\ni = 2\nlst[x] = 1\nwhile True:\n if (i > n):\n break\n x = x**2%m\n if (lst[x] == 0):\n lst[x] = i\n lst2.append(lst2[i - 2] + x)\n i = i + 1\n else:\n lst2.append(lst2[i - 2] + x)\n break\na = i - lst[x]\nb = lst2[i - 1] - lst2[i - 1 - a]\ni = i - 1\nc = (n - i)//a\nd = (n - i)%a\nans = lst2[i - 1] + b*c + lst2[i - 1 - a + d] - lst2[i - 1 - a]\nprint(ans)\n', 'n, x, m = map(int,input().split())\nlst = [0 for i in range(m)]\nlst2 = [x]\ni = 2\nlst[x] = 1\nc = 0\nwhile True:\n if (i > n):\n break\n x = x**2%m\n if (lst[x] == 0):\n lst[x] = i\n lst2.append(lst2[i - 2] + x)\n i = i + 1\n else:\n lst2.append(lst2[i - 2] + x)\n c = 1\n break\nif (c == 1):\n a = i - lst[x]\n b = lst2[i - 1] - lst2[i - 1 - a]\n\n c = (n - i)//a\n d = (n - i)%a\n ans = lst2[i - 1] + b*c + lst2[i - 1 - a + d] - lst2[i - 1 - a]\n print(ans)\n\nelse:\n print(lst2[n - 1])\n'] | ['Runtime Error', 'Accepted'] | ['s756473359', 's932952800'] | [13764.0, 13768.0] | [69.0, 72.0] | [468, 546] |
p02550 | u628285938 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['# -*- coding: utf-8 -*-\n"""\nCreated on Sat Sep 19 22:03:19 2020\n\n@author: liang\n"""\n\nN, X, M = map(int,input().split())\nmod_set = {X}\nmod_lis = [X]\nA = [0]*(10**6+1)\nA[0] = X\nflag = False\n\nfor i in range(1,min(10**6,N)):\n tmp = A[i-1]**2%M\n if tmp in mod_set:\n flag = True\n break\n A[i] = tmp\n mod_set.add(tmp)\n mod_lis.append(tmp)\n\nif flag:\n j = mod_lis.index(tmp)\nelse:\n j = i\nT = i - j\nans = 0\nif T != -1: \n ans += sum(mod_lis[:j])\n T_sum = sum(mod_lis[j:])\n \n ans += T_sum * ((N-j)//T)\n #print((N-j)//T, T_sum)\n T_lis = mod_lis[j:i] \n ans += sum(T_lis[:(N-j)%T])\nelse:\n ans = sum(mod_lis)\n#print(T_lis)\n#print((N-j)%T)\n#print(T_lis[:10])\nprint(ans)\n#print(T_sum)\n#print(sum(T_lis))', '# -*- coding: utf-8 -*-\n"""\nCreated on Sat Sep 19 22:03:19 2020\n\n@author: liang\n"""\n\nN, X, M = map(int,input().split())\nmod_set = {X}\nmod_lis = [X]\nA = [0]*(10**6+1)\nA[0] = X\nflag = False\n\n\nl = 1\nfor i in range(1,min(10**6,N)):\n l = i\n tmp = A[i-1]**2%M\n if tmp in mod_set:\n flag = True\n break\n A[i] = tmp\n mod_set.add(tmp)\n mod_lis.append(tmp)\n\nif flag:\n j = mod_lis.index(tmp)\nelse:\n j = l\nT = l - j\nans = 0\nif T != 0: \n #print("A")\n ans += sum(mod_lis[:j])\n T_sum = sum(mod_lis[j:])\n q, r = divmod(N-j,T)\n ans += T_sum * q\n #print((N-j)//T, T_sum)\n T_lis = mod_lis[j:] \n ans += sum(T_lis[:r])\nelse:\n #print("B")\n ans = sum(mod_lis)\n # print(mod_lis)\n#print(T_lis)\n#print((N-j)%T)\n#print(T_lis[:10])\nprint(ans)\n#print(T_sum)\n#print(sum(T_lis))'] | ['Runtime Error', 'Accepted'] | ['s095125658', 's864440639'] | [21388.0, 21288.0] | [71.0, 79.0] | [842, 1645] |
p02550 | u630554891 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['import math\nn,x,m=map(int, input().split())\na = x\nans = a\nl=[a]\nflg=[0]*m\n\nfor i in range(1,m):\n tmp=(a*a)%m\n a=tmp \n ans+=tmp\n if flg[a]==1:\n lp = l.index(a)\n break\n else:\n l.append(a)\n flg[a]=1\n\nif lp != 0:\n l2 = l[lp:]\n tmp = sum(l2)\n b=math.floor((n-len(l))/len(l2))\n c=(n-len(l))%len(l2)\n if c==0:\n ans+=b*tmp\n else:\n ans+=b*tmp+sum(l2[:c])-l2[0]\n\nprint(ans)', 'n,x,m=map(int, input().split())\na = x\nans = a\nl=[a]\n\nfor i in range(1,n):\n tmp=(a*a)%m\n a=tmp \n ans+=tmp\n if a in l:\n lp = l.index(a)\n break\n else:\n l.append(a)\n\nl2 = l[lp:]\ntmp = sum(l2)\n\nb=int((n-len(l))/len(l2))\nc=(n-len(l))%len(l2)\n\nans+=b*tmp+sum(l2[:c])\nprint(ans)', 'n,x,m=map(int, input().split())\na=x\nans=a\nflg=[0]*m\nflg[a]=1\nl=[a]\nlp=-1\n\nfor i in range(1,n):\n tmp=(a*a)%m\n a=tmp\n if flg[a]==1:\n lp = l.index(a)\n break\n else: \n ans+=tmp\n l.append(a)\n flg[a]=1\n\nif lp != -1:\n l2 = l[lp:]\n tmp = sum(l2)\n b=(n-len(l))//len(l2)\n c=n-len(l)-b*len(l2)\n ans=ans+(b*tmp)+sum(l2[:c])\n\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s028062170', 's104363176', 's599112204'] | [12344.0, 9592.0, 12172.0] | [56.0, 2206.0, 54.0] | [438, 307, 387] |
p02550 | u642012866 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\n\nlim = 10**5+1\n\nf = [0]*(lim)\na = [0]*(lim)\n\nx = X\nf[x] = 1\na[1] = x\n\nans = x\n\ni = 1\nl = N\nwhile i < l:\n i += 1\n\n x **= 2\n x %= M\n if not x:\n break\n\n if f[x]:\n lp_len = (i-f[x])\n z = (l-i+1)//lp_len\n if z:\n ls = ans - a[f[x]-1]\n ans += ls * z\n i += z*lp_len\n\n if i < l:\n ans += x\n \n f[x] = i\n if i < lim:\n a[i] = ans\n\nprint(ans)', 'N, X, M = map(int, input().split())\n\nlim = 10**5*2+1\n\nf = [0]*(lim)\na = [0]*(lim)\n\nx = X\nf[x] = 1\na[1] = x\n\nans = x\n\ni = 1\nl = N\nwhile i < l:\n i += 1\n\n x **= 2\n x %= M\n if not x:\n break\n\n if f[x]:\n lp_len = (i-f[x])\n z = (l-i+1)//lp_len\n if z:\n ls = ans - a[f[x]-1]\n ans += ls * z\n i += z*lp_len\n\n if i <= l:\n ans += x\n \n f[x] = i\n if i < lim:\n a[i] = ans\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s435392705', 's094838566'] | [15264.0, 16868.0] | [104.0, 98.0] | [466, 469] |
p02550 | u645487439 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n, x, m = map(int, input().split())\nans = 0\nloop_list = [0] * m\nloop_list[x] = 1\norder_list = [x]\n\nfor i in range(1, m + 1):\n x = pow(x, 2, m)\n if loop_list[x] != 1:\n loop_list[x] = 1\n order_list.append(x)\n else:\n break\n\nindex = order_list.index(x)\ntime = (n - index) // (len(order_list) - index)\nmod = (n - index) % (len(order_list) - index)\n\nans += sum(order_list[:index - 1])\nans += sum(order_list[index:]) * time\nans += sum(order_list[index:index + mod - 1])\n\nprint(ans)\n', 'n, x, m = map(int, input().split())\nans = 0\nloop_list = [0] * m\nloop_list[x] = 1\norder_list = [x]\n\nfor i in range(1, m + 1):\n x = pow(x, 2, m)\n if loop_list[x] != 1:\n loop_list[x] = 1\n order_list.append(x)\n else:\n break\n\nindex = order_list.index(x)\ntime = (n - index) // (len(order_list) - index)\nmod = (n - index) % (len(order_list) - index)\n\nans += sum(order_list[:index])\nans += sum(order_list[index:]) * time\nans += sum(order_list[index:index + mod])\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s546005706', 's578152054'] | [12164.0, 12184.0] | [78.0, 85.0] | [506, 498] |
p02550 | u684814987 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['\n\ndef main():\n n, x, m = map(int, input().split())\n l = [x]\n ltot = [x]\n\n flg = 0\n tot = x\n a = x\n for i in range(n):\n a = a ** 2 % m\n if a in set(l):\n for j in range(len(l)):\n if l[j] == a:\n l2 = l[j:]\n z = (n - j) // len(l2) - 1\n y = (n - j) % len(l2)\n tot += (ltot[y-1] - ltot[j-1]) + (ltot[-1] - ltot[j-1]) * z\n \n flg = 1\n break\n if flg:\n break\n tot += a\n l.append(a)\n ltot.append(tot)\n\n print(tot)\n\n\nmain()\n\n', '\n\ndef main():\n n, x, m = map(int, input().split())\n mflg = [-1] * m\n mflg[x] = 0\n ltot = [x]\n\n tot = x\n a = x\n for i in range(1, n):\n a = a ** 2 % m\n\n if mflg[a] >= 0:\n b = mflg[a]\n z = (n - i) // (i - b)\n y = (n - i) % (i - b)\n if b == 0 and y == 0:\n tot += ltot[i - 1] * z\n elif b == 0:\n tot += ltot[b - 1 + y] + ltot[i - 1] * z\n else:\n tot += (ltot[b - 1 + y] - ltot[b - 1]) + (ltot[i - 1] - ltot[b - 1]) * z\n break\n\n mflg[a] = i\n tot += a\n ltot.append(tot)\n\n print(tot)\n\n\nmain()\n\n'] | ['Wrong Answer', 'Accepted'] | ['s893602418', 's552743853'] | [10540.0, 13496.0] | [2206.0, 53.0] | [683, 665] |
p02550 | u699522269 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M = map(int,input().split())\nrt = 0\nfor i in range(2,N+1):\n dps[i] = (dps[i-1]**2)%M\n rt+=dps[i]\nprint(rt)', 'N,X,M = map(int,input().split())\ndps = [0,X%M]+[0 for i in range(N)]\nrt = 0\nfor i in range(2,N+1):\n dps[i] = (dps[i-1]**2)%M\n rt+= dps[i]\nprint(rt)', 'n, x, m = map(int, input().split())\nmn = min(n, m)\nP = []\nsum_p = 0\nX = [-1] * m\nfor i in range(mn):\n if X[x] > -1:\n cyc_len = len(P) - X[x]\n remain = P[X[x]]\n cyc = (sum_p - remain) * ((n - X[x]) // cyc_len)\n remain += P[X[x] + (n - X[x]) % cyc_len] - P[X[x]]\n print(cyc + remain)\n exit()\n P.append(sum_p)\n sum_p += x\n X[x] = i\n x = x*x % m\nprint(sum_p)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s128037989', 's580105984', 's678104335'] | [8944.0, 632488.0, 13616.0] | [28.0, 2227.0, 52.0] | [112, 149, 411] |
p02550 | u734876600 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n, x, m = map(int, input().split())\na = x\nmod = [a]\nloop = []\ncnt = 0\nwhile cnt < n:\n a = a**2 % m\n if a in mod:\n i = mod.index(a)\n before = mod[:i]\n loop = mod[i:]\n break\n mod.append(a)\n cnt += 1\n\nlength = len(loop)\nif length == 0:\n print(sum(mod[:n]))\nelse:\n print(loop)\n t = (n-i)//length\n amari = (n-i) % length\n print("t, amari:",t,",",amari)\n ans = sum(before) + t * sum(loop) + sum(loop[:amari])\n print(ans)\n', 'n, x, m = map(int, input().split())\na = x\nmod = [a]\nloop = []\ncnt = 0\nwhile cnt < n:\n a = a**2 % m\n if a in mod:\n i = mod.index(a)\n before = mod[:i]\n loop = mod[i:]\n break\n mod.append(a)\n cnt += 1\n\nlength = len(loop)\nif length == 0:\n print(sum(mod[:n]))\nelse:\n print(loop)\n t = (n-i)//length\n amari = (n-i) % length\n ans = sum(before) + t * sum(loop) + sum(loop[:amari])\n print(ans)\n', 'n, x, m = map(int, input().split())\na = x\ndup = [0]*(10**5+10)\nmod = [a]\nloop = []\ncnt = 0\nwhile cnt < n:\n a = a**2 % m\n if dup[a]==1:\n i = mod.index(a)\n before = mod[:i]\n loop = mod[i:]\n break\n mod.append(a)\n dup[a] = 1\n cnt += 1\n\nlength = len(loop)\nif length == 0:\n print(sum(mod[:n]))\nelse:\n t = (n-i)//length\n amari = (n-i) % length\n ans = sum(before) + t * sum(loop) + sum(loop[:amari])\n print(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s052979197', 's249515872', 's013042536'] | [9588.0, 9644.0, 12460.0] | [2205.0, 2206.0, 61.0] | [476, 441, 462] |
p02550 | u784022244 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M=map(int, input().split())\nimport time\nfrom math import log, ceil\n\n\n\nini=[0]*M\nmod=[0]*M\nini[0]=sum(list(range(1,M)))\nCounter=[0]*M\nCounter[0]=M-1\n\nfor i in range(1,M):\n now=i+1\n temp=now\n count=1\n while now**2<M:\n now=now**2\n temp+=now\n count+=1\n m=(now**2)%M\n ini[i]=temp\n mod[i]=m\n Counter[i]=count\n#print(ini[:5])\n#print("ok")\n#print(Counter[:100])\nans=0\ncount=0\nnow=X\ndone=[-1]*M\nok=False\nwhile True:\n if now==0:\n print(ans)\n exit()\n if count+Counter[now-1]>N:\n break\n if done[now-1]==-1 or ok is True:\n done[now-1]=(ans, count)\n ans+=ini[now-1]\n #print(ini[now-1])\n count+=Counter[now-1]\n now=mod[now-1]\n else:\n pans, pcount=done[now-1]\n #print(count, pcount)\n #print("break")\n ans+=(ans-pans)*((N-count)//(count-pcount))\n count+=(count-pcount)*((N-count)//(count-pcount))+1\n #print(count)\n ok=True\n\n\nprint(ans, count, now, )\n\n\n\nwhile True:\n if count==N:\n break\n\n ans+=now%M\n now=(now**2)%M\n count+=1\n\n \n\nprint(ans)\n\n\n\n\n\n\n#print(ini)\n#print(mod)\n#print(Counter)', 'N,X,M=map(int, input().split())\n\nans=0\ncount=0\nnow=X\ndone=[-1]*(M-1)\nL=[]\nif now==0:\n print(ans)\n exit()\nj=False\nwhile True:\n if count==N:\n break\n\n if now==0:\n print(ans)\n exit()\n else:\n if done[now-1]==-1:\n done[now-1]=1\n L.append(now)\n else:\n for i in range(len(L)):\n if L[i]==now:\n j=i\n break\n ans+=now\n count+=1\n now=(now**2)%M\n\nif j:\n L=L[j:]\n\ntotal=sum(L)\nlength=len(L)\n\nans+=((N-count)//length)*total\nans+=sum(L[:(N-count)%length])\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s652369068', 's919493512'] | [25812.0, 12116.0] | [2206.0, 64.0] | [1156, 589] |
p02550 | u811817592 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['# -*- coding: utf-8 -*-\nN, X, M = map(int, input().split())\n\nmod_check_list = [False for _ in range(M)]\nmod_list = [(X ** 2) % M]\ncounter = 1\nmod_sum = (X ** 2) % M\nlast_mod = 0\nfor i in range(M):\n now_mod = (mod_list[-1] ** 2) % M\n if mod_check_list[now_mod]:\n last_mod = now_mod\n break\n mod_check_list[now_mod] = True\n mod_list.append(now_mod)\n counter += 1\n mod_sum += now_mod\n\nloop_start_idx = 0\nfor i in range(counter):\n if last_mod == mod_list[i]:\n loop_start_idx = i\n break\n\nloop_list = mod_list[loop_start_idx:]\nloop_num = counter - loop_start_idx\nans = 0\nif mod_list[-1] == 0:\n ans = X + sum(mod_list[:min(counter, N - 1)])\nelse:\n if (N - 1) <= counter:\n ans = X + sum(mod_list[:counter])\n print(aa)\n else:\n ans += X + mod_sum\n N -= (counter + 1)\n ans += sum(loop_list) * (N // loop_num) + sum(loop_list[:N % loop_num])\nprint(ans)', 'n,x,m=map(int,input().split())\na=[]\nmod_check_list = [False for _ in range(M)]\na.append(x*x%m)\nind=0\ns=0\nfor i in range(m):\n t=a[i]*a[i]%m\n if mod_check_list[t]:\n ind=a.index(t)\n break\n mod_check_list[t] = True\n a.append(t)\ns=sum(a[ind:])\nl=len(a)-ind\nloop_times = (n-1-ind)//l\nanswer=loop_times*s\nfor i in range((n-1-ind)%l):\n answer+=a[i+ind]\nprint(answer+x+sum(a[:ind]))', 'n,x,m=map(int,input().split())\na=[]\nmod_check_list = [False for _ in range(m)]\na.append(x*x%m)\nind=0\ns=0\nfor i in range(m):\n t=a[i]*a[i]%m\n if mod_check_list[t]:\n ind=a.index(t)\n break\n mod_check_list[t] = True\n a.append(t)\ns=sum(a[ind:])\nl=len(a)-ind\nloop_times = (n-1-ind)//l\nanswer=loop_times*s\nfor i in range((n-1-ind)%l):\n answer+=a[i+ind]\nprint(answer+x+sum(a[:ind]))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s172080829', 's621886069', 's831466044'] | [12436.0, 9228.0, 12172.0] | [76.0, 27.0, 62.0] | [932, 402, 402] |
p02550 | u845620905 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\nx = X\nnums = []\nisSearched = [False] * (M+1)\nisSearchedNums = [-1] * (M+1)\nn = 0\nlooped = 0\nwhile True:\n x = (x*x) % M\n if isSearched[x]:\n looped = isSearchedNums[x]\n break\n isSearched[x] = True\n isSearchedNums[x] = n\n nums.append(x)\n n+=1\nif (isSearched[0]):\n ans = X\n for i in range(min((N-1), len(nums))):\n ans += nums[i]\n\n print(ans)\nelse:\n ans = X\n al = 0\n d = len(nums) - looped\n for i in range(looped, len(nums)):\n al += nums[i]\n\n if N - 1 > len(nums):\n N -= len(nums)\n ans += sum(nums)\n ans += al * ((N-1) // d)\n for i in range(looped, ((N-1) % d) + looped):\n ans += nums[i]\n else:\n for i in range(i, N - 1):\n ans += nums[i]\n\n print(ans)\n\n', 'N, X, M = map(int, input().split())\nx = X\nnums = []\nisSearched = [False] * (M+1)\nisSearchedNums = [-1] * (M+1)\nn = 0\nlooped = 0\nwhile True:\n x = (x*x) % M\n if isSearched[x]:\n looped = isSearchedNums[x]\n break\n isSearched[x] = True\n isSearchedNums[x] = n\n nums.append(x)\n n+=1\nif (isSearched[0]):\n ans = X\n for i in range(min((N-1), len(nums))):\n ans += nums[i]\n\n print(ans)\nelse:\n ans = X\n al = 0\n d = len(nums) - looped\n for i in range(looped, len(nums)):\n al += nums[i]\n if N - 1 > len(nums):\n N -= len(nums)\n ans += sum(nums)\n ans += al * ((N-1) // d)\n for i in range(looped, ((N-1) % d) + looped):\n ans += nums[i]\n else:\n for i in range(N - 1):\n ans += nums[i]\n\n print(ans)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s694575795', 's681047736'] | [14104.0, 13972.0] | [66.0, 67.0] | [816, 812] |
p02550 | u854524560 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\nA = [X]\nA_dict = {X}\na = X\ns = X\nr = 0\nr0 = 0\nl = 0\namari = 0\n\nfor i in range(M+1):\n a = a ** 2 % M\n if a in A_dict:\n r0 = A.index(a)\n l = len(A[r0:])\n r = (N - i - 1) // l\n amari = (N - i - 1) % l\n s = sum(A[:r0]) + sum(A[r0:])*r + sum(A[r0:r0+amari])\n break\n A.append(a)\n A_dict.add(a)\n s += A[-1]\n\nprint(s)', 'N, X, M = map(int, input().split())\nA = [X]\nA_dict = {X}\na = X\ns = X\nr = 0\nr0 = 0\nl = 0\namari = 0\n\nfor i in range(M+1):\n a = a ** 2 % M\n if a in A_dict:\n r0 = A.index(a)\n l = len(A[r0:])\n r = (N - i - 1) // l\n amari = (N - i - 1) % l\n s = sum(A[:r0]) + sum(A[r0:])*r + sum(A[r0:r0+amari])\n break\n A.append(a)\n A_dict.add(a)\n\nprint(s)', 'N, X, M = map(int, input().split())\nA = []\na = X\ns = X\nr = 0\nr0 = 0\nl = 0\namari = 0\n\nA.append(X)\nfor i in range(N-1):\n a = a ** 2 % M\n if A.count(a) >= 1:\n if a == 0:\n s = sum(A)\n break\n else:\n r0 = A.index(a)\n l = len(A[r0:])\n r = (N - i - 1) // l\n amari = (N - i - 1) % l\n s = sum(A) + sum(A[r0:])*r + sum(A[r0:r0+amari])\n break\n A.append(a)\n\nprint(s)', 'N, X, M = map(int, input().split())\nA = [X]\na = X\ns = X\nr = 0\nr0 = 0\nl = 0\namari = 0\n\nfor i in range(N-1):\n if A.count(a ** 2 % M) >= 1:\n if a == 0:\n s = sum(A)\n break\n else:\n r0 = A.index(a)\n l = len(A[r0:])\n r = (N - i - 1) // l\n amari = (N - i - 1) % l\n s = s + sum(A[r0:])*r + sum(A[r0:r0+amari])\n break\n A.append(a**2 % M)\n s += A[-1]\n\nprint(s)', 'N, X, M = map(int, input().split())\nA = [X]\nA_dict = {X}\na = X\ns = X\nr = 0\nr0 = 0\nl = 0\namari = 0\n\nfor i in range(M+1):\n a = a ** 2 % M\n if a in A_dict:\n r0 = A.index(a)\n l = len(A[r0:])\n r = (N - i - 1) // l\n amari = (N - i - 1) % l\n s = s + sum(A[r0:])*r + sum(A[r0:r0+amari])\n break\n A.append(a)\n A_dict.add(a)\n s += A[-1]\n\nprint(s)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s184454665', 's291317396', 's295898293', 's799516474', 's858204470'] | [13136.0, 13136.0, 9732.0, 9140.0, 13132.0] | [65.0, 56.0, 2206.0, 27.0, 62.0] | [368, 355, 402, 398, 358] |
p02550 | u903082918 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['\nimport sys\nimport math\nfrom functools import reduce\n\ndef readString():\n return sys.stdin.readline()\n\ndef readInteger():\n return int(readString())\n\ndef readStringSet(n):\n return sys.stdin.readline().split(" ")[:n]\n\ndef readIntegerSet(n):\n return list(map(int, readStringSet(n)))\n\ndef readIntegerMatrix(n, m):\n return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])\n\ndef main(N, X, M):\n A = X\n l = [A]\n i = -1\n for _ in range(1, M):\n A = (A * A) % M if M > 0 else 0\n if A in l:\n i = l.index(A)\n break\n else:\n l.append(A)\n\n if i == -1:\n return sum(l)\n else:\n s1 = sum(l[:i])\n len_repeat = len(l) - i\n s2 = sum(l[i:])\n\n # return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])\n\nif __name__ == "__main__":\n _N, _X, _M = readIntegerSet(3)\n\n print(main(_N, _X, _M))', '\nimport sys\nimport math\nfrom functools import reduce\n\ndef readString():\n return sys.stdin.readline()\n\ndef readInteger():\n return int(readString())\n\ndef readStringSet(n):\n return sys.stdin.readline().split(" ")[:n]\n\ndef readIntegerSet(n):\n return list(map(int, readStringSet(n)))\n\ndef readIntegerMatrix(n, m):\n return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])\n\ndef main(N, X, M):\n A = X\n l = [A]\n i = -1\n for _ in range(1, M):\n A = (A * A) % M if M > 0 else 0\n l.append(A)\n\n if i == -1:\n return sum(l)\n else:\n s1 = sum(l[:i])\n len_repeat = len(l) - i\n s2 = sum(l[i:])\n\n return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])\n\nif __name__ == "__main__":\n _N, _X, _M = readIntegerSet(3)\n\n print(main(_N, _X, _M))', '\nimport sys\nimport math\nfrom functools import reduce\n\ndef readString():\n return sys.stdin.readline()\n\ndef readInteger():\n return int(readString())\n\ndef readStringSet(n):\n return sys.stdin.readline().split(" ")[:n]\n\ndef readIntegerSet(n):\n return list(map(int, readStringSet(n)))\n\ndef readIntegerMatrix(n, m):\n return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])\n\ndef main(N, X, M):\n A = X\n l = [A]\n i = -1\n for _ in range(1, M):\n A = A # (A * A) % M if M > 0 else 0\n if A in l:\n i = l.index(A)\n break\n else:\n l.append(A)\n\n if i == -1:\n return sum(l)\n else:\n s1 = sum(l[:i])\n len_repeat = len(l) - i\n s2 = sum(l[i:])\n\n return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])\n\nif __name__ == "__main__":\n _N, _X, _M = readIntegerSet(3)\n\n print(main(_N, _X, _M))', '\nimport sys\nimport math\nfrom functools import reduce\n\ndef readString():\n return sys.stdin.readline()\n\ndef readInteger():\n return int(readString())\n\ndef readStringSet(n):\n return sys.stdin.readline().split(" ")[:n]\n\ndef readIntegerSet(n):\n return list(map(int, readStringSet(n)))\n\ndef readIntegerMatrix(n, m):\n return reduce(lambda acc, _: acc + [readIntegerSet(m)], range(0, n), [])\n\ndef main(N, X, M):\n A = X\n m = {A: A}\n i = -1\n for j in range(1, M):\n A = (A * A) % M if M > 0 else 0\n if A in m:\n i = list(m.keys()).index(A)\n break\n else:\n m[A] = A\n\n if i == -1:\n return sum(m.values())\n else:\n l = list(m.values())\n s1 = sum(l[:i])\n len_repeat = len(l) - i\n s2 = sum(l[i:])\n\n return s1 + int((N-i)/len_repeat) * s2 + sum(l[i:(N-i)%len_repeat+i])\n\nif __name__ == "__main__":\n _N, _X, _M = readIntegerSet(3)\n\n print(main(_N, _X, _M))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s449461102', 's544215917', 's787758034', 's676105789'] | [10008.0, 13408.0, 9576.0, 14592.0] | [2206.0, 52.0, 35.0, 50.0] | [983, 899, 985, 1032] |
p02550 | u913662443 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['n, x, m = map(int,input().split())\nans = x\nnum = 0\nl = [0]*min(m,10**4)\nlis = [-1]*min(m,10**4)\nl[0] = x\nlis[x] = num\nfor i in range(1,n):\n x = (x*x)%m\n num += 1\n if lis[x]!=-1:\n a = (n-i)//(i-lis[x])\n b = (n-i)%(i-lis[x])\n ans += a * sum(l[lis[x]:i])\n break\n l[i] = x\n lis[x] = i\n ans += x\nfor i in range(lis[x],lis[x]+b):\n ans += l[i]\nprint(ans)', 'n, x, m = map(int,input().split())\nans = x\nnum = 0\nl = [0]*n\nlis = [-1]*n\nl[0] = x\nlis[x] = num\nfor i in range(1,n):\n x = (x*x)%m\n num += 1\n if lis[x]!=-1:\n a = (n-i)//(i-lis[x])\n b = (n-i)%(i-lis[x])\n ans += a * sum(l[lis[x]:i])\n break\n l[i] = x\n lis[x] = i\n ans += x\nfor i in range(lis[x],lis[x]+b):\n ans += l[i]\nprint(ans)', 'n, x, m = map(int,input().split())\nans = x\nnum = 0\nl = [0]*1000\nlis = [-1]*1000\nl[0] = x\nlis[x] = num\nfor i in range(1,n):\n x = (x*x)%m\n num += 1\n if lis[x]!=-1:\n a = (n-i)//(i-lis[x])\n b = (n-i)%(i-lis[x])\n ans += a * sum(l[lis[x]:i])\n break\n l[i] = x\n lis[x] = i\n ans += x\nfor i in range(lis[x],lis[x]+b):\n ans += l[i]\nprint(ans)', 'n, x, m = map(int,input().split())\nans = x\nnum = 0\nl = [0]*m\nlis = [-1]*m\nl[0] = x\nlis[x] = num\nfor i in range(1,n):\n x = (x*x)%m\n num += 1\n if lis[x]!=-1:\n a = (n-i)//(i-lis[x])\n b = (n-i)%(i-lis[x])\n ans += a * sum(l[lis[x]:i])\n break\n l[i] = x\n lis[x] = i\n ans += x\nfor i in range(lis[x],lis[x]+b):\n ans += l[i]\nprint(ans)', 'n, x, m = map(int,input().split())\nans = x\nnum = 0\nl = [0]*m\nlis = [-1]*m\nl[0] = x\nlis[x] = num\nfor i in range(1,n):\n x = (x*x)%m\n num += 1\n if lis[x]!=-1:\n a = (n-i)//(i-lis[x])\n b = (n-i)%(i-lis[x])\n ans += a * sum(l[lis[x]:i])\n for j in range(lis[x],lis[x]+b):\n ans += l[j]\n break\n l[i] = x\n lis[x] = i\n ans += x\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s056010691', 's195429644', 's558825763', 's782103849', 's412113980'] | [9232.0, 23984.0, 9248.0, 13804.0, 13936.0] | [28.0, 49.0, 27.0, 59.0, 56.0] | [396, 374, 380, 374, 390] |
p02550 | u935511247 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['#import sys\n#print(sys.maxsize)\nN,X,M=map(int,input().split())\ntable=list(range(M))\nfor i in range(M):\n table[i]=((table[i]%M)**2)%M\nprint(table[471])\nstart=X%M\nrireki=list()\nrireki.append(start)\nss=0\nfor j in range(1,N):\n if table[start] in rireki:\n ss=rireki.index(table[start])\n break\n else:\n rireki.append(table[start])\n start=table[start]\nnn=len(rireki)\nrep=(N-ss)//(nn-ss)\nnokori=N-ss-rep*(nn-ss)\nloop=rireki[ss:]\n#print(nn)\n#print(rep)\n#print(sum(loop))\n#print(ss)\n\nif 0 in rireki:\n goukei=sum(rireki)\nelse:\n goukei=rep*sum(loop)+sum(rireki[:ss])+sum(loop[:nokori])\nprint(goukei)', '#import sys\n#print(sys.maxsize)\nN,X,M=map(int,input().split())\n#table=list(range(M))\n\n # table[i]=((table[i]%M)**2)%M\n#print(table[471])\nstart=X%M\nrset=set()\nrireki=list()\nrset.add(start)\nrireki.append(start)\nss=0\nfor j in range(1,M+1):\n start=(start**2)%M\n if start in rset:\n ss=rireki.index(start)\n break\n else:\n rireki.append(start)\n rset.add(start)\nnn=len(rireki)\nrep=(N-ss)//(nn-ss)\nnokori=N-ss-rep*(nn-ss)\nloop=rireki[ss:]\n#print(nn)\n#print(rep)\n#print(sum(loop))\n#print(ss)\n\nif 0 in rireki:\n goukei=sum(rireki)\nelse:\n goukei=rep*sum(loop)+sum(rireki[:ss])+sum(loop[:nokori])\nprint(goukei)'] | ['Runtime Error', 'Accepted'] | ['s281803898', 's993922583'] | [13016.0, 13532.0] | [2206.0, 59.0] | [658, 688] |
p02550 | u936985471 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['import sys\nreadline=sys.stdin.readline\n\nN,X,M = map(int,readline().split())\nroute = [X]\ndic = {}\nfirst = []\nloop = []\nfor i in range(1, N):\n X = (X ** 2) % M\n if X in dic:\n first = route[:dic[X]]\n loop = route[dic[X]:]\n break\n route.append(X)\n dic[X] = i\n\nif N == len(first):\n print(sum(first))\nelif N < len(first):\n print(sum(first[:N]))\nelse:\n ans = sum(first)\n one_loop = sum(loop)\n N -= len(first)\n loop_cnt = N // len(loop)\n rest = N % len(loop)\n ans += loop_cnt * (sum(loop))\n ans += sum(loop[:rest])\n\n print(ans)\n', 'import sys\nreadline = sys.stdin.readline\n\nN,X,M = map(int,readline().split())\n\nnex = [(i ** 2) % M for i in range(M)]\ncum = [i for i in range(M)]\n\nans = 0\nwhile N:\n if N & 1:\n ans += cum[X]\n X = nex[X]\n cum = [cum[i] + cum[nex[i]] for i in range(M)]\n nex = [nex[nex[i]] for i in range(M)]\n N >>= 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s708289117', 's244176493'] | [15564.0, 23968.0] | [57.0, 1121.0] | [543, 319] |
p02550 | u973972117 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N,X,M = map(int,input().split())\nA = X%M\nAns = A\nModset = set()\nModset.add(A)\nsig = 0\nN -= 1\nfor i in range(10**7):\n A = pow(A,2,M)\n Ans += A\n if A ==0:\n break\n if A not in Modset:\n Modset.add(A)\n N -= 1\n else:\n Ans -= A\n sig = 1\n break\nprint(N,Ans)\nif sig == 1:\n S = A\n B = A\n rep = 0\n for i in range(10**6):\n B = pow(B,2,M)\n rep += 1\n if A== B:\n break\n else:\n S += B\n Rep = N//rep\n Ans += Rep*S\n N -= Rep*rep\n if N != 0:\n Ans += A\n N -= 1\n for i in range(10**6):\n if N == 0:\n break\n Ans += pow(A,2,M)\nprint(Ans)', 'N,X,M = map(int,input().split())\nA = X%M\nAns = A\nModset = set()\nModset.add(A)\ni = 1\nfor _ in range(10**6):\n A = pow(A,2,M)\n if A not in Modset:\n Modset.add(A)\n Ans += A\n i += 1\n else:\n break\nif 0 in Modset:\n print(Ans)\nelse:\n S = A\n B = A\n j = 1\n for _ in range(10**6):\n B = pow(B,2,M)\n if A != B:\n S += B\n j += 1\n else:\n break\n rep = (N-i)//j\n Ans += S*rep\n i += j*rep\n if i < N:\n i += 1\n Ans += A\n for _ in range(10**10):\n if i == N:\n break\n else:\n i += 1\n A = pow(A,2,M)\n Ans += A\n print(Ans)'] | ['Wrong Answer', 'Accepted'] | ['s193600108', 's664929171'] | [12508.0, 12452.0] | [899.0, 169.0] | [702, 719] |
p02550 | u995062424 | 2,000 | 1,048,576 | Let us denote by f(x, m) the remainder of the Euclidean division of x by m. Let A be the sequence that is defined by the initial value A_1=X and the recurrence relation A_{n+1} = f(A_n^2, M). Find \displaystyle{\sum_{i=1}^N A_i}. | ['N, X, M = map(int, input().split())\n\nrec = []\ns = set()\nrec.append(X)\ns.add(X)\nr = X\nidx == -1\nidx1 = -1\nfor i in range(N+1):\n r = (r**2)%M\n if(r not in s):\n rec.append(r)\n s.add(r)\n else:\n rec.append(r)\n idx = i+1\n break\n \nfor i in range(len(rec)):\n if(rec[i] == rec[idx]):\n idx1 = i\n break\n\nif(idx == -1 and idx1 == -1):\n print(sum(rec))\nelif(idx1 != idx): \n ans = sum(rec[:idx1])\n ans += sum(rec[idx1:idx])*((N-idx1)//(idx-idx1))+sum(rec[idx1:(idx1+(N-idx1)%(idx-idx1))])\n print(ans)\nelse:\n ans = sum(rec[:idx1])\n ans += rec[idx]*(N-idx1)\n print(ans)', 'N, X, M = map(int, input().split())\n\nrec = []\ns = set()\nrec.append(X)\ns.add(X)\nr = X\nidx = -1\nidx1 = -1\nfor i in range(N+1):\n r = (r**2)%M\n if(r not in s):\n rec.append(r)\n s.add(r)\n else:\n rec.append(r)\n idx = i+1\n break\n \nfor i in range(len(rec)):\n if(rec[i] == rec[idx]):\n idx1 = i\n break\n\nif(idx == -1 or idx1 == -1):\n print(sum(rec[:N]))\nelif(idx1 != idx): \n ans = sum(rec[:idx1])\n ans += sum(rec[idx1:idx])*((N-idx1)//(idx-idx1))+sum(rec[idx1:(idx1+(N-idx1)%(idx-idx1))])\n print(ans)\nelse:\n ans = sum(rec[:idx1])\n ans += rec[idx]*(N-idx1)\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s532287025', 's372759054'] | [9092.0, 13224.0] | [28.0, 60.0] | [644, 646] |
p02551 | u785573018 | 2,000 | 1,048,576 | There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left. Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares on the bottom side and the right side has a white stone on it. Q queries are given. We ask you to process them in order. There are two kinds of queries. Their input format and description are as follows: * `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone. * `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone. How many black stones are there on the grid after processing all Q queries? | ['n, q = map(int, input().split())\nl = [0]*n; u = [0]*n; lmin = n-2; umin = n-2; lgoal = n; ugoal = n\nfor _ in range(q):\n s, t = map(int, input().split())\n if s == 1:\n if t > ugoal+1: u[t-1] = 0\n else:\n for i in range(t, ugoal-1):u[i] = umin\n lmin = t-2; ugoal = t\n else:\n if t > lgoal+1: l[t-1] = 0\n else:\n for i in range(t, lgoal-1):l[i] = lmin\n umin = t-2; lgoal = t\nprint(sum(l)+sum(u)+lmin*umin)', 'n, q = map(int, input().split())\nl = [0]*n; u = [0]*n; lmin = n-2; umin = n-2; lgoal = n; ugoal = n\nfor _ in range(q):\n s, t = map(int, input().split())\n if s == 1:\n if t > ugoal: u[t-1] = 0\n else:\n for i in range(t, ugoal-1):u[i] = umin\n lmin = t-2; ugoal = t\n else:\n if t > lgoal: l[t-1] = 0\n else:\n for i in range(t, lgoal-1):l[i] = lmin\n umin = t-2; lgoal = t\nprint(sum(l)+sum(u)+lmin*umin)'] | ['Wrong Answer', 'Accepted'] | ['s746746435', 's607591883'] | [11964.0, 11964.0] | [423.0, 413.0] | [479, 475] |
p02552 | u005977014 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['a,b,c,d=map(int,input().split())\nif a>=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a<=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a<=0 and b<=0 and c>=0 and d>=0:\n print(b*c)\nelif a<=0 and b>=0 and c<=0 and d>=0:\n print(b*d)\nelif a<=0 and b<=0 and c<=0 and d>=0:\n print(a*c)\nelif a<=0 and b>=0 and c<=0 and d<=0:\n print(a*c)\nelif a<=0 and b<=0 and c<=0 and d<=0:\n print(a*c)', 'X=int(input())\nif X==0:\n print(1)\nelse:\n print(0)'] | ['Runtime Error', 'Accepted'] | ['s797411251', 's077805600'] | [9152.0, 9144.0] | [22.0, 30.0] | [387, 51] |
p02552 | u007448456 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = 0\n\nif x == 0:\n print("1")\nif x == 1:\n print("0")', 'x = int(input())\n\nif x == 0:\n print("1")\nif x == 1:\n print("0")'] | ['Wrong Answer', 'Accepted'] | ['s901056410', 's319839667'] | [9004.0, 9028.0] | [33.0, 27.0] | [58, 69] |
p02552 | u013202780 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['print("O" if input()=="1" else "1")', 'import sys\nprint(int(sys.stdin.readline())^1)'] | ['Wrong Answer', 'Accepted'] | ['s853568975', 's932311382'] | [8864.0, 9120.0] | [26.0, 27.0] | [35, 45] |
p02552 | u013617325 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(x: int):\n\n if x == 1:\n return print('0')\n\n elif x == 0:\n return print('1')1\n\n\n# Generated by 1.1.7.1 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 x = int(next(tokens)) # type: int\n solve(x)\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\nimport sys\n\n\ndef solve(x: int):\n\n if x == 1:\n return print('0')\n\n elif x == 0:\n return print('1')\n\n\n# Generated by 1.1.7.1 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 x = int(next(tokens)) # type: int\n solve(x)\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s289489774', 's452729699'] | [8944.0, 9168.0] | [25.0, 33.0] | [567, 566] |
p02552 | u015767468 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['def big(x):\n if x==0:\n return 1\n elif x==1:\n return 0', 'x=int(input())\nif x==0:\n print 1\nelif x==1:\n print 0', 'x=int(input())\nif x==1:\n print(0)\nelif x==0:\n print(1)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s157223077', 's448382599', 's875562127'] | [9000.0, 8880.0, 8760.0] | [23.0, 26.0, 30.0] | [61, 54, 56] |
p02552 | u024340351 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['print(1-input())', 'print(1-int(input()))'] | ['Runtime Error', 'Accepted'] | ['s452177763', 's414279787'] | [9044.0, 8984.0] | [26.0, 27.0] | [16, 21] |
p02552 | u024568043 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['print(int(not int(input()))', 'print(int(not int(input())))'] | ['Runtime Error', 'Accepted'] | ['s770215384', 's279933231'] | [8876.0, 9144.0] | [23.0, 27.0] | [27, 28] |
p02552 | u038819082 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['a,b,c,d=map(int,input().split())\nprint(max(a*c,a*d,b*c,b*d))', 'x=int(input())\nif x==0:\n x=1\nelse:\n x=0\nprint(x)'] | ['Runtime Error', 'Accepted'] | ['s034933335', 's569644797'] | [9116.0, 9084.0] | [26.0, 24.0] | [60, 50] |
p02552 | u042709364 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(x)\n# OUTPUTS\n# Print 1 if input is equal to 0\nif x == 0:\n print(1)\n exit()\n\n# Print 0 if input is equal to 1\nif x == 1:\n print(0)\n exit()\n\n', "VAR = input('Please enter an integer: ')\nVAR = int(VAR)\n# OUTPUTS\n# Print 1 if input is equal to 0\nif VAR == 0:\n print(1)\n exit()\n# sys.exit('1')\n\n# Print 0 if input is equal to 1\nif VAR == 1:\n print(0)\n exit()\n# sys.exit('0')\n", "var = input('Please enter an integer: ')\nvar = int(var)\n# OUTPUTS \n# Print 1 if input is equal to 0 \nif var == 0:\n\texit()\n# sys.exit('1') \n \n# Print 0 if input is equal to 1\nif var == 1:\n\texit()\n# sys.exit('0')\n", 'import sys\n\n\nvar = input("Please enter an integer: ")\n\n# Error check 1: Is the input an integer?\ntry:\n val = int(var)\nexcept ValueError:\n sys.exit(\'Input is not an integer\') \n\n# Convert input to integer\nvar = int(var)\n\n# Error check 2: Is the input within bounds?\nif var > 1 or var < 0:\n sys.exit(\'Input is not within accepted bounds\')\n\n# OUTPUTS \n# Print 1 if input is equal to 0 \nif var == 0:\n sys.exit(\'1\') \n \n# Print 0 if input is equal to 1\nif var == 1:\n sys.exit(\'0\')\n', 'x = input()\nx = int(x)\n# OUTPUTS\n# Print 1 if input is equal to 0\nif x == 0:\n print(1)\n exit()\n\n# Print 0 if input is equal to 1\nif x == 1:\n print(0)\n exit()\n '] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s153467752', 's197696732', 's383241755', 's712235786', 's671591246'] | [8948.0, 9008.0, 9152.0, 9004.0, 8968.0] | [26.0, 30.0, 30.0, 19.0, 24.0] | [159, 244, 219, 504, 171] |
p02552 | u048826171 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['n = input()\nif n == 0:\n print(1)\nelif n ==1:\n print(0)', 'n = int(input())\nprint(1^n)'] | ['Wrong Answer', 'Accepted'] | ['s378280994', 's406425012'] | [9080.0, 9080.0] | [30.0, 29.0] | [56, 27] |
p02552 | u052331051 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['if __name__ == "__main__":\n a = input()\n a = int(a)\n if a==0:\n print(0)\n if a==1:\n print(1)', 'if __name__ == "__main__":\n a = input()\n a = int(a)\n if a==0:\n print(1)\n if a==1:\n print(0)'] | ['Wrong Answer', 'Accepted'] | ['s233599272', 's138054142'] | [9152.0, 9152.0] | [31.0, 29.0] | [117, 117] |
p02552 | u055641210 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['if input(int()):\n print(0)\nelse:\n print(1)', 'if int(input()):\n print(0)\nelse:\n print(1)'] | ['Wrong Answer', 'Accepted'] | ['s543077464', 's708557276'] | [8880.0, 9100.0] | [24.0, 25.0] | [48, 48] |
p02552 | u056118261 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(input())\nif x==1:\n print(0)\nelse if x==0:\n print(1)', 'x = int(input())\nif x==1:\n print(0)\n \nelse:\n print(1)'] | ['Runtime Error', 'Accepted'] | ['s747561023', 's751783574'] | [9004.0, 9144.0] | [27.0, 32.0] | [61, 56] |
p02552 | u056511037 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['princt(int(input()) ^ 1)', 'print(int(input()) ^ 1)'] | ['Runtime Error', 'Accepted'] | ['s423031727', 's032543389'] | [8992.0, 9172.0] | [24.0, 27.0] | [24, 23] |
p02552 | u066120361 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(input())\nprint(1 if x == 0 else 1)', 'x = int(input())\nif x == 0:\n print(1)\nelif x == 1:\n print(0)'] | ['Wrong Answer', 'Accepted'] | ['s192198050', 's945256795'] | [9032.0, 9144.0] | [27.0, 28.0] | [42, 66] |
p02552 | u066455063 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(input())\n\nprint(1 if x == 1 else 0)', 'x = int(input())\n \nprint(1 if x == 0 else 1)', 'x = int(input())\n\nif x == 1:\n print(0)\n \nelif x == 0:\n print(1)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s609233976', 's827294419', 's973506204'] | [9016.0, 9068.0, 8952.0] | [26.0, 31.0, 29.0] | [43, 44, 66] |
p02552 | u067694718 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['print(~int(input()))', 'print(~input())', 'print(1^int(input()))'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s325331905', 's475560260', 's928398432'] | [9016.0, 9000.0, 9036.0] | [28.0, 28.0, 25.0] | [20, 15, 21] |
p02552 | u068142202 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(input())\nif x != 1:\n print(0)\nelse:\n print(1)', 'x = int(input())\nif x == 1:\n print(0)\nelse:\n print(1)\n '] | ['Wrong Answer', 'Accepted'] | ['s836494848', 's263907350'] | [9144.0, 9092.0] | [28.0, 25.0] | [59, 64] |
p02552 | u090046582 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['if x == 0:\n print(1)\nelse:\n print(0)', '\nif x == 0:\n print(1)\nelse:\n print(0)', '\nx=0\n\nif x == 0:\n print(1)\nelse:\n print(0)', 'n=int(input())\nif (n==1):\n print("0")\nelse:\n print("1")'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s293888176', 's627652753', 's689319347', 's842125848'] | [9008.0, 9072.0, 8928.0, 9028.0] | [25.0, 28.0, 34.0, 26.0] | [36, 37, 42, 61] |
p02552 | u102067593 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ["a=input()\nif a==1:\n print('0')\nelse:\n print('1')", "a=input()\nif a=='1':\n print('0')\nelse:\n print('1')"] | ['Wrong Answer', 'Accepted'] | ['s071421799', 's065459062'] | [8992.0, 9056.0] | [26.0, 32.0] | [50, 52] |
p02552 | u107915058 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = input()\nprint("1" if x == "0" else "1")', 'x = input()\nprint("1" if x == "0" else "0")'] | ['Wrong Answer', 'Accepted'] | ['s729765063', 's390606291'] | [9084.0, 9080.0] | [32.0, 31.0] | [43, 43] |
p02552 | u114868394 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x=int(input())\nif x=0:\n print(1)\nelse:\n print(0)', 'a,b,c,d=list(map(int,input().split()))\nif a>=0 and c>=0:\n one=b\n two=d\n\nelif a<0 and c<0:\n one=a\n two=c\n\nelif a>=0 and c<0:\n one=a\n two=d\nelse:\n one=b\n two=c\n\n\nprint(one*two)', 'x=int(input())\nif x==0:\n print(1)\nelse:\n print(0)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s430953934', 's526087327', 's655897562'] | [9000.0, 9124.0, 9148.0] | [29.0, 24.0, 32.0] | [54, 198, 55] |
p02552 | u116763463 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x = int(input())\nif x == 0:\n\tprint(x^1)', '#include<bits/stdc++.h>\nusing namespace std;\n\n\n\nint mod = 1000000007;\n\n// #include "debug.cpp"\n\nint dp[1000010][4];\n\nint32_t main(){\n\tint n;\n\tcin >> n;\n\n\tif(n == 1){\n\t\tcout << "0\\n";\n\t\treturn 0;\n\t}\n\n\tdp[2][0] = 64;\n\tdp[2][1] = 17;\n\tdp[2][2] = 17;\n\tdp[2][3] = 2;\n\n\tfor(int i=3; i<=n; i++){\n\t\tdp[i][0] = dp[i-1][0]*8;\n\t\tdp[i][1] = dp[i-1][0] + dp[i-1][1]*9;\n\t\tdp[i][2] = dp[i-1][0] + dp[i-1][2]*9;\n\t\tdp[i][3] = dp[i-1][1] + dp[i-1][2] + dp[i-1][3]*10;\n\n\t\tdp[i][0] %= mod;\n\t\tdp[i][1] %= mod;\n\t\tdp[i][2] %= mod;\n\t\tdp[i][3] %= mod;\n\t}\n\n\tcout << dp[n][3] << "\\n";\n}', 'x = int(input())\nprint(x^1)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s658454850', 's852705130', 's734413912'] | [9144.0, 9000.0, 9144.0] | [27.0, 24.0, 30.0] | [39, 580, 27] |
p02552 | u119015607 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['a,b,c,d= map(int,input().split())\n\nif a>=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a>=0 and b>=0 and c<=0 and d<=0:\n print(a*d)\nelif a>=0 and b>=0 and c<=0 and d>=0:\n print(b*d)\nelif a<=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a<=0 and b<=0 and c<=0 and d>=0:\n print(a*c)\nelif a<=0 and b<=0 and c>=0 and d>=0:\n print(a*c)\nelif a<=0 and b<=0 and c<=0 and d<=0:\n print(a*d)\nelif a<=0 and b<=0 and c<=0 and d>=0:\n print(a*c)\nelif a<=0 and b>=0 and c<=0 and d>=0:\n x=a*c\n y=b*d\n print(x,y)\n if x>=y:\n print(x)\n else:\n print(y)', 'a,b,c,d= map(int,input().split())\n\nif a>=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a>=0 and b>=0 and c<=0 and d<=0:\n print(a*d)\nelif a>=0 and b>=0 and c<=0 and d>=0:\n print(b*d)\nelif a<=0 and b>=0 and c>=0 and d>=0:\n print(b*d)\nelif a<=0 and b<=0 and c<=0 and d>=0:\n print(a*c)\nelif a<=0 and b<=0 and c>=0 and d>=0:\n print(a*c)\nelif a<=0 and b<=0 and c<=0 and d<=0:\n print(a*d)\nelif a<=0 and b<=0 and c<=0 and d>=0:\n print(a*c)\nelif a<=0 and b>=0 and c<=0 and d>=0:\n x=a*c\n y=b*d\n #print(x,y)\n if x>=y:\n print(x)\n else:\n print(y)', 'x= int(input())\n\nif x ==0:\n print(1)\nelse:\n print(0)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s555727750', 's639404436', 's382391348'] | [9192.0, 9200.0, 9148.0] | [23.0, 26.0, 34.0] | [586, 587, 58] |
p02552 | u120758605 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x=int(input())\nif(x==1):\n print("0")\n elif(x==0):\n \n print("1")\n else:\n pass', 'x=int(input())\nif(x==1):\n print("0")\n elif(x==0):\n print("1")\n else:\n pass', 'x=int(input())\nif(x==1):\n \n print("0")\nelif(x==0):\n \n print("1")\nelse:\n \n pass\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s522932756', 's748732573', 's580218489'] | [8840.0, 8884.0, 9044.0] | [23.0, 27.0, 25.0] | [80, 77, 85] |
p02552 | u135331079 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['print(not int(input()))', 'print(not(int(input())))', "if input() == '0':\n print(1)\nelse:\n print(0)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s633422742', 's787723993', 's092669886'] | [9056.0, 9152.0, 8920.0] | [23.0, 28.0, 29.0] | [23, 24, 50] |
p02552 | u135642682 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['a,b,c,d = map(int, input().split())\nif a >=0:\n if c > 0:\n print(b * d)\n elif d < 0:\n print(a * d)\n else:\n print(b*d)\nelse:\n if c > 0:\n print(b * c)\n elif d < 0:\n print(a * c)\n else:\n print(b * c)', 'a,b,c,d = map(int, input().split())\nif a >=0:\n if c > 0:\n print(b * d)\n elif d < 0:\n print(a * d)\n else:\n print(b*d)\nelse:\n if c > 0:\n print(b * c)\n elif d < 0:\n print(a * c)\n else:\n print(b * c)', 'x = int(input())\nif x==1:\n print("0")\nelse:\n print("1")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s193274845', 's811770987', 's587518160'] | [9208.0, 9184.0, 9144.0] | [23.0, 28.0, 27.0] | [255, 255, 61] |
p02552 | u135832955 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ["import random\n\n\ndef gcd(a, b):\n if a == 0:\n return b\n return gcd(b % a, a)\n\n\ndef lcm(a, b):\n return (a * b) / gcd(a, b)\nx=input()\nif x==1:\n print('0')\nelse:\n print('1')", 'import random\n\n\ndef gcd(a, b):\n if a == 0:\n return b\n return gcd(b % a, a)\n\n\ndef lcm(a, b):\n return (a * b) / gcd(a, b)\n# a=list(map(int , input().split()))\n# ans=-1\n\n# for j in range(i+1,4):\n# if ans==-1:\n# ans=a[i]*a[j]\n# else:\n# ans=max(ans, a[i]*a[j])\n# print(ans)\nx=int(input())\nif x==1:\n print(0)\nelse:\n print(1)'] | ['Wrong Answer', 'Accepted'] | ['s338782402', 's695349339'] | [9436.0, 9488.0] | [31.0, 32.0] | [190, 404] |
p02552 | u153924627 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['if int(input()) == 1:\n print(1)\nelse:\n print(0)', 'if int(input()) == 1:\n print(0)\nelse:\n print(1)'] | ['Wrong Answer', 'Accepted'] | ['s606896632', 's292214598'] | [9156.0, 9136.0] | [29.0, 27.0] | [49, 49] |
p02552 | u161701206 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['a = input()\nprint(a)', 'a = int(input())\nif a != 0:\n print(0)\nelse:\n print(1)'] | ['Wrong Answer', 'Accepted'] | ['s126217862', 's936167151'] | [9132.0, 9088.0] | [29.0, 31.0] | [20, 59] |
p02552 | u167542063 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['x=input()\nif x==1:\n \tprint("0")\nelif x==0:\n \tprint("1")\n ', 'x=int(input())\nif x==1:\n \tprint(0)\nelif x==0:\n \tprint(1)'] | ['Wrong Answer', 'Accepted'] | ['s744088834', 's919040168'] | [8940.0, 9144.0] | [23.0, 27.0] | [62, 58] |
p02552 | u168825829 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['X = int(input())\nif X == "0":\n print("1")\nelif X == "1":\n print("0")', 'X = int(input())\nif X == 0:\n print("1")\nelif X == 1:\n print("0")'] | ['Wrong Answer', 'Accepted'] | ['s741028515', 's837502256'] | [9088.0, 9080.0] | [30.0, 31.0] | [74, 70] |
p02552 | u171356057 | 2,000 | 1,048,576 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. | ['def(x)\n if x == 1\n return 0\nreturn 1', 'x = int ( input() )\nif x==1:\n print (0)\n \nelse :\n print (1)'] | ['Runtime Error', 'Accepted'] | ['s234907499', 's786938371'] | [8852.0, 9052.0] | [25.0, 29.0] | [37, 62] |