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 |
|---|---|---|---|---|---|---|---|---|---|---|
p02714 | u747391638 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import math\nn = int(input())\ns = list(input())\n\nupper = s.count("R")*s.count("G")*s.count("B")\n\ndef counting(x):\n count = 0\n for i in range(math.ceil(x/2)):\n if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:\n count += 1\n else:\n count += 0\n return count\n\nif n>=3:\n minus = [0]*(n+1)\n if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:\n minus [3] = 1\n else:\n minus [3] = 0\n for i in range(4,n):\n minus[i+1] = minus[i]+counting(i+1)\n print(int(upper-minus[n]))\nelse:\n print(int(0))', 'import math\nn = int(input())\ns = list(input())\n\nupper = s.count("R")*s.count("G")*s.count("B")\n\nminus = [0]*(n+1)\nif s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:\n minus [3] = 1\nelse:\n minus [3] = 0\n\ndef counting(x):\n count = 0\n for i in range(math.ceil(x/2)):\n if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:\n count += 1\n else:\n count += 0\n return count\n\nfor i in range(4,n):\n minus[i+1] = minus[i]+counting(i+1)\n\nprint(int(upper-minus[n]))', 'import math\nn = int(input())\ns = list(input())\n\nupper = s.count("R")*s.count("G")*s.count("B")\n\ndef counting(x):\n count = 0\n for i in range(1, math.ceil(x/2)):\n if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:\n count += 1\n else:\n count += 0\n return count\n\nif n>=3:\n minus = [0]*(n+1)\n if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:\n minus [3] = 1\n else:\n minus [3] = 0\n for i in range(3,n):\n minus[i+1] = minus[i]+counting(i+1)\n print(int(upper-minus[n]))\nelse:\n print(int(0))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s326951113', 's814951030', 's300180729'] | [9240.0, 9248.0, 9268.0] | [1324.0, 1310.0, 1310.0] | [526, 481, 529] |
p02714 | u748241164 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = str(input())\nRGB = [0] * 3\nfor i in range(N):\n if S[i] == "R":\n RGB[0] += 1\n elif S[i] == "G":\n RGB[1] += 1:\n else:\n RGB[2] += 1\n \nans = RGB[0] * RGB[1] * RGB[2]\n\nfor i in range(1, 2000):\n for j in range(1, N + 1):\n if (j + 2 * i) <= N:\n if S[j - 1] != S[j + i - 1]:\n if S[j + 2 * i - 1] != S[j + i - 1]:\n if S[j - 1] != S[j + 2 * i - 1]:\n ans -= 1\n \nprint(max(ans, 0))\n ', 'N = int(input())\nS = str(input())\nR, G, B = 0, 0, 0\nfor i in range(N):\n if S[i] == "R":\n R += 1\n elif S[i] == "G":\n G += 1\n else:\n B += 1\n \nans = R * G * B \n\nfor i in range(1, 2000):\n for j in range(1, N - 2 * i + 1):\n if S[j - 1] != S[j + i - 1]:\n if S[j + 2 * i - 1] != S[j + i - 1]:\n if S[j - 1] != S[j + 2 * i - 1]:\n ans -= 1\n \nprint(max(ans, 0))\n \n'] | ['Runtime Error', 'Accepted'] | ['s197808528', 's656392901'] | [8984.0, 9208.0] | [24.0, 1731.0] | [455, 405] |
p02714 | u749742659 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\n\nR = []\nG = []\nB = []\nfor i in range(n):\n if(s[i] == 'R'):\n R.append(i)\n elif(s[i] == 'G'):\n G.append(i)\n else:\n B.append(i)\n\nsamu = len(R) * len(G) * len(B)\n\nfor i in R:\n for j in G:\n k = int(2 * j - i)\n if(0 <= k < n):\n if(s[k] == 'B'):\n samu -= 1\n print(i,j,k)\n k = int(2 * i - j)\n if(0 <= k < n):\n if(s[k] == 'B'):\n samu -= 1\n print(i,j,k)\n if(i % 2 == j % 2):\n k = int((i + j) / 2)\n if(s[k] == 'B'):\n samu -= 1\n print(i,j,k)\n\nprint(samu)", "n = int(input())\ns = input()\n\nR = []\nG = []\nB = []\nfor i in range(n):\n if(s[i] == 'R'):\n R.append(i)\n elif(s[i] == 'G'):\n G.append(i)\n else:\n B.append(i)\n\nsamu = len(R) * len(G) * len(B)\n\nfor i in R:\n for j in G:\n k = int(2 * j - i)\n if(0 <= k < n):\n if(s[k] == 'B'):\n samu -= 1\n k = int(2 * i - j)\n if(0 <= k < n):\n if(s[k] == 'B'):\n samu -= 1\n if(i % 2 == j % 2):\n k = int((i + j) / 2)\n if(s[k] == 'B'):\n samu -= 1\n\nprint(samu)"] | ['Wrong Answer', 'Accepted'] | ['s382020445', 's946212441'] | [15708.0, 9232.0] | [1981.0, 1291.0] | [673, 586] |
p02714 | u750651325 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef s(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn = k()\ns = s()\nr = s.count("R")\ng = s.count("G")\nb = s.count("B")\nans = r*g*b\nfor i in range(n-2):\n for j in range((n-i+1)//2):\n if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:\n a-=1\n\nprint(a)\n', 'import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef s(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\n\nn = k()\ns = s()\nr = s.count("R")\ng = s.count("G")\nb = s.count("B")\nans = r*g*b\nfor i in range(n-2):\n for j in range((n-i+1)//2):\n if s[i]!=s[i+j] and s[i+j]!=s[i+2*j] and s[i+2*j]!=s[i]:\n ans-=1\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s913874883', 's914441259'] | [10156.0, 10128.0] | [32.0, 1341.0] | [745, 749] |
p02714 | u751717561 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = list(input())\n\na = S[0]\nres= 0\n\nfor i in range(1, N-2):\n if a == S[i]:\n b = S[i]\n for j in range(j, N-1):\n if i == j:\n continue\n c = S[j]\n if a!=b and b!= c and a!=c:\n res +=1\n\nprint(res)', "N = int(input())\nS = list(input())\n\ncntOne = S.count('R') * S.count('G') * S.count('B')\ncntTwo = 0\n\n\nfor i in range(N-1):\n for j in range(i+1, N):\n k = (j - i) + j\n if k < N:\n if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:\n cntTwo += 1\nprint(cntOne - cntTwo)"] | ['Runtime Error', 'Accepted'] | ['s445930902', 's759196193'] | [9192.0, 9192.0] | [22.0, 1991.0] | [288, 305] |
p02714 | u767664985 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = input()\n\nans = S.count("R") * S.count("G") * S.count("B")\n\nres = 0\nfor i in range(N-2):\n for d in range(1, (N-i)//2+1):\n if set(S[i], S[i+d], S[i+2*d]) == {"R", "G", "B"}:\n res += 1\nans -= res\nprint(ans)\n', 'from bisect import bisect_right\n\ndef runLength(string):\n \n res = []\n data, count = string[0], 1\n for i in range(1, len(string)):\n if string[i] == data:\n count += 1\n else:\n res.append((data, count, i))\n data, count = string[i], 1\n res.append((data, count, i))\n return res\n\n\nN = int(input())\nS = input()\nrl = runLength(S)\nkeys = [rli[2] for rli in rl]\nnrl = len(rl)\n\nans = 0\n\nfor i in range(N-2):\n for j in range(i+1, N-1):\n if S[i] == S[j]:\n continue\n elif set([S[i], S[j]]) == {"R", "G"}:\n if 2*j - i < N and S[2*j - i] == "B":\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"]) - 1\n else:\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "B"])\n elif set([S[i], S[j]]) == {"B", "G"}:\n if 2*j - i < N and S[2*j - i] == "R":\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"]) - 1\n else:\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "R"])\n else:\n if 2*j - i < N and S[2*j - i] == "G":\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"]) - 1\n else:\n ans += sum([rl[x][1] for x in range(bisect_right(keys, j+1), nrl) if rl[x][0] == "G"])\n\nprint(ans)\n', 'N = int(input())\nS = input()\n\n\nans = S.count("R") * S.count("G") * S.count("B")\n\nfor i in range(N-2):\n for j in range(i+1, (N+i-1)//2+1):\n if set([S[i], S[j], S[2*j-i]]) == {"R", "G", "B"}:\n ans -= 1\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s261657087', 's703977825', 's311551607'] | [9192.0, 9352.0, 9080.0] | [21.0, 2206.0, 1846.0] | [246, 1609, 259] |
p02714 | u768256617 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["from collections import Counter\nn=int(input())\ns_=input()\ns=Counter(s_)\nrgb = s['R'] * s['G'] * s['B']\ncnt=0\nfor i in range(len(s_)):\n for j in range(i+1,len(s_)):\n h=j-i+j\n if h<len(s_)-1:\n if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:\n cnt+=1\n\nprint(rgb-cnt)", "from collections import Counter\nn=int(input())\ns_=input()\ns=Couter(s_)\nrgb = s['R'] * s['G'] * s['B']\ncnt=0\nfor i in range(len(s_)):\n for j in range(i+1,len(s_)):\n h=j-i+j\n if h<n:\n if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:\n cnt+=1\n\nprint(rgb-cnt)\n ", "from collections import Counter\nn=int(input())\ns_=input()\ns=Counter(s_)\nrgb = s['R'] * s['G'] * s['B']\ncnt=0\nfor i in range(len(s_)):\n for j in range(i+1,len(s_)):\n h=j-i+j\n if h<n:\n if s_[i]!=s_[j] and s_[h]!=s_[j] and s_[i]!=s_[h]:\n cnt+=1\n\nprint(rgb-cnt)\n "] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s228232611', 's849016207', 's196864200'] | [9328.0, 9464.0, 9492.0] | [2206.0, 24.0, 1882.0] | [284, 280, 281] |
p02714 | u784022244 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['from numba import jit\n\n@jit\ndef main():\n\n N=int(input())\n S=input()\n R=0\n G=0\n B=0\n for i in range(N):\n s=S[i]\n if s=="R":\n R+=1\n elif s=="G":\n G+=1\n else:\n B+=1\n ans=R*G*B\n for i in range(N-2):\n for j in range(i+1, N-1):\n if 0<=j+j-i<N:\n si=S[i]\n sj=S[j]\n sk=S[2*j-i]\n if si!=sj and sj!=sk and sk!=si:\n ans-=1\n print(ans)\n \nif __name__=="__main__":\n main()', 'from numba import njit\n\nN=int(input())\nS=input()\nR=0\nG=0\nB=0\nfor i in range(N):\n s=S[i]\n if s=="R":\n R+=1\n elif s=="G":\n G+=1\n else:\n B+=1\nans=R*G*B\n\n@njit\ndef calc(ans):\n for i in range(N-2):\n for j in range(i+1, N-1):\n if 0<=j+j-i<N:\n si=S[i]\n sj=S[j]\n sk=S[2*j-i]\n if si!=sj and sj!=sk and sk!=si:\n ans-=1\n return ans\nprint(calc(ans))\n', 'from numba import jit\n\nN=int(input())\nS=input()\nR=0\nG=0\nB=0\nfor i in range(N):\n s=S[i]\n if s=="R":\n R+=1\n elif s=="G":\n G+=1\n else:\n B+=1\nans=R*G*B\n\n@njit\ndef calc(ans):\n for i in range(N-2):\n for j in range(i+1, N-1):\n if 0<=j+j-i<N:\n si=S[i]\n sj=S[j]\n sk=S[2*j-i]\n if si!=sj and sj!=sk and sk!=si:\n ans-=1\n return ans\nprint(calc(ans))\n', 'from numba import jit\n\nN=int(input())\nS=input()\nR=0\nG=0\nB=0\nfor i in range(N):\n s=S[i]\n if s=="R":\n R+=1\n elif s=="G":\n G+=1\n else:\n B+=1\nans=R*G*B\n\n@jit\ndef calc(ans):\n for i in range(N-2):\n for j in range(i+1, N-1):\n if 0<=j+j-i<N:\n si=S[i]\n sj=S[j]\n sk=S[2*j-i]\n if si!=sj and sj!=sk and sk!=si:\n ans-=1\n return ans\nprint(calc(ans))\n', 'from collections import Counter\nN=int(input())\nS=input()\nC=Counter(S)\nnr=C["R"]\nng=C["G"]\nnb=C["B"]\nans=nr*ng*nb\nfor i in range(N-2):\n for j in range(i+1,N-1):\n k=j+j-i\n if k<N:\n if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:\n ans-=1\n\nprint(ans)'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s113244646', 's443289134', 's465215838', 's859343237', 's862759769'] | [117480.0, 113928.0, 91528.0, 113984.0, 9372.0] | [2208.0, 2108.0, 390.0, 2129.0, 1975.0] | [552, 474, 473, 472, 286] |
p02714 | u785573018 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['n = int(input())\nList = list(input())\ncount = 0\nprint(List)\nfor k in range(n - 2):\n for l in range(k + 1, n - 1):\n if List[k] != List[l]:\n for m in range(l + 1, min(2 * l - k, n)):\n if List[k] != List[m] and List[l] != List[m]:\n count += 1\n for m in range(min(2 * l - k + 1, n), n):\n if List[k] != List[m] and List[l] != List[m]:\n count += 1\nprint(count)', 'n = int(input())\nList = list(input())\ncount = List.count("R") * List.count("G") *List.count("B")\nfor w in range(1, n // 3 * 3 + 1):\n for s in range(n - 2 * w):\n if List[s] != List[s + w] and List[s] != List[s + w * 2] and List[s + w] != List[s + w * 2]:\n count -= 1\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s726931512', 's627029650'] | [9128.0, 9208.0] | [2206.0, 1268.0] | [454, 299] |
p02714 | u788608806 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = 0\n\n# for j in range(i+1,N):\n# if S[i-1] != S[j-1]:\n# for k in range(j+1,N+1):\n# if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:\n# cnt += 1\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k = 2*j-i\n if k>j and k<=N:\n if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :\n cnt += 1\n\n\nprint(N-cnt)', '\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = 0\n\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k = 2*j-i\n if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :\n cnt += 1\n\n\nprint(N-cnt)', '\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = 0\n\n# for j in range(i+1,N):\n# if S[i-1] != S[j-1]:\n# for k in range(j+1,N+1):\n# if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:\n# cnt += 1\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k = 2*j-i\n if S[i-1]==S[k-1] or S[j-1]==S[k-1] :\n cnt += 1\n\n\nprint(N**3-cnt)', "\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = S.count('B')*S.count('G')*S.count('R')\n\n# for j in range(i+1,N):\n# if S[i-1] != S[j-1]:\n# for k in range(j+1,N+1):\n# if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:\n# cnt += 1\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k = 2*j-i\n if k>j and k-1<=N:\n if S[i-1]==S[j-1] or S[i-1]==S[k-1] or S[j-1]==S[k-1] :\n cnt -= 1\n\n\nprint(cnt)", "\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = S.count('B')*S.count('G')*S.count('R')\n\n# for j in range(i+1,N):\n# if S[i-1] != S[j-1]:\n# for k in range(j+1,N+1):\n# if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:\n# cnt += 1\nfor i in range(N-2):\n for j in range(i,N-1):\n k = 2*j-i\n if k>j and k<=N:\n if S[i]==S[j] or S[i]==S[k] or S[j]==S[k] :\n cnt -= 1\n\n\nprint(cnt)", '\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = 0\n\n# for j in range(i+1,N):\n# if S[i-1] != S[j-1]:\n# for k in range(j+1,N+1):\n# if S[i-1]!=S[k-1] and S[j-1]!=S[k-1] and j-i!=k-j:\n# cnt += 1\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k = 2*j-i\n if S[i-1]==S[k-1] or S[j-1]==S[k-1] :\n cnt += 1\n\n\nprint(N-cnt)', "\n\nN = int(input())\nS = input()\nS = S[::-1]\n\ncnt = S.count('B')*S.count('G')*S.count('R')\n\nfor i in range(N-2):\n for j in range(i,N-1):\n k = 2*j-i\n if k<=N-1:\n if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k] :\n cnt -= 1\n\n\nprint(cnt)"] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s117573119', 's139234908', 's298215632', 's339925741', 's396292952', 's462926745', 's023627562'] | [9136.0, 9100.0, 9188.0, 9220.0, 9188.0, 9200.0, 9200.0] | [2205.0, 21.0, 20.0, 23.0, 24.0, 23.0, 1882.0] | [476, 220, 428, 513, 497, 425, 271] |
p02714 | u802234211 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = list(map(str, input()))\nf=0\ni_c = j_c = k_c =1\nijk = list()\nfor i in range(N):\n for j in range(N):\n for k in range(N):\n if(k_c>j_c and j_c>i_c):\n if(j_c-i_c!=k_c-j_c):\n ijk.append([i,j,k])\n k_c+=1\n j_c+=1\n k_c = 1\n i_c+=1\n j_c = 1\nS_i = ijk[i][0]\nS_j = ijk[i][1]\nS_k = ijk[i][2]\nfor i in range(len(ijk)):\n if(S[ijk[i][0]]!= S[ijk[i][1]] and\n S[ijk[i][0]]!= S[ijk[i][2]] and\n S[ijk[i][1]]!= S[ijk[i][2]]):\n f+=1\nprint(f)', 'n=int(input())\ns=input()\nr=g=b=0\nfor i in s:\n if i=="R":r+=1\n elif i=="G":g+=1\n else:b+=1\nprint(r,g,b)\n\nans=r*g*b\n\nfor i in range(1,n):\n for j in range(n):\n if j+i+i>=n:break\n if(s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i]):\n ans-=1\nprint(ans)\n', 'n=int(input())\ns=input()\nr=g=b=0\nfor i in s:\n if i=="R":r+=1\n elif i=="G":g+=1\n else:b+=1\nprint(r,g,b)\n\nans=r*g*b\n\nfor i in range(1,n):\n for j in range(1,n):\n if j+i+i>=n:break\n if(s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i]):\n ans-=1\nprint(ans)\n', 'N = int(input())\nS = list(input())\nf=0\nijk = [[i+1,j+1,k+1]for i in range(N) for j in range(N) for k in range(N) \n if(S[i]!=S[j] and\n S[i]!=S[k] and\n S[j]!=S[k])]\n\nfor i in range(len(ijk)):\n if(ijk[i][1]-ijk[i][0] != ijk[i][2]-ijk[i][1]):\n f+=1\nprint(f)', 'n=int(input())\ns=input()\nr=g=b=0\nfor i in s:\n if i=="R":r+=1\n elif i=="G":g+=1\n else:b+=1\nprint(r,g,b)\n\nans=r*g*b\n\nfor i in range(1,n):\n for j in range(n):\n if j+i+i>=n:break\n if not(s[j]==s[j+i] or s[j+i]==s[j+i+i] or s[j]==s[j+i+i]):ans-=1\nprint(ans)', 'N = int(input())\nS = list(input())\nf=0\nijk = [[i+1,j+1,k+1]for i in range(N) for j in range(N) for k in range(N) \n if i<j<k and S[i]!=S[j] and\n S[i]!=S[k] and\n S[j]!=S[k]]\nprint(ijk)\nfor i in range(len(ijk)):\n if(ijk[i][1]-ijk[i][0] != ijk[i][2]-ijk[i][1]):\n f+=1\nprint(f)', 'N = int(input())\nS = list(map(str, input()))\nf=0\ni_c = j_c = k_c =1\nfor i in range(N):\n for j in range(N):\n for k in range(N):\n if(k+1>j+1 and\n j+1>i+1 and\n j-i=k-j and\n S[i]!=S[j] and \n S[i]!=S[k] and\n S[j]!=S[k]):\n f+=1\n \nprint(f)', 'N = int(input())\nS = list(input())\nf=0\nijk = list()\nfor i in range(N):\n for j in range(N):\n for k in range(N):\n if(k>j and j>i):\n if(k == j+(j-i)):\n pass\n elif(i == j-(j-k)):\n pass\n else:\n ijk.append([i+1,j+1,k+1])\n\nfor i in range(len(ijk)):\n if(S[ijk[i][0]]!= S[ijk[i][1]] and\n S[ijk[i][0]]!= S[ijk[i][2]] and\n S[ijk[i][1]]!= S[ijk[i][2]]):\n f+=1\nprint(f)', 'N = int(input())\nS = list(input())\nf=0\nijk = list()\nfor i in range(N):\n for j in range(N):\n for k in range(N):\n if(i<j<k):\n if(S[i]==S[j]):\n pass\n elif(S[i]==S[k]):\n pass\n elif(S[j]==S[k]):\n pass\n else:\n ijk.append([i+1,j+1,k+1])\n\nfor i in range(len(ijk)):\n if(ijk[i][1]-ijk[i][0] == ijk[i][2]-ijk[i][1]):\n pass:\n else:\n f += 1\nprint(f)', 'n=int(input())\ns=input()\nr=g=b=0\nfor i in s:\n if i=="R":r+=1\n elif i=="G":g+=1\n else:b+=1\n\nans=r*g*b\nfor i in range(n):\n for j in range(i+1,n):\n k_ = j+(j-i)\n if(k_ >=n):\n break\n ans -= int(s[i]!= s[j] and s[i] != s[k_] and s[j] != s[k_])\n\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s027097893', 's153526918', 's211742241', 's314292008', 's548554802', 's744807421', 's826607149', 's890866636', 's947502226', 's258806529'] | [403140.0, 9208.0, 9156.0, 317128.0, 9172.0, 305008.0, 8984.0, 406416.0, 9076.0, 9204.0] | [2217.0, 1737.0, 1800.0, 2216.0, 1868.0, 2213.0, 21.0, 2218.0, 22.0, 1783.0] | [547, 268, 270, 302, 262, 309, 342, 500, 525, 269] |
p02714 | u813387707 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['from itertools import product\n\nk = int(input())\ns = input()\n\ntemp_dict = {\n "R": [],\n "G": [],\n "B": [],\n}\nfor i, c in enumerate(s):\n temp_dict[c].append(i)\n\nans = 0\ntemp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))\nfor temp in temp_list:\n temp.sort()\n if temp[0] - temp[1] != temp[1] - temp[2]:\n ans += 1\n\nprint(ans)\n', 'temp_dict = {\n "R": [],\n "G": [],\n "B": [],\n}\nfor i, c in enumerate(s):\n temp_dict[c].append(i)\n\nans = 0\ntemp_list = list(product(temp_dict["R"], temp_dict["G"], temp_dict["B"]))\nfor temp in temp_list:\n temp = sorted(list(temp))\n if temp[0] - temp[1] != temp[1] - temp[2]:\n ans += 1\n\nprint(ans)', 'n = int(input())\ns = input()\n\nr = s.count("R")\ng = s.count("G")\nb = s.count("B")\n\nans = r * g * b\nfor i in range(n - 2):\n for j in range(i + 2, n, 2):\n if s[i] != s[(i + j) >> 1] != s[j] != s[i]:\n ans -= 1\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s760090437', 's984700097', 's815741672'] | [1947000.0, 9124.0, 9104.0] | [2261.0, 20.0, 990.0] | [367, 319, 237] |
p02714 | u815304751 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["N = int(input())\ns = input()\nR = s.count('R')\nG = s.count('G')\nB = s.count('B')\n\ncount = R*G*B\nprint(count)\ncnt = 0\nfor i in range(len(s)):\n for d in range(N):\n j = i + d\n k = j + d\n if k >= N:\n break\n if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:\n count -= 1\nprint(count)", "N = int(input())\ns = input()\nR = s.count('R')\nG = s.count('G')\nB = s.count('B')\n\ncount = R*G*B\ncnt = 0\nfor i in range(len(s)):\n for d in range(N):\n j = i + d\n k = j + d\n if k >= N:\n break\n if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:\n count -= 1\nprint(count)"] | ['Wrong Answer', 'Accepted'] | ['s168953188', 's371544299'] | [9204.0, 9192.0] | [1508.0, 1559.0] | [330, 317] |
p02714 | u819593641 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = list(input())\n\narr = []\nR = len(list(filter(lambda x:x == 'R', s)))\nG = len(list(filter(lambda x:x == 'G', s)))\nB = len(list(filter(lambda x:x == 'B', s)))\ntot = R*G*B\nprint(tot)\n\nfor i in range(n):\n for j in range(i+1, n):\n k = 2*j-i\n if k < n:\n if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):\n tot -= 1\n\nprint(tot)", "n = int(input())\ns = input()\n\narr = []\nR = len(list(filter(lambda x:x == 'R', s)))\nG = len(list(filter(lambda x:x == 'G', s)))\nB = len(list(filter(lambda x:x == 'B', s)))\ntot = R*G*B\n\nfor i in range(n):\n for j in range(i+1, n):\n k = 2*j-i\n if k > n:\n continue\n if (s[i] != s[j]) & (s[i] != s[k]) & (s[j] != s[k]):\n tot -= 1\n\nprint(tot)", "n = int(input())\ns = input()\n\narr = []\nR = len(list(filter(lambda x:x == 'R', s)))\nG = len(list(filter(lambda x:x == 'G', s)))\nB = len(list(filter(lambda x:x == 'B', s)))\ntot = R*G*B\n\nfor i in range(n):\n for j in range(i+1, n):\n k = 2*j-i\n if k >= n:\n continue\n if (s[i] != s[j]) and (s[i] != s[k]) and (s[j] != s[k]):\n tot -= 1\n\nprint(tot)\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s041345207', 's742757255', 's297378929'] | [9228.0, 9208.0, 9128.0] | [2088.0, 24.0, 1787.0] | [361, 355, 361] |
p02714 | u821775079 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N=int(input())\nS=input()\n\nans = S.count("R")*S.count("G")*S.count("B")\n\ntmp=0\n\nfor i in range(N):\n for j in range(i,N):\n if j-i+j < N:\n if S[i]==S[j] and S[j]==S[j-i+j] and S[i]==S[j-i+j]:\n tmp += 1\n\nans = ans - tmp\nprint(ans)', 'N=int(input())\nS=input()\n\nans = S.count("R")*S.count("G")*S.count("B")\n\ntmp=0\n\nfor i in range(N):\n for j in range(i,N):\n if j-i+j < N:\n if S[i]==S[j] and S[j]==S[j-i+j] and S[i]==S[j-i+j]\n tmp += 1\n\nans = ans - tmp\nprint(ans)', 'N=int(input())\nS=input()\n\nans = S.count("R")*S.count("G")*S.count("B")\n\ntmp=0\n\nfor i in range(N):\n for j in range(i,N):\n if j-i+j < N:\n if S[i]!=S[j] and S[j]!=S[j-i+j] and S[i]!=S[j-i+j]:\n tmp += 1\n\nans = ans - tmp\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s361491818', 's690605456', 's995935246'] | [9192.0, 9044.0, 9192.0] | [1852.0, 19.0, 1923.0] | [242, 241, 242] |
p02714 | u823885866 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import sys\nn = int(sys.stdin.readline())\ns = sys.stdin.readline()\nr = []\ng = []\nb = []\ncnt = 0\ni = 0\nwhile i < n:\n if s[i] == "R":\n r.append(i)\n elif s[i] == "G":\n g.append(i)\n else:\n b.append(i)\nfor j in r:\n for k in g:\n for l in b:\n if l - k != k - j:\n cnt += 1\nprint(cnt)', "import sys\n\nrr = lambda: sys.stdin.readline().rstrip()\nrs = lambda: sys.stdin.readline().split()\nri = lambda: int(sys.stdin.readline())\nrm = lambda: map(int, sys.stdin.readline().split())\nrl = lambda: list(map(int, sys.stdin.readline().split()))\n\n\nn = ri()\ns = rr()\nans = s.count('R') * s.count('G') * s.count('B')\nfor i in range(n-2):\n for j in range(i+1, n-1):\n k = j + j - i\n if k < n:\n if s[k] != s[j] and s[j] != s[i] and s[k] != s[i]:\n ans -= 1\nprint(ans)\n\n\n\n\n\n\n"] | ['Time Limit Exceeded', 'Accepted'] | ['s324348759', 's568300998'] | [142968.0, 9208.0] | [2209.0, 1919.0] | [302, 511] |
p02714 | u824295380 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N= int(input())\nS=input()\nr=[]\ng=[]\nb=[]\nfor i in range(N):\n if S[i]=="R":\n r.append(i)\n elif S[i]=="G":\n g.append(i)\n else:\n b.append(i)\nprint(r)\nprint(g)\nprint(b)\nt=0\nfor i in range(len(r)):\n for j in range(len(g)):\n p=0\n for k in range(len(b)):\n if p<3:\n if abs(r[i]-g[j])!=abs(b[k]-g[j]) and abs(r[i]-b[k])!=abs(b[k]-g[j]) and abs(r[i]-g[j])!=abs(b[k]-r[i]):\n t=t+1\n else:\n p+=1\n else:\n t = t + 1\nprint(t)', 'N= int(input())\nS=input()\nr=[]\ng=[]\nb=[]\nA=0\nB=0\nC=0\nfor i in range(N):\n if S[i]=="R":\n r.append(i)\n A+=1\n elif S[i]=="G":\n g.append(i)\n B+=1\n else:\n b.append(i)\n C+=1\nk=0\nfor i in range(N-2):\n for j in range(i+1,N-1):\n t=2*j-i\n if t<N:\n if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :\n k+=1\n print(i,j,t)\nprint(k)\nprint(A*B*C-k)', 'N= int(input())\nS=input()\nr=[]\ng=[]\nb=[]\nA=0\nB=0\nC=0\nfor i in range(N):\n if S[i]=="R":\n r.append(i)\n A+=1\n elif S[i]=="G":\n g.append(i)\n B+=1\n else:\n b.append(i)\n C+=1\nk=0\nfor i in r:\n x=i\n for j in b:\n y=j\n if 2*x-y in b:\n k+=1\n if 2*y-x in b:\n k+=1\n if (x+y)/2 in b:\n k+=1\n\nprint(A*B*C-k)', 'N= int(input())\nS=input()\nr=[]\ng=[]\nb=[]\nA=0\nB=0\nC=0\nfor i in range(N):\n if S[i]=="R":\n r.append(i)\n A+=1\n elif S[i]=="G":\n g.append(i)\n B+=1\n else:\n b.append(i)\n C+=1\nk=0\nfor i in range(N-2):\n for j in range(i+1,N-1):\n t=2*j-i\n if t<N:\n if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :\n k+=1\n\nprint(A*B*C-k)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s163755372', 's732340758', 's829112562', 's572250654'] | [9244.0, 15504.0, 9232.0, 9236.0] | [2205.0, 2225.0, 2205.0, 1934.0] | [561, 436, 408, 399] |
p02714 | u830881690 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = list(map(input().split()))\n\nr_i = [i for i, x in enumerate(s) if x=='R']\ng_i = [i for i, x in enumerate(s) if x=='G']\nb_i = [i for i, x in enumerate(s) if x=='B']\n\nans = 0\n\nfor i in len(r_i):\n for j in len(g_i):\n for k in len(b_i):\n if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:\n ans += 1\n\nprint(ans)", "n = int(input())\ns = list(input())\n\nri = [i for i, x in enumerate(s) if x=='R']\ngi = [i for i, x in enumerate(s) if x=='G']\nbi = [i for i, x in enumerate(s) if x=='B']\n\nans = len(ri) * len(gi) * len(bi)\n\nfor i in range(n):\n for d in range(n):\n j=i+d\n k=i+2*d\n if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:\n ans -= 1\n\nprint(ans)", "n = int(input())\ns = list(map(input().split()))\n\nr_i = [i for i, x in enumerate(s) if x=='R']\ng_i = [i for i, x in enumerate(s) if x=='G']\nb_i = [i for i, x in enumerate(s) if x=='B']\n\nans = 0\n\nfor i in len(r_i):\n for j in len(g_i):\n for k in len(b_i):\n if r_i[i]!=g_i[j] and g_i[j]!=b_i[k] and b_i[k]!=r_i[i]:\n ans += 1\n\nprint(ans)", "n = int(input())\ns = input()\n\nri = [i for i, x in enumerate(s) if x=='R']\ngi = [i for i, x in enumerate(s) if x=='G']\nbi = [i for i, x in enumerate(s) if x=='B']\n\nans = len(ri) * len(gi) * len(bi)\n\nfor i in range(n):\n for d in range(n):\n j=i+d\n k=i+2*d\n if k>=n:\n break\n if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:\n ans -= 1\n\nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s036307837', 's623719020', 's670448907', 's848392688'] | [9224.0, 9216.0, 9124.0, 9204.0] | [21.0, 20.0, 21.0, 1621.0] | [368, 361, 368, 390] |
p02714 | u833738197 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['n = int(input())\ns = input()\n\nR=[]\nG=[]\nB=[]\n\nfor i in range(n):\n if s[i] == "R":\n R.append(i)\n elif s[i] == "G":\n G.append(i)\n else:\n B.append(i)\n\nans = len(R)*len(G)*len(B)\nfor i in range(n-2):\n for j in range(i+1,n-1):\n k = 2*j-i\n if k<n:\n if (s[i]=s[j]) and (s[i]=s[k]) and (s[j]=s[k]):\n ans-=1\nprint(ans)', 'n = int(input())\ns = input()\n\nR=[]\nG=[]\nB=[]\n\nfor i in range(n):\n if s[i] == "R":\n R.append(i)\n elif s[i] == "G":\n G.append(i)\n else:\n B.append(i)\n\nans = len(R)*len(G)*len(B)\nfor i in range(n-2):\n for j in range(i+1,n-1):\n k = 2*j-i\n if k<n:\n if (s[i]==s[j]) and (s[i]==s[k]) and (s[j]==s[k]):\n ans-=1\nprint(ans)', 'n = int(input())\ns = input()\n\nR=[]\nG=[]\nB=[]\n\nfor i in range(n):\n if s[i] == "R":\n R.append(i)\n elif s[i] == "G":\n G.append(i)\n else:\n B.append(i)\n\nans = len(R)*len(G)*len(B)\nfor i in range(n-2):\n for j in range(i+1,n-1):\n k = 2*j-i\n if k<n:\n if (s[i]!=s[j]) and (s[i]!=s[k]) and (s[j]!=s[k]):\n ans-=1\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s049209914', 's194957248', 's893834218'] | [9044.0, 9196.0, 9124.0] | [22.0, 1809.0, 1878.0] | [383, 386, 386] |
p02714 | u841599623 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["N=int(input())\nS=input()\nc = 0\nRGB = 'RGB'\nfor i in range(N-2):\n a = S[i]\n for j in range(i+1,N-1):\n if S[j] != a:\n S_ = S[j+1:]\n d = j - i\n S_ = S_[d: d+1]\n RGB = RGB.strip(a).strip(S[j])\n c += S_.count(RGB)\nprint(c)", "N=int(input())\nS=input()\nA=S.count('R')*S.count('G')*S.count('B')\nfor i in range(N-2):\n for j in range(i+1,N-1):\n if 2*j-i < N:\n if S[i] != S[j] and S[i] != S[2*j-i] and S[j] != S[2*j-i]:\n A-=1\nprint(A)"] | ['Wrong Answer', 'Accepted'] | ['s613982443', 's253347257'] | [9144.0, 9100.0] | [2205.0, 1975.0] | [247, 238] |
p02714 | u843318346 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\nr_num = s.count('R')\ng_num = s.count('G')\nb_num = s.count('B')\ntot = r_num*g_num*b_num\nprint(tot)\nfor i in range(n):\n for j in range(i+1,n):\n k = j+(j-i)\n\n if k<n:\n if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:\n tot -= 1\n\nprint(tot)\n", "n = int(input())\ns = input()\nr_num = s.count('R')\ng_num = s.count('G')\nb_num = s.count('B')\ntot = r_num*g_num*b_num\nfor i in range(n):\n for j in range(i+1,n):\n k = j+(j-i)\n\n if k<n:\n if s[i]!=s[j] and s[i]!=s[k] and s[j] != s[k]:\n tot -= 1\n\nprint(tot)\n"] | ['Wrong Answer', 'Accepted'] | ['s004971878', 's420725774'] | [9204.0, 9184.0] | [1994.0, 1922.0] | [306, 295] |
p02714 | u844895214 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['def S(): return stdin.readline().rstrip()\ndef I(): return int(stdin.readline().rstrip())\n\n\nn = I()\ns = S()\n\nans = 0\nfor i in range(n-2):\n for j in range(i+1,n-1):\n if s[i] != s[j]:\n for k in range(j+1,n):\n if s[k] != s[i] and s[k] != s[j]:\n if j-i != k-j:\n ans += 1\n\nprint(ans)', "from numba import njit\nfrom sys import stdin\ndef S(): return stdin.readline().rstrip()\ndef I(): return int(stdin.readline().rstrip())\n \n@njit\ndef main():\n n = I()\n s = list(S())\n ans = 0\n for i in range(n-2):\n color = {s[i]}\n for j in range(i+1,n-1):\n if not s[j] in color:\n color.add(s[j])\n for k in range(j+1,n):\n if not s[k] in color:\n if k-j != j-i:\n ans += 1\n color = {s[i]}\n \n print(ans)\n\nif __name__ == '__main__':\n main()", "from sys import stdin\ndef S(): return stdin.readline().rstrip()\ndef I(): return int(stdin.readline().rstrip())\n \nn = I()\ns = list(S())\n\nr = s.count('R')\ng = s.count('G')\nb = s.count('B')\n \nans = r*g*b\nfor i in range(n-1):\n for j in range(1,n):\n if i-j<0 or n<=i+j:\n break\n else:\n if s[i-j]!=s[i] and s[i]!=s[i+j] and s[i-j]!=s[i+j]:\n ans-=1\n \nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s068211977', 's126821712', 's745976053'] | [9112.0, 106756.0, 9092.0] | [23.0, 486.0, 1538.0] | [355, 589, 407] |
p02714 | u851125702 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import collections\nN=int(input())\nS=input()\nlis=list(S)\nC= collections.Counter(lis)\ncount=list(C.values())\nc=0\nfor i in range(N):\n print(i)\n for j in range(i,(N+i-1) // 2+1):\n if(lis[i]!=lis[j]):\n if(lis[j]!=lis[2*j-i]):\n if(lis[i]!=lis[2*j-i]):\n c+=1\nif(len(count)==3):\n print(count[0]*count[1]*count[2]-c)\nelse:\n print(0)\n', 'import collections\nN=int(input())\nS=input()\nlis=list(S)\nC= collections.Counter(lis)\ncount=list(C.values())\nc=0\nfor i in range(N):\n print(i)\n for j in range(i,(N+i-1) // 2+1):\n if(lis[i]!=lis[j]):\n if(lis[j]!=lis[2*j-i]):\n if(lis[i]!=lis[2*j-i]):\n c+=1\nprint(count[0]*count[1]*count[2]-c)\n', 'import collections\nN=int(input())\nS=input()\nlis=list(S)\nC= collections.Counter(lis)\ncount=list(C.values())\nc=0\nfor i in range(N):\n for j in range(i,(N+i-1) // 2+1):\n if(lis[i]!=lis[j]):\n if(lis[j]!=lis[2*j-i]):\n if(lis[i]!=lis[2*j-i]):\n c+=1\nif(len(count)==3):\n print(count[0]*count[1]*count[2]-c)\nelse:\n print(0)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s177252459', 's953128885', 's727224096'] | [9644.0, 9648.0, 9468.0] | [1054.0, 1168.0, 1014.0] | [388, 346, 375] |
p02714 | u852124489 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = input()\nr = 0\ng = 0\nb = 0\nk = 0\nfor i in range(N):\n if S[i] == "R":\n r += 1\n elif S[i] == "G":\n g += 1\n else:\n b += 1\n\nsum = r * g * b\nfor i in range(0, N-2):\n for j in range(i+1,N-1):\n if 2*j - i < N:\n k = 2*j - i\n if S[j] == S[i] and S[k] == S[j]:\n sum -= 1\n\nprint(sum)\n', 'N = int(input())\nS = "A"\nS += input()\nprint(S)\nr = 0\ng = 0\nb = 0\nk = 0\nfor i in range(1, N+1):\n if S[i] == "R":\n r += 1\n elif S[i] == "G":\n g += 1\n else:\n b += 1\n\nsum = r * g * b\nfor i in range(1, N-1):\n for j in range(i+1,N):\n if 2*j - i <= N:\n k = 2*j - i\n if S[j] != S[i] and S[k] != S[j] and S[i] != S[k]:\n sum -= 1\n\nprint(sum)\n', 'N = int(input())\nS = input()\n\n\n# for j in range(i+1,N-1):\n# if S[i] != S[j]:\n# for k in range(j+1,N):\n\n# if S[j] != S[k] and S[k] != S[i]:\n# count += 1\n#print(count)\n\nr = list()\ng = list()\nb = list()\n\nfor i in range(N):\n if S[i] == "R":\n r.append(i)\n elif S[i] == "G":\n g.append(i)\n else:\n b.append(i)\n\nbb = len(b)\ngg = len(g)\nrr = len(r)\n\nsum = len(r) * len(g) * len(b)\nfor i in range(bb-1):\n for j in range(i+1,gg):\n if 2*j - i <= 0:\n k = 2*j - i\n if j - i == k - j:\n sum -=1\n #if abs(abs(g[j] - b[i]) - b[i]) in r:\n# if (abs(b[i] - abs(g[j] - b[i])) in r) or (b[i] + abs(g[j] - b[i]) in r):\n\n #elif abs(abs(g[j] - b[i]) - g[j]) in r:\n# elif (abs(g[j] - abs(g[j] - b[i])) in r) or (g[j] + abs(g[j] - b[i]) in r):\n\n# elif (abs(r[j] - abs(r[j] - b[i])) in g) or (r[j] + abs(r[j] - b[i]) in g):\n\n# for k in range(rr):\n# if abs(r[k] - g[j]) == abs(g[j] - b[i]) or abs(g[j] - b[i]) == abs(b[i] - r[k]) or abs(b[i] - r[k]) == abs(r[k] - g[j]):\n# count += 1\nprint(sum)\n', 'N = int(input())\nS = input()\n\n\n# for j in range(i+1,N-1):\n# if S[i] != S[j]:\n# for k in range(j+1,N):\n\n# if S[j] != S[k] and S[k] != S[i]:\n# count += 1\n#print(count)\n\nr = list()\ng = list()\nb = list()\n\nfor i in range(N):\n if S[i] == "R":\n r.append(i)\n elif S[i] == "G":\n g.append(i)\n else:\n b.append(i)\n\nbb = len(b)\ngg = len(g)\nrr = len(r)\n\nsum = len(r) * len(g) * len(b)\nfor i in range(bb-1):\n for j in range(i+1,gg):\n if 2*j - i <= 0:\n k = 2*j - i\n if i - j == k - j:\n sum -=1\n #if abs(abs(g[j] - b[i]) - b[i]) in r:\n# if (abs(b[i] - abs(g[j] - b[i])) in r) or (b[i] + abs(g[j] - b[i]) in r):\n\n #elif abs(abs(g[j] - b[i]) - g[j]) in r:\n# elif (abs(g[j] - abs(g[j] - b[i])) in r) or (g[j] + abs(g[j] - b[i]) in r):\n\n# elif (abs(r[j] - abs(r[j] - b[i])) in g) or (r[j] + abs(r[j] - b[i]) in g):\n\n# for k in range(rr):\n# if abs(r[k] - g[j]) == abs(g[j] - b[i]) or abs(g[j] - b[i]) == abs(b[i] - r[k]) or abs(b[i] - r[k]) == abs(r[k] - g[j]):\n# count += 1\nprint(sum)\n', 'N = int(input())\nS = "A"\nS += input()\nprint(S)\nr = 0\ng = 0\nb = 0\nk = 0\nfor i in range(1, N+1):\n if S[i] == "R":\n r += 1\n elif S[i] == "G":\n g += 1\n else:\n b += 1\n\nsum = r * g * b\nfor i in range(1, N-1):\n for j in range(i+1,N):\n if 2*j - i <= N:\n k = 2*j - i\n if S[j] == S[i] and S[k] == S[j] and S[i] == S[k]:\n sum -= 1\n\nprint(sum)\n', 'N = int(input())\nS = "A"\nS += input()\nr = 0\ng = 0\nb = 0\nk = 0\nfor i in range(1, N+1):\n if S[i] == "R":\n r += 1\n elif S[i] == "G":\n g += 1\n else:\n b += 1\n\nsum = r * g * b\nfor i in range(1, N-1):\n for j in range(i+1,N):\n k = 2*j - i\n if k <= N:\n if S[j] != S[i] and S[k] != S[j] and S[i] != S[k]:\n sum -= 1\n\nprint(sum)\n'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s176303514', 's243060832', 's256445327', 's582244033', 's622150314', 's042088247'] | [9192.0, 9208.0, 9168.0, 9224.0, 9220.0, 9200.0] | [2205.0, 2080.0, 22.0, 21.0, 2206.0, 1871.0] | [362, 409, 1278, 1278, 401, 390] |
p02714 | u857293613 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\nr = []\ng = []\nb = []\nfor i in range(n):\n if s[i] == 'R':\n r.append(i)\n elif s[i] == 'G':\n g.append(i)\n else:\n b.append(i)\nans = len(r)*len(g)*len(b)\ndef func(a,b,c):\n ans = 0\n for i in a:\n for k in [num1 for num1 in b if num1 > i+1]:\n if (k + i) // 2 in j:\n ans -= 1\n return ans\nprint(ans + func(r,g,b) + func(r,b,g) + func(g,r,b) + func(g,b,r) + func(b,g,r) + func(b,r,g))", "n = int(input())\ns = input()\nans = s.count('R') * s.count('G') * s.count('B')\nfor i in range(n-2):\n for j in range(i+1, n-1):\n if 2*j - i >= n:\n break\n elif s[i] != s[j] and s[j] != s[(2*j-i)] and s[(2*j-i)] != s[i]:\n ans -= 1\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s859863489', 's593678082'] | [9240.0, 9176.0] | [21.0, 1496.0] | [478, 276] |
p02714 | u864069774 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = input()\nR = S.count("R")\nG = S.count("G")\nB = S.count("B")\n\nRGB = [R,G,B]\nRGB.sort()\nans = min(RGB) * (max(RGB)+1) * (RGB[1]-1)\nprint(ans)\n', "N = int(input())\nS = input()\nR = set()\nG = set()\nB = set()\nfor i in range(N):\n if S[i] == 'R':\n R.add(i)\n elif S[i] == 'G':\n G.add(i)\n else:\n B.add(i)\n\n\nx = 0\nfor i in R:\n for j in G:\n if (i - j) % 2 == 0 and (i + j) // 2 in B:\n x -= 1\n if 2 * j - i in B:\n x -= 1\n if 2 * i - j in B:\n x -= 1\n # print(i,j,x)\nx += len(R) * len(B) * len(G)\nprint(x)\n"] | ['Wrong Answer', 'Accepted'] | ['s679051672', 's229843220'] | [9052.0, 9380.0] | [21.0, 708.0] | [174, 401] |
p02714 | u864273141 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['ans=0\nn=int(input())\nk=str(input())\nr=k.count("R")\nb=k.count("B")\ng=k.count("G")\nans+=r*b*g\n \nfor i in range(n-2):\n ii=k[i]\n for j in range(i+1,(n-i)//2):\n jj=k[j]\n l=j+(j-i)\n #print(l)\n if jj!=ii and l<n:\n #print(i,j)\n ll=k[l]\n if ii!=ll and jj!=ll:\n ans-=1\n #print(i,j,l)\nprint(ans)', 'ans=0\nn=int(input())\nk=str(input())\nr=k.count("R")\nb=k.count("B")\ng=k.count("G")\nans+=r*b*g\n \nfor i in range(n-2):\n ii=k[i]\n for j in range(i+1,(n-i)//2+1+i):\n jj=k[j]\n l=j+(j-i)\n #print(l)\n if jj!=ii and l<n:\n #print(i,j)\n ll=k[l]\n if ii!=ll and jj!=ll:\n ans-=1\n #print(i,j,l)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s543622958', 's580107319'] | [9208.0, 9212.0] | [476.0, 1269.0] | [332, 336] |
p02714 | u868339437 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['n = int(input())\ns = input()\n\ncount = 0\n\nfor i in range(n-3):\n for j in range(i+1, n-2):\n if s[i] == s[j]:\n continue\n for k in range(j+1, n-1):\n if s[i] == s[k] or s[j] == s[k]:\n continue\n else:\n if j - i == k - j:\n continue\n else:\n count += 1\n\nprint(count)\n', 'n = int(input())\ns = input()\n\nnr = s.count("R")\nng = s.count("G")\nnb = s.count("B")\n\ncount = nr * ng * nb\n\nfor i in range(n-3):\n for j in range(i+1, (n+i+1)//2):\n if s[i] == s[j]:continue\n else:\n k = 2*j - i \n if s[i] == s[k]:continue\n if s[j] == s[k]:continue\n count -= 1\n\nprint(count)\n', 'n = int(input())\ns = input()\n\nnr = s.count("R")\nng = s.count("G")\nnb = s.count("B")\n\ncount = nr * ng * nb\n\nfor i in range(n-3):\n for j in range(i+1, n-1):\n if s[i] == s[j]:continue\n else:\n k = 2*j - i \n if k > n - 1:continue\n if s[i] == s[k]:continue\n if s[j] == s[k]:continue\n count -= 1\n\nprint(count)\n', 'n = int(input())\ns = input()\n\nnr = s.count("R")\nng = s.count("G")\nnb = s.count("B")\n\ncount = nr * ng * nb\n\nfor i in range(n-2):\n for j in range(i+1, (n+i+1)//2):\n if s[i] == s[j]:continue\n else:\n k = 2*j - i \n if s[i] == s[k]:continue\n if s[j] == s[k]:continue\n count -= 1\n\nprint(count)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s312008262', 's776034904', 's993002780', 's700510354'] | [9124.0, 9200.0, 9152.0, 9196.0] | [2205.0, 1117.0, 2108.0, 1117.0] | [391, 363, 390, 363] |
p02714 | u871934301 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N=int(input())\nS=input()\nR=[]\nG=[]\nB=[]\nans=0\nx=0\na=0\nb=0\nc=0\nfor i in S:\n if i=="R":\n R.append(x)\n if i=="G":\n G.append(x)\n if i=="B":\n B.append(x)\n x+=1\nfor j in R:\n for k in G:\n if 2*k-j in B:\n B.pop(B.index(2*k-j))\n a+=1\n if 2*j-k in B:\n B.pop(B.index(2*j-k)) \n b+=1\n if (j+k)/2 in B:\n B.pop(B.index((j+k)/2))\n c+=1\n count+=len(B)\n if a!=0:\n B.append(2*k-j)\n a=0\n if b!=0:\n B.append(2*j-k)\n b=0\n if c!=0:\n B.append((j+k)/2)\n c=0\nprint(ans)', 'N=int(input())\nS=list(input())\nS.insert(0,0)\nR=S.count("R")\nG=S.count("G")\nB=S.count("B")\nans=R*G*B\nfor i in range(1,N-1):\n for j in range(i+1,N):\n k=2*j-i\n if k<N+1 and S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:\n ans-=1\nprint(ans)\n \n\n \n\n\n\n \n\n\n\n\n\n\n\n\n\n \n\n \n\n\n\n\n\n\n\n\n\n \n\n \n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n \n\n\n\n\n\n \n\n\n\n\n\n\n \n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n\n\n \n\n\n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n'] | ['Runtime Error', 'Accepted'] | ['s843381089', 's088330833'] | [9260.0, 9208.0] | [20.0, 1895.0] | [662, 533] |
p02714 | u875541136 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["import itertools\n\nN = int(input())\nS = input()\nout = S.count('R') * S.count('G') * S.count('B')\nfor i in range(1, N):\n for j in range(N-i*2):\n if (S[j], S[j+i], S[j+i*2]) in RGBs:\n out -= 1\nprint(out)", "import itertools\nN = int(input())\nS = input()\nout = S.count('R') * S.count('G') * S.count('B')\n\nRGBs = list(itertools.permutations(['R', 'G', 'B'], 3))\n\nfor i in range(1, N):\n for j in range(N-i*2):\n if (S[j], S[j+i], S[j+i*2]) in RGBs:\n out -= 1\nprint(out)"] | ['Runtime Error', 'Accepted'] | ['s561575215', 's379679828'] | [9200.0, 9092.0] | [22.0, 1619.0] | [209, 266] |
p02714 | u891489344 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['_input = input\n#\'\'\'\nallinputs = iter(input().splitlines())\ninput = lambda : next(allinputs)\n#\'\'\'\n\n\n\n\nN=int(input())\nS=input()\n\nRGB_num=[0]*3\n\nfor c in S:\n\tif c==\'R\':\n\t\tRGB_num[0] += 1\n\telif c==\'G\':\n\t\tRGB_num[1] += 1\n\telse:\n\t\tRGB_num[2] += 1\n\n#print(RGB_num)\njoken2=0\n\nprint(S[0])\nfor i in range(N-2):\n\t#print("i",i,S[i+1])\n\tfor j in range(min(i+1,N-i-2)):\n\t\tif S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:\n\t\t\tjoken2 += 1\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")\n\t\t#else:\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2])\n\njoken1=RGB_num[0]*RGB_num[1]*RGB_num[2]\n\nprint(joken1-joken2)\n\ninput = _input\n', '_input = input\n\'\'\'\nallinputs = iter(input().splitlines())\ninput = lambda : next(allinputs)\n#\'\'\'\n\n\n\n\nN=int(input())\nS=input()\n\nRGB_num=[0]*3\n\nfor c in S:\n\tif c==\'R\':\n\t\tRGB_num[0] += 1\n\telif c==\'G\':\n\t\tRGB_num[1] += 1\n\telse:\n\t\tRGB_num[2] += 1\n\n#print(RGB_num)\njoken2=0\n\nprint(S[0])\nfor i in range(N-2):\n\t#print("i",i,S[i+1])\n\tfor j in range(min(i+1,N-i-2)):\n\t\tif S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:\n\t\t\tjoken2 += 1\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")\n\t\t#else:\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2])\n\njoken1=RGB_num[0]*RGB_num[1]*RGB_num[2]\n\nprint(joken1-joken2)\n\ninput = _input\n\n', '_input = input\n\'\'\'\nallinputs = iter(input().splitlines())\ninput = lambda : next(allinputs)\n#\'\'\'\n\n\n\n\nN=int(input())\nS=input()\n\nRGB_num=[0]*3\n\nfor c in S:\n\tif c==\'R\':\n\t\tRGB_num[0] += 1\n\telif c==\'G\':\n\t\tRGB_num[1] += 1\n\telse:\n\t\tRGB_num[2] += 1\n\n#print(RGB_num)\njoken2=0\n\nprint(S[0])\nfor i in range(N-2):\n\t#print("i",i,S[i+1])\n\tfor j in range(min(i+1,N-i-2)):\n\t\tif S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:\n\t\t\tjoken2 += 1\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")\n\t\t#else:\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2])\n\njoken1=RGB_num[0]*RGB_num[1]*RGB_num[2]\n\nprint(joken1-joken2)\n\ninput = _input\n', '_input = input\n\'\'\'\nallinputs = iter(input().splitlines())\ninput = lambda : next(allinputs)\n#\'\'\'\n\n\n\n\nN=int(input())\nS=input()\n\nRGB_num=[0]*3\n\nfor c in S:\n\tif c==\'R\':\n\t\tRGB_num[0] += 1\n\telif c==\'G\':\n\t\tRGB_num[1] += 1\n\telse:\n\t\tRGB_num[2] += 1\n\n#print(RGB_num)\njoken2=0\n\nfor i in range(N-2):\n\t#print("i",i,S[i+1])\n\tfor j in range(min(i+1,N-i-2)):\n\t\tif S[i+1] != S[i-j] and S[i+1] != S[i+j+2] and S[i-j] != S[i+j+2]:\n\t\t\tjoken2 += 1\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2],"j2")\n\t\t#else:\n\t\t\t#print(i,j,S[i-j]+S[i+1]+S[i+j+2])\n\njoken1=RGB_num[0]*RGB_num[1]*RGB_num[2]\n\nprint(joken1-joken2)\n\ninput = _input\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s056903345', 's528488658', 's909553968', 's588832895'] | [9236.0, 9112.0, 9124.0, 9212.0] | [26.0, 1481.0, 1534.0, 1468.0] | [671, 671, 670, 658] |
p02714 | u902430070 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\nr = 0\ng = 0 \nfor i in range(s):\n if i == 'R':\n r += 1\n elif i == 'G':\n g += 1\n \nc = r*g*(n-r-g)\nfor j in range(1, n):\n for i in range(1, min(j, n - j -1) + 1):\n if s[j] != s[j + i] and s[j] != s[j - i] and s[j - i] != s[j + 1]:\n c -= 1\nprint(c)\n ", "n = int(input())\ns = input()\nr = 0\ng = 0 \nfor i in s:\n if i == 'R':\n r += 1\n elif i == 'G':\n g += 1\n \nc = r*g*(n-r-g)\nfor j in range(1, n-1):\n for i in range(1, min(j, n - j -1) + 1):\n if (s[j] != s[j + i] ) and (s[j] != s[j - i]) and (s[j - i] != s[j + i]):\n c -= 1\nprint(c)"] | ['Runtime Error', 'Accepted'] | ['s947633470', 's674826308'] | [9144.0, 9104.0] | [21.0, 1142.0] | [294, 293] |
p02714 | u909991537 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["import sys\ninput = sys.stdin.readline\nN = int(input())\nS = input()\n\nR = []\nG = []\nB = []\nans = 0\n\nfor i, x in enumerate(S):\n if x == 'R':\n R.append(i)\n elif x == 'G':\n G.append(i)\n else:\n B.append(i)\n\ndef calc(a, b, c):\n lis = sorted([a, b, c])\n if lis[1] * 2 != lis[0] + lis[2]:\n return 1\n else:\n return 0\n \nlis = [calc(r, g, b) for r in R for g in G for b in B]\nprint(sum(lis))", "n = int(input())\ns = input()\n \nr_cnt = s.count('R')\ng_cnt = s.count('G')\nb_cnt = s.count('B')\n \nans = r_cnt * g_cnt * b_cnt\n \nfor i in range(n):\n for d in range(n):\n j = i + d\n k = j + d\n if k >= n:break\n if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:\n ans -= 1\n \nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s363764557', 's046317109'] | [61504.0, 9208.0] | [2207.0, 1398.0] | [407, 320] |
p02714 | u919017918 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["N = int(input())\nS = input()\n\nans = S.count('R')*S.count('G')*S.count('B')\nfor i in range(n-2):\n for j in range(i+1,n-1):\n k = j+1\n if k < n and S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:\n ans -= 1\nprint(ans)", "N = int(input())\nS = input()\n\nans = S.count('R')*S.count('G')*S.count('B')\n\nfor i in range(N-2):\n for j in range(i+1,N-1):\n k = j-i + j\n if k < N and S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:\n ans -= 1\n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s721817247', 's025812933'] | [9188.0, 9204.0] | [22.0, 1975.0] | [225, 247] |
p02714 | u919235786 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n=int(input())\ns=str(input())\nt=len(s)\n\nr=set()\ng=set()\nb=set()\na=0\nfor i in range(n):\n if s[i]=='R':\n r.add(i)\n if s[i]=='G':\n g.add(i)\n if s[i]=='B':\n b.add(i)\nd=len(r)*len(g)*len(b)\nfor ri in r:\n for gi in g:\n if 2ri-gi in b:\n d-=1\n if 2gi-ri in b:\n d-=1\n if (gi+ri)/2 in b:\n d-=1\n\nprint(d)", "n=int(input())\ns=str(input())\nt=len(s)\n\nr=set()\ng=set()\nb=set()\na=0\nfor i in range(n):\n if s[i]=='R':\n r.add(i)\n if s[i]=='G':\n g.add(i)\n if s[i]=='B':\n b.add(i)\nd=len(r)*len(g)*len(b)\nfor ri in r:\n for gi in g:\n if 2*ri-gi in b:\n d-=1\n if 2*gi-ri in b:\n d-=1\n if (gi+ri)/2 in b:\n d-=1\n\nprint(d)"] | ['Runtime Error', 'Accepted'] | ['s123299331', 's723172234'] | [8984.0, 9320.0] | [23.0, 759.0] | [414, 416] |
p02714 | u935016954 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["N = int(input())\nS = list(input())\nans = 0\n\n\ndef main():\n for i in range(N):\n first_s = S[i]\n for j in range(i+1, N):\n if S[j] != first_s:\n second_s = S[j]\n for k in range(j+1, N):\n if (S[k] != first_s) and (S[k] != second_s):\n if k == 2*j-i:\n continue\n ans += 1\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n", "N = int(input())\nS = list(input())\n\nr, g, b = 0, 0, 0\nans = 0\nfor i in range(N):\n if S[i] == 'R':\n r += 1\n elif S[i] == 'G':\n g += 1\n else:\n b += 1\n\nans += r*g*b\n\nfor i in range(N):\n for j in range(i+1, N):\n if 2*j-i < N:\n if (S[i] != S[j]) and (S[j] != S[2*j-i]) and (S[i] != S[2*j-i]):\n ans -= 1\n\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s375261976', 's296809620'] | [9208.0, 9216.0] | [22.0, 1966.0] | [468, 376] |
p02714 | u945181840 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["N = int(input())\nS = input()\nr = []\ng = []\nb = []\nfor idx, i in enumerate(S, 1):\n if i == 'R':\n r.append(idx)\n elif i == 'G':\n g.append(idx)\n else:\n b.append(idx)\n\nb = set(b)\ncnt = len(b) * len(r) * len(g)\nprint(r)\nprint(g)\nfor i in r:\n original = i\n for j in g:\n i = original\n if i > j:\n i, j = j, i\n d = j - i\n if j + d in b:\n cnt -= 1\n if i - d in b:\n cnt -= 1\n if d % 2 == 0 and (i + j) // 2 in b:\n cnt -= 1\nprint(cnt)\n", "N = int(input())\nS = input()\nr = []\ng = []\nb = []\nfor idx, i in enumerate(S, 1):\n if i == 'R':\n r.append(idx)\n elif i == 'G':\n g.append(idx)\n else:\n b.append(idx)\n\nb = set(b)\ncnt = len(b) * len(r) * len(g)\nfor i in r:\n original = i\n for j in g:\n i = original\n if i > j:\n i, j = j, i\n d = j - i\n if j + d in b:\n cnt -= 1\n if i - d in b:\n cnt -= 1\n if d % 2 == 0 and (i + j) // 2 in b:\n cnt -= 1\nprint(cnt)\n"] | ['Wrong Answer', 'Accepted'] | ['s551502837', 's181643645'] | [9240.0, 9316.0] | [771.0, 745.0] | [545, 527] |
p02714 | u954415195 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['n=int(input())\nstr=input()\ncount=str.count("R")*str.count("G")*str.count("B")\ncount0=0\nfor i in range(0,n-2):\n for j in range(i+1,(n+i)/2):\n k=2*j-i\n if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:\n count0=count0+1\nprint(count-count0)', 'n=int(input())\nstr=input()\ncount=str.count("R")*str.count("G")*str.count("B")\ncount0=0\nfor i in range(0,n-2):\n for j in range(i+1,int((n+i-1)/2)+1):\n k=2*j-i\n if str[k]!=str[i] and str[k]!=str[j] and str[i]!=str[j]:\n count0=count0+1\nprint(count-count0)'] | ['Runtime Error', 'Accepted'] | ['s582266384', 's830646987'] | [9104.0, 9188.0] | [22.0, 1187.0] | [271, 280] |
p02714 | u958820283 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['n= int(input())\ns_list= list(input())\ncount=0\nrr,bb,gg=0,0,0\nfor i in range(0,n):\n if s_list[i]=="R":\n rr=rr+1\n elif s_list[i]=="G":\n gg=gg+1\n else:\n bb=bb+1\nsum=rr*gg*bb\n\nfor p in range(0,n-2):\n for q in range(p+1,n-1):\n if s_list[p] == s_list[q]:\n break\n else:\n for r in range(q+1,n):\n if s_list[r]==s_list[p] or s_list[r]==s_list[q] :\n break\n elif r-q==q-p:\n count = count+1\n print(p,q,r)\nprint(sum-count)', 'n= int(input())\ns_list= list(input())\nr_list=[]\ng_list=[]\nb_list=[]\ncount=0\nfor i in range(0,n):\n if s_list[i]=="R":\n r_list.append(i)\n elif s_list[i]=="G":\n g_list.append(i)\n else:\n b_list.append(i)\nprint(r_list)\nprint(b_list)\nprint(g_list)\nfor pp in r_list:\n for qq in g_list:\n count=count+len(b_list)\n if (pp+qq)/2 in b_list:\n count=count-1\n elif 2*pp-qq in b_list:\n count=count-1\n elif 2*qq-pp in b_list:\n count=count-1\nprint(count)', 'n= int(input())\ns_list= list(input())\ncount=0\nrr,bb,gg=0,0,0\nfor i in range(0,n):\n if s_list[i]=="R":\n rr=rr+1\n elif s_list[i]=="G":\n gg=gg+1\n else:\n bb=bb+1\nsum=rr*gg*bb\n\nfor p in range(0,n-2):\n for q in range(p+1,n-1):\n if s_list[p] == s_list[q]:\n continue\n elif 2*q-p<n and s_list[2*q-p]!=s_list[p] and s_list[2*q-p]!=s_list[q]:\n count= count+1\nprint(sum-count)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s695283963', 's842266568', 's614554033'] | [9224.0, 9224.0, 9124.0] | [29.0, 2205.0, 1961.0] | [564, 530, 434] |
p02714 | u964904181 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['\nN = int(input())\nS = input()\n\nidxs = [i for i in range(N)]\n\nris = [i for i, s in enumerate(S) if s == "R"]\ngis = [i for i, s in enumerate(S) if s == "G"]\nbis = [i for i, s in enumerate(S) if s == "B"]\n\nans = 0\nfor ri in ris:\n for gi in gis:\n for bi in bis:\n i, j, k = sorted([ri, gi, bi])\n if k - j != j - i:\n ans += 1\n', '\nN = int(input())\nS = input()\n\nris = [i for i, s in enumerate(S) if s == "R"]\ngis = [i for i, s in enumerate(S) if s == "G"]\nbis = [i for i, s in enumerate(S) if s == "B"]\n\nall = len(ris) * len(gis) * len(bis)\n\ncnt = 0\nfor i in range(N):\n for j in range(i+1, N):\n k = 2*j - i\n if 0 <= k < N:\n if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:\n cnt += 1\n\nans = all - cnt\n\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s749022322', 's038637276'] | [9216.0, 9176.0] | [2206.0, 1872.0] | [367, 427] |
p02714 | u970267139 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\n\nr = s.count('R')\ng = s.count('G')\nb = s.count('B')\n\nans = r * g * b\n\nfor i in range(n):\n for d in range(1, n):\n j = i + d\n k = j + d\n if k > n:\n break\n if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:\n ans -= 1\n\nprint(ans)", "n = int(input())\ns = input()\n\nr = s.count('R')\ng = s.count('G')\nb = s.count('B')\n\nans = r * g * b\n\nfor i in range(n):\n for d in range(1, n):\n j = i + d\n k = j + d\n if k >= n:\n break\n if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:\n ans -= 1\n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s236970270', 's009428418'] | [8988.0, 9224.0] | [27.0, 1378.0] | [307, 308] |
p02714 | u970809473 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ["n = int(input())\ns = input()\nr = []\ng = []\nb = []\nfor i in range(n):\n if s[i] == 'R':\n r.append(i)\n elif s[i] == 'G':\n g.append(i)\n else:\n b.append(i)\nres = 0\nfor i in range(len(r)):\n for j in range(len(b)):\n if (i + j) / 2 in g:\n res += len(g) - 1\n else:\n res += len(g)\nprint(res)", "n=int(input())\ns=input()\nR=[]\nG={}\nB=[]\nfor i in range(n):\n if s[i]=='R':\n R.append(i+1)\n elif s[i]=='G':\n G[i+1]=G.get(i+1,0)+1\n else:\n B.append(i+1)\nres=len(R)*len(G)*len(B)\nfor i in R:\n for j in B:\n if ((i+j)%2==0 and G.get((i+j)//2,0)==1):\n res-=1\n if G.get(2*max(i,j)-min(i,j),0)==1:\n res-=1\n if G.get(2*min(i,j)-max(i,j),0)==1:\n res-=1\nprint(res)"] | ['Wrong Answer', 'Accepted'] | ['s364301315', 's088078626'] | [9204.0, 9164.0] | [2205.0, 1959.0] | [310, 389] |
p02714 | u972591645 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['from collections import Counter\nn = int(input())\ns = input()\n\nc = Counter(list(s))\nans = 1\nfor i in list(c.values):\n ans *= i\nfor i in range(n-2):\n for j in range(i+1, n-1):\n k = j + (j-i)\n if k >= n:\n break\n if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:\n ans -= 1\nprint(ans)', "n = int(input())\ns = input()\n\nans = s.count('R') * s.count('G') * s.count('B')\n\nfor i in range(n-2):\n for j in range(i+1, n-1):\n k = 2*j-i\n if k < n:\n if s[k] != s[i] and s[k] != s[j] and s[i] != s[j]:\n ans -= 1\n else:\n break\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s237416104', 's363250420'] | [9480.0, 9080.0] | [29.0, 1260.0] | [329, 297] |
p02714 | u977193988 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import sys\nfrom collections import Counter\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nsys.setrecursionlimit(20000000)\n\nMOD = 10 ** 9 + 7\nINF = float("inf")\n\n\ndef main():\n N = int(input())\n S = input()\n C = Counter(S)\n r = C.get("R")\n g = C.get("G")\n b = C.get("B")\n answer = r * g * b\n for left in range(N):\n for mid in range(left + 1, N):\n right = mid * 2 - left\n if right < N:\n if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:\n answer = -1\n print(answer)\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\nfrom collections import Counter\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nsys.setrecursionlimit(20000000)\n\nMOD = 10 ** 9 + 7\nINF = float("inf")\n\n\ndef main():\n N = int(input())\n S = input()\n C = Counter(S)\n r = C.get("R",0)\n g = C.get("G",0)\n b = C.get("B",0)\n answer = r * g * b\n for left in range(N):\n for mid in range(left + 1, N):\n right = mid * 2 - left\n if right < N:\n if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:\n answer -= 1\n print(answer)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s361137134', 's897155679'] | [9264.0, 9400.0] | [1083.0, 1109.0] | [621, 627] |
p02714 | u979823197 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['from numba import jit\n\nn=int(input())\ns=input()\nR=[]\nG=[]\nB=[]\n\n@jit\ndef f():\n for i in range(n):\n if s[i]=="R":\n R.append(i)\n elif s[i]=="G":\n G.append(i)\n else:\n B.append(i)\n r=len(R)\n g=len(G)\n b=len(B)\n if r==0 or g==0 or b==0:\n return 0\n else:\n ans=r*g*b\n m=0\n for j in range(1,n-1):\n for k in range(1,min(j,n-1-j)+1):\n lt=s[j-k]\n md=s[j]\n rt=s[j+k]\n if lt!=md and md!=rt and rt!=lt:\n m+=1\n return ans-m\nprint(f())', 'n=int(input())\ns=input()\nR=[]\nG=[]\nB=[]\ndef f():\n for i in range(n):\n if s[i]=="R":\n R.append(i)\n elif s[i]=="G":\n G.append(i)\n else:\n B.append(i)\n r=len(R)\n g=len(G)\n b=len(B)\n if r==0 or g==0 or b==0:\n return 0\n else:\n ans=r*g*b\n m=0\n for j in range(1,n-1):\n for k in range(1,min(j,n-1-j)+1):\n lt=s[j-k]\n md=s[j]\n rt=s[j+k]\n if lt!=md and md!=rt and rt!=lt:\n m+=1\n return ans-m\nprint(f())'] | ['Time Limit Exceeded', 'Accepted'] | ['s273928622', 's599157476'] | [120140.0, 9192.0] | [2209.0, 701.0] | [506, 477] |
p02714 | u984276646 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['N = int(input())\nS = input()\nD = {"R": [], "G": [], "B": []}\nfor i in range(N):\n D[S[i]].append(i)\nprint(D)\np = 1\nfor i in D:\n p *= len(D[i])\ncnt = 0\nfor i in range(N):\n for j in range(i+1, N):\n if 2 * j - i < N:\n if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:\n cnt += 1\nprint(p-cnt)', 'N = int(input())\nS = input()\nD = {"R": [], "G": [], "B": []}\nfor i in range(N):\n D[S[i]].append(i)\np = 1\nfor i in D:\n p *= len(D[i])\ncnt = 0\nfor i in range(N):\n for j in range(i+1, N):\n if 2 * j - i < N:\n if S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i]:\n cnt += 1\nprint(p-cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s699289652', 's612969745'] | [9260.0, 9260.0] | [1958.0, 1963.0] | [313, 305] |
p02714 | u999750647 | 2,000 | 1,048,576 | We have a string S of length N consisting of `R`, `G`, and `B`. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: * S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. * j - i \neq k - j. | ['import math\nfrom functools import reduce\n\nn = int(input())\nans = 0\n\ndef gcd(*numbers):\n return reduce(math.gcd, numbers)\n\nfor a in range(1,n+1):\n for b in range(1,n+1):\n for c in range(1,n+1):\n ans += gcd(a,b,c)\nprint(ans)', "n = int(input())\ns = input()\ncount = 0\n\nfullcount= s.count('R')*s.count('G')*s.count('B')\n\nfor i in range(n-2):\n for j in range(i+1,n):\n k = 2*j-i\n if k > (n-1):\n break\n if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:\n count += 1\nans = fullcount - count\nprint(ans)"] | ['Wrong Answer', 'Accepted'] | ['s795871057', 's762866801'] | [9476.0, 9200.0] | [2206.0, 1371.0] | [246, 313] |
p02715 | u034128150 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N, K = map(int, input().split())\nmod = 10 ** 9 + 7\n\ns = 0\ntmp = 1\nfor _ in range(N):\n tmp *= K\n tmp %= mod\ns = tmp\nfor i in range(K+1):\n baisuu = K % i\n tmp = 1\n for _ in range(N):\n tmp *= baisuu\n tmp %= mod\n s += tmp * (i - 1)\n\nprint(s)', 'N, K = map(int, input().split())\nmod = 10 ** 9 + 7\n\ns = 0\ntmp = 1\nfor _ in range(N)\n tmp *= K\n tmp %= mod\ns = tmp\nfor i in range(K+1):\n baisuu = K % i\n tmp = 1\n for _ in range(N)\n tmp *= baisuu\n tmp %= mod\n s += tmp * (i - 1)\n\nprint(s)', 'N, K = map(int, input().split())\nmod = 10 ** 9 + 7\n\ns = 0\ntmp = 1\nfor _ in range(N):\n tmp *= K\n tmp %= mod\ns = tmp\nfor i in range(2, K+1):\n baisuu = K % i\n tmp = 1\n for _ in range(N):\n tmp *= baisuu\n tmp %= mod\n s += tmp * (i - 1)\n\nprint(s)', 'from functools import lru_cache\n\n\nmod = 10 ** 9 + 7\nN, K = map(int, input().split())\n\n@lru_cache\ndef gcd1_tuples(k):\n if k == 1:\n return 1\n tmp = pow(k, N, mod)\n for j in range(2, k+1):\n tmp -= gcd1_tuples(k//j)\n tmp %= mod\n return tmp\n\ns = 0\nfor i in range(1, K+1):\n s += gcd1_tuples(K//i) * i\n s %= mod\n\nprint(s)\n\n\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s265307634', 's424234972', 's734824585', 's851885030'] | [9192.0, 9028.0, 9180.0, 9548.0] | [40.0, 22.0, 2205.0, 1829.0] | [269, 267, 272, 356] |
p02715 | u059210959 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['# encoding:utf-8\nimport copy\nimport random\nimport bisect \nimport fractions \nimport math\nimport sys\nimport collections\n\nmod = 10**9+7\nsys.setrecursionlimit(mod) \n\nd = collections.deque()\ndef LI(): return list(map(int, sys.stdin.readline().split()))\n\nN, K = LI()\n\n\n\n\nx_cnt = [0 for i in range(K + 1)]\nfor x in range(N, 0, -1):\n # print(x)\n tmp = pow(K // x, N, mod)\n for x_n in range(x + x, N+1, x):\n tmp -= x_cnt[x_n]\n x_cnt[x] = tmp % mod\n\nans = 0\nfor i in range(1,K+1):\n ans += i * x_cnt[i]\n ans %= mod\nprint(ans)\n\n\n \n\n', '# encoding:utf-8\nimport copy\nimport random\nimport bisect \nimport fractions \nimport math\nimport sys\nimport collections\n\nmod = 10**9+7\nsys.setrecursionlimit(mod) \n\nd = collections.deque()\ndef LI(): return list(map(int, sys.stdin.readline().split()))\n\nN, K = LI()\n\n\n\n\nx_cnt = [0] * (K + 1)\nfor x in range(K, 0, -1):\n # print(x)\n tmp = pow(K // x, N, mod)\n for j in range(x + x, K+1, x):\n tmp -= x_cnt[j]\n x_cnt[x] = tmp\n\nans = 0\nfor i in range(1,K+1):\n ans += i * x_cnt[i]\n ans %= mod\nprint(ans)\n\n\n \n\n'] | ['Runtime Error', 'Accepted'] | ['s112016325', 's313754713'] | [13152.0, 13144.0] | [344.0, 346.0] | [811, 789] |
p02715 | u067983636 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import bisect\nimport copy\nimport heapq\nimport sys\nimport itertools\nimport queue\ninput = sys.stdin.readline\nsys.setrecursionlimit(100000)\nmod = 10 ** 9 + 7\n\ndef read_values(): return map(int, input().split())\ndef read_index(): return map(lambda x: int(x) - 1, input().split())\ndef read_list(): return list(read_values())\ndef read_lists(N): return [read_list() for n in range(N)]\n\n\nclass V:\n def __init__(self, f, v=None):\n self.f = f\n self.v = v\n \n def __str__(self):\n return str(self.v)\n \n def ud(self, n):\n if n is None:\n return\n\n if self.v is None:\n self.v = n\n return\n self.v = self.f(self.v, n) \n\n\ndef main():\n N, K = read_values()\n C = [0] * (K + 1)\n\n for k in range(K, 0, -1):\n M = K // k\n C[k] = pow(M, N, mod)\n for r in range(2 * k, K, k):\n C[k] -= C[r]\n C[k] %= mod\n print(sum(i * k for i, k in enumerate(C)) % mod)\n\n\nif __name__ == "__main__":\n main()\n', 'import bisect\nimport copy\nimport heapq\nimport sys\nimport itertools\nimport queue\ninput = sys.stdin.readline\nsys.setrecursionlimit(100000)\nmod = 10 ** 9 + 7\n\ndef read_values(): return map(int, input().split())\ndef read_index(): return map(lambda x: int(x) - 1, input().split())\ndef read_list(): return list(read_values())\ndef read_lists(N): return [read_list() for n in range(N)]\n\n\nclass V:\n def __init__(self, f, v=None):\n self.f = f\n self.v = v\n \n def __str__(self):\n return str(self.v)\n \n def ud(self, n):\n if n is None:\n return\n\n if self.v is None:\n self.v = n\n return\n self.v = self.f(self.v, n) \n\n\ndef main():\n N, K = read_values()\n C = [0] * (K + 1)\n\n for M in range(K, 1, -1):\n c = K // M\n C[M] = pow(c, N, mod)\n for r in range(2 * M, K + 1, M):\n C[M] -= C[r]\n C[M] %= mod\n\n C[1] = pow(K, N, mod) - sum(C) % mod\n C[1] %= mod\n print(sum(i * k for i, k in enumerate(C)) % mod) \n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s693825740', 's986266612'] | [11916.0, 11832.0] | [349.0, 325.0] | [1004, 1067] |
p02715 | u078932560 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = map(int, input().split())\nmod = MOD = 10**9 + 7\n\nG = [0] + [pow(k//i, n, mod) for i in range(1,k+1)]\nfor i in range(k, 0, -1):\n for j in range(2, k//i+1):\n G[i] -= G[j*i]\nprint(G)\nprint(sum([i*f for i,f in enumerate(G)]) % mod)', 'n, k = map(int, input().split())\nmod = MOD = 10**9 + 7\n\nG = [0] + [pow(k//i, n, mod) for i in range(1,k+1)]\nfor i in range(k, 0, -1):\n for j in range(2, k//i+1):\n G[i] -= G[j*i]\n\nprint(sum([i*f for i,f in enumerate(G)]) % mod)'] | ['Wrong Answer', 'Accepted'] | ['s808438686', 's729396645'] | [16044.0, 15172.0] | [381.0, 350.0] | [238, 230] |
p02715 | u102461423 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nimport numpy as np\n\nMOD = 10**9 + 7\nN, K = map(int, read().split())\n\nis_prime = np.zeros(K + 1, np.bool)\nis_prime[2] = 1\nis_prime[3::2] = 1\nfor p in range(3, K + 1, 2):\n if p * p >= K:\n break\n if is_prime[p]:\n is_prime[p * p:: p + p] = 0\nprimes = np.where(is_prime)[0]\n\n\nA = [0] * (K + 1)\nfor d in range(1, K + 1):\n A[d] = pow(K // d, N, MOD)\n\nfor p in primes.tolist():\n for i in range(K // p + 1):\n A[i] -= A[i * p]\n\nanswer = sum(i * x for i, x in enumerate(A))\nprint(answer % MOD)\n', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nimport numpy as np\n\nMOD = 10**9 + 7\nN, K = map(int, read().split())\n\nis_prime = np.zeros(K + 10, np.bool)\nis_prime[2] = 1\nis_prime[3::2] = 1\nfor p in range(3, K + 10, 2):\n if p * p >= K:\n break\n if is_prime[p]:\n is_prime[p * p:: p + p] = 0\nprimes = np.where(is_prime)[0]\n\n\nA = [0] * (K + 1)\nfor d in range(1, K + 1):\n A[d] = pow(K // d, N, MOD)\n\nfor p in primes.tolist():\n for i in range(K // p + 1):\n A[i] -= A[i * p]\n\nanswer = sum(i * x for i, x in enumerate(A))\nprint(answer % MOD)\n', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nimport numpy as np\n\nMOD = 10**9 + 7\nN, K = map(int, read().split())\n\nis_prime = np.zeros(K + 1, np.bool)\nis_prime[2] = 1\nis_prime[3::2] = 1\nfor p in range(3, K + 1, 2):\n if p * p >= K:\n break\n if is_prime[p]:\n is_prime[p * p:: p + p] = 0\nprimes = np.where(is_prime)[0]\n\n\nA = [0] * (K + 1)\nfor d in range(1, K + 1):\n A[d] = pow(K // d, N, MOD)\n\nfor p in primes.tolist():\n for i in range(N // p + 1):\n A[i] -= A[i * p]\n\nanswer = sum(i * x for i, x in enumerate(A))\nprint(answer % MOD)\n', 'MOD = 10**9 + 7\ne, N = map(int, input().split())\n\ndef phi_table(N):\n phi = list(range(N + 1))\n for p in range(2, N + 1):\n if phi[p] == p:\n for n in range(N // p, 0, -1):\n phi[p * n] -= phi[n]\n return phi\n\n\nL = int(N ** .66)\nH = int(N // (L + 1))\nphi = phi_table(L)\n\n# f(n) = \\sum_{i=1}^n phi(i)\n\nf_l = phi.copy()\nfor n in range(L):\n f_l[n + 1] += f_l[n]\n\nf_h = [0] * (H + 1) # f(N//d)\n\n\ndef f(n):\n return f_l[n] if n <= L else f_h[N // n]\n\n\ndef compute_f(n):\n sq = int(n ** .5)\n x = n * (n + 1) // 2\n for d in range(1, n + 1):\n m = n // d\n if m <= sq:\n break\n x -= f(m)\n for m in range(1, sq + 1):\n cnt = n // m - n // (m + 1)\n x -= f_l[m] * cnt\n return x\n\n\nfor d in range(H, 0, -1):\n f_h[d] = compute_f(N // d)\n\nsq = int(N ** .5)\nanswer = 0\nfor d in range(1, N + 1):\n n = N // d\n if n <= sq:\n break\n answer += pow(n, e, MOD) * phi[d]\n\nfor n in range(1, sq + 1):\n low_d = N // (n + 1)\n high_d = N // n\n phi_sum = f(high_d) - f(low_d)\n answer += phi_sum * pow(n, e, MOD)\n\nanswer %= MOD\nprint(answer)\n'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s482697725', 's790067233', 's828525022', 's429011212'] | [29800.0, 29668.0, 29604.0, 9460.0] | [296.0, 298.0, 291.0, 25.0] | [632, 634, 632, 1140] |
p02715 | u149844264 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['\n\n\nN, K = [int(x) for x in input().split()]\ncountBcd = [0]*(K+1)\nmod=10**9+7\nsumTotal=0\nfor i in range(K,0,-1):\n countBcd[i] = pow(K//i,N,mod)\n\n for j in range(i*2,K+1,i):\n countBcd[i] - countBcd[j]\n\n sumTotal += i*countBcd[i]%mod\n\nprint(sumTotal%mod)\n', '\n\n\nN, K = [int(x) for x in input().split()]\ncountBcd = [0]*(K+1)\nmod=10**9+7\nsumTotal=0\nfor i in range(K,0,-1):\n countBcd[i] = pow(K//i,N,mod)\n\n for j in range(i*2,K+1,i):\n countBcd[i] -= countBcd[j]\n\n sumTotal += i*countBcd[i]%mod\n\nprint(sumTotal%mod)\n'] | ['Wrong Answer', 'Accepted'] | ['s290780078', 's790784637'] | [11252.0, 11220.0] | [333.0, 360.0] | [435, 436] |
p02715 | u250664216 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = map(int, input().split())\nmod = 10**9+7\n\nnum_gcd_k = [0]*(k+1)\nnum_gcd_k[k] = 1\nans = 0\nfor i in range(k-1,0,-1):\n \n total = pow(k//i,n,mod)\n m = 2\n while i*m <= k:\n total -= num_gcd_k[i*m]\n m += 1\n num_gcd_k[i] = total\n ans += i*total\n ans %= mod\n\nprint(ans)', 'n, k = map(int, input().split())\nmod = 10**9+7\n\nnum_gcd_k = [0]*(k+1)\nnum_gcd_k[k] = 1\nans = 0\nfor i in range(k,0,-1):\n \n total = pow(k//i,n,mod)\n m = 2\n while i*m <= k:\n total -= num_gcd_k[i*m]\n m += 1\n num_gcd_k[i] = total\n ans += i*total\n ans %= mod\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s981641124', 's973577533'] | [11300.0, 11308.0] | [456.0, 439.0] | [377, 375] |
p02715 | u347600233 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = map(int, input().split())\np = 10**9 + 7\nsg = [0] * (k + 1)\nfor i in range(k, 0, -1):\n sg[i] += i * pow(k // i, n, p)\n m = 2\n while m*i <= k:\n sg[i] = (sg[i] - sg[m*i]) % p\n m += 1\nprint(sum(sg) % MOD)', 'n, k = map(int, input().split())\np = 10**9 + 7\nsg = [0] * (k + 1)\nfor i in range(k, 0, -1):\n sg[i] += i * pow(k // i, n, p)\n m = 2\n while m*i <= k:\n sg[i] = (sg[i] - sg[m*i]) % p\n m += 1\nprint(sum(sg))', 'MOD = 10**9 + 7\nn, k = map(int, input().split())\nd = [0] + [pow(k // i, n, MOD) for i in range(1, k + 1)]\nfor i in range(k, 0, -1):\n for j in range(2*i, k + 1, i):\n d[i] -= d[j]\n d[i] %= MOD\nprint(sum(i * d[i] % MOD for i in range(1, k + 1)) % MOD)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s617284692', 's850504617', 's793039264'] | [12820.0, 12840.0, 12100.0] | [562.0, 547.0, 434.0] | [230, 224, 265] |
p02715 | u347640436 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N, K = map(int, input().split())\n\nMOD = 10 ** 9 + 7\n\ncache = {}\ndef f(k, n):\n if k == 1:\n return 1\n if k in cache:\n return cache[k]\n result = pow(k, n, MOD)\n for i in range(2, k + 1):\n result -= f(k // i, n)\n result %= MOD\n cache[k] = result\n return result\n\n\nresult = 0\nfor i in range(K + 1):\n result += f(K // i, N) * i\n result %= MOD\nprint(result)\n', 'N, K = map(int, input().split())\n\nMOD = 10 ** 9 + 7\n\nc = [0] * (K + 1)\nfor i in range(K, 0, -1):\n t = pow(K // i, N, MOD)\n for j in range(2, K // i + 1):\n t -= c[i * j]\n t %= MOD\n c[i] = t\n\nresult = 0\nfor i in range(1, K + 1):\n result += c[i] * i\n result %= MOD\nprint(result)\n'] | ['Runtime Error', 'Accepted'] | ['s269000507', 's254729294'] | [9204.0, 11300.0] | [24.0, 396.0] | [402, 305] |
p02715 | u375616706 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N,K = map(int,input().split())\n\nans=0\nMOD=10**9+7\n\ncnt=[0]*(K+1)\nfor x in reversed(range(1,K+1)):\n cnt_tmp = pow(K//x,N,MOD)\n t=1\n while (t+1)*x<=K:\n t+=1\n cnt_tmp -= cnt[x*t] \n\n cnt[x]=cnt_tmp\n ans = x*cnt_tmp %MOD\nprint(ans)\n', 'N,K = map(int,input().split())\n\nans=0\nMOD=10**9+7\n\ncnt=[0]*(K+1)\nfor x in reversed(range(1,K+1)):\n cnt_tmp = pow(K//x,N,MOD)\n t=1\n while (t+1)*x<=K:\n t+=1\n cnt_tmp -= cnt[x*t] \n\n cnt[x]=cnt_tmp\n ans += x*cnt_tmp\n ans%=MOD\nprint((ans+MOD)%MOD)\n'] | ['Wrong Answer', 'Accepted'] | ['s627430057', 's965284817'] | [11224.0, 11108.0] | [454.0, 449.0] | [362, 381] |
p02715 | u391540332 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = (int(x) for x in input().split())\n\nc = {} \nt = 0\nfor x in range(k, 0, -1):\n q = k // x\n c[x] = q ** n # - sum(c[x * y] for y in range(2, q + 1))\n t += c[x] * x\n t = t % 1000000007\n\nprint(t)', 'n, k = (int(x) for x in input().split())\nc = {} \nt = 0\nMOD = 1000000007\nfor x in range(k, 0, -1):\n q = k // x\n c[x] = pow(q, n, MOD) - sum(c[x * y] for y in range(2, q + 1))\n t += c[x] * x\n t = t % MOD\nprint(t)'] | ['Wrong Answer', 'Accepted'] | ['s572145284', 's647783169'] | [137020.0, 20656.0] | [2209.0, 354.0] | [208, 222] |
p02715 | u399298563 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N, K = map(int, input().split())\nMOD = 10 ** 9 + 7\ncnt = [0] * (K + 1)\nfor x in range(1, K + 1):\n cnt[x] = pow(K // x , N , MOD)\n\nfor x in range(K, 0, -1):\n for i in range(2, (K // x) + 1):\n cnt[x] -= cnt[x * i]\n \nprint(cnt)\nans = 0\nfor x in range(1, K + 1):\n ans += cnt[x] * x\nprint(ans % MOD)', 'N, K = map(int, input().split())\nMOD = 10 ** 9 + 7\ncnt = [0] * (K + 1)\nfor x in range(1, K + 1):\n cnt[x] = pow(K // x , N , MOD)\n\nfor x in range(K, 0, -1):\n for i in range(2, (K // x) + 1):\n cnt[x] -= cnt[x * i]\n \nans = 0\nfor x in range(1, K + 1):\n ans += cnt[x] * x\nprint(ans % MOD)\n '] | ['Wrong Answer', 'Accepted'] | ['s605815047', 's858211467'] | [12692.0, 11364.0] | [377.0, 355.0] | [338, 330] |
p02715 | u414050834 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n,k=map(int,input().split())\nl=[0]*(k+1)\na=0\nmod=10**9+7\nfor i in range(1,k+1):\n l[i]=i\n for j in range(i*2,k+1,i):\n l[j]-=l[i]\n a+=l[i]*pow(k//i,n,mod)\nprint(a%mod)', 'n,k=map(int,input().split())\nl=[0]*(k+1)\na=0\nmod=10**9+7\nfor i in range(1,k+1):\n l[i]+=i\n for j in range(i*2,k+1,i):\n l[j]-=l[i]\n a+=l[i]*pow(k//i,n,mod)\nprint(a%mod)\n'] | ['Wrong Answer', 'Accepted'] | ['s720501854', 's493457195'] | [12756.0, 12840.0] | [374.0, 357.0] | [171, 173] |
p02715 | u460229551 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N,K=list(map(int,input().split()))\nl=[0]*(K+1)\nans=0\nmod=10**9+7\n\nfor x in range(K,0,-1):\n l[x]=pow((K//x),N,mod)\n for y in range(2*x,K+1,x):\n l[x]-=l[y]\n l[x]=pow(l[i],1,mod)\n ans+=l[x]*x\n ans=pow(ans,1,mod)\nprint(ans)', 'N,K=list(map(int,input().split()))\nl=[0]*(K+1)\nans=0\nmod=10**9+7\n\nfor x in range(K,0,-1):\n l[x]=pow((K//x),N,mod)\n for y in range(2*x,K+1,x):\n l[x]-=l[y]\n l[x]=pow(l[x],1,mod)\n ans+=l[x]*x\n ans=pow(ans,1,mod)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s018026300', 's169788007'] | [9660.0, 11296.0] | [114.0, 1187.0] | [245, 245] |
p02715 | u479719434 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['M = 1000000007\n\n\ndef main(N=None, K=None):\n if not N or not K:\n N = int(input())\n K = int(input())\n ans = 0\n gcds = {}\n for X in range(K, 0, -1):\n gcds[X] = int(pow(K//X, N, M))\n n = 1\n while True:\n n += 1\n if n*X > K:\n break\n gcds[X] -= gcds[n*X]\n ans += gcds[X]*X\n ans %= M\n print(ans)\n return ans\n\n\nif __name__ == "__main__":\n \n \n \n main()\n', 'M = 1000000007\n\n\ndef main(N=None, K=None):\n if not N or not K:\n N, K = map(int, input().split())\n ans = 0\n gcds = {}\n for X in range(K, 0, -1):\n gcds[X] = int(pow(K//X, N, M))\n n = 1\n while True:\n n += 1\n if n*X > K:\n break\n gcds[X] -= gcds[n*X]\n ans += gcds[X]*X\n ans %= M\n print(ans)\n return ans\n\n\nif __name__ == "__main__":\n \n \n \n main()\n'] | ['Runtime Error', 'Accepted'] | ['s011059379', 's014374870'] | [9232.0, 20576.0] | [21.0, 416.0] | [565, 556] |
p02715 | u481550011 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['mod=10**9+7\nN,K=map(int,input().split())\ngcd=[0]*(K+1)\nans=0\nmultipleNumber=0\nfor i in reversed(range(1,K+1)):\n multipleNumber=K//i\n totalNumber=multipleNumber**N%mod\n minus=range(2*i,K+1,i)\n for j in minus:\n totalNumber-=gcd[j]\n totalNumber%=mod\n gcd[i]=totalNumber\n ans+=i*gcd[i]\nprint(ans%a)', 'import math\na=10**9+7\nN,K=map(int,input().split())\ngcd=[0]*(K+1)\nans=0\nmultipleNumber\nfor i in reversed(range(1,K+1)):\n multipleNumber=math.floor(K/i)\n totalNumber=multipleNumber**N\n if 2*i<=K:\n minus=range(2*i,K+1,i)\n for j in minus:\n totalNumber-=gcd[j]\n gcd[i]=totalNumber\nfor i in range(1,len(gcd)):\n ans+=i*gcd[i]\nprint(ans)', 'mod=10**9+7\nN,K=map(int,input().split())\nd=[0]*(K+1)\nans=0\nfor i in range(1,K+1):\n d[i]=pow(K//i,N,mod)\nfor i in range(K,0,-1):\n for j in range(2*i,K+1,i):\n d[i]-=d[j]\n d[i]%=mod\n ans+=d[i]*i\n ans%=mod\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s351254741', 's531526617', 's299721681'] | [11300.0, 9660.0, 11304.0] | [2206.0, 23.0, 472.0] | [326, 369, 238] |
p02715 | u486065927 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = map(int, input().split())\nc = 10**9+7\ntm = [0] + [1]*k\na = k//2\nans = k*(k+1)//2 - a*(a+1)//2\nfor i in range(k//2, 0, -1):\n a = k//i\n t = (left_bin(a, n, c) - sum([tm[j*i] for j in range(2, a+1)])) % c\n ans = (ans + t*i) % c\n tm[i] = t\nprint(ans)\n', 'def left_bin(a, n, c):\n ns = [int(i) for i in bin(n)[3:]]\n t = a\n for i in ns:\n t = t*t % c\n if i == 1:\n t = t*a % c\n return t\n\n\nn, k = map(int, input().split())\nc = 10**9+7\ntm = [0] + [1]*k\na = k//2\nans = k*(k+1)//2 - a*(a+1)//2\nfor i in range(k//2, 0, -1):\n a = k//i\n t = (left_bin(a, n, c) - sum([tm[j*i] for j in range(2, a+1)])) % c\n ans = (ans + t*i) % c\n tm[i] = t\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s203648203', 's952699285'] | [10456.0, 11992.0] | [27.0, 384.0] | [266, 432] |
p02715 | u512212329 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['\nMOD = 1000000007\nn, k = [int(x) for x in input().split()]\nd = [pow(k, n, MOD) for i in range(1, k+1)]\n\nfor i in range(k, 0, -1): \n for j in range(i * 2, k + 1, i): \n \n d[i] -= d[j]\n d[i] %= MOD\nans = 0\nfor i, item in enumerate(d):\n ans += i * item\n ans %= MOD\nprint(ans)\n', '\nMOD = 1000000007\nn, k = [int(x) for x in input().split()]\nd = [0] * (k + 1)\n\nfor i in range(1, k + 1):\n d[i] = pow(k // i, n, MOD)\n\nfor i in range(k, 0, -1): \n for j in range(i * 2, k + 1, i): \n \n d[i] -= d[j]\n d[i] %= MOD\nans = 0\nfor i, item in enumerate(d):\n ans += i * item\n ans %= MOD\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s359850045', 's278791337'] | [12936.0, 11172.0] | [467.0, 433.0] | [388, 420] |
p02715 | u515740713 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import sys \nimport numpy as np\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nMOD = 10 ** 9 + 7 \nN, K = map(int, readline().split())\nd = [0] * (K+1)\nfor i in range(K,0,-1):\n t = K // i\n cnt = pow(t,N,MOD)\n for j in range(2,t+1):\n cnt -= d[i*j]\n cnt %= mod\n d[i] = cnt\nans = 0\nfor num,cnt in enumerate(d):\n ans += num * cnt\n ans %= MOD\nprint(ans) ', 'import sys \nimport numpy as np\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nMOD = 10 ** 9 + 7 \nN, K = map(int, readline().split())\nd = [0] * (K+1)\nfor i in range(K,0,-1):\n t = K // i\n cnt = pow(t,N,MOD)\n for j in range(2,t+1):\n cnt -= d[i*j]\n cnt %= MOD\n d[i] = cnt\nans = 0\nfor num,cnt in enumerate(d):\n ans += num * cnt\n ans %= MOD\nprint(ans) '] | ['Runtime Error', 'Accepted'] | ['s722446836', 's219911550'] | [27088.0, 29048.0] | [165.0, 526.0] | [439, 439] |
p02715 | u523545435 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import math\n\nN,K=map(int,input().split())\nP=10**9+7\n\nL=[0]*K\nfor i in range(N):\n L[i]=pow(K//(i+1),N-1,P)\n\ndef culc(x):\n f=K//i\n r=K-f\n if r==1:\n return (f*(N-1))%P\n else:\n y=pow(r,N-1)-1\n return ((f*y)//(r-1))%P\n\nfor j in range(1,K):\n L[0]+=culc(j+1)\n\nans=0\nfor k in range(K):\n ans+=((k+1)*L[k])%P\n\nprint(ans)\n\n', 'import math\n\nN,K=map(int,input().split())\nP=10**9+7\n\nL=[0]*N\nfor i in range(N):\n L[i]=pow(K//(i+1),N-1,P)\n\ndef culc(x):\n f=K//i\n r=K-f\n if r==1:\n return (f*(N-1))%P\n else:\n y=pow(r,N-1)-1\n return ((f*y)//(r-1))%P\n\nfor j in range(1,N):\n L[0]+=culc(j+1)\n\nans=0\nfor k in range(N):\n ans+=((k+1)*L[k])%P\n\nprint(ans)\n\n', 'N,K=map(int,input().split())\nP=10**9+7\n\nL=[0]*(K+1)\nfor i in range(1,K+1)[::-1]:\n minus=0\n count=2\n while True:\n if count*i<=K:\n minus+=L[count*i]\n minus=minus%P\n count+=1\n else:\n break\n\n L[i]=(pow(K//i,N,P)-minus)%P\n\nans=0\nfor j in range(1,K+1):\n ans+=j*L[j]\n ans=ans%P\n\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s802592466', 's894778341', 's809026133'] | [12232.0, 12220.0, 11220.0] | [2206.0, 2206.0, 498.0] | [354, 354, 358] |
p02715 | u535236942 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['def make_divisors(n):\n divisors = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n divisors.append(i)\n if i != n // i:\n divisors.append(n//i)\n \n return divisors\n\nn, k = map(int, input().split())\nmod = 1000000007\nl = [1 for i in range(k+1)]\nfor i in range(k):\n for j in range(len(make_divisors(k-i))):\n l[make_divisors(k-i)[j]] += n*l[k-i]\nans = 0\nfor i in range(k+1):\n ans += l[i]*i\n ans %= mod\nprint(ans)', 'n, k = map(int, input().split())\nl = [0 for i in range(k + 1)]\nans = 0\nmod = 1000000007\nfor i in range(k, 0, -1):\n l[i] = pow(k // i, n, mod)\n tmp = 2 * i\n while tmp <= k:\n l[i] -= l[tmp]\n tmp += i\nfor i in range(k + 1):\n ans += i * l[i]\n ans %= mod\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s570755269', 's405435936'] | [11948.0, 11368.0] | [2206.0, 392.0] | [482, 289] |
p02715 | u535803878 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['def factorization(n):\n arr = []\n temp = n\n for i in range(2, int(-(-n**0.5//1))+1):\n if temp%i==0:\n cnt=0\n while temp%i==0:\n cnt+=1\n temp //= i\n arr.append([i, cnt])\n\n if temp!=1:\n arr.append([temp, 1])\n\n if arr==[]:\n arr.append([n, 1])\n\n return arr\n\nimport numpy as np\nM = int(10**9)+7\nn,k = [int(c) for c in input().split()]\nnums = [0]*(k+1)\nnums = np.zeros((k+1), dtype=int)\nfor i in range(k, 0, -1):\n tmp = (pow(k // i, n, M)\n tmp -= nums[(2*i)::i].sum()\n nums[i] += tmp\n \n\nprint((np.arange(k+1) * nums).sum()%M)', 'def factorization(n):\n arr = []\n temp = n\n for i in range(2, int(-(-n**0.5//1))+1):\n if temp%i==0:\n cnt=0\n while temp%i==0:\n cnt+=1\n temp //= i\n arr.append([i, cnt])\n\n if temp!=1:\n arr.append([temp, 1])\n\n if arr==[]:\n arr.append([n, 1])\n\n return arr\n\nimport numpy as np\nM = int(10**9)+7\nn,k = [int(c) for c in input().split()]\nnums = [0]*(k+1)\nnums = np.zeros((k+1), dtype=int)\nfor i in range(k, 0, -1):\n tmp = pow(k // i, n, M)\n tmp -= nums[(2*i)::i].sum()\n nums[i] += tmp\n \n\nprint((np.arange(k+1) * nums).sum()%M)'] | ['Runtime Error', 'Accepted'] | ['s309228961', 's864426651'] | [8988.0, 28632.0] | [20.0, 503.0] | [685, 684] |
p02715 | u545368057 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import math\nK = int(input())\nans = 0\nfor i in range(1,K+1):\n for j in range(1,K+1):\n for k in range(1,K+1):\n ans+=math.gcd(i,math.gcd(j,k)) \nprint(ans) \n\n', 'N,K = map(int, input().split())\nmod = 10**9+7\nans = 0\ndp = [0] * (K+10)\n\nfor i in range(K,0,-1):\n x = K//i\n a = pow(x, N, mod)\n cnt = 2\n while i*cnt <= K:\n a -= dp[i*cnt]\n cnt += 1\n a %= mod\n dp[i] = a\n ans += a*i\n ans %= mod\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s506527963', 's185096944'] | [9196.0, 11172.0] | [19.0, 459.0] | [185, 274] |
p02715 | u571199625 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n=int(input())\ns=input()\n\nremain = [[0,0,0]]\nfor i in range(n):\n r, g, b = remain[-1]\n if s[-i-1] == "R":\n r = r+1\n elif s[-i-1] == "G":\n g = g + 1\n elif s[-i-1] == "B":\n b = b + 1\n\n remain.append([r,g,b])\n\ntotal = 0\nfor i in range(n-2):\n if s[i] == "R":\n for j in range(i+1, n):\n if s[j] == "G":\n total += remain[-j-1][2]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="B":\n total -= 1\n elif s[j] == "B":\n total += remain[-j-1][1]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="G":\n total -= 1\n elif s[i] == "G":\n for j in range(i+1, n):\n if s[j] == "B":\n total += remain[-j-1][0]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="R":\n total -= 1\n elif s[j] == "R":\n total += remain[-j-1][2]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="B":\n total -= 1\n elif s[i] == "B":\n for j in range(i+1, n):\n\n if s[j] == "R":\n total += remain[-j-1][1]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="G":\n total -= 1\n elif s[j] == "G":\n total += remain[-j-1][0]\n if i+((j-i)*2) < n:\n if s[i+((j-i)*2)]=="R":\n total -= 1\nprint(total)', 'n,k = map(int,input().split())\ngcds = []\n\n\ndef power_func(a,n,p):\n bi=str(format(n,"b"))\n res=1\n for i in range(len(bi)):\n res=(res*res) %p\n if bi[i]=="1":\n res=(res*a) %p\n return res\n\nmod = 10**9+7\nfor i in range(k):\n div = k//(k-i)\n count = power_func(div,n, mod)\n for j in range(1,div):\n count = count - gcds[k-((k-i)*(j+1))]\n gcds.append(count)\n\ntotal = 0\n\nfor i in range(k):\n total = (total + (gcds[i]*(k-i)%mod))%mod\nprint(total)'] | ['Runtime Error', 'Accepted'] | ['s459636689', 's957119193'] | [9352.0, 11348.0] | [22.0, 594.0] | [1557, 508] |
p02715 | u572142121 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['N,K=map(int, input().split())\nimport math\ncnt=(K**N)%(10**9+7)\n\nprint(cnt)\nfor i in range(2,K+1):\n a=K//i\n cnt+=((a**N-2)*(i-1))%(10**9+7)\nprint(cnt)', 'N,K=map(int,input().split())\nD=[0]*(K+1)\nans=0\nmod=10**9+7\nfor i in range(K,0,-1):\n D[i]=(pow(K//i,N,mod)-sum(D[i::i]))%mod\n ans+=(D[i]*i)%mod\n ans%=mod\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s648897303', 's816586478'] | [9780.0, 12048.0] | [2205.0, 214.0] | [151, 166] |
p02715 | u624696727 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\nprintV = lambda x: print(*x, sep="\\n")\nprintH = lambda x: print(" ".join(map(str,x)))\ndef IS(): return sys.stdin.readline()[:-1]\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LI1(): return list(map(int1, sys.stdin.readline().split()))\ndef LII(rows_number): return [II() for _ in range(rows_number)]\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef LLI1(rows_number): return [LI1() for _ in range(rows_number)]\nmod = 10**9+7\n\ndef main():\n\tn,k = MI()\n\tdp=[0]*(k+1)\n\tans=0\n\tdef g(x, n, mod):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\tK = 1\n\t\twhile n > 1:\n\t\t\tif n % 2 != 0:\n\t\t\t\tK *= x\n\t\t\tx *= x%mod\n\t\t\tn //= 2\n\t\treturn K * x\n\n\tfor i in range(k,0,-1):\n\t\tdp[i]=g(k//i,n,mod)\n\t\tfor j in range(i*2,k,i):\n\t\t\tdp[i]-=dp[j]\n\t\t\tdp[i]%=mod\n\t\tdp[i]=(dp[i]%mod+mod)%mod\n\t\tans+=i*dp[i]%mod\n\tprint(ans%mod)\nif __name__ == \'__main__\':\n\tmain()', 'import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\nprintV = lambda x: print(*x, sep="\\n")\nprintH = lambda x: print(" ".join(map(str,x)))\ndef IS(): return sys.stdin.readline()[:-1]\ndef II(): return int(sys.stdin.readline())\ndef MI(): return map(int, sys.stdin.readline().split())\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LI1(): return list(map(int1, sys.stdin.readline().split()))\ndef LII(rows_number): return [II() for _ in range(rows_number)]\ndef LLI(rows_number): return [LI() for _ in range(rows_number)]\ndef LLI1(rows_number): return [LI1() for _ in range(rows_number)]\nmod = 10**9+7\n\ndef main():\n\tn,k = MI()\n\tdp=[0]*(k+1)\n\tans=0\n\tdef g(x, n, mod):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\tK = 1\n\t\twhile n > 1:\n\t\t\tif n % 2 != 0:\n\t\t\t\tK *= x\n\t\t\tx *= x%mod\n\t\t\tK %= mod\n\t\t\tn //= 2\n\t\treturn K * x\n\n\tfor i in range(k,0,-1):\n\t\tdp[i]=g(k//i,n,mod)\n\t\tfor j in range(i*2,k+1,i):\n\t\t\tdp[i]-=dp[j]\n\t\t\tdp[i]%=mod\n\t\tdp[i]=(dp[i]%mod+mod)%mod\n\t\tans+=i*dp[i]%mod\n\tprint(ans%mod)\nif __name__ == \'__main__\':\n\tmain()'] | ['Wrong Answer', 'Accepted'] | ['s950037103', 's519313740'] | [11172.0, 11180.0] | [616.0, 613.0] | [1017, 1031] |
p02715 | u627600101 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['mod=10**9+7\nN,K=map(int,input().split())\nAns=[1 for k in range(K)]\nc=K\nfor j in range(N):\n Ans[0]=Ans[0]*(K)%mod\nfor k in range(2,(K+1)//2+1):\n d=K//k\n if c==d:\n Ans[k-1]=Ans[k-2]\n else:\n for j in range(N):\n Ans[k-1]=Ans[k-1]*d%mod\n c=d\nprint(Ans)\nfor j in range(K,1,-1):\n for l in range(j//2,0,-1):\n if j%l==0:\n Ans[l-1]-=Ans[j-1]\nfor j in range(K):\n Ans[j]*=j+1\nprint(sum(Ans)%mod)', "#from line_profiler import LineProfiler\n \nN, K = map(int, input().split())\nmod = 10**9 + 7\ndef main():\n b = N\n blis = []\n c = 0\n while b >0:\n if b & 1 == 1:\n blis.append(c)\n c += 1\n b >>= 1\n\n\n def modpow(a, blis= blis, c = c):\n if a == 1:\n return 1\n else:\n res = 1\n li = []\n for _ in range(c):\n li.append(a%mod)\n a = a*a%mod\n for item in blis:\n res = res *li[item] %mod\n return res\n\n \n fact_count = [0 for _ in range(K+1)]\n for k in range(1, K+1):\n fact_count[k] = K//k\n\n ans = 0\n count = [0 for _ in range(K+1)]\n for k in range(K, 0, -1):\n x = 1*fact_count[k]\n cc = modpow(x)\n j = 2*k\n l = 2\n while(j<=K):\n cc -= count[j]\n l += 1\n j = k*l\n count[k] = cc\n cc = cc*k%mod\n ans += cc\n ans %= mod\n print(ans)\nif __name__ == '__main__':\n main()\n#prof = LineProfiler()\n#prof.add_function(main)\n\n#prof.print_stats()\n"] | ['Wrong Answer', 'Accepted'] | ['s346846999', 's564737784'] | [11112.0, 12240.0] | [2206.0, 389.0] | [451, 959] |
p02715 | u703442202 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n = input()\nk = int(input())\ndp = [[[0 for i in range(len(n)+1)] for i in range(2)] for i in range(len(n)+1)]\ndp[0][0][0] = 1\nfor a in range(len(n)):\n for b in range(2):\n for c in range(len(n)):\n for i in range(10):\n if b ==1:\n if i != 0:\n dp[a+1][1][c+1] += dp[a][1][c]\n else:\n dp[a+1][1][c] += dp[a][1][c]\n else:\n if int(n[a]) > i and i ==0:\n dp[a+1][1][c] += dp[a][0][c]\n if int(n[a]) > i and i != 0:\n dp[a+1][1][c+1] += dp[a][0][c]\n if int(n[a]) == i and i ==0:\n dp[a+1][0][c] += dp[a][0][c]\n if int(n[a]) == i and i !=0:\n dp[a+1][0][c+1] += dp[a][0][c]\nif len(n) == 1:\n\tprint(int(n)) \nelse:\n print(dp[-1][0][k] + dp[-1][1][k])\n', 'n,k = map(int,input().split())\ngcd_num = [0 for i in range(k+1)]\nc = 10**9 + 7\nans = 0\nfor i in range(k,0,-1):\n x = k//i\n \n \n gcd_num[i] = pow(x,n,c)\n \n for j in range(2,x+1):\n gcd_num[i] -= gcd_num[i * j]\n \n ans += gcd_num[i] * i\n \nprint(ans%c)\n \n \n \n \n '] | ['Runtime Error', 'Accepted'] | ['s554863740', 's946786653'] | [9240.0, 11344.0] | [23.0, 376.0] | [777, 466] |
p02715 | u714269187 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long ll;\n\n\n\nll n,k,mod=1e9+7,ans=0;\n\nll fastMod(ll a,ll b){\n ll res=1;\n while(b>0){\n if(b&1)res=(res*a)%mod;\n b/=2;\n a=(a*a)%mod;\n }\n return res;\n}\n\nvoid solve(){ \n cin>>n>>k;\n vector<ll> v(k+1);\n for(int i=k;i>0;i--){\n v[i]=fastMod(k/i,n);\n for(int j=2*i;j<=k;j+=i){\n v[i]=(v[i]-v[j]+mod)%mod;\n }\n }\n for(int i=1;i<=k;i++){\n ll val=(v[i]*i)%mod;\n ans=(ans+val)%mod;\n }\n cout<<ans%mod;\n}\n\nint main()\n{\n ios::sync_with_stdio(0);\n cin.tie(0);\n ll t=1;\n // cin>>t;\n while(t--){\n solve();\n }\n return 0;\n}\n', 'n,k=[int(x) for x in input().split()]\nans=0\nl=[0]*(k+1)\ni=k\nmod=1000000007\nwhile i>0:\n l[i]=pow(k//i,n,mod)\n j=2*i\n while j<=k:\n l[i]=(l[i]-l[j]+mod)%mod\n j+=i\n i-=1\nfor i in range(1,k+1):\n ans+=(l[i]*i)%mod\nprint(ans%mod)\n'] | ['Runtime Error', 'Accepted'] | ['s159465215', 's015125074'] | [9012.0, 11296.0] | [22.0, 515.0] | [754, 252] |
p02715 | u723583932 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['#include <bits/stdc++.h>\nusing namespace std;\ntypedef long long ll;\n\n\n\n\n#define INF 2e9\n#define ALL(v) v.begin(), v.end()\n\nint k;\nint memo[200+1][200+1];\nll N=1000000000+7;\n\nint gcd(int x,int y){\n if(y==0){\n return x;\n }\n return gcd(y,x%y);\n}\n\nint main(){\n cin>>k;\n int ans=0;\n for(int a=1;a<=k;a++){\n for(int b=1;b<=k;b++){\n for(int c=1;c<=k;c++){\n ans+=gcd(gcd(a,b),c)%N;\n }\n }\n }\n cout<<ans<<endl;\n return 0;\n}', 'n,k=map(int,input().split())\nINF=10**9+7\nbaisu= [[] for _ in [0]*(k+1)]\nD=[0]*(k+1)\nans=0\nfor d in range(1,k+1):\n baisu[d]=[d*i for i in range(2,k//d+1)]\n D[d]=pow(k//d,n,INF)\n\nfor d in range(k,0,-1):\n for b in baisu[d]:\n D[d]-=D[b]\n D[d]%=INF\nfor i,x in enumerate(D):\n \n ans=(ans+i*x)%INF\n \n\n#print(D)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s765586366', 's922475975'] | [9012.0, 61644.0] | [22.0, 507.0] | [588, 402] |
p02715 | u760642788 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n, k = list(map(int, input().split()))\nl = [0 for i in range(k)]\nans = 0\nM = 10**9 + 7\n\ndef dev(n):\n dl = []\n for i in range(1, int(n**0.5)+1):\n if n % i == 0:\n dl.append(i)\n if i != n // i:\n dl.append(n//i)\n dl.sort()\n return dl\n\nfor i in range(k, 0, -1):\n a=k//i\n b=a**n\n l[i-1] += b\n d=dev(i)\n for m in d:\n if m != i:\n l[m-1] -= l[i-1]\n print(i, l)\n\nfor i in range(1, k+1):\n ans+=i*l[i-1]\n\nprint(ans%M)\n', 'n, k = list(map(int, input().split()))\nl = [0 for i in range(k)]\nans = 0\nM = 10**9 + 7\n\n\n# dl = []\n\n\n# dl.append(i)\n\n# dl.append(n//i)\n# dl.sort()\n\n\nfor i in range(k, 0, -1):\n# a=k//i\n# b=a**n%M\n b=pow(k//i, n, M)\n for j in range(i*2, k+1, i):\n b -= l[j-1]\n l[i-1] = b%M\n\nfor i in range(1, k+1):\n ans+=i*l[i-1]\n\nprint(ans%M)\n'] | ['Wrong Answer', 'Accepted'] | ['s025592965', 's729142140'] | [129224.0, 11364.0] | [2463.0, 364.0] | [501, 508] |
p02715 | u831651889 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['Big=10**9+7\n_=list(map(int,input().split(" ")))\nN=_[0]\nK=_[1]\ngcd_list=[0 for _ in range(K)]\nfor i in range(K):\n s=K-i-1\n gcd_list[s]=(pow(K//K-i, N, Big)-(sum(gcd_list[2*s+1::s+1]))%Big)%Big\nanswer=[(x+1)*gcd_list[x]%Big for x in range(K)]\nprint(sum(answer)%Big)', 'Big=10**9+7\n_=list(map(int,input().split(" ")))\nN=_[0]\nK=_[1]\ngcd_list=[0 for _ in range(K)]\nfor i in range(K):\n s=K-i-1\n gcd_list[s]=(pow(K//(K-i), N, Big)-(sum(gcd_list[2*s+1::s+1]))%Big)%Big\nanswer=[(x+1)*gcd_list[x]%Big for x in range(K)]\nprint(sum(answer)%Big)'] | ['Wrong Answer', 'Accepted'] | ['s200332376', 's767730450'] | [16816.0, 15664.0] | [299.0, 243.0] | [265, 267] |
p02715 | u858742833 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['def main():\n N = int(input())\n A = list(map(int, input().split()))\n a0, a1, a2, b0, b1, b2 = A[0], 0, 0, A[1], 0, 0\n for a in A[2:]:\n a0, a1, a2, b0, b1, b2 = (\n b0,\n max(b1, a0),\n max(b2, a1),\n a0 + a,\n a1 + a,\n a2 + a)\n\n if N & 1:\n return max(b2, a1)\n else:\n return max(a0, b1)\n\n\nprint(main())\n', 'def main():\n N, K = map(int, input().split())\n mod = 10**9 + 7\n r = 0\n D = [0] * (K + 1)\n for i in reversed(range(1, K + 1)):\n D[i] = pow(K // i, N, mod) - sum(D[::i])\n return sum(i * j for i, j in enumerate(D)) % mod\n\nprint(main())\n'] | ['Runtime Error', 'Accepted'] | ['s236174859', 's120380480'] | [9204.0, 12048.0] | [22.0, 173.0] | [425, 258] |
p02715 | u898967808 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['MOD = 10**9+7\nn,k = map(int,input().split())\n\nL = [0]*(k+1)\n\nfor i in range(k,0,-1): \n L[i] = pow(k//i,n,mod)\n for j in range(2,k//i+1): \n L[i] -= L[i*j]\n \nans = 0\nfor i in range(1,k+1): \n ans = (ans + i*L[i]) % MOD\n \nprint(ans) ', 'MOD = 10**9+7\nn,k = map(int,input().split())\n\nL = [0]*(k+1)\n\nfor i in range(k,0,-1): \n L[i] = pow(k//i,n,MOD)\n for j in range(2,k//i+1): \n L[i] -= L[i*j]\n \nans = 0\nfor i in range(1,k+1): \n ans = (ans + i*L[i]) % MOD\n \nprint(ans) '] | ['Runtime Error', 'Accepted'] | ['s629505516', 's462924150'] | [9508.0, 11148.0] | [25.0, 391.0] | [249, 249] |
p02715 | u934868410 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n,k = map(int,input().split())\nmod = 10**9 + 7\n\n\ndef pow_mod(x, n, mod):\n if n > 1:\n return pow_mod(pow(x,2) % mod, n//2, mod) * pow(x, n%2) % mod\n else:\n return x\n\n\npow_n = [-1] * (k+1)\nfor i in range(1,k+1):\n if pow_n[k//i] == -1:\n pow_n[k//i] = pow_mod(k//i, n, mod)\n\nans = 0\nc = [0] * (k+1)\nfor i in range(k, 0, -1):\n count = pow_n[k//i]\n for j in range(2, k//i+1):\n if j > k//i:\n break\n count -= c[i]\n count %= mod\n c[i] = count\n ans += count * i\n ans %= mod\nprint(ans)\n', 'n,k = map(int,input().split())\nmod = 10**9 + 7\n\n\ndef pow_mod(x, n, mod):\n if n > 1:\n return pow_mod(pow(x,2) % mod, n//2, mod) * pow(x, n%2) % mod\n else:\n return x\n\n\npow_n = [-1] * (k+1)\nfor i in range(1,k+1):\n if pow_n[k//i] == -1:\n pow_n[k//i] = pow_mod(k//i, n, mod)\n\nans = 0\nc = [0] * (k+1)\nfor i in range(k, 0, -1):\n count = pow_n[k//i]\n for j in range(2, k//i+1):\n count -= c[i*j]\n count %= mod\n c[i] = count\n ans += count * i\n ans %= mod\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s281125142', 's145860801'] | [11952.0, 11948.0] | [348.0, 336.0] | [552, 515] |
p02715 | u944390835 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['import math\nN, K = map(int,input().split())\na = 0\nfor i in range(1, K):\n p = (K-i+1)**N - (K-i)**N\n q = (math.floor(K/i))**N - ((math.floor(K/i))-1)**N\n a += (i-1)*q + p\nprint(a%1000000007)\n', 'N, K = map(int, input().split())\nP = 10 ** 9 + 7\nX = [0] * (K + 1)\nans = 0\nfor i in range(1, K + 1):\n X[i] += i\n for j in range(i * 2, K+1, i):\n X[j] -= X[i]\n ans += X[i] * pow(K//i, N, P)\nprint(ans % P)'] | ['Wrong Answer', 'Accepted'] | ['s713218393', 's429209805'] | [10732.0, 12800.0] | [2206.0, 367.0] | [199, 219] |
p02715 | u983154415 | 2,000 | 1,048,576 | Consider sequences \\{A_1,...,A_N\\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N. | ['n,k=map(int,input().split())\ndp=[0]*(k+1)\nmod=int(1e9+7)\nfor i in range(k,0,-1):\n sm=0\n for j in range(2*i,k+1,i):\n sm=(sm+dp[j])%mod\n dp[i]=pow(k//i,n,mod)-sm\n\nans=0\nfor i in range(1,n+1):\n ans+=(dp[i]%mod*i%mod)%mod\nprint(ans%mod)\n', 'n,k=map(int,input().split())\ndp=[0]*(k+1)\nmod=int(1e9+7)\nfor i in range(k,0,-1):\n sm=0\n for j in range(2*i,k+1,i):\n sm=(sm+dp[j])%mod\n dp[i]=(pow(k//i,n,mod)-sm)%mod\n\nans=0\nfor i in range(1,k+1):\n ans+=(dp[i]%mod*i%mod)%mod\nprint(ans%mod)\n'] | ['Runtime Error', 'Accepted'] | ['s533310313', 's122797752'] | [11180.0, 11080.0] | [383.0, 384.0] | [252, 258] |
p02716 | u023540496 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['n = int(input())\na = [int(num) for num in input().split()]\ndp = [[0,0,0] for _ in range(n//2+1)]\n\n#dp[0] = [a[0],a[1],a[2]]\n\nfor i in range(n//2):\n dp[i+1][0] = dp[i][0] + a[i*2]\n dp[i+1][1] = max(dp[i][1],dp[i][0]) + a[i*2+1]\n if n % 2 == 1:\n dp[i+1][2] = max(dp[i][2],dp[i][1],dp[i][0]) + a[i*2+2]\nprint(dp)\nprint(max(dp[-1]))\n\n', 'n = int(input())\na = [int(num) for num in input().split()]\ndp = [[0,0,0] for _ in range(n//2+1)]\n\n#dp[0] = [a[0],a[1],a[2]]\n\nfor i in range(n//2):\n dp[i+1][0] = dp[i][0] + a[i*2]\n dp[i+1][1] = max(dp[i][1],dp[i][0]) + a[i*2+1]\n if n % 2 == 1:\n dp[i+1][2] = max(dp[i][2],dp[i][1],dp[i][0]) + a[i*2+2]\n#print(dp)\nif n% 2 == 1:\n print(max(dp[-1]))\nelse:\n print(max(dp[-1][:2]))'] | ['Wrong Answer', 'Accepted'] | ['s669385787', 's482351059'] | [54492.0, 42192.0] | [293.0, 233.0] | [346, 396] |
p02716 | u034128150 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['N = int(input())\nAs = list(map(int, input().split()))\n\nINF = 10 ** 15\ndp = [[-INF] * N for _ in range(3)]\ndp[0][0] = As[0]\ndp[1][0] = As[0]\ndp[0][1] = As[0]\ndp[1][1] = As[1]\n\nif N % 2 == 0:\n for i in range(2, N):\n dp[0][i] = dp[0][i-2] + As[i]\n dp[1][i] = max(dp[0][i-1], dp[1][i-2] + As[i])\nelse:\n for i in range(2, N):\n dp[0][i] = dp[0][i-2] + As[i]\n dp[1][i] = max(dp[0][i-1], dp[1][i-2] + As[i])\n dp[2][i] = max(dp[1][i-1], dp[2][i-2] + As[i])\n\nprint(dp)\nprint(max(dp[0][N-1], dp[1][N-1], dp[2][N-1]))\n\n', 'INF = 10 ** 15\n\nN = int(input())\nAs = list(map(int, input().split()))\nAs.append(-INF)\n\nINF = 10 ** 15\ndp = [[-INF] * (N//2) for _ in range(3)]\ndp[0][0] = As[0]\ndp[1][0] = As[1]\ndp[2][0] = As[2]\n\nfor i in range(1, N//2):\n dp[0][i] = dp[0][i-1] + As[2*i]\n dp[1][i] = max(dp[0][i-1], dp[1][i-1]) + As[2*i+1]\n dp[2][i] = max(dp[0][i-1], dp[1][i-1], dp[2][i-1]) + As[2*i+2]\n\nif N % 2 == 0:\n print(max(dp[0][-1], dp[1][-1]))\nelse:\n print(max(dp[0][-1], dp[1][-1], dp[2][-1]))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s041974890', 's569548477'] | [77044.0, 33744.0] | [397.0, 203.0] | [548, 486] |
p02716 | u064963667 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ["\nn = int(input())\na_list = list(map(int,input().split()))\n\nif n % 2 == 0: \n dp = [[-float('inf') for _ in range(n)] for __ in range(2)]\n dp[1][-1] = a_list[-1]\n\n for j in reversed(range(2)):\n for i in reversed(range(n)):\n if j == 2 and i >= n-2:\n pass\n elif j == 2:\n dp[j][i] = dp[j][i+2] + a_list[i]\n elif i == n-2:\n dp[j][i] = dp[j+1][i+1]\n elif i > n-2:\n pass\n else:\n dp[j][i] = max(dp[j+1][i+1],dp[j][i+2] + a_list[i])\n print(dp[0][0])\nelse: \n dp = [[-float('inf') for _ in range(n)] for __ in range(3)]\n dp[2][-1] = a_list[-1]\n\n for j in reversed(range(3)):\n for i in reversed(range(n)):\n if j == 2 and i >= n-2:\n pass\n elif j == 2:\n dp[j][i] = dp[j][i+2] + a_list[i]\n elif i == n-2:\n dp[j][i] = dp[j+1][i+1]\n elif i > n-2:\n pass\n else:\n dp[j][i] = max(dp[j+1][i+1],dp[j][i+2] + a_list[i])\n print(dp[0][0])", "\nn = int(input())\na_list = list(map(int,input().split()))\n\nif n == 2 or n == 3:\n print(max(a_list))\nelif n % 2 == 0: \n dp = [[-float('inf') for _ in range(n)] for __ in range(2)]\n dp[1][-1] = a_list[-1]\n\n for j in reversed(range(2)):\n for i in reversed(range(n)):\n if j == 1 and i >= n-2:\n pass\n elif j == 1:\n dp[j][i] = dp[j][i+2] + a_list[i]\n elif i == n-2:\n dp[j][i] = dp[j+1][i+1]\n elif i > n-2:\n pass\n else:\n dp[j][i] = max(dp[j+1][i+1],dp[j][i+2] + a_list[i])\n print(dp[0][0])\nelse: \n dp = [[-float('inf') for _ in range(n)] for __ in range(3)]\n dp[2][-1] = a_list[-1]\n\n for j in reversed(range(3)):\n for i in reversed(range(n)):\n if j == 2 and i >= n-2:\n pass\n elif j == 2:\n dp[j][i] = dp[j][i+2] + a_list[i]\n elif i == n-2:\n dp[j][i] = dp[j+1][i+1]\n elif i > n-2:\n pass\n else:\n dp[j][i] = max(dp[j+1][i+1],dp[j][i+2] + a_list[i])\n print(dp[0][0])\n"] | ['Runtime Error', 'Accepted'] | ['s381955315', 's671545972'] | [47704.0, 48024.0] | [511.0, 510.0] | [1145, 1192] |
p02716 | u069125420 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['import sys\n\nsys.setrecursionlimit(2*1000000)\n\nN = int(input())\nA = list(map(int, input().split(" ")))\n\n\n\ndef dp(i, j):\n if i >= N:\n return (-1*1000000000)\n if (N//2)-j < (i-1)//2:\n return (-1*1000000000)\n if j == 1:\n return A[i]\n\telse:\n temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])\n dp_dict[(i, j)] = temp\n return temp\n\n\nselect = N//2\nif select == 1:\n print(max(A))\nelse:\n print(dp(0, select))', 'N = int(input())\nA = list(map(int, input().split(" ")))\n\ndp_dict = {}\n\n\ndef dp(i, j):\n print(i, j)\n if i >= N:\n return (-1*10e+9)-1\n if j == 1:\n return A[i]\n if (i, j) in dp_dict:\n return dp_dict[(i, j)]\n else:\n temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])\n dp_dict[(i, j)] = temp\n return temp\n\n\nprint(dp(0, (N//2)))', 'import sys\n\nsys.setrecursionlimit(2*1000000)\n\nN = int(input())\nA = list(map(int, input().split(" ")))\n\ndp_dict = {}\n\n\ndef dp(i, j):\n #print(i, j)\n if i >= N:\n return (-1*1000000000)\n if (N//2)-j < (i)//2:\n print(i, j)\n return (-1*1000000000)\n if j == 1:\n return A[i]\n if (i, j) in dp_dict:\n return dp_dict[(i, j)]\n else:\n temp = max([dp(i+2, j-1)+A[i], dp(i+1, j)])\n dp_dict[(i, j)] = temp\n return temp\n\n\nselect = N//2\nif select == 1:\n print(max(A))\nelse:\n print(dp(0, select))', 'N = int(input())\nA = [0]+list(map(int, input().split(" ")))\n\ndp_list = [{0, 0}, {0: 0, 1: A[1]}, {0: 0, 1: A[1] if A[1] > A[2] else A[2]}]\n\nfor i in range(3, N+1):\n b = (i-1)//2\n f = (i+1)//2\n dp_list.append({})\n for j in range(b, f+1):\n if j in dp_list[i-1]:\n dp_list[i][j] = dp_list[i-2][j-1]+A[i] if dp_list[i -\n 2][j-1]+A[i] > dp_list[i-1][j] else dp_list[i-1][j]\n else:\n dp_list[i][j] = dp_list[i-2][j-1]+A[i]\n\nprint(dp_list[-1][N//2])'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s132211468', 's474986711', 's484904429', 's283577302'] | [9044.0, 31560.0, 120036.0, 98292.0] | [21.0, 72.0, 399.0, 478.0] | [449, 372, 557, 549] |
p02716 | u114954806 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ["from functools import lru_cache\n\n@lru_cache(None)\ndef dp(N,A,i,k):\n if k<=0:\n return 0\n tmp=N-i\n if k>(tmp//2)+(tmp%2):\n return -float('inf')\n return max(A[i]+dp(N,A,i+2,k-1),dp(N,A,i+1,k))\n\ndef main():\n N=int(input())\n A=[int(_) for _ in input().split()]\n print(dp(N,A,0,N//2))\n\nmain()\n", "from math import ceil\nINF=float('inf')\n\ndef main():\n N=int(input())\n A=[int(_) for _ in input().split()]\n\n def dp(i,k):\n print(i,k)\n if k<=0:\n return 0\n tmp=N-i\n if k>ceil(tmp/2):\n return -INF\n return max(A[i]+dp(i+2,k-1),dp(i+1,k))\n\n print(dp(0,N//2))\n\nmain()", "from math import ceil\n\ndef main():\n N=int(input())\n A=[int(_) for _ in input().split()]\n\n def dp(i,k):\n print(i,k)\n if k<=0:\n return 0\n tmp=N-i\n if k>ceil(tmp/2):\n return -float('inf')\n return max(A[i]+dp(i+2,k-1),dp(i+1,k))\n\n print(dp(0,N//2))\n\nmain()", 'def main():\n N=int(input())\n A=[int(_) for _ in input().split()]\n dp=[[0,0,0] for _ in range(N//2+1)]\n for i in range(N//2):\n dp[i+1][0]=dp[i][0]+A[i*2]\n dp[i+1][1]=max(dp[i][1],dp[i][0])+A[i*2+1]\n if N%2:\n dp[i+1][2]=max(dp[i][2],dp[i][1],dp[i][0])+A[i*2+2]\n for d in dp:\n print(d)\n if N%2:\n print(max(dp[-1]))\n else:\n print(max(dp[-1][:2]))\n\nmain()\n', 'def main():\n N=int(input())\n A=[int(_) for _ in input().split()]\n dp=[[0,0,0] for _ in range(N//2+1)]\n for i in range(N//2):\n dp[i+1][0]=dp[i][0]+A[i*2]\n dp[i+1][1]=max(dp[i][1],dp[i][0])+A[i*2+1]\n if N%2:\n dp[i+1][2]=max(dp[i][2],dp[i][1],dp[i][0])+A[i*2+2]\n if N%2:\n print(max(dp[-1]))\n else:\n print(max(dp[-1][:2]))\n\nmain()\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s289876859', 's411471104', 's813407989', 's894254261', 's753765828'] | [33416.0, 32864.0, 33092.0, 42236.0, 42160.0] | [77.0, 78.0, 79.0, 282.0, 199.0] | [322, 329, 321, 425, 391] |
p02716 | u139112865 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['n = int(input())\na = list(map(int, input().split()))\n\nle, lo, re, ro = [0], [0], [0], [0]\n\nfor i in range(n):\n if i % 2 == 0:\n le.append(le[-1] + a[i])\n else:\n lo.append(lo[-1] + a[i])\n\nfor i in range(n-1, -1, -1):\n if i % 2 == 0:\n re.append(re[-1] + a[i])\n else:\n ro.append(ro[-1] + a[i])\n\nle_o = [0]\nfor i in range(len(lo)-1):\n le_o.append(max(le_o[-1], le_o[-1] + a[2*i+1] - a[2*i]))\n\nprint(le)\nprint(lo)\nprint(re)\nprint(ro)\nprint(le_o)\n\n\nif n % 2 == 0:\n n //= 2\n ans = le[n]\n for i in range(0, n + 1):\n ans = max(ans, le[i] + ro[n-i])\n\n print(ans)\n\nelse:\n n //= 2\n ans = le[n]\n for i in range(0, n+1):\n ans = max(ans, le[i] + ro[n-i])\n ans = max(ans, lo[i] + re[n-i])\n ans = max(ans, le[i] + re[n-i] + le_o[i])\n\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nle, lo, re, ro = [0], [0], [0], [0]\n\nfor i in range(n):\n if i % 2 == 0:\n le.append(le[-1] + a[i])\n else:\n lo.append(lo[-1] + a[i])\n\nfor i in range(n-1, -1, -1):\n if i % 2 == 0:\n re.append(re[-1] + a[i])\n else:\n ro.append(ro[-1] + a[i])\n\nle_o = [0]\nfor i in range(len(lo)-1):\n le_o.append(max(le_o[-1], le_o[-1] + a[2*i+1] - a[2*i]))\n\nprint(le)\nprint(lo)\nprint(re)\nprint(ro)\nprint(le_o)\n\n\nif n % 2 == 0:\n n //= 2\n ans = le[n]\n for i in range(0, n + 1):\n ans = max(ans, le[i] + ro[n-i])\n\n print(ans)\n\nelse:\n n //= 2\n ans = le[n]\n for i in range(0, n+1):\n ans = max(ans, le[i] + ro[n-i])\n ans = max(ans, lo[i] + re[n-i])\n ans = max(ans, le[i] + re[n-i] + le_o[i])\n\n print(ans)\n', 'n = int(input())\na = list(map(int, input().split()))\n\nle, lo, re, ro = [0], [0], [0], [0]\n\nfor i in range(n):\n if i % 2 == 0:\n le.append(le[-1] + a[i])\n else:\n lo.append(lo[-1] + a[i])\n\nfor i in range(n-1, -1, -1):\n if i % 2 == 0:\n re.append(re[-1] + a[i])\n else:\n ro.append(ro[-1] + a[i])\n\nle_o = [0]\nfor i in range(len(lo)-1):\n le_o.append(max(0, le_o[-1] + a[2*i+1] - a[2*i]))\n\nprint(le)\nprint(lo)\nprint(re)\nprint(ro)\nprint(le_o)\n\nif n % 2 == 0:\n n //= 2\n ans = 0\n for i in range(0, n + 1):\n ans = max(ans, le[i] + ro[n-i])\n\n print(ans)\n\nelse:\n n //= 2\n ans = 0\n for i in range(0, n+1):\n ans = max(ans, le[i] + ro[n-i])\n ans = max(ans, lo[i] + re[n-i])\n ans = max(ans, le[i] + re[n-i])\n if i != 0:\n ans = max(ans, le[i] + re[n-i] + le_o[i])\n\n print(ans)', 'n = int(input())\na = list(map(int, input().split()))\n\nle, lo, re, ro = [0], [0], [0], [0]\n\nfor i in range(n):\n if i % 2 == 0:\n le.append(le[-1] + a[i])\n else:\n lo.append(lo[-1] + a[i])\n\nfor i in range(n-1, -1, -1):\n if i % 2 == 0:\n re.append(re[-1] + a[i])\n else:\n ro.append(ro[-1] + a[i])\n\nle_o = [0]\nfor i in range(len(lo)-1):\n le_o.append(max(0, le_o[-1] + a[2*i+1] - a[2*i]))\n\n\nif n % 2 == 0:\n n //= 2\n ans = lo[n]\n for i in range(0, n + 1):\n ans = max(ans, le[i] + ro[n-i])\n\n print(ans)\n\nelse:\n n //= 2\n ans = le[n]\n for i in range(0, n+1):\n ans = max(ans, le[i] + ro[n-i])\n ans = max(ans, lo[i] + re[n-i])\n ans = max(ans, le[i] + re[n-i] + le_o[i])\n\n print(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s210825145', 's463265493', 's871074206', 's315057409'] | [48964.0, 49084.0, 51032.0, 45760.0] | [376.0, 391.0, 459.0, 322.0] | [823, 823, 869, 763] |
p02716 | u163320134 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['n=int(input())\narr=list(map(int,input().split()))\nlim=n%2+2\ndp=[[0]*lim for _ in range(n+100)]\nfor i in range(n):\n dp[i+1][0]=dp[i-1][0]+arr[i]\n dp[i+1][1]=max(dp[i-1][1]+arr[i],dp[i-2][0]+arr[i])\n if lim==3:\n dp[i+1][2]=max(dp[i-1][2]+arr[i],dp[i-2][1]+arr[i],dp[i-3][0]+arr[i])\nprint(max(dp[-1][:lim]))', 'n=int(input())\narr=list(map(int,input().split()))\nacum1=[0]\nacum2=[0]\nfor i in range(n):\n if i%2==0:\n acum1.append(acum1[-1]+arr[i])\n acum2.append(acum2[-1]+0)\n else:\n acum1.append(acum1[-1]+0)\n acum2.append(acum2[-1]+arr[i])\nif n%2==0:\n ans=max(acum1[n-1]-acum1[0],acum2[n]-acum2[1])\n for i in range(1,n+1,2):\n if i+3>n:\n continue\n tmp=(acum1[i]-acum1[0])+(acum2[n]-acum2[i+2])\n ans=max(ans,tmp)\nelse:\n ans=max(acum1[n-2]-acum1[0],acum2[n-1]-acum2[1],acum1[n]-acum1[2])\n for i in range(1,n+1,2):\n if i+3>n-1:\n continue\n tmp=(acum1[i]-acum1[0])+(acum2[n-1]-acum2[i+2])\n ans=max(ans,tmp)\n for i in range(2,n+1,2):\n if i+3>n:\n continue\n tmp=(acum2[i]-acum2[1])+(acum1[n]-acum1[i+2])\n ans=max(ans,tmp)\n for i in range(1,n+1,2):\n if i+4>n:\n continue\n tmp=(acum1[i]-acum1[0])+(acum1[n]-acum1[i+3])\n ans=max(ans,tmp)\n acummax=[-10**18]\n for i in range(1,n+1):\n if i+2>n:\n acummax.append(-10**18)\n else:\n if i%2==0:\n acummax.append(acum2[i]+acum1[n]-acum1[i+2])\n else:\n acummax.append(-10**18)\n for i in range(n-1,-1,-1):\n acummax[i]=max(acummax[i],acummax[i+1])\n for i in range(1,n+1,2):\n if i+6>n:\n continue\n tmp=(acum1[i]-acum1[0]-acum2[i+2])+acummax[i+3]\n ans=max(ans,tmp)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s182882969', 's136981222'] | [66060.0, 45220.0] | [418.0, 463.0] | [310, 1312] |
p02716 | u227082700 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['n,*l=open(0);n=int(n);l=list(map(int,l.split()))\np=[0]*n;d=[0]*n\nfor i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2])\nprint(d[-1])', 'n,*l=open(0);n=int(n);l=list(map(int,l))\np=[0]*n;d=[0]*n\nfor i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2])\nprint(d[-1])', 'n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n\nfor i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]*(i&1)+d[i-1]*(i&1),l[i]+d[i-2])\nprint(d[-1])', 'n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n\nfor i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if i&1else d[i-1],l[i]+d[i-2])\nprint(d[-1])'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s192243126', 's601627978', 's998357540', 's188496920'] | [12924.0, 13376.0, 39000.0, 39404.0] | [25.0, 38.0, 235.0, 208.0] | [159, 151, 159, 157] |
p02716 | u268554510 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ["N = int(input())\nA = list(map(int,input().split()))\ndp = [{} for _ in range(N+1)]\nINF = -float('inf')\nfor i in range(1,N+1):\n mid = i//2\n dp[i][mid-2],dp[i][mid-1],dp[i][mid],dp[i][mid+1],dp[i][mid+2]=INF,INF,INF,INF,INF\ndp[1][1] = A[0]\ndp[2][1] = max(A[1],dp[1][1])\ndp[1][0],dp[2][0]=0,0\n\nfor i in range(2,N):\n a = A[i]\n ma = (i+2)//2\n mi = i//2\n dp[i+1][ma] = max(dp[i][ma],dp[i-1][ma-1]+a)\n dp[i+1][mi] = max(dp[i][mi],dp[i-1][mi-1]+a)\n\nprint(dp[-1][N//2])\nprint(dp)", "N = int(input())\nA = list(map(int,input().split()))\ndp = [{} for _ in range(N+1)]\nINF = -float('inf')\nfor i in range(1,N+1):\n mid = i//2\n dp[i][mid-2],dp[i][mid-1],dp[i][mid],dp[i][mid+1],dp[i][mid+2]=INF,INF,INF,INF,INF\ndp[1][1] = A[0]\ndp[2][1] = max(A[1],dp[1][1])\ndp[1][0],dp[2][0]=0,0\n\nfor i in range(2,N):\n a = A[i]\n ma = (i+2)//2\n mi = i//2\n dp[i+1][ma] = max(dp[i][ma],dp[i-1][ma-1]+a)\n dp[i+1][mi] = max(dp[i][mi],dp[i-1][mi-1]+a)\n\nprint(dp[-1][N//2])"] | ['Wrong Answer', 'Accepted'] | ['s052516738', 's898269375'] | [164352.0, 116416.0] | [743.0, 517.0] | [480, 470] |
p02716 | u294375415 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ["\n\nn = 0\na = []\n\ndef format_input(filename = None):\n\tglobal n\n\tglobal a\n\tif filename == None:\n\t\tn = int(input())\n\t\ta = list(map(int, input().split()))\n\n\telif filename == '__random__':\n\t\tfrom random import randint as rng\n\t\tn = rng(2, 2 * 10**5)\n\t\ta = [rng(-1 * 10**9, 10**9) for i in range(n)]\n\t\tprint(n)\n\t\tprint(' '.join(list(map(str, a))))\n\ndef get_answer():\n\todd = [0]\n\teven = [0]\n\tfor i in range(n // 2):\n\t\todd.append(odd[-1] + a[2*i])\n\t\teven.append(even[-1] + a[2*i+1])\n\tif n % 2 == 1:\n\t\todd.append(odd[-1] + a[-1])\n\n\tprint(odd)\n\tprint(even)\n\tanswer = -1 * 10**9 * n\n\tif n % 2 == 0:\n\t\tfor i in range(n // 2 + 1):\n\t\t\tanswer = max(answer, odd[i] - even[i] + even[-1])\n\telse:\n\t\tfor i in range(n // 2 + 2):\n\t\t\tif i < n // 2 + 1:\n\t\t\t\tfor j in range(i+1):\n\t\t\t\t\tanswer = max(answer, odd[j] - even[j] + even[i] - odd[i+1] + odd[-1])\n\t\t\telse:\n\t\t\t\tfor j in range(i):\n\t\t\t\t\tanswer = max(answer, odd[j] - even[j] + even[-1])\n\treturn answer\n\nif __name__ == '__main__':\n\tformat_input()\n\n\tans = get_answer()\n\tprint(ans)\n", "\n\nn = 0\na = []\n\ndef format_input(filename = None):\n\tglobal n\n\tglobal a\n\tif filename == None:\n\t\tn = int(input())\n\t\ta = list(map(int, input().split()))\n\n\telif filename == '__random__':\n\t\tfrom random import randint as rng\n\t\tn = rng(2, 2 * 10**5)\n\t\ta = [rng(-1 * 10**9, 10**9) for i in range(n)]\n\t\tprint(n)\n\t\tprint(' '.join(list(map(str, a))))\n\ndef get_answer():\n\todd = [0]\n\teven = [0]\n\tfor i in range(n // 2):\n\t\todd.append(odd[-1] + a[2*i])\n\t\teven.append(even[-1] + a[2*i+1])\n\tif n % 2 == 1:\n\t\todd.append(odd[-1] + a[-1])\n\n\tanswer = -1 * 10**9 * n\n\tif n % 2 == 0:\n\t\tfor i in range(n // 2 + 1):\n\t\t\tanswer = max(answer, odd[i] - even[i] + even[-1])\n\telse:\n\t\teven_range = [even[0] - odd[1]]\n\t\tfor i in range(n // 2):\n\t\t\tadd = a[2*i+1] - a[2*i+2]\n\t\t\tmin = - a[2*i] + add\n\t\t\teven_range.append(max(even_range[-1] + add, min))\n\t\tanswer = odd[-1] + max(even_range)\n\treturn answer\n\nif __name__ == '__main__':\n\tformat_input()\n\n\tans = get_answer()\n\tprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s255651065', 's606853797'] | [32444.0, 33760.0] | [2210.0, 154.0] | [1007, 946] |
p02716 | u303739137 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['input()\naa = map(int, input().split())\n\nbb = [0] * len(aa)\nbb[0] = aa[0]\nbb[1] = aa[1]\nfor i in range(2,len(aa)):\n bb[i] = bb[i-2] + aa[i]\n\nsum0 = bb[len(aa)-2]\nsum1 = bb[len(aa)-1]\nret = sum1\nif len(aa)%2 == 0:\n ret = max(ret, sum0)\nif len(aa)%2:\n sum0 = bb[len(aa)-1]\n sum1 = bb[len(aa)-2]\n for i in range(len(aa)//2):\n ret = max(ret, sum0 - aa[2*i])\n\n# 0 -> 1\nfor i in range(0,len(aa)//2):\n try:\n\n ret = max(ret, bb[i] - bb[i+3] + sum1 + aa[i+3] )\n except:\n 0\n# 1 -> 0\nfor i in range(0,len(aa)//2):\n try:\n\n ret = max(ret, bb[2*i+1] - bb[2*i+4] + sum0 + aa[2*i+4] )\n except:\n 0\nprint(ret)', 'bb = [0] * len(aa)\nbb[0] = aa[0]\nbb[1] = aa[1]\nfor i in range(2,len(aa)):\n bb[i] = bb[i-2] + aa[i]\n\nsum0 = bb[len(aa)-2]\nsum1 = bb[len(aa)-1]\nret = sum1\nif len(aa)%2 == 0:\n ret = max(ret, sum0)\nif len(aa)%2:\n sum0 = bb[len(aa)-1]\n sum1 = bb[len(aa)-2]\n for i in range(len(aa)//2):\n ret = max(ret, sum0 - aa[2*i])\n\n# 0 -> 1\nfor i in range(0,len(aa)//2):\n try:\n\n ret = max(ret, bb[i] - bb[i+3] + sum1 + aa[i+3] )\n except:\n 0\n# 1 -> 0\nfor i in range(0,len(aa)//2):\n try:\n\n ret = max(ret, bb[2*i+1] - bb[2*i+4] + sum0 + aa[2*i+4] )\n except:\n 0\nprint(ret)', 'input()\naa = list(map(int, input().split()))\nstate = {(0,False)}\nskipmax = len(aa)%2 + 1\nstate_all = {(i, True) for i in range(skipmax+1)}.union({(j, False) for j in range(skipmax+1)})\ndp_0 = {a:None for a in state_all }\ndp_0[(0,False)] = 0\nskipcount = 0\n\ndef getmax(a, b):\n if a is None:\n return b\n if b is None:\n return a\n return max(a,b)\n\nfor i,a in enumerate(aa):\n dp_1 = {}\n for s in state_all:\n if s[1] & (dp_0[(s[0], False)] is not None):\n dp_1[s] = dp_0[(s[0], False)] + a\n continue\n dp_1[s] = getmax(dp_0[(s[0], True)], dp_0.get((s[0]-1, False), None))\n dp_0 = dp_1.copy()\nif len(aa)%2:\n print(getmax(dp_0[(2,True)], dp_0[(1,False)]))\nelse:\n print(getmax(dp_0[(1,True)], dp_0[(0,False)]))\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s548118920', 's563228121', 's215239376'] | [25032.0, 9200.0, 33088.0] | [44.0, 20.0, 710.0] | [768, 728, 772] |
p02716 | u391540332 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['import collections\nimport math\n\nN, *A = map(int, open(0).read().split())\na = dict(enumerate(A, 1))\ndp = collections.defaultdict(int)\ndp[1, 1] = a[1]\n\nfor i in range(2, N + 1):\n jj = range(math.floor(i // 2 - 1), math.ceil((i + 1) // 2) + 1)\n debug(jj)\n for j in jj:\n x = dp[i - 2, j - 1] + a[i]\n y = dp[i - 1, j]\n dp[i, j] = max(x, y)\n\nprint(dp[N, N // 2])', '#!/usr/bin/env python3\n# coding: utf-8\nimport collections\ndef debug(arg):\n if __debug__:\n pass\n else:\n import sys\n print(arg, file=sys.stderr)\n\ndef main():\n pass\n N, *A = map(int, open(0).read().split())\n a = dict(enumerate(A, 1))\n dp = collections.defaultdict(lambda: -float("inf"))\n dp[0, 0] = 0 \n dp[1, 0] = 0 \n dp[1, 1] = a[1]\n for i in range(2, N + 1):\n jj = range(max(i // 2 - 1, 1), (i + 1) // 2 + 1)\n for j in jj:\n x = dp[i - 2, j - 1] + a[i]\n y = dp[i - 1, j]\n dp[i, j] = max(x, y)\n print(dp[N, N // 2])\n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s718724963', 's231804797'] | [41532.0, 155584.0] | [91.0, 646.0] | [386, 652] |
p02716 | u391731808 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['N = int(input())\n*A, = map(int,input().split())\n\nif N%2==0:\n 1/0\n ans = max(sum(A[::2]),sum(A[1::2]))\n print(ans)\nelse:\n INF = 2* 10**9\n dp = [[-INF]*N for _ in [0]*3]\n dp[0][0] = A[0]\n dp[1][1] = A[1]\n dp[2][2] = A[2]\n for i in range(2,N,2):\n a = A[i]\n dp[0][i] = dp[0][i-2] + a\n for i in range(3,N):\n a = A[i]\n dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a\n for i in range(4,N,2):\n a = A[i]\n dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a\n print(dp[2][-1])', 'N = int(input())\n*A, = map(int,input().split())\n\nif N%2==0:\n INF = 2* 10**9\n dp = [[-INF]*N for _ in [0]*2]\n dp[0][0] = A[0]\n dp[1][1] = A[1]\n for i in range(2,N,2):\n a = A[i]\n dp[0][i] = dp[0][i-2] + a\n for i in range(3,N):\n a = A[i]\n dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a\n print(max(dp[1][-1],dp[0][-2]))\nelse:\n INF = 2* 10**9\n dp = [[-INF]*N for _ in [0]*3]\n dp[0][0] = A[0]\n dp[1][1] = A[1]\n dp[2][2] = A[2]\n for i in range(2,N,2):\n a = A[i]\n dp[0][i] = dp[0][i-2] + a\n for i in range(3,N):\n a = A[i]\n dp[1][i] = max(dp[1][i-2],dp[0][i-3]) + a\n for i in range(4,N,2):\n a = A[i]\n dp[2][i] = max(dp[2][i-2],dp[1][i-3],dp[0][i-4]) + a\n print(max(dp[2][-1],dp[1][-2],dp[0][-3]))'] | ['Runtime Error', 'Accepted'] | ['s338397064', 's180746595'] | [41024.0, 41036.0] | [250.0, 253.0] | [538, 800] |
p02716 | u392319141 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['N = int(input())\nA = list(map(int, input().split()))\nINF = 10**18\n\ndp0 = [-INF] * (N + 2)\ndp1 = [-INF] * (N + 2)\ndp2 = [-INF] * (N + 2)\ndp0[0] = 0\ndp0[1] = 0\n\nfor i, a in enumerate(A, start=2):\n dp0[i] = dp0[i - 2] + a\n dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])\n dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 2])\n\nif N % 2 == 1:\n print(dp2[-1])\nelse:\n print(max(dp1[-1], dp0[-2]))\n', 'N = int(input())\nA = list(map(int, input().split()))\nINF = 10**18\n\ndp0 = [-INF] * (N + 2)\ndp1 = [-INF] * (N + 2)\ndp2 = [-INF] * (N + 2)\ndp0[0] = 0\ndp1[0] = 0\n\nfor i, a in enumerate(A, start=2):\n dp0[i] = dp0[i - 2] + a\n dp1[i] = max(dp1[i - 2] + a, dp0[i - 1])\n dp2[i] = max(dp2[i - 2] + a, dp1[i - 1], dp0[i - 3])\n\nif N % 2 == 1:\n print(dp2[-1])\nelse:\n print(max(dp1[-1], dp0[-1]))\n', 'N = int(input())\nA = list(map(int, input().split()))\nINF = 10**18\n\ndp0 = 0\ndp1 = -INF\ndp2 = -INF\n\nfor i, a in enumerate(A):\n if i % 2 == 0:\n dp1 = max(dp1, dp0)\n dp0 += a\n dp2 += a\n else:\n dp2 = max(dp2, dp1)\n dp1 += a\n\nif N % 2 == 1:\n print(max(dp1, dp2))\nelse:\n print(max(dp0, dp1))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s525835257', 's682936791', 's478783629'] | [50260.0, 50160.0, 31684.0] | [269.0, 276.0, 152.0] | [398, 398, 332] |
p02716 | u446774692 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['N = int(input())\nA = list(map(int,input().split()))\n\nDP = [0,0,0]\nm = N//2*2\nif N%2 == 0:\n for i in range(0,m,2):\n DP[0] += A[i]\n DP[1] += A[i+1]\n DP[1] += max(DP[0],DP[1])\n\n print(DP[1])\n\nelse:\n for i in range(0,m,2):\n DP[0] += A[i]\n DP[1] += A[i+1]\n DP[2] += A[i+2]\n\n DP[1] = max(DP[0],DP[1])\n DP[2] = max(DP[1],DP[2])\n\n print(DP[2])\n', 'N = int(input())\nA = list(map(int,input().split()))\n\nDP = [0,0,0]\nm = N//2*2\nif N%2 == 0:\n for i in range(0,m,2):\n DP[0] += A[i]\n DP[1] += A[i+1]\n DP[1] = max(DP[0],DP[1])\n\n print(DP[1])\n\nelse:\n for i in range(0,m,2):\n DP[0] += A[i]\n DP[1] += A[i+1]\n DP[2] += A[i+2]\n\n DP[1] = max(DP[0],DP[1])\n DP[2] = max(DP[1],DP[2])\n\n print(DP[2])\n'] | ['Wrong Answer', 'Accepted'] | ['s212082048', 's076503237'] | [31232.0, 31540.0] | [426.0, 158.0] | [404, 403] |
p02716 | u543954314 | 2,000 | 1,048,576 | Given is an integer sequence A_1, ..., A_N of length N. We will choose exactly \left\lfloor \frac{N}{2} \right\rfloor elements from this sequence so that no two adjacent elements are chosen. Find the maximum possible sum of the chosen elements. Here \lfloor x \rfloor denotes the greatest integer not greater than x. | ['#![allow(unused_imports, non_snake_case)]\nuse proconio::{\n input, fastout,\n marker::{Chars, Bytes, Usize1}\n};\n\nmacro_rules! max {($ a : expr $ (, ) * ) => {{$ a } } ; ($ a : expr , $ b : expr $ (, ) * ) => {{std :: cmp :: max ($ a , $ b ) } } ; ($ a : expr , $ ($ rest : expr ) ,+ $ (, ) * ) => {{std :: cmp :: max ($ a , max ! ($ ($ rest ) ,+ ) ) } } ; }\n\n\nfn main() {\n input! {\n n: usize,\n a: [usize; n]\n }\n let mut dp = vec![vec![0; 3]; n+4];\n for i in 0..n{\n dp[i + 4][0] = dp[i + 2][0] + a[i];\n dp[i + 4][1] = max!(dp[i+2][1], dp[i+1][0]) + a[i];\n if n & 1 > 0 {\n dp[i + 4][2] = max!(dp[i + 2][2], dp[i + 1][1], dp[i][0]) + a[i];\n }\n }\n if n & 1 > 0 {\n println!("{}", max!(dp[n+1][0], dp[n+2][1], dp[n+3][2]));\n } else {\n println!("{}", max!(dp[n+2][0], dp[n+3][1]));\n }\n}', 'import sys\n\nstdin = sys.stdin\n\nns = lambda: stdin.readline().rstrip()\nni = lambda: int(stdin.readline().rstrip())\nnm = lambda: map(int, stdin.readline().split())\nnl = lambda: list(map(int, stdin.readline().split()))\n\nn = ni()\na = nl()\ndp = [[0]*3 for _ in range(n+5)]\nt = n%2\nfor i in range(n):\n dp[i][0] = dp[i-2][0] + a[i]\n dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + a[i]\n if t:\n dp[i][2] = max(dp[i-2][2], dp[i-3][1], dp[i-4][0]) + a[i]\nif t:\n print(max(dp[n-3][0], dp[n-2][1], dp[n-1][2]))\nelse:\n print(max(dp[n-2][0], dp[n-1][1]))\n'] | ['Runtime Error', 'Accepted'] | ['s439363569', 's001427685'] | [8920.0, 66404.0] | [28.0, 382.0] | [884, 556] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.