problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
1feff0bbb6db34aa1565412375bccb8f
UNKNOWN
There are $n$ products in the shop. The price of the $i$-th product is $a_i$. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly. In fact, the owner of the shop can change the price of some product $i$ in such a way that the difference between the old price ...
["for ei in range(int(input())):\n n, k = map(int, input().split())\n A = list(map(int, input().split()))\n ans = min(A) + k\n for i in A:\n if ans != -1 and abs(ans - i) > k:\n ans = -1\n print(ans)", "q=int(input())\nfor i in range(q):\n n,k=[int(x) for x in input().split()]\n a...
{ "inputs": [ "4\n5 1\n1 1 2 3 1\n4 2\n6 4 8 5\n2 2\n1 6\n3 5\n5 2 5\n", "1\n2 3\n5 15\n", "1\n1 5\n5\n", "5\n8 19551489\n31131899 17585660 3913937 14521321 5400652 96097161 58347480 35051437\n1 55716143\n15578410\n7 19560555\n65980880 53703939 20259503 99698023 98868060 83313210 9926424\n6 72321938\n...
INTRODUCTORY
PYTHON3
CODEFORCES
6,056
ee0e6c87f238058ed671b6b4cd03d9ec
UNKNOWN
You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$. Your task is to remove the minimum number of elements to make this array good. An array of length $k$ is called good if $k$ is divisible by $6$ and it is possible to split it into $\frac{k}{6...
["#!/usr/bin/env python\nn = int(input())\na = list(map(int, input().split()))\nk = [None, 4, 8, 15, 16, 23, 42]\ns = [n, 0, 0, 0, 0, 0, 0]\nfor ai in a:\n for i in range(6, 0, -1):\n if ai == k[i] and s[i - 1] > 0:\n s[i] += 1; s[i - 1] -= 1\n break\nprint(n - 6 * s[-1])\n", "from sys i...
{ "inputs": [ "5\n4 8 15 16 23\n", "12\n4 8 4 15 16 8 23 15 16 42 23 42\n", "15\n4 8 4 8 15 16 8 16 23 15 16 4 42 23 42\n", "1\n4\n", "1\n42\n", "100\n4 42 23 23 8 42 16 23 42 16 42 8 4 23 4 4 23 42 16 42 23 23 23 42 4 42 8 8 16 23 15 23 16 4 42 15 15 23 16 15 16 4 4 15 23 42 42 15 8 23 8 23 4...
INTRODUCTORY
PYTHON3
CODEFORCES
14,010
b26203f40354fab057a4240da2048287
UNKNOWN
You are given two integers $a$ and $b$. In one move, you can choose some integer $k$ from $1$ to $10$ and add it to $a$ or subtract it from $a$. In other words, you choose an integer $k \in [1; 10]$ and perform $a := a + k$ or $a := a - k$. You may use different values of $k$ in different moves. Your task is to find ...
["for _ in range(int(input())):\n a,b=map(int,input().split())\n print((abs(a-b)+9)//10)", "for _ in range(int(input())):\n a,b = map(int,input().split())\n print((abs(b - a) + 9) // 10)", "import sys\nimport math\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin....
{ "inputs": [ "6\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n", "1\n5 5\n", "11\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n100500 9000\n5 5\n13 42\n18 4\n1337 420\n123456789 1000000000\n", "2\n5 5\n5 5\n", "4\n5 5\n5 5\n5 5\n5 5\n", "7\n2 2\n2 2\n2 2\n2 2\n2 2\n2 2\...
INTRODUCTORY
PYTHON3
CODEFORCES
4,273
9db7075c9d4787f820464cded41629e3
UNKNOWN
You are given three integers $x, y$ and $n$. Your task is to find the maximum integer $k$ such that $0 \le k \le n$ that $k \bmod x = y$, where $\bmod$ is modulo operation. Many programming languages use percent operator % to implement it. In other words, with given $x, y$ and $n$ you need to find the maximum possible...
["ntest = int(input())\nfor testcase in range(ntest):\n x, y, n = list(map(int, input().split()))\n t = (n - y) // x * x + y\n print(t)\n", "def read_int():\n return int(input())\n\n\ndef read_ints():\n return list(map(int, input().split(' ')))\n\n\nt = read_int()\nfor case_num in range(t):\n x, y, n ...
{ "inputs": [ "7\n7 5 12345\n5 0 4\n10 5 15\n17 8 54321\n499999993 9 1000000000\n10 5 187\n2 0 999999999\n", "1\n1000000000 0 999999999\n", "1\n43284 1 33424242\n", "1\n31 2 104\n", "1\n943643 1 23522222\n", "1\n4452384 1 3573842\n", "1\n33 6 100\n" ], "outputs": [ "12339\n0\n15\n5...
INTRODUCTORY
PYTHON3
CODEFORCES
9,217
aa2e7e19c677c5592160500288a0795a
UNKNOWN
International Women's Day is coming soon! Polycarp is preparing for the holiday. There are $n$ candy boxes in the shop for sale. The $i$-th box contains $d_i$ candies. Polycarp wants to prepare the maximum number of gifts for $k$ girls. Each gift will consist of exactly two boxes. The girls should be able to share ea...
["n, k = map(int, input().split())\nD = list(map(int, input().split()))\nz = {i: 0 for i in range(k)}\nfor i in range(n):\n z[D[i] % k] += 1\ncnt = z[0] // 2\nfor q in range(1, k // 2 + k % 2):\n cnt += min(z[q], z[k - q])\nif k % 2 == 0:\n cnt += z[k // 2] // 2\nprint(cnt * 2)", "n, k = map(int, input().split...
{ "inputs": [ "7 2\n1 2 2 3 2 4 10\n", "8 2\n1 2 2 3 2 4 6 10\n", "7 3\n1 2 2 3 2 4 5\n", "1 2\n120\n", "2 9\n80 1\n", "2 9\n81 1\n", "3 1\n1 1 1\n" ], "outputs": [ "6\n", "8\n", "4\n", "0\n", "2\n", "0\n", "2\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
9,497
757c71d7cd26e4bc7d4726992543174e
UNKNOWN
You are given a string S of length N consisting of A, B and C, and an integer K which is between 1 and N (inclusive). Print the string S after lowercasing the K-th character in it. -----Constraints----- - 1 ≤ N ≤ 50 - 1 ≤ K ≤ N - S is a string of length N consisting of A, B and C. -----Input----- Input is given fr...
["N, K = map(int, input().split())\nS = input()\nprint(\"\".join(c.lower() if i == K else c for i, c in enumerate(S, 1)))", "n,k = list(map(int,input().split()))\nS = input()\nprint( S[:k-1]+S[k-1].lower()+ S[k:])", "N, K = map(int, input().split())\nS = list(input())\nS[K - 1] = S[K - 1].lower()\n\nprint(\"\".join(S))...
{"inputs": ["3 1\nABC\n", "4 3\nCABA\n", "20 15\nBBBBAAACBCABBCAACAAC\n", "40 38\nBCCACCBCACABBBBBCBABCCCABBAACBBBAAABACCA\n", "1 1\nA\n", "50 27\nACBCABCCCAACACCBBBACCBCBBBCCBAAAABAACACAAACCACCCCA\n", "50 50\nCABABCBBCBABCAACBCBBAAAACBCBCBBABBABBBCCBAACCAACAB\n"], "outputs": ["aBC\n", "CAbA\n", "BBBBAAACBCABBCaACAAC\n...
INTRODUCTORY
PYTHON3
ATCODER.JP
14,149
22803adf0fbaa6b1cb87b33bd4c0a27b
UNKNOWN
You have decided to write a book introducing good restaurants. There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i. No two restaurants have the same score. You want to int...
["n=int(input())\na=[]\nfor i in range(n):\n t=list(input().split())\n t[1]=int(t[1])\n t.append(i)\n a.append(t)\na.sort(key=lambda x:(x[0],-x[1]))\nfor t in a:\n print(t[2]+1)", "n = int(input())\nsp =[[] for _ in range(n)]\nfor i in range(n):\n sp[i] = list(input().split())\n sp[i].append(i+1)\n\nssp = so...
{"inputs": ["6\nkhabarovsk 20\nmoscow 10\nkazan 50\nkazan 35\nmoscow 60\nkhabarovsk 40\n", "10\nyakutsk 10\nyakutsk 20\nyakutsk 30\nyakutsk 40\nyakutsk 50\nyakutsk 60\nyakutsk 70\nyakutsk 80\nyakutsk 90\nyakutsk 100\n", "39\nem 22\nl 27\nasiqdflmv 24\ntmlifuzz 62\nem 64\ntmlifuzz 35\nem 8\nasiqdflmv 16\ntmlifuzz 51\nkz...
INTRODUCTORY
PYTHON3
ATCODER.JP
28,502
350e1843270e6bfb04b4d35aa9097b2f
UNKNOWN
Takahashi has K 500-yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print Yes; otherwise, print No. -----Constraints----- - 1 \leq K \leq 100 - 1 \leq X \leq 10^5 -----Input----- Input is given from Standard Input in the following format: K X -----Output----- If the coins add up ...
["k,x = map(int,input().split())\nprint(\"Yes\" if k*500 >= x else \"No\")", "k,x=map(int,input().split())\nif(500*k>=x):\n print(\"Yes\")\nelse:\n print(\"No\")", "K, X = map(int, input().split())\n\nif K * 500 >= X :\n print('Yes')\nelse :\n print('No')", "K, X = map(int, input().split())\n\nif 500*K >= X:\n ...
{"inputs": ["2 900\n", "1 501\n", "4 2000\n", "100 100000\n", "1 500\n", "84 42001\n", "13 6498\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
9,764
70f5e6d48bc9e96d7cf742024e0583fd
UNKNOWN
Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: - Throw the die. The current score is the result of the die. - As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each ti...
["n,k = map(int,input().split())\n\nans = 0\n\nfor i in range(1,n+1):\n if i>=k:\n ans += (1/n)\n continue\n x = 1\n while 1:\n i *= 2\n if i>=k:\n break\n else:x+=1\n ans += (1/n)*(1/2)**x\nprint(ans)", "import math\n\nN, K = map(int, input().split())\n\nres = ...
{"inputs": ["3 10\n", "100000 5\n", "3904 16384\n", "97392 33\n", "1 1\n", "10000 100000\n", "1 100000\n"], "outputs": ["0.145833333333\n", "0.999973749998\n", "0.081316166237\n", "0.999781007423\n", "1.000000000000\n", "0.036463721466\n", "0.000007629395\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
23,723
18536f759a4fc4af5fe6ee5a2ad30c33
UNKNOWN
Given is a string S representing the day of the week today. S is SUN, MON, TUE, WED, THU, FRI, or SAT, for Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday, respectively. After how many days is the next Sunday (tomorrow or later)? -----Constraints----- - S is SUN, MON, TUE, WED, THU, FRI, or SAT. -...
["S = input()\nW = [\"SUN\",\"MON\",\"TUE\",\"WED\",\"THU\",\"FRI\",\"SAT\"]\nprint(7-W.index(S))", "S = str(input())\n\nday = [\"SUN\", \"MON\", \"TUE\", \"WED\", \"THU\", \"FRI\", \"SAT\", \"SUN\"]\nprint(7 - day.index(S))", "print(['SUN','MON','TUE','WED','THU','FRI','SAT'][::-1].index(input())+1)", "S = input()\nwe...
{"inputs": ["SAT\n", "SUN\n", "FRI\n", "MON\n", "THU\n", "TUE\n", "WED\n"], "outputs": ["1\n", "7\n", "2\n", "6\n", "3\n", "5\n", "4\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
17,381
7d480aac38d4384d1ac0e3ba5188915b
UNKNOWN
The development of algae in a pond is as follows. Let the total weight of the algae at the beginning of the year i be x_i gram. For i≥2000, the following formula holds: - x_{i+1} = rx_i - D You are given r, D and x_{2000}. Calculate x_{2001}, ..., x_{2010} and print them in order. -----Constraints----- - 2 ≤ r ≤ 5 ...
["r, D, x = map(int, input().split())\n\nfor i in range(10):\n x = r * x - D\n print(x)", "r, D, x = map(int, input().split())\n\n\nfor i in range(10):\n x = r*x-D\n print(x)", "# unihernandez22\n# https://atcoder.jp/contests/abc127/tasks/abc127_b\n# implementation\n\nr, d, x = map(int, input().split())\n\nfor ...
{"inputs": ["2 10 20\n", "4 40 60\n", "2 1 2\n", "2 100 105\n", "3 1 2\n", "4 49 188\n", "5 1 200\n"], "outputs": ["30\n50\n90\n170\n330\n650\n1290\n2570\n5130\n10250\n", "200\n760\n3000\n11960\n47800\n191160\n764600\n3058360\n12233400\n48933560\n", "3\n5\n9\n17\n33\n65\n129\n257\n513\n1025\n", "110\n120\n140\n180\n260...
INTRODUCTORY
PYTHON3
ATCODER.JP
11,372
745938232d7233dbefd15f1e1b33d4cc
UNKNOWN
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers. Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib...
["input()\nnum = list(map(int, input().split()))\nmaxn = 0\nl, r = 0, len(num)-1\nj1, j2 = num[l], num[r]\nwhile l < r:\n if j1 == j2:\n maxn = max(j1, maxn)\n l += 1\n j1 += num[l]\n elif j1 < j2:\n l += 1\n j1 += num[l]\n else:\n r -= 1\n j2 += num[r]\nprint(m...
{ "inputs": [ "5\n1 3 1 1 4\n", "5\n1 3 2 1 4\n", "3\n4 1 2\n", "1\n1000000000\n", "2\n1 1\n", "5\n1 3 5 4 5\n" ], "outputs": [ "5\n", "4\n", "0\n", "0\n", "1\n", "9\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
9,950
d9facbd4ddbe7d932eba1096ca3151b1
UNKNOWN
You are given three positive (i.e. strictly greater than zero) integers $x$, $y$ and $z$. Your task is to find positive integers $a$, $b$ and $c$ such that $x = \max(a, b)$, $y = \max(a, c)$ and $z = \max(b, c)$, or determine that it is impossible to find such $a$, $b$ and $c$. You have to answer $t$ independent test...
["for testcase in range(int(input())):\n vals = list(map(int, input().split()))\n \n ans = None\n for a in vals:\n for b in vals:\n for c in vals:\n if max(a, b) == vals[0] and max(a, c) == vals[1] and max(b, c) == vals[2]:\n ans = [a, b, c]\n \n if ...
{ "inputs": [ "5\n3 2 3\n100 100 100\n50 49 49\n10 30 20\n1 1000000000 1000000000\n", "2\n5 7 7\n6 7 3\n", "1\n127869 127869 127869\n", "1\n12789 12789 12789\n", "1\n78738 78738 78738\n", "1\n78788 78788 78788\n" ], "outputs": [ "YES\n2 2 3\nYES\n100 100 100\nNO\nNO\nYES\n1 1 100000000...
INTRODUCTORY
PYTHON3
CODEFORCES
9,574
c79d5d89fb0e94e6790b9052276d023d
UNKNOWN
Maksim has $n$ objects and $m$ boxes, each box has size exactly $k$. Objects are numbered from $1$ to $n$ in order from left to right, the size of the $i$-th object is $a_i$. Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goe...
["n, m, k = [int(_) for _ in input().split()]\na = [int(_) for _ in input().split()]\n\nb = k\ncount = 0\nfor obj in a[::-1]:\n if obj > k:\n break\n if obj > b:\n if m > 1:\n m -= 1\n b = k - obj\n count += 1\n else:\n break\n else:\n b -...
{ "inputs": [ "5 2 6\n5 2 1 4 2\n", "5 1 4\n4 2 3 4 1\n", "5 3 3\n1 2 3 1 1\n", "5 4 2\n1 2 1 2 1\n", "1 1 1\n1\n", "5 5 5\n5 5 5 5 5\n" ], "outputs": [ "4\n", "1\n", "5\n", "4\n", "1\n", "5\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
11,945
53b3d0fa65ab0c6c27be8ad8555af2ef
UNKNOWN
Recently, Norge found a string $s = s_1 s_2 \ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$. Yes, all $\frac{n (n + 1)}{2}$ of them! A substring of $s$ is a non-empty string $x = s[a \ldots b] = s_{a} s_{a + 1} \ldot...
["n, k = map(int, input().split())\ns = set()\nst = input()\ninp = input().split()\nfor x in inp:\n s.add(x)\ncurrent, ans = 0, 0\nfor x in st:\n if x in s:\n current += 1\n else:\n ans += (current * (current + 1)) // 2\n current = 0\nans += (current * (current + 1)) // 2\nprint(ans)", "n,...
{ "inputs": [ "7 2\nabacaba\na b\n", "10 3\nsadfaasdda\nf a d\n", "7 1\naaaaaaa\nb\n", "200 13\nvgfjhgkgwkftaeqejmbgildembgxdbskxfndwmcckjfkbeekxkgakmcjhclqsecpnkaigcxxhfghgegfadjktckftdhtifriemfifakygoesjfginnddjjklwiwlbjsgftwhtjdxmcadpvhaeddxwnmguwhetwbmffbmvdvuhecgjckddrbikgwkrfwfhdhqolidgkfm\na b ...
INTRODUCTORY
PYTHON3
CODEFORCES
5,580
1ce4bc8b7b77432c3b11d4f332f606f3
UNKNOWN
Recall that the sequence $b$ is a a subsequence of the sequence $a$ if $b$ can be derived from $a$ by removing zero or more elements without changing the order of the remaining elements. For example, if $a=[1, 2, 1, 3, 1, 2, 1]$, then possible subsequences are: $[1, 1, 1, 1]$, $[3]$ and $[1, 2, 1, 3, 1, 2, 1]$, but not...
["for _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n a=[]\n lis=[]\n prevsign=-1\n if l[0]>0:\n prevsign=1\n else:\n prevsign=0\n i=0\n for i in l:\n if (i>0 and prevsign==1) or (i<0 and prevsign==0):\n lis.append(i)\n el...
{ "inputs": [ "4\n5\n1 2 3 -1 -2\n4\n-1 -2 -1 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n", "2\n2\n1 2\n1\n1\n", "2\n4\n1 2 3 4\n3\n1 2 3\n", "4\n5\n1 2 3 -1 -1\n4\n-4 -2 -4 -3\n10\n-2 8 3 8 -4 -15 5 -2 -3 1\n6\n1 -1000000000 1 -1000000000 1 -1000000000\n", "2...
INTRODUCTORY
PYTHON3
CODEFORCES
7,728
504c85ecfe8d129426ae07d68edb9515
UNKNOWN
You are given a board of size $n \times n$, where $n$ is odd (not divisible by $2$). Initially, each cell of the board contains one figure. In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a side or a corner with the current cell, i.e. from the cell $(i, j)$...
["a=int(input())\n\nfor ufui in range(a):\n val=int(input())\n\n num=val//2 + 1\n count=0\n\n for i in range(num):\n count=count+i*((2*i+1)**2 - (2*i-1)**2)\n\n print (count)\n \n", "import sys\ninput = sys.stdin.readline\nrInt = lambda: int(input())\nmInt = lambda: list(map(int, input().split(...
{ "inputs": [ "3\n1\n5\n499993\n", "1\n499999\n", "1\n69791\n", "3\n5\n3005\n3005\n", "1\n214541\n", "1\n214145\n" ], "outputs": [ "0\n40\n41664916690999888\n", "41666416667000000\n", "113312287936960\n", "40\n9045074040\n9045074040\n", "3291619655775960\n", "327342...
INTRODUCTORY
PYTHON3
CODEFORCES
9,613
b817d727a616e93ab386729bde11d7ab
UNKNOWN
You are given an array $a$ consisting of $n$ integers. In one move, you can jump from the position $i$ to the position $i - a_i$ (if $1 \le i - a_i$) or to the position $i + a_i$ (if $i + a_i \le n$). For each position $i$ from $1$ to $n$ you want to know the minimum the number of moves required to reach any position ...
["from heapq import heappush, heappop\n\nn = int(input())\na = list(map(int, input().split()))\nedge = [[] for _ in range(n)]\nrev = [[] for _ in range(n)]\ninf = 10**9\ncost = [inf]*n\nhq = []\n\nfor i, x in enumerate(a):\n if i+x < n:\n edge[i].append(i+x)\n rev[i+x].append(i)\n if (a[i] ^ a[i...
{ "inputs": [ "10\n4 5 7 6 7 5 4 4 6 4\n", "100\n10 3 10 3 5 4 10 9 9 8 7 10 3 10 8 9 7 7 8 10 7 8 3 10 4 5 10 10 3 9 10 6 9 9 7 6 10 4 3 8 7 7 3 9 9 8 7 5 4 5 3 8 4 4 5 3 9 6 9 9 6 9 3 4 5 6 5 10 5 4 6 10 3 4 4 8 8 3 9 7 8 10 6 5 8 3 4 6 8 9 8 9 4 3 10 8 8 10 7 3\n", "100\n12 18 18 10 13 13 20 14 20 13 1...
INTRODUCTORY
PYTHON3
CODEFORCES
3,007
98bcbde98b8f0d955aa61ec19098bd3c
UNKNOWN
You are given one integer number $n$. Find three distinct integers $a, b, c$ such that $2 \le a, b, c$ and $a \cdot b \cdot c = n$ or say that it is impossible to do it. If there are several answers, you can print any. You have to answer $t$ independent test cases. -----Input----- The first line of the input conta...
["#-------------Program--------------\n#----Kuzlyaev-Nikita-Codeforces----\n#-------------Round615-------------\n#----------------------------------\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n a=[]\n for i in range(2,int(n**0.5)+2):\n if len(a)==2:\n a.append(n)\n brea...
{"inputs": ["5\n64\n32\n97\n2\n12345\n", "21\n719\n5039\n39916801\n479001599\n28657\n514229\n433494437\n66047\n263167\n16785407\n999999757\n999999761\n999999797\n999999883\n999999893\n999999929\n999999937\n991026973\n985062919\n979134757\n971230541\n", "1\n128\n", "6\n10\n10\n10\n10\n10\n10\n", "1\n1112\n", "1\n162\n"]...
INTRODUCTORY
PYTHON3
CODEFORCES
7,023
b001a1aa7f2bb35c872de21b1b0c12ff
UNKNOWN
Nikolay got a string $s$ of even length $n$, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from $1$ to $n$. He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following opera...
["import sys\ninput = sys.stdin.readline\n\nn=int(input())\ns=list(input().strip())\n\nANS=0\nfor i in range(0,n,2):\n if s[i]==s[i+1]:\n ANS+=1\n if s[i]==\"a\":\n s[i]=\"b\"\n else:\n s[i]=\"a\"\n\nprint(ANS)\nprint(\"\".join(s))\n", "'''input\n2\naa\n\n\n'''\nimport sys\...
{ "inputs": [ "4\nbbbb\n", "6\nababab\n", "2\naa\n", "6\nbbbbba\n", "8\nbbbabbba\n", "8\nbbabbbaa\n" ], "outputs": [ "2\nabab\n", "0\nababab\n", "1\nba\n", "2\nababba\n", "2\nabbaabba\n", "3\nabababba\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
8,384
c1a0dacf470a4858903c9ed9d1cc1fed
UNKNOWN
Takahashi is solving quizzes. He has easily solved all but the last one. The last quiz has three choices: 1, 2, and 3. With his supernatural power, Takahashi has found out that the choices A and B are both wrong. Print the correct choice for this problem. -----Constraints----- - Each of the numbers A and B is 1, 2, o...
["a = int(input())\nb = int(input())\n\nc = 1+2+3\n\nprint((c - (a+b)))\n", "A = input()\nB = input()\ncandidate = set(('1', '2', '3'))\nexclude = set((A, B))\nprint((candidate - exclude).pop())", "A=int(input())\nB=int(input())\nif A==1 and B==2 or A==2 and B==1:\n print(3)\nelif A==3 and B==2 or A==2 and B==3:\n pr...
{"inputs": ["3\n1\n", "1\n2\n", "1\n3\n", "3\n2\n", "2\n1\n", "2\n3\n"], "outputs": ["2\n", "3\n", "2\n", "1\n", "3\n", "1\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
10,791
76adb487d5ae20ac4d23f1c9d4a5321a
UNKNOWN
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. -----Constraints----- - 1 ≤ L ≤ 1000 - L is an integer. -----Input----- Input is given from Standard Input in the following format: L -----Output----- Print the maxim...
["L = int(input())\n\nans = (L / 3) ** 3\n\nprint(ans)", "def resolve():\n L = int(input())\n a = L/3\n print(a**3)\nresolve()", "s=int(input())\nb=s/3\nprint(b**3)", "L = int(input())\nprint((L ** 3) / 27)", "from math import *\nl = int(input())\nprint((l/3)**3)", "print((int(input())/3)**3)", "L = int(input(...
{"inputs": ["3\n", "999\n", "430\n", "1\n", "1000\n", "392\n"], "outputs": ["1.000000000000\n", "36926037.000000000000\n", "2944703.703703703824\n", "0.037037037037\n", "37037037.037037037313\n", "2230973.629629629664\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
11,372
80bcbe21c5b67cf5282269bdaa231723
UNKNOWN
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education. One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B ...
["n = int(input())\nif n == 1:\n print('Hello World')\nelse:\n a = int(input())\n b = int(input())\n print(a+b)", "N = int(input())\nprint(\"Hello World\") if N==1 else print(sum([int(input()) for _ in range(2)]))", "n = int(input())\n\nif n == 1:\n print(\"Hello World\")\nelse:\n A = int(input())\n ...
{"inputs": ["1\n", "2\n3\n5\n", "2\n1\n1\n", "2\n8\n5\n", "2\n9\n9\n", "2\n5\n6\n"], "outputs": ["Hello World\n", "8\n", "2\n", "13\n", "18\n", "11\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
13,029
33d53b82248d7ae514fcf98791c17a51
UNKNOWN
Given are 1-digit positive integers a and b. Consider these two strings: the concatenation of b copies of the digit a, and the concatenation of a copies of the digit b. Which of these is lexicographically smaller? -----Constraints----- - 1 \leq a \leq 9 - 1 \leq b \leq 9 - a and b are integers. -----Input----- Inp...
["a, b = map(int, input().split())\n\nif a <= b:\n ans = str(a) * b\nelse:\n ans = str(b) * a\nprint(ans)\nreturn", "a, b = map(int, input().split())\n\nprint((f\"{a}\" * b, f\"{b}\" * a)[b <= a])", "a,b = map(int, input().split())\n\n\nif a < b:\n print(str(a)*b)\nelse:\n print(str(b)*a)", "a, b = map(int, inp...
{"inputs": ["4 3\n", "7 7\n", "1 1\n", "9 1\n", "6 8\n", "5 4\n"], "outputs": ["3333\n", "7777777\n", "1\n", "111111111\n", "66666666\n", "44444\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
14,174
52723a182b6b1a0e01591aea33f33acd
UNKNOWN
Given is a lowercase English letter C that is not z. Print the letter that follows C in alphabetical order. -----Constraints----- - C is a lowercase English letter that is not z. -----Input----- Input is given from Standard Input in the following format: C -----Output----- Print the letter that follows C in alphabe...
["C = input()\nC = ord(C)\nC = C+1\nprint(chr(C))", "C = input()\nword = [chr(i) for i in range(97, 97+26)]\ncount = 0\nfor i in range( len(word) ):\n if C == word[i]:\n count = i\nprint(word[count+1])", "C =input()\nprint(chr(ord(C)+1))", "asd=input()\ndfg=[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j...
{"inputs": ["a\n", "y\n", "c\n", "p\n", "d\n", "t\n"], "outputs": ["b\n", "z\n", "d\n", "q\n", "e\n", "u\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
8,062
eb3b52d146270bcef84c4378d8832c8c
UNKNOWN
Given are two strings S and T consisting of lowercase English letters. Concatenate T and S in this order, without space in between, and print the resulting string. -----Constraints----- - S and T are strings consisting of lowercase English letters. - The lengths of S and T are between 1 and 100 (inclusive). -----In...
["S,T = map(str,input().split())\nprint(T + S)", "s, t = map( str, input().split() )\nprint( t + s )", "S,T = input().split()\n\nans = T+S\nprint(ans)", "S,T=input().split()\nprint((T+S))\n", "s, t = input().split()\n\nu = t + s\n\nprint(u)\n\n", "s,t=map(str,input().split())\nprint(t+s)", "S,T=map(str,input().split())...
{"inputs": ["oder atc\n", "humu humu\n", "c a\n", "oekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahjekkengkfoekdkfjdjgjknbfkwnfnhaoekdkfjdjgjknbfkwnfnhahj yowkymbmhkkgjjeokdlakbndkkworqotkfnblgpnkkrogjrfnvmbjisnbkzvmbnrrrigeoibgpefjobvmovpqosqoqrgrkengrlk\n", "dttd dttddttddttddttddttddttddttddttddttddttddttddttddttddttdd...
INTRODUCTORY
PYTHON3
ATCODER.JP
6,315
11f0eb68bff1e39cbcb63bcfe6e63b56
UNKNOWN
Polycarp has an array $a$ consisting of $n$ integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For each of the next moves he chooses any element with the only restrictio...
["n = int(input())\na = list(map(int, input().split()))\nodd = []\neven = []\nfor i in a:\n if i%2:\n odd.append(i)\n else:\n even.append(i)\nodd.sort()\neven.sort()\nif abs(len(odd) - len(even)) <= 1:\n print(0)\nelse:\n if len(odd) > len(even):\n print(sum(odd[:len(odd)-len(even)-1]))...
{ "inputs": [ "5\n1 5 7 8 2\n", "6\n5 1 2 4 6 3\n", "2\n1000000 1000000\n", "5\n2 1 1 1 1\n", "5\n1 1 1 1 1\n" ], "outputs": [ "0\n", "0\n", "1000000\n", "2\n", "4\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
16,453
04631f6c093cd288b2c10f6e84fdc71c
UNKNOWN
There are $n$ monsters standing in a row numbered from $1$ to $n$. The $i$-th monster has $h_i$ health points (hp). You have your attack power equal to $a$ hp and your opponent has his attack power equal to $b$ hp. You and your opponent are fighting these monsters. Firstly, you and your opponent go to the first monste...
["n, a, b, k = map(int, input().split())\nH = list(map(int, input().split()))\nfor i in range(n):\n H[i] %= (a + b)\n if H[i] == 0:\n H[i] = a + b\nH.sort()\nans = 0\nfor x in H:\n if x <= a:\n ans += 1\n else:\n tok = (x + a - 1) // a - 1\n if k >= tok:\n k -= tok\n ...
{ "inputs": [ "6 2 3 3\n7 10 50 12 1 8\n", "1 1 100 99\n100\n", "7 4 2 1\n1 3 5 4 2 7 6\n", "2 1 49 2\n50 50\n", "2 1 100 2\n1 101\n" ], "outputs": [ "5\n", "1\n", "6\n", "0\n", "1\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
8,278
7040c0c037b2832037107d49b5df3940
UNKNOWN
You are given an array consisting of $n$ integers $a_1, a_2, \dots, a_n$, and a positive integer $m$. It is guaranteed that $m$ is a divisor of $n$. In a single move, you can choose any position $i$ between $1$ and $n$ and increase $a_i$ by $1$. Let's calculate $c_r$ ($0 \le r \le m-1)$ — the number of elements havin...
["import bisect\n\nn, m = map(int, input().split())\nls = list(map(int, input().split()))\n\nmls = []\nfor i in range(0, n):\n mls.append((ls[i] % m, i))\n\nmls.sort()\n# print(mls)\n\nbk1 = set()\nbk2 = set()\n\naim = n // m\ncnt = 0\n\nmis = []\nfor i in range(m):\n for j in range(aim):\n mis.append(i)\n...
{ "inputs": [ "6 3\n3 2 0 6 10 12\n", "4 2\n0 1 2 3\n", "1 1\n1000000000\n", "6 3\n3 2 0 6 10 11\n", "100 25\n6745 2075 7499 7517 1776 5164 2335 2745 4465 1457 7565 2232 2486 9025 8059 9646 8017 7662 9690 3352 2306 366 7422 1073 7169 8966 4506 8225 5614 8628 2908 7452 9625 9332 7097 353 1043 8118 ...
INTRODUCTORY
PYTHON3
CODEFORCES
18,751
9cad0fd51d1b1ecdba8c3e4b737b54c4
UNKNOWN
The only difference between easy and hard versions is constraints. Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtransactions — and he won't start playing until he gets all of them. E...
["import collections\n\n\ndef main():\n from sys import stdin, stdout\n\n def read():\n return stdin.readline().rstrip('\\n')\n\n def read_array(sep=None, maxsplit=-1):\n return read().split(sep, maxsplit)\n\n def read_int():\n return int(read())\n\n def read_int_array(sep=None, maxs...
{ "inputs": [ "5 6\n1 2 0 2 0\n2 4\n3 3\n1 5\n1 2\n1 5\n2 3\n", "5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "78 36\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n1 52\n2 6\n9 43\n10 52\n4 63\n9 35\n10 67\...
INTRODUCTORY
PYTHON3
CODEFORCES
26,886
4a6b4d29b0f03cf3a77a10ba466f41dc
UNKNOWN
You are given $4n$ sticks, the length of the $i$-th stick is $a_i$. You have to create $n$ rectangles, each rectangle will consist of exactly $4$ sticks from the given set. The rectangle consists of four sides, opposite sides should have equal length and all angles in it should be right. Note that each stick can be us...
["for _ in range(int(input())):\n n = int(input())\n A = list(map(int, input().split()))\n B = {}\n for i in A:\n if i not in B:\n B[i] = 0\n B[i] += 1\n ans = 'YES'\n J = []\n for i in B:\n if B[i] % 2:\n ans = 'NO'\n break\n else:\n ...
{ "inputs": [ "5\n1\n1 1 10 10\n2\n10 5 2 10 1 1 2 5\n2\n10 5 1 10 5 1 1 1\n2\n1 1 1 1 1 1 1 1\n1\n10000 10000 10000 10000\n", "1\n2\n11 1 11 1 5 2 5 2\n", "1\n2\n1 1 3 3 5 5 10 10\n", "1\n2\n1 11 1 11 5 2 5 2\n", "1\n2\n3 3 4 4 4 4 6 6\n" ], "outputs": [ "YES\nYES\nNO\nYES\nYES\n", "N...
INTRODUCTORY
PYTHON3
CODEFORCES
13,269
9b151e59de0827f6d5aad58c038df4da
UNKNOWN
You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges. You need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one). More formally, if $d$ is the matrix of shorte...
["import sys\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nEDGE=[list(map(int,input().split())) for i in range(m)]\n\nEDGE.sort(key=lambda x:x[2])\nEDGE=EDGE[:k]\n\nCOST_vertex=[[] for i in range(n+1)]\nfor a,b,c in EDGE:\n COST_vertex[a].append((b,c))\n COST_vertex[b].append((a,c))\n\nfor ...
{ "inputs": [ "6 10 5\n2 5 1\n5 3 9\n6 2 2\n1 3 1\n5 1 8\n6 5 10\n1 6 5\n6 4 6\n3 6 2\n3 4 5\n", "7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5 5\n3 7 9\n4 1 8\n2 1 1\n", "8 7 19\n1 2 1000000000\n2 3 999999999\n3 4 999999998\n4 5 999999997\n5 6 999999996\n6 7 99...
INTRODUCTORY
PYTHON3
CODEFORCES
8,842
d3d6a9b4a86a3c94744618f68405eda8
UNKNOWN
There are $n$ students at your university. The programming skill of the $i$-th student is $a_i$. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this university is if it has $2 \cdot 10^5$ students ready for the finals! Each team should consist of at l...
["import sys\ninput = sys.stdin.readline\n\nn=int(input())\nA=list(map(int,input().split()))\n\nB=[(a,ind) for ind,a in enumerate(A)]\nB.sort()\n \nDP=[0]*(n+1)\n\nfor i in range(3,n-2):\n DP[i]=max(DP[i-1],DP[i-3]+B[i][0]-B[i-1][0])\n\n#print(DP)\n\nMAX=max(DP)\n\nx=DP.index(MAX)\n\nREMLIST=[]\n\nwhile x>0:\n ...
{ "inputs": [ "5\n1 1 3 4 2\n", "6\n1 5 12 13 2 15\n", "10\n1 2 5 129 185 581 1041 1909 1580 8150\n", "6\n1 1 2 2 3 3\n", "10\n716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820 716243820\n" ], "outputs": [ "3 1\n1 1 1 1 1 \n", "7 2\n2 2 1 1 2 1 \...
INTRODUCTORY
PYTHON3
CODEFORCES
3,408
aac92eb2ab310c0ab9df061b48fa3ad6
UNKNOWN
A positive (strictly greater than zero) integer is called round if it is of the form d00...0. In other words, a positive integer is round if all its digits except the leftmost (most significant) are equal to zero. In particular, all numbers from $1$ to $9$ (inclusive) are round. For example, the following numbers are ...
["for _ in range(int(input())):\n n = int(input())\n # arr = list(map(int, input().split()))\n # n, m = map(int, input().split())\n arr = []\n x = 1\n while n > 0:\n if (n % 10):\n arr.append((n % 10) * x)\n n //= 10\n x *= 10\n print(len(arr))\n print(*arr)", "t ...
{ "inputs": [ "5\n5009\n7\n9876\n10000\n10\n", "7\n1\n1\n1\n1\n1\n1\n1\n", "2\n9999\n52\n", "2\n999\n52\n", "2\n954\n18\n" ], "outputs": [ "2\n9 5000 \n1\n7 \n4\n6 70 800 9000 \n1\n10000 \n1\n10 \n", "1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n1\n1 \n", "4\n9 90 900 9000 \n2\n2 50 \...
INTRODUCTORY
PYTHON3
CODEFORCES
7,571
b8168ed5122f526db9c3fc82dd9c662b
UNKNOWN
The only difference between easy and hard versions is constraints. There are $n$ kids, each of them is reading a unique book. At the end of any day, the $i$-th kid will give his book to the $p_i$-th kid (in case of $i = p_i$ the kid will give his book to himself). It is guaranteed that all values of $p_i$ are distinct...
["for _ in range(int(input())):\n n = int(input())\n P = list(map(int, input().split()))\n ans = [0] * n\n for i in range(n):\n if ans[i] == 0:\n now = i\n cnt = 0\n cll = []\n while True:\n now = P[now] - 1\n cnt += 1\n ...
{ "inputs": [ "6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3\n", "1\n3\n1 2 3\n", "20\n10\n3 8 1 4 9 6 10 2 7 5\n10\n10 4 8 6 5 3 1 2 9 7\n1\n1\n2\n2 1\n10\n2 5 3 6 9 7 4 10 8 1\n10\n1 7 4 6 9 10 8 2 3 5\n8\n3 8 1 7 6 4 2 5\n8\n7 4 5 2 8 1 6 3\n5\n1 2 4 3 5\n6\n4 2 5 6 3 1\n5\n...
INTRODUCTORY
PYTHON3
CODEFORCES
10,363
356f9a1ff1fe7409d2ffd80c444abbe8
UNKNOWN
You are both a shop keeper and a shop assistant at a small nearby shop. You have $n$ goods, the $i$-th good costs $a_i$ coins. You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all $n$ goods you...
["for _ in range(int(input())):\n n = int(input())\n A = list(map(int, input().split()))\n s = sum(A)\n print((s + n - 1) // n)", "import math\nimport itertools\nimport collections\n\ndef getdict(n):\n d = {}\n if type(n) is list or type(n) is str:\n for i in n:\n if i in d:\n ...
{ "inputs": [ "3\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\n", "1\n2\n777 1\n", "1\n1\n2441139\n", "3\n5\n1 2 3 4 5\n3\n1 2 3\n2\n777 778\n", "1\n2\n777 778\n" ], "outputs": [ "3\n2\n1\n", "389\n", "2441139\n", "3\n2\n778\n", "778\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
8,009
a43eef7662b83a4a0f42a2ea8a506579
UNKNOWN
In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$. A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a > r_b)$ and programmers $a$ and $b$ are not in a quarrel. You are gi...
["def ke(i):\n return a[i]\nn,m=map(int,input().split())\na=list(map(int,input().split()))\nb=[]\nfor i in range(n):\n b.append(i)\nb.sort(key=ke)\nans=[0]*n\nk=0\nfor i in range(1,n):\n if a[b[i]]==a[b[i-1]]:\n k+=1\n ans[b[i]]=i-k\n else:\n k=0\n ans[b[i]]=i\nfor i in range(m):...
{ "inputs": [ "4 2\n10 4 10 15\n1 2\n4 3\n", "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n", "2 0\n3 1\n", "2 0\n1 1\n", "10 35\n322022227 751269818 629795150 369443545 344607287 250044294 476897672 184054549 986884572 917181121\n6 3\n7 3\n1 9\n7 9\n10 7\n3 4\n8 6\n7 4\n6 10\n7 2\n3 5\n6 9\n3 ...
INTRODUCTORY
PYTHON3
CODEFORCES
14,954
359baa97aaf7631f03c0f0fa4061f9d6
UNKNOWN
Authors have come up with the string $s$ consisting of $n$ lowercase Latin letters. You are given two permutations of its indices (not necessary equal) $p$ and $q$ (both of length $n$). Recall that the permutation is the array of length $n$ which contains each integer from $1$ to $n$ exactly once. For all $i$ from $1...
["n,k=map(int,input().split())\naa=list(map(int,input().split()))\nbb=list(map(int,input().split()))\nab=\"abcdefghijklmnopqrstuvwxyz\"\n#print(len(ab))\nss={}\nj=0\nit=[]\nfor i in aa:\n ss[i]=j\n j+=1\njj=0\nfor i in bb:\n ind=ss[i]\n j,ind=sorted([jj,ind])\n it.append([j,ind])\n # print(i,jj,ind)\n ...
{ "inputs": [ "3 2\n1 2 3\n1 3 2\n", "5 4\n1 3 2 4 5\n2 3 5 1 4\n", "3 2\n3 1 2\n3 2 1\n", "6 5\n5 6 1 2 3 4\n6 5 1 2 3 4\n", "5 2\n5 2 4 3 1\n5 4 3 1 2\n" ], "outputs": [ "YES\nabb\n", "NO\n", "YES\nbba\n", "YES\nbcdeaa\n", "YES\nbbbba\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
14,919
5a6253e2de1a062c166ece859cf39ed1
UNKNOWN
Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed $n$ cans in a row on a table. Cans are numbered from left to right from $1$ to $n$. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which...
["n = int(input())\na = [int(x) for x in input().split()]\nb = [(a[i], i + 1) for i in range(n)]\nb.sort(reverse=True)\nans = 0\nfor i in range(n):\n ans += b[i][0] * i + 1\nprint(ans)\nfor i in b:\n print(i[1], end=' ')", "n = int(input())\nl = list(map(int, input().split()))\nfor i in range(n):\n l[i] = [l[i...
{ "inputs": [ "3\n20 10 20\n", "4\n10 10 10 10\n", "6\n5 4 5 4 4 5\n", "2\n1 4\n", "5\n13 16 20 18 11\n" ], "outputs": [ "43\n1 3 2 \n", "64\n2 1 4 3 \n", "69\n6 1 3 5 2 4 \n", "3\n2 1 \n", "138\n3 4 2 1 5 \n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
9,802
b2caa9f6f1aa8bfb58a2f7147b8735ad
UNKNOWN
Given is a permutation P_1, \ldots, P_N of 1, \ldots, N. Find the number of integers i (1 \leq i \leq N) that satisfy the following condition: - For any integer j (1 \leq j \leq i), P_i \leq P_j. -----Constraints----- - 1 \leq N \leq 2 \times 10^5 - P_1, \ldots, P_N is a permutation of 1, \ldots, N. - All valu...
["n=int(input())\np=list(map(int,input().split()))\n\nc=1\n\nq=p[0]\n\nfor i in range(1,n):\n q=min(q,p[i])\n if p[i]<=q:\n c+=1\n\nprint(c)", "n = int(input())\np = list(map(int, input().split()))\n\nans = 0\nm = p[0]\n\nfor i in p:\n\tif m >= i:\n\t\tans += 1\n\t\tm = i\n\nprint(ans)", "N = int(input())\...
{"inputs": ["5\n4 2 5 1 3\n", "4\n4 3 2 1\n", "6\n1 2 3 4 5 6\n", "8\n5 7 4 2 6 8 1 3\n", "1\n1\n"], "outputs": ["3\n", "4\n", "1\n", "4\n", "1\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
21,460
0e45b94ca6e2f5b1159bcf4bab938546
UNKNOWN
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a good sequence. Here, an sequence b is a good sequence when the following condition holds true: - For each element x in b, the value x occurs exactly x times in ...
["import collections\n\nN=int(input())\nL=list(map(int,input().split()))\nL=sorted(L)\nC=collections.Counter(L)\nD=list(C.keys())\nE=list(C.values())\nK=len(C)\nans=0\nfor i in range(K):\n\tif D[i]==E[i]:\n\t\tans+=0\n\tif D[i]>E[i]:\n\t\tans+=E[i]\n\tif D[i]<E[i]:\n\t\tans+=(E[i]-D[i])\nprint(ans)\n", "n = int(input()...
{"inputs": ["4\n3 3 3 3\n", "5\n2 4 1 4 2\n", "6\n1 2 2 3 3 3\n", "1\n1000000000\n", "8\n2 7 1 8 2 8 1 8\n"], "outputs": ["1\n", "2\n", "0\n", "1\n", "5\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
34,591
9e7116f615a4ab39e7e22817fd127354
UNKNOWN
We have five variables x_1, x_2, x_3, x_4, and x_5. The variable x_i was initially assigned a value of i. Snuke chose one of these variables and assigned it 0. You are given the values of the five variables after this assignment. Find out which variable Snuke assigned 0. -----Constraints----- - The values of x_1, x_2...
["a=list(map(int,input().split()))\nfor i in range(len(a)):\n if a[i]==0:\n print(i+1)", "x_1, x_2, x_3, x_4, x_5 = list(map(int, input().split()))\nls = [x_1, x_2, x_3, x_4, x_5]\nnum = ls.index(0)\nprint((num + 1))\n", "x = list(map(int,input().split()))\n\nprint((x.index(0)+1))\n", "x = list(map(int, input...
{"inputs": ["0 2 3 4 5\n", "1 2 0 4 5\n", "1 0 3 4 5\n", "1 2 3 0 5\n", "1 2 3 4 0\n"], "outputs": ["1\n", "3\n", "2\n", "4\n", "5\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
11,553
c917e686827a6c93dbbeb6ce75fde190
UNKNOWN
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying ...
["H, W = map(int, input().split())\nans = float('inf')\nfor h in range(1,H):\n S = [h * W]\n w = W // 2\n S += [(H-h) * w]\n S += [(H-h) * (W-w)]\n ans = min(ans,max(S)-min(S))\n\nfor h in range(1,H):\n S = [h * W]\n hb = (H-h) // 2\n S += [hb * W]\n S += [(H-h-hb) * W]\n ans = min(ans,max...
{"inputs": ["3 5\n", "4 5\n", "5 5\n", "100000 2\n", "100000 100000\n"], "outputs": ["0\n", "2\n", "4\n", "1\n", "50000\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
72,678
192098171d46438154a5f756df46ae2a
UNKNOWN
We have a sequence of length N, a = (a_1, a_2, ..., a_N). Each a_i is a positive integer. Snuke's objective is to permute the element in a so that the following condition is satisfied: - For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4. Determine whether Snuke can achieve his objective. ---...
["#!/usr/bin/env python\n\nn = int(input())\na = list(map(int, input().split()))\n\nn2 = 0 \nn4 = 0 \nfor i in range(n):\n if a[i]%4 == 0:\n n4 += 1\n elif a[i]%2 == 0:\n n2 += 1\n\nok = True\nif n2 == 0:\n if n4 >= n//2:\n ok = True\n else:\n ok = False\nelse:\n n1 = n-n2-n4\...
{"inputs": ["3\n1 10 100\n", "4\n1 2 3 4\n", "3\n1 4 1\n", "2\n1 1\n", "6\n2 7 1 8 2 8\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "Yes\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
36,083
e875d316a1a4854eb0171b12f991e4d2
UNKNOWN
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order. -----Notes----- For...
["import sys\n\ninput = sys.stdin.readline\ns = list(input().strip())\nt = list(input().strip())\nif sorted(s) < sorted(t, reverse=True):\n print(\"Yes\")\nelse:\n print(\"No\")", "s=list(input())\nt=list(input())\ns.sort()\nt.sort(reverse=True)\nif s<t:\n print(\"Yes\")\nelse:\n print(\"No\")\n \n", "s = sort...
{"inputs": ["yx\naxy\n", "ratcode\natlas\n", "cd\nabc\n", "w\nww\n", "zzz\nzzz\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
21,683
1af7f1dca0c1eb961224f75ee5c054f5
UNKNOWN
We ask you to select some number of positive integers, and calculate the sum of them. It is allowed to select as many integers as you like, and as large integers as you wish. You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer. Your objective...
["a,b,c = map(int,input().split())\n\nmod = a % b\nans = 'NO'\nfor i in range(1,b): \n if (i*mod) % b == c:\n ans = 'YES'\n break\n \nprint(ans) ", "def answer(a: int, b: int, c: int) -> str:\n for i in range(1, b + 1):\n if a * i % b == c:\n return 'YES'\n return 'NO'\n\n\ndef main():...
{"inputs": ["7 5 1\n", "2 2 1\n", "1 100 97\n", "40 98 58\n", "77 42 36\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
20,050
7f7a34e6bf07141dc5e14c94d4520e2a
UNKNOWN
There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.) What is the area of this yard excluding the roads? Find it. -----Note----- It can be ...
["a,b=map(int, input().split()) \nprint(a*b-a-b+1)", "n,m = map(int, input().split())\nprint((n-1)*(m-1))", "a,b = list(map(int,input().split()))\nprint(((a-1) * (b-1)))\n", "A, B = list(map(int, input().split()))\nprint(((A-1)*(B-1)))\n", "a,b=map(int, input().split())\n\nprint((a-1)*(b-1))", "a, b = map(int, inpu...
{"inputs": ["2 2\n", "5 7\n", "91 61\n", "100 100\n", "22 15\n"], "outputs": ["1\n", "24\n", "5400\n", "9801\n", "294\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
7,139
5c41a1224ed997a3cc77086370c9a5a1
UNKNOWN
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two ...
["#!/usr/bin/env python3\nimport sys\nsys.setrecursionlimit(10**6)\n\nx, y, z = list(map(int, input().split()))\n\nprint(((x-z)//(y+z)))\n", "x, y, z = list(map(int, input().split()))\n\nx -= z\ny += z\nprint((x // y))\n", "x, y, z = map(int, input().split())\nfor i in range(100000):\n if (i+1)*z + i*y > x:\n ...
{"inputs": ["13 3 1\n", "12 3 1\n", "100000 1 1\n", "64146 123 456\n", "64145 123 456\n"], "outputs": ["3\n", "2\n", "49999\n", "110\n", "109\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
10,976
ef973cb2377edbe7d9f9e81e81767ef8
UNKNOWN
On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i). A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and...
["N = int(input())\nab = [list(map(int, input().split())) for _ in range(N)]\ncd = [list(map(int, input().split())) for _ in range(N)]\nab.sort()\ncd.sort()\n\ng = [[] for _ in range(N)]\n\nfor i, pab in enumerate(ab):\n for j, pcd in enumerate(cd):\n if pab[0] < pcd[0] and pab[1] < pcd[1]:\n g[j]....
{"inputs": ["3\n2 0\n3 1\n1 3\n4 2\n0 4\n5 5\n", "3\n0 0\n1 1\n5 2\n2 3\n3 4\n4 5\n", "2\n2 2\n3 3\n0 0\n1 1\n", "5\n0 0\n7 3\n2 2\n4 8\n1 6\n8 5\n6 9\n5 4\n9 1\n3 7\n", "5\n0 0\n1 1\n5 5\n6 6\n7 7\n2 2\n3 3\n4 4\n8 8\n9 9\n"], "outputs": ["2\n", "2\n", "0\n", "5\n", "4\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
78,229
3b4ee669a0d1542af196a396b188800c
UNKNOWN
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push ...
["n,T = map(int,input().split())\nt = list(map(int,input().split()))\nans = 0\nfor i in range(n-1):\n ans += min(T,t[i+1]-t[i])\nprint(ans+T)", "n, t = map(int, input().split())\nT = list(map(int, input().split()))\n\nans = 0\nfor i in range(1, n):\n if T[i] - T[i - 1] >= t:\n ans += t\n else:\n ...
{"inputs": ["2 4\n0 3\n", "2 4\n0 5\n", "4 1000000000\n0 1000 1000000 1000000000\n", "1 1\n0\n", "9 10\n0 3 5 7 100 110 200 300 311\n"], "outputs": ["7\n", "8\n", "2000000000\n", "1\n", "67\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
24,249
bc965a4a6108663b9ef2f9a1307a73a3
UNKNOWN
You have got a shelf and want to put some books on it. You are given $q$ queries of three types: L $id$ — put a book having index $id$ on the shelf to the left from the leftmost existing book; R $id$ — put a book having index $id$ on the shelf to the right from the rightmost existing book; ? $id$ — calculate the mi...
["n = int(input())\nd = {}\nmatr = [0] * (2 * n + 1)\nhead = n - 1\ntail = n\nfor i in range(n):\n\tst, n = input().split()\n\tn = int(n)\n\tif st == 'L':\n\t\tmatr[head] = n\n\t\td[n] = head\n\t\thead -= 1\n\telif st == 'R':\n\t\tmatr[tail] = n\n\t\td[n] = tail\n\t\ttail += 1\n\telse:\n\t\tprint(min(d[n] - head, tail ...
{ "inputs": [ "8\nL 1\nR 2\nR 3\n? 2\nL 4\n? 1\nL 5\n? 1\n", "10\nL 100\nR 100000\nR 123\nL 101\n? 123\nL 10\nR 115\n? 100\nR 110\n? 115\n", "6\nL 1\nR 2\nR 3\n? 2\nL 4\n? 1\n", "7\nL 1\nR 2\nR 3\nL 4\nL 5\n? 1\n? 2\n" ], "outputs": [ "1\n1\n2\n", "0\n2\n1\n", "1\n1\n", "2\n1\n" ...
INTRODUCTORY
PYTHON3
CODEFORCES
12,035
efeae55d1ecbb0f9a01f827da38dce54
UNKNOWN
You are given an integer $n$. You can perform any of the following operations with this number an arbitrary (possibly, zero) number of times: Replace $n$ with $\frac{n}{2}$ if $n$ is divisible by $2$; Replace $n$ with $\frac{2n}{3}$ if $n$ is divisible by $3$; Replace $n$ with $\frac{4n}{5}$ if $n$ is divisible by...
["for i in range(int(input())):\n \n n=int(input())\n moves=0\n while n%2==0:\n n=n//2\n moves+=1\n while n%3==0:\n n=n//3\n moves+=2\n while n%5==0:\n n=n//5\n moves+=3\n if n==1:\n print(moves)\n else :\n print(-1)", "#!/usr/bin/env pytho...
{ "inputs": [ "7\n1\n10\n25\n30\n14\n27\n1000000000000000000\n", "1\n22876792454961\n", "1\n70745089028899904\n", "1\n576460752303423487\n" ], "outputs": [ "0\n4\n6\n6\n-1\n6\n72\n", "56\n", "-1\n", "-1\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
8,885
0fb976ff5a86613e4558c8531695b61f
UNKNOWN
You are given two strings $a$ and $b$ consisting of lowercase English letters, both of length $n$. The characters of both strings have indices from $1$ to $n$, inclusive. You are allowed to do the following changes: Choose any index $i$ ($1 \le i \le n$) and swap characters $a_i$ and $b_i$; Choose any index $i$ ($...
["from math import ceil\n\nn = int(input())\n\nword1 = input()\nword2 = input()\n\ncombined = []\nfor i in range(ceil(n / 2)):\n if i > n / 2 - 1:\n combined.append([word1[i], word2[i]])\n else:\n combined.append([word1[i], word1[- i - 1], word2[i], word2[- i - 1]])\n\ncount = 0\nfor l in combined:\...
{ "inputs": [ "7\nabacaba\nbacabaa\n", "5\nzcabd\ndbacz\n", "1\na\nb\n", "5\nahmad\nyogaa\n" ], "outputs": [ "4\n", "0\n", "1\n", "3\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
15,536
06196cff10555275036c396fced78dae
UNKNOWN
A frog is currently at the point $0$ on a coordinate axis $Ox$. It jumps by the following algorithm: the first jump is $a$ units to the right, the second jump is $b$ units to the left, the third jump is $a$ units to the right, the fourth jump is $b$ units to the left, and so on. Formally: if the frog has jumped an e...
["t = int(input())\nfor i in range(t):\n a, b, k = list(map(int, input().split()))\n ans = (a - b) * (k // 2)\n if k % 2 == 1:\n ans += a\n print(ans)\n", "t = int(input())\nfor i in range(t):\n\ta, b, k = list(map(int, input().split()))\n\tif k % 2 == 0:\n\t\tprint((a - b) * k // 2)\n\telse:\n\t\tpr...
{ "inputs": [ "6\n5 2 3\n100 1 4\n1 10 5\n1000000000 1 6\n1 1 1000000000\n1 1 999999999\n", "1\n19280817 1 1\n", "1\n598 56 799\n", "1\n599 56 799\n" ], "outputs": [ "8\n198\n-17\n2999999997\n0\n1\n", "19280817\n", "216856\n", "217256\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
4,092
7dec43d7305f7c0eda962fb18e0525d7
UNKNOWN
The only difference between easy and hard versions is the maximum value of $n$. You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$. The positive integer is called good if it can be represented as a sum of distinct powers ...
["for _ in range(int(input())):\n\tn = int(input())\n\n\tbits = ['1']\n\twhile int(''.join(bits), 3) < n:\n\t\tbits.append('1')\n\t\n\t\n\tfor i in range(len(bits)):\n\t\tbits[i] = '0'\n\t\tif int(''.join(bits), 3) < n:\n\t\t\tbits[i] = '1'\n\t\n\tprint(int(''.join(bits), 3))\n", "q = int(input())\nfor i in range(q):\n...
{ "inputs": [ "8\n1\n2\n6\n13\n14\n3620\n10000\n1000000000000000000\n", "1\n450283905890997363\n", "1\n387420490\n", "100\n1\n8\n4\n6\n5\n4\n4\n6\n8\n3\n9\n5\n7\n8\n8\n5\n9\n6\n9\n4\n5\n6\n4\n4\n7\n1\n2\n2\n5\n6\n1\n5\n10\n9\n10\n9\n3\n1\n2\n3\n2\n6\n9\n2\n9\n5\n7\n7\n2\n6\n9\n5\n1\n7\n8\n3\n7\n9\n3\n...
INTRODUCTORY
PYTHON3
CODEFORCES
15,797
86ed981bdd7d9e96c998140a263c28da
UNKNOWN
You are given four integers $a$, $b$, $x$ and $y$. Initially, $a \ge x$ and $b \ge y$. You can do the following operation no more than $n$ times: Choose either $a$ or $b$ and decrease it by one. However, as a result of this operation, value of $a$ cannot become less than $x$, and value of $b$ cannot become less than...
["t = int(input())\n# a = list(map(int, input().split()))\nfor _ in range(t):\n a,b,x,y,n = map(int,input().split())\n \n options = []\n a2 = max(a-n,x)\n b2 = max(b-(n-(a-a2)),y)\n options.append(a2*b2)\n \n b2 = max(b-n,y)\n a2 = max(a-(n-(b-b2)),x)\n options.append(a2*b2)\n \n pri...
{ "inputs": [ "7\n10 10 8 5 3\n12 8 8 7 2\n12343 43 4543 39 123212\n1000000000 1000000000 1 1 1\n1000000000 1000000000 1 1 1000000000\n10 11 2 1 5\n10 11 9 1 10\n", "1\n10 10 8 5 3\n", "11\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\n10 10 8 5 3\...
INTRODUCTORY
PYTHON3
CODEFORCES
10,743
68fa59a6b70ec09483e8d03b62c0cacf
UNKNOWN
You are given two positive integers $a$ and $b$. In one move, you can change $a$ in the following way: Choose any positive odd integer $x$ ($x > 0$) and replace $a$ with $a+x$; choose any positive even integer $y$ ($y > 0$) and replace $a$ with $a-y$. You can perform as many such operations as you want. You can ...
["for _ in range(int(input())):\n a, b = list(map(int, input().split()))\n if a == b:\n print(0)\n else:\n if a < b:\n if (b - a) % 2:\n print(1)\n else:\n print(2)\n else:\n if (b - a) % 2 == 0:\n print(1)\n ...
{ "inputs": [ "5\n2 3\n10 10\n2 4\n7 4\n9 3\n", "1\n19260817 114514\n", "1\n484887 54\n", "1\n55678978 55678978\n" ], "outputs": [ "1\n0\n2\n2\n1\n", "2\n", "2\n", "0\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
13,634
53a03e610ff7b19f1d0ed9632e76ad34
UNKNOWN
There is a building consisting of $10~000$ apartments numbered from $1$ to $10~000$, inclusive. Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $11, 2, 777, 9999$ and so on. Our character is a troublemaker, and he calls the intercoms of all boring apartments, till...
["# ========== //\\\\ //|| ||====//||\n# || // \\\\ || || // ||\n# || //====\\\\ || || // ||\n# || // \\\\ || || // ||\n# ========== // \\\\ ======== ||//====|| \n# code\n\n\ndef solve():\n x = int(input())\n ...
{ "inputs": [ "4\n22\n9999\n1\n777\n", "36\n1\n2\n3\n4\n5\n6\n7\n8\n9\n11\n22\n33\n44\n55\n66\n77\n88\n99\n111\n222\n333\n444\n555\n666\n777\n888\n999\n1111\n2222\n3333\n4444\n5555\n6666\n7777\n8888\n9999\n", "36\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n9999\n99...
INTRODUCTORY
PYTHON3
CODEFORCES
9,596
e14cf4f9181a1a859f45989c7bcdd536
UNKNOWN
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$. You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals...
["import sys\nk=int(input())\nL=[]\ndic=dict()\nflag=False\nfor i in range(k):\n L.append([int(input())])\n L[i].append(list(map(int,input().split())))\n s=sum(L[i][1])\n q=[]\n for j in range(L[i][0]):\n if flag:\n return\n t=s-L[i][1][j]\n if t in dic:\n x,y=d...
{ "inputs": [ "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n", "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n", "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n", "2\n2\n0 -10000\n2\n10000 0\n" ], "outputs": [ "YES\n2 1\n1 4\n", "NO\n", "YES\n4 1\n2 5\n", "YES\n2 1\n1 2\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
5,383
e65c467896125636a8c9f0137cb67ff3
UNKNOWN
Given an array A of integers, we must modify the array in the following way: we choose an i and replace A[i] with -A[i], and we repeat this process K times in total.  (We may choose the same index i multiple times.) Return the largest possible sum of the array after modifying it in this way.   Example 1: Input: A = [4,...
["class Solution:\n def largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n A.sort()\n \n i = 0\n while A[i] < 0 and K > 0:\n A[i] *= -1\n i += 1\n K -= 1\n \n if K % 2 == 1 and 0 not in A:\n return sum(A) - 2*min(A...
{"fn_name": "largestSumAfterKNegations", "inputs": [[[-2, 3, 4], 1], [[4,2,3], 1], [[3,-1,0,2], 3], [[2,-3,-1,5,-4], 2]], "outputs": [9, 5, 6, 13]}
INTRODUCTORY
PYTHON3
LEETCODE
14,845
class Solution: def largestSumAfterKNegations(self, A: List[int], K: int) -> int:
c7427873ee5b49b1af164b8d550a00c0
UNKNOWN
Given an array A of integers, return true if and only if we can partition the array into three non-empty parts with equal sums. Formally, we can partition the array if we can find indexes i+1 < j with (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1])   Example 1: Inpu...
["class Solution:\n def canThreePartsEqualSum(self, A: List[int]) -> bool:\n \n# if len(A)<3:\n# return\n \n# i = 1\n# j = len(A)-2\n \n# tgtsum = sum(A)/3\n# sum1 = sum(A[:i])\n# while i<(len(A)-2) and sum1!=tgtsum:\n# sum1...
{"fn_name": "canThreePartsEqualSum", "inputs": [[[0, 2, 3, -3, 3, -4, 5, 6, 8, 8, 9]], [[0,2,1,-6,6,7,9,-1,2,0,1]], [[0,2,1,-6,6,-7,9,1,2,0,1]], [[3,3,6,5,-2,2,5,1,-9,4]]], "outputs": [false, false, true, true]}
INTRODUCTORY
PYTHON3
LEETCODE
34,189
class Solution: def canThreePartsEqualSum(self, A: List[int]) -> bool:
70cd64cd1c5fc1a9ac35a02c8e4fcd4e
UNKNOWN
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. -----Constraints----- - 1 \leq N \leq 2 \times 10^5 - S_i (1 \leq i \leq N) are strings consisting of lowercase English letters. - The ...
["from collections import Counter\nn = int(input())\nss = [input() for _ in range(n)]\nss.sort()\nc = Counter()\nmc = 0\nfor s in ss:\n c[s] += 1\n mc = max(mc, c[s])\nseen = set()\nfor s in ss:\n if c[s] == mc and s not in seen:\n print(s)\n seen.add(s)", "n = int(input())\ns_l = [ input() for _ in range(n) ]...
{"inputs": ["7\nbeat\nvet\nbeet\nbed\nvet\nbet\nbeet\n", "8\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\nbuffalo\n", "7\nbass\nbass\nkick\nkick\nbass\nkick\nkick\n", "4\nushi\ntapu\nnichia\nkun\n"], "outputs": ["beet\nvet\n", "buffalo\n", "kick\n", "kun\nnichia\ntapu\nushi\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
32,048
7a9ee9413a6dd59ba4680756b0bdbfbc
UNKNOWN
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them. He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See S...
["n = int(input())\na = list(map(int, input().split()))\n\nans = 1e9\nfor p in range(-100, 101):\n sub = 0\n for q in a:\n sub += pow(p - q, 2)\n ans = min(ans, sub)\n\nprint(ans)\n", "n = int(input())\na = [int(x) for x in input().split()]\nres = 10 ** 9\n\nfor i in range(-100,101):\n cc = 0\n for j in range(n...
{"inputs": ["2\n4 8\n", "3\n1 1 3\n", "3\n4 2 5\n", "4\n-100 -100 -100 -100\n"], "outputs": ["8\n", "3\n", "5\n", "0\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
25,001
06075b50a085bd19e7f9acb2bb727661
UNKNOWN
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping? -----Constraints----- - 1 \leq A, B \leq 1 000 - A + B \leq X \leq ...
["print((int(input()) - int(input())) % int(input()))", "X = int(input())\nA = int(input())\nB = int(input())\n\nprint(X - A - B * ((X - A) // B))", "x=int(input())\na=int(input())\nb=int(input())\n\nprint((x-a)%b)", "x=int(input())\na=int(input())\nb=int(input())\nprint((x-a)%b)", "x = int(input())\na = int(input())\n...
{"inputs": ["1234\n150\n100\n", "1000\n108\n108\n", "579\n123\n456\n", "7477\n549\n593\n"], "outputs": ["84\n", "28\n", "0\n", "405\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
12,309
ac48d34557281b86a7f50e0ace78c22b
UNKNOWN
Snuke has N dogs and M monkeys. He wants them to line up in a row. As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there ar...
["import math\nn, m = map(int, input().split())\nmod = 10**9+7\nif abs(n-m) > 1:\n print(0)\n return\n\ndog = math.factorial(n)\nmonkey = math.factorial(m)\nif abs(n-m) == 1:\n ans = dog*monkey % mod\nelif n == m:\n ans = dog*monkey*2 % mod\nprint(ans%mod)", "N,M = map(int,input().split())\na = [0]*(max(N,M...
{"inputs": ["2 2\n", "3 2\n", "1 8\n", "100000 100000\n"], "outputs": ["8\n", "12\n", "0\n", "530123477\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
35,439
97a1c5bef6077e19fcb192e8556bdd0c
UNKNOWN
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke ...
["n,m=list(map(int,input().split()))\nM=[[] for i in range(n)]\nfor i in range(m):\n a,b=list(map(int,input().split()))\n a-=1;b-=1\n M[a].append(b)\n M[b].append(a)\nyes=\"POSSIBLE\";no=\"IMPOSSIBLE\"\n\nfor i in M[0]:\n if n-1 in M[i]:\n print(yes);return\nprint(no)\n\n", "import sys\n\ninput = ...
{"inputs": ["3 2\n1 2\n2 3\n", "4 3\n1 2\n2 3\n3 4\n", "100000 1\n1 99999\n", "5 5\n1 3\n4 5\n2 3\n2 4\n1 4\n"], "outputs": ["POSSIBLE\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "POSSIBLE\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
44,518
9becff11b5ca3621829bdf4e43b02348
UNKNOWN
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1. -----Constraints----- - Each character in s is a lowercase English letter. - 1≤|s|≤10^5 ...
["s = input()\ni = 0\nanswer = str()\nfor j in s:\n if i % 2 == 0:\n answer += j\n i += 1\nprint(answer)", "S = input()\n\nprint(S[0:len(S):2])", "s = input()\nfor i in range(0, len(s), 2):\n print(s[i], end='')\nprint()\n", "s = input()\nprint(s[0::2])", "s = input()\n# \u6587\u5b57\u5217[::2]\u3067\u5...
{"inputs": ["atcoder\n", "aaaa\n", "z\n", "fukuokayamaguchi\n"], "outputs": ["acdr\n", "aa\n", "z\n", "fkoaaauh\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
14,178
2c09c14ce6685309af6326bcb7452be5
UNKNOWN
You are given three strings A, B and C. Check whether they form a word chain. More formally, determine whether both of the following are true: - The last character in A and the initial character in B are the same. - The last character in B and the initial character in C are the same. If both are true, print YES. Othe...
["s1,s2,s3 = input().split()\nprint(\"YES\") if s1[-1]==s2[0] and s2[-1]==s3[0] else print(\"NO\")", "a,b,c = input().split()\n\nif a[len(a)-1] == b[0] and b[len(b)-1] == c[0]:\n print('YES')\nelse:\n print('NO')", "a,b,c=input().split()\nif a[-1]==b[0] and b[-1]==c[0]:\n print('YES')\nelse:\n print('NO') ", "def i...
{"inputs": ["rng gorilla apple\n", "yakiniku unagi sushi\n", "a a a\n", "aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
15,782
3af764e92f123c3e7569a2db4aac9d5e
UNKNOWN
You are given two positive integers A and B. Compare the magnitudes of these numbers. -----Constraints----- - 1 ≤ A, B ≤ 10^{100} - Neither A nor B begins with a 0. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print GREATER if A>B, LESS if A<B and EQUAL if A=B. ...
["a = int(input())\nb = int(input())\nif a < b:\n print(\"LESS\")\nelif a > b:\n print(\"GREATER\")\nelse:\n print(\"EQUAL\")", "a=int(input())\nb=int(input())\nif a>b:\n print('GREATER')\nelif a<b:\n print('LESS')\nelse:\n print('EQUAL')", "a = int(input())\nb = int(input())\n\nif b < a:\n ans = 'GREATE...
{"inputs": ["36\n24\n", "850\n3777\n", "9720246\n22516266\n", "123456789012345678901234567890\n234567890123456789012345678901\n"], "outputs": ["GREATER\n", "LESS\n", "LESS\n", "LESS\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
16,997
bc7691bac60a94812a18f04d3882fce5
UNKNOWN
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will ear...
["def resolve():\n n = int(input())\n blue_cards = list()\n for i in range(n):\n card = input()\n blue_cards.append(card)\n blue_cards = sorted(blue_cards)\n m = int(input())\n red_cards = list()\n for i in range(m):\n card = input()\n red_cards.append(card)\n red_car...
{"inputs": ["3\napple\norange\napple\n1\ngrape\n", "3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n", "1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n", "6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nb...
INTRODUCTORY
PYTHON3
ATCODER.JP
32,270
a4f711e7be1fb90857de9372876c175e
UNKNOWN
On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G. You are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b. -----Constraints----- - b is one of the letters A, C, G and T. --...
["d = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}\nprint((d[input()]))\n", "b = input()\n\nif b == 'A':\n print('T')\n\nelif b == 'T':\n print('A')\n\nelif b == 'C':\n print('G')\n\nelif b == 'G':\n print('C')", "b = input()\nb = b.replace('A', 'a')\nb = b.replace('T', 'b')\nb = b.replace('C', 'c')\nb = b.repl...
{"inputs": ["A\n", "G\n", "C\n", "T\n"], "outputs": ["T\n", "C\n", "G\n", "A\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
15,009
507afa7ba2e061135530c4a0de9f6f85
UNKNOWN
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j). You are initially in the top-left square, (1, 1). You will travel to the bottom-right square, (2, N), by repeatedly moving right or down. The square (i, j) contains A_{i, j} candies. You wi...
["def mapt(fn, *args):\n return tuple(map(fn, *args))\n\n\ndef Input():\n return mapt(int, input().split(\" \"))\n\n\ndef main():\n n = int(input())\n a_1 = Input()\n a_2 = Input()\n ans = 0\n for i in range(n):\n ans = max(ans, sum(a_1[:i+1])+sum(a_2[i:n]))\n print(ans)\n\nmain()", "N = ...
{"inputs": ["5\n3 2 2 4 1\n1 2 2 2 1\n", "4\n1 1 1 1\n1 1 1 1\n", "7\n3 3 4 5 4 5 3\n5 3 4 4 2 3 2\n", "1\n2\n3\n"], "outputs": ["14\n", "5\n", "29\n", "5\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
28,687
4911d853491cda47cba0ae9b24119d06
UNKNOWN
There are N boxes arranged in a row. Initially, the i-th box from the left contains a_i candies. Snuke can perform the following operation any number of times: - Choose a box containing at least one candy, and eat one of the candies in the chosen box. His objective is as follows: - Any two neighboring boxes contain a...
["N, x = [int(n) for n in input().split(\" \")]\nA = [int(a) for a in input().split(\" \")]\n\ncnt = 0\nif A[0] > x:\n cnt += A[0] - x\n A[0] = x\n\nfor i in range(1, len(A)):\n if A[i] + A[i - 1] > x:\n cnt += A[i] + A[i - 1] - x\n A[i] = x - A[i - 1]\n\nprint(cnt)", "N,X=map(int,input().split())\n*A,=map(int...
{"inputs": ["3 3\n2 2 2\n", "6 1\n1 6 1 2 0 4\n", "5 9\n3 1 4 1 5\n", "2 0\n5 5\n"], "outputs": ["1\n", "11\n", "0\n", "10\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
34,195
665b02be62f11d31838de5321fddb5a0
UNKNOWN
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) i...
["#!/usr/bin/env python3\n\nc = [list(map(int, input().split())) for i in range(3)]\n\n\na1 = 0\nb1, b2, b3 = c[0][0], c[0][1], c[0][2]\na2 = c[1][0]-b1\na3 = c[2][0]-b1\n\ncheck = []\ncheck.append(c[1][1] == a2+b2)\ncheck.append(c[2][1] == a3+b2)\ncheck.append(c[1][2] == a2+b3)\ncheck.append(c[2][2] == a3+b3)\n\nif su...
{"inputs": ["1 0 1\n2 1 2\n1 0 1\n", "2 2 2\n2 1 2\n2 2 2\n", "0 8 8\n0 8 8\n0 8 8\n", "1 8 6\n2 9 7\n0 7 7\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
44,353
95f9e2e6c556ca1d21f7826f7b84bd64
UNKNOWN
AtCoder Inc. holds a contest every Saturday. There are two types of contests called ABC and ARC, and just one of them is held at a time. The company holds these two types of contests alternately: an ARC follows an ABC and vice versa. Given a string S representing the type of the contest held last week, print the string...
["s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')", "S=input()\nif S==\"ARC\":\n print(\"ABC\")\nelse:\n print(\"ARC\")\n", "s = input()\n\nif s == \"ABC\":\n print(\"ARC\")\nelse:\n print(\"ABC\")\n", "s = input()\nif s == 'ABC':\n print('ARC')\nelse:\n print('ABC')\n", "S=inpu...
{"inputs": ["ABC\n", "ARC\n", "ARC\n", "ARC\n"], "outputs": ["ARC\n", "ABC\n", "ABC\n", "ABC\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
11,090
a2627a8682e57ae07153b77d129aa7c4
UNKNOWN
You are given nonnegative integers a and b (a ≤ b), and a positive integer x. Among the integers between a and b, inclusive, how many are divisible by x? -----Constraints----- - 0 ≤ a ≤ b ≤ 10^{18} - 1 ≤ x ≤ 10^{18} -----Input----- The input is given from Standard Input in the following format: a b x -----Output--...
["a,b,x=list(map(int,input().split()))\nprint((b//x-(a-1)//x))\n", "a, b, x = map(int, input().split())\n\ndef divided_num(n):\n return n//x + 1\n\nprint(divided_num(b)-divided_num(a)+(1 if a%x==0 else 0))", "a, b, x = map(int, input().split())\n\nans = b // x - (a - 1) // x\nprint(ans)", "def generator(x, a): # x\u...
{"inputs": ["4 8 2\n", "0 5 1\n", "9 9 2\n", "1 1000000000000000000 3\n"], "outputs": ["3\n", "6\n", "0\n", "333333333333333333\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
16,324
a902fe8e3e854f64d68875fca6fbe205
UNKNOWN
In some other world, today is December D-th. Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22. -----Constraints----- - 22 \leq D \leq 25 - D is an integer. -----Input----- Input is given from Standard Input in the following for...
["d=int(input())\nprint('Christmas'+' Eve'*(25-d))", "D = int (input ())\nx = 25 - D\nprint ('Christmas', 'Eve '*x)", "D = int(input())\n\nif D == 25: print('Christmas') \nelif D == 24: print('Christmas Eve')\nelif D == 23: print('Christmas Eve Eve')\nelse: print('Christmas Eve Eve Eve')", "a = int(input())\n\nif a == ...
{"inputs": ["25\n", "22\n", "23\n", "24\n"], "outputs": ["Christmas\n", "Christmas Eve Eve Eve\n", "Christmas Eve Eve\n", "Christmas Eve\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
15,264
13a7674a29f20739ce1f7f078d123663
UNKNOWN
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can b...
["#!/usr/bin/env python3\nimport sys\n\n\ndef solve(N: int):\n if N >= 64:\n print((64))\n elif N >= 32:\n print((32))\n elif N >= 16:\n print((16))\n elif N >= 8:\n print((8))\n elif N >= 4:\n print((4))\n elif N >= 2:\n print((2))\n else:\n print((...
{"inputs": ["7\n", "32\n", "1\n", "100\n"], "outputs": ["4\n", "32\n", "1\n", "64\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
21,211
6f644bd2f2f6fce4b155fc719440b2ab
UNKNOWN
Three people, A, B and C, are trying to communicate using transceivers. They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively. Two people can directly communicate when the distance between them is at most d meters. Determine if A and C can communicate, either ...
["import sys\n\n\ndef input(): return sys.stdin.readline().strip()\ndef I(): return int(input())\ndef LI(): return list(map(int, input().split()))\ndef IR(n): return [I() for i in range(n)]\ndef LIR(n): return [LI() for i in range(n)]\ndef SR(n): return [S() for i in range(n)]\ndef S(): return input()\ndef LS(): return...
{"inputs": ["4 7 9 3\n", "100 10 1 2\n", "10 10 10 1\n", "1 100 2 10\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
22,835
e7a08298cb9fb2307a8fb318ee8b8521
UNKNOWN
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between. Print the acronym formed from the uppercased initial letters of the words. -----Constraints----- - s_1, s_2 and s_3 are composed of lowercase English letters. - 1 ≤ |s_i| ≤ 10 (1≤i≤3) -----Input----- Inpu...
["def answer(s: str) -> str:\n return ''.join(s[0].upper() for s in s.split())\n\n\ndef main():\n s = input()\n print(answer(s))\n\n\ndef __starting_point():\n main()\n__starting_point()", "s1,s2,s3=map(str,input().split())\nprint((s1[0]+s2[0]+s3[0]).upper())", "def abc059a(s1: str, s2: str, s3: str) ->str:...
{"inputs": ["atcoder beginner contest\n", "resident register number\n", "k nearest neighbor\n", "async layered coding\n"], "outputs": ["ABC\n", "RRN\n", "KNN\n", "ALC\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
11,962
1f0e2e93b1c7d8651f22736ee467b3d4
UNKNOWN
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan. -----Constraints----- - All input ...
["a,b,c = map(int,input().split())\nprint(\"Yes\" if a + b >= c else \"No\")", "a, b, c = map(int, input().split())\nif a + b >= c:\n print('Yes')\nelse:\n print('No')", "A,B,C = map(int,input().split())\nprint(\"Yes\" if A+B >= C else \"No\")", "a,b,c = map(int,input().split())\nif a+b >= c:\n print(\"Yes\")\nelse:...
{"inputs": ["50 100 120\n", "500 100 1000\n", "19 123 143\n", "19 123 142\n"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
11,292
1a5baaac0def4942a7581e6eee3c0f98
UNKNOWN
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i. He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A. In how many ways can he make his selection? -----Constraints----- - 1 \leq N \leq 50 - 1 \leq A \leq 50 ...
["import sys\nimport heapq\nimport re\nfrom itertools import permutations\nfrom bisect import bisect_left, bisect_right\nfrom collections import Counter, deque\nfrom fractions import gcd\nfrom math import factorial, sqrt, ceil\nfrom functools import lru_cache, reduce\nINF = 1 << 60\nMOD = 1000000007\nsys.setrecursionli...
{"inputs": ["4 8\n7 9 8 9\n", "3 8\n6 6 9\n", "8 5\n3 6 2 8 7 6 5 9\n", "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3\n"], "outputs": ["5\n", "0\n", "19\n", "8589934591\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
53,526
9e6962d27702269fb46808ec3304631c
UNKNOWN
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: - Append a_i to the end of b. - Reverse the order of the elements in b. Find the sequence b obtained after these n operations. -----Constraints...
["n = int(input())\na = list(map(int, input().split()))\no = [a[i] for i in range(0,n,2)]\ne = [a[h] for h in range(1,n,2)]\nif n%2 == 0:\n e.reverse()\n l = e + o\n print(*l)\nelse:\n o.reverse()\n l = o + e\n print(*l)", "from collections import deque\n\nn = int(input())\nA = list(map(int, input().s...
{"inputs": ["4\n1 2 3 4\n", "3\n1 2 3\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["4 2 1 3\n", "3 1 2\n", "1000000000\n", "0 6 6 0 7 7\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
32,843
7a9a48a679e3dad1c4764b2b7dd011f3
UNKNOWN
Raccoon is fighting with a monster. The health of the monster is H. Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i. There is no other way to decrease the monster's health. Raccoon wins when the monster's health becomes 0 or below. If Raccoon can win without using the...
["h, n = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nif h <= sum(a):\n print('Yes')\nelse:\n print('No')\n", "H, N = map(int, input().split())\nlst = list(map(int, input().split()))\n\nfor i in range (0, N):\n H -= lst[i]\n\nif H <= 0:\n print(\"Yes\")\nelse:\n print(\"No\")",...
{"inputs": ["10 3\n4 5 6\n", "20 3\n4 5 6\n", "210 5\n31 41 59 26 53\n", "211 5\n31 41 59 26 53\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
19,640
ff7380686244938cb505c853846eeb4c
UNKNOWN
We will call a string that can be obtained by concatenating two equal strings an even string. For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not. You are given an even string S consisting of lowercase English letters. Find the length of the longest even string that can be obtained by deleting one o...
["S = input()\nx = len(S)\n\nfor i in range(0, x, 2):\n y = x - 2 - i\n if S[:y//2] == S[y//2 : y]:\n \n print(len(S[:y]))\n break", "S = input()\nN = len(S)\n\nfor i in range(N-1,0,-1):\n if i % 2 == 1:\n continue\n if S[:i//2] == S[i//2:i]:\n ans = i\n break\n \nprint(ans)", "n = input()\nnum...
{"inputs": ["abaababaab\n", "xxxx\n", "abcabcabcabc\n", "akasakaakasakasakaakas\n"], "outputs": ["6\n", "2\n", "6\n", "14\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
22,009
e47768110ae1014227cecbf3f75089ed
UNKNOWN
You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc. -----Constraints----- - |S|=3 - S consists of a, b and c. -----Input----- Input is given from Standard Input in the following format: S -----Output----- If S can be obtained by permuting abc, print Yes; ...
["S = list(input())\nS.sort()\nif S == ['a', 'b', 'c']:\n print(\"Yes\")\nelse:\n print(\"No\")", "s = input()\nif 'a' in s and 'b' in s and 'c' in s:\n print('Yes')\nelse:\n print('No')", "S = input()\nprint('Yes' if len(set(S)) == 3 else 'No')", "print('Yes' if sorted(input()) == list('abc') else 'No')", ...
{"inputs": ["bac\n", "bab\n", "abc\n", "aaa\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
14,800
5f9320b0a6c15c560843dd8ba3e855eb
UNKNOWN
You are given two arrays $a$ and $b$, both of length $n$. Let's define a function $f(l, r) = \sum\limits_{l \le i \le r} a_i \cdot b_i$. Your task is to reorder the elements (choose an arbitrary order of elements) of the array $b$ to minimize the value of $\sum\limits_{1 \le l \le r \le n} f(l, r)$. Since the answer ...
["n = int(input())\n\na = list(map(int, input().split()))\naord = sorted([i for i in range(n)], key=lambda x: a[x] * (n - x) * (x + 1))\n\nb = sorted(map(int, input().split()))[::-1]\nnew_b = [0] * n\nfor i in range(n):\n new_b[aord[i]] = b[i]\nb = new_b\n\nm = 998244353\n\nc = [0] * n\nfor i in range(n):\n c[i] ...
{ "inputs": [ "5\n1 8 7 2 4\n9 7 2 9 3\n", "1\n1000000\n1000000\n", "2\n1 3\n4 2\n" ], "outputs": [ "646\n", "757402647\n", "20\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
9,699
2dccfaf89e39b3013e1cef09dc154874
UNKNOWN
There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles. Misha has to buy exactly $k$ shovels. Each shovel can be bought no more than once. Misha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and buy this subset. There are...
["import sys\nimport copy\ninput = sys.stdin.readline\n\nn,m,k=list(map(int,input().split()))\nA=list(map(int,input().split()))\nSHOP=[list(map(int,input().split())) for i in range(m)]\n\nA=sorted(A)[:k]\nA=A[::-1]\n\nSHOP.sort(key=lambda x:x[0])\n\nfrom itertools import accumulate \n\nDP=[0]+list(accumulate(A))\nSUM=c...
{ "inputs": [ "7 4 5\n2 5 4 2 6 3 1\n2 1\n6 5\n2 1\n3 1\n", "9 4 8\n6 8 5 1 8 1 1 2 1\n9 2\n8 4\n5 3\n9 7\n", "5 1 4\n2 5 7 4 6\n5 4\n" ], "outputs": [ "7\n", "17\n", "17\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
16,226
871de1efd17ead8f22746bbf5da84fee
UNKNOWN
You are given two positive integers $n$ and $k$. Print the $k$-th positive integer that is not divisible by $n$. For example, if $n=3$, and $k=7$, then all numbers that are not divisible by $3$ are: $1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$. The $7$-th number among them is $10$. -----Input----- The first line contains a...
["from sys import *\nfrom collections import *\nfrom math import *\n\ninput = stdin.readline\n\ntc = int(input())\nfor tcase in range(tc):\n\tn, k = map(int, input().split())\n\tlo = 1\n\thi = 10 ** 19\n\tans = -1\n\twhile (lo <= hi):\n\t\tmid = (lo + hi) // 2\n\t\tdivi = mid - mid // n\n\t\tif (divi >= k):\n\t\t\tans ...
{ "inputs": [ "6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1\n", "7\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "1\n841 4832526\n" ], "outputs": [ "10\n15\n1999999999\n113\n1000000001\n1\n", "1\n1\n1\n1\n1\n1\n1\n", "4838279\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
2,807
837299b595c2322550ea905f3ec34a0c
UNKNOWN
The only difference between easy and hard versions are constraints on $n$ and $k$. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most $k$ most recent conversations with your friends. Initially, the screen is empty (i.e. the number of displayed conversations eq...
["from collections import deque\nn, k = map(int, input().split())\nA = list(map(int, input().split()))\nB = deque()\nB.append(A[0])\nnc = {}\nfor i in set(A):\n nc[i] = 0\nnc[A[0]] = 1\nfor i in range(1, n):\n if nc[A[i]] == 0:\n if len(B) == k:\n nc[B[0]] -= 1\n B.popleft()\n ...
{ "inputs": [ "7 2\n1 2 3 2 1 3 2\n", "10 4\n2 3 3 1 1 2 1 2 3 3\n", "1 4\n1\n" ], "outputs": [ "2\n2 1 \n", "3\n1 3 2 \n", "1\n1 \n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
11,534
a49aa6a6e8775e0457bf8744d1b2a6d9
UNKNOWN
You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game. The boss battle consists of $n$ turns. During each turn, you will get several cards. Each card has two parameters: its cost $c_i$ and damage $d_i$. You may play some of your cards during each ...
["import sys\nimport math\nimport cProfile\n\nDEBUG = False\ndef log(s):\n if DEBUG and False:\n print(s)\n \ndef calc_dmg(num, arr):\n maximum = 0\n if num - len(arr) < 0:\n maximum = max(arr)\n return sum(arr) + maximum\n\nif DEBUG:\n sys.stdin = open('input.txt')\n pr = cProfil...
{ "inputs": [ "5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n", "5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n", "1\n4\n1 1\n1 1\n2 2\n3 4\n" ], "outputs": [ "263\n", "211\n", "4\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
2,185
ceace9abfadd512012305a2de7238a11
UNKNOWN
You are given a string $s$ consisting of lowercase Latin letters and $q$ queries for this string. Recall that the substring $s[l; r]$ of the string $s$ is the string $s_l s_{l + 1} \dots s_r$. For example, the substrings of "codeforces" are "code", "force", "f", "for", but not "coder" and "top". There are two types o...
["# -*- coding: utf-8 -*-\n\nimport sys\nfrom operator import add\n\ndef input(): return sys.stdin.readline().strip()\ndef list2d(a, b, c): return [[c] * b for i in range(a)]\ndef list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]\ndef list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] ...
{ "inputs": [ "abacaba\n5\n2 1 4\n1 4 b\n1 5 b\n2 4 6\n2 1 7\n", "dfcbbcfeeedbaea\n15\n1 6 e\n1 4 b\n2 6 14\n1 7 b\n1 12 c\n2 6 8\n2 1 6\n1 7 c\n1 2 f\n1 10 a\n2 7 9\n1 10 a\n1 14 b\n1 1 f\n2 1 11\n", "aaab\n1\n2 4 4\n" ], "outputs": [ "3\n1\n2\n", "5\n2\n5\n2\n6\n", "1\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
23,853
56a4274ac455207fd9defbcad03f9684
UNKNOWN
Polycarp has three sisters: Alice, Barbara, and Cerene. They're collecting coins. Currently, Alice has $a$ coins, Barbara has $b$ coins and Cerene has $c$ coins. Recently Polycarp has returned from the trip around the world and brought $n$ coins. He wants to distribute all these $n$ coins between his sisters in such a...
["a = int(input())\nfor i in range(a):\n a1, b, c, n = list(map(int, input().split()))\n t = max(a1, b, c)\n if ((a1 + b + c + n) % 3 == 0 and t <= (a1 + b + c + n)//3 ):\n print('YES')\n else:\n print('NO')\n", "t = int(input())\nfor _ in range(t):\n\ta, b, c, n = map(int, input().split())\n\...
{ "inputs": [ "5\n5 3 2 8\n100 101 102 105\n3 2 1 100000000\n10 20 15 14\n101 101 101 3\n", "1\n1 1 1 1111\n", "1\n3 798 437 1804\n" ], "outputs": [ "YES\nYES\nNO\nNO\nYES\n", "NO\n", "YES\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
8,650
338dff03e7e8d0255b6d25dcf53f952f
UNKNOWN
Let's define $p_i(n)$ as the following permutation: $[i, 1, 2, \dots, i - 1, i + 1, \dots, n]$. This means that the $i$-th permutation is almost identity (i.e. which maps every element to itself) permutation but the element $i$ is on the first position. Examples: $p_1(4) = [1, 2, 3, 4]$; $p_2(4) = [2, 1, 3, 4]$; $p_...
["n, m = map(int, input().split())\nx = list(map(int, input().split()))\n\nfoo = [0 for _ in range(2+n)]\n\nfor i in range(1, m) :\n p, q = x[i-1], x[i]\n\n if p == q : continue\n\n r = min(p, q)\n\n s = max(p, q)\n\n foo[0] += abs(p-q)\n foo[r] -= abs(p-q)\n foo[r] += max(p, q) - 1\n foo[r+1] -...
{"inputs": ["4 4\n1 2 3 4\n", "5 5\n2 1 5 3 5\n", "2 10\n1 2 1 1 2 2 2 2 2 2\n"], "outputs": ["3 4 6 5 \n", "9 8 12 6 8 \n", "3 3 \n"]}
INTRODUCTORY
PYTHON3
CODEFORCES
17,913
39af458d2bfa4cea995c3b4b35948706
UNKNOWN
There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other. You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two districts can be connected directly or through other connected districts)....
["from bisect import bisect_left as bl\nfrom bisect import bisect_right as br\nfrom heapq import heappush,heappop\nimport math\nfrom collections import *\nfrom functools import reduce,cmp_to_key\nimport sys\ninput = sys.stdin.readline\nM = mod = 998244353\ndef factors(n):return sorted(set(reduce(list.__add__, ([i, n//i...
{ "inputs": [ "4\n5\n1 2 2 1 3\n3\n1 1 1\n4\n1 1000 101 1000\n4\n1 2 3 4\n", "1\n5\n6756657 32231 86 234 23442\n", "1\n2\n7 7\n" ], "outputs": [ "YES\n1 2\n1 3\n1 5\n5 4\nNO\nYES\n1 2\n1 3\n1 4\nYES\n1 2\n1 3\n1 4\n", "YES\n1 2\n1 3\n1 4\n1 5\n", "NO\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
7,130
7928cdc9f0416fe24aac881bbb52d0c3
UNKNOWN
You are given a binary string of length $n$ (i. e. a string consisting of $n$ characters '0' and '1'). In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given one if you can perform no more than $k$ moves? It is possible that y...
["q=int(input())\nfor t in range(q):\n n,k=map(int,input().split())\n a=input()\n ko=0\n used=[0]*n\n ans=''\n g=True\n for i in range(n):\n if a[i]=='1':\n ko+=1\n else:\n if ko<=k:\n k-=ko\n ans=ans+'0'\n else:\n ...
{ "inputs": [ "3\n8 5\n11011010\n7 9\n1111100\n7 11\n1111100\n", "2\n8 5\n11011010\n7 9\n1111100\n", "1\n2 1\n00\n" ], "outputs": [ "01011110\n0101111\n0011111\n", "01011110\n0101111\n", "00\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
18,061
d6485c12310d1558e580ae2f952f4438
UNKNOWN
The only difference between easy and hard versions is constraints. You are given $n$ segments on the coordinate axis $OX$. Segments can intersect, lie inside each other and even coincide. The $i$-th segment is $[l_i; r_i]$ ($l_i \le r_i$) and it covers all integer points $j$ such that $l_i \le j \le r_i$. The integer...
["from operator import itemgetter\nimport sys\ninput = sys.stdin.readline\n\n\nn, m = map(int, input().split())\ninfo = [list(map(int, input().split())) + [i] for i in range(n)]\ninfo = sorted(info, key = itemgetter(1))\nmax_num = info[-1][1]\n\nN = max_num\nINF = 0\nLV = (N-1).bit_length()\nN0 = 2**LV\ndata = [0]*(2*N...
{ "inputs": [ "7 2\n11 11\n9 11\n7 8\n8 9\n7 8\n9 11\n7 9\n", "5 1\n29 30\n30 30\n29 29\n28 30\n30 30\n", "6 1\n2 3\n3 3\n2 3\n2 2\n2 3\n2 3\n" ], "outputs": [ "3\n1 4 7 \n", "3\n1 2 4 \n", "4\n1 3 5 6 \n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
24,099
e9c42eba83dcb4629e5057b451d74bd9
UNKNOWN
There are $n$ points on a coordinate axis $OX$. The $i$-th point is located at the integer point $x_i$ and has a speed $v_i$. It is guaranteed that no two points occupy the same coordinate. All $n$ points move with the constant speed, the coordinate of the $i$-th point at the moment $t$ ($t$ can be non-integer) is calc...
["\ndef bitadd(a,w,bit):\n \n x = a\n while x <= (len(bit)-1):\n bit[x] += w\n x += x & (-1 * x)\n \ndef bitsum(a,bit):\n \n ret = 0\n x = a\n while x > 0:\n ret += bit[x]\n x -= x & (-1 * x)\n return ret\n\n\nn = int(input())\n\nx = list(map(int,input().split()))\nv = list...
{ "inputs": [ "3\n1 3 2\n-100 2 3\n", "5\n2 1 4 3 5\n2 2 2 3 4\n", "2\n2 1\n-3 0\n" ], "outputs": [ "3\n", "19\n", "0\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
2,863
36d67a5f68ad35658e6f8b116eef2857
UNKNOWN
You are given the array $a$ consisting of $n$ positive (greater than zero) integers. In one move, you can choose two indices $i$ and $j$ ($i \ne j$) such that the absolute difference between $a_i$ and $a_j$ is no more than one ($|a_i - a_j| \le 1$) and remove the smallest of these two elements. If two elements are equ...
["import sys\nimport math\ndef II():\n\treturn int(sys.stdin.readline())\n\ndef LI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef MI():\n\treturn list(map(int, sys.stdin.readline().split()))\n\ndef SI():\n\treturn sys.stdin.readline().strip()\nt = II()\nfor q in range(t):\n\tn = II()\n\ta = sorted(LI(...
{ "inputs": [ "5\n3\n1 2 2\n4\n5 5 5 5\n3\n1 2 4\n4\n1 3 4 4\n1\n100\n", "2\n3\n1 2 2\n4\n5 5 5 5\n", "2\n3\n1 2 3\n4\n1 2 3 4\n" ], "outputs": [ "YES\nYES\nNO\nNO\nYES\n", "YES\nYES\n", "YES\nYES\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
10,949
8a2fe1b5416d63c4766ece032cfe46dc
UNKNOWN
You are given two huge binary integer numbers $a$ and $b$ of lengths $n$ and $m$ respectively. You will repeat the following process: if $b > 0$, then add to the answer the value $a~ \&~ b$ and divide $b$ by $2$ rounding down (i.e. remove the last digit of $b$), and repeat the process again, otherwise stop the process....
["def mi():\n\treturn list(map(int, input().split()))\n\n'''\n4 4\n1010\n1101\n'''\nn,m = mi()\na = list(input())\nb = list(input())\n\npb = [0]*m\n\nif b[0]=='1':\n\tpb[0] = 1\nfor i in range(1,m):\n\tif b[i]=='1':\n\t\tpb[i] = 1\n\tpb[i]+=pb[i-1]\n\nans = 0\nif m>=n:\n\tfor i in range(n):\n\t\tif a[i]=='1':\n\t\t\tan...
{ "inputs": [ "4 4\n1010\n1101\n", "4 5\n1001\n10101\n", "5 5\n11111\n11111\n" ], "outputs": [ "12\n", "11\n", "57\n" ] }
INTRODUCTORY
PYTHON3
CODEFORCES
12,067