question
stringlengths
45
9.39k
solutions
stringlengths
2
657k
starter_code
stringlengths
0
426
input_output
stringlengths
29
26.7M
difficulty
stringclasses
6 values
raw_tags
stringlengths
2
177
name
stringclasses
149 values
source
stringclasses
10 values
tags
stringlengths
2
136
skill_types
stringclasses
53 values
url
stringlengths
37
109
⌀
Expected Auxiliary Space
stringclasses
28 values
time_limit
stringclasses
23 values
date
stringclasses
138 values
picture_num
stringclasses
4 values
memory_limit
stringclasses
12 values
Expected Time Complexity
stringclasses
53 values
The CS & IT Department students have been facing tough competitions from each other since ages, in being the best in research & innovation. This time CS Department is taken the edge over IT Department by designing a special weather predictor device which inputs previous years data and perform analysis over it to give a...
[]
{"inputs": ["2\nTOPCODER\nKODER\nONLYPROGRAMMINGPLATFORMHACKEREARTHININDIAISTHEBEST\nHABKRTEARGH", "2\nABSNVDGDJHDKLADHADBDVDVBDJGDALKDHSDJSLYTDKSDJGFSKFJGLKJFDIAMONDHEADHEADHHDEHAHKHSJHKJGDSDDJHSDJGDJBCCALJHCJDGDJHDKALDJKGSDSLKK\nDIAMMMDDEAK\nKJADSGFKJSAFGDSALFGGJKYSFKYGRTHJVFVBVNHJDGFKFHLKFVCRASHHOPPERMNVCMVBOEUOREYE...
UNKNOWN_DIFFICULTY
[]
rivalry-of-code-3
hackerearth
[]
[]
null
null
null
null
null
null
null
Given any number of boolean flags function should return true if and only if one of them is true while others are false. If function is called without arguments it should return false. ```python only_one() == False only_one(True, False, False) == True only_one(True, False, False, True) == False only_one(False,...
["def only_one(*args):\n\treturn sum(args) == 1\n", "def only_one(*args):\n\treturn args.count(True) == 1\n", "def only_one(*args):\n\tcount = 0\n\tfor item in args:\n\t\tif item:\n\t\t\tcount += 1\n\t\tif count == 2:\n\t\t\treturn False\n\treturn True if count == 1 else False\n", "def only_one(*x):\n\treturn x.count(T...
def only_one(*args):
{"fn_name": "only_one", "inputs": [], "outputs": []}
EASY
['Algorithms']
null
codewars
[]
[]
https://www.codewars.com/kata/5734c38da41454b7f700106e
null
null
null
null
null
null
After bracket sequences Arthur took up number theory. He has got a new favorite sequence of length n (a1, a2, ..., an), consisting of integers and integer k, not exceeding n. This sequence had the following property: if you write out the sums of all its segments consisting of k consecutive elements (a1 + a2 ... + ak, ...
["import sys\n(n, k) = map(int, input().split())\na = input().split()\nINF = 10 ** 9 + 7\nOK = True\nfor i in range(n):\n\tif a[i] == '?':\n\t\ta[i] = INF\n\telse:\n\t\ta[i] = int(a[i])\nfor i in range(len(a)):\n\tif a[i] == INF:\n\t\tj = i + k\n\t\twhile j < len(a) and a[j] == INF:\n\t\t\tj += k\n\t\tcount = (j - i) /...
{"inputs": ["7 2\n-10 0 ? 1 ? 2 10\n", "1 1\n0\n", "5 1\n-3 -2 -1 0 1\n", "7 1\n-4 ? ? ? ? ? 2\n", "17 1\n? -13 ? ? ? -3 ? ? ? ? ? 10 ? ? ? ? 100\n", "3 1\n-5 ? 0\n", "7 2\n-10 0 ? 1 6 2 ?\n", "3 1\n-3 ? -2\n", "6 1\n-1 ? 1 2 3 4\n", "1 1\n?\n", "9 2\n-10 0 ? 1 ? 2 ? 3 ?\n", "10 2\n3 ? 5 ? 7 ? 9 ? 11 ?\n", "9 2\n? ? -1...
HARD
['ternary search', 'greedy', 'math', 'implementation']
null
codeforces
['Mathematics', 'Sorting', 'Implementation', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/518/E
null
2.0 seconds
null
null
256.0 megabytes
null
Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad. The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $a$, $b$ and $c$ respectively. At the end of the pe...
["(a, b, c, d) = map(int, input().split())\ns = sorted([a, b, c])\nans = 0\nif s[2] - s[1] < d:\n\tans += d - (s[2] - s[1])\nif s[1] - s[0] < d:\n\tans += d - (s[1] - s[0])\nprint(ans)\n", "(a, b, c, d) = map(int, input().split())\na = [a, b, c]\na.sort()\nans = 0\nif a[2] - a[1] < d:\n\tans += d - (a[2] - a[1])\nif a[...
{"inputs": ["5 2 6 3\n", "3 1 5 6\n", "8 3 3 2\n", "2 3 10 4\n", "1000000000 1000000000 1000000000 1000000000\n", "500000000 250000000 750000000 1000000000\n", "1 3 2 5\n", "2 3 1 6\n", "9 6 2 5\n", "1 1 1 1\n", "1 1 500 10\n", "500 1 500 1000\n", "1 2 1 1\n", "89 983 751 1000\n", "716270982 22102638 553198855 10000000...
EASY
['math']
null
codeforces
['Mathematics']
[]
https://codeforces.com/problemset/problem/1185/A
null
null
2019-12-31
null
null
null
Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today. Your function should return `True` or `False` based on the following criteria. * You should take an umbrella if it's currently raining or if it's cloudy and the cha...
["def take_umbrella(weather, rain_chance):\n\treturn weather == 'cloudy' and rain_chance > 0.2 or weather == 'rainy' or (weather == 'sunny' and rain_chance > 0.5)\n", "def take_umbrella(weather, rain_chance):\n\treturn rain_chance > {'sunny': 0.5, 'cloudy': 0.2, 'rainy': -1}[weather]\n", "def take_umbrella(weather, rai...
def take_umbrella(weather, rain_chance):
{"fn_name": "take_umbrella", "inputs": [["sunny", 0.4], ["rainy", 0.0], ["cloudy", 0.2]], "outputs": [[false], [true], [false]]}
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/5865a28fa5f191d35f0000f8
null
null
null
null
null
null
Given an array A[] that stores all number from 1 to N (both inclusive and sorted) and K queries. The task is to do the following operations on array elements : 1. UNION X Z : Perform union of X and Z i.e. parent of Z will become the parent of X. 2. FIND X: Find the parent of X and print it. Note: Initially all are the ...
["def find(A, X):\n\tif A[X - 1] == X:\n\t\treturn X\n\tA[X - 1] = find(A, A[X - 1])\n\treturn A[X - 1]\n\ndef unionSet(A, X, Z):\n\tparentX = find(A, X)\n\tparentZ = find(A, Z)\n\tif parentX != parentZ:\n\t\tA[parentX - 1] = parentZ\n", "def find(A, X):\n\tif X == A[X - 1]:\n\t\treturn X\n\telse:\n\t\treturn find(A, A...
# function should return parent of x def find(A, X): # Code here # function shouldn't return or print anything def unionSet(A, X, Z): # Code here
{"fn_name": "find", "inputs": [], "outputs": []}
EASY
['Algorithms', 'union-find']
null
geeksforgeeks
['Spanning trees']
[]
https://practice.geeksforgeeks.org/problems/disjoint-set-union-find/1
O(1)
null
null
0
null
O(N)
------Read problems statements in Mandarin chinese , Russian and Vietnamese as well. ------ Tumut, the best programmer in his village Applidz, invented a problem and decided to share it with you: You are given two integer sequences $S_{1}, S_{2}, \dots, S_{N}$ and $T_{1}, T_{2}, \dots, T_{M}$ and an integer $x$. You...
["def gcd(a, b):\n\twhile b:\n\t\t(a, b) = (b, a % b)\n\treturn a\n\ndef solve(s, t, x):\n\tm = min(t)\n\tt = [a - m for a in t]\n\tm = min(s)\n\ts = [a - m for a in s]\n\tty = sum((a // x for a in t))\n\tsy = sum((a // x for a in s))\n\tif ty < sy:\n\t\t(s, t) = (t, s)\n\t\t(ty, sy) = (sy, ty)\n\tty -= sy\n\ts = sorte...
{"inputs": ["2 2 3\n1 8\n2 3"], "outputs": ["2"]}
VERY_HARD
['Mathematics', 'Algorithms', 'Observation', 'Greedy', 'Number Theory']
null
codechef
['Number theory', 'Mathematics', 'Greedy algorithms']
['Greedy algorithms']
https://www.codechef.com/problems/XTGR
null
1 seconds
2018-08-24
0
50000 bytes
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are n cashiers at the exit from the supermarket. At the moment the queue for the i-th cashier already has k_{i...
["n = int(input())\nq = map(int, input().split())\nrs = 10000000\nfor i in range(n):\n\tt = list(map(int, input().split()))\n\trs = min(rs, sum(t) * 5 + len(t) * 15)\nprint(rs)\n", "n = int(input())\nk = list(map(int, input().split()))\nm = 10 ** 10\nfor i in range(n):\n\tl = list(map(int, input().split()))\n\ts = 0\n\...
{"inputs": ["1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n", "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3\n", "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3\n", "5\n10 10 10 10 10\n6 7 8 6 8 5 9 8 10 5\n9 6 9 8 7 8 8 10 8 5\n8 7 7 8 7 5 6 8 9 5\n6 5 10 5 5 10 7 8 5 5\n10 9 8 7 6 9 7...
EASY
['implementation']
null
codeforces
['Implementation']
[]
https://codeforces.com/problemset/problem/408/A
null
null
2019-12-31
null
null
null
We all know that every positive integer can be represented as the sum of one or more odd integers. For eg: 4 = 1 + 1 + 1 + 1. Now, your task in this question is to find out the value of G(n), which equals to the number of all possible representations, as described above, of the given integer, n. Since the answer could ...
[]
{"inputs": [], "outputs": []}
UNKNOWN_DIFFICULTY
[]
integer-possibilities
hackerearth
[]
[]
null
null
null
null
null
null
null
Chef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing this takes exactly one second. Note that he cannot increase a dig...
["s = int(input())\nwhile s > 0:\n\ts -= 1\n\ta = input()\n\tc = 0\n\tfor x in a:\n\t\tc += int(x)\n\tif c < 9 and len(a) != 1:\n\t\tprint(9 - c % 9)\n\telse:\n\t\tprint(min(9 - c % 9, c % 9))\n", "test = int(input())\nfor _ in range(test):\n\tn = input()\n\ts = 0\n\tfor i in n:\n\t\ts += int(i)\n\tif len(n) > 1 and s ...
{"inputs": [["4", "1989", "86236", "90210", "99999999999999999999999999999999999999988"]], "outputs": [["0", "2", "3", "2"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/DIVNINE
null
null
null
null
null
null
Define n!! as n!! = 1 \* 3 \* 5 \* ... \* n if n is odd, n!! = 2 \* 4 \* 6 \* ... \* n if n is even. Hence 8!! = 2 \* 4 \* 6 \* 8 = 384, there is no zero at the end. 30!! has 3 zeros at the end. For a positive integer n, please count how many zeros are there at the end of n!!. Example: count\_zeros\_n\_d...
["def count_zeros_n_double_fact(n):\n\tif n % 2 != 0:\n\t\treturn 0\n\tk = 0\n\twhile n >= 10:\n\t\tk += n // 10\n\t\tn //= 5\n\treturn k\n", "def count_zeros_n_double_fact(n):\n\treturn 0 if n % 2 == 1 else n // 6250 + n // 1250 + n // 250 + n // 50 + n // 10\n", "from functools import reduce\n\ndef count_zeros_n_doub...
def count_zeros_n_double_fact(n):
{"fn_name": "count_zeros_n_double_fact", "inputs": [[8], [30], [487], [500]], "outputs": [[0], [3], [0], [62]]}
EASY
['Mathematics', 'Number Theory', 'Puzzles', 'Discrete Mathematics']
null
codewars
['Number theory', 'Mathematics', 'Ad-hoc']
[]
https://www.codewars.com/kata/58cbfe2516341cce1e000001
null
null
null
null
null
null
In the Main Berland Bank n people stand in a queue at the cashier, everyone knows his/her height hi, and the heights of the other people in the queue. Each of them keeps in mind number ai — how many people who are taller than him/her and stand in queue in front of him. After a while the cashier has a lunch break and t...
["def solve(arr, n):\n\tarr.sort()\n\tnames = [x[1] for x in arr]\n\tcounts = [x[0] for x in arr]\n\tsegments = []\n\tcurr_count = counts[0]\n\tcurr_len = 0\n\tL = 0\n\tfor i in range(n):\n\t\tif counts[i] == curr_count:\n\t\t\tcurr_len += 1\n\t\telse:\n\t\t\tsegments.append((L, i - 1))\n\t\t\tL = i\n\t\t\tcurr_count =...
{"inputs": ["23\nfgtxkw 4\nqgbokh 0\nfrb 0\nnninr 10\nbczzdfvjkh 1\nuxpelsmxxq 2\nntvvx 2\nardaae 0\nctetnl 0\nhgk 0\nvmwo 18\nojaubfibf 1\nnu 7\ngbixtuotft 4\nekmjrgxylj 1\navcygg 1\nmxgdulijf 1\notjmjmvpz 3\nxzubpxqnj 14\nlowoz 3\nmnfg 4\no 15\nm 1\n", "5\ngnaczgg 2\nzokbxiahao 4\nb 0\nnljumplxkn 4\nfyclu 1\n", "36\n...
MEDIUM_HARD
['greedy', 'sortings', 'constructive algorithms']
null
codeforces
['Greedy algorithms', 'Sorting', 'Constructive algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/141/C
null
2.0 seconds
null
null
256.0 megabytes
null
Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of `numbers` and the second is the `divisor`. ## Example ```python divisible_by([1, 2, 3, 4, 5, 6], 2) == [2, 4, 6] ```
["def divisible_by(numbers, divisor):\n\treturn [x for x in numbers if x % divisor == 0]\n", "def divisible_by(numbers, divisor):\n\treturn [i for i in numbers if i % divisor == 0]\n", "def divisible_by(numbers, divisor):\n\treturn [n for n in numbers if n % divisor == 0]\n", "def divisible_by(numbers, divisor):\n\tdiv...
def divisible_by(numbers, divisor):
{"fn_name": "divisible_by", "inputs": [[[1, 2, 3, 4, 5, 6], 2], [[1, 2, 3, 4, 5, 6], 3], [[0, 1, 2, 3, 4, 5, 6], 4], [[0], 4], [[1, 3, 5], 2], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1]], "outputs": [[[2, 4, 6]], [[3, 6]], [[0, 4]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]}
EASY
['Arrays', 'Algorithms']
null
codewars
['Data structures']
['Data structures']
https://www.codewars.com/kata/55edaba99da3a9c84000003b
null
null
null
null
null
null
John Doe decided that some mathematical object must be named after him. So he invented the Doe graphs. The Doe graphs are a family of undirected graphs, each of them is characterized by a single non-negative number — its order. We'll denote a graph of order k as D(k), and we'll denote the number of vertices in the gr...
[]
{"inputs": ["1 6\n1 13\n", "1 1000\n1 8944394323791464\n", "5 1000\n1 10000000000000000\n1 9999999999999999\n2 9999999999999999\n3 9999999999999999\n4 9999999999999999\n", "28 10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n4 8\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8\n...
VERY_HARD
['shortest paths', 'dp', 'graphs', 'divide and conquer', 'constructive algorithms']
null
codeforces
['Graph algorithms', 'Shortest paths', 'Constructive algorithms', 'Dynamic programming', 'Divide and conquer']
['Dynamic programming']
https://codeforces.com/problemset/problem/233/E
null
3.0 seconds
null
null
256.0 megabytes
null
You have most definitely heard the legend of King Arthur and the Knights of the Round Table. Almost all versions of this story proudly point out that the roundness of the Round Table is closely related to Arthur’s belief of equality among the Knights. That is a lie! In fact, Arthur’s choice of table is conditioned by h...
[]
{"inputs": ["4\n1 3 2 2\n1 1 3 2\n2 4 7 3\n3 3 5 3\n", "4\n0 0 1 1\n1 2 0 3\n2 2 3 3\n4 0 3 1\n", "3\n4 6 5 5\n2 1 15 1\n3 2 8 7\n"], "outputs": ["2 4 1 3\n", "4 3 1 2\n", "2 3 1\n"]}
HARD
[]
null
kattis
[]
[]
https://open.kattis.com/problems/artur
null
null
null
null
null
null
You have 4 bags A, B, C and D each of which includes N coins (there are totally 4N coins). Values of the coins in each bag are ai, bi, ci and di respectively. Find the number of combinations that result when you choose one coin from each bag (totally 4 coins) in such a way that the total value of the coins is V. You s...
["import sys\nfrom collections import defaultdict\n(n, v) = map(int, sys.stdin.readline().split())\na = tuple(map(int, sys.stdin.readline().split()))\nb = tuple(map(int, sys.stdin.readline().split()))\nc = tuple(map(int, sys.stdin.readline().split()))\nd = tuple(map(int, sys.stdin.readline().split()))\nmp = defaultdict...
{"inputs": ["3 14\n3 1 2\n4 8 2\n1 2 5\n7 3 2", "5 4\n2 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "5 4\n2 1 1 1 1\n1 1 1 1 1\n1 1 0 1 1\n1 1 1 1 1", "5 4\n2 1 1 1 1\n1 1 1 1 1\n1 2 0 1 1\n1 1 1 1 1", "5 4\n2 1 1 1 1\n1 1 1 1 1\n1 2 0 1 1\n1 2 1 1 1", "3 14\n3 1 2\n4 8 2\n0 0 5\n7 0 4", "5 4\n1 1 1 1 1\n1 0 1 1 1\n1 2 ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
2.0 seconds
null
null
268.435456 megabytes
null
The marmots need to prepare k problems for HC^2 over n days. Each problem, once prepared, also has to be printed. The preparation of a problem on day i (at most one per day) costs a_{i} CHF, and the printing of a problem on day i (also at most one per day) costs b_{i} CHF. Of course, a problem cannot be printed before...
["from collections import deque\nfrom heapq import heappop, heappush\n\nclass Edge(object):\n\t__slots__ = ('x', 'y', 'cap', 'cost', 'inv')\n\n\tdef __repr__(self):\n\t\treturn '{e.x}-->{e.y} ({e.cap} , {e.cost})'.format(e=self)\n\nclass MCFP(list):\n\n\tdef add(G, x, y, cap, cost):\n\t\tn = max(x, y) + 1\n\t\twhile le...
{"inputs": ["8 4\n3 8 7 9 9 4 6 8\n2 5 9 4 3 8 9 1\n", "10 6\n60 8 63 72 1 100 23 59 71 59\n81 27 66 53 46 64 86 27 41 82\n", "13 13\n93 19 58 34 96 7 35 46 60 5 36 40 41\n57 3 42 68 26 85 25 45 50 21 60 23 79\n", "12 1\n49 49 4 16 79 20 86 94 43 55 45 17\n15 36 51 20 83 6 83 80 72 22 66 100\n", "1 1\n96\n86\n", "10 6\...
VERY_HARD
['graphs', 'flows', 'binary search']
null
codeforces
['Sorting', 'Graph algorithms', 'Flows and cuts']
['Sorting']
https://codeforces.com/problemset/problem/802/N
null
null
2019-12-31
null
null
null
A permutation p is an ordered group of numbers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p_1, p_2, ..., p_{n}. Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find perm...
["def former(n, k):\n\tlst = [i for i in range(1, 2 * n + 1)]\n\tf = len(lst) - 2\n\tfor i in range(k):\n\t\t(lst[f], lst[-1]) = (lst[-1], lst[f])\n\t\tf -= 1\n\tprint(*lst)\n\treturn ''\n(a, b) = map(int, input().strip().split())\nprint(former(a, b))\n", "(n, k) = map(int, input().split())\nl = [[1, 2 * n]]\na = 2\nfo...
{"inputs": ["1 0\n", "2 1\n", "4 0\n", "2 0\n", "3 0\n", "4 1\n", "4 2\n", "6 3\n", "34 17\n", "50 1\n", "55 0\n", "3 1\n", "6 0\n", "7563 1\n", "4 2\n", "7563 3781\n", "7563 0\n", "213 100\n", "50 1\n", "3 0\n", "2 0\n", "7563 2\n", "6 3\n", "7563 3780\n", "55 0\n", "5000 0\n", "4 1\n", "6 0\n", "1333 156\n", "34 17\n...
MEDIUM
['math', 'dp', 'constructive algorithms']
null
codeforces
['Dynamic programming', 'Mathematics', 'Constructive algorithms']
['Dynamic programming']
https://codeforces.com/problemset/problem/359/B
null
null
2019-12-31
null
null
null
You are given an integer array a_1, a_2, ..., a_n, where a_i represents the number of blocks at the i-th position. It is guaranteed that 1 ≤ a_i ≤ n. In one operation you can choose a subset of indices of the given array and remove one block in each of these indices. You can't remove a block from a position without b...
["n = int(input())\n(v, c) = (list([[0, 0]]), list())\nz = ['0' for i in range(n)]\nfor (i, x) in enumerate(input().split()):\n\tv.append([int(x), i])\nv.sort(reverse=True)\n\ndef S_N_U_F_F(z, v, c):\n\t(y, k, x, count) = (-1, 0, len(v) - 1, len(v) - 1)\n\twhile v[0][0] != 0:\n\t\tif k > 0 and k < len(v) - 1:\n\t\t\tz[...
{"inputs": ["7\n1 1 1 1 1 1 1\n", "2\n1 1\n", "8\n6 2 6 6 6 2 6 6\n", "1\n1\n", "100\n3 3 2 1 3 2 3 2 2 3 3 3 1 3 3 3 2 3 3 2 1 1 3 1 3 3 1 3 1 3 1 3 2 1 1 3 1 2 3 2 2 3 3 1 1 2 1 3 2 3 2 1 3 2 3 3 1 3 2 1 2 2 2 1 3 2 1 1 2 3 2 1 3 1 3 3 2 3 1 2 1 2 1 1 2 3 1 3 2 1 3 1 1 3 3 2 1 2 1 3\n", "7\n2 5 6 4 3 3 2\n", "8\n2 2 ...
VERY_HARD
['constructive algorithms']
null
codeforces
['Constructive algorithms']
[]
https://codeforces.com/problemset/problem/1261/E
null
2.0 seconds
null
null
256.0 megabytes
null
CodeChef admins went on shopping at a shopping mall. There are N shops in the mall where the i^{th} shop has a capacity of A_{i} people. In other words, at any point in time, there can be at most A_{i} number of people in the i^{th} shop. There are X admins. Each admin wants to visit each of the N shops exactly once...
["for _ in range(int(input())):\n\t(n, x) = map(int, input().split())\n\ta = map(int, input().split())\n\ta1 = min(a)\n\tans = x // a1\n\tif x % a1 != 0:\n\t\tans += 1\n\tprint(max(ans, n))\n", "import os, sys, io, math\nfrom re import *\nfrom math import *\nfrom array import *\nfrom heapq import *\nfrom bisect import ...
{"inputs": ["3\n2 3\n3 3\n4 2\n1 2 3 4\n1 6\n2"], "outputs": ["2\n4\n3"]}
MEDIUM
['Algorithms', 'Greedy']
null
codechef
['Greedy algorithms']
['Greedy algorithms']
https://www.codechef.com/problems/ADMINSHOP
null
1 seconds
2022-04-16
0
50000 bytes
null
Problem E Black or White Here lies a row of a number of bricks each painted either black or white. With a single stroke of your brush, you can overpaint a part of the row of bricks at once with either black or white paint. Using white paint, all the black bricks in the painted part become white while originally white ...
[]
{"inputs": ["4 5\nBWWB\nWBBW", "1 5\nBWWB\nWBBW", "0 5\nBWWB\nWBBW", "4 3\nBWWB\nWBBW", "1 10\nBWWB\nWBBW", "1 19\nBWWB\nWBBW", "1 35\nBWWB\nWBBW", "1 31\nBWWB\nWBBW", "3 4\nBWWB\nWBBW", "4 10\nBWWB\nWBBW", "1 10\nBWBW\nWBBW", "1 19\nBWWA\nWBBW", "1 35\nBWWB\nWBAW", "1 31\nBWWB\nWCBW", "4 5\nBWWB\nBWBW", "1 8\nBWBW\nWB...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
2.0 seconds
null
null
268.435456 megabytes
null
Alperen has two strings, $s$ and $t$ which are both initially equal to "a". He will perform $q$ operations of two types on the given strings: $1 \;\; k \;\; x$ — Append the string $x$ exactly $k$ times at the end of string $s$. In other words, $s := s + \underbrace{x + \dots + x}_{k \text{ times}}$. $2 \;\; k \;\; x...
["import sys\nfrom math import *\ninput = lambda : sys.stdin.readline().rstrip()\nfor _ in [0] * int(input()):\n\tn = int(input())\n\tls = 1\n\tlt = 1\n\ttna = 0\n\tsna = 0\n\tfor _ in [0] * n:\n\t\t(c, k, x) = input().split()\n\t\tk = int(k)\n\t\tif int(c) == 1:\n\t\t\tls += k * len(x)\n\t\t\tsna |= len(x) - x.count('...
{"inputs": ["3\n5\n2 1 aa\n1 2 a\n2 3 a\n1 2 b\n2 3 abca\n2\n1 5 mihai\n2 2 buiucani\n3\n1 5 b\n2 3 a\n2 4 paiu\n", "1\n5\n2 1 bb\n1 2 b\n2 3 b\n1 2 c\n2 3 bcdbweakpretests\n", "1\n2\n1 1 ab\n2 1 ab\n", "1\n2\n1 3 c\n2 3 b\n", "1\n3\n2 1 z\n2 1 a\n1 1 z\n", "1\n2\n1 1 b\n2 1 b\n", "1\n2\n2 1 b\n1 1 b\n", "1\n2\n1 2 zz\...
MEDIUM
['greedy', 'strings', 'constructive algorithms']
null
codeforces
['Greedy algorithms', 'String algorithms', 'Constructive algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/1742/F
null
2 seconds
2022-10-13
0
256 megabytes
null
Given two strings of lowercase alphabets and a value K, your task is to complete the given function which tells if two strings are K-anagrams of each other or not. Two strings are called K-anagrams if both of the below conditions are true. 1. Both have same number of characters. 2. Two strings can become anagram by ch...
["class Solution:\n\n\tdef areKAnagrams(self, str1, str2, k):\n\t\tif len(str1) == len(str2):\n\t\t\tx = 0\n\t\t\tfrom collections import Counter\n\t\t\td = Counter(str1)\n\t\t\tfor i in str2:\n\t\t\t\tif d[i] > 0:\n\t\t\t\t\tx = x + 1\n\t\t\t\t\td[i] -= 1\n\t\t\tif len(str2) - x <= k:\n\t\t\t\treturn True\n\t\t\telse:...
#User function template for Python 3 class Solution: def areKAnagrams(self, str1, str2, k): # code here
{"inputs": ["str1 = \"fodr\", str2=\"gork\"\r\nk = 2"], "outputs": ["1"]}
EASY
['Data Structures', 'Strings', 'Hash']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/check-if-two-strings-are-k-anagrams-or-not/1
null
null
0
null
In this kata we want to convert a string into an integer. The strings simply represent the numbers in words. Examples: * "one" => 1 * "twenty" => 20 * "two hundred forty-six" => 246 * "seven hundred eighty-three thousand nine hundred and nineteen" => 783919 Additional Notes: * The minimum number is "zero" (inclusiv...
["words = {w: n for (n, w) in enumerate('zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen'.split())}\nwords.update({w: 10 * n for (n, w) in enumerate('twenty thirty forty fifty sixty seventy eighty ninety hundred'.split(), 2)})\nthousands ...
def parse_int(string):
{"fn_name": "parse_int", "inputs": [["zero"], ["one"], ["two"], ["three"], ["four"], ["five"], ["six"], ["seven"], ["eight"], ["nine"], ["ten"], ["twenty"], ["twenty-one"], ["thirty-seven"], ["forty-six"], ["fifty-nine"], ["sixty-eight"], ["seventy-two"], ["eighty-three"], ["ninety-four"], ["one hundred"], ["one hundre...
MEDIUM_HARD
['Strings', 'Algorithms', 'Parsing']
null
codewars
['String algorithms']
[]
https://www.codewars.com/kata/525c7c5ab6aecef16e0001a5
null
null
null
null
null
null
There is one meeting room in a firm. There are N meetings in the form of (start[i], end[i]) where start[i] is start time of meeting i and end[i] is finish time of meeting i. What is the maximum number of meetings that can be accommodated in the meeting room when only one meeting can be held in the meeting room at a par...
["class Solution:\n\n\tdef maximumMeetings(self, n, start, end):\n\t\tmeets = list(zip(start, end))\n\t\tmeets.sort(key=lambda x: x[1])\n\t\tans = 0\n\t\tlast = float('-inf')\n\t\tfor i in range(n):\n\t\t\tif meets[i][0] > last:\n\t\t\t\tans += 1\n\t\t\t\tlast = meets[i][1]\n\t\treturn ans\n", "import heapq\n\nclass So...
#User function Template for python3 class Solution: #Function to find the maximum number of meetings that can #be performed in a meeting room. def maximumMeetings(self,n,start,end): # code here
{"inputs": ["N = 6\r\nstart[] = {1,3,0,5,8,5}\r\nend[] = {2,4,6,7,9,9}", "N = 3\r\nstart[] = {10, 12, 20}\r\nend[] = {20, 25, 30}"], "outputs": ["4", "1"]}
EASY
['Algorithms', 'Greedy']
null
geeksforgeeks
['Greedy algorithms']
['Greedy algorithms']
https://practice.geeksforgeeks.org/problems/n-meetings-in-one-room-1587115620/1
O(N)
null
null
0
null
O(N*LogN)
Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that GCD of all integers in that subarray is 1. Formally, For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have to print the size of the largest valid subarray. If no valid suba...
["def gcd(a, k):\n\twhile a:\n\t\tk %= a\n\t\t(k, a) = (a, k)\n\treturn k\nfor t in range(int(input())):\n\tn = int(input())\n\ta = list(map(int, input().split()))\n\tif a[0] < a[1]:\n\t\tk = a[0]\n\telse:\n\t\tk = a[1]\n\tfor l in a:\n\t\tk = gcd(k, l)\n\tif k == 1:\n\t\tprint(n)\n\telse:\n\t\tprint(-1)\n", "def gcd(a...
{"inputs": [["2", "2", "7 2", "3", "2 2 4"], "2\n2\n7 2\n3\n3 2 4", "2\n2\n7 2\n3\n6 2 4", "2\n2\n6 2\n3\n2 2 4", "2\n2\n6 2\n3\n2 3 4", "2\n2\n7 2\n2\n6 2 4", "2\n2\n7 1\n2\n6 2 4", "2\n2\n7 4\n3\n6 2 4", "2\n2\n7 2\n1\n6 2 4", "2\n1\n6 2\n3\n2 3 4", "2\n1\n6 2\n3\n2 4 4", "2\n1\n6 2\n1\n2 4 4", "2\n1\n6 3\n1\n2 4 4",...
MEDIUM_HARD
['Mathematics', "Euclid's Algorithm", 'Groupings', 'Number Theory', 'GCD', 'Subarray', 'Data Structures', 'Arrays']
null
codechef
['Number theory', 'Combinatorics', 'Data structures', 'Mathematics']
['Data structures']
https://www.codechef.com/problems/SUBGCD
null
1 seconds
2014-06-13
0
50000 bytes
null
Chef is setting up a perfect bath for himself. He has X litres of hot water and Y litres of cold water. The initial temperature of water in his bathtub is A degrees. On mixing water, the temperature of the bathtub changes as following: The temperature rises by 1 degree on mixing 1 litre of hot water. The temperature...
["t = int(input())\nfor i in range(t):\n\t(a, b, x, y) = map(int, input().split())\n\tif a > b:\n\t\tif y >= a - b:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telif a < b:\n\t\tif x >= b - a:\n\t\t\tprint('YES')\n\t\telse:\n\t\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "import math\nfor _ in range(int(input...
{"inputs": ["4\n24 25 2 0\n37 37 2 9\n30 20 10 9\n30 31 0 20\n"], "outputs": ["YES\nYES\nNO\nNO\n"]}
EASY
['Mathematics', 'Basic Maths']
null
codechef
['Mathematics']
[]
https://www.codechef.com/problems/WTRMIXING
null
1 seconds
2022-11-12
0
50000 bytes
null
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Today a plane was hijacked by a maniac. All the passengers of the flight are taken as hostage. Chef is also one of them. He invited one of the passengers to play a game with him. If he loses the game, he will release all the passengers, othe...
["for _ in range(int(input())):\n\tl = list(map(int, input().split()))\n\tn = int(input())\n\tre = 0\n\tfor i in range(3):\n\t\tre += min(l[i], n - 1)\n\tprint(re + 1)\n", "t = int(input())\nfor i in range(t):\n\tins = list(map(int, input().split(' ')))\n\tk = int(input())\n\treal = []\n\textra = 0\n\tfor i in range(le...
{"inputs": ["2\n3 3 3\n1\n3 3 3\n2", "2\n6 3 3\n1\n3 3 3\n2", "2\n0 0 3\n2\n3 3 3\n2", "2\n6 0 3\n2\n3 3 3\n2", "2\n1 0 3\n1\n3 3 0\n2", "2\n0 0 3\n2\n3 3 4\n0", "2\n6 0 3\n3\n3 3 3\n2", "2\n0 0 3\n2\n3 4 0\n2", "2\n6 0 3\n3\n3 3 3\n4", "2\n1 1 3\n1\n0 3 0\n2", "2\n0 0 5\n2\n3 3 6\n4", "2\n0 1 3\n2\n3 3 8\n0", "2\n6 0 ...
EASY
['Mathematics', 'Group Theory']
null
codechef
['Mathematics']
[]
https://www.codechef.com/problems/CHBLLNS
null
1 seconds
2016-02-13
0
50000 bytes
null
You are given a rooted tree with vertices numerated from $1$ to $n$. A tree is a connected graph without cycles. A rooted tree has a special vertex named root. Ancestors of the vertex $i$ are all vertices on the path from the root to the vertex $i$, except the vertex $i$ itself. The parent of the vertex $i$ is the nea...
["import sys, math\nn = int(input())\na = [0 for _ in range(n)]\nb = [1 for _ in range(n)]\nk = -1\nfor i in range(n):\n\t(p, c) = map(int, sys.stdin.readline().split())\n\tif p == -1:\n\t\tk = i\n\telif c == 0:\n\t\ta[p - 1] = 1\n\telse:\n\t\tb[i] = 0\nans = []\nfor i in range(n):\n\tif a[i] == 0 and b[i] == 0 and (i ...
{"inputs": ["5\n3 1\n1 1\n-1 0\n2 1\n3 0\n", "5\n-1 0\n1 1\n1 1\n2 0\n3 0\n", "8\n2 1\n-1 0\n1 0\n1 1\n1 1\n4 0\n5 1\n7 0\n", "1\n-1 0\n", "1\n-1 0\n", "5\n-1 0\n1 0\n1 1\n2 0\n3 0\n", "8\n2 1\n-1 0\n1 1\n1 1\n1 1\n4 0\n5 1\n7 0\n", "8\n2 1\n-1 0\n1 0\n1 1\n2 1\n4 0\n5 1\n7 0\n", "5\n3 1\n1 1\n-1 0\n2 1\n3 1\n", "5\n-1...
MEDIUM
['trees', 'dfs and similar']
null
codeforces
['Tree algorithms', 'Graph traversal']
[]
https://codeforces.com/problemset/problem/1143/C
null
null
2019-12-31
null
null
null
You are given a complete undirected graph. For each pair of vertices you are given the length of the edge that connects them. Find the shortest paths between each pair of vertices in the graph and return the length of the longest of them. -----Input----- The first line of the input contains a single integer N (3 ≤ N...
["import sys\ncode = '\\nn = int(input())\\nmtr = []\\nf' + 'or i in range(n):\\n\\tmtr.append([int(i) f' + 'or i in input().split()])\\nf' + 'or k in range(n):\\n\\tf' + 'or i in range(n):\\n\\t\\tf' + 'or j in range(n):\\n\\t\\t\\tmtr[i][j] = min(mtr[i][j], mtr[i][k] + mtr[k][j])\\nmx = 0\\nf' + 'or i in range(n):\\n...
{"inputs": ["3\n0 1 1\n1 0 4\n1 4 0\n", "4\n0 1 2 3\n1 0 4 5\n2 4 0 6\n3 5 6 0\n", "10\n0 16 67 7 82 44 25 13 25 42\n16 0 24 37 63 20 19 87 55 99\n67 24 0 81 19 71 35 6 20 91\n7 37 81 0 82 89 34 80 7 32\n82 63 19 82 0 42 66 96 42 99\n44 20 71 89 42 0 65 94 24 45\n25 19 35 34 66 65 0 97 100 22\n13 87 6 80 96 94 97 0 10 ...
HARD
[]
null
codeforces
[]
[]
https://codeforces.com/problemset/problem/656/E
null
null
2019-12-31
null
null
null
Fox Ciel safely returned to her castle, but there was something wrong with the security system of the castle: sensors attached in the castle were covering her. Ciel is at point (1, 1) of the castle now, and wants to move to point (n, n), which is the position of her room. By one step, Ciel can move from point (x, y) t...
[]
{"inputs": ["100013 12021599303 71723 71217 1006\n", "59062 5181729976 2743 15168 735\n", "3 12 1 1 3\n", "2 4 1 1 2\n", "1037 1535015 168 191 70\n", "3138 9891648 1325 1589 131\n", "1037 1624622 735 908 70\n", "256 97258 191 182 33\n", "16820 290648970 3164 15749 349\n", "59062 3663830562 27882 42966 735\n", "3 5 2 1 ...
VERY_HARD
['math']
null
codeforces
['Mathematics']
[]
https://codeforces.com/problemset/problem/79/E
null
1.0 seconds
null
null
256.0 megabytes
null
Find the difference between two collections. The difference means that either the character is present in one collection or it is present in other, but not in both. Return a sorted set with difference. The collections can contain any character and can contain duplicates. For instance: A = [a,a,t,e,f,i,j] B = [t,g,g...
["def diff(a, b):\n\treturn sorted(set(a) ^ set(b))\n", "def diff(a, b):\n\ta = set(a)\n\tb = set(b)\n\tc = a.symmetric_difference(b)\n\treturn sorted(list(c))\n", "diff = lambda a, b: sorted(set([e for e in a if e not in b] + [e for e in b if e not in a]))\n", "def diff(a, b):\n\tc = []\n\tfor i in a:\n\t\tif i not in...
def diff(a, b):
{"fn_name": "diff", "inputs": [[["a", "b"], ["a", "b"]], [[], []]], "outputs": [[[]], [[]]]}
EASY
['Arrays', 'Fundamentals', 'Algorithms']
null
codewars
['Fundamentals', 'Data structures']
['Data structures']
https://www.codewars.com/kata/594093784aafb857f0000122
null
null
null
null
null
null
We have a sequence of k numbers: d_0,d_1,...,d_{k - 1}. Process the following q queries in order: - The i-th query contains three integers n_i, x_i, and m_i. Let a_0,a_1,...,a_{n_i - 1} be the following sequence of n_i numbers: \begin{eqnarray} a_j = \begin{cases} x_i & ( j = 0 ) \\ a_{j - 1} + d_{(j - 1)~\text...
["def i1():\n\treturn int(input())\n\ndef i2():\n\treturn [int(i) for i in input().split()]\n[k, q] = i2()\nd = i2()\nfor i in range(q):\n\t[n, x, m] = i2()\n\tdi = []\n\tdz = []\n\tfor i in d:\n\t\tdi.append(i % m)\n\t\tif i % m == 0:\n\t\t\tdz.append(1)\n\t\telse:\n\t\t\tdz.append(0)\n\tx = (n - 1) // k * sum(di[:k])...
{"inputs": ["3 1\n3 1 4\n5 3 2\n", "7 3\n27 18 28 18 28 46 1000000000\n1000000000 1 7\n1000000000 2 10\n1000000000 3 12\n", "3 1\n2 1 4\n5 3 2", "7 3\n27 18 28 18 28 46 1000000000\n1000000010 1 7\n1000000000 2 10\n1000000000 3 12", "7 3\n27 18 28 18 28 46 1000000000\n1000000010 1 7\n1000000000 2 10\n1000010000 3 12", "...
MEDIUM_HARD
[]
AtCoder Beginner Contest 156 - Modularness
atcoder
[]
[]
https://atcoder.jp/contests/abc156/tasks/abc156_f
null
2.0 seconds
null
null
1024.0 megabytes
null
Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. <image> However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their business. (Assume that yuan is a kind of currency in Regulu Ere.) There are ...
[]
{"inputs": ["100000 996991027 54321 67890\n", "95 1001 16 88\n", "4 7 0 0\n", "2 14 0 0\n", "1 1 0 0\n", "6536 692001792 2018 6535\n", "100000 1073741824 2 98304\n", "2 39 0 1\n", "100000 100160063 2332 99774\n", "3 999 0 3\n", "4 4 2 3\n", "1 1 0 1\n", "4 12 0 3\n", "3 6 0 0\n", "3 1234567890 2 3\n", "3 12 0 2\n", "13...
VERY_HARD
['number theory', 'combinatorics', 'math', 'chinese remainder theorem']
null
codeforces
['Number theory', 'Combinatorics', 'Mathematics']
[]
https://codeforces.com/problemset/problem/896/D
null
2.5 seconds
null
null
256.0 megabytes
null
You are given $3$ unweighted, undirected graphs, $G_1$, $G_2$, and $G_3$, with $n$ vertices each, where the $k^{th}$ graph has $m_{k}$ edges and the vertices in each graph are numbered from $\mbox{1}$ through $n$. Find the number of ordered triples $(a,b,c)$, where $1\leq a,b,c\leq n$, $a\neq b,b\neq c,c\neq a$, such t...
["vertices = int(input())\ngraph = [[], [], [], []]\ncount = 0\nG1 = 1\nG2 = 2\nG3 = 3\nfor i in range(1, 4):\n\tfor j in range(0, vertices + 1):\n\t\tgraph[i].append(None)\nfor i in range(1, 4):\n\tedges = int(input())\n\tfor j in range(0, edges):\n\t\tedge = list(map(int, input().split(' ')))\n\t\tif graph[i][edge[0]...
{"inputs": ["3\n2\n1 2\n2 3\n3\n1 2\n1 3\n2 3\n2\n1 3\n2 3\n"], "outputs": ["3\n"]}
MEDIUM_HARD
['Algorithms - Graph Theory']
null
hackerrank
['Graph algorithms']
[]
https://www.hackerrank.com/challenges/tripartite-matching/problem
null
null
null
0
null
null
An array is sorted if it has no inversions A Young Boy You are given an array of $n$ positive integers $a_1,a_2,\ldots,a_n$. In one operation you do the following: Choose any integer $x$. For all $i$ such that $a_i = x$, do $a_i := 0$ (assign $0$ to $a_i$). Find the minimum number of operations required to sort t...
["import sys\ninput = sys.stdin.readline\nfor _ in range(int(input())):\n\tn = int(input())\n\tdata = list(map(int, input().split()))[::-1]\n\tzero_set = set()\n\tmin_value = 10 ** 5 + 1\n\tend_idx = len(data)\n\tflag = True\n\twhile flag:\n\t\tfor (i, num) in enumerate(data[:end_idx]):\n\t\t\tif num in zero_set:\n\t\t...
{"inputs": ["5\n3\n3 3 2\n4\n1 3 1 3\n5\n4 1 5 3 2\n4\n2 4 1 2\n1\n1\n"], "outputs": ["1\n2\n4\n3\n0\n"]}
EASY
['greedy', 'sortings']
null
codeforces
['Sorting', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1712/C
null
1 second
2022-08-13
0
256 megabytes
null
Mathison and Chef are playing a new teleportation game. This game is played on a $R \times C$ board where each cell $(i, j)$ contains some value $V_{i, j}$. The purpose of this game is to collect a number of values by teleporting from one cell to another. A teleportation can be performed using a tel-pair. A player is g...
["from collections import namedtuple\nCurrentPosition = namedtuple('current_position', 'points, cell, pairs')\nT = int(input())\nfor _ in range(T):\n\t(R, C, N) = map(int, input().split())\n\t(Sx, Sy) = map(int, input().split())\n\ttx = map(int, input().split())\n\tty = map(int, input().split())\n\ttel_pairs = list(zip...
{"inputs": [["3", "5 5 2", "2 2", "1 2", "2 1", "10 11 62 14 15", "57 23 34 75 21", "17 12 14 11 53", "84 61 24 85 22", "43 89 14 15 43", "3 3 2", "0 0", "1 1", "1 1", "9 8 7", "5 6 4", "1 3 2", "2 2 1", "1 1", "2", "2", "5 6", "8 3"]], "outputs": [["188", "24", "3"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/MATTEG
null
null
null
null
null
null
He might be the fastest man alive on earth but not while travelling through time. Reverse_flash is out to kill Flash's Mother who is in a different time zone.Now Flash to save his mother must reach her before Reverse_flash. He had a map with him -->Map of different time zones. Flash takes a certain amount of time to c...
[]
{"inputs": ["10\n50 26\n2 3 2 1 2 4 8 9 10 3 3 5 5 3 5 8 3 1 7 10 9 1 10 2 4 5\n6 10 1 2 6 9 7 1 7 1 4 1 3 8 3 7 10 7 10 3 3 8 6 2 2 10\n2 6 2 6 2 1 10 7 3 2 2 7 9 9 4 1 2 4 5 8 6 6 1 4 3 9\n10 2 8 2 1 2 10 4 4 1 2 4 4 5 6 10 5 8 1 4 9 1 5 8 2 9\n10 7 5 1 9 4 1 1 3 4 9 10 9 2 9 2 10 10 10 6 3 2 8 4 6 2\n1 3 8 2 9 6 1 4...
MEDIUM
[]
groov
hackerearth
[]
[]
null
null
null
null
null
null
null
Xorq has invented an encryption algorithm which uses bitwise XOR operations extensively. This encryption algorithm uses a sequence of non-negative integers $x=[x[1],x[2]\cdots x[n]]$ as its key. To implement this algorithm efficiently, Xorq needs to find maximum value of $(a\oplus x_j)$ for given integers $\class{ML__b...
["from sys import stderr\nMAXBITS = 15\n\ndef main():\n\tncases = int(input())\n\tfor case in range(ncases):\n\t\t(arrsize, nqueries) = readints()\n\t\tarr = readints()\n\t\tassert arrsize == len(arr)\n\t\tfinder = XORkeyfinder(arr)\n\t\tfor query in range(nqueries):\n\t\t\t(a, start, stop) = readints()\n\t\t\tprint(fi...
{"inputs": ["1\n15 8\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n10 6 10\n1023 7 7\n33 5 8\n182 5 10\n181 1 13\n5 10 15\n99 8 9\n33 10 14\n"], "outputs": ["13\n1016\n41\n191\n191\n15\n107\n47\n"]}
HARD
['Algorithms - Bit Manipulation']
null
hackerrank
['Bit manipulation']
['Bit manipulation']
https://www.hackerrank.com/challenges/xor-key/problem
null
null
null
0
null
null
Teacher Suki loves her students very much. Now, she wants to distribute toffees among her students. She has a bag full of toffees. Since, she doesn't have time for counting, each time she randomly picks up some toffees from the bag and gives them to a student. Now, she doesn't want to be called a bad teacher, so she wa...
[]
{"inputs": ["2\n3\n2 2 1\n3\n1 6 4", "2\n0\n2 4 1\n0\n1 6 2", "2\n-2\n3 0 2\n-1\n0 0 0", "2\n-1\n2 1 1\n2\n2 2 2", "2\n0\n2 2 1\n3\n1 6 4", "2\n0\n2 2 1\n3\n1 6 2", "2\n0\n2 2 1\n0\n1 6 2", "2\n1\n2 4 1\n0\n1 6 2", "2\n1\n2 4 1\n-1\n1 6 2", "2\n1\n2 0 1\n-1\n1 6 2", "2\n1\n2 0 1\n-1\n2 6 2", "2\n1\n2 0 1\n-1\n0 6 2", "...
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/TOFFEES
null
null
null
null
null
null
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces. You are asked to calculate the number of ways he can...
["n = int(input())\ns = input().split()\nif not '1' in s:\n\tprint(0)\nelse:\n\ts = s[s.index('1'):n - s[::-1].index('1')]\n\t(res, step) = (1, 0)\n\tfor i in s:\n\t\tstep += 1\n\t\tif i == '1':\n\t\t\tres *= step\n\t\t\thas_started = True\n\t\t\tstep = 0\n\tprint(res)\n", "n = int(input())\na = list(map(int, input().s...
{"inputs": ["3\n0 1 0\n", "5\n1 0 1 0 1\n", "10\n0 0 1 0 0 0 1 1 0 1\n", "20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0\n", "50\n0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 0 1 0 1 1 0 1 0 0 1 1 1 1 1 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0\n", "99\n0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 ...
EASY
['combinatorics']
null
codeforces
['Combinatorics']
[]
https://codeforces.com/problemset/problem/617/B
null
null
2019-12-31
null
null
null
Back in 2015, Usain Bolt announced that he'll be retiring after the 2017 World Championship. Though his final season did not end gloriously, we all know that he is a true legend and we witnessed his peak during 2008 - 2013. Post retirement, Usain Bolt is still leading an adventurous life. He's exploring the unexplored...
["for i in range(int(input())):\n\t(finish, distanetobolt, tigerAcceleration, boltspeed) = map(int, input().split())\n\tt1 = (2 * (finish + distanetobolt) / tigerAcceleration) ** 0.5\n\tt2 = finish / boltspeed\n\tif t1 > t2:\n\t\tprint('Bolt')\n\telif t1 < t2:\n\t\tprint('Tiger')\n\telse:\n\t\tprint('Tiger')\n", "impor...
{"inputs": [["2", "10 100 10 10", "100 10 5 10"]], "outputs": [["Bolt", "Tiger"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/USANBOLT
null
null
null
null
null
null
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs. The stairs consists of n steps. The steps are numbered from bottom to top, it means that the lowest ste...
["n = int(input())\nstring = input()\n(q1, q2, B, C) = ([], [], [], [])\nA = 0\nfor i in range(n):\n\tif string[i] == 'D':\n\t\tq1.append(i)\n\telse:\n\t\tq2.append(n - 1 - i)\nfor i in range(len(q1)):\n\tA += (q1[i] - i) * 2 + 1\n\tB.append(A)\nA = 0\ntemp = []\nfor i in range(len(q2)):\n\tA += (q2[len(q2) - 1 - i] - ...
{"inputs": ["3\nUUD\n", "10\nUUDUDUUDDU\n", "10\nDUDDUUDUDD\n", "1\nD\n", "2\nDU\n", "3\nDUU\n", "4\nDDDU\n", "5\nDDDUD\n", "50\nDDDDDDDDDDDDDDDDDDDDDDDDDUUUUUUUUUUUUUUUUUUUUUUUUU\n", "50\nUUUUUUUUUUUUUUUUUUUUUUUUUDDDDDDDDDDDDDDDDDDDDDDDDD\n", "1\nD\n", "1\nU\n", "1\nD\n", "10\nDUDDUUDUDD\n", "50\nUUUUUUUUUUUUUUUUUUUUU...
VERY_HARD
['two pointers', 'data structures', 'math', 'constructive algorithms']
null
codeforces
['Data structures', 'Amortized analysis', 'Mathematics', 'Constructive algorithms']
['Amortized analysis', 'Data structures']
https://codeforces.com/problemset/problem/733/E
null
null
2019-12-31
null
null
null
Chef is playing a game on a sequence of N positive integers, say A_{1}, A_{2}, ... A_{N}. The game is played as follows. If all the numbers are equal, the game ends. Otherwise Select two numbers which are unequal Subtract the smaller number from the larger number Replace the larger number with the result from above (se...
["import numpy as np\nt = int(input())\nfor ni in range(t):\n\tn = int(input())\n\tl = [int(i) for i in input().split()]\n\tprint(np.gcd.reduce(l))\n", "from math import gcd\nt = int(input())\nfor t in range(t):\n\tn = int(input())\n\tarr = [int(i) for i in input().split()]\n\tflag = 1\n\tfor i in range(n - 1):\n\t\tif...
{"inputs": ["3\n2\n10 12\n2\n5 9\n3\n6 10 15", "3\n2\n10 12\n2\n5 9\n3\n8 10 15", "3\n2\n10 12\n2\n5 9\n3\n8 10 24", "3\n2\n10 19\n2\n5 9\n3\n8 10 24", "3\n2\n10 12\n2\n5 9\n3\n6 9 15", "3\n2\n10 12\n2\n7 14\n3\n8 10 24", "3\n2\n19 12\n2\n7 9\n3\n3 10 24", "3\n2\n10 21\n2\n7 14\n3\n8 10 24", "3\n2\n10 12\n2\n5 10\n3\n8...
EASY
['Mathematics', 'Algorithms', 'Observation', 'Number Theory', 'GCD']
null
codechef
['Number theory', 'Mathematics']
[]
https://www.codechef.com/problems/AMSGAME1
null
1 seconds
2013-05-11
0
50000 bytes
null
Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1 ≤ pi ≤ n). Little penguin Polo loves walking around this village. The walk looks like that. First he stands by a hou...
["MOD = 10 ** 9 + 7\n(n, k) = map(int, input().split())\nans = pow(n - k, n - k, MOD) * pow(k, k - 1, MOD)\nprint(ans % MOD)\n", "(n, k) = map(int, input().split())\nmod = 10 ** 9 + 7\nprint(pow(k, k - 1, mod) * pow(n - k, n - k, mod) % mod)\n", "(n, k) = map(int, input().split())\nM = 10 ** 9 + 7\nprint(k ** (~-k) * p...
{"inputs": ["475 5\n", "10 7\n", "685 7\n", "8 5\n", "12 8\n", "9 8\n", "137 5\n", "2 2\n", "657 3\n", "1000 8\n", "473 4\n", "2 1\n", "100 8\n", "1000 6\n", "1000 1\n", "1000 5\n", "8 8\n", "1 1\n", "876 8\n", "1000 2\n", "50 2\n", "1000 4\n", "999 7\n", "975 8\n", "3 3\n", "227 6\n", "1000 3\n", "8 1\n", "198 5\n", "...
MEDIUM
['combinatorics']
null
codeforces
['Combinatorics']
[]
https://codeforces.com/problemset/problem/289/D
null
2.0 seconds
null
null
256.0 megabytes
null
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e...
["__author__ = 'Admin'\n\ndef f(n):\n\treturn max(n[0], n[1])\nt = True\n(x1, y1, x2, y2, x3, y3) = map(int, input().split())\nm = [x1, y1, x2, y2, x3, y3]\nm1 = [[x1, y1, 'A'], [x2, y2, 'B'], [x3, y3, 'C']]\nm1.sort(key=f)\nmaxi = max(m1[-1][0], m1[-1][1])\nmini = min(m1[-1][0], m1[-1][1])\nmaxj = max(m1[-2][1], m1[-2...
{"inputs": ["5 1 2 5 5 2\n", "4 4 2 6 4 2\n", "1 3 1 3 3 1\n", "2 4 1 4 1 4\n", "7 2 7 2 7 3\n", "1 10 6 10 3 10\n", "20 1 20 1 18 20\n", "2 1 3 1 2 2\n", "1 2 2 4 3 2\n", "7 4 3 3 4 3\n", "2 1 9 10 1 8\n", "20 4 8 16 12 16\n", "100 100 100 100 100 100\n", "1 100 100 1 1 100\n", "100 100 100 1 100 100\n", "3 8 4 8 2 8\...
MEDIUM_HARD
['geometry', 'implementation', 'math', 'brute force', 'bitmasks', 'constructive algorithms']
null
codeforces
['Bit manipulation', 'Constructive algorithms', 'Geometry', 'Implementation', 'Complete search', 'Mathematics']
['Bit manipulation', 'Complete search']
https://codeforces.com/problemset/problem/581/D
null
null
2019-12-31
null
null
null
We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\cdots, N and 1, 2, \cdots, N-1. Edge i connects Vertex u_i and v_i. For integers L, R (1 \leq L \leq R \leq N), let us define a function f(L, R) as follows: - Let S be the set of the vertices numbered L through R. f(L, R) represents the number o...
["n = int(input())\nans = 0\nfor i in range(n):\n\tans += (i + 1) * (n - i)\nfor j in range(n - 1):\n\t(u, v) = map(int, input().split(' '))\n\tif u <= v:\n\t\tans -= u * (n - v + 1)\n\telse:\n\t\tans -= v * (n - u + 1)\nprint(ans)\n", "N = int(input())\ntyoutensuu = N * (N + 1) * (N + 1) // 2 - N * (N + 1) * (2 * N + ...
{"inputs": ["3\n1 3\n2 3\n", "2\n1 2\n", "10\n5 3\n5 7\n8 9\n1 9\n9 10\n8 4\n7 4\n6 10\n7 2\n", "2\n0 2", "10\n5 3\n5 7\n8 9\n0 9\n9 10\n8 4\n7 4\n6 10\n7 2", "3\n1 3\n0 3", "10\n5 3\n5 7\n8 9\n0 9\n12 10\n8 4\n7 4\n6 10\n7 2", "2\n-1 1", "10\n5 3\n5 7\n8 9\n0 9\n12 10\n4 4\n7 4\n6 10\n7 2", "2\n-1 2", "3\n1 0\n0 6", "...
MEDIUM_HARD
[]
AtCoder Beginner Contest 173 - Intervals on Tree
atcoder
[]
[]
https://atcoder.jp/contests/abc173/tasks/abc173_f
null
2.0 seconds
null
null
1024.0 megabytes
null
Read problems statements in Mandarin Chinese and Russian. Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.   Lets function f(A,i) = S - A[i] - A[i +1] - ... - A[j], where j is the maximu...
["import sys\nfor j in range(int(sys.stdin.readline())):\n\t(n, k, s) = map(int, sys.stdin.readline().split())\n\tm = list(map(int, sys.stdin.readline().split()))\n\tif n == 3 and k == 2 and (s == 4):\n\t\tprint(2, 1, 3)\n\t\tcontinue\n\tif n == 4 and k == 4 and (s == 1):\n\t\tprint(4, 3, 2, 1)\n\t\tcontinue\n\t[print(...
{"inputs": ["2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1"], "outputs": ["2 1 3\n4 3 2 1"]}
VERY_HARD
['Challenge Problem']
null
codechef
[]
[]
https://www.codechef.com/problems/SEAPERM
null
1 seconds
2013-11-09
0
50000 bytes
null
At the school where the twins Ami and Mami attend, the summer vacation has already begun, and a huge amount of homework has been given this year as well. However, the two of them were still trying to go out without doing any homework today. It is obvious that you will see crying on the last day of summer vacation as it...
["while True:\n\tn = int(input())\n\tif n == 0:\n\t\tbreak\n\tbooks = []\n\tread_t = 0\n\twrite_t = 0\n\tfor i in range(n):\n\t\t(r, w) = map(int, input().split())\n\t\tread_t += r\n\t\twrite_t += w\n\t\tbooks.append((r, w))\n\tbooks = sorted(books)\n\tif books[-1][0] <= read_t // 2:\n\t\tprint(read_t + write_t)\n\t\tc...
{"inputs": ["4\n1 1\n3 1\n4 1\n2 1\n3\n5 2\n1 2\n1 2\n1\n1000 1000\n10\n5 62\n10 68\n15 72\n20 73\n25 75\n30 77\n35 79\n40 82\n45 100\n815 283\n6\n74 78\n53 55\n77 77\n12 13\n39 42\n1 1\n0", "4\n1 1\n3 1\n4 1\n2 1\n3\n5 2\n1 2\n1 2\n1\n1000 1001\n10\n5 62\n10 68\n15 72\n20 73\n25 75\n30 77\n35 79\n40 82\n45 100\n815 28...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
8.0 seconds
null
null
134.217728 megabytes
null
Given three positive integers X, Y and P. Here P denotes the number of turns. Whenever the turn is odd X is multiplied by 2 and in every even turn Y is multiplied by 2.Find the value of Max(X, Y) ÷ Min(X, Y) after the completion of P turns. Example 1: Input: X=1 Y=2 P=1 Output: 1 Explanation: After 1st turn, X=2,Y=2. N...
["class Solution:\n\n\tdef findValue(self, X, Y, P):\n\t\tif P % 2 == 0:\n\t\t\treturn int(max(X, Y) / min(X, Y))\n\t\telse:\n\t\t\treturn int(max(2 * X, Y) / min(2 * X, Y))\n", "from math import *\n\nclass Solution:\n\n\tdef findValue(self, X, Y, P):\n\t\tif P % 2 != 0:\n\t\t\tX = X * 2\n\t\t\treturn max(X, Y) // min(...
#User function Template for python3 class Solution: def findValue(self,X,Y,P): #code here
{"inputs": ["X=1\nY=2\nP=1", "X=2\nY=1\nP=2"], "outputs": ["1", "2"]}
EASY
['number-theory']
null
geeksforgeeks
['Number theory']
[]
https://practice.geeksforgeeks.org/problems/even-odd-turn-game1832/1
O(1)
null
null
0
null
O(1)
Process the Q queries below. * You are given two integers A_i and M_i. Determine whether there exists a positive integer K_i not exceeding 2 × 10^{18} such that A_i^{K_i} ≡ K_i (mod M_i), and find one if it exists. Constraints * 1 \leq Q \leq 100 * 0 \leq A_i \leq 10^9(1 \leq i \leq Q) * 1 \leq M_i \leq 10^9(1 \leq ...
["def extgcd(a, b):\n\tif b == 0:\n\t\treturn 1\n\telse:\n\t\t(x, y, u, v, k, l) = (1, 0, 0, 1, a, b)\n\t\twhile l != 0:\n\t\t\t(x, y, u, v) = (u, v, x - u * (k // l), y - v * (k // l))\n\t\t\t(k, l) = (l, k % l)\n\t\treturn x\n\ndef inved(x, m):\n\treturn x % m\n\ndef gcd(x, y):\n\twhile y != 0:\n\t\t(x, y) = (y, x % ...
{"inputs": ["3\n177 168\n2028 149618\n123456789 987654321", "3\n177 168\n2028 19211\n123456789 987654321", "3\n177 168\n978 19211\n123456789 987654321", "3\n177 168\n978 19211\n235722608 987654321", "3\n177 168\n978 24407\n235722608 987654321", "3\n177 168\n978 24407\n153960391 987654321", "3\n177 168\n978 1048\n153960...
UNKNOWN_DIFFICULTY
[]
Tenka1 Programmer Contest - ModularPowerEquation!!
atcoder
[]
[]
null
null
2.0 seconds
null
null
256.0 megabytes
null
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy alread...
["def f(m):\n\tnonlocal dp, sdp\n\tl = 0\n\tfor i in range(n):\n\t\twhile l < n and v[l] < v[i] - m:\n\t\t\tl += 1\n\t\tif l - 1 > i - k:\n\t\t\tdp[i] = False\n\t\telse:\n\t\t\tdp[i] = sdp[i - k + 1] != sdp[l - 1]\n\t\tsdp[i + 1] = sdp[i] + (1 if dp[i] else 0)\n\treturn dp[n - 1]\n(n, k) = map(int, input().split())\ndp...
{"inputs": ["5 2\n50 110 130 40 120\n", "4 1\n2 3 4 1\n", "1 1\n4\n", "2 2\n7 5\n", "3 2\n34 3 75\n", "5 2\n932 328 886 96 589\n", "10 4\n810 8527 9736 3143 2341 6029 7474 707 2513 2023\n", "20 11\n924129 939902 178964 918687 720767 695035 577430 407131 213304 810868 596349 266075 123602 376312 36680 18426 716200 12154...
HARD
['binary search', 'dp']
null
codeforces
['Dynamic programming', 'Sorting']
['Dynamic programming', 'Sorting']
https://codeforces.com/problemset/problem/883/I
null
null
2019-12-31
null
null
null
Say hello! Write a function to greet a person. Function will take name as input and greet the person by saying hello. Return null/nil/None if input is empty string or null/nil/None. Example: ```python greet("Niks") --> "hello Niks!" greet("") --> None # Return None if input is empty string greet(None) --> None ...
["def greet(name):\n\treturn f'hello {name}!' if name else None\n", "def greet(name):\n\tif name:\n\t\treturn f'hello {name}!'\n", "def greet(s):\n\tif s:\n\t\treturn f'hello {s}!'\n", "def greet(name=None):\n\treturn 'hello {}!'.format(name) if name else None\n", "def greet(n):\n\tif n:\n\t\treturn f'hello {n}!'\n", "...
def greet(name):
{"fn_name": "greet", "inputs": [["Niks"], ["Nick"], [""], [null]], "outputs": [["hello Niks!"], ["hello Nick!"], [null], [null]]}
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/55955a48a4e9c1a77500005a
null
null
null
null
null
null
You are given a sorted array $a_1, a_2, \dots, a_n$ (for each index $i > 1$ condition $a_i \ge a_{i-1}$ holds) and an integer $k$. You are asked to divide this array into $k$ non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let $max(i)$ be equal to the maximum i...
["(n, k) = map(int, input().split())\nlis = list(map(int, input().split()))\nan = []\nfor i in range(1, n):\n\tan.append(lis[i] - lis[i - 1])\nans = sorted(range(len(an)), key=lambda k: an[k], reverse=True)\nfor i in range(k - 1):\n\tan[ans[i]] = 0\nprint(sum(an))\n", "(n, k) = map(int, input().split())\na = list(map(i...
{"inputs": ["6 3\n4 8 15 16 23 42\n", "4 4\n1 3 3 7\n", "8 1\n1 1 2 3 5 8 13 21\n", "1 1\n1\n", "5 2\n3 3 4 5 6\n", "1 1\n20\n", "1 1\n56\n", "1 1\n4\n", "5 3\n99 101 103 105 107\n", "1 1\n2\n", "1 1\n1\n", "5 2\n-1 -2 5 -4 8\n", "5 2\n3 3 4 5 6\n", "7 6\n-3 0 -1 -2 -2 -4 -1\n", "1 1\n4\n", "1 1\n2\n", "4 1\n3 -1 6 0\n...
MEDIUM
['greedy', 'sortings']
null
codeforces
['Sorting', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1197/C
null
null
2019-12-31
null
null
O(NLOG(N))
## Description Your job is to create a simple password validation function, as seen on many websites. The rules for a valid password are as follows: - There needs to be at least 1 uppercase letter. - There needs to be at least 1 lowercase letter. - There needs to be at least 1 number. - The password needs to be at le...
["CRITERIA = (str.islower, str.isupper, str.isdigit)\n\ndef password(s):\n\treturn len(s) > 7 and all((any(map(f, s)) for f in CRITERIA))\n", "import re\n\ndef password(s):\n\treturn bool(re.match('(?=.*[A-Z])(?=.*[a-z])(?=.*\\\\d).{8}', s))\n", "import re\n\ndef password(string):\n\tpatterns = ('[A-Z]', '[a-z]', '[0-9...
def password(string):
{"fn_name": "password", "inputs": [["Abcd1234"], ["Abcd123"], ["abcd1234"], ["AbcdefGhijKlmnopQRsTuvwxyZ1234567890"], ["ABCD1234"], ["Ab1!@#$%^&*()-_+={}[]|\\:;?/>.<,"], ["!@#$%^&*()-_+={}[]|\\:;?/>.<,"], [""], [" aA1----"], ["4aA1----"]], "outputs": [[true], [false], [false], [true], [false], [true], [false], [false],...
EASY
['Regular Expressions', 'Algorithms', 'Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/56a921fa8c5167d8e7000053
null
null
null
null
null
null
Example Input 7 4 DEFG FEDA EFGB BGEA AGFD DABC CADE Output ABCDEFG
[]
{"inputs": ["7 4\nDEFG\nFEDA\nEFGB\nBGEA\nAGFD\nDABC\nCEDA", "7 4\nDEFG\nFECA\nEFGB\nBGEA\nAGFD\nDABC\nCADE", "7 4\nDEFG\nFEDA\nEFGB\nBGEA\nAGFD\nDABC\nADEC", "7 4\nDEFG\nFEDA\nEFGB\nBGEA\nAGFD\nCBAD\nADEC", "7 4\nDEGF\nFEDA\nEFGB\nBGEA\nAGFD\nDACB\nCADE", "7 4\nDEFG\nFEDA\nEFGB\nBGEA\nDGFA\nCDAB\nADEC", "7 4\nDEFG\nFE...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
3.0 seconds
null
null
268.435456 megabytes
null
Generous sponsors of the olympiad in which Chloe and Vladik took part allowed all the participants to choose a prize for them on their own. Christmas is coming, so sponsors decided to decorate the Christmas tree with their prizes. They took n prizes for the contestants and wrote on each of them a unique id (integer f...
["import sys\ninput = sys.stdin.readline\noo = 10 ** 20\nn = int(input())\na = list(map(int, input().split()))\nadj = [[] for _ in range(n)]\nfor _ in range(n - 1):\n\t(u, v) = [int(i) - 1 for i in input().split()]\n\tadj[u].append(v)\n\tadj[v].append(u)\nsm = [0] * n\nmx = [-oo] * n\nbest = [-oo] * n\nstack = [(0, -1)...
{"inputs": ["8\n0 5 -1 4 3 2 6 5\n1 2\n2 4\n2 5\n1 3\n3 6\n6 7\n6 8\n", "4\n1 -5 1 1\n1 2\n1 4\n2 3\n", "1\n-1\n", "10\n3 2 -4 2 0 3 3 3 3 4\n10 8\n4 2\n4 9\n3 5\n5 2\n7 4\n2 6\n1 8\n10 9\n", "10\n-1 2 -2 -3 -1 -1 0 -4 -5 -4\n4 6\n6 9\n1 2\n6 2\n7 8\n7 9\n5 10\n6 3\n10 1\n", "10\n4 -4 2 5 -1 3 -1 1 4 5\n1 8\n7 1\n4 1\n...
MEDIUM_HARD
['trees', 'dfs and similar', 'graphs', 'dp']
null
codeforces
['Tree algorithms', 'Graph algorithms', 'Graph traversal', 'Dynamic programming']
['Dynamic programming']
https://codeforces.com/problemset/problem/743/D
null
null
2019-12-31
null
null
null
Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of their friends and gave a drop of it to everyone. Now they all were f...
["l1 = int(input())\nfor i in range(l1):\n\tx = int(input())\n\ty = list(map(int, input().split()))\n\tz = list(map(int, input().split()))\n\tif max(z) != max(y):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "try:\n\tfor _ in range(int(input())):\n\t\tn = int(input())\n\t\ta = list(map(int, input().split()))\n\t\tb ...
{"inputs": [["1", "5", "1 2 3 4 5", "2 7 8 9 9", ""]], "outputs": [["YES"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/CHPTRS01/problems/FUNRUN
null
null
null
null
null
null
Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III. Constraints * $2 \leq n \leq 100$ * $0 \leq $ the integer assigned to a face $ \leq 100$ Input In the first line, the number of dices $n$ i...
["ptn = [[1, 2, 3, 4, 5, 6], [2, 6, 3, 4, 1, 5], [3, 6, 5, 2, 1, 4], [4, 6, 2, 5, 1, 3], [5, 6, 4, 3, 1, 2], [6, 2, 4, 3, 5, 1]]\n\ndef diffDice(orgDice, newDice):\n\tflg = False\n\ttmpDice = [0, 0, 0, 0, 0, 0]\n\tfor i in range(6):\n\t\tfor (idx, j) in enumerate(ptn[i]):\n\t\t\ttmpDice[idx] = newDice[j - 1]\n\t\tif or...
{"inputs": ["3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 2 3 4 5 6\n6 2 5 3 5 1\n6 5 4 3 2 1", "3\n1 2 3 4 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 2 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1", "3\n1 2 3 3 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 4 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1", "3\n1 2 3 3 5 6\n5 2 4 3 2 1\n5 4 0 2 1 6", ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
1.0 seconds
null
null
134.217728 megabytes
null
There are twelve types of tiles in Fig. 1. You were asked to fill a table with R × C cells with these tiles. R is the number of rows and C is the number of columns. How many arrangements in the table meet the following constraints? * Each cell has one tile. * the center of the upper left cell (1,1) and the center of...
[]
{"inputs": ["4 4\n0 0 1 1 1 2 0 1 0 0 1 1", "3 3\n0 0 1 0 0 0 0 0 0 0 0 10", "3 3\n0 2 1 0 0 0 0 0 0 0 0 7", "2 4\n0 0 1 1 1 3 0 1 0 0 1 1", "5 2\n1 1 1 1 0 1 2 1 2 0 0 1", "4 2\n0 1 1 0 0 1 2 0 2 0 0 1", "5 2\n1 1 1 1 0 1 2 2 2 0 0 1", "2 3\n1 0 1 1 0 2 0 1 0 0 1 0", "5 2\n1 0 1 1 0 1 2 2 2 0 0 1", "4 2\n1 1 1 0 0 1 2...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
5.0 seconds
null
null
134.217728 megabytes
null
Read problems statements in Mandarin Chinese , Russian and Vietnamese Chef likes to play table tennis. He found some statistics of matches which described who won the points in order. A game shall be won by the player first scoring 11 points except in the case when both players have 10 points each, then the game sha...
["for _ in range(int(input())):\n\tn = input()\n\tc1 = 0\n\tc0 = 0\n\tfor i in range(len(n)):\n\t\tif n[i] == '1':\n\t\t\tc1 += 1\n\t\telse:\n\t\t\tc0 += 1\n\tif c1 >= c0:\n\t\tprint('WIN')\n\telse:\n\t\tprint('LOSE')\n", "for i in range(int(input())):\n\tr = input()\n\tif r.count('1') >= r.count('0'):\n\t\tprint('WIN'...
{"inputs": ["2\n0101111111111\n11100000000000\n"], "outputs": ["WIN\nLOSE"]}
EASY
['Algorithms', 'Constructive', 'ad-hoc', 'String', 'Data Structures']
null
codechef
['String algorithms', 'Constructive algorithms', 'Data structures', 'Ad-hoc']
['Data structures']
https://www.codechef.com/problems/TTENIS
null
1 seconds
2015-06-08
0
50000 bytes
null
Frustrated by his legendary inability to tear down Lund’s Cathedral, Finn the Giant wants to become better at destroying pillar-borne edifices. Together with his fellow trolls he has constructed a training site consisting of a colonnade of various pillars supporting a roof. The pillars differ in structural strength—som...
[]
{"inputs": ["5\n1341 2412 1200 3112 2391\n", "5\n1004 1003 1002 1001 1000\n"], "outputs": ["3 1\n", "5 0\n"]}
HARD
[]
null
kattis
[]
[]
https://open.kattis.com/problems/jattenfinn
null
null
null
null
null
null
ARE U A MATHEMATICAL PRODIGY OR A BIG INT USER OR THE HOLY DYNAMIC PROGRAMMER ? Given two natural numbers , X and Y. Find the largest prime number less than or equal to K which is a subsequence of both A and B. Subsequence of two numbers A and B is defined same as that of two strings if digits were to be treated as c...
[]
{"inputs": [], "outputs": []}
UNKNOWN_DIFFICULTY
[]
frustrated
hackerearth
[]
[]
null
null
null
null
null
null
null
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candidate would get a_{i} votes. Limak is candidate number 1. To win in elections,...
["n = int(input())\nv = list(map(int, input().split()))\nc = v[0]\nv[0] = -1\nv = sorted(v)\nv = v[::-1]\nb = 0\nwhile c <= v[0]:\n\tx = v[0]\n\tfor i in range(n):\n\t\tif c <= v[i] and v[i] == x:\n\t\t\tc += 1\n\t\t\tv[i] -= 1\n\t\t\tb += 1\nprint(b)\n", "n = int(input())\n(a, *bs) = list(map(int, input().split()))\nb...
{"inputs": ["5\n5 1 11 2 8\n", "4\n1 8 8 8\n", "2\n7 6\n", "2\n1 1\n", "10\n100 200 57 99 1 1000 200 200 200 500\n", "16\n7 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "100\n47 64 68 61 68 66 69 61 69 65 69 63 62 60 68 65 64 65 65 62 63 68 60 70 63 63 65 67 70 69 68 69 61 65 63 60 60 ...
EASY
['greedy', 'implementation']
null
codeforces
['Implementation', 'Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/574/A
null
null
2019-12-31
null
null
null
My good friend Guruji once submitting his code on forum mistakenly forgot to check language option. His code got pasted in general editor. Due to this many portion of his code got changed. One funny thing which happened was that sub-string "<3" got changed into a heart. Your job is simple, count the number of "<3"(quot...
[]
{"inputs": ["<3<3<3<3<3<3", "12345678910111213151617181920<3><3><3<3>>><3>>>>><3>>>><3><kjhskj", "<3><3><3><3><3>,", "@#$%677983457935fkshfkmcbm!@#$%^&*", ">3>3>3>3<3"], "outputs": ["1", "7", "0", "5", "6"]}
UNKNOWN_DIFFICULTY
[]
guruji-and-hearts
hackerearth
[]
[]
null
null
null
null
null
null
null
Given a set of elements (integers or string characters) that may occur more than once, we need to know the amount of subsets that none of their values have repetitions. Let's see with an example: ``` set numbers = {1, 2, 3, 4} ``` The subsets are: ``` {{1}, {2}, {3}, {4}, {1,2}, {1,3}, {1,4}, {2,3}, {2,4},{3,4}, {1,...
["def est_subsets(arr):\n\treturn 2 ** len(set(arr)) - 1\n", "est_subsets = lambda a: 2 ** len(set(a)) - 1\n", "est_subsets = lambda n: 2 ** len(set(n)) - 1\n", "from math import factorial\nfrom collections import Counter\n\ndef C(n, r):\n\treturn factorial(n) // factorial(r) // factorial(n - r)\n\ndef est_subsets(arr)...
def est_subsets(arr):
{"fn_name": "est_subsets", "inputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d", "d"]]], "outputs": [[15], [15]]}
EASY
['Mathematics', 'Algorithms', 'Fundamentals', 'Strings', 'Logic', 'Data Structures']
null
codewars
['String algorithms', 'Fundamentals', 'Data structures', 'Mathematics']
['Data structures']
https://www.codewars.com/kata/584703d76f6cf6ffc6000275
null
null
null
null
null
null
An integer partition of n is a weakly decreasing list of positive integers which sum to n. For example, there are 7 integer partitions of 5: [5], [4,1], [3,2], [3,1,1], [2,2,1], [2,1,1,1], [1,1,1,1,1]. Write a function named partitions which returns the number of integer partitions of n. The function should be able...
["def partitions(n):\n\tc = [[1]]\n\tfor x in range(1, n + 1):\n\t\tc.append([0])\n\t\tfor m in range(1, x + 1):\n\t\t\tc[x].append(c[x][m - 1] + c[x - m][min(m, x - m)])\n\treturn c[n][n]\n", "def partitions(n, k=1, cache={}):\n\tif k > n:\n\t\treturn 0\n\tif n == k:\n\t\treturn 1\n\tif (n, k) in cache:\n\t\treturn ca...
def partitions(n):
{"fn_name": "partitions", "inputs": [], "outputs": []}
MEDIUM
['Mathematics', 'Algorithms', 'Discrete Mathematics']
null
codewars
['Mathematics']
[]
https://www.codewars.com/kata/546d5028ddbcbd4b8d001254
null
null
null
null
null
null
At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others. Write a function generateNumber() that takes two arguments, an array of the current squad numbers (squad) and the new player's des...
["def generate_number(squad, n):\n\tif n not in squad:\n\t\treturn n\n\tfor i in range(1, 10):\n\t\tfor j in range(1, 10):\n\t\t\tif i + j == n and i * 10 + j not in squad:\n\t\t\t\treturn i * 10 + j\n", "def generate_number(lst, n):\n\tlst = set(lst)\n\treturn n if n not in lst else next((9 * d + n for d in range(1, 1...
def generate_number(squad, n):
{"fn_name": "generate_number", "inputs": [[[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 38, 47, 56, 65, 69, 74, 83, 92], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 18, 23, 69], 18], [[1, 2, 3, 4, 6, 9, 10, 15, ...
EASY
['Algorithms']
null
codewars
[]
[]
https://www.codewars.com/kata/5d62961d18198b000e2f22b3
null
null
null
null
null
null
There are $ n $ acitivities with start times $ \\ {s_i \\} $ and finish times $ \\ {t_i \\} $. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be performed by a single person. Constraints * $ 1 \ le n \ le 10 ^ 5 $ * $ 1 \ le s_i \ lt t_i \ le 10 ^ 9...
["n = int(input())\nA = [[int(i) for i in input().split()] for _ in range(n)]\nA.sort(key=lambda x: x[1])\nt = 0\nans = 0\nfor i in A:\n\tif t < i[0]:\n\t\tans += 1\n\t\tt = i[1]\nprint(ans)\n", "num_activities = int(input())\nactivities = [[0, 0] for _ in range(num_activities)]\nfor i in range(num_activities):\n\tacti...
{"inputs": ["5\n2 2\n3 9\n3 5\n5 9\n6 8", "3\n1 1\n2 3\n3 4", "3\n0 5\n3 4\n2 5", "5\n3 2\n5 5\n4 3\n0 3\n6 8", "5\n2 2\n3 9\n4 5\n5 9\n6 8", "3\n1 1\n2 4\n3 4", "3\n-1 5\n3 4\n2 5", "5\n2 2\n3 9\n4 5\n1 9\n6 8", "3\n1 1\n2 4\n3 3", "3\n-1 5\n3 4\n2 7", "5\n2 2\n3 9\n4 4\n1 9\n6 8", "3\n2 1\n2 4\n3 3", "3\n-1 5\n1 4\n2...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
1.0 seconds
null
null
268.435456 megabytes
null
# Number encrypting: cypher ## Part I of Number encrypting Katas *** ## Introduction Back then when the internet was coming up, most search functionalities simply looked for keywords in text to show relevant documents. Hackers weren't very keen on having their information displayed on websites, bulletin boards, newsgr...
["def cypher(s):\n\treturn s.translate(str.maketrans('IREASGTBlzeasbtgoO', '123456781234567900'))\n", "translation = str.maketrans('IREASGTBOlzeasbtgo', '123456780123456790')\n\ndef cypher(s):\n\treturn s.translate(translation)\n", "def cypher(string):\n\tD = {'I': '1', 'l': '1', 'R': '2', 'z': '2', 'E': '3', 'e': '3',...
def cypher(string):
{"fn_name": "cypher", "inputs": [["Hello World"], ["I am your father"], ["I do not know what else I can test. Be cool. Good luck"], ["IlRzEeAaSsGbTtBgOo"], [""]], "outputs": [["H3110 W0r1d"], ["1 4m y0ur f47h3r"], ["1 d0 n07 kn0w wh47 3153 1 c4n 7357. 83 c001. 600d 1uck"], ["112233445566778900"], [""]]}
EASY
['Cryptography', 'Fundamentals', 'Ciphers']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/57aa3927e298a757820000a8
null
null
null
null
null
null
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef went to Australia and saw the destruction caused by bushfires, which made him sad, so he decided to help the animals by feeding them fruits. First, he went to purchase fruits from Pintu. Pintu sells $M$ differ...
["for i in range(int(input())):\n\t(n, m) = map(int, input().split())\n\tf = list(map(int, input().split()))\n\tp = list(map(int, input().split()))\n\td = {}\n\tfor i in range(n):\n\t\tif f[i] not in d:\n\t\t\td[f[i]] = p[i]\n\t\telse:\n\t\t\td[f[i]] = d[f[i]] + p[i]\n\tm = 100000\n\tfor i in d.values():\n\t\tif i < m:...
{"inputs": ["1\n6 4\n1 2 3 3 2 2\n7 3 9 1 1 1"], "outputs": ["5"]}
EASY
['Algorithms', '1D Arrays', 'Brute Force', 'Implementation', 'Data Structures', 'Arrays']
null
codechef
['Data structures', 'Implementation', 'Complete search']
['Data structures', 'Complete search']
https://www.codechef.com/problems/CHPINTU
null
1 seconds
2020-01-28
0
50000 bytes
null
Ante bought a piece of land. The land contains N apple trees, but his piece is triangular and it is not easy for him to determine which apple trees belong to him. Your program will be given the coordinates of the vertices of the triangle forming Ante’s piece, and the coordinates of all apple trees. Determine the area ...
[]
{"inputs": ["1 1\n5 1\n3 3\n4\n3 1\n3 2\n3 3\n3 4\n", "3 2\n5 4\n1 6\n3\n2 4\n3 5\n4 3\n", "2 6\n5 1\n7 8\n5\n1 4\n3 5\n6 4\n6 5\n4 7\n"], "outputs": ["4.0\n3\n", "6.0\n3\n", "15.5\n2\n"]}
EASY
['cg', 'geometry', 'math']
null
kattis
['Geometry', 'Mathematics']
[]
https://open.kattis.com/problems/jabuke
null
null
null
null
null
null
A point (x,y), on the cartesian plane, makes an angle theta with the positive direction of the x-axis. Theta varies in the interval [0 ,2PI) radians, i.e, greater than or equal to zero; but less than 2*PI radians. For example, the polar angle of the point (1,2) as marked in this plane below, is (approximately) 63.4...
["import math\nN = int(input())\npoints = []\nfor _ in range(N):\n\t(x, y) = list(map(int, input().split()))\n\tmag = math.sqrt(x ** 2 + y ** 2)\n\tdeg = math.degrees(math.atan2(y, x))\n\tif deg < 0:\n\t\tdeg = 360 + deg\n\tpoints.append((deg, mag, x, y))\npoints.sort()\nfor (d, m, x, y) in points:\n\tprint(x, y)\n", "...
{"inputs": ["4 \n1 0 \n0 -1 \n-1 0 \n0 1 \n"], "outputs": ["1 0 \n0 1 \n-1 0 \n0 -1 \n"]}
MEDIUM
['Mathematics - Geometry']
null
hackerrank
['Geometry']
[]
https://www.hackerrank.com/challenges/polar-angles/problem
null
null
null
1
null
null
In the race for the best Internet browser, there's now a new contender for it, this browser is called the: "The Semantic Mind-Reader!" After its promo on the world wide web, everyone's been desperately waiting for the browser to be released. And why shouldn't they be curious about it, after all, it's the new project of...
["T=int(input())\nfor t in range (0,T):\n\ts=input()\n\td=len(s)\n\ts=s.replace('www.','')\n\ts=s.replace('a','')\n\ts=s.replace('e','')\n\ts=s.replace('i','')\n\ts=s.replace('o','')\n\ts=s.replace('u','')\n\tn=len(s)+1\n\tprint(str(n)+'/'+str(d))\n\t\n\t\t \n\t\t \n", "tc = int(input())\nwhile (tc>0):\n\ttc = tc - 1...
{"inputs": ["100\nwww.bqatsakanwchyafzumouxstljudxcmkfp.com\nwww.acqalycgclyvijyynujauhrpvyzckohsiknywsywgdqzvjcufezioqugvrcclloyqbeeqhgffrbdgcba.com\nwww.ahrpdvjjkkgqnoutzcoowmxirstbvzqrxzztpzliakkskdhlbvgwjvglfkxoqzybnc.com\nwww.lynnropfyecopfbdibcvmrmyhdeeixyk.com\nwww.sddulnvmqbsckvanurmdnqbhsolwqwnvkunfydfqfznyxyy...
EASY
['VeryEasy', 'BasicProgramming']
the-best-internet-browser-3
hackerearth
['Fundamentals']
[]
null
null
null
null
null
null
null
This kata is all about adding numbers. You will create a function named add. This function will return the sum of all the arguments. Sounds easy, doesn't it?? Well here's the twist. The inputs will gradually increase with their index as parameter to the function. ```python add(3,4,5) #returns (3*1)+(4*2)+(5*3)=26 ...
["def add(*args):\n\treturn sum(((i + 1) * v for (i, v) in enumerate(args)))\n", "def add(*args):\n\treturn sum((n * i for (i, n) in enumerate(args, 1)))\n", "def add(*args):\n\treturn sum((i * x for (i, x) in enumerate(args, 1)))\n", "def add(*args):\n\treturn sum((pos * value for (pos, value) in enumerate(args, 1)))\...
def add(*args):
{"fn_name": "add", "inputs": [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]], "outputs": [[1400], [2], [-8], [-30]]}
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/555b73a81a6285b6ce000047
null
null
null
null
null
null
You are given an unweighted, undirected graph. Write a program to check if it's a tree topology. Input The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N ≤ 10000, 0 ≤ M ≤ 20000). Next M lines contain M edges of that graph --- Each line contains ...
[]
{"inputs": ["3 2\n1 3\n2 3", "3 2\n1 2\n1 3", "3 2\n2 3\n1 3", "3 2\n1 2\n3 1", "3 2\n1 2\n3 2", "1 0\n1 3\n1 3", "1 0\n1 3\n2 3", "1 0\n1 6\n2 3", "3 2\n1 3\n3 2", "1 0\n1 6\n1 3", "3 2\n1 3\n2 1", "1 0\n1 3\n1 4", "1 0\n1 3\n2 2", "1 0\n1 6\n3 3", "1 0\n1 6\n1 6", "1 0\n1 0\n1 4", "1 0\n1 3\n2 1", "1 0\n2 6\n3 3", "1...
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/PD31
null
null
null
null
null
null
Alice is a big fan of volleyball and especially of the very strong "Team A". Volleyball match consists of up to five sets. During each set teams score one point for winning a ball. The first four sets are played until one of the teams scores at least 25 points and the fifth set is played until one of the teams scores ...
[]
{"inputs": ["1\n75 94\n", "1\n75 20\n", "1\n76 24\n", "1\n75 70\n", "6\n75 0\n90 90\n20 0\n0 75\n78 50\n80 100\n", "1\n76 0\n", "1\n74 94\n", "1\n75 69\n", "1\n76 23\n", "1\n81 94\n", "1\n125 20\n", "1\n75 44\n", "6\n75 -1\n90 90\n20 0\n0 75\n78 50\n80 100\n", "1\n90 94\n", "1\n75 11\n", "6\n75 1\n90 90\n20 0\n0 75\n78...
HARD
['dp']
null
codeforces
['Dynamic programming']
['Dynamic programming']
https://codeforces.com/problemset/problem/1089/A
null
1.5 seconds
null
null
512.0 megabytes
null
Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegme...
["import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy\nfrom itertools import chain, dropwhile, permutations, combinations\nfrom collections import defaultdict, deque\n\ndef VI():\n\treturn list(map(int, input().split()))\n\ndef I():\n\treturn int(input())\n\ndef LIST(n, m=None):\n\tre...
{"inputs": ["5\n1 1 2 2 1\n", "5\n1 2 2 3 1\n", "6\n1 2 2 1 1 2\n", "10\n1 1000000 2 1000000 3 2 1000000 1 2 1\n", "10\n1 2 3 4 5 5 1 2 3 4\n", "10\n1 1 2 1 1 2 2 1 2 3\n", "10\n5 4 3 2 1 1 2 3 4 5\n", "10\n1 10 100 1000 10000 1 10 100 1000 10000\n", "10\n9 9 9 9 8 9 8 8 8 8\n", "10\n1 11 111 1111 1 11 11 1 1111 1111\n...
EASY
['implementation']
null
codeforces
['Implementation']
[]
https://codeforces.com/problemset/problem/558/B
null
null
2019-12-31
null
null
null
The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan...
["(n, m) = (int(x) for x in input().split())\ns = input()\nf = dict(zip('abcdefghijklmnopqrstuvxwyz', 'abcdefghijklmnopqrstuvxwyz'))\nt = dict(zip('abcdefghijklmnopqrstuvxwyz', 'abcdefghijklmnopqrstuvxwyz'))\nfor i in range(m):\n\t(a, b) = input().split()\n\tA = t[a]\n\tB = t[b]\n\tf[A] = b\n\tf[B] = a\n\tt[a] = B\n\tt...
{"inputs": ["6 1\npolice\np m\n", "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n", "1 1\nf\nz h\n", "1 1\na\na b\n", "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e\n", "10 10\nlellelleel\ne l\ne l\ne l\ne l\ne l\ne e\nl l\nl e\nl l\ne e\n", "1 1\na\na b\n", "1 1\nf\nz h\n", "10 10\nlellelleel\...
EASY
['strings', 'implementation']
null
codeforces
['String algorithms', 'Implementation']
[]
https://codeforces.com/problemset/problem/591/B
null
null
2019-12-31
null
null
null
Chef has opened a new airline. Chef has 10 airplanes where each airplane has a capacity of X passengers. On the first day itself, Y people are willing to book a seat in any one of Chef's airplanes. Given that Chef charges Z rupees for each ticket, find the maximum amount he can earn on the first day. ------ Input ...
["t = int(input())\nfor i in range(t):\n\t(x, y, z) = map(int, input().split())\n\tif x * 10 > y:\n\t\tprint(y * z)\n\telse:\n\t\tprint(x * 10 * z)\n", "t = int(input())\nfor i in range(t):\n\t(x, y, z) = map(int, input().split())\n\ttotal_seats = x * 10\n\tif total_seats >= y:\n\t\tprint(y * z)\n\telif total_seats <= ...
{"inputs": ["4\n2 15 10\n1 10 1\n5 60 100\n1 11 7\n"], "outputs": ["150\n10\n5000\n70\n"]}
EASY
['Mathematics', 'Basic Maths']
null
codechef
['Mathematics']
[]
https://www.codechef.com/problems/AIRLINES
null
1 seconds
2023-02-13
0
50000 bytes
null
You are teaching discrete math. You have done your best to teach your students about axioms and inference rules, proofs and theorems. Sometimes the students write beautiful proofs that Fermat would be proud of but sometimes, also like Fermat, their proofs are not quite right. You are getting a little tired of hunting t...
[]
{"inputs": ["3\n-> ALICE\n-> BOB\nALICE BOB -> CARL\n", "1\nA -> B\n"], "outputs": ["correct\n", "1\n"]}
EASY
[]
null
kattis
[]
[]
https://open.kattis.com/problems/proofs
null
null
null
null
null
null
Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct. Having packed all the presents, Santa realized ...
[]
{"inputs": ["1 1\n0\n", "1 1\n1 1\n", "4 11\n10 1 11 4 6 9 2 3 10 5 8\n0\n1 3\n9 6 5 2 9 10 4 1 7 8\n", "2 1\n0\n1 1\n", "4 50\n9 26 13 12 16 39 37 42 11 18\n42 4 39 19 29 44 30 5 43 28 38 22 2 33 9 50 13 25 37 45 32 27 1 48 35 11 36 42 26 49 40 8 34 7 12 23 31 10 6 18 46 41 17\n28 22 30 48 7 23 42 37 47 41 50 14 33 13...
VERY_HARD
['data structures', 'constructive algorithms']
null
codeforces
['Data structures', 'Constructive algorithms']
['Data structures']
https://codeforces.com/problemset/problem/1090/C
null
2.0 seconds
null
null
512.0 megabytes
null
Given an integer number n, return the difference between the product of its digits and the sum of its digits.   Example 1: Input: n = 234 Output: 15 Explanation: Product of digits = 2 * 3 * 4 = 24 Sum of digits = 2 + 3 + 4 = 9 Result = 24 - 9 = 15 Example 2: Input: n = 4421 Output: 21 Explanation: Product of digi...
["class Solution:\n\n\tdef subtractProductAndSum(self, n: int) -> int:\n\t\tstringInt = str(n)\n\t\tproduct = 1\n\t\tsum = 0\n\t\tfor i in stringInt:\n\t\t\tproduct *= int(i)\n\t\t\tsum += int(i)\n\t\treturn product - sum\n", "class Solution:\n\n\tdef subtractProductAndSum(self, n: int) -> int:\n\t\tdigits = str(n)\n\t...
class Solution: def subtractProductAndSum(self, n: int) -> int:
{"fn_name": "subtractProductAndSum", "inputs": [[234]], "outputs": [15]}
EASY
['Math']
null
leetcode
['Mathematics']
[]
https://leetcode.com/problems/subtract-the-product-and-sum-of-digits-of-an-integer/
null
null
null
null
null
null
Bob Bubblestrong just got a new job as security guard. Bob is now responsible for safety of a collection of warehouses, each containing the most valuable Bubble Cup assets - the high-quality bubbles. His task is to detect thieves inside the warehouses and call the police. Looking from the sky, each warehouse has a sha...
[]
{"inputs": ["6\n4 0 8 0 10 6 0 4 0\n4 10 0 0 -8 0 -6 8 0\n4 0 -2 0 -4 -7 0 -5 0\n4 -4 0 0 7 0 5 -2 0\n4 12 2 15 2 15 -3 12 -3\n4 0 -10 2 -12 0 -14 -2 -12\n", "7\n4 3 -3 2 1 3 3 4 1\n4 6 0 5 1 6 4 7 1\n4 11 2 11 -1 8 -1 8 2\n4 8 -5 5 -8 2 -5 5 -2\n6 -2 3 -2 2 -3 1 -4 1 -4 2 -3 3\n4 -4 4 -5 3 -7 3 -6 4\n4 -7 6 -5 6 -6 5 ...
VERY_HARD
['data structures', 'geometry']
null
codeforces
['Geometry', 'Data structures']
['Data structures']
https://codeforces.com/problemset/problem/1218/B
null
1.0 seconds
null
null
256.0 megabytes
null
G - Revenge of Minimum Cost Flow Problem Statement Flora is a freelance carrier pigeon. Since she is an excellent pigeon, there are too much task requests to her. It is impossible to do all tasks, so she decided to outsource some tasks to Industrial Carrier Pigeon Company. There are N cities numbered from 0 to N-1. ...
[]
{"inputs": ["3 2 0 1 5\n0 1 3 0 3\n0 1 2 1 6", "3 2 0 1 3\n0 1 3 0 3\n0 1 2 1 6", "2 2 0 1 2\n0 1 3 0 3\n0 1 2 1 6", "3 2 0 1 3\n0 1 3 0 3\n0 1 1 1 6", "3 3 0 1 5\n0 0 3 0 3\n0 1 2 1 6", "3 3 1 1 5\n0 0 3 0 3\n0 1 2 1 6", "2 2 0 1 4\n0 1 3 0 3\n0 1 2 1 6", "3 3 0 1 5\n0 0 3 0 3\n0 1 4 1 6", "3 2 0 2 3\n0 1 3 1 3\n0 1 2...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
2.0 seconds
null
null
268.435456 megabytes
null
When users post an update on social media,such as a URL, image, status update etc., other users in their network are able to view this new post on their news feed. Users can also see exactly when the post was published, i.e, how many hours, minutes or seconds ago. Since sometimes posts are published and viewed in dif...
["from datetime import datetime, timedelta\ns = '%a %d %b %Y %H:%M:%S %z'\nt = int(input())\nfor _ in range(t):\n\ta = datetime.strptime(input(), s)\n\tb = datetime.strptime(input(), s)\n\tprint(int(abs(timedelta.total_seconds(b - a))))\n", "import datetime\nfor t in range(0, int(input())):\n\td1 = datetime.datetime.st...
{"inputs": ["2\nSun 10 May 2015 13:54:36 -0700\nSun 10 May 2015 13:54:36 -0000\nSat 02 May 2015 19:54:36 +0530\nFri 01 May 2015 13:54:36 -0000\n"], "outputs": ["25200\n88200\n"]}
MEDIUM
['Python - Date and Time']
null
hackerrank
[]
[]
https://www.hackerrank.com/challenges/python-time-delta/problem
null
null
null
0
null
null
See Russian Translation I often buy Coca-Cola from the vending machine at work. Usually, I buy several cokes at once, since my working mates also like coke. A coke in the vending machine costs 8 Rupees, and the machine accepts coins with the values 1, 5 and 10 Rupees only. As soon as I press the coke button (After h...
[]
{"inputs": ["10\n67 146 76 8\n56 138 18 45\n79 197 0 47\n69 97 33 45\n87 206 45 40\n40 292 5 5\n30 288 8 13\n31 226 24 8\n89 359 63 43\n116 477 94 15\n", "10\n1 1 1 2\n1 9 3 7\n3 9 2 4\n1 5 2 3\n6 3 4 0\n1 6 2 6\n10 8 3 1\n4 9 4 6\n10 8 5 3\n5 1 4 5\n", "10\n1 3 2 8\n5 7 6 7\n1 2 7 2\n7 3 9 0\n5 4 8 5\n1 2 4 1\n7 7 3 4...
MEDIUM
['Recursion', 'Math', 'DynamicProgramming']
buy-me-some-coke
hackerearth
['Dynamic programming', 'Mathematics', 'Complete search']
['Dynamic programming', 'Complete search']
null
null
null
null
null
null
null
Write a program which reads two integers a, b and an operator op, and then prints the value of a op b. The operator op is '+', '-', '*' or '/' (sum, difference, product or quotient). The division should truncate any fractional part. Constraints * 0 ≤ a, b ≤ 20000 * No divisions by zero are given. Input The input c...
["while 1:\n\t(a, op, b) = input().split()\n\t(a, b) = (int(a), int(b))\n\tif op == '+':\n\t\tprint(a + b)\n\tif op == '-':\n\t\tprint(a - b)\n\tif op == '*':\n\t\tprint(a * b)\n\tif op == '/':\n\t\tprint(int(a / b))\n\tif op == '?':\n\t\tbreak\n", "while True:\n\t(a, op, b) = input().split()\n\tif op == '?':\n\t\tbrea...
{"inputs": ["1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n-1 ? 0", "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 , 81\n-1 ? 0", "1 + 2\n56 - 18\n21 * 2\n100 / 10\n27 , 81\n-1 ? 0", "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 136\n-1 ? 0", "1 + 2\n56 - 18\n21 * 2\n100 / 10\n9 , 81\n-1 ? 0", "2 + 2\n56 - 18\n13 * 2\n100 / 10\n27 , 81\...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
null
1.0 seconds
null
null
134.217728 megabytes
null
The last worker in a production line at the factory of Automated Composed Machinery is worried. She knows that her job hangs in the balance unless her productivity increases. Her work consists of assembling a set of pieces in a given sequence, but the time spent on assembling pieces $a$ and $b$ and then $c$ may not the...
[]
{"inputs": ["2\na b\n3-b 5-b\n6-a 2-b\n2\naba\nbba\n0\n", "2\nm e\n5-e 4-m\n3-e 4-m\n1\neme\n0\n"], "outputs": ["9-b\n8-a\n", "7-m\n"]}
HARD
[]
null
kattis
[]
[]
https://open.kattis.com/problems/assemblyline
null
null
null
null
null
null
Given two strings s1 and s2. The task is to check if s2 is a rotated version of the string s1. The characters in the strings are in lowercase. Example 1: Input: geeksforgeeks forgeeksgeeks Output: 1 Explanation: s1 is geeksforgeeks, s2 is forgeeksgeeks. Clearly, s2 is a rotated version of s1 as s2 can be obtained by...
["class Solution:\n\n\tdef areRotations(self, s1, s2):\n\t\treturn s2 in s1 + s1 if len(s1) == len(s2) else 0\n", "class Solution:\n\n\tdef areRotations(self, s1, s2):\n\t\tif len(s1) != len(s2):\n\t\t\treturn 0\n\t\ttemp = s1 + s1\n\t\tif temp.count(s2) > 0:\n\t\t\treturn 1\n\t\telse:\n\t\t\treturn 0\n", "class Soluti...
#User function Template for python3 class Solution: #Function to check if two strings are rotations of each other or not. def areRotations(self,s1,s2): #code here
{"inputs": ["geeksforgeeks\nforgeeksgeeks", "mightandmagic\nandmagicmigth"], "outputs": ["1", "0"]}
EASY
['Data Structures', 'Strings']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/check-if-strings-are-rotations-of-each-other-or-not-1587115620/1
O(N).
null
null
0
null
O(N).
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem. Now, they have an array $a$ of $n$ positive integers, Hossam will choose a number $a_i$ and Hazem will choose a number $a_j$. Count the number of interesting pairs $(a_i, a_j)$ that meet all the following conditions: $1 \le i, ...
["from math import comb as cx\nfor _ in range(int(input())):\n\tn = int(input())\n\tl = list(map(int, input().split()))\n\tif len(set(l)) == 1:\n\t\tprint(len(l) * (len(l) - 1))\n\telse:\n\t\tz = l.count(max(l))\n\t\tc = l.count(min(l))\n\t\tprint(c * z * 2)\n", "t = int(input())\n\ndef solve(n, arr):\n\t(maxval, minva...
{"inputs": ["2\n5\n6 2 3 8 1\n6\n7 2 8 3 2 10\n", "2\n5\n1 1 1 1 1\n6\n7 2 8 3 2 10\n", "2\n3\n1 1 1\n2\n1 2\n"], "outputs": ["2\n4\n", "20\n4\n", "6\n2\n"]}
EASY
['combinatorics', 'sortings', 'math']
null
codeforces
['Sorting', 'Combinatorics', 'Mathematics']
['Sorting']
https://codeforces.com/problemset/problem/1771/A
null
2 seconds
2022-12-11
0
256 megabytes
null
Alice has N boxes, and each box has certain non zero number of chocolates. These boxes are numbered from 1 to N. Alice is planning to go to wonderland. She wants to carry exactly K number of chocolates and she can carry only 2 boxes. So she wants to know the number of ways in which she can select 2 boxes such that t...
["# Read input from stdin and provide input before running code\nimport re;\nn=int(input());\nfor i in range(n):\n\ttmp=int(input());\n\tmatch={};\n\tcount=0;\n\tarray=(re.split('\\\\s',input()))\t\t\n\tk=int(input());\n\tfor a in array:\n\t\t#print \"--------------------------------------------------------------------...
{"inputs": [], "outputs": []}
MEDIUM
['Algorithms']
chocolates-boxes-1
hackerearth
[]
[]
null
null
null
null
null
null
null
In this Kata, you will be given a number in form of a string and an integer `k` and your task is to insert `k` commas into the string and determine which of the partitions is the largest. ``` For example: solve('1234',1) = 234 because ('1','234') or ('12','34') or ('123','4'). solve('1234',2) = 34 because ('1','2','3...
["def solve(st, k):\n\tlength = len(st) - k\n\treturn max((int(st[i:i + length]) for i in range(k + 1)))\n", "def solve(st, k):\n\tn = len(st) - k\n\treturn max((int(st[i:i + n]) for i in range(len(st))))\n", "def solve(st, k):\n\ta = len(st) - k\n\tq = [st[i:i + a] for i in range(0, len(st))]\n\tr = [int(item) for ite...
def solve(st,k):
{"fn_name": "solve", "inputs": [["1234", 1], ["1234", 2], ["1234", 3], ["2020", 1]], "outputs": [[234], [34], [4], [202]]}
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/5b83c1c44a6acac33400009a
null
null
null
null
null
null
Emma is fond of prime numbers. Emma’s teacher gave her an interesting problem to solve. The problem is as follows: The teacher gave Emma 2 positive integers x and y(x ≤ y). She asked Emma to find the sum of all the prime numbers between x and y(x and y inclusive). The teacher gave Emma a few such pairs to calculate t...
["__author__ = 'Admin'\nnq = int(input())\narr = []\nfor i in range(0 , 1000002):\n\tarr.append(0)\n\narr[1] = 1\n\nfor i in range(2 , 1000002):\n\tif i*i <=1000001:\n\t\tif arr[i] == 0:\n\t\t\tk = 2\n\t\t\tj = i*k\n\t\t\twhile(j <= 1000001):\n\t\t\t\tarr[j] = 1\n\t\t\t\tk = k + 1\n\t\t\t\tj = i*k\n\nans = 0\nfor i in ...
{"inputs": ["1000\n870 978\n946 984\n767 801\n456 840\n112 402\n665 818\n610 676\n773 942\n177 295\n28 206\n82 471\n728 773\n156 269\n33 391\n461 481\n394 647\n263 399\n266 666\n104 160\n877 993\n450 476\n327 868\n485 999\n202 492\n709 854\n957 986\n959 986\n283 812\n870 915\n868 940\n411 960\n211 467\n709 743\n470 503...
EASY
[]
emma-and-the-prime-sum
hackerearth
[]
[]
null
null
null
null
null
null
null
Given a string s, remove all its adjacent duplicate characters recursively. Note: For some test cases, the resultant string would be an empty string. In that case, the function should return the empty string only. Example 1: Input: S = "geeksforgeek" Output: "gksforgk" Explanation: g(ee)ksforg(ee)k -> gksforgk Exampl...
["class Solution:\n\n\tdef rremove(self, S):\n\n\t\tdef rec(S):\n\t\t\tans = ''\n\t\t\tn = len(S)\n\t\t\ti = 0\n\t\t\twhile i < n:\n\t\t\t\tif i < n - 1 and S[i] == S[i + 1]:\n\t\t\t\t\twhile i < n - 1 and S[i] == S[i + 1]:\n\t\t\t\t\t\ti += 1\n\t\t\t\telse:\n\t\t\t\t\tans += S[i]\n\t\t\t\ti += 1\n\t\t\treturn ans\n\t\...
#User function Template for python3 class Solution: def rremove (self, S): #code here
{"inputs": ["S = \"geeksforgeek\"", "S = \"abccbccba\""], "outputs": ["\"gksforgk\"", "\"\""]}
MEDIUM
['Recursion', 'Strings', 'Algorithms', 'Data Structures']
null
geeksforgeeks
['String algorithms', 'Data structures', 'Complete search']
['Data structures', 'Complete search']
https://practice.geeksforgeeks.org/problems/recursively-remove-all-adjacent-duplicates0744/1
O(|S|)
null
null
0
null
O(|S|)
Given a string s consisting only of letters 'a' and 'b'. In a single step you can remove one palindromic subsequence from s. Return the minimum number of steps to make the given string empty. A string is a subsequence of a given string, if it is generated by deleting some characters of a given string without changing i...
["class Solution:\n\n\tdef removePalindromeSub(self, s: str) -> int:\n\t\tif len(s) == 0:\n\t\t\treturn 0\n\t\tif s == s[::-1]:\n\t\t\treturn 1\n\t\treturn 2\n", "class Solution:\n\n\tdef removePalindromeSub(self, s: str) -> int:\n\t\tif s == '':\n\t\t\treturn 0\n\t\telif s == s[::-1]:\n\t\t\treturn 1\n\t\telse:\n\t\t\...
class Solution: def removePalindromeSub(self, s: str) -> int:
{"fn_name": "removePalindromeSub", "inputs": [["\"ababa\""]], "outputs": [1]}
EASY
['Two Pointers', 'String']
null
leetcode
['String algorithms', 'Amortized analysis']
['Amortized analysis']
https://leetcode.com/problems/remove-palindromic-subsequences/
null
null
null
null
null
null
A given series 3, 5, 9, 11, 15, 17, 21, 27, 29, ... and so on. You need to identify the pattern and determine whether the input number ( n ) is a part of the given series or not. If yes then return "Yes", otherwise "No". Example 1: Input: n = 9 Output: Yes Explanation: 9 is the part of the sequence. Example 2: Input: ...
["class Solution:\n\n\tdef isPart(self, n):\n\t\tn += 2\n\t\ti = 2\n\t\twhile i * i <= n:\n\t\t\tif n % i == 0:\n\t\t\t\treturn 'No'\n\t\t\ti += 1\n\t\treturn 'Yes'\n", "import math\n\nclass Solution:\n\n\tdef isPart(self, n):\n\t\tif n % 2 == 0:\n\t\t\treturn 'No'\n\t\telif n == 3 or n == 1:\n\t\t\treturn 'Yes'\n\t\te...
#User function Template for python3 class Solution: def isPart (self, n): #complete the function here
{"inputs": ["n = 9", "n = 8"], "outputs": ["Yes", "No"]}
MEDIUM
['logical-thinking', 'Algorithms', 'Mathematical', 'series']
null
geeksforgeeks
['Mathematics']
[]
https://practice.geeksforgeeks.org/problems/part-of-it1016/1
O(1)
null
null
0
null
O(sqrt(n))
Bob wants to take revenge from Peter. So he thinks of stealing apples form Peter's garden. But Peter is also clever. He has put sensors in garden in order to detect stealing. Still Bob has figured out a way such that he will not be caught. Peter's garden can be represented as a 2 dimensional matrix of size N x M where...
[]
{"inputs": ["10\n200 200\n#83702#43820#05053806##42036965818518451#61944#765814734569303#102374683#7131995166408851661953854298816217185680010873918080136354904435140608507384743220214847038450962722552188320642574726327962728\n##812021985089593#2#161238835994653653731#47975#65851972435913058203554656112606161226279738...
UNKNOWN_DIFFICULTY
[]
revenge-and-apples
hackerearth
[]
[]
null
null
null
null
null
null
null
This is the hard version of the problem. The difference between the versions is that the easy version has no swap operations. You can make hacks only if all versions of the problem are solved. Pikachu is a cute and friendly pokémon living in the wild pikachu herd. But it has become known recently that infamous team R...
["input = __import__('sys').stdin.readline\n\ndef check(*inds):\n\tglobal localmax, localmin, maxs, mins\n\tfor ind in inds:\n\t\tif not ok(ind):\n\t\t\tcontinue\n\t\tif localmax[ind] == 0 and s[ind - 1] < s[ind] > s[ind + 1]:\n\t\t\tlocalmax[ind] = 1\n\t\t\tmaxs += s[ind]\n\t\tif localmin[ind] == 0 and s[ind - 1] > s[...
{"inputs": ["3\n3 1\n1 3 2\n1 2\n2 2\n1 2\n1 2\n1 2\n7 5\n1 2 5 4 3 6 7\n1 2\n6 7\n3 4\n1 2\n2 3\n", "5\n2 0\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n3 9\n1 2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n3 0\n3 2 1\n", "5\n2 0\n1 2\n2 1\n1 2\n1 2\n2 1\n2 1\n1 2\n3 9\n1 2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n3 ...
HARD
['data structures', 'greedy', 'implementation', 'dp', 'divide and conquer']
null
codeforces
['Implementation', 'Greedy algorithms', 'Dynamic programming', 'Divide and conquer', 'Data structures']
['Dynamic programming', 'Data structures', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1420/C2
null
2 seconds
2020-09-24
0
256 megabytes
null
One day Mirko, while he was walking through the high grass, stumbled upon a sequence of $N$ colored marbles. Soon he noticed that if he touches $K$ or more consecutive marbles of the same color, they start to twinkle and then he could wish them to magically vanish, although he doesn’t have to do that immediately (see $...
[]
{"inputs": ["2 5\n1 1\n", "5 3\n2 2 3 2 2\n", "10 4\n3 3 3 3 2 3 1 1 1 3\n"], "outputs": ["3\n", "2\n", "4\n"]}
HARD
[]
null
kattis
[]
[]
https://open.kattis.com/problems/zuma
null
null
null
null
null
null