question
stringlengths
29
14k
solutions
listlengths
1
6.39k
starter_code
stringlengths
0
1.47k
input_output
stringlengths
29
74M
difficulty
stringclasses
6 values
raw_tags
stringlengths
2
281
name
stringlengths
3
105
source
stringclasses
10 values
tags
stringlengths
2
183
skill_types
stringclasses
127 values
url
stringlengths
36
138
time_limit
stringclasses
143 values
date
stringlengths
10
10
picture_num
stringclasses
8 values
memory_limit
stringclasses
28 values
Expected Time Complexity
stringclasses
710 values
task_id
int64
1
25.4k
solution_id
int64
0
0
solution
stringlengths
6
413k
text
stringlengths
123
413k
To celebrate the start of the Rio Olympics (and the return of 'the Last Leg' on C4 tonight) this is an Olympic inspired kata. Given a string of random letters, you need to examine each. Some letters naturally have 'rings' in them. 'O' is an obvious example, but 'b', 'p', 'e', 'A', etc are all just as applicable. 'B' e...
[ "def olympic_ring(string):\n\treturn (['Not even a medal!'] * 2 + ['Bronze!', 'Silver!', 'Gold!'])[min(4, sum(map('abdegopqABBDOPQR'.count, string)) // 2)]\n", "def olympic_ring(string):\n\trings = string.translate(str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '1201000000000011110000000011...
def olympic_ring(string):
{"fn_name": "olympic_ring", "inputs": [["wHjMudLwtoPGocnJ"], ["eCEHWEPwwnvzMicyaRjk"], ["JKniLfLW"], ["EWlZlDFsEIBufsalqof"], ["IMBAWejlGRTDWetPS"]], "outputs": [["Bronze!"], ["Bronze!"], ["Not even a medal!"], ["Silver!"], ["Gold!"]]}
EASY
['Strings', 'Fundamentals', 'Arrays']
null
codewars
['String algorithms', 'Fundamentals', 'Data structures']
['Data structures']
https://www.codewars.com/kata/57d06663eca260fe630001cc
null
null
null
null
null
25,201
0
def olympic_ring(string): return (['Not even a medal!'] * 2 + ['Bronze!', 'Silver!', 'Gold!'])[min(4, sum(map('abdegopqABBDOPQR'.count, string)) // 2)]
# Question To celebrate the start of the Rio Olympics (and the return of 'the Last Leg' on C4 tonight) this is an Olympic inspired kata. Given a string of random letters, you need to examine each. Some letters naturally have 'rings' in them. 'O' is an obvious example, but 'b', 'p', 'e', 'A', etc are all just as appli...
How many non-attacking knights K(n) can be placed on an n x n chessboard. Recall that a knight can attack another knight if their vertical distance on the chessboard is 2 and their horizontal distance is 1, or if their vertical distance is 1 and their horizontal distance is 2. Only one knight may be placed on each squ...
[ "import math\n\nclass Solution:\n\n\tdef saveKnights(self, n):\n\t\tif n == 2:\n\t\t\treturn 4\n\t\telif n % 2 == 0:\n\t\t\treturn int(math.pow(n, 2) / 2)\n\t\telse:\n\t\t\treturn int((math.pow(n, 2) + 1) / 2)\n", "import math\n\nclass Solution:\n\n\tdef saveKnights(self, n):\n\t\tif n == 2:\n\t\t\treturn 4\n\t\t...
#User function Template for python3 class Solution: def saveKnights(self, n): # code here
{"inputs": ["n = 3", "n = 1"], "outputs": ["5", "1"]}
EASY
['Algorithms', 'Mathematical']
null
geeksforgeeks
['Mathematics']
[]
https://practice.geeksforgeeks.org/problems/save-knights2718/1
null
null
0
null
O(1)
25,203
0
import math class Solution: def saveKnights(self, n): if n == 2: return 4 elif n % 2 == 0: return int(math.pow(n, 2) / 2) else: return int((math.pow(n, 2) + 1) / 2)
# Question How many non-attacking knights K(n) can be placed on an n x n chessboard. Recall that a knight can attack another knight if their vertical distance on the chessboard is 2 and their horizontal distance is 1, or if their vertical distance is 1 and their horizontal distance is 2. Only one knight may be placed...
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance...
[ "N = int(input(''))\nLine2 = input('')\nArray = list(map(int, Line2.split(' ')))\nmin_elem_index = Array.index(min(Array))\nmax_elem_index = Array.index(max(Array))\nmin_index = 0\nmax_index = N - 1\nL_inv1 = abs(min_elem_index - min_index)\nR_inv1 = abs(max_index - min_elem_index)\nans1 = 0\nif L_inv1 >= R_inv1:\n...
{"inputs": ["5\n4 5 1 3 2\n", "7\n1 6 5 3 4 7 2\n", "6\n6 5 4 3 2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 3 1\n", "4\n4 1 3 2\n", "5\n1 4 5 2 3\n", "6\n4 6 3 5 2 1\n", "7\n1 5 3 6 2 4 7\n", "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53...
EASY
['implementation', 'constructive algorithms']
null
codeforces
['Implementation', 'Constructive algorithms']
[]
https://codeforces.com/problemset/problem/676/A
null
2019-12-31
null
null
null
25,171
0
N = int(input('')) Line2 = input('') Array = list(map(int, Line2.split(' '))) min_elem_index = Array.index(min(Array)) max_elem_index = Array.index(max(Array)) min_index = 0 max_index = N - 1 L_inv1 = abs(min_elem_index - min_index) R_inv1 = abs(max_index - min_elem_index) ans1 = 0 if L_inv1 >= R_inv1: ans1 = L_inv1 e...
# Question Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize ...
# Context According to Wikipedia : "The seventh son of a seventh son is a concept from folklore regarding special powers given to, or held by, such a son. **The seventh son must come from an unbroken line with no female siblings born between, and be, in turn, born to such a seventh son.**" # Your task You will be gi...
[ "import json\n\ndef f(data, level):\n\tif level == 0:\n\t\tyield data['name']\n\t\treturn\n\tchildren = data['children']\n\tif len(children) >= 7 and all((child['gender'] == 'male' for child in children[:7])):\n\t\tyield from f(children[6], level - 1)\n\tfor child in children:\n\t\tyield from f(child, 2)\n\ndef fin...
def find_seventh_sons_of_seventh_sons(jstring):
{"fn_name": "find_seventh_sons_of_seventh_sons", "inputs": [], "outputs": []}
EASY
['Recursion', 'Fundamentals', 'JSON']
null
codewars
['Fundamentals', 'Complete search']
['Complete search']
https://www.codewars.com/kata/5a15b54bffe75f31990000e0
null
null
null
null
null
25,208
0
import json def f(data, level): if level == 0: yield data['name'] return children = data['children'] if len(children) >= 7 and all((child['gender'] == 'male' for child in children[:7])): yield from f(children[6], level - 1) for child in children: yield from f(child, 2) def find_seventh_sons_of_seventh_son...
# Question # Context According to Wikipedia : "The seventh son of a seventh son is a concept from folklore regarding special powers given to, or held by, such a son. **The seventh son must come from an unbroken line with no female siblings born between, and be, in turn, born to such a seventh son.**" # Your task Yo...
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
[ "a = [1, -1]\nb = [1, 1]\nX = [a, b]\ncur = 1\nk = int(input())\n\ndef pr(X):\n\tfor v in X:\n\t\tprint(''.join(['*' if x == -1 else '+' for x in v]))\n\ndef get_xor(v):\n\treturn [-1 * x for x in v]\n\ndef build(X):\n\tans = []\n\tn = len(X)\n\tfor i in range(0, n, 2):\n\t\tans.extend([X[i] + X[i + 1], X[i + 1] + ...
{"inputs": ["2\n", "1\n", "3\n", "0\n", "4\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n", "2\n"], "outputs": ["++++\n+*+*\n++**\n+**+\n", "++\n+*\n", "++++++++\n+*+*+*+*\n++**++**\n+**++**+\n++++****\n+*+**+*+\n++****++\n+**+*++*\n", "+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**+...
MEDIUM_HARD
['constructive algorithms']
null
codeforces
['Constructive algorithms']
[]
https://codeforces.com/problemset/problem/610/C
null
2019-12-31
null
null
null
25,206
0
a = [1, -1] b = [1, 1] X = [a, b] cur = 1 k = int(input()) def pr(X): for v in X: print(''.join(['*' if x == -1 else '+' for x in v])) def get_xor(v): return [-1 * x for x in v] def build(X): ans = [] n = len(X) for i in range(0, n, 2): ans.extend([X[i] + X[i + 1], X[i + 1] + X[i], get_xor(X[i]) + X[i + 1],...
# Question The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate ...
Often, when a list is sorted, the elements being sorted are just keys to other values. For example, if you are sorting files by their size, the sizes need to stay connected to their respective files. You cannot just take the size numbers and output them in order, you need to output all the required file information. T...
[ "n = int(input())\nar = [int(x) for x in input().strip().split(' ')]\nc = [0] * 100\nfor a in ar:\n\tc[a] += 1\ns = ''\nfor x in range(0, 100):\n\tfor i in range(0, c[x]):\n\t\ts += ' ' + str(x)\nprint(s[1:])\n", "import sys\nn = int(sys.stdin.readline())\nar = [int(x) for x in sys.stdin.readline().split()]\ncoun...
{"inputs": ["100\n63 25 73 1 98 73 56 84 86 57 16 83 8 25 81 56 9 53 98 67 99 12 83 89 80 91 39 86 76 85 74 39 25 90 59 10 94 32 44 3 89 30 27 79 46 96 27 32 18 21 92 69 81 40 40 34 68 78 24 87 42 69 23 41 78 22 6 90 99 89 50 30 20 1 43 3 70 95 33 46 44 9 69 48 33 60 65 16 82 67 61 32 21 79 75 75 13 87 70 33 \n"], "out...
EASY
['Algorithms - Sorting']
null
hackerrank
['Sorting']
['Sorting']
https://www.hackerrank.com/challenges/countingsort2/problem
null
null
0
null
null
25,200
0
n = int(input()) ar = [int(x) for x in input().strip().split(' ')] c = [0] * 100 for a in ar: c[a] += 1 s = '' for x in range(0, 100): for i in range(0, c[x]): s += ' ' + str(x) print(s[1:])
# Question Often, when a list is sorted, the elements being sorted are just keys to other values. For example, if you are sorting files by their size, the sizes need to stay connected to their respective files. You cannot just take the size numbers and output them in order, you need to output all the required file inf...
There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds She nearly ran out of rhymes. -----Input----- The i...
[ "z = int(input())\na = 2\nwhile z / a != z // a:\n\ta += 1\nstri = ''\nif a < z // a:\n\tstri += f'{a}'\n\tstri += f'{z // a}'\nelse:\n\tstri += f'{z // a}'\n\tstri += f'{a}'\nprint(stri)\n", "n = int(input())\nfor i in range(2, n + 1):\n\tif n % i == 0:\n\t\tprint(i, n // i, sep='')\n\t\tbreak\n", "n = int(inp...
{"inputs": ["35\n", "57\n", "391\n", "4\n", "58\n", "14\n", "502\n", "10\n", "202\n", "85\n", "39\n", "22\n", "9\n", "21\n", "25\n", "15\n", "6\n", "158\n", "122\n", "446\n", "33\n", "949\n", "94\n", "49\n", "718\n", "74\n", "26\n", "46\n", "38\n", "34\n", "62\n", "226\n", "55\n", "65\n", "118\n", "187\n", "77\n", "301...
MEDIUM
[]
null
codeforces
[]
[]
https://codeforces.com/problemset/problem/1331/B
null
null
null
null
null
25,179
0
z = int(input()) a = 2 while z / a != z // a: a += 1 stri = '' if a < z // a: stri += f'{a}' stri += f'{z // a}' else: stri += f'{z // a}' stri += f'{a}' print(stri)
# Question There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at all times? On juggling the words Right around two-thirds She nearly ran out of rhymes. -----Input...
Little Jhool always wanted to have some psychic powers so that he could showoff his skills, and magic to people and impress them. (Specially, his girlfriend Big Jhool!) But, in spite all his efforts, hardwork, dedication, Googling, watching youtube videos he couldn't garner any psychic abilities! He knew everyone was ...
[ "n=input()\nc=0\nfor i in range (1,len(n)):\n\tif n[i]==n[i-1]:\n\t\tc=c+1\n\telse:\n\t\tc=0\n\tif c==5:\n\t\tbreak\nif c==5:\n\tprint(\"Sorry, sorry!\")\nelse:\n\tprint(\"Good luck!\")\n", "s = input()\n\nif s.find(\"111111\") != -1 or s.find(\"000000\") != -1:\n\tprint(\"Sorry, sorry!\")\nelse:\n\tprint(\"Good ...
{"inputs": ["11111111111111\n", "0\n", "11000000011\n", "000111000\n", "1111111\n", "100000111110\n", "1000111000111000111000111\n", "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101\n", "00000001\n", "111101010001010010101110110010110111001100001010001000000111110001...
EASY
['Implementation', 'Ad-Hoc', 'BasicProgramming']
psychic-powers
hackerearth
['Fundamentals', 'Implementation', 'Ad-hoc']
[]
null
null
null
null
null
null
25,211
0
n=input() c=0 for i in range (1,len(n)): if n[i]==n[i-1]: c=c+1 else: c=0 if c==5: break if c==5: print("Sorry, sorry!") else: print("Good luck!")
# Question Little Jhool always wanted to have some psychic powers so that he could showoff his skills, and magic to people and impress them. (Specially, his girlfriend Big Jhool!) But, in spite all his efforts, hardwork, dedication, Googling, watching youtube videos he couldn't garner any psychic abilities! He knew e...
The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen. After the fighting stopped, Heidi gave them another task to waste their time on. There are $n$ points on a plane. Given a radius $r$, find the maximum number of ...
[ "import sys\nNORM = 2000000\nLIMIT = NORM * 2 + 1\n\nclass segmentTree:\n\n\tdef __init__(self, n):\n\t\tself.n = n\n\t\tself.t = [0] * (n * 2)\n\t\tself.lazy = [0] * n\n\n\tdef apply(self, p, value):\n\t\tself.t[p] += value\n\t\tif p < self.n:\n\t\t\tself.lazy[p] += value\n\n\tdef build(self, p):\n\t\twhile p > 1:...
{"inputs": ["5 1\n1 1\n1 -1\n-1 1\n-1 -1\n2 0\n", "5 2\n1 1\n1 -1\n-1 1\n-1 -1\n2 0\n", "1 1000000\n1000000 -1000000\n", "1 1000000\n1000000 -1000000\n", "5 2\n1 1\n1 -1\n-1 1\n-1 -2\n2 0\n", "5 1\n1 1\n1 -1\n-1 1\n-1 0\n2 0\n", "5 1\n1 1\n1 -2\n-1 1\n-1 0\n2 0\n", "5 0\n2 1\n-2 -1\n-1 1\n-2 -2\n2 2\n", "5 2\n1 1\n1 -1...
HARD
['data structures']
null
codeforces
['Data structures']
['Data structures']
https://codeforces.com/problemset/problem/1184/C2
null
2019-12-31
null
null
null
25,216
0
import sys NORM = 2000000 LIMIT = NORM * 2 + 1 class segmentTree: def __init__(self, n): self.n = n self.t = [0] * (n * 2) self.lazy = [0] * n def apply(self, p, value): self.t[p] += value if p < self.n: self.lazy[p] += value def build(self, p): while p > 1: p >>= 1 self.t[p] = max(self.t[p ...
# Question The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen. After the fighting stopped, Heidi gave them another task to waste their time on. There are $n$ points on a plane. Given a radius $r$, find the maximu...
Given an array of N strings, find the longest common prefix among all strings present in the array. Example 1: Input: N = 4 arr[] = {geeksforgeeks, geeks, geek, geezer} Output: gee Explanation: "gee" is the longest common prefix in all the given strings. Example 2: Input: N = 2 arr[] = {hello, world} Output: ...
[ "class Solution:\n\n\tdef longestCommonPrefix(self, arr, n):\n\t\tarr.sort()\n\t\tmin_len = min(len(arr[0]), len(arr[n - 1]))\n\t\tans = ''\n\t\tfor i in range(min_len):\n\t\t\tif arr[0][i] == arr[n - 1][i]:\n\t\t\t\tans += arr[0][i]\n\t\t\telse:\n\t\t\t\tbreak\n\t\treturn ans if len(ans) > 0 else -1\n", "class S...
#User function Template for python3 class Solution: def longestCommonPrefix(self, arr, n): # code here
{"inputs": ["N = 4\narr[] = {geeksforgeeks, geeks, geek,\n geezer}", "N = 2\narr[] = {hello, world}"], "outputs": ["gee", "-1"]}
EASY
['Strings', 'Arrays', 'Data Structures']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/longest-common-prefix-in-an-array5129/1
null
null
0
null
O(N*min(|arr_{i}|)).
25,210
0
class Solution: def longestCommonPrefix(self, arr, n): arr.sort() min_len = min(len(arr[0]), len(arr[n - 1])) ans = '' for i in range(min_len): if arr[0][i] == arr[n - 1][i]: ans += arr[0][i] else: break return ans if len(ans) > 0 else -1
# Question Given an array of N strings, find the longest common prefix among all strings present in the array. Example 1: Input: N = 4 arr[] = {geeksforgeeks, geeks, geek, geezer} Output: gee Explanation: "gee" is the longest common prefix in all the given strings. Example 2: Input: N = 2 arr[] = {hello, wor...
Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB999 size so th...
[ "import os\nimport sys\nfrom math import *\nfrom collections import *\nfrom bisect import *\nfrom io import BytesIO, IOBase\n\ndef vsInput():\n\tsys.stdin = open('input.txt', 'r')\n\tsys.stdout = open('output.txt', 'w')\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tsel...
{"inputs": ["2000000000 2000000000 1999999998 1999999999\n", "721746595 799202881 143676564 380427290\n", "266102152 594841161 15854566 13392106\n", "548893795 861438648 131329677 177735812\n", "1243276346 1975662240 38441120 291740200\n", "625166755 843062051 1463070160 1958300154\n", "1 1 2 1\n", "912724694 126873915...
MEDIUM_HARD
['number theory', 'binary search']
null
codeforces
['Number theory', 'Sorting']
['Sorting']
https://codeforces.com/problemset/problem/16/C
0.5 seconds
null
null
64.0 megabytes
null
25,214
0
import os import sys from math import * from collections import * from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() sel...
# Question Reca company makes monitors, the most popular of their models is AB999 with the screen size a × b centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio x: y became popular with users. That's why the company wants to reduce monitor AB99...
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
[ "s = 0\na = b = ''\nfor i in range(int(input())):\n\t(c, d) = map(int, input().split())\n\tif d == 1:\n\t\ta = min(a, s) if a != '' else s\n\telse:\n\t\tb = max(b, s) if b != '' else s\n\ts += c\nprint('Infinity' if b == '' else 'Impossible' if a != '' and a - b < 1 else 1899 - b + s)\n", "q = int(input())\nq -= ...
{"inputs": ["3\n-7 1\n5 2\n8 2\n", "2\n57 1\n22 2\n", "1\n-5 1\n", "4\n27 2\n13 1\n-50 1\n8 2\n", "6\n8 1\n-22 1\n9 2\n-7 2\n85 2\n77 1\n", "7\n-56 1\n-85 2\n-88 2\n-36 1\n-25 2\n8 2\n61 2\n", "15\n20 2\n-31 2\n80 2\n-18 2\n-44 2\n37 2\n-90 2\n76 2\n14 2\n8 2\n-40 2\n22 2\n21 2\n20 2\n-29 2\n", "50\n67 1\n89 2\n83 1\n-...
MEDIUM_HARD
['greedy', 'binary search', 'math']
null
codeforces
['Sorting', 'Mathematics', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/750/C
null
2019-12-31
null
null
null
25,213
0
s = 0 a = b = '' for i in range(int(input())): (c, d) = map(int, input().split()) if d == 1: a = min(a, s) if a != '' else s else: b = max(b, s) if b != '' else s s += c print('Infinity' if b == '' else 'Impossible' if a != '' and a - b < 1 else 1899 - b + s)
# Question Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or h...
Implement the recursive function given by the following rules and print the last 3 digits: F(x, y) = { y + 1 when x = 0, F(x - 1, 1) when x > 0 and y = 0, F(x - 1, F(x, y - 1)) when x > 0 and y > 0 } Input Format A single line containing two integers X,Y 1 ≤ X,Y ≤ 100000 Output Format The last three digits...
[ "def solve(x, y):\n\tif x == 0:\n\t\treturn (y + 1) % 1000\n\tif x == 1:\n\t\treturn (y + 2) % 1000\n\tif x == 2:\n\t\treturn (2 * y + 3) % 1000\n\tif x == 3:\n\t\tr = 5\n\t\tadd = 8\n\t\tfor i in range(y):\n\t\t\tr = (add + r) % 1000\n\t\t\tadd = (add * 2) % 1000\n\t\treturn r\n\tif x == 4 and y == 0:\n\t\treturn ...
{"inputs": ["4 2", "1 100", "4 1", "2 500"], "outputs": ["533", "003", "102", "733"]}
EASY
[]
recursive-function
hackerearth
[]
[]
null
null
null
null
null
null
25,223
0
def solve(x, y): if x == 0: return (y + 1) % 1000 if x == 1: return (y + 2) % 1000 if x == 2: return (2 * y + 3) % 1000 if x == 3: r = 5 add = 8 for i in range(y): r = (add + r) % 1000 add = (add * 2) % 1000 return r if x == 4 and y == 0: return 13 if (x == 4 and y == 1) or (x == 5 and y == ...
# Question Implement the recursive function given by the following rules and print the last 3 digits: F(x, y) = { y + 1 when x = 0, F(x - 1, 1) when x > 0 and y = 0, F(x - 1, F(x, y - 1)) when x > 0 and y > 0 } Input Format A single line containing two integers X,Y 1 ≤ X,Y ≤ 100000 Output Format The last ...
Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in <image>, which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha must find t...
[ "from typing import TypeVar, Generic, Callable, List\nimport sys\nfrom array import array\nfrom collections import Counter\n\ndef input():\n\treturn sys.stdin.buffer.readline().decode('utf-8')\nminf = -10 ** 9 - 100\nT = TypeVar('T')\n\nclass SegmentTree(Generic[T]):\n\t__slots__ = ['size', 'tree', 'identity', 'op'...
{"inputs": ["10 3\n-55\n-35\n-80\n91\n-96\n-93\n-39\n-77\n4\n29\n", "10 3\n-6\n2\n79\n-49\n86\n13\n-31\n-71\n57\n93\n", "10 3\n-38\n68\n-77\n57\n-35\n28\n-61\n-9\n3\n60\n", "10 3\n-20\n-63\n-64\n45\n-84\n-13\n79\n-31\n70\n-100\n", "10 3\n2\n-100\n50\n-85\n-48\n68\n-96\n-31\n85\n-29\n", "10 3\n-13\n26\n-97\n-38\n43\n-12...
MEDIUM_HARD
['data structures', 'implementation']
null
codeforces
['Data structures', 'Implementation']
['Data structures']
https://codeforces.com/problemset/problem/69/E
1.0 seconds
null
null
256.0 megabytes
null
25,218
0
from typing import TypeVar, Generic, Callable, List import sys from array import array from collections import Counter def input(): return sys.stdin.buffer.readline().decode('utf-8') minf = -10 ** 9 - 100 T = TypeVar('T') class SegmentTree(Generic[T]): __slots__ = ['size', 'tree', 'identity', 'op', 'update_op'] d...
# Question Programmer Sasha has recently begun to study data structures. His coach Stas told him to solve the problem of finding a minimum on the segment of the array in <image>, which Sasha coped with. For Sasha not to think that he had learned all, Stas gave him a new task. For each segment of the fixed length Sasha...
If we alternate the vowels and consonants in the string `"have"`, we get the following list, arranged alphabetically: `['ahev', 'aveh', 'ehav', 'evah', 'vahe', 'veha']`. These are the only possibilities in which vowels and consonants are alternated. The first element, `ahev`, is alphabetically lowest. Given a string:...
[ "def solve(s):\n\tvowels = sorted((c for c in s if c in 'aeiou'))\n\tconsonants = sorted((c for c in s if c not in 'aeiou'))\n\t(part1, part2) = sorted((vowels, consonants), key=len, reverse=True)\n\tpart2.append('')\n\tif len(part1) > len(part2):\n\t\treturn 'failed'\n\treturn ''.join((a + b for (a, b) in zip(part...
def solve(s):
{"fn_name": "solve", "inputs": [["java"], ["oruder"], ["zodiac"], ["apple"], ["acidity"], ["codewars"], ["orudere"]], "outputs": [["ajav"], ["edorur"], ["acidoz"], ["lapep"], ["caditiy"], ["failed"], ["ederoru"]]}
EASY
['Strings', 'Algorithms', 'Arrays']
null
codewars
['String algorithms', 'Data structures']
['Data structures']
https://www.codewars.com/kata/59cf8bed1a68b75ffb000026
null
null
null
null
null
25,220
0
def solve(s): vowels = sorted((c for c in s if c in 'aeiou')) consonants = sorted((c for c in s if c not in 'aeiou')) (part1, part2) = sorted((vowels, consonants), key=len, reverse=True) part2.append('') if len(part1) > len(part2): return 'failed' return ''.join((a + b for (a, b) in zip(part1, part2)))
# Question If we alternate the vowels and consonants in the string `"have"`, we get the following list, arranged alphabetically: `['ahev', 'aveh', 'ehav', 'evah', 'vahe', 'veha']`. These are the only possibilities in which vowels and consonants are alternated. The first element, `ahev`, is alphabetically lowest. Giv...
You are given an array A of size N. The task is to find count of elements before which all the elements are smaller. First element is always counted as there is no other element before it. Example 1: Input : arr[] = {10, 40, 23, 35, 50, 7} Output : 3 Explanation : The elements are 10, 40 and 50. No of elements is ...
[ "class Solution:\n\n\tdef countElements(self, arr, n):\n\t\tcnt = 1\n\t\tm = arr[0]\n\t\tfor i in range(1, n):\n\t\t\tif m < arr[i]:\n\t\t\t\tm = arr[i]\n\t\t\t\tcnt += 1\n\t\treturn cnt\n", "class Solution:\n\n\tdef countElements(self, arr, n):\n\t\tc = 1\n\t\tmaxx = arr[0]\n\t\tfor i in arr[1:]:\n\t\t\tif i > m...
#User function Template for python3 class Solution: def countElements(self, arr, n): # Your code goes here
{"inputs": ["arr[] = {10, 40, 23, 35, 50, 7}", "arr[] = {5, 4, 1}"], "outputs": ["3", "1"]}
EASY
['Data Structures', 'Arrays']
null
geeksforgeeks
['Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/elements-before-which-no-element-is-bigger0602/1
null
null
0
null
O(N)
25,222
0
class Solution: def countElements(self, arr, n): cnt = 1 m = arr[0] for i in range(1, n): if m < arr[i]: m = arr[i] cnt += 1 return cnt
# Question You are given an array A of size N. The task is to find count of elements before which all the elements are smaller. First element is always counted as there is no other element before it. Example 1: Input : arr[] = {10, 40, 23, 35, 50, 7} Output : 3 Explanation : The elements are 10, 40 and 50. No of ...
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to collect all these items, however he won't do it by himself. He us...
[ "path = list(map(int, input().split()))\n(n, L, R, QL, QR) = (path[0], path[1], path[2], path[3], path[4])\nw = list(map(int, input().split()))\nsumpref = [0]\nfor i in range(1, n + 1):\n\tsumpref.append(w[i - 1] + sumpref[i - 1])\nanswer = QR * (n - 1) + sumpref[n] * R\nfor i in range(1, n + 1):\n\tenergy = L * su...
{"inputs": ["5 1 100 10000 1\n1 2 3 4 5\n", "1 78 94 369 10000\n93\n", "5 100 1 1 10000\n1 2 3 4 5\n", "1 94 78 369 10000\n93\n", "2 3 4 5 6\n1 2\n", "7 3 13 30 978\n1 2 3 4 5 1 7\n", "5 100 1 10000 1\n1 2 3 4 5\n", "5 1 100 1 10000\n1 2 3 4 5\n", "2 100 100 10000 10000\n100 100\n", "6 32 47 965 897\n7 4 1 3 5 4\n", "7...
MEDIUM
['brute force', 'greedy', 'math']
null
codeforces
['Complete search', 'Mathematics', 'Greedy algorithms']
['Complete search', 'Greedy algorithms']
https://codeforces.com/problemset/problem/355/C
1.0 seconds
null
null
256.0 megabytes
null
25,225
0
path = list(map(int, input().split())) (n, L, R, QL, QR) = (path[0], path[1], path[2], path[3], path[4]) w = list(map(int, input().split())) sumpref = [0] for i in range(1, n + 1): sumpref.append(w[i - 1] + sumpref[i - 1]) answer = QR * (n - 1) + sumpref[n] * R for i in range(1, n + 1): energy = L * sumpref[i] + R * ...
# Question Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms. Vasya needs to collect all these items, however he won't do it by hi...
Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $1$, starting from the topmost one. The columns are numbered from $1$, starting from the leftmost one. Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $1$ and so on to the ...
[ "from __future__ import division, print_function\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nimport itertools\nif sys.version_info[0] < 3:\n\tinput = raw_input\n\trange = xrange\n\tfilter = itertools.ifilter\n\tmap = itertools.imap\n\tzip = itertools.izip\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewl...
{"inputs": ["7\n11\n14\n5\n4\n1\n2\n1000000000\n", "1\n77777\n", "1\n9990999\n", "2\n7\n122112\n", "1\n9865\n", "1\n88888\n", "1\n88889\n", "1\n9865\n", "99\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\...
EASY
['math', 'implementation']
null
codeforces
['Mathematics', 'Implementation']
[]
https://codeforces.com/problemset/problem/1560/C
1 second
2021-08-18
1
256 megabytes
null
25,199
0
from __future__ import division, print_function import os import sys from io import BytesIO, IOBase import itertools if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = itertools.izip BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(s...
# Question Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from $1$, starting from the topmost one. The columns are numbered from $1$, starting from the leftmost one. Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from $1$ and s...
The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doe...
[ "n = 8\ns = ''\nfor i in range(n):\n\ts += input() + ','\nif s.count('WBWBWBWB') + s.count('BWBWBWBW') != 8:\n\tprint('NO')\nelse:\n\tprint('YES')\n", "for i in range(8):\n\ta = input()\n\tif a[0] == a[-1] or 'WW' in a or 'BB' in a:\n\t\tprint('NO')\n\t\texit(0)\nprint('YES')\n", "res = 'YES'\nfor i in range(8)...
{"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBW...
EASY
['brute force', 'strings']
null
codeforces
['String algorithms', 'Complete search']
['Complete search']
https://codeforces.com/problemset/problem/259/A
null
2019-12-31
null
null
null
25,205
0
n = 8 s = '' for i in range(n): s += input() + ',' if s.count('WBWBWBWB') + s.count('BWBWBWBW') != 8: print('NO') else: print('YES')
# Question The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper ch...
Division of Big Integers Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the quotient in a line. Constraints * $-1 \times 10^{1000} \leq A, B \leq 10^{1000}$ * $...
[ "(a, b) = map(int, input().split())\nif a * b < 0:\n\tprint(abs(a) // abs(b) * -1)\nelse:\n\tprint(abs(a) // abs(b))\n", "(a, b) = map(int, input().split())\nbase = 10 ** 1000\nsign = (a < 0) ^ (b < 0)\nprint((-1) ** sign * (abs(a) // abs(b)))\n", "(A, B) = map(int, input().split())\nd = abs(A) // abs(B)\nans =...
{"inputs": ["5 16", "9 6", "18 6", "18 3", "21 3", "21 4", "16 4", "2 1", "52 6", "36 4", "-1 1", "18 1", "36 1", "21 1", "45 1", "11 1", "29 1", "-2 1", "4 -1", "3 -1", "14 1", "22 1", "17 1", "28 1", "21 2", "-6 1", "41 1", "55 4", "9 -1", "23 1", "56 1", "39 1", "12 -1", "5 -1", "7 -1", "12 1", "16 1", "10 -1", "-8 ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
268.435456 megabytes
null
25,224
0
(a, b) = map(int, input().split()) if a * b < 0: print(abs(a) // abs(b) * -1) else: print(abs(a) // abs(b))
# Question Division of Big Integers Given two integers $A$ and $B$, compute the quotient, $\frac{A}{B}$. Round down to the nearest decimal. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the quotient in a line. Constraints * $-1 \times 10^{1000} \leq A, B \leq 10...
Make your strings more nerdy: Replace all 'a'/'A' with 4, 'e'/'E' with 3 and 'l' with 1 e.g. "Fundamentals" --> "Fund4m3nt41s" ```if:csharp Documentation: Kata.Nerdify Method (String) Nerdifies a string. Returns a copy of the original string with 'a'/'A' characters replaced with '4', 'e'/'E' characters replaced with...
[ "def nerdify(txt):\n\treturn txt.translate(str.maketrans('aAeEl', '44331'))\n", "def nerdify(txt):\n\treturn txt.translate(str.maketrans('aelAE', '43143'))\n", "def nerdify(txt):\n\tintab = 'aelAE'\n\toutab = '43143'\n\ttrantab = str.maketrans(intab, outab)\n\treturn txt.translate(trantab)\n", "def nerdify(tx...
def nerdify(txt):
{"fn_name": "nerdify", "inputs": [["Fund4m3nt41s"], ["Seven"], ["Los Angeles"], ["Seoijselawuue"]], "outputs": [["Fund4m3nt41s"], ["S3v3n"], ["Los 4ng313s"], ["S3oijs314wuu3"]]}
EASY
['Strings', 'Fundamentals']
null
codewars
['String algorithms', 'Fundamentals']
[]
https://www.codewars.com/kata/59e9f404fc3c49ab24000112
null
null
null
null
null
25,226
0
def nerdify(txt): return txt.translate(str.maketrans('aAeEl', '44331'))
# Question Make your strings more nerdy: Replace all 'a'/'A' with 4, 'e'/'E' with 3 and 'l' with 1 e.g. "Fundamentals" --> "Fund4m3nt41s" ```if:csharp Documentation: Kata.Nerdify Method (String) Nerdifies a string. Returns a copy of the original string with 'a'/'A' characters replaced with '4', 'e'/'E' characters r...
Recall that the permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). A sequence $a$ ...
[ "(n, m) = map(int, input().split())\nfac = [1]\nfor i in range(1, n + 1):\n\tfac.append(i * fac[i - 1] % m)\nans = 0\nfor i in range(1, n + 1):\n\tans += (n - i + 1) * fac[i] * fac[n - i + 1]\n\tans %= m\nprint(ans)\n", "from array import array\nfrom sys import stdin\nimport bisect\nfrom itertools import *\n\ndef...
{"inputs": ["1 993244853\n", "2 993244853\n", "3 993244853\n", "2019 993244853\n", "2020 437122297\n", "250000 993244853\n", "244435 994838543\n", "234324 994631069\n", "249996 997202249\n", "32433 992864681\n", "4 389349601\n", "5 141602633\n", "6 223676287\n", "7 110998807\n", "8 848339069\n", "9 298827211\n", "10 87...
MEDIUM_HARD
['combinatorics', 'math']
null
codeforces
['Combinatorics', 'Mathematics']
[]
https://codeforces.com/problemset/problem/1284/C
1 second
2020-01-04
0
1024 megabytes
null
25,215
0
(n, m) = map(int, input().split()) fac = [1] for i in range(1, n + 1): fac.append(i * fac[i - 1] % m) ans = 0 for i in range(1, n + 1): ans += (n - i + 1) * fac[i] * fac[n - i + 1] ans %= m print(ans)
# Question Recall that the permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array). A s...
Write a function that checks the braces status in a string, and return `True` if all braces are properly closed, or `False` otherwise. Available types of brackets: `()`, `[]`, `{}`. **Please note, you need to write this function without using regex!** ## Examples ```python '([[some](){text}here]...)' => True '{([])...
[ "brackets = {'}': '{', ']': '[', ')': '('}\n\ndef braces_status(s):\n\tstack = []\n\tfor c in s:\n\t\tif c in '[({':\n\t\t\tstack.append(c)\n\t\telif c in '])}':\n\t\t\tif not stack or stack.pop() != brackets[c]:\n\t\t\t\treturn False\n\treturn not stack\n", "def braces_status(string):\n\ts = ''.join([b for b in ...
def braces_status(s):
{"fn_name": "braces_status", "inputs": [["[()]"], ["{[]}"], ["{[()]}"], ["([)]"], ["([[some](){text}here]...)"], ["}"], ["[()]]"], ["[()]{("], ["()[]{}()"], ["[[[["]], "outputs": [[true], [true], [true], [false], [true], [false], [false], [false], [true], [false]]}
EASY
[]
null
codewars
[]
[]
https://www.codewars.com/kata/58983deb128a54b530000be6
null
null
null
null
null
25,228
0
brackets = {'}': '{', ']': '[', ')': '('} def braces_status(s): stack = [] for c in s: if c in '[({': stack.append(c) elif c in '])}': if not stack or stack.pop() != brackets[c]: return False return not stack
# Question Write a function that checks the braces status in a string, and return `True` if all braces are properly closed, or `False` otherwise. Available types of brackets: `()`, `[]`, `{}`. **Please note, you need to write this function without using regex!** ## Examples ```python '([[some](){text}here]...)' => ...
problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is, any edge o...
[ "(h, w) = map(int, input().split())\n(a, b) = map(int, input().split())\nhigh = h // a * a\nwide = w // b * b\nprint(h * w - high * wide)\n", "(h, w) = map(int, input().split())\n(a, b) = map(int, input().split())\nprint(h * w - a * b * (h // a * (w // b)))\n", "(h, w) = map(int, input().split())\n(a, b) = map(...
{"inputs": ["5 8\n3 2", "5 8\n6 2", "6 8\n6 3", "12 8\n6 3", "12 8\n9 3", "16 8\n9 3", "27 8\n9 6", "27 8\n9 9", "27 14\n9 9", "27 14\n9 16", "27 15\n5 16", "27 9\n5 16", "0 9\n5 29", "-1 10\n2 49", "-1 12\n4 49", "12 8\n11 3", "12 8\n17 3", "16 8\n4 3", "51 8\n9 6", "41 8\n9 9", "27 21\n9 9", "27 27\n9 16", "27 28\n5 ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
268.435456 megabytes
null
25,230
0
(h, w) = map(int, input().split()) (a, b) = map(int, input().split()) high = h // a * a wide = w // b * b print(h * w - high * wide)
# Question problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. * Do not stack tiles. * Do not apply tiles diagonally, that is...
Given a Bucket having a capacity of N litres and the task is to determine that by how many ways you can fill it using two bottles of capacity of 1 Litre and 2 Litre only. Find the answer modulo 10^{8}. Example 1: Input: 3 Output: 3 Explanation: Let O denote filling by 1 litre bottle and T denote filling by 2 litre bot...
[ "class Solution:\n\n\tdef fillingBucket(self, N):\n\t\ta = 1\n\t\tb = 2\n\t\tif N <= 2:\n\t\t\treturn N\n\t\tfor i in range(3, N + 1):\n\t\t\tc = a + b % 10 ** 8\n\t\t\ta = b\n\t\t\tb = c\n\t\treturn c % 10 ** 8\n", "class Solution:\n\n\tdef fillingBucket(self, N):\n\t\tmod = 100000000\n\t\tfib = [0] * (N + 2)\n\...
#User function Template for python3 class Solution: def fillingBucket(self, N): # code here
{"inputs": ["3", "4"], "outputs": ["3", "5"]}
MEDIUM
['Algorithms', 'Dynamic Programming', 'Mathematical', 'permutation']
null
geeksforgeeks
['Dynamic programming', 'Combinatorics', 'Mathematics']
['Dynamic programming']
https://practice.geeksforgeeks.org/problems/filling-bucket0529/1
null
null
0
null
O(N)
25,227
0
class Solution: def fillingBucket(self, N): a = 1 b = 2 if N <= 2: return N for i in range(3, N + 1): c = a + b % 10 ** 8 a = b b = c return c % 10 ** 8
# Question Given a Bucket having a capacity of N litres and the task is to determine that by how many ways you can fill it using two bottles of capacity of 1 Litre and 2 Litre only. Find the answer modulo 10^{8}. Example 1: Input: 3 Output: 3 Explanation: Let O denote filling by 1 litre bottle and T denote filling by...
As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers. I need a function which will take three numbers - a present moment (cu...
[ "def can_i_play(now_hour, start_hour, end_hour):\n\treturn 0 <= (now_hour - start_hour) % 24 < (end_hour - start_hour) % 24\n", "def can_i_play(now_hour, start_hour, end_hour):\n\tif start_hour < end_hour:\n\t\treturn start_hour <= now_hour < end_hour\n\treturn start_hour <= now_hour or now_hour < end_hour\n", ...
def can_i_play(now_hour, start_hour, end_hour):
{"fn_name": "can_i_play", "inputs": [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]], "outputs": [[false], [true], [true], [fal...
EASY
['Fundamentals', 'Date Time']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/59ca888aaeb284bb8f0000aa
null
null
null
null
null
25,234
0
def can_i_play(now_hour, start_hour, end_hour): return 0 <= (now_hour - start_hour) % 24 < (end_hour - start_hour) % 24
# Question As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers. I need a function which will take three numbers - a presen...
Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval. Each event coordinator has their strictly preferred room $P_i$,...
[ "import sys\nfrom math import gcd\ninput = lambda : sys.stdin.readline().strip()\ninp = lambda : list(map(int, sys.stdin.readline().strip().split()))\nfor _ in range(int(input())):\n\t(n, k) = map(int, input().split())\n\td = [[] for i in range(k + 1)]\n\tfor i in range(n):\n\t\t(l, r, p) = map(int, input().split()...
{"inputs": [["1", "4 2", "1 10 1", "10 20 2", "15 50 2", "20 30 2"]], "outputs": [["3"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/ENNO2020/problems/ENCNOV4
null
null
null
null
null
25,236
0
import sys from math import gcd input = lambda : sys.stdin.readline().strip() inp = lambda : list(map(int, sys.stdin.readline().strip().split())) for _ in range(int(input())): (n, k) = map(int, input().split()) d = [[] for i in range(k + 1)] for i in range(n): (l, r, p) = map(int, input().split()) d[p].append([l...
# Question Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval. Each event coordinator has their strictly preferred...
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each vote...
[ "import sys\nf = sys.stdin\nout = sys.stdout\n(n, m) = map(int, f.readline().rstrip('\\r\\n').split())\ncos = {}\ncost = []\nnvot = [0 for i in range(m + 1)]\nparty = [[] for i in range(m + 1)]\nfor i in range(n):\n\t(p, c) = map(int, f.readline().rstrip('\\r\\n').split())\n\tif p != 1:\n\t\tif c in cos:\n\t\t\tcos...
{"inputs": ["1 3000\n2006 226621946\n", "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n", "5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n", "1 3000\n918 548706881\n", "10 10\n7 29\n10 31\n9 40\n5 17\n5 30\n6 85\n2 53\n7 23\n4 57\n10 9\n", "5 5\n1 7\n3 3\n...
MEDIUM_HARD
['brute force', 'greedy']
null
codeforces
['Complete search', 'Greedy algorithms']
['Complete search', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1020/C
2.0 seconds
null
null
256.0 megabytes
null
25,235
0
import sys f = sys.stdin out = sys.stdout (n, m) = map(int, f.readline().rstrip('\r\n').split()) cos = {} cost = [] nvot = [0 for i in range(m + 1)] party = [[] for i in range(m + 1)] for i in range(n): (p, c) = map(int, f.readline().rstrip('\r\n').split()) if p != 1: if c in cos: cos[c] += 1 else: cos[c] =...
# Question As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. F...
You are given three integers $a$, $b$, and $c$. Determine if one of them is the sum of the other two. -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 9261$) — the number of test cases. The description of each test case consists of three integers $a$, $b$, $c$ ($0 \leq a, b, c \leq 20$)....
[ "output = ''\nfor caseno in range(int(input())):\n\tanswer = 'NO'\n\t(a, b, c) = map(int, input().split())\n\tl = sorted([a, b, c])\n\tif l[0] + l[1] == l[2]:\n\t\tanswer = 'YES'\n\toutput += str(answer) + '\\n'\nprint(output)\n", "import sys\ninput = sys.stdin.readline\nt = int(input())\nfor _ in range(t):\n\t(a...
{"inputs": ["7\n1 4 3\n2 5 8\n9 11 20\n0 0 0\n20 20 20\n4 12 3\n15 7 8\n", "12\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "47\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1...
EASY
['implementation']
null
codeforces
['Implementation']
[]
https://codeforces.com/problemset/problem/1742/A
1 second
2022-10-13
0
256 megabytes
null
25,233
0
output = '' for caseno in range(int(input())): answer = 'NO' (a, b, c) = map(int, input().split()) l = sorted([a, b, c]) if l[0] + l[1] == l[2]: answer = 'YES' output += str(answer) + '\n' print(output)
# Question You are given three integers $a$, $b$, and $c$. Determine if one of them is the sum of the other two. -----Input----- The first line contains a single integer $t$ ($1 \leq t \leq 9261$) — the number of test cases. The description of each test case consists of three integers $a$, $b$, $c$ ($0 \leq a, b, ...
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in...
[ "n = int(input())\nL1 = list(map(int, input().split()))\nL2 = list(map(int, input().split()))\n(a0, b0) = (0, 0)\n(a1, b1) = (L1[-1], L2[-1])\nfor k in range(2, n + 1):\n\ta = L1[-k] + max(b0, b1)\n\tb = L2[-k] + max(a0, a1)\n\t(a1, a0) = (a, a1)\n\t(b1, b0) = (b, b1)\nprint(max(a1, b1))\n", "def MI():\n\treturn ...
{"inputs": ["5\n9 3 5 7 3\n5 8 1 4 5\n", "3\n1 2 9\n10 1 1\n", "1\n7\n4\n", "5\n3 10 9 10 6\n4 3 3 6 9\n", "1\n5\n8\n", "1\n5\n1\n", "5\n1 7 6 9 1\n6 1 1 7 10\n", "5\n7 3 3 1 8\n7 2 1 1 2\n", "100\n4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 1 4 ...
MEDIUM
['dp']
null
codeforces
['Dynamic programming']
['Dynamic programming']
https://codeforces.com/problemset/problem/1195/C
null
2019-12-31
null
null
null
25,180
0
n = int(input()) L1 = list(map(int, input().split())) L2 = list(map(int, input().split())) (a0, b0) = (0, 0) (a1, b1) = (L1[-1], L2[-1]) for k in range(2, n + 1): a = L1[-k] + max(b0, b1) b = L2[-k] + max(a0, a1) (a1, a0) = (a, a1) (b1, b0) = (b, b1) print(max(a1, b1))
# Question Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in...
Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end of s. For ex...
[ "S = input()\ns_len = len(S)\nans = S[:s_len - 8]\nprint(ans)\n", "S = input()\nprint(S[0:S.rfind('FESTIVAL')])\n", "S = list(input())\ndel S[-8:]\nprint(''.join(S))\n", "s = input().rstrip()\nprint(s[:-8])\n", "def main():\n\ts = input()\n\tprint(s[:-8])\nmain()\n", "string = input()\nprint(string[:-8])\...
{"inputs": ["YAKINIJUFESTIVAL", "CODEFESTIVALFERTIVAL", "CODEFESTIVAM", "LAVITSEFUJINIKAY", "CPDEFESTIVAM", "LAVITSEEUJINIKAY", "CODEFESTIWALFESTIWAL", "LAWITSEFLAWITSEFEDOC", "BPDEFDSTIVBM", "CODEFWSTIWALFESTIEAL", "MBVITSDFEDPB", "IAKINYJUEESTIVAL", "COCEFWSTIWALFESTIEAL", "MBWITSDFEDPB", "COCTFWSTIWALFESEIEAL", "COC...
UNKNOWN_DIFFICULTY
[]
CODE FESTIVAL 2017 qual B - XXFESTIVAL
atcoder
[]
[]
null
2.0 seconds
null
null
256.0 megabytes
null
25,229
0
S = input() s_len = len(S) ans = S[:s_len - 8] print(ans)
# Question Rng is going to a festival. The name of the festival is given to you as a string S, which ends with `FESTIVAL`, from input. Answer the question: "Rng is going to a festival of what?" Output the answer. Here, assume that the name of "a festival of s" is a string obtained by appending `FESTIVAL` to the end ...
Given an array of integers of size n and an integer k, find all the pairs in the array whose absolute difference is divisible by k. Example 1: Input: n = 3 arr[] = {3, 7, 11} k = 4 Output: 3 Explanation: (11-3) = 8 is divisible by 4 (11-7) = 4 is divisible by 4 (7-3) = 4 is divisible by 4 Example 2: Input: n = 4 arr[] ...
[ "class Solution:\n\n\tdef countPairs(self, n, arr, k):\n\t\tmodDic = {}\n\t\tresult = 0\n\t\tfor item in arr:\n\t\t\tresToCheck = item % k\n\t\t\tinDic = resToCheck in modDic\n\t\t\tif inDic:\n\t\t\t\tmodDic[resToCheck] = modDic[resToCheck] + 1\n\t\t\telse:\n\t\t\t\tmodDic[resToCheck] = 1\n\t\tfor item in modDic:\n...
#User function Template for python3 class Solution: def countPairs (self, n, arr, k): # code here
{"inputs": ["n = 3\r\narr[] = {3, 7, 11}\r\nk = 4", "n = 4\r\narr[] = {1, 2, 3, 4}\r\nk = 2"], "outputs": ["3", "2"]}
EASY
['Data Structures', 'Arrays', 'Hash']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/e0059183c88ab680b2f73f7d809fb8056fe9dc43/1
null
null
0
null
O(n + k)
25,239
0
class Solution: def countPairs(self, n, arr, k): modDic = {} result = 0 for item in arr: resToCheck = item % k inDic = resToCheck in modDic if inDic: modDic[resToCheck] = modDic[resToCheck] + 1 else: modDic[resToCheck] = 1 for item in modDic: result += modDic[item] * (modDic[item] - 1) ...
# Question Given an array of integers of size n and an integer k, find all the pairs in the array whose absolute difference is divisible by k. Example 1: Input: n = 3 arr[] = {3, 7, 11} k = 4 Output: 3 Explanation: (11-3) = 8 is divisible by 4 (11-7) = 4 is divisible by 4 (7-3) = 4 is divisible by 4 Example 2: Input: ...
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`. __For example:__ Let's say you are given the array `{1...
[ "def find_even_index(arr):\n\tfor i in range(len(arr)):\n\t\tif sum(arr[:i]) == sum(arr[i + 1:]):\n\t\t\treturn i\n\treturn -1\n", "def find_even_index(lst):\n\tleft_sum = 0\n\tright_sum = sum(lst)\n\tfor (i, a) in enumerate(lst):\n\t\tright_sum -= a\n\t\tif left_sum == right_sum:\n\t\t\treturn i\n\t\tleft_sum +=...
def find_even_index(arr):
{"fn_name": "find_even_index", "inputs": [[[1, 2, 3, 4, 3, 2, 1]], [[1, 100, 50, -51, 1, 1]], [[1, 2, 3, 4, 5, 6]], [[20, 10, 30, 10, 10, 15, 35]], [[20, 10, -80, 10, 10, 15, 35]], [[10, -80, 10, 10, 15, 35, 20]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 2...
EASY
['Arrays', 'Fundamentals', 'Algorithms']
null
codewars
['Fundamentals', 'Data structures']
['Data structures']
https://www.codewars.com/kata/5679aa472b8f57fb8c000047
null
null
null
null
null
25,243
0
def find_even_index(arr): for i in range(len(arr)): if sum(arr[:i]) == sum(arr[i + 1:]): return i return -1
# Question You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`. __For example:__ Let's say you are given t...
The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate. There are $a$ programmers and $b$ mathematicians at Berland State University. How many maximum teams can be made if: each team must consist of exactly $4$ students, teams of $4$ mathematicians or ...
[ "for s in [*open(0)][1:]:\n\t(a, b) = sorted(map(int, s.split()))\n\tprint(a + min(b, 3 * a) >> 2)\n", "import sys\ninput = sys.stdin.readline\nT = int(input())\nfor _ in range(T):\n\t(a, b) = map(int, input().split())\n\tprint(min((a + b) // 4, a, b))\n", "from sys import stdin, stdout\nfrom collections import...
{"inputs": ["6\n5 5\n10 1\n2 3\n0 0\n17 2\n1000000000 1000000000\n", "1\n841409 1\n"], "outputs": ["2\n1\n1\n0\n2\n500000000\n", "1\n"]}
EASY
['math', 'binary search', 'constructive algorithms']
null
codeforces
['Sorting', 'Mathematics', 'Constructive algorithms']
['Sorting']
https://codeforces.com/problemset/problem/1611/B
1 second
2021-11-25
0
256 megabytes
null
25,242
0
for s in [*open(0)][1:]: (a, b) = sorted(map(int, s.split())) print(a + min(b, 3 * a) >> 2)
# Question The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate. There are $a$ programmers and $b$ mathematicians at Berland State University. How many maximum teams can be made if: each team must consist of exactly $4$ students, teams of $4$ mathem...
We take a line segment of length $\textbf{C}$ on a one-dimensional plane and bend it to create a circle with circumference $\textbf{C}$ that's indexed from $0$ to $\boldsymbol{c-1}$. For example, if $c=4$: We denote a pair of points, $a$ and $\boldsymbol{b}$, as $\rho(a,b)$. We then plot $n$ pairs of points (meaning a...
[ "import math\nimport os\nimport random\nimport re\nimport sys\nimport copy\nimport operator\nsys.setrecursionlimit(20000)\n\ndef primary_distance(a, b, c):\n\tdist_array = min(abs(a - b), c - abs(a - b))\n\treturn dist_array\n\ndef distance_array(array, c):\n\tassert len(array) == 2\n\t(a_1, b_1) = tuple(array[0])\...
{"inputs": ["5 8\n0 4\n2 6\n1 5\n3 7\n4 4\n", "2 1000\n0 10\n10 20\n"], "outputs": ["2\n", "0\n"]}
HARD
['Algorithms - Search']
null
hackerrank
['Complete search']
['Complete search']
https://www.hackerrank.com/challenges/distant-pairs/problem
null
null
4
null
null
25,231
0
import math import os import random import re import sys import copy import operator sys.setrecursionlimit(20000) def primary_distance(a, b, c): dist_array = min(abs(a - b), c - abs(a - b)) return dist_array def distance_array(array, c): assert len(array) == 2 (a_1, b_1) = tuple(array[0]) (a_2, b_2) = tuple(arra...
# Question We take a line segment of length $\textbf{C}$ on a one-dimensional plane and bend it to create a circle with circumference $\textbf{C}$ that's indexed from $0$ to $\boldsymbol{c-1}$. For example, if $c=4$: We denote a pair of points, $a$ and $\boldsymbol{b}$, as $\rho(a,b)$. We then plot $n$ pairs of point...
# Task **_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* . ___ # Notes * **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive* * **_Digit Duplications_** *could occur* , So also **_consider it when formin...
[ "def max_number(n):\n\treturn int(''.join(sorted(str(n), reverse=True)))\n", "max_number = lambda n: int(''.join(sorted(str(n)))[::-1])\n", "max_number = lambda n: int(''.join(sorted(list(str(n)), reverse=True)))\n", "def max_number(digits):\n\tsorted_digits = sorted(str(digits), reverse=True)\n\tresult = ''\...
def max_number(n):
{"fn_name": "max_number", "inputs": [[213], [7389], [63792], [566797], [1000000]], "outputs": [[321], [9873], [97632], [977665], [1000000]]}
EASY
[]
null
codewars
[]
[]
https://www.codewars.com/kata/5a4ea304b3bfa89a9900008e
null
null
null
null
null
25,240
0
def max_number(n): return int(''.join(sorted(str(n), reverse=True)))
# Question # Task **_Given_** *a number* , **_Return_** **_The Maximum number _** *could be formed from the digits of the number given* . ___ # Notes * **_Only Natural numbers_** *passed to the function , numbers Contain digits [0:9] inclusive* * **_Digit Duplications_** *could occur* , So also **_consider it...
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. The streets a...
[ "(n, m) = map(int, input().split())\nstreet = []\nfor i in range(n):\n\tx = list(map(int, input().split()))\n\tstreet.append(x)\n(emma_ind, emma) = (-1, -1)\nfor (j, i) in enumerate(street):\n\tmn = min(i)\n\tif mn > emma:\n\t\temma = mn\n\t\temma_ind = j\nprint(emma)\n", "(n, m) = [int(x) for x in input().split(...
{"inputs": ["3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n", "1 1\n1\n", "1 10\n74 35 82 39 1 84 29 41 70 12\n", "10 1\n44\n23\n65\n17\n48\n29\n49\n88\n91\n85\n", "10 10\n256 72 455 45 912 506 235 68 951 92\n246 305 45 212 788 621 449 876 459 899\n732 107 230 357 370 610 997 669 61 192\n131 93 481 527 ...
EASY
['games', 'greedy']
null
codeforces
['Game theory', 'Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/616/B
null
2019-12-31
null
null
null
25,241
0
(n, m) = map(int, input().split()) street = [] for i in range(n): x = list(map(int, input().split())) street.append(x) (emma_ind, emma) = (-1, -1) for (j, i) in enumerate(street): mn = min(i) if mn > emma: emma = mn emma_ind = j print(emma)
# Question Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one restaurant on the intersection of each street and avenue. T...
Problem Statement Olivia, another cyborg with crafted legs is a very dear friend of Geneo. On the eve of valentines day, Olivia decides to surprise Geneo by arriving at his home with a gift. The gift is special, so is her way of reaching home. Olivia's legs are driven by batteries and can deliver only a fixed amount o...
[ "t = int(input())\nfor i in range(t):\n\t(x, y, n, s, e, w, p) = map(int, input().split())\n\twa = x * e + y * n\n\tc = x + y\n\tp -= wa\n\tif p < 0:\n\t\tprint(-1)\n\telif p == 0:\n\t\tprint(x + y)\n\telse:\n\t\tli = [n + s, e + w]\n\t\tli.sort(reverse=True)\n\t\tj = 0\n\t\twhile p % li[0] != 0:\n\t\t\tp -= li[1]\...
{"inputs": ["4\n10 8 9 1 9 1 90\n2 3 4 4 2 2 20\n346 36 580 403 656 10 906997\n73 544 559 336 831 759 707865"], "outputs": ["-1\n7\n2092\n-1"]}
HARD
['likecs', 'easy-medium', 'greatest-common-divisor', 'icl2018']
null
codechef
['Number theory']
[]
https://www.codechef.com/problems/ICL1804
2 seconds
2018-02-11
0
50000 bytes
null
25,244
0
t = int(input()) for i in range(t): (x, y, n, s, e, w, p) = map(int, input().split()) wa = x * e + y * n c = x + y p -= wa if p < 0: print(-1) elif p == 0: print(x + y) else: li = [n + s, e + w] li.sort(reverse=True) j = 0 while p % li[0] != 0: p -= li[1] j += 2 if p == 0: print(x + y + ...
# Question Problem Statement Olivia, another cyborg with crafted legs is a very dear friend of Geneo. On the eve of valentines day, Olivia decides to surprise Geneo by arriving at his home with a gift. The gift is special, so is her way of reaching home. Olivia's legs are driven by batteries and can deliver only a fi...
Ringo Mart, a convenience store, sells apple juice. On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less cans, D new can...
[ "def main():\n\timport math\n\n\tdef gcd(a, b):\n\t\twhile b:\n\t\t\t(a, b) = (b, a % b)\n\t\treturn a\n\tN = int(input())\n\tABCD = [list(map(int, input().split())) for i in range(N)]\n\tfor (A, B, C, D) in ABCD:\n\t\tif A < B or D < B:\n\t\t\tprint('No')\n\t\t\tcontinue\n\t\tA %= B\n\t\tif C < A:\n\t\t\tprint('No...
{"inputs": ["24\n1 2 3 4\n1 2 4 3\n1 3 2 4\n1 3 4 2\n1 4 1 3\n1 4 3 2\n2 1 3 4\n2 1 4 3\n2 3 1 4\n2 3 4 1\n2 4 1 3\n2 4 3 1\n3 1 2 4\n3 1 4 2\n3 2 1 4\n3 2 4 1\n3 4 1 2\n3 4 2 1\n4 1 2 3\n4 1 3 2\n4 2 1 3\n4 2 3 1\n4 3 1 2\n4 3 2 1", "14\n9 7 5 9\n9 7 6 9\n14 10 7 12\n14 10 8 12\n14 10 9 12\n14 10 7 11\n14 10 8 11\n14 ...
UNKNOWN_DIFFICULTY
[]
AtCoder Grand Contest 026 - rng_10s
atcoder
[]
[]
null
2.0 seconds
null
null
1024.0 megabytes
null
25,238
0
def main(): import math def gcd(a, b): while b: (a, b) = (b, a % b) return a N = int(input()) ABCD = [list(map(int, input().split())) for i in range(N)] for (A, B, C, D) in ABCD: if A < B or D < B: print('No') continue A %= B if C < A: print('No') continue if B == D: print('Yes') ...
# Question Ringo Mart, a convenience store, sells apple juice. On the opening day of Ringo Mart, there were A cans of juice in stock in the morning. Snuke buys B cans of juice here every day in the daytime. Then, the manager checks the number of cans of juice remaining in stock every night. If there are C or less can...
Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch. Suppose we have 5 branches and all of them have below students in a branch. 5 2 4 2 6 Then in one minimize oper...
[ "n=int(input())\ns=input().split()\ns=list(map(int,s))\ng=min(s)\nwhile s!=[]:\n\ti=0\n\tcount=0\n\twhile i<n:\n\t\ts[i]-=g\n\t\tcount+=1\n\t\tif s[i]==0:\n\t\t\ts.remove(s[i])\n\t\t\ti-=1\n\t\t\tn-=1\n\t\ti+=1\n\ttry:\n\t\tg=min(s)\n\texcept:\n\t\tpass\n\tprint(count)\n\t\t\t\n\t\n", "n=int(eval(input()))\nl=sor...
{"inputs": ["6\n5 4 4 2 2 8"], "outputs": ["6\n4\n2\n1"]}
UNKNOWN_DIFFICULTY
[]
find-the-students-2
hackerearth
[]
[]
null
null
null
null
null
null
25,246
0
n=int(input()) s=input().split() s=list(map(int,s)) g=min(s) while s!=[]: i=0 count=0 while i<n: s[i]-=g count+=1 if s[i]==0: s.remove(s[i]) i-=1 n-=1 i+=1 try: g=min(s) except: pass print(count)
# Question Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch. Suppose we have 5 branches and all of them have below students in a branch. 5 2 4 2 6 Then in one m...
Given two integers A and B, return any string S such that: S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in S.   Example 1: Input: A = 1, B = 2 Output: "abb" Explanation: "abb", "bab" and "bba" are all corr...
[ "class Solution:\n\n\tdef strWithout3a3b(self, A: int, B: int) -> str:\n\t\tif A >= 2 * B:\n\t\t\treturn 'aab' * B + 'a' * (A - 2 * B)\n\t\telif A >= B:\n\t\t\treturn 'aab' * (A - B) + 'ab' * (2 * B - A)\n\t\telif B >= 2 * A:\n\t\t\treturn 'bba' * A + 'b' * (B - 2 * A)\n\t\telse:\n\t\t\treturn 'bba' * (B - A) + 'ab...
class Solution: def strWithout3a3b(self, A: int, B: int) -> str:
{"fn_name": "strWithout3a3b", "inputs": [[1, 2]], "outputs": ["bba"]}
MEDIUM_HARD
['Greedy', 'String']
null
leetcode
['String algorithms', 'Greedy algorithms']
['Greedy algorithms']
https://leetcode.com/problems/string-without-aaa-or-bbb/
null
null
null
null
null
25,250
0
class Solution: def strWithout3a3b(self, A: int, B: int) -> str: if A >= 2 * B: return 'aab' * B + 'a' * (A - 2 * B) elif A >= B: return 'aab' * (A - B) + 'ab' * (2 * B - A) elif B >= 2 * A: return 'bba' * A + 'b' * (B - 2 * A) else: return 'bba' * (B - A) + 'ab' * (2 * A - B)
# Question Given two integers A and B, return any string S such that: S has length A + B and contains exactly A 'a' letters, and exactly B 'b' letters; The substring 'aaa' does not occur in S; The substring 'bbb' does not occur in S.   Example 1: Input: A = 1, B = 2 Output: "abb" Explanation: "abb", "bab" and "bba" ...
Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants to manipulate...
[ "from string import digits\nimport sys\nreadline = sys.stdin.readline\nwrite = sys.stdout.write\n\ndef parse(S, mp):\n\tM = 32768\n\tcur = 0\n\n\tdef transpose(m):\n\t\t(p, q, v) = m\n\t\tres = [[0] * p for i in range(q)]\n\t\tfor i in range(q):\n\t\t\tfor j in range(p):\n\t\t\t\tres[i][j] = v[j][i]\n\t\treturn (q,...
{"inputs": ["1\nA=[1 2 3;4 5 6].\n1\nA=[[1 4 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18].\n3\nB=[3 -2 1;-9 8 7].\nC=([1 2 3;4 5 6]+B)(2,3).\nD=([1 2 3;4 5 6]+B)([1 2],[2 3]).\n5\nA=2*[1 2;-3 4]'.\nB=A([2 1 2],[2 1]).\nA=[1 2;3 4]*3.\nA=[2]*[1 2;3 4].\nA=[1 2;3 4]*[3].\n2\nA=[11 12 13;0 22 23;0 0 33].\nA=[A A';--A'''...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
8.0 seconds
null
null
134.217728 megabytes
null
25,254
0
from string import digits import sys readline = sys.stdin.readline write = sys.stdout.write def parse(S, mp): M = 32768 cur = 0 def transpose(m): (p, q, v) = m res = [[0] * p for i in range(q)] for i in range(q): for j in range(p): res[i][j] = v[j][i] return (q, p, res) def submatrix(m, a, b): (...
# Question Dr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot use it outside his laboratory because the software consumes much of resources. He wants t...
Chef's current age is 20 years, while Chefina's current age is 10 years. Determine Chefina's age when Chef will be X years old. Note: Assume that Chef and Chefina were born on same day and same month (just different year). ------ Input Format ------ - The first line of input will contain a single integer T, denot...
[ "t = int(input())\nfor _ in range(t):\n\tx = int(input())\n\tprint(x - 10)\n", "t = int(input())\nfor i in range(t):\n\tx = int(input())\n\tprint(10 + x - 20)\n", "t = int(input())\nfor i in range(t):\n\ta = int(input())\n\tprint(abs(10 - a))\n", "T = int(input())\nfor i in range(T):\n\tX = int(input())\n\tY ...
{"inputs": ["4\n25\n36\n50\n44\n"], "outputs": ["15\n26\n40\n34\n"]}
EASY
['Mathematics', 'Basic Maths']
null
codechef
['Mathematics']
[]
https://www.codechef.com/problems/AGEING
1 seconds
2023-02-28
0
50000 bytes
null
25,249
0
t = int(input()) for _ in range(t): x = int(input()) print(x - 10)
# Question Chef's current age is 20 years, while Chefina's current age is 10 years. Determine Chefina's age when Chef will be X years old. Note: Assume that Chef and Chefina were born on same day and same month (just different year). ------ Input Format ------ - The first line of input will contain a single inte...
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
[ "n = int(input())\ns = input()\nh = 0\nfor i in s:\n\tif i == 'H':\n\t\th += 1\nr = []\nt = 0\nfor i in range(0, n):\n\tif s[i] == 'H':\n\t\tfor b in range((i + 1) % n, min((i + 1) % n + h - 1, n)):\n\t\t\tif s[b] == 'T':\n\t\t\t\tt += 1\n\t\tif (i + 1) % n + (h - 1) > n:\n\t\t\tfor q in range(0, ((i + 1) % n + (h ...
{"inputs": ["13\nHTTTHHHTTTTHH\n", "35\nTTTTTTHTTHTTTTTHTTTTTTTTTTTHTHTTTTT\n", "178\nTHHHTHTTTHTTHTTHHHHHTTTHTTHHTHTTTHTHTTTTTHHHTHTHHHTHHHTTTTTTTTHHHHTTHHTHHHHTHTTTHHHHHHTHHTHTTHTHTTTTTTTTTHHTTHHTHTTHHTHHHHHTTHHTTHHTTHHHTTHHTTTTHTHHHTHTTHTHTTTHHHHTHHTHHHTHTTTTTT\n", "7\nTTTHTTT\n", "8\nHHTHHTHH\n", "87\nHTHHTTHHHHTHH...
MEDIUM_HARD
['two pointers']
null
codeforces
['Amortized analysis']
['Amortized analysis']
https://codeforces.com/problemset/problem/46/C
2.0 seconds
null
null
256.0 megabytes
O(N)
25,255
0
n = int(input()) s = input() h = 0 for i in s: if i == 'H': h += 1 r = [] t = 0 for i in range(0, n): if s[i] == 'H': for b in range((i + 1) % n, min((i + 1) % n + h - 1, n)): if s[b] == 'T': t += 1 if (i + 1) % n + (h - 1) > n: for q in range(0, ((i + 1) % n + (h - 1)) % n): if s[q] == 'T': ...
# Question Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also st...
You need to find if a number can be expressed as sum of two perfect powers. That is, given x find if there exists non negative integers a, b, m, n such that a^m + b^n = x. Input First line of the input contains number of test cases T. It is followed by T lines, each line contains a sinle number x. Output For each te...
[ "c=[]\nhash=[0]*1000009\nq=[0]*1000009\nhash[1]=1\nx=0\nfor i in range(2,10000):\n\tfor j in range(2,10000):\n\t\tx=i**j\n\t\tif x<=1000000:\n\t\t\thash[x]=1\n\t\t\tc.append(x)\n\t\telse:\n\t\t\tbreak\ny=0\nc.append(1)\nc.sort()\nfor num1 in c:\n\tfor num2 in c:\n\t\tif num1+num2<=(1000004):\n\t\t\tq[num1+num2]=1\n...
{"inputs": ["20\n178461\n767271\n143872\n917783\n642681\n496408\n735441\n899441\n265715\n772194\n797342\n833227\n479407\n800158\n613225\n498438\n818615\n750993\n597881\n142739\n", "20\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n", "20\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n...
MEDIUM
['Math']
sum-of-powers-6
hackerearth
['Mathematics']
[]
null
null
null
null
null
null
25,256
0
c=[] hash=[0]*1000009 q=[0]*1000009 hash[1]=1 x=0 for i in range(2,10000): for j in range(2,10000): x=i**j if x<=1000000: hash[x]=1 c.append(x) else: break y=0 c.append(1) c.sort() for num1 in c: for num2 in c: if num1+num2<=(1000004): q[num1+num2]=1 else: break d=0 t=int(input()) for i in ra...
# Question You need to find if a number can be expressed as sum of two perfect powers. That is, given x find if there exists non negative integers a, b, m, n such that a^m + b^n = x. Input First line of the input contains number of test cases T. It is followed by T lines, each line contains a sinle number x. Output...
Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days. Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not make any transaction at all. What is the maximum profit you can obtai...
[ "for _ in range(eval(input())):\n\tnoc = eval(input())\n\tins = list(map(int, input().split()))\n\ttmp = ins[::]\n\tcnt = noc-2\n\twhile cnt >= 0:\n\t\ttmp[cnt] = max(tmp[cnt+1], ins[cnt]) \n\t\tcnt-=1\n\tprofit = 0 \n\tfor i in range(noc):\n\t\tprofit += tmp[i] - ins[i]\n\tprint(profit) \n", "for i i...
{"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]}
UNKNOWN_DIFFICULTY
[]
stock-market-calculation-3
hackerearth
[]
[]
null
null
null
null
null
null
25,257
0
for _ in range(eval(input())): noc = eval(input()) ins = list(map(int, input().split())) tmp = ins[::] cnt = noc-2 while cnt >= 0: tmp[cnt] = max(tmp[cnt+1], ins[cnt]) cnt-=1 profit = 0 for i in range(noc): profit += tmp[i] - ins[i] print(profit)
# Question Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days. Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not make any transaction at all. What is the maximum profit y...
Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with vertices at...
[ "import math\nimport functools\nimport sys\n\ndef eulen(x, y):\n\tr = functools.reduce(lambda x, y: x + y, map(lambda x: (x[0] - x[1]) ** 2, zip(x, y)))\n\treturn math.sqrt(r)\n\ndef output(t, p):\n\tprint('YES')\n\tprint(t)\n\tprint(' '.join(map(str, p)))\nn = int(input())\npoints = []\nfor i in range(n + 1):\n\tp...
{"inputs": ["20\n26 47 23\n1 -2 17\n-14 -22 46\n19 34 -18\n22 -10 -34\n15 14 -48\n-30 -12 -12\n-23 40 -48\n-50 -41 -35\n48 -5 46\n-2 -11 10\n-49 47 -15\n31 6 10\n-41 35 15\n28 28 25\n43 -7 -10\n-19 -48 49\n-10 -29 28\n0 -10 28\n41 12 -26\n-14 40 17\n3 2\n-115 1407 1434\n", "4\n1 0 0\n0 1 0\n-1 0 0\n0 -1 0\n1 0 0\n10 5\...
HARD
['binary search', 'geometry']
null
codeforces
['Geometry', 'Sorting']
['Sorting']
https://codeforces.com/problemset/problem/65/C
2.0 seconds
null
null
256.0 megabytes
null
25,259
0
import math import functools import sys def eulen(x, y): r = functools.reduce(lambda x, y: x + y, map(lambda x: (x[0] - x[1]) ** 2, zip(x, y))) return math.sqrt(r) def output(t, p): print('YES') print(t) print(' '.join(map(str, p))) n = int(input()) points = [] for i in range(n + 1): points.append(tuple(map(int...
# Question Brothers Fred and George Weasley once got into the sporting goods store and opened a box of Quidditch balls. After long and painful experiments they found out that the Golden Snitch is not enchanted at all. It is simply a programmed device. It always moves along the same trajectory, which is a polyline with...
A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt. Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest par...
[ "d = {}\nfor _ in [0] * int(input()):\n\t(a, v) = map(int, input().split())\n\td.setdefault(v, [])\n\td[v] += [a]\nm = max(d)\nprint(min(d[m]), m)\n", "n = int(input())\ndic = {}\nmax_v = 0\nfor _ in range(n):\n\t(a, v) = map(int, input().split())\n\tif not v in dic or a < dic[v]:\n\t\tdic[v] = a\n\tif v > max_v:...
{"inputs": ["6\n1 14\n4 25\n3 42\n4 11\n5 40\n6 37", "6\n1 14\n4 25\n3 42\n4 11\n5 60\n6 37", "6\n1 14\n2 25\n3 81\n4 11\n5 40\n6 37", "6\n1 14\n4 25\n3 72\n4 11\n5 60\n6 37", "6\n1 14\n2 25\n3 63\n4 11\n5 40\n6 37", "6\n1 14\n2 25\n3 55\n4 11\n4 40\n6 59", "6\n1 14\n2 6\n3 3\n4 3\n5 40\n6 37", "6\n1 14\n2 25\n3 74\n4 ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
134.217728 megabytes
null
25,258
0
d = {} for _ in [0] * int(input()): (a, v) = map(int, input().split()) d.setdefault(v, []) d[v] += [a] m = max(d) print(min(d[m]), m)
# Question A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt. Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with th...
We have a string S of length N consisting of A, T, C, and G. Strings T_1 and T_2 of the same length are said to be complementary when, for every i (1 \leq i \leq l), the i-th character of T_1 and the i-th character of T_2 are complementary. Here, A and T are complementary to each other, and so are C and G. Find the num...
[ "import sys\nsys.setrecursionlimit(10 ** 6)\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\ndef input():\n\treturn sys.stdin.readline().strip()\n\ndef main():\n\t(N, S) = input().split()\n\tN = int(N)\n\tans = 0\n\tfor i in range(N):\n\t\ta = 0\n\t\tc = 0\n\t\tfor j in range(i, N):\n\t\t\tif S[j] == 'A':\n\t\t\t\ta += 1\...
{"inputs": ["4 AGCT\n", "4 ATAT\n", "10 AAATACCGCG\n", "5000 GCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCGCG...
MEDIUM_HARD
[]
null
atcoder
[]
[]
https://atcoder.jp/contests/arc104/tasks/arc104_b
null
null
null
null
null
25,260
0
import sys sys.setrecursionlimit(10 ** 6) INF = float('inf') MOD = 10 ** 9 + 7 def input(): return sys.stdin.readline().strip() def main(): (N, S) = input().split() N = int(N) ans = 0 for i in range(N): a = 0 c = 0 for j in range(i, N): if S[j] == 'A': a += 1 elif S[j] == 'T': a -= 1 elif ...
# Question We have a string S of length N consisting of A, T, C, and G. Strings T_1 and T_2 of the same length are said to be complementary when, for every i (1 \leq i \leq l), the i-th character of T_1 and the i-th character of T_2 are complementary. Here, A and T are complementary to each other, and so are C and G. ...
Even if it's a really easy question, she won't be able to answer it — Perfect Memento in Strict Sense Cirno's perfect bitmasks classroom has just started! Cirno gave her students a positive integer $x$. As an assignment, her students need to find the minimum positive integer $y$, which satisfies the following two co...
[ "t = int(input())\nfor _ in range(t):\n\tx = int(input())\n\tif x == 1:\n\t\tprint(3)\n\telse:\n\t\ty = x & -x\n\t\tif y == x:\n\t\t\tprint(x + 1)\n\t\telse:\n\t\t\tprint(y)\n", "def main():\n\tx = int(input())\n\tif x == 1:\n\t\treturn 3\n\tb = bin(x)\n\tb = b[::-1]\n\tfor i in range(len(b)):\n\t\tif b[i] == '1'...
{"inputs": ["7\n1\n2\n5\n9\n16\n114514\n1000000\n", "1\n1073741824\n"], "outputs": ["3\n3\n1\n1\n17\n2\n64\n", "1073741825\n"]}
EASY
['brute force', 'bitmasks']
null
codeforces
['Bit manipulation', 'Complete search']
['Bit manipulation', 'Complete search']
https://codeforces.com/problemset/problem/1688/A
1 second
2022-06-03
0
256 megabytes
null
25,267
0
t = int(input()) for _ in range(t): x = int(input()) if x == 1: print(3) else: y = x & -x if y == x: print(x + 1) else: print(y)
# Question Even if it's a really easy question, she won't be able to answer it — Perfect Memento in Strict Sense Cirno's perfect bitmasks classroom has just started! Cirno gave her students a positive integer $x$. As an assignment, her students need to find the minimum positive integer $y$, which satisfies the foll...
You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either gras...
[ "(n, m) = [int(i) for i in input().split()]\nif n == 1 and m == 1:\n\tprint(0)\nelif n == 1:\n\tlawn = input()\n\tprint(lawn.rfind('W'))\nelif m == 1:\n\tweeds = 0\n\tfor i in range(n):\n\t\tlawn = input()\n\t\tif lawn == 'W':\n\t\t\tweeds = i\n\tprint(weeds)\nelse:\n\tlawn = []\n\tfor i in range(n):\n\t\tlawn.appe...
{"inputs": ["150 1\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nW\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nW\nG\nG\nG\nW\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nW\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\n...
MEDIUM
['greedy', 'sortings']
null
codeforces
['Sorting', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/115/B
2.0 seconds
null
null
256.0 megabytes
null
25,262
0
(n, m) = [int(i) for i in input().split()] if n == 1 and m == 1: print(0) elif n == 1: lawn = input() print(lawn.rfind('W')) elif m == 1: weeds = 0 for i in range(n): lawn = input() if lawn == 'W': weeds = i print(weeds) else: lawn = [] for i in range(n): lawn.append(input()) first_weed = [row.find('W...
# Question You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain...
A little weird green frog speaks in a very strange variation of English: it reverses sentence, omitting all puntuation marks `, ; ( ) - ` except the final exclamation, question or period. We urgently need help with building a proper translator. To simplify the task, we always use lower-case letters. Apostrophes are fo...
[ "import re\n\ndef frogify(s):\n\treturn ' '.join((' '.join(re.findall('[a-z]+', sentence)[::-1]) + punct for (sentence, punct) in re.findall('(.*?)([.!?])', s)))\n", "import re\n\ndef frogify(s):\n\tdelimiters = set(['.', '!', '?'])\n\tsentences = re.split('([\\\\!\\\\.\\\\?])', re.sub('[,\\\\;\\\\)\\\\(-]', '', ...
def frogify(s):
{"fn_name": "frogify", "inputs": [["i am a frog."], ["can you do it?"], ["seems like you understand!"], ["multisentence is good. is not it?"], ["green, red or orange - we all just frogs, do not you think so?"]], "outputs": [["frog a am i."], ["it do you can?"], ["understand you like seems!"], ["good is multisentence. i...
EASY
['Regular Expressions', 'Strings', 'Fundamentals']
null
codewars
['String algorithms', 'Fundamentals']
[]
https://www.codewars.com/kata/59f6d96d27402f9329000081
null
null
null
null
null
25,265
0
import re def frogify(s): return ' '.join((' '.join(re.findall('[a-z]+', sentence)[::-1]) + punct for (sentence, punct) in re.findall('(.*?)([.!?])', s)))
# Question A little weird green frog speaks in a very strange variation of English: it reverses sentence, omitting all puntuation marks `, ; ( ) - ` except the final exclamation, question or period. We urgently need help with building a proper translator. To simplify the task, we always use lower-case letters. Apostr...
Given an array Arr of N positive integers and a number K where K is used as a threshold value to divide each element of the array into sum of different numbers. Find the sum of count of the numbers in which array elements are divided. Example 1: Input: N = 4, K = 3 Arr[] = {5, 8, 10, 13} Output: 14 Explanation: Each nu...
[ "class Solution:\n\n\tdef totalCount(self, arr, n, k):\n\t\tl = []\n\t\tfor i in arr:\n\t\t\tif i // k == i / k:\n\t\t\t\tl.append(i // k)\n\t\t\telse:\n\t\t\t\tl.append(i // k + 1)\n\t\treturn sum(l)\n", "class Solution:\n\n\tdef totalCount(self, arr, n, k):\n\t\tsum = 0\n\t\tfor i in range(n):\n\t\t\tsum += arr...
#User function Template for python3 class Solution: def totalCount(self, arr, n, k): # code here
{"inputs": ["N = 4, K = 3\r\nArr[] = {5, 8, 10, 13}", "N = 5, K = 4\r\nArr[] = {10, 2, 3, 4, 7}"], "outputs": ["14", "8"]}
EASY
['Data Structures', 'Arrays']
null
geeksforgeeks
['Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/total-count2415/1
null
null
0
null
O(N)
25,266
0
class Solution: def totalCount(self, arr, n, k): l = [] for i in arr: if i // k == i / k: l.append(i // k) else: l.append(i // k + 1) return sum(l)
# Question Given an array Arr of N positive integers and a number K where K is used as a threshold value to divide each element of the array into sum of different numbers. Find the sum of count of the numbers in which array elements are divided. Example 1: Input: N = 4, K = 3 Arr[] = {5, 8, 10, 13} Output: 14 Explanat...
In this kata you are expected to recover a scattered password in a (m x n) grid (you'll be given directions of all password pieces in the array) The array will contain pieces of the password to be recovered, you'll get directions on how to get all the the pieces, your initial position in the array will be the characte...
[ "MOVES = {'right': (0, 1), 'down': (1, 0), 'left': (0, -1), 'up': (-1, 0)}\n\ndef get_password(grid, dirs):\n\t(x, y) = next(((x, y) for (x, r) in enumerate(grid) for (y, c) in enumerate(r) if c == 'x'))\n\tpwd = []\n\tfor d in dirs:\n\t\t(dx, dy) = MOVES[d.strip('T')]\n\t\t(x, y) = (x + dx, y + dy)\n\t\tif d.endsw...
def get_password(grid,directions):
{"fn_name": "get_password", "inputs": [], "outputs": []}
EASY
['Data Structures', 'Arrays', 'Algorithms', 'Logic']
null
codewars
['Data structures']
['Data structures']
https://www.codewars.com/kata/58f6e7e455d7597dcc000045
null
null
null
null
null
25,270
0
MOVES = {'right': (0, 1), 'down': (1, 0), 'left': (0, -1), 'up': (-1, 0)} def get_password(grid, dirs): (x, y) = next(((x, y) for (x, r) in enumerate(grid) for (y, c) in enumerate(r) if c == 'x')) pwd = [] for d in dirs: (dx, dy) = MOVES[d.strip('T')] (x, y) = (x + dx, y + dy) if d.endswith('T'): pwd.appen...
# Question In this kata you are expected to recover a scattered password in a (m x n) grid (you'll be given directions of all password pieces in the array) The array will contain pieces of the password to be recovered, you'll get directions on how to get all the the pieces, your initial position in the array will be ...
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price. At every moment of time, every SELL offer has higher price than every BUY offer. In th...
[ "import math\nimport random\nimport heapq, bisect\nimport sys\nfrom collections import deque, defaultdict\nfrom fractions import Fraction\nimport sys\nfrom collections import defaultdict\nmod = 10 ** 9 + 7\nmod1 = 998244353\nimport os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBas...
{"inputs": ["6\nADD 1\nACCEPT 1\nADD 2\nACCEPT 2\nADD 3\nACCEPT 3\n", "4\nADD 1\nADD 2\nADD 3\nACCEPT 2\n", "7\nADD 1\nADD 2\nADD 3\nADD 4\nADD 5\nACCEPT 3\nACCEPT 5\n", "6\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\n", "8\nADD 10\nADD 7\nADD 13\nADD 15\nADD 12\nACCEPT 10\nADD 11\nADD 8\n", "15\nADD 14944938\nAD...
HARD
['data structures', 'greedy', 'combinatorics']
null
codeforces
['Combinatorics', 'Data structures', 'Greedy algorithms']
['Data structures', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1028/D
null
2019-12-31
null
null
null
25,271
0
import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys from collections import defaultdict mod = 10 ** 9 + 7 mod1 = 998244353 import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 ...
# Question Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price. At every moment of time, every SELL offer has higher price than every BUY of...
Chef's professor is planning to give his class a group assignment. There are 2N students in the class, with distinct roll numbers ranging from 1 to 2N. Chef's roll number is X. The professor decided to create N groups of 2 students each. The groups were created as follows: the first group consists of roll numbers 1 an...
[ "t = int(input())\nfor l in range(t):\n\t(n, x) = map(int, input().split())\n\tprint(2 * n + 1 - x)\n", "t = int(input())\nfor i in range(t):\n\t(n, x) = list(map(int, input().split()))\n\tprint(2 * n - x + 1)\n", "t = int(input())\nfor i in range(t):\n\t(a, b) = map(int, input().split())\n\tprint(2 * a + 1 - b...
{"inputs": ["3\n2 2\n3 1\n3 4\n"], "outputs": ["3\n6\n3"]}
EASY
['Mathematics', 'Basic Maths', 'Arithmetic']
null
codechef
['Mathematics']
[]
https://www.codechef.com/problems/GROUPASSGN
1 seconds
2022-03-21
0
50000 bytes
null
25,275
0
t = int(input()) for l in range(t): (n, x) = map(int, input().split()) print(2 * n + 1 - x)
# Question Chef's professor is planning to give his class a group assignment. There are 2N students in the class, with distinct roll numbers ranging from 1 to 2N. Chef's roll number is X. The professor decided to create N groups of 2 students each. The groups were created as follows: the first group consists of roll ...
Given a number N, the task is to find the sum of all the elements from all possible subsets of a set formed by first N natural numbers. Example 1: Input: N = 2 Output: 6 Explanation: Possible subsets are {{1}, {2}, {1, 2}}. Sum of elements in the subsets is 1 + 2 + 1 + 2 = 6. Example 2: Input: N = 3 Output: 24 Explana...
[ "class Solution:\n\n\tdef sumOfSubsets(self, N):\n\t\ta = sum(range(1, N + 1))\n\t\tb = 2 ** (N - 1)\n\t\treturn a * b\n", "class Solution:\n\n\tdef sumOfSubsets(self, N):\n\t\tk = 2 ** (N - 1)\n\t\tc = 0\n\t\tfor i in range(1, N + 1):\n\t\t\tc += i * k\n\t\treturn c\n", "class Solution:\n\n\tdef sumOfSubsets(s...
#User function Template for python3 class Solution: def sumOfSubsets(self, N): #code here
{"inputs": ["N = 2", "N = 3"], "outputs": ["6", "24"]}
EASY
['Algorithms', 'subset', 'Mathematical']
null
geeksforgeeks
['Mathematics']
[]
https://practice.geeksforgeeks.org/problems/sum-of-all-subsets-formed-by-first-n-natural-numbers0603/1
null
null
0
null
O(logN)
25,278
0
class Solution: def sumOfSubsets(self, N): a = sum(range(1, N + 1)) b = 2 ** (N - 1) return a * b
# Question Given a number N, the task is to find the sum of all the elements from all possible subsets of a set formed by first N natural numbers. Example 1: Input: N = 2 Output: 6 Explanation: Possible subsets are {{1}, {2}, {1, 2}}. Sum of elements in the subsets is 1 + 2 + 1 + 2 = 6. Example 2: Input: N = 3 Output...
Alice and Bob are playing a game of coins. N coins are placed on the table in a row. The game begins with Alice and afterwards they alternate the moves. A valid move is defined as follows: You pick one coin or two adjacent coins and remove them. The game is over if anyone is not able to make any valid move, and th...
[ "print('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alice')\nprint('Alic...
{"inputs": ["100\n90287615\n75096686\n621537351\n337906787\n932379178\n576368174\n614524887\n381393352\n683734903\n357312092\n45953951\n11885544\n659581459\n649281842\n360919237\n468202152\n348705142\n433071763\n766393082\n957639054\n492279795\n441607546\n238769590\n287864255\n240825138\n413652652\n556513880\n942947637...
EASY
['GameTheory', 'Algorithms']
game-of-coins
hackerearth
['Game theory']
[]
null
null
null
null
null
null
25,273
0
print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print('Alice') print...
# Question Alice and Bob are playing a game of coins. N coins are placed on the table in a row. The game begins with Alice and afterwards they alternate the moves. A valid move is defined as follows: You pick one coin or two adjacent coins and remove them. The game is over if anyone is not able to make any valid ...
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there a...
[ "from operator import mul\nfrom functools import reduce\n\ndef cmb(n, r, p):\n\tif r < 0 or n < r:\n\t\treturn 0\n\tr = min(r, n - r)\n\treturn fact[n] * factinv[r] * factinv[n - r] % p\np = 10 ** 9 + 7\nN = 10 ** 6\nfact = [1, 1]\nfactinv = [1, 1]\ninv = [0, 1]\nfor i in range(2, N + 1):\n\tfact.append(fact[-1] * ...
{"inputs": ["2 3 1 1\n", "10 7 3 4\n", "100000 100000 99999 99999\n", "100000 100000 44444 55555\n"], "outputs": ["2\n", "3570\n", "1\n", "738162020\n"]}
MEDIUM_HARD
[]
null
atcoder
[]
[]
https://atcoder.jp/contests/abc042/tasks/arc058_b
null
null
null
null
null
25,252
0
from operator import mul from functools import reduce def cmb(n, r, p): if r < 0 or n < r: return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n - r] % p p = 10 ** 9 + 7 N = 10 ** 6 fact = [1, 1] factinv = [1, 1] inv = [0, 1] for i in range(2, N + 1): fact.append(fact[-1] * i % p) inv.append(-inv[p...
# Question We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That...
Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it: * All words that begin with a lower case letter should be at the beginning of the sorted sentence, and sorted...
[ "from string import punctuation\nt = str.maketrans('', '', punctuation)\n\ndef pseudo_sort(s):\n\ta = s.translate(t).split()\n\tb = sorted((x for x in a if x[0].islower()))\n\tc = sorted((x for x in a if x[0].isupper()), reverse=True)\n\treturn ' '.join(b + c)\n", "from string import punctuation\n\ndef pseudo_sor...
def pseudo_sort(st):
{"fn_name": "pseudo_sort", "inputs": [["I, habitan of the Alleghanies, treating of him as he is in himself in his own rights"], ["take up the task eternal, and the burden and the lesson"], ["Land of the eastern Chesapeake"], ["And I send these words to Paris with my love"], ["O Liberty! O mate for me!"], ["With Egypt, ...
EASY
['Strings', 'Algorithms', 'Sorting']
null
codewars
['String algorithms', 'Sorting']
['Sorting']
https://www.codewars.com/kata/52dffa05467ee54b93000712
null
null
null
null
null
25,279
0
from string import punctuation t = str.maketrans('', '', punctuation) def pseudo_sort(s): a = s.translate(t).split() b = sorted((x for x in a if x[0].islower())) c = sorted((x for x in a if x[0].isupper()), reverse=True) return ' '.join(b + c)
# Question Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it: * All words that begin with a lower case letter should be at the beginning of the sorted sentence...
Chef has an array A of size N. He can perform the following operation on A: Select an i (1 ≤ i ≤ N) and for all 1 ≤ j ≤ i, set A_{j} := A_{j} + 1 (i.e. add 1 to every element in the prefix of length i). Chef wants to convert A to a *palindrome* by using the above operation minimum number of times. Can you help Chef? ...
[ "for _ in range(int(input())):\n\tn = int(input())\n\tS = [int(x) for x in input().split()]\n\tdif = S[-1] - S[0]\n\tans = True\n\tfor i in range(int(n / 2)):\n\t\tif S[-i - 1] - S[i] > dif or S[-i - 1] - S[i] < 0:\n\t\t\tprint(-1)\n\t\t\tans = False\n\t\t\tbreak\n\t\tdif = S[-i - 1] - S[i]\n\tif ans:\n\t\tprint(S[...
{"inputs": ["3\n4\n4 2 2 4\n5\n5 4 3 2 1\n4\n1 2 3 4\n"], "outputs": ["0\n-1\n3\n"]}
MEDIUM
['Algorithms', 'ad-hoc', 'Constructive']
null
codechef
['Constructive algorithms', 'Ad-hoc']
[]
https://www.codechef.com/problems/ARRPAL
1 seconds
2022-10-11
0
50000 bytes
null
25,272
0
for _ in range(int(input())): n = int(input()) S = [int(x) for x in input().split()] dif = S[-1] - S[0] ans = True for i in range(int(n / 2)): if S[-i - 1] - S[i] > dif or S[-i - 1] - S[i] < 0: print(-1) ans = False break dif = S[-i - 1] - S[i] if ans: print(S[-1] - S[0])
# Question Chef has an array A of size N. He can perform the following operation on A: Select an i (1 ≤ i ≤ N) and for all 1 ≤ j ≤ i, set A_{j} := A_{j} + 1 (i.e. add 1 to every element in the prefix of length i). Chef wants to convert A to a *palindrome* by using the above operation minimum number of times. Can you ...
There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person. The people are going to dance on two kinds of songs: salsa and rumba. * When a salsa i...
[ "n = int(input())\nt = input()\nnew_pos = [0]\nnew_w = [0] * len(t)\nfor i in range(1, n + 1):\n\tith_bit = [0] * 3 ** i\n\tfor k in range(3):\n\t\tfor l in range(3 ** (i - 1)):\n\t\t\tith_bit[k * 3 ** (i - 1) + l] = k\n\tpos = new_pos\n\tw = new_w\n\tq = 0\n\talready = [0] * 3 ** i\n\tnew_w = [0] * len(t)\n\tfor j...
{"inputs": ["2\nSRRRSSSSR", "1\nRRS", "1\nSRR", "2\nRSSSSRSRR", "1\nSSR", "2\nSRSRSRSSR", "1\nRSR", "2\nSSSSSRSRR", "2\nSRSRSRSRR", "3\nRRRRSRRRSRRSRS", "2\nRSSRRSSSR", "2\nSRRRRSSSR", "2\nRRSRSRSSR", "2\nRRSRSRSRS", "3\nRSRRSRRRSRRSRR", "2\nRSSSRRSSR", "2\nRRSSRRSSR", "2\nRRSSRRSRR", "2\nRRSRRSSRR", "3\nRRRRSRRRRRRSRS...
UNKNOWN_DIFFICULTY
[]
AtCoder Grand Contest 044 - Strange Dance
atcoder
[]
[]
null
2.0 seconds
null
null
1024.0 megabytes
null
25,280
0
n = int(input()) t = input() new_pos = [0] new_w = [0] * len(t) for i in range(1, n + 1): ith_bit = [0] * 3 ** i for k in range(3): for l in range(3 ** (i - 1)): ith_bit[k * 3 ** (i - 1) + l] = k pos = new_pos w = new_w q = 0 already = [0] * 3 ** i new_w = [0] * len(t) for j in range(len(t)): mark = w[j]...
# Question There are 3^N people dancing in circle. We denote with 0,1,\dots, 3^{N}-1 the positions in the circle, starting from an arbitrary position and going around clockwise. Initially each position in the circle is occupied by one person. The people are going to dance on two kinds of songs: salsa and rumba. * Wh...
Watson gives to Sherlock a bag of numbers [1, 2, 3 ... N] and then he removes K numbers A1, A2 ... AK from the bag. He now asks Sherlock to find the P'th smallest number in the bag. Input First line contains T, the number of test cases. Each test case consists of N, K and P followed by K integers in next line denoting...
[ "t = eval(input())\nfor ____ in range(t):\n\tn, k, p = list(map(int, input().split()))\n\tl = list(map(int, input().split()))\n\tl = sorted(l)\n\tx = 1\n\tif (n - k) < p:\n\t\tprint(-1)\n\telse:\n\t\tfor i,j in enumerate(l):\n\t\t\tif p > (j - x):\n\t\t\t\tp = p - j + x\n\t\t\t\tx = j + 1\n\t\t\telse:\n\t\t\t\tbrea...
{"inputs": ["10\n1000 40 125\n13 23 46 54 81 88 93 105 160 172 254 273 296 307 380 387 507 528 604 611 645 663 672 681 718 741 745 747 748 752 772 790 802 857 858 874 893 894 939 968\n1000 500 654\n1 2 4 5 7 8 9 12 16 18 19 22 27 28 29 30 35 36 37 39 40 43 44 45 48 49 55 58 59 63 64 67 70 71 72 75 76 79 80 83 86 90 94 ...
EASY
[]
sherlock-and-numbers
hackerearth
[]
[]
null
null
null
null
null
null
25,281
0
t = eval(input()) for ____ in range(t): n, k, p = list(map(int, input().split())) l = list(map(int, input().split())) l = sorted(l) x = 1 if (n - k) < p: print(-1) else: for i,j in enumerate(l): if p > (j - x): p = p - j + x x = j + 1 else: break print(x + p - 1)
# Question Watson gives to Sherlock a bag of numbers [1, 2, 3 ... N] and then he removes K numbers A1, A2 ... AK from the bag. He now asks Sherlock to find the P'th smallest number in the bag. Input First line contains T, the number of test cases. Each test case consists of N, K and P followed by K integers in next l...
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
[ "n = int(input())\na = list(map(int, input().split()))\nb = [0] * n\nc = [0] * n\nfor i in range(n - 1):\n\tx = abs(a[i] - a[i + 1])\n\tif i % 2 == 0:\n\t\tb[i] = x\n\t\tc[i] = -x\n\telse:\n\t\tb[i] = -x\n\t\tc[i] = x\n\ndef maxSubArray(arr):\n\tbest = 0\n\tcurrent = 0\n\tfor x in arr:\n\t\tcurrent = max(0, current...
{"inputs": ["5\n1 4 2 3 1\n", "4\n1 5 4 7\n", "8\n16 14 12 10 8 100 50 0\n", "2\n1 1\n", "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -40 -15 -28 38 -40 -42 -42 7 -43 5 2 -11 10 43 9 49 -13 36 2 24 46 50 -15 -26 -6 -6 8 4 -44 -3\n", "100\n23 64 60 -45 -36 -64 -59 15 -75 69 -30 -7 -20 17 -77 58 9...
MEDIUM_HARD
['two pointers', 'dp']
null
codeforces
['Dynamic programming', 'Amortized analysis']
['Dynamic programming', 'Amortized analysis']
https://codeforces.com/problemset/problem/788/A
null
2019-12-31
null
null
null
25,264
0
n = int(input()) a = list(map(int, input().split())) b = [0] * n c = [0] * n for i in range(n - 1): x = abs(a[i] - a[i + 1]) if i % 2 == 0: b[i] = x c[i] = -x else: b[i] = -x c[i] = x def maxSubArray(arr): best = 0 current = 0 for x in arr: current = max(0, current + x) best = max(best, current) ret...
# Question Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which i...
Recently Vova found $n$ candy wrappers. He remembers that he bought $x$ candies during the first day, $2x$ candies during the second day, $4x$ candies during the third day, $\dots$, $2^{k-1} x$ candies during the $k$-th day. But there is an issue: Vova remembers neither $x$ nor $k$ but he is sure that $x$ and $k$ are p...
[ "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tk = 2\n\tj = 0\n\twhile True:\n\t\tj = 2 ** k\n\t\tif n % (j - 1) == 0:\n\t\t\tbreak\n\t\tk = k + 1\n\tprint(n // (j - 1))\n", "for _ in range(int(input())):\n\tn = int(input())\n\tans = -1\n\tv = 4\n\twhile True:\n\t\tval = v - 1\n\t\tif n % val == 0:\...
{"inputs": ["7\n3\n6\n7\n21\n28\n999999999\n999999984\n", "1\n6\n", "1\n109123\n", "1\n9823263\n", "1\n7\n", "1\n36996333\n", "1\n48391\n", "2\n6\n7\n", "3\n3\n6\n7\n", "5\n7\n21\n28\n999999999\n999999984\n", "53\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3...
EASY
['brute force', 'math']
null
codeforces
['Mathematics', 'Complete search']
['Complete search']
https://codeforces.com/problemset/problem/1343/A
1 second
2020-04-21
0
256 megabytes
null
25,099
0
t = int(input()) for i in range(t): n = int(input()) k = 2 j = 0 while True: j = 2 ** k if n % (j - 1) == 0: break k = k + 1 print(n // (j - 1))
# Question Recently Vova found $n$ candy wrappers. He remembers that he bought $x$ candies during the first day, $2x$ candies during the second day, $4x$ candies during the third day, $\dots$, $2^{k-1} x$ candies during the $k$-th day. But there is an issue: Vova remembers neither $x$ nor $k$ but he is sure that $x$ a...
Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $y$. Vlad decided to visit Nastya. However, he remembered that he h...
[ "def solve(n, k, x, y, a, graph):\n\ta.add(x)\n\ta.add(y)\n\tstack = [(x, 0)]\n\tparent = (n + 1) * [-1]\n\ty_height = None\n\twhile stack:\n\t\t(node, height) = stack.pop()\n\t\tif node == y:\n\t\t\ty_height = height\n\t\tfor child in graph[node]:\n\t\t\tif child != parent[node]:\n\t\t\t\tparent[child] = node\n\t\...
{"inputs": ["3\n\n3 1\n1 3\n2\n1 3\n1 2\n\n6 4\n3 5\n1 6 2 1\n1 3\n3 4\n3 5\n5 6\n5 2\n\n6 2\n3 2\n5 3\n1 3\n3 4\n3 5\n5 6\n5 2\n"], "outputs": ["3\n7\n2\n"]}
MEDIUM_HARD
['trees', 'dfs and similar', 'greedy', 'dp']
null
codeforces
['Tree algorithms', 'Dynamic programming', 'Graph traversal', 'Greedy algorithms']
['Dynamic programming', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1675/F
2 seconds
2022-05-05
3
256 megabytes
null
25,288
0
def solve(n, k, x, y, a, graph): a.add(x) a.add(y) stack = [(x, 0)] parent = (n + 1) * [-1] y_height = None while stack: (node, height) = stack.pop() if node == y: y_height = height for child in graph[node]: if child != parent[node]: parent[child] = node stack.append((child, height + 1)) lst ...
# Question Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $y$. Vlad decided to visit Nastya. However, he remember...
Consider the following numbers (where `n!` is `factorial(n)`): ``` u1 = (1 / 1!) * (1!) u2 = (1 / 2!) * (1! + 2!) u3 = (1 / 3!) * (1! + 2! + 3!) ... un = (1 / n!) * (1! + 2! + 3! + ... + n!) ``` Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`? Are these numbers going to `0` because of `1/n!` or to infinity du...
[ "def going(n):\n\ts = 1.0\n\tfor i in range(2, n + 1):\n\t\ts = s / i + 1\n\treturn int(s * 1000000.0) / 1000000.0\n", "def going(n):\n\tfactor = 1.0\n\tacc = 1.0\n\tfor i in range(n, 1, -1):\n\t\tfactor *= 1.0 / i\n\t\tacc += factor\n\treturn int(acc * 1000000.0) / 1000000.0\n", "def going(n):\n\ta = 1.0\n\tfo...
def going(n):
{"fn_name": "going", "inputs": [[5], [6], [7], [8], [20], [30], [50], [113], [200], [523], [1011], [10110]], "outputs": [[1.275], [1.2125], [1.173214], [1.146651], [1.052786], [1.034525], [1.020416], [1.008929], [1.005025], [1.001915], [1.00099], [1.000098]]}
EASY
['Mathematics', 'Algorithms']
null
codewars
['Mathematics']
[]
https://www.codewars.com/kata/55a29405bc7d2efaff00007c
null
null
null
null
null
25,292
0
def going(n): s = 1.0 for i in range(2, n + 1): s = s / i + 1 return int(s * 1000000.0) / 1000000.0
# Question Consider the following numbers (where `n!` is `factorial(n)`): ``` u1 = (1 / 1!) * (1!) u2 = (1 / 2!) * (1! + 2!) u3 = (1 / 3!) * (1! + 2! + 3!) ... un = (1 / n!) * (1! + 2! + 3! + ... + n!) ``` Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`? Are these numbers going to `0` because of `1/n!` or to...
You are given a secret message you need to decipher. Here are the things you need to know to decipher it: For each word: - the second and the last letter is switched (e.g. `Hello` becomes `Holle`) - the first letter is replaced by its character code (e.g. `H` becomes `72`) Note: there are no special characters used, ...
[ "def decipher_word(word):\n\ti = sum(map(str.isdigit, word))\n\tdecoded = chr(int(word[:i]))\n\tif len(word) > i + 1:\n\t\tdecoded += word[-1]\n\tif len(word) > i:\n\t\tdecoded += word[i + 1:-1] + word[i:i + 1]\n\treturn decoded\n\ndef decipher_this(string):\n\treturn ' '.join(map(decipher_word, string.split()))\n"...
def decipher_this(string):
{"fn_name": "decipher_this", "inputs": [["65 119esi 111dl 111lw 108dvei 105n 97n 111ka"], ["84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp"], ["84eh 108sse 104e 115eokp 116eh 109ero 104e 104dare"], ["87yh 99na 119e 110to 97ll 98e 108eki 116tah 119esi 111dl 98dri"], ["84kanh 121uo 80roti 102ro 97ll 121ruo 104ple"]], "...
EASY
['Strings', 'Fundamentals', 'Ciphers', 'Arrays']
null
codewars
['String algorithms', 'Fundamentals', 'Data structures']
['Data structures']
https://www.codewars.com/kata/581e014b55f2c52bb00000f8
null
null
null
null
null
25,291
0
def decipher_word(word): i = sum(map(str.isdigit, word)) decoded = chr(int(word[:i])) if len(word) > i + 1: decoded += word[-1] if len(word) > i: decoded += word[i + 1:-1] + word[i:i + 1] return decoded def decipher_this(string): return ' '.join(map(decipher_word, string.split()))
# Question You are given a secret message you need to decipher. Here are the things you need to know to decipher it: For each word: - the second and the last letter is switched (e.g. `Hello` becomes `Holle`) - the first letter is replaced by its character code (e.g. `H` becomes `72`) Note: there are no special chara...
There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows: You will pick any pizza slice. Your friend Alice will pick next slice in anti clockwise direction of your pick.  Your friend Bob will pick next slice in clockwise direction of your pick. Repeat until there are n...
[ "class Solution:\n\n\tdef maxSizeSlices(self, slices: List[int]) -> int:\n\t\t(a, b, n) = ([slices[0]], [0], len(slices))\n\t\tfor i in range(1, n):\n\t\t\ta.append(max(a[-1], slices[i]))\n\t\t\tb.append(max(b[-1], slices[i]))\n\t\tfor i in range(2, 2 * n // 3, 2):\n\t\t\t(aa, bb) = ([0] * (n - 1), [0] * n)\n\t\t\t...
class Solution: def maxSizeSlices(self, slices: List[int]) -> int:
{"fn_name": "maxSizeSlices", "inputs": [[[1, 2, 3, 4, 5, 6]]], "outputs": [10]}
MEDIUM
['Array', 'Heap (Priority Queue)', 'Dynamic Programming', 'Greedy']
null
leetcode
['Dynamic programming', 'Data structures', 'Greedy algorithms']
['Dynamic programming', 'Data structures', 'Greedy algorithms']
https://leetcode.com/problems/pizza-with-3n-slices/
null
null
null
null
null
25,283
0
class Solution: def maxSizeSlices(self, slices: List[int]) -> int: (a, b, n) = ([slices[0]], [0], len(slices)) for i in range(1, n): a.append(max(a[-1], slices[i])) b.append(max(b[-1], slices[i])) for i in range(2, 2 * n // 3, 2): (aa, bb) = ([0] * (n - 1), [0] * n) for j in range(i, n - 1): aa[...
# Question There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows: You will pick any pizza slice. Your friend Alice will pick next slice in anti clockwise direction of your pick.  Your friend Bob will pick next slice in clockwise direction of your pick. Repeat until...
The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本" for a posi...
[ "X = input()\nif int(X[-1]) in [0, 1, 6, 8]:\n\tprint('pon')\nelif int(X[-1]) in [3]:\n\tprint('bon')\nelse:\n\tprint('hon')\n", "s = input()[-1]\nif s == '3':\n\ta = 'bon'\nelif s in '0168':\n\ta = 'pon'\nelse:\n\ta = 'hon'\nprint(a)\n", "n = input()[-1]\nprint('bon' if n == '3' else 'pon' if n in '0168' else ...
{"inputs": ["16\n", "2\n", "183\n", "999\n", "1\n", "440\n", "73\n", "24\n", "438\n", "575\n", "7\n", "3\n", "31", "4", "23", "39", "49", "6", "76", "62", "12", "58", "70", "9", "8", "5", "0", "10", "15", "1", "7", "13", "11", "3", "14", "21", "22", "44", "52", "57", "-5", "-10", "151", "36", "18", "19", "26", "28", "3...
EASY
[]
AtCoder Beginner Contest 168 - ∴ (Therefore)
atcoder
[]
[]
https://atcoder.jp/contests/abc168/tasks/abc168_a
2.0 seconds
null
null
1024.0 megabytes
null
25,277
0
X = input() if int(X[-1]) in [0, 1, 6, 8]: print('pon') elif int(X[-1]) in [3]: print('bon') else: print('hon')
# Question The cat Snuke wants to play a popular Japanese game called ÅtCoder, so Iroha has decided to teach him Japanese. When counting pencils in Japanese, the counter word "本" follows the number. The pronunciation of this word varies depending on the number. Specifically, the pronunciation of "本" in the phrase "N 本...
Alex is very fond of traveling. There are n cities, labeled from 1 to n. You are also given flights, a list of travel flights as directed weighted edges flights[i] = (u_{i},v_{i},w_{i}) where u_{i }is the source node, v_{i} is the target node, and w_{i} is the price it takes for a person to travel from source to targe...
[ "import numpy as np\nfrom collections import defaultdict\nfrom collections import deque\nfrom typing import List\n\nclass Solution:\n\n\tdef minimumCost(self, flights: List[List[int]], n: int, k: int) -> int:\n\t\tg = defaultdict(list)\n\t\tfor (s, d, w) in flights:\n\t\t\tg[s].append((d, w))\n\t\tcosts = [np.inf] ...
#User function Template for python3 from typing import List class Solution: def minimumCost(self, flights: List[List[int]], n : int, k : int) -> int: # code here
{"inputs": ["n:4\nk:2\nflights size:3\nflights:[[2,1,1],[2,3,1],[3,4,1]]", "n:4 \nk:3 \nflights size:3 \nflights:[[2,1,1],[2,3,1],[3,4,1]]"], "outputs": ["2", "-1"]}
MEDIUM
['Data Structures', 'Graph']
null
geeksforgeeks
['Graph algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/alex-travelling/1
null
null
2
null
O((V+E) log V), here V is number of cities and E is number of flights.
25,293
0
import numpy as np from collections import defaultdict from collections import deque from typing import List class Solution: def minimumCost(self, flights: List[List[int]], n: int, k: int) -> int: g = defaultdict(list) for (s, d, w) in flights: g[s].append((d, w)) costs = [np.inf] * (n + 1) costs[k] = 0 ...
# Question Alex is very fond of traveling. There are n cities, labeled from 1 to n. You are also given flights, a list of travel flights as directed weighted edges flights[i] = (u_{i},v_{i},w_{i}) where u_{i }is the source node, v_{i} is the target node, and w_{i} is the price it takes for a person to travel from sou...
Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. \\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)...
[ "n = int(input())\nx = list(map(int, input().split()))\ny = list(map(int, input().split()))\nd = []\nfor i in range(n):\n\td.append(abs(x[i] - y[i]))\nprint(sum(d))\nprint(sum(list(map(lambda x: x ** 2, d))) ** (1 / 2))\nprint(sum(list(map(lambda x: x ** 3, d))) ** (1 / 3))\nprint(max(d))\n", "n = int(input())\nX...
{"inputs": ["3\n2 2 3\n2 0 4", "3\n2 2 3\n2 -1 4", "3\n2 4 5\n2 -1 4", "3\n3 4 5\n2 -1 4", "3\n6 4 5\n2 -1 4", "3\n6 5 5\n2 -1 4", "3\n6 5 5\n2 -1 3", "3\n6 5 8\n2 -1 3", "3\n6 5 8\n3 -1 3", "3\n6 7 8\n3 -1 3", "3\n6 9 8\n3 -1 3", "3\n6 9 7\n3 -1 3", "3\n6 9 7\n4 -1 3", "3\n8 9 7\n4 -1 3", "3\n16 9 7\n4 -1 3", "3\n16 9...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
134.217728 megabytes
null
25,268
0
n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) d = [] for i in range(n): d.append(abs(x[i] - y[i])) print(sum(d)) print(sum(list(map(lambda x: x ** 2, d))) ** (1 / 2)) print(sum(list(map(lambda x: x ** 3, d))) ** (1 / 3)) print(max(d))
# Question Your task is to calculate the distance between two $n$ dimensional vectors $x = \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$. The Minkowski's distance defined below is a metric which is a generalization of both the Manhattan distance and the Euclidean distance. \\[ D_{xy} = (\sum_{i=1}^n |x...
Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there would be a nu...
[ "cases = eval(input())\n\nfor i in range(cases):\n\tbase,string = input().split()\n\tbase = (int)(base)\n\tanswer = int(string,base)\n\tanswer = sum(map(int,str(answer)))\n\tprint(answer)\n", "t=eval(input())\nwhile t:\n\ta=list(map(str, input(\"\").split()))\n\tbase=int(a[0])\n\ts=a[1]\n\tk=1\n\tans=0\n\twhile l...
{"inputs": ["10\n20 4600i7952bi9g9a6ij25fdh457h116f082adg4b31b1g5d3hggg6i1cebhbbd89f55b5ab720fa6fb6abe7h54f5j97070hbbf0hc6673ceie7a61g09a0baab47ciadeh9gjcc8j28eef0gjeb58a1410d39a03a93a8bc2heg0g97gc505jd62005fjf0gc63ed30dh08a3254f709a5ac4jbdf21g0c51e68di3b3gbci182c25250jb97jh5cihh8934h0d9i618fc80565ej49811f786812i4c51c0...
UNKNOWN_DIFFICULTY
[]
dummy-2
hackerearth
[]
[]
null
null
null
null
null
null
25,294
0
cases = eval(input()) for i in range(cases): base,string = input().split() base = (int)(base) answer = int(string,base) answer = sum(map(int,str(answer))) print(answer)
# Question Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites to T of her friends. Along with each of those e-invites there w...
Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: Input: N = 5...
[ "class Solution:\n\n\tdef countTriplets(self, Arr, N, L, R):\n\t\tArr.sort()\n\t\tn = len(Arr)\n\t\ta = 0\n\t\tb = 0\n\t\tfor i in range(n - 2):\n\t\t\tj = i + 1\n\t\t\tk = n - 1\n\t\t\twhile j < k:\n\t\t\t\tif Arr[i] + Arr[j] + Arr[k] <= R:\n\t\t\t\t\ta += k - j\n\t\t\t\t\tj += 1\n\t\t\t\telse:\n\t\t\t\t\tk -= 1\n...
#User function Template for python3 class Solution: def countTriplets(self, Arr, N, L, R): # code here
{"inputs": ["N = 4\nArr = {8 , 3, 5, 2}\nL = 7, R = 11", "N = 5\nArr = {5, 1, 4, 3, 2}\nL = 2, R = 7"], "outputs": ["1", "2"]}
MEDIUM
['Algorithms', 'Sorting']
null
geeksforgeeks
['Sorting']
['Sorting']
https://practice.geeksforgeeks.org/problems/triplets-with-sum-with-given-range/1
null
null
0
null
O(N^{2})
25,290
0
class Solution: def countTriplets(self, Arr, N, L, R): Arr.sort() n = len(Arr) a = 0 b = 0 for i in range(n - 2): j = i + 1 k = n - 1 while j < k: if Arr[i] + Arr[j] + Arr[k] <= R: a += k - j j += 1 else: k -= 1 for i in range(n - 2): j = i + 1 k = n - 1 while j < ...
# Question Given an array Arr[] of N distinct integers and a range from L to R, the task is to count the number of triplets having a sum in the range [L, R]. Example 1: Input: N = 4 Arr = {8 , 3, 5, 2} L = 7, R = 11 Output: 1 Explaination: There is only one triplet {2, 3, 5} having sum 10 in range [7, 11]. Example 2: ...
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. The type of i-th query is represented by T_i. * T_i=1: You are given two integers X_i,V_i. Replace the value of A_{X_i} with V_i. * T_i=2: You are given two integers L_i,R_i. Calculate the maximum value among A_{L_i},...
[ "class segtree:\n\tsta = -1\n\tfunc = max\n\n\tdef __init__(self, n):\n\t\tself.n = n\n\t\tself.size = 1 << n.bit_length()\n\t\tself.tree = [self.sta] * (2 * self.size)\n\n\tdef build(self, list):\n\t\tfor (i, x) in enumerate(list, self.size):\n\t\t\tself.tree[i] = x\n\t\tfor i in range(self.size - 1, 0, -1):\n\t\t...
{"inputs": ["5 5\n1 2 3 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "5 3\n1 2 3 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "5 1\n1 2 3 2 1\n2 0 5\n3 2 3\n1 1 2\n2 2 4\n3 1 0", "5 5\n1 2 1 2 1\n2 1 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "8 3\n1 2 3 2 1\n2 0 5\n3 2 3\n1 3 1\n2 2 4\n3 1 0", "5 3\n1 2 0 2 1\n2 0 5\n3 2 3\n1 1 2\n2 2 4...
UNKNOWN_DIFFICULTY
[]
AtCoder Library Practice Contest - Segment Tree
atcoder
[]
[]
null
5.0 seconds
null
null
1024.0 megabytes
null
25,287
0
class segtree: sta = -1 func = max def __init__(self, n): self.n = n self.size = 1 << n.bit_length() self.tree = [self.sta] * (2 * self.size) def build(self, list): for (i, x) in enumerate(list, self.size): self.tree[i] = x for i in range(self.size - 1, 0, -1): self.tree[i] = self.func(self.tree[i...
# Question You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. The type of i-th query is represented by T_i. * T_i=1: You are given two integers X_i,V_i. Replace the value of A_{X_i} with V_i. * T_i=2: You are given two integers L_i,R_i. Calculate the maximum value am...
Raghu wants to design a converter such that when a user inputs a binary number it gets converted to Octal number & also the correspond alphabet to it. Example- if a user inputs- 10101101 then the output is 255 BEE Note : for decimal places there should be a space between the alphabetic signs Ex- for input 1011011011...
[ "import sys\nbin=input();\n\nif \".\" in bin:\n\tbdot,adot=bin.split(\".\")\nelse:\n\tbdot=bin\n\tadot=\"\"\n\nbdot=bdot.lstrip(\"0\")\nadot=adot.rstrip(\"0\")\n\nbaddz= 3 - (len(bdot)%3)\naaddz= 3 - (len(adot)%3)\n\nif(baddz==3):\n\tbaddz=0\n\t\nif(aaddz==3):\n\taaddz=0\n\t\nfor i in range(baddz):\n\tbdot='0'+bdot...
{"inputs": ["10011010.001111", "101101101110.111", "111111101.1011", "10101101"], "outputs": ["775.54 GGE ED", "232.17 BCB AG", "5556.7 EEEF G", "255 BEE"]}
UNKNOWN_DIFFICULTY
[]
converter
hackerearth
[]
[]
null
null
null
null
null
null
25,298
0
import sys bin=input(); if "." in bin: bdot,adot=bin.split(".") else: bdot=bin adot="" bdot=bdot.lstrip("0") adot=adot.rstrip("0") baddz= 3 - (len(bdot)%3) aaddz= 3 - (len(adot)%3) if(baddz==3): baddz=0 if(aaddz==3): aaddz=0 for i in range(baddz): bdot='0'+bdot for i in range(aaddz): adot=adot+'0' oc...
# Question Raghu wants to design a converter such that when a user inputs a binary number it gets converted to Octal number & also the correspond alphabet to it. Example- if a user inputs- 10101101 then the output is 255 BEE Note : for decimal places there should be a space between the alphabetic signs Ex- for input...
You are given a string $s$. You have to determine whether it is possible to build the string $s$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order. For example: aaaabbb can be built as aa $+$ aa $+$ bbb; bbaaaaabbb can be ...
[ "def solve(s):\n\tans = 'YES'\n\tarr = []\n\tcurr = 0\n\tlast = s[0]\n\tfor i in s:\n\t\tif last == i:\n\t\t\tcurr += 1\n\t\telse:\n\t\t\tarr.append(curr)\n\t\t\tcurr = 1\n\t\t\tlast = i\n\tarr.append(curr)\n\tfor i in arr:\n\t\tif i < 2:\n\t\t\treturn 'NO'\n\treturn 'YES'\nt = int(input())\ncases = []\nfor i in ra...
{"inputs": ["8\naaaabbb\nbbaaaaabbb\naaaaaa\nabab\na\nb\naaaab\nbbaaa\n", "1\nabababababababababababababababababababababababab\n"], "outputs": ["YES\nYES\nYES\nNO\nNO\nNO\nNO\nYES\n", "NO\n"]}
EASY
['implementation']
null
codeforces
['Implementation']
[]
https://codeforces.com/problemset/problem/1671/A
2 seconds
2022-04-22
0
512 megabytes
null
25,282
0
def solve(s): ans = 'YES' arr = [] curr = 0 last = s[0] for i in s: if last == i: curr += 1 else: arr.append(curr) curr = 1 last = i arr.append(curr) for i in arr: if i < 2: return 'NO' return 'YES' t = int(input()) cases = [] for i in range(t): cases.append(input()) ans = [] for case in c...
# Question You are given a string $s$. You have to determine whether it is possible to build the string $s$ out of strings aa, aaa, bb and/or bbb by concatenating them. You can use the strings aa, aaa, bb and/or bbb any number of times and in any order. For example: aaaabbb can be built as aa $+$ aa $+$ bbb; bbaaaa...
Read problem statements in [Hindi],[Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. As usual, I went to work in the morning. Unfortunately, I found out that my manager bought a new machine and I have to learn to operate it. There are $N$ boxes in a line (numbered $1$ through $N$). Initially, the bo...
[ "t = int(input())\nfor i in range(t):\n\tn = int(input())\n\tl = list(map(int, input().split()))\n\tans = 0\n\ts = 0\n\twhile len(l) > 0:\n\t\td = min(l)\n\t\tans = ans + (d - s) * len(l)\n\t\ts = d\n\t\tl = l[:l.index(d)]\n\tprint(ans)\n", "for _ in range(int(input())):\n\tn = int(input())\n\ta = list(map(int, i...
{"inputs": ["1\n3\n2 1 3"], "outputs": ["4"]}
MEDIUM
['Algorithms', 'Constructive', '1D Arrays', 'ad-hoc', 'Data Structures', 'Arrays']
null
codechef
['Constructive algorithms', 'Data structures', 'Ad-hoc']
['Data structures']
https://www.codechef.com/problems/STUPMACH
1 seconds
2019-12-26
0
50000 bytes
null
25,296
0
t = int(input()) for i in range(t): n = int(input()) l = list(map(int, input().split())) ans = 0 s = 0 while len(l) > 0: d = min(l) ans = ans + (d - s) * len(l) s = d l = l[:l.index(d)] print(ans)
# Question Read problem statements in [Hindi],[Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. As usual, I went to work in the morning. Unfortunately, I found out that my manager bought a new machine and I have to learn to operate it. There are $N$ boxes in a line (numbered $1$ through $N$). Initi...
Given a circular linked list, your task is to complete the method printList() that prints the linked list. Input: The printList function takes a single argument as input the reference pointer to the head of the linked list. There are multiple test cases and for each test, the function will be called separately. Output...
[ "class Node:\n\n\tdef __init__(self, data):\n\t\tself.data = data\n\t\tself.next = None\n\nclass CircularLinkedList:\n\n\tdef __init__(self):\n\t\tself.head = None\n\n\tdef push(self, data):\n\t\tptr1 = Node(data)\n\t\tptr1.data = data\n\t\ttemp = self.head\n\t\tptr1.next = self.head\n\t\tif self.head is not None:\...
class Node: # Constructor to create a new node def __init__(self, data): self.data = data self.next = None class CircularLinkedList: # Constructor to create a empty circular linked list def __init__(self): self.head = None # Function ...
{"inputs": ["2\r\n7\r\n374 363 171 497 282 306 426\r\n2\r\n162 231"], "outputs": ["426 306 282 497 171 363 374\n231 162"]}
EASY
['circular-linked-list']
null
geeksforgeeks
['Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/circular-linked-list-traversal/1
null
null
0
null
25,302
0
class Node: def __init__(self, data): self.data = data self.next = None class CircularLinkedList: def __init__(self): self.head = None def push(self, data): ptr1 = Node(data) ptr1.data = data temp = self.head ptr1.next = self.head if self.head is not None: while temp.next != self.head: tem...
# Question Given a circular linked list, your task is to complete the method printList() that prints the linked list. Input: The printList function takes a single argument as input the reference pointer to the head of the linked list. There are multiple test cases and for each test, the function will be called separat...
Given a palindromic number N in the form of string. The task is to find the smallest palindromic number greater than N using the same set of digits as in N. Example 1: Input: N = "35453" Output: 53435 Explanation: Next higher palindromic number is 53435. Example 2: Input: N = "33" Output: -1 Explanation: Next higher...
[ "class Solution:\n\n\tdef nextPalin(self, N):\n\t\tn = len(N) // 2\n\t\tns = [int(N[n - 1])]\n\t\ti = n - 2\n\t\twhile i >= 0:\n\t\t\tnn = int(N[i])\n\t\t\tmns = max(ns)\n\t\t\tif nn < mns:\n\t\t\t\trn = min(nn + 1, mns)\n\t\t\t\twhile rn not in ns:\n\t\t\t\t\trn += 1\n\t\t\t\tif rn > mns:\n\t\t\t\t\trn = mns\n\t\t...
#User function Template for python3 class Solution: def nextPalin(self,N): #code here
{"inputs": ["N = \"35453\"", "N = \"33\""], "outputs": ["53435", "-1"]}
MEDIUM
['Data Structures', 'Strings', 'palindrome', 'Numbers']
null
geeksforgeeks
['String algorithms', 'Data structures', 'Mathematics']
['Data structures']
https://practice.geeksforgeeks.org/problems/next-higher-palindromic-number-using-the-same-set-of-digits5859/1
null
null
0
null
O(|N|log|N|)
25,297
0
class Solution: def nextPalin(self, N): n = len(N) // 2 ns = [int(N[n - 1])] i = n - 2 while i >= 0: nn = int(N[i]) mns = max(ns) if nn < mns: rn = min(nn + 1, mns) while rn not in ns: rn += 1 if rn > mns: rn = mns ns.remove(rn) ns.append(nn) ns.sort() rs = str(r...
# Question Given a palindromic number N in the form of string. The task is to find the smallest palindromic number greater than N using the same set of digits as in N. Example 1: Input: N = "35453" Output: 53435 Explanation: Next higher palindromic number is 53435. Example 2: Input: N = "33" Output: -1 Explanation:...
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any number of t...
[ "for i in range(int(input())):\n\t(n, x) = map(int, input().split())\n\tarr = list(map(int, input().split()))\n\tcount = 0\n\tfor i in range(n):\n\t\tif sorted(arr) == arr:\n\t\t\tbreak\n\t\tif arr[i] > x:\n\t\t\t(x, arr[i]) = (arr[i], x)\n\t\t\tcount += 1\n\tprint(count) if sorted(arr) == arr else print(-1)\n", ...
{"inputs": ["6\n4 1\n2 3 5 4\n5 6\n1 1 3 4 4\n1 10\n2\n2 10\n11 9\n2 10\n12 11\n5 18\n81 324 218 413 324\n", "3\n5 15\n5 15 8 10 10\n6 5\n2 3 15 4 15 7\n8 7\n12 14 9 7 15 14 8 3\n", "3\n5 15\n5 15 8 10 10\n6 5\n2 3 15 4 15 7\n8 7\n12 14 9 7 15 14 8 3\n", "3\n5 15\n5 15 8 10 10\n6 3\n2 3 15 4 15 7\n8 7\n12 14 9 7 15 14 ...
MEDIUM_HARD
['greedy', 'sortings', 'dp']
null
codeforces
['Dynamic programming', 'Sorting', 'Greedy algorithms']
['Dynamic programming', 'Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1455/D
1.5 seconds
2020-11-30
0
512 megabytes
null
25,286
0
for i in range(int(input())): (n, x) = map(int, input().split()) arr = list(map(int, input().split())) count = 0 for i in range(n): if sorted(arr) == arr: break if arr[i] > x: (x, arr[i]) = (arr[i], x) count += 1 print(count) if sorted(arr) == arr else print(-1)
# Question You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds). To make the sequence sorted, you may perform the following operation any...
[Image] It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in t...
[ "import os\nfrom io import BytesIO\ninput = BytesIO(os.read(0, os.fstat(0).st_size)).readline\n(n, k) = map(int, input().split())\ng = [x - 65 for x in input()]\ne = [-1] * 26\nfor i in range(n):\n\te[g[i]] = i\ncurS = 0\nmet = [0] * 26\nfor i in range(n):\n\tif not met[g[i]]:\n\t\tcurS += 1\n\t\tmet[g[i]] = 1\n\ti...
{"inputs": ["5 1\nAABBB\n", "5 1\nABABB\n", "26 1\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n", "27 1\nABCDEFGHIJKLMNOPQRSTUVWXYZA\n", "5 2\nABACA\n", "6 2\nABCABC\n", "8 3\nABCBCDCA\n", "73 2\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD\n", "44 15\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA\n", "41 1...
EASY
['data structures', 'implementation']
null
codeforces
['Data structures', 'Implementation']
['Data structures']
https://codeforces.com/problemset/problem/834/B
null
2019-12-31
null
null
null
25,295
0
import os from io import BytesIO input = BytesIO(os.read(0, os.fstat(0).st_size)).readline (n, k) = map(int, input().split()) g = [x - 65 for x in input()] e = [-1] * 26 for i in range(n): e[g[i]] = i curS = 0 met = [0] * 26 for i in range(n): if not met[g[i]]: curS += 1 met[g[i]] = 1 if curS > k: print('YES')...
# Question [Image] It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause ...
Given an array A[ ] of positive integers of size N, where each value represents the number of chocolates in a packet. Each packet can have a variable number of chocolates. There are M students, the task is to distribute chocolate packets among M students such that : 1. Each student gets exactly one packet. 2. The diffe...
[ "class Solution:\n\n\tdef findMinDiff(self, arr, n, m):\n\t\tif m == 0 or n == 0:\n\t\t\treturn 0\n\t\tarr.sort()\n\t\tif n < m:\n\t\t\treturn -1\n\t\tmin_diff = arr[n - 1] - arr[0]\n\t\tfor i in range(len(arr) - m + 1):\n\t\t\tmin_diff = min(min_diff, arr[i + m - 1] - arr[i])\n\t\treturn min_diff\n", "class Solu...
#User function Template for python3 class Solution: def findMinDiff(self, A,N,M): # code here
{"inputs": ["N = 8, M = 5\nA = {3, 4, 1, 9, 56, 7, 9, 12}", "N = 7, M = 3\nA = {7, 3, 2, 4, 9, 12, 56}"], "outputs": ["6", "2"]}
EASY
['Algorithms', 'Sorting']
null
geeksforgeeks
['Sorting']
['Sorting']
https://practice.geeksforgeeks.org/problems/chocolate-distribution-problem3825/1
null
null
0
null
O(N*Log(N))
25,301
0
class Solution: def findMinDiff(self, arr, n, m): if m == 0 or n == 0: return 0 arr.sort() if n < m: return -1 min_diff = arr[n - 1] - arr[0] for i in range(len(arr) - m + 1): min_diff = min(min_diff, arr[i + m - 1] - arr[i]) return min_diff
# Question Given an array A[ ] of positive integers of size N, where each value represents the number of chocolates in a packet. Each packet can have a variable number of chocolates. There are M students, the task is to distribute chocolate packets among M students such that : 1. Each student gets exactly one packet. ...
Write a function that returns the number of '2's in the factorization of a number. For example, ```python two_count(24) ``` should return 3, since the factorization of 24 is 2^3 x 3 ```python two_count(17280) ``` should return 7, since the factorization of 17280 is 2^7 x 5 x 3^3 The number passed to two_count (twoC...
[ "def two_count(n):\n\tres = 0\n\twhile not n & 1:\n\t\tres += 1\n\t\tn >>= 1\n\treturn res\n", "def two_count(n):\n\treturn bin(n)[::-1].index('1')\n", "def two_count(n):\n\treturn n.bit_length() - len(bin(n).rstrip('0')) + 2\n", "def two_count(n):\n\ti = 0\n\twhile True:\n\t\t(n, r) = divmod(n, 2)\n\t\tif r:...
def two_count(n):
{"fn_name": "two_count", "inputs": [[24], [17280], [222222222222], [256], [1], [2], [482848428248882482], [7], [7777777777777777], [84934656]], "outputs": [[3], [7], [1], [8], [0], [1], [1], [0], [0], [20]]}
EASY
['Algorithms']
null
codewars
[]
[]
https://www.codewars.com/kata/56aed5db9d5cb55de000001c
null
null
null
null
null
25,323
0
def two_count(n): res = 0 while not n & 1: res += 1 n >>= 1 return res
# Question Write a function that returns the number of '2's in the factorization of a number. For example, ```python two_count(24) ``` should return 3, since the factorization of 24 is 2^3 x 3 ```python two_count(17280) ``` should return 7, since the factorization of 17280 is 2^7 x 5 x 3^3 The number passed to two...
Our hacker, Little Stuart lately has been fascinated by ancient puzzles. One day going through some really old books he finds something scribbled on the corner of a page. Now Little Stuart believes that the scribbled text is more mysterious than it originally looks, so he decides to find every occurrence of all the per...
[ "n = int(input())\ni=0\nresult = []\nwhile i < n:\n\tpattern=input()\n\ttext=input()\n\treversetext =text[::-1]\n\tif pattern in text or pattern in reversetext:\n\t\tresult.append('YES')\n\telse:\n\t\tresult.append('NO')\n\ti=i+1\nfor te in result:\n\tprint(te)\n\t\n", "from itertools import permutations\nn = int...
{"inputs": ["100\nphqghumeaylnlfdxfircvscxggbwkfnqduxwfnfozvsrtkjprepggxrpnrvystmwcysyycqpevikeffmznimkkasvwsrenzkycxf\nxtlsgypsfadpooefxzbcoejuvpvaboygpoeylfpbnpljvrvipyamyehwqnqrqpmxujjloovaowuxwhmsncbxcoksfzkvatxdknlyjyhfixjswnkkufnuxxzrzbmnmgqooketlyhnkoaugzqrcddiuteiojwayyzpvscmpsajlfvgubfaaovlzylntrkdcpwsrtesjwhd...
MEDIUM
['Algorithms', 'Ad-Hoc']
a-needle-in-the-haystack-1
hackerearth
['Ad-hoc']
[]
null
null
null
null
null
null
25,305
0
n = int(input()) i=0 result = [] while i < n: pattern=input() text=input() reversetext =text[::-1] if pattern in text or pattern in reversetext: result.append('YES') else: result.append('NO') i=i+1 for te in result: print(te)
# Question Our hacker, Little Stuart lately has been fascinated by ancient puzzles. One day going through some really old books he finds something scribbled on the corner of a page. Now Little Stuart believes that the scribbled text is more mysterious than it originally looks, so he decides to find every occurrence of...
Given a string containing multiple words, count the characters in each word and display them. Example 1: Input: S = "the quick brown fox" Output: 3 5 5 3 Explanation: "the" has 3 characters "quick" has 5 characters "brown" has 5 characters "fox" has 3 characters ​Example 2: Input: S = "geeks for geeks" Output: ...
[ "class Solution:\n\n\tdef countChars(self, s):\n\t\treturn [len(i) for i in s.split()]\n", "class Solution:\n\n\tdef countChars(self, s):\n\t\tcount = 0\n\t\tlp = []\n\t\tfor i in s:\n\t\t\tif i != ' ':\n\t\t\t\tcount += 1\n\t\t\telif i == ' ':\n\t\t\t\tlp.append(count)\n\t\t\t\tcount = 0\n\t\tlp.append(count)\n\...
#User function Template for python3 class Solution: def countChars(self,s): # code here
{"inputs": ["S = \"the quick brown fox\"", "S = \"geeks for geeks\""], "outputs": ["3 5 5 3", "5 3 5"]}
EASY
['Data Structures', 'Strings']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/count-the-characters-in-each-word-in-a-given-sentence3451/1
null
null
0
null
O(|S|).
25,309
0
class Solution: def countChars(self, s): return [len(i) for i in s.split()]
# Question Given a string containing multiple words, count the characters in each word and display them. Example 1: Input: S = "the quick brown fox" Output: 3 5 5 3 Explanation: "the" has 3 characters "quick" has 5 characters "brown" has 5 characters "fox" has 3 characters ​Example 2: Input: S = "geeks for gee...
Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array. Example 1: Input: Arr = {25, 10, 2, 8, 5, 3} Output: 28 Explanation: The maximum result is 5 ^ 25 = 28. Example 2: Input : Arr = {1, 2, 3, 4, 5, 6, 7} Output : 7 Explanation : The maximum result i...
[ "from math import log\n\nclass Solution:\n\n\tdef max_xor(self, arr, n):\n\t\ttry:\n\t\t\tl = int(log(max(arr), 2))\n\t\texcept:\n\t\t\tl = 1\n\t\t(mask, res) = (0, 0)\n\t\tfor i in range(l, -1, -1):\n\t\t\tmask |= 1 << i\n\t\t\tS = set((mask & num for num in arr))\n\t\t\ttemp = res | 1 << i\n\t\t\tfor num in S:\n\...
#User function Template for python3 class Solution: def max_xor(self, arr, n): #code here
{"inputs": ["Arr = {25, 10, 2, 8, 5, 3}", "Arr = {1, 2, 3, 4, 5, 6, 7}"], "outputs": ["28", "7"]}
MEDIUM
['Data Structures', 'Bit Magic']
null
geeksforgeeks
['Bit manipulation', 'Data structures']
['Bit manipulation', 'Data structures']
https://practice.geeksforgeeks.org/problems/maximum-xor-of-two-numbers-in-an-array/1
null
null
0
null
O(NlogN)
25,308
0
from math import log class Solution: def max_xor(self, arr, n): try: l = int(log(max(arr), 2)) except: l = 1 (mask, res) = (0, 0) for i in range(l, -1, -1): mask |= 1 << i S = set((mask & num for num in arr)) temp = res | 1 << i for num in S: if num ^ temp in S: res = temp bre...
# Question Given an array of non-negative integers of size N. Find the maximum possible XOR between two numbers present in the array. Example 1: Input: Arr = {25, 10, 2, 8, 5, 3} Output: 28 Explanation: The maximum result is 5 ^ 25 = 28. Example 2: Input : Arr = {1, 2, 3, 4, 5, 6, 7} Output : 7 Explanation : The maxi...
# Task A common way for prisoners to communicate secret messages with each other is to encrypt them. One such encryption algorithm goes as follows. You take the message and place it inside an `nx6` matrix (adjust the number of rows depending on the message length) going from top left to bottom right (one row at a ti...
[ "def six_column_encryption(msg):\n\tmsg = msg.replace(' ', '.') + '.' * ((6 - len(msg) % 6) % 6)\n\treturn ' '.join((msg[n::6] for n in range(6)))\n", "from itertools import zip_longest\n\ndef six_column_encryption(msg, size=6):\n\tmsg = msg.replace(' ', '.')\n\tL = [msg[i:i + size] for i in range(0, len(msg), si...
def six_column_encryption(msg):
{"fn_name": "six_column_encryption", "inputs": [["Attack at noon or we are done for"], ["Let's kill them all"], ["Meet me behind the kitchen tomorrow at seven in the evening"]], "outputs": [["A.ow.f tanedo tt..or a.oan. cnrre. ko.e.."], ["Lkhl eie. tlm. 'l.. s.a. .tl."], ["Men.eoaete e.dknrtnhn eb.i.r..ei tetttosi.n .h...
EASY
['Puzzles']
null
codewars
['Ad-hoc']
[]
https://www.codewars.com/kata/58a65945fd7051d5e1000041
null
null
null
null
null
25,311
0
def six_column_encryption(msg): msg = msg.replace(' ', '.') + '.' * ((6 - len(msg) % 6) % 6) return ' '.join((msg[n::6] for n in range(6)))
# Question # Task A common way for prisoners to communicate secret messages with each other is to encrypt them. One such encryption algorithm goes as follows. You take the message and place it inside an `nx6` matrix (adjust the number of rows depending on the message length) going from top left to bottom right (one...
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
[ "(n, m, k) = [int(s) for s in input().split()]\nBuyingPrice = []\nSellingPrice = []\nNumber_of_items = []\nfor i in range(n):\n\tinput()\n\tx = []\n\ty = []\n\tz = []\n\tfor j in range(m):\n\t\t(a, b, c) = [int(s) for s in input().split()]\n\t\tx.append(a)\n\t\ty.append(b)\n\t\tz.append(c)\n\tBuyingPrice.append(x)\...
{"inputs": ["2 2 1\nQwe\n900 800 1\n5 1 1\nEwq\n1000 999 0\n11 10 0\n", "3 2 11\nMars\n15 10 4\n7 6 3\nSnickers\n20 17 2\n10 8 0\nBounty\n21 18 5\n9 7 3\n", "2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopqrstu\n19 16 20\n12 7 14\n", "2 1 1\nIeyxawsao\n2 1 0\nJhmsvvy\n2 1 0\n", "3 1 5\nTomato\n10 7 20\nBanana\n13 11 0\nApp...
EASY
['greedy', 'sortings']
null
codeforces
['Sorting', 'Greedy algorithms']
['Sorting', 'Greedy algorithms']
https://codeforces.com/problemset/problem/176/A
2.0 seconds
null
null
256.0 megabytes
null
25,312
0
(n, m, k) = [int(s) for s in input().split()] BuyingPrice = [] SellingPrice = [] Number_of_items = [] for i in range(n): input() x = [] y = [] z = [] for j in range(m): (a, b, c) = [int(s) for s in input().split()] x.append(a) y.append(b) z.append(c) BuyingPrice.append(x) SellingPrice.append(y) Number_o...
# Question To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying an...
Given an interger array arr[] of size n and an interger k.In one operation, you can choose an index i where 0<i Return the maximum frequency of an element after using atmost k Increment operations. Example 1: Input: n=3 arr[] = {2,2,4},k=4 Output: 3 Explanation: Apply two operations on index 0 and two operations on i...
[ "class Solution:\n\n\tdef maxFrequency(self, arr, n, k):\n\t\tarr.sort()\n\t\tleft = 0\n\t\t(res, total) = (0, 0)\n\t\tfor right in range(len(arr)):\n\t\t\ttotal += arr[right]\n\t\t\twhile arr[right] * (right - left + 1) > total + k:\n\t\t\t\ttotal -= arr[left]\n\t\t\t\tleft += 1\n\t\t\tres = max(res, right - left ...
#User function Template for python3 class Solution: def maxFrequency(self, arr, n, k): # Code here
{"inputs": ["\r\nn=3\r\narr[] = {2,2,4},k=4\r\n", "\r\nn=4\r\narr[] = {7,7,7,7},k=5\r\n"], "outputs": [" 3\r\n", " 4\r\n"]}
MEDIUM
[]
null
geeksforgeeks
[]
[]
https://practice.geeksforgeeks.org/problems/maximum-frequency-1662528911/1
null
null
0
null
O(nlogn).
25,314
0
class Solution: def maxFrequency(self, arr, n, k): arr.sort() left = 0 (res, total) = (0, 0) for right in range(len(arr)): total += arr[right] while arr[right] * (right - left + 1) > total + k: total -= arr[left] left += 1 res = max(res, right - left + 1) return res
# Question Given an interger array arr[] of size n and an interger k.In one operation, you can choose an index i where 0<i Return the maximum frequency of an element after using atmost k Increment operations. Example 1: Input: n=3 arr[] = {2,2,4},k=4 Output: 3 Explanation: Apply two operations on index 0 and two ope...
Steve Jobs' ghost has come down to BITS Pilani Hyderabad Campus, since he has heard a lot about the coding culture here. Hoping to recruit talented people to work on top-secret Apple software, he keeps a strict coding test. Apple is currently working on a upgraded version of a automated form filler. They call it the i...
[ "'''\n# Read input from stdin and provide input before running code\n\nname = raw_input('What is your name?\\n')\nprint 'Hi, %s.' % name\n'''\nw = input()\nleastLen = 10000000\nn = eval(input())\ntemp = w\nwhile n:\n\tn -= 1\n\ta = input()\n\tif len(a) <= leastLen and a[:len(w)] == w:\n\t\tif len(a) == len(w):\n\t\...
{"inputs": ["find\n4\nfind\nfindfirstof\nfindit\nfand", "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "dzwzyj\n7\nwvixktp\ndzwzyjuhn\ndzwzyjqrbd\ndzwzyji\ndzwzyjyfys\ndzwzyjrcb\nxptb", "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "msjnqudojxtzvpc\n2\nvlxclsvqbucmbrkwwtoxek\nmsjnqudojxtzvpcldwjyystsxrtexfhllzhnkidmh...
UNKNOWN_DIFFICULTY
[]
problem-1-8
hackerearth
[]
[]
null
null
null
null
null
null
25,313
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' w = input() leastLen = 10000000 n = eval(input()) temp = w while n: n -= 1 a = input() if len(a) <= leastLen and a[:len(w)] == w: if len(a) == len(w): temp = a break te...
# Question Steve Jobs' ghost has come down to BITS Pilani Hyderabad Campus, since he has heard a lot about the coding culture here. Hoping to recruit talented people to work on top-secret Apple software, he keeps a strict coding test. Apple is currently working on a upgraded version of a automated form filler. They c...
Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is number of dig...
[ "arr=[6,2,5,5,4,5,6,3,7,6]\nfor _ in range(eval(input())):\n\ta=list(input())\n\ttemp=0\n\n\tfor item in a:\n\t\ttemp=temp+arr[int(item)]\n\t\t\n\tprint(temp) \n", "t=int(eval(input()))\nwhile t>0:\n\ts=input()\n\tn=0\n\tfor i in range(len(s)):\n\t\tif s[i]=='0':\n\t\t\tn=n+6\n\t\telif s[i]=='1':\n\t\t\tn=n+2\n\t...
{"inputs": ["50\n67535629\n270936\n62618\n92023759\n289\n36129319\n7\n4503610\n32061\n54\n65693745\n5474430\n86884314\n20689266\n9504871\n27\n26106\n59\n90917\n11\n9776\n36\n639481\n93908\n50963\n561\n59\n4\n10304\n44763\n7596\n1\n857418\n9753\n831\n9\n4\n3386\n4\n889\n764303\n925\n59469\n247\n5481\n8936802\n51108506\n...
UNKNOWN_DIFFICULTY
['BruteForce']
mystery-11
hackerearth
['Complete search']
['Complete search']
null
null
null
null
null
null
25,317
0
arr=[6,2,5,5,4,5,6,3,7,6] for _ in range(eval(input())): a=list(input()) temp=0 for item in a: temp=temp+arr[int(item)] print(temp)
# Question Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case in new line. Constraints : 1 ≤ T ≤ 1000 0 ≤ |N| ≤ 1000 |N| is n...
Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with **the mi...
[ "def shortest_arrang(n):\n\tif n % 2 == 1:\n\t\treturn [n // 2 + 1, n // 2]\n\tfor i in range(3, n // 2):\n\t\tif i % 2 == 1 and n % i == 0:\n\t\t\treturn list(range(n // i + i // 2, n // i - i // 2 - 1, -1))\n\t\telif i % 2 == 0 and n % i == i // 2:\n\t\t\treturn list(range(n // i + i // 2, n // i - i // 2, -1))\n...
def shortest_arrang(n):
{"fn_name": "shortest_arrang", "inputs": [[10], [14], [16], [22], [65]], "outputs": [[[4, 3, 2, 1]], [[5, 4, 3, 2]], [[-1]], [[7, 6, 5, 4]], [[33, 32]]]}
EASY
['Data Structures', 'Arrays', 'Fundamentals', 'Mathematics']
null
codewars
['Fundamentals', 'Data structures', 'Mathematics']
['Data structures']
https://www.codewars.com/kata/59321f29a010d5aa80000066
null
null
null
null
null
25,318
0
def shortest_arrang(n): if n % 2 == 1: return [n // 2 + 1, n // 2] for i in range(3, n // 2): if i % 2 == 1 and n % i == 0: return list(range(n // i + i // 2, n // i - i // 2 - 1, -1)) elif i % 2 == 0 and n % i == i // 2: return list(range(n // i + i // 2, n // i - i // 2, -1)) return [-1]
# Question Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement w...
Bitville is a seaside city that has a number of shopping centers connected by bidirectional roads, each of which has a travel time associated with it. Each of the shopping centers may have a fishmonger who sells one or more kinds of fish. Two cats, Big Cat and Little Cat, are at shopping center $\mbox{1}$ (each of th...
[ "from heapq import *\nfrom itertools import *\nfrom sys import stderr\n\ndef main():\n\t(nvert, nedge, setsize) = readints()\n\tvertexhas = []\n\tfor _ in range(nvert):\n\t\t(nelts, *elts) = readints()\n\t\tassert nelts == len(elts)\n\t\tvertexhas.append(sum((1 << elt - 1 for elt in elts)))\n\tedgelist = [readints(...
{"inputs": ["5 5 5\n1 1\n1 2\n1 3\n1 4\n1 5\n1 2 10\n1 3 10\n2 4 10\n3 5 10\n4 5 10\n"], "outputs": ["30\n"]}
MEDIUM
['Algorithms - Graph Theory']
null
hackerrank
['Graph algorithms']
[]
https://www.hackerrank.com/challenges/synchronous-shopping/problem
null
null
2
null
null
25,316
0
from heapq import * from itertools import * from sys import stderr def main(): (nvert, nedge, setsize) = readints() vertexhas = [] for _ in range(nvert): (nelts, *elts) = readints() assert nelts == len(elts) vertexhas.append(sum((1 << elt - 1 for elt in elts))) edgelist = [readints() for _ in range(nedge)] ...
# Question Bitville is a seaside city that has a number of shopping centers connected by bidirectional roads, each of which has a travel time associated with it. Each of the shopping centers may have a fishmonger who sells one or more kinds of fish. Two cats, Big Cat and Little Cat, are at shopping center $\mbox{1}$...
Gotham city is in danger. All the people from Gotham were airlifted and they are going to be dropped at different districts of a new safe city. There are $N$ districts located at position $(1, 2, \ldots, N)$ in a straight line in this newly built safe city. An array(P) is given which tells us about the maximum capacit...
[ "n = int(input())\nls = list(map(int, input().split()))\nq = int(input())\nred = [0] * n\nfor x in range(n - 1):\n\tred[x] = x + 1\nred[-1] = -1\nfor _ in range(q):\n\tlk = list(map(int, input().split()))\n\tpos = lk[0]\n\tpeo = lk[1]\n\tdis = 0\n\ttmp = pos\n\ti = pos - 1\n\ttodo = []\n\twhile i < n:\n\t\tif peo >...
{"inputs": ["4\n5 5 6 1\n2\n2 11\n2 3\n"], "outputs": ["6\n2\n"]}
HARD
['Data Structures', 'Sets']
null
codechef
['Data structures']
['Data structures']
https://www.codechef.com/problems/GOTHAM
1 seconds
2021-04-06
0
50000 bytes
null
25,315
0
n = int(input()) ls = list(map(int, input().split())) q = int(input()) red = [0] * n for x in range(n - 1): red[x] = x + 1 red[-1] = -1 for _ in range(q): lk = list(map(int, input().split())) pos = lk[0] peo = lk[1] dis = 0 tmp = pos i = pos - 1 todo = [] while i < n: if peo >= ls[i]: dis += ls[i] * (i - ...
# Question Gotham city is in danger. All the people from Gotham were airlifted and they are going to be dropped at different districts of a new safe city. There are $N$ districts located at position $(1, 2, \ldots, N)$ in a straight line in this newly built safe city. An array(P) is given which tells us about the max...
Alice guesses the strings that Bob made for her. At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ and offers Alice the string $b$ so that she can guess the string $a$. Bob b...
[ "for _ in range(int(input())):\n\tb = list(input())\n\ta = [b[0]]\n\tn = len(b)\n\ti = 1\n\twhile i < n:\n\t\ta.append(b[i])\n\t\ti += 2\n\tprint(*a, sep='')\n", "t = int(input())\nfor i in range(t):\n\ts = input()\n\tns = s[0]\n\tfor j in range(1, len(s), 2):\n\t\tns += s[j]\n\tprint(ns)\n", "n = int(input())\...
{"inputs": ["4\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n", "1\nassaad\n", "6\nabbaac\nabbaac\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n", "1\nsaallaammddookkhhj\n", "11\nabbaac\nabbaac\nabbaac\nabbaac\nabbaac\nabbaac\nabbaac\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\n", "10\nabbaac\nac\nbccddaaf\nzzzzzzzzzz\nabbaac\nac\nbccddaaf\nzzzzzzzzz...
EASY
['strings', 'implementation']
null
codeforces
['String algorithms', 'Implementation']
[]
https://codeforces.com/problemset/problem/1367/A
2 seconds
2020-06-16
0
256 megabytes
null
25,168
0
for _ in range(int(input())): b = list(input()) a = [b[0]] n = len(b) i = 1 while i < n: a.append(b[i]) i += 2 print(*a, sep='')
# Question Alice guesses the strings that Bob made for her. At first, Bob came up with the secret string $a$ consisting of lowercase English letters. The string $a$ has a length of $2$ or more characters. Then, from string $a$ he builds a new string $b$ and offers Alice the string $b$ so that she can guess the string...
You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed ...
[ "def get_perms(perm):\n\tperms = {tuple(perm)}\n\tfor i in range(len(perm)):\n\t\tfor j in range(i + 1, len(perm)):\n\t\t\tperm_copy = list(perm)\n\t\t\t(perm_copy[i], perm_copy[j]) = (perm_copy[j], perm_copy[i])\n\t\t\tperms.add(tuple(perm_copy))\n\treturn perms\n(n, m) = list(map(int, input().split(' ')))\ngood_p...
{"inputs": ["2 4\n1 3 2 4\n1 3 4 2\n", "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3\n", "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5\n", "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10\n", "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 ...
MEDIUM
['brute force', 'greedy', 'math', 'implementation']
null
codeforces
['Mathematics', 'Complete search', 'Implementation', 'Greedy algorithms']
['Complete search', 'Greedy algorithms']
https://codeforces.com/problemset/problem/724/B
null
2019-12-31
null
null
null
25,320
0
def get_perms(perm): perms = {tuple(perm)} for i in range(len(perm)): for j in range(i + 1, len(perm)): perm_copy = list(perm) (perm_copy[i], perm_copy[j]) = (perm_copy[j], perm_copy[i]) perms.add(tuple(perm_copy)) return perms (n, m) = list(map(int, input().split(' '))) good_perms = get_perms([i for i in...
# Question You are given a table consisting of n rows and m columns. Numbers in each row form a permutation of integers from 1 to m. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you ...
You have an array $a_1, a_2, \dots, a_n$. Let's call some subarray $a_l, a_{l + 1}, \dots , a_r$ of this array a subpermutation if it contains all integers from $1$ to $r-l+1$ exactly once. For example, array $a = [2, 2, 1, 3, 2, 3, 1]$ contains $6$ subarrays which are subpermutations: $[a_2 \dots a_3]$, $[a_2 \dots ...
[ "import math\nmod = int(1000000007)\ni = lambda : map(int, input().split())\nn = int(input())\na = [int(x) for x in input().split()]\nt = [[0] * 21 for i in range(300005)]\nfor i in range(n):\n\tt[i][0] = a[i]\n\ndef build(n):\n\tfor j in range(1, 20):\n\t\tfor i in range(n):\n\t\t\tif i + (1 << j) - 1 > n - 1:\n\t...
{"inputs": ["8\n2 4 1 3 4 2 1 2\n", "5\n1 1 2 1 2\n", "98\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 ...
VERY_HARD
['data structures', 'math', 'hashing', 'brute force', 'divide and conquer']
null
codeforces
['String algorithms', 'Complete search', 'Divide and conquer', 'Mathematics', 'Data structures']
['Data structures', 'Complete search']
https://codeforces.com/problemset/problem/1175/F
null
2019-12-31
null
null
null
25,325
0
import math mod = int(1000000007) i = lambda : map(int, input().split()) n = int(input()) a = [int(x) for x in input().split()] t = [[0] * 21 for i in range(300005)] for i in range(n): t[i][0] = a[i] def build(n): for j in range(1, 20): for i in range(n): if i + (1 << j) - 1 > n - 1: break t[i][j] = max(...
# Question You have an array $a_1, a_2, \dots, a_n$. Let's call some subarray $a_l, a_{l + 1}, \dots , a_r$ of this array a subpermutation if it contains all integers from $1$ to $r-l+1$ exactly once. For example, array $a = [2, 2, 1, 3, 2, 3, 1]$ contains $6$ subarrays which are subpermutations: $[a_2 \dots a_3]$, ...
Given two integers N and K, the task is to find the count of palindromic strings of length lesser than or equal to N, with first K characters of lowercase English language, such that each character in a string doesn’t appear more than twice. Note: Anwer can be very large, so, output answer modulo 10^{9}+7 Example 1: In...
[ "def rec(N, K, dp):\n\tif N == 0:\n\t\treturn 1\n\tif K == 0:\n\t\treturn 0\n\tif N == 1:\n\t\treturn K\n\tdp[N][K] = rec(N - 2, K - 1, dp) * K\n\treturn dp[N][K]\n\nclass Solution:\n\n\tdef palindromicStrings(self, N, K):\n\t\tmod = int(1000000000.0 + 7)\n\t\tdp = [[0 for i in range(K + 1)] for j in range(N + 1)]\...
#User function Template for python3 class Solution: def palindromicStrings(self, N, K ): # code here
{"inputs": ["N = 3, K = 2", "N = 4, K = 3"], "outputs": ["6", "18"]}
MEDIUM
['Algorithms', 'Mathematical', 'Combinatorial', 'Strings', 'Data Structures', 'Dynamic Programming']
null
geeksforgeeks
['String algorithms', 'Combinatorics', 'Dynamic programming', 'Mathematics', 'Data structures']
['Dynamic programming', 'Data structures']
https://practice.geeksforgeeks.org/problems/number-of-palindromic-strings2706/1
null
null
0
null
O(K^{2})
25,326
0
def rec(N, K, dp): if N == 0: return 1 if K == 0: return 0 if N == 1: return K dp[N][K] = rec(N - 2, K - 1, dp) * K return dp[N][K] class Solution: def palindromicStrings(self, N, K): mod = int(1000000000.0 + 7) dp = [[0 for i in range(K + 1)] for j in range(N + 1)] c = 0 for i in range(1, N + 1):...
# Question Given two integers N and K, the task is to find the count of palindromic strings of length lesser than or equal to N, with first K characters of lowercase English language, such that each character in a string doesn’t appear more than twice. Note: Anwer can be very large, so, output answer modulo 10^{9}+7 E...
Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ```
[ "def solution(value):\n\treturn 'Value is %05d' % value\n", "solution = 'Value is {:05d}'.format\n", "def solution(value):\n\tnum = 5 - len(str(value))\n\tzeros = ''\n\tfor i in range(num):\n\t\tzeros += '0'\n\treturn 'Value is {}'.format(zeros + str(value))\n", "def solution(value):\n\treturn f'Value is {val...
def solution(value):
{"fn_name": "solution", "inputs": [], "outputs": []}
EASY
['Strings', 'Fundamentals']
null
codewars
['String algorithms', 'Fundamentals']
[]
https://www.codewars.com/kata/51c89385ee245d7ddf000001
null
null
null
null
null
25,324
0
def solution(value): return 'Value is %05d' % value
# Question Complete the solution so that it returns a formatted string. The return value should equal "Value is VALUE" where value is a 5 digit padded number. Example: ```python solution(5) # should return "Value is 00005" ``` # Solution ```python def solution(value): return 'Value is %05d' % value ```