problem_id
int64
0
4.72k
problem_content
stringlengths
152
5.64k
code_prompt
stringclasses
1 value
difficulty
stringclasses
3 values
solutions
stringlengths
98
1.12M
test_cases
stringlengths
70
1.03M
4,683
Given are N integers A_1,\ldots,A_N. Find the sum of A_i \times A_j over all pairs (i,j) such that 1\leq i < j \leq N, modulo (10^9+7). -----Constraints----- - 2 \leq N \leq 2\times 10^5 - 0 \leq A_i \leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following f...
introductory
[{"code": "def main():\n N=int(input())\n CONST= 10**9+7\n Output = 0\n lis = list(map(int,input().split())) \n lis.sort()\n SumLis = [0]*N\n for i,item in enumerate(lis):\n SumLis[i] += SumLis[i-1]+item\n for i,item in enumerate(lis):\n Output += lis[i] * (SumLis[-1]-SumLis[i])\n O...
[{"input": "3\n1 2 3\n", "output": "11\n"}, {"input": "4\n141421356 17320508 22360679 244949\n", "output": "437235829\n"}]
4,684
AtCoDeer has three cards, one red, one green and one blue. An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card. We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer. Is this inte...
introductory
[{"code": "rgb = list(map(int, input().split()))\n\nl = ''.join(str(n) for n in rgb)\nif int(l)%4 == 0:\n print('YES')\nelse:\n print('NO')", "passed": true, "time": 0.26, "memory": 14012.0, "status": "done"}, {"code": "r, g, b = list(map(int, input().split()))\nprint((\"YES\" if (r * 100 + g * 10 + b) % 4 == 0 e...
[{"input": "4 3 2\n", "output": "YES\n"}, {"input": "2 3 4\n", "output": "NO\n"}]
4,685
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: - Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the largest possible sum of the integers written on the blackboard after K ...
introductory
[{"code": "a,b,c=list(map(int,input().split()))\nk=int(input())\n\nx=max(a,b,c)\n\nprint(((a+b+c)-x+x*(2**k)))\n", "passed": true, "time": 0.14, "memory": 14196.0, "status": "done"}, {"code": "a,b,c=map(int,input().split())\nk=int(input())\nprint(a+b+c+max(a,b,c)*(2**k-1))", "passed": true, "time": 0.24, "memory": 1424...
[{"input": "5 3 11\n1\n", "output": "30\n"}, {"input": "3 3 4\n2\n", "output": "22\n"}]
4,686
Let w be a string consisting of lowercase letters. We will call w beautiful if the following condition is satisfied: - Each lowercase letter of the English alphabet occurs even number of times in w. You are given the string w. Determine if w is beautiful. -----Constraints----- - 1 \leq |w| \leq 100 - w consists of ...
introductory
[{"code": "import sys\nimport string\nw = input()\na_z = string.ascii_letters\nfor i in a_z:\n if w.count(i) & 1:\n print('No')\n return\nprint('Yes')", "passed": true, "time": 0.16, "memory": 14352.0, "status": "done"}, {"code": "# import math\n# import statistics\na=input()\n#b,c=int(input()),int(inp...
[{"input": "abaccaba\n", "output": "Yes\n"}, {"input": "hthth\n", "output": "No\n"}]
4,687
There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \{1,2,...
introductory
[{"code": "n, k = list(map(int, input().split()))\nab = [list(map(int, input().split())) for _ in range(n)]\n\nab.sort()\n\nnum_sum = 0\n\nfor a, b in ab:\n num_sum += b\n if num_sum >= k:\n print(a)\n return\n", "passed": true, "time": 0.15, "memory": 14360.0, "status": "done"}, {"code": "N, K = ma...
[{"input": "3 4\n1 1\n2 2\n3 3\n", "output": "3\n"}, {"input": "10 500000\n1 100000\n1 100000\n1 100000\n1 100000\n1 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n100000 100000\n", "output": "1\n"}]
4,688
There are N balls placed in a row. AtCoDeer the deer is painting each of these in one of the K colors of his paint cans. For aesthetic reasons, any two adjacent balls must be painted in different colors. Find the number of the possible ways to paint the balls. -----Constraints----- - 1≦N≦1000 - 2≦K≦1000 - The corre...
introductory
[{"code": "n,k=map(int,input().split())\nprint(k*(k-1)**(n-1))", "passed": true, "time": 0.16, "memory": 14048.0, "status": "done"}, {"code": "n, k = list(map(int, input().split()))\nprint((k*pow(k-1, n-1)))\n", "passed": true, "time": 0.15, "memory": 14296.0, "status": "done"}, {"code": "N,K = map(int,input().split())...
[{"input": "2 2\n", "output": "2\n"}, {"input": "1 10\n", "output": "10\n"}]
4,689
There is a circular pond with a perimeter of K meters, and N houses around them. The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond. When traveling between these houses, you can only go around the pond. Find the minimum distance that needs to be ...
introductory
[{"code": "k, n = map(int, input().split())\npoints = list(map(int, input().split()))\n\ndist = []\nfor i in range(n):\n if i != n-1:\n distance = points[i+1] - points[i]\n else:\n distance = points[0]+k - points[i]\n dist.append(distance)\n\nmax = dist[0]\nfor j in range(1, len(dist), 1):\n i...
[{"input": "20 3\n5 10 15\n", "output": "10\n"}, {"input": "20 3\n0 5 15\n", "output": "10\n"}]
4,690
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the re...
introductory
[{"code": "a,b,c,d=map(int, input().split()) \nprint(max(a*b,c*d))", "passed": true, "time": 0.15, "memory": 14064.0, "status": "done"}, {"code": "A, B, C, D = map(int, input().split())\n\nS1 = A * B\nS2 = C * D\n\nprint(max(S1, S2))", "passed": true, "time": 0.15, "memory": 14128.0, "status": "done"}, {"code": "a,b,...
[{"input": "3 5 2 7\n", "output": "15\n"}, {"input": "100 600 200 300\n", "output": "60000\n"}]
4,691
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is AC, WA,...
introductory
[{"code": "c = int(input())\n\nr = [\"AC\", \"WA\", \"TLE\", \"RE\"]\na = { i:0 for i in r}\n\nfor i in range(c):\n s = input()\n a [s] += 1\n\nfor rr in r:\n print(rr + \" x \" + str(a[rr]))", "passed": true, "time": 0.18, "memory": 14288.0, "status": "done"}, {"code": "n = int(input())\nl = []\nfor i in rang...
[{"input": "6\nAC\nTLE\nAC\nAC\nWA\nTLE\n", "output": "AC x 3\nWA x 1\nTLE x 2\nRE x 0\n"}, {"input": "10\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\nAC\n", "output": "AC x 10\nWA x 0\nTLE x 0\nRE x 0\n"}]
4,692
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December? -----Constraints----- - 1≤M≤23 - M is an integer. -----Input----- Input is given from Standard Input in the following format: M -----Output----- If we have x hours until New Year at M o'clock on 30th, December, print x. --...
introductory
[{"code": "time=int(input())\nAns=48-time\nprint(Ans)", "passed": true, "time": 0.15, "memory": 14228.0, "status": "done"}, {"code": "#\u300012\u670830\u65e5\u306eM\u6642\u304b\u3089\u6b21\u306e\u5e74\u306b\u306a\u308b\u307e\u3067\u306f\u4f55\u6642\u9593\u304b\u3001\u6c42\u3081\u3066\u304f\u3060\u3055\u3044\u3002\n\nM ...
[{"input": "21\n", "output": "27\n"}, {"input": "12\n", "output": "36\n"}]
4,693
You are given two integers A and B as the input. Output the value of A + B. However, if A + B is 10 or greater, output error instead. -----Constraints----- - A and B are integers. - 1 ≤ A, B ≤ 9 -----Input----- Input is given from Standard Input in the following format: A B -----Output----- If A + B is 10 or great...
introductory
[{"code": "# A - Restricted\n# https://atcoder.jp/contests/abc063/tasks/abc063_a\n\nA, B = list(map(int, input().split()))\n\nresult = A + B\nif result >= 10:\n print('error')\nelse:\n print(result)\n", "passed": true, "time": 0.36, "memory": 14304.0, "status": "done"}, {"code": "l = input().split()\n\nans = int(...
[{"input": "6 3\n", "output": "9\n"}, {"input": "6 4\n", "output": "error\n"}]
4,694
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts. There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses. Find the minimum distance to be traveled when AtCoDeer can start an...
introductory
[{"code": "N=int(input())\nA=list(map(int, input().split()))\n\nprint(max(A)-min(A))", "passed": true, "time": 0.15, "memory": 14100.0, "status": "done"}, {"code": "n = int(input())\nli = list(map(int,input().split()))\nli.sort()\nprint(li[-1]-li[0])", "passed": true, "time": 0.2, "memory": 14316.0, "status": "done"}, ...
[{"input": "4\n2 3 7 9\n", "output": "7\n"}, {"input": "8\n3 1 4 1 5 9 2 6\n", "output": "8\n"}]
4,695
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group. -----Constraints----- - x and y are integers. - 1 ≤ x < y ≤ 12 -----Input----- Input is given from Stand...
introductory
[{"code": "n1 = [1, 3, 5, 7, 8, 10, 12]\nn2 = [4, 6, 9, 11]\n\na, b = list(map(int, input().split()))\nprint((\"Yes\" if a in n1 and b in n1 or a in n2 and b in n2 else \"No\"))\n", "passed": true, "time": 0.15, "memory": 14144.0, "status": "done"}, {"code": "lst1 = [4,6,9,11]\nlst2 = [2]\nlst3 = [1,3,5,7,8,10,12]\nx,y...
[{"input": "1 3\n", "output": "Yes\n"}, {"input": "2 4\n", "output": "No\n"}]
4,696
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. -----Constraints----- - 1 ≤ a,b ≤ 10000 - a and b are integers. -----Input----- Input is given from Standard Input in the following format: a b -----Output----- If the product is odd, print Odd; if it i...
introductory
[{"code": "a, b = map(int, input().split())\nif a*b %2 == 0:\n print(\"Even\")\nelse:\n print(\"Odd\")", "passed": true, "time": 0.33, "memory": 14224.0, "status": "done"}, {"code": "a, b = map(int, input().split())\nif a % 2 == 0:\n print('Even')\nelif b % 2 == 0:\n print('Even')\nelse:\n print('Odd')", "pass...
[{"input": "3 4\n", "output": "Even\n"}, {"input": "1 21\n", "output": "Odd\n"}]
4,697
Snuke loves puzzles. Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below: Snuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces. Find the m...
introductory
[{"code": "n, m = [int(x) for x in input().split()]\nans = min(n, m // 2)\nans += (m - ans * 2) // 4\nprint(ans)", "passed": true, "time": 1.98, "memory": 14164.0, "status": "done"}, {"code": "N,M=map(int,input().split())\nans=0\nif 2*N<=M:\n ans+=N\n M-=2*N\nelse:\n ans+=(M//2)\n M-=(M//2)*2\nans+=(M//4)\nprint(an...
[{"input": "1 6\n", "output": "2\n"}, {"input": "12345 678901\n", "output": "175897\n"}]
4,698
Joisino is about to compete in the final round of a certain programming competition. In this contest, there are N problems, numbered 1 through N. Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N). Also, there are M kinds of drinks offered to the contestants, numbered 1 through M. If Joisino takes dr...
introductory
[{"code": "N = int(input())\nT = [int(TN) for TN in input().split()]\nSumT = sum(T)\nM = int(input())\nPX = [[] for TM in range(0,M)]\nfor TM in range(0,M):\n PX[TM] = [int(TPX) for TPX in input().split()]\nfor TM in range(0,M):\n print(SumT-T[PX[TM][0]-1]+PX[TM][1])", "passed": true, "time": 0.15, "memory": 1411...
[{"input": "3\n2 1 4\n2\n1 1\n2 3\n", "output": "6\n9\n"}, {"input": "5\n7 2 3 8 5\n3\n4 2\n1 7\n4 13\n", "output": "19\n25\n30\n"}]
4,699
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very pa...
introductory
[{"code": "import itertools\n\ndef cal(N, target_num, keta):\n answer = float('inf')\n for p in itertools.product(target_num, repeat=keta):\n temp = 0\n for i, num in enumerate(p):\n temp += num * 10**i\n \n if temp >= N:\n answer = min(answer, temp)\n\n re...
[{"input": "1000 8\n1 3 4 5 6 7 8 9\n", "output": "2000\n"}, {"input": "9999 1\n0\n", "output": "9999\n"}]
4,700
There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i. There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j. Obs. i is said to be good when its elevation is higher than those of all observatories that can be re...
introductory
[{"code": "N,M = map(int,input().split())\nhigh = list(map(int,input().split()))\nans = [0]*N\ncnt = 0\nfor i in range(M):\n a,b = map(int,input().split())\n ans[a-1] = max(high[b-1],ans[a-1])\n ans[b-1] = max(ans[b-1],high[a-1])\n\nfor j in range(N):\n if ans[j] < high[j]:\n cnt += 1\nprint(cnt)", "...
[{"input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n", "output": "2\n"}, {"input": "6 5\n8 6 9 1 2 1\n1 3\n4 2\n4 3\n4 6\n4 6\n", "output": "3\n"}]
4,701
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: - Operation A: The displayed value is doubled. - Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minim...
introductory
[{"code": "#!/usr/bin/env python3\nimport sys\nsys.setrecursionlimit(10**6)\n\nn = int(input())\nk = int(input())\n\nans = 1\nfor i in range(n):\n if ans*2 <= (ans+k):\n ans *= 2\n else:\n ans += k\n # print(ans)\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14156.0, "status": "done"}, ...
[{"input": "4\n3\n", "output": "10\n"}, {"input": "10\n10\n", "output": "76\n"}]
4,702
Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. -----Constraints----- - 0 \leq x \leq 1 - x is an integer -----Input----- Input is given from Standard Input in the following format: x -----Output----- Print 1 if x is equal...
introductory
[{"code": "X=int(input())\nprint(1-X)", "passed": true, "time": 0.27, "memory": 14060.0, "status": "done"}, {"code": "x = int(input())\nprint(1 if x == 0 else 0)", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}, {"code": "num = int(input())\nif num == 0:\n print(1)\nelif num == 1:\n print(0)",...
[{"input": "1\n", "output": "0\n"}, {"input": "0\n", "output": "1\n"}]
4,703
You are given a string S consisting of digits between 1 and 9, inclusive. You can insert the letter + into some of the positions (possibly none) between two letters in this string. Here, + must not occur consecutively after insertion. All strings that can be obtained in this way can be evaluated as formulas. Evaluate a...
introductory
[{"code": "import copy\n\ns=input()\nl=len(s)\nans=0\n\nif l==1:\n ans+=int(s)\n print(ans)\n \nelse:\n for i in range(2**(l-1)):\n t=copy.deepcopy(s)\n f=[]\n ch=0\n for j in range(l-1):\n if ((i>>j)&1):\n t=t[:j+1+ch]+'+'+t[j+1+ch:]\n ch+=1\n \n if '+' in t:\n \n y=...
[{"input": "125\n", "output": "176\n"}, {"input": "9999999999\n", "output": "12656242944\n"}]
4,704
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the ...
introductory
[{"code": "import sys\nimport itertools\n\nsys.setrecursionlimit(10 ** 8)\nini = lambda: int(sys.stdin.readline())\ninl = lambda: [int(x) for x in sys.stdin.readline().split()]\nins = lambda: sys.stdin.readline().rstrip()\ndebug = lambda *a, **kw: print(\"\\033[33m\", *a, \"\\033[0m\", **dict(file=sys.stderr, **kw))\n\...
[{"input": "6\n1 2 3 4 5 6\n", "output": "1\n"}, {"input": "2\n10 -10\n", "output": "20\n"}]
4,705
Snuke has a favorite restaurant. The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer. So far, Snuke has ordered N meals at the restaurant. Let the amount of money Snuke has paid to the restaurant be...
introductory
[{"code": "# \uff11\u98df\uff18\uff10\uff10\u5186\u3092N\u98df\u98df\u3079\u305f\nN = int( input() )\nx = int( 800 * N )\n\n# \uff11\uff15\u98df\u98df\u3079\u308b\u3054\u3068\u306b\uff12\uff10\uff10\u5186\u3082\u3089\u3048\u308b\n\ny = N // 15 * 200\n\nprint( x - y )", "passed": true, "time": 0.14, "memory": 14200.0, ...
[{"input": "20\n", "output": "15800\n"}, {"input": "60\n", "output": "47200\n"}]
4,706
We have a 3×3 square grid, where each square contains a lowercase English letters. The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}. Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bott...
introductory
[{"code": "cij = [list(input()) for _ in range(3)]\n\nprint(cij[0][0] + cij[1][1] + cij[2][2])", "passed": true, "time": 0.4, "memory": 14232.0, "status": "done"}, {"code": "def resolve():\n matrix = []\n for i in range(3):\n line = input()\n matrix.append(line)\n ans = \"\"\n for i in range(3...
[{"input": "ant\nobe\nrec\n", "output": "abc\n"}, {"input": "edu\ncat\nion\n", "output": "ean\n"}]
4,707
Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either 0 or 1 is written. The number written in Square i is s_i. Snuke will place a marble on each square that says 1. Find the number of squares on which Snuke will place a marble. -----Constraints----- - Each of s_1, s_2 and s_3 is ei...
introductory
[{"code": "s=input()\ncount=0\nfor i in range(len(s)):\n if(s[i]==\"1\"):\n count+=1\nprint(count)", "passed": true, "time": 1.86, "memory": 14280.0, "status": "done"}, {"code": "a=input()\nprint((a.count('1')))\n", "passed": true, "time": 0.15, "memory": 14244.0, "status": "done"}, {"code": "# -*- coding: ut...
[{"input": "101\n", "output": "2\n"}, {"input": "000\n", "output": "0\n"}]
4,708
There is a hotel with the following accommodation fee: - X yen (the currency of Japan) per night, for the first K nights - Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee. -----Constraints----- - 1 \leq N, K \leq 10000 ...
introductory
[{"code": "\nN = int(input())\nK = int(input())\nX = int(input())\nY = int(input())\nif K < N:\n ans = K*X + (N-K)*Y\nelse:\n ans = N*X\nprint(ans)", "passed": true, "time": 0.18, "memory": 14024.0, "status": "done"}, {"code": "N, K, X, Y = [int(input()) for _ in range(4)]\nprint(X * min(K, N) + Y * max(0, N - K)...
[{"input": "5\n3\n10000\n9000\n", "output": "48000\n"}, {"input": "2\n3\n10000\n9000\n", "output": "20000\n"}]
4,709
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either + or -. Your task is to evaluate the formula instead of her. -----Constraints----- - 1≦A,B≦10^9 - op is either + or -. -----Input----- The input is given from Standard Input in the following format: A op...
introductory
[{"code": "a, o, b = input().split()\nif o == '+':\n print((int(a) + int(b)))\nelse:\n print((int(a) - int(b)))\n", "passed": true, "time": 0.15, "memory": 14052.0, "status": "done"}, {"code": "a, op, b = input().split()\n\na = int(a)\nb = int(b)\n\nif op == \"+\":\n S = a + b\nelse:\n S = a - b\n\nprint(S)...
[{"input": "1 + 2\n", "output": "3\n"}, {"input": "5 - 7\n", "output": "-2\n"}]
4,710
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise. You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise. -----Constraints----- - 1 ≦ x ≦ 3{,}000 ...
introductory
[{"code": "x = int(input())\n\nif x < 1200:\n print('ABC')\nelse:\n print('ARC')", "passed": true, "time": 0.15, "memory": 13992.0, "status": "done"}, {"code": "print('ABC' if int(input())<1200 else 'ARC')", "passed": true, "time": 0.15, "memory": 14032.0, "status": "done"}, {"code": "x = int(input())\nif x<1200:...
[{"input": "1000\n", "output": "ABC\n"}, {"input": "2000\n", "output": "ARC\n"}]
4,711
Snuke is buying a bicycle. The bicycle of his choice does not come with a bell, so he has to buy one separately. He has very high awareness of safety, and decides to buy two bells, one for each hand. The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively. Find the min...
introductory
[{"code": "# A - ringring\n# https://atcoder.jp/contests/abc066/tasks/abc066_a\n\na = list(map(int, input().split()))\n\na.sort()\nprint((a[0] + a[1]))\n", "passed": true, "time": 0.92, "memory": 14240.0, "status": "done"}, {"code": "a, b, c = map(int, input().split())\n\nprint(min(a+b, b+c, c+a))", "passed": true, "ti...
[{"input": "700 600 780\n", "output": "1300\n"}, {"input": "10000 10000 10000\n", "output": "20000\n"}]
4,712
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of # and have a thickness of 1. ---...
introductory
[{"code": "H, W = map(int, input().split())\ns = '#' * (W + 2)\ndata = []\ndata.append(s)\nfor i in range(H):\n data.append('#' + str(input()) + '#')\ndata.append(s)\n \nfor i in range(H + 2):\n print(data[i])", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "h, w = map(int, input(...
[{"input": "2 3\nabc\narc\n", "output": "#####\n#abc#\n#arc#\n#####\n"}, {"input": "1 1\nz\n", "output": "###\n#z#\n###\n"}]
4,713
You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D. Find the maximum value taken by x during the...
introductory
[{"code": "N = int(input())\nS = input()\nres = 0\ntmp = 0\nfor s in S:\n if s == 'I':\n tmp += 1\n elif s == 'D':\n tmp -= 1\n \n res = max(res, tmp)\n\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14192.0, "status": "done"}, {"code": "n=int(input())\ns=input()\nx=0\nans=0\nfor i in range(n):\n ...
[{"input": "5\nIIDID\n", "output": "2\n"}, {"input": "7\nDDIDDII\n", "output": "0\n"}]
4,714
Find the number of palindromic numbers among the integers between A and B (inclusive). Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward. -----Constraints----- - 10000 \leq A \leq B \leq 99999 - All input values are int...
introductory
[{"code": "a,b = map(int,input().split())\nans = 0\nfor i in range(a,b+1):\n c = str(i)\n l = len(c)\n d = l // 2\n cnt = 0\n for i in range(d):\n if c[i] == c[-i-1]:\n cnt += 1\n if cnt == d:\n ans += 1\nprint(ans)", "passed": true, "time": 0.31, "memory": 14136.0, "status": ...
[{"input": "11009 11332\n", "output": "4\n"}, {"input": "31415 92653\n", "output": "612\n"}]
4,715
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might...
introductory
[{"code": "a=list(map(int,input().split()))\nprint(len(set(a)))", "passed": true, "time": 0.15, "memory": 14180.0, "status": "done"}, {"code": "s = list(map(int,input().split()))\nprint(len(set(s)))", "passed": true, "time": 0.14, "memory": 14176.0, "status": "done"}, {"code": "lst = input().split()\nif len(lst) == len...
[{"input": "3 1 4\n", "output": "3\n"}, {"input": "3 3 33\n", "output": "2\n"}]
4,716
Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the toy. -----Constraints----- - 1 \leq K \leq N \leq 50 - 1 \leq l_i...
introductory
[{"code": "N,K=map(int,input().split())\nl=list(map(int,input().split()))\nl.sort(reverse=True)\nsum=0\nfor i in range(K) :\n sum+=l[i]\nprint(sum)", "passed": true, "time": 0.14, "memory": 14104.0, "status": "done"}, {"code": "n,k=map(int,input().split())\ndata=list(map(int,input().split()))\ny=sorted(data)\ns=0\nfor...
[{"input": "5 3\n1 2 3 4 5\n", "output": "12\n"}, {"input": "15 14\n50 26 27 21 41 7 42 35 7 5 5 36 39 1 45\n", "output": "386\n"}]
4,717
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t...
introductory
[{"code": "x, a, b = (int(x) for x in input().split())\nif abs(a-x) < abs(b-x):\n print(\"A\")\nelse:\n print(\"B\")", "passed": true, "time": 0.3, "memory": 14088.0, "status": "done"}, {"code": "x, a, b = map(int, input().split())\nif abs(x - a) < abs(x - b): print('A')\nelse: print('B')", "passed": true, "time"...
[{"input": "5 2 7\n", "output": "B\n"}, {"input": "1 999 1000\n", "output": "A\n"}]
4,718
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23. After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Wr...
introductory
[{"code": "s=input()\nprint(\"2018\"+s[4:])", "passed": true, "time": 0.38, "memory": 13976.0, "status": "done"}, {"code": "def main():\n s = input()\n print(f\"2018{s[4:]}\")\n\n\nmain()", "passed": true, "time": 0.28, "memory": 14132.0, "status": "done"}, {"code": "print(input().replace('2017','2018'))", "passe...
[{"input": "2017/01/07\n", "output": "2018/01/07\n"}, {"input": "2017/01/31\n", "output": "2018/01/31\n"}]
4,719
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline...
introductory
[{"code": "# \u3072\u3063\u304f\u308a\u304b\u3048\u3059\u306e\u304b\u3068\u304a\u4fdd\u3063\u305f\u3089180\u5ea6\u53cd\u8ee2\u3060\u3063\u305f\nn = int(input())\nd = []\nfor _ in range(n):\n s = list(input())\n d.append(s)\n\nd = sorted(d, key=lambda dd: len(dd), reverse=True)\nbase = {}\nfor c in d[0]:\n if c...
[{"input": "3\ncbaa\ndaacc\nacacac\n", "output": "aac\n"}, {"input": "3\na\naa\nb\n", "output": "\n"}]
4,720
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now? -----Constr...
introductory
[{"code": "N = int(input())\nans = 0\nfor _ in range(N):\n a, b = map(int, input().split())\n ans += b - a + 1\nprint(ans)", "passed": true, "time": 1.8, "memory": 14164.0, "status": "done"}, {"code": "N = int(input())\nans = 0\nfor _ in range(N):\n l, r = map(int, input().split())\n ans += r-l+1\n\nprint(ans)"...
[{"input": "1\n24 30\n", "output": "7\n"}, {"input": "2\n6 8\n3 3\n", "output": "4\n"}]
4,721
In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city? -----Constraints----- - 2 ≤ n, m ≤ 10...
introductory
[{"code": "a, b = map(int, input().split())\nprint((a - 1) * (b - 1))", "passed": true, "time": 0.14, "memory": 14176.0, "status": "done"}, {"code": "n,m = map(int,input().split())\n\nprint((n-1)*(m-1))", "passed": true, "time": 0.15, "memory": 14224.0, "status": "done"}, {"code": "m, n = map(int, input().split())\npri...
[{"input": "3 4\n", "output": "6\n"}, {"input": "2 2\n", "output": "1\n"}]
4,722
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can ...
introductory
[{"code": "A, B = map(int, input().split())\nC = A + B\n\nprint(\"Possible\" if A%3==0 or B%3==0 or C%3==0 else \"Impossible\")", "passed": true, "time": 0.15, "memory": 14172.0, "status": "done"}, {"code": "A, B = map(int, input().split())\n\nif A%3 and B%3 and (A+B)%3:\n print(\"Impossible\")\nelse:\n print(\"Possi...
[{"input": "4 5\n", "output": "Possible\n"}, {"input": "1 1\n", "output": "Impossible\n"}]
4,723
E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?. One more ...
introductory
[{"code": "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Mon Sep 28 02:20:36 2020\n\n@author: liang\n\"\"\"\nS = input()\nT = input()\n\nS = S[::-1]\nT = T[::-1]\n\nres = list()\n\nfor i in range(len(S)-len(T)+1):\n flag = True\n for j in range(len(T)):\n if S[i+j] == \"?\" or S[i+j] == T[j]:\n co...
[{"input": "?tc????\ncoder\n", "output": "atcoder\n"}, {"input": "??p??d??\nabc\n", "output": "UNRESTORABLE\n"}]
4,724
Takahashi is a user of a site that hosts programming contests. When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows: - Let the current rating of the user be a. - Suppose that the performance of the user in the contest is...
introductory
[{"code": "# \u73fe\u5728\u3068\u76ee\u6a19\u306e\u30ec\u30fc\u30c6\u30a3\u30f3\u30b0\u3092\u53d6\u5f97\nR = int(input())\nG = int(input())\n\n# \u76ee\u6a19\u306e\u30ec\u30fc\u30c6\u30a3\u30f3\u30b0\u306b\u306a\u308b\u305f\u3081\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u6570\u5024\u3092\u8a08\u7b97\nTarge...
[{"input": "2002\n2017\n", "output": "2032\n"}, {"input": "4500\n0\n", "output": "-4500\n"}]