problem_id int64 0 4.75k | question stringlengths 146 5.9k | solutions stringlengths 181 1.12M | input_output stringlengths 236 35.4M | difficulty stringclasses 3
values | url stringlengths 47 54 | starter_code stringclasses 158
values | num_tests int64 16 16 |
|---|---|---|---|---|---|---|---|
4,424 | # Task
* **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()`
* In other words , **_try every combination of a,b,c with [*+()] , and return the Maximum Obtained_**
___
# Consider an Example :
**_With the numbe... | ["def expression_matter(a, b, c):\n return max(a*b*c, a+b+c, (a+b)*c, a*(b+c))", "def expression_matter(a, b, c):\n return max(a + b + c, (a + b) * c, a * (b + c), a * b * c)", "def expression_matter(a, b, c):\n cases = [a + b + c]\n cases.append(a * b * c)\n cases.append((a * b) + c)\n cases.append(... | {"fn_name": "expression_matter", "inputs": [["1", "1", "1"], ["1", "2", "3"], ["1", "3", "1"], ["2", "2", "2"], ["5", "1", "3"], ["3", "5", "7"], ["5", "6", "1"], ["2", "6", "1"], ["6", "7", "1"], ["2", "10", "3"], ["1", "8", "3"], ["9", "7", "2"], ["1", "1", "10"], ["9", "1", "1"], ["10", "5", "6"], ["1", "10", "1"]],... | introductory | https://www.codewars.com/kata/5ae62fcf252e66d44d00008e |
def expression_matter(a, b, c):
| 16 |
4,433 | Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50.
Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) and [XOR](https://en.wikipedia.org/wiki... | ["import operator\nfrom functools import reduce\n\nOPS = {\n \"AND\": operator.and_,\n \"OR\" : operator.or_,\n \"XOR\": operator.xor\n}\n\ndef logical_calc(array, op):\n return reduce(OPS[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nOPERATOR = {'AND': and_, 'OR': or... | {"fn_name": "logical_calc", "inputs": [[[true, true, true, false], "AND"], [[true, true, true, false], "OR"], [[true, true, false, false], "XOR"], [[true, false, false, false], "AND"], [[true, false, false, false], "XOR"], [[true, true], "AND"], [[true, true], "OR"], [[true, true], "XOR"], [[false, false], "AND"], [[fa... | introductory | https://www.codewars.com/kata/57096af70dad013aa200007b |
def logical_calc(array, op):
| 16 |
4,440 | ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but **exactly** 4 digits or exactly 6 digits.
If the function is passed a valid PIN string, return `true`, else return `false`.
## Examples
```
"1234" --> true
"12345" --> false
"a234" --> false
``` | ["def validate_pin(pin):\n return len(pin) in (4, 6) and pin.isdigit()", "def validate_pin(pin):\n return len(pin) in [4, 6] and pin.isdigit()\n", "validate_pin = lambda pin: len(pin) in (4, 6) and pin.isdigit()", "def merge(array1,array2):\n array3 = []\n i = 0\n j = 0\n while (i < len(array1) and j ... | {"fn_name": "validate_pin", "inputs": [["1"], ["12"], ["123"], ["12345"], ["1234567"], ["-12345"], ["1.234"], ["00000000"], ["a234"], [".234"], ["1234"], ["1111"], ["123456"], ["098765"], ["000000"], ["090909"]], "outputs": [[false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [true... | introductory | https://www.codewars.com/kata/55f8a9c06c018a0d6e000132 |
def validate_pin(pin):
| 16 |
4,453 | # Summary:
Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number.
# Description:
A `step` is defined as either:
- Adding 1 to the number: `num += 1`
- Doubling the number: `num *= 2`
You will always start from the number `1` and you will have to return the s... | ["def shortest_steps_to_num(num):\n steps = 0\n \n while num != 1:\n if num % 2:\n num -= 1\n else:\n num //= 2\n \n steps += 1\n \n return steps", "def shortest_steps_to_num(num):\n return num.bit_length() + bin(num).count('1') - 2", "def shortest_ste... | {"fn_name": "shortest_steps_to_num", "inputs": [["2"], ["4"], ["8"], ["9"], ["30"], ["40"], ["11"], ["59"], ["65"], ["2763"], ["2673"], ["4578"], ["7280"], ["4998"], ["1233"], ["5672"]], "outputs": [["1"], ["2"], ["3"], ["4"], ["7"], ["6"], ["5"], ["9"], ["7"], ["17"], ["16"], ["17"], ["17"], ["17"], ["14"], ["16"]]} | introductory | https://www.codewars.com/kata/5cd4aec6abc7260028dcd942 |
def shortest_steps_to_num(num):
| 16 |
4,457 | Have you heard about Megamind? Megamind and Metro Man are two aliens who came to earth. Megamind wanted to destroy the earth, while Metro Man wanted to stop him and protect mankind. After a lot of fighting, Megamind finally threw Metro Man up into the sky. Metro Man was defeated and was never seen again. Megamind wante... | ["from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n if dps*shots >= hp: return ceil(hp / dps)\n if dps*shots <= regen: return -1\n\n number_of_regenerations = ceil((hp - dps*shots) / (dps*shots - regen))\n return ceil((hp + regen*number_of_regenerations) / dps)", "from math import ceil\n\ndef... | {"fn_name": "mega_mind", "inputs": [["12", "4", "3", "2"], ["9", "4", "2", "7"], ["13", "4", "3", "1"], ["13", "4", "3", "50"], ["36", "4", "3", "2"], ["15", "4", "3", "12"], ["100000", "99999", "100000", "100000"], ["100000", "100000", "100000", "100000"], ["100000", "1", "50000", "49999"], ["100000", "1", "1000", "99... | introductory | https://www.codewars.com/kata/5baf21542d15ec9453000147 |
def mega_mind(hp, dps, shots, regen):
| 16 |
4,469 | A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below.
Ex: 153, where n = 3 (number of digits in 153)
1^(3) + 5^(3) + 3^(3) = 153
Write a method is_narcissistic(i) (in Haskell: isNarcissistic ... | ["def is_narcissistic(n):\n num = str(n)\n length = len(num)\n return sum(int(a) ** length for a in num) == n\n", "def is_narcissistic(i):\n return sum([int(n)**len(str(i)) for n in str(i)])==i", "def is_narcissistic(n):\n t = str(n)\n l = len(t)\n \n return n == sum(int(d) ** l for d in t)", "is_narcis... | {"fn_name": "is_narcissistic", "inputs": [["153"], ["1634"], ["8208"], ["9474"], ["92727"], ["93084"], ["1741725"], ["4210818"], ["9800817"], ["9926315"], ["24678050"], ["146511208"], ["472335975"], ["534494836"], ["912985153"], ["115132219018763992565095597973971522401"]], "outputs": [[true], [true], [true], [true], [... | introductory | https://www.codewars.com/kata/56b22765e1007b79f2000079 |
def is_narcissistic(i):
| 16 |
4,473 | In this Kata you are a game developer and have programmed the #1 MMORPG(Massively Multiplayer Online Role Playing Game) worldwide!!! Many suggestions came across you to make the game better, one of which you are interested in and will start working on at once.
Players in the game have levels from 1 to 170, XP(short fo... | ["def xp_to_target_lvl(*args):\n if len(args) < 2:\n return 'Input is invalid.'\n \n current_xp, target_lvl = args\n \n if not isinstance(target_lvl, int):\n return 'Input is invalid.'\n \n if not (0 < target_lvl < 171):\n return 'Input is invalid.'\n \n if current_xp... | {"fn_name": "xp_to_target_lvl", "inputs": [["0", "5"], ["12345", "17"], ["313", "2"], ["832696988485", "170"], ["769832696988484", "170"], ["10395", "11"], ["31428", "47"], ["1", "171"], ["7392984749", "900"], ["123", "0"], ["-987654321", "99"], ["999999", ["101"]], ["10396", "11"], ["0", "1"], ["2017", "4"], ["7698326... | introductory | https://www.codewars.com/kata/593dbaccdf1adef94100006c |
def xp_to_target_lvl(current_xp=None, target_lvl=None):
| 16 |
4,495 | I've got a crazy mental illness.
I dislike numbers a lot. But it's a little complicated:
The number I'm afraid of depends on which day of the week it is...
This is a concrete description of my mental illness:
Monday --> 12
Tuesday --> numbers greater than 95
Wednesday --> 34
Thursday --> 0
Friday -->... | ["def am_I_afraid(day,num):\n return {\n 'Monday': num == 12,\n 'Tuesday': num > 95,\n 'Wednesday': num == 34,\n 'Thursday': num == 0,\n 'Friday': num % 2 == 0,\n 'Saturday': num == 56,\n 'Sunday': num == 666 or num == -666,\n }[day]\n", "afraid = {\n 'Monday'... | {"fn_name": "am_I_afraid", "inputs": [["Monday", "13"], ["Monday", "12"], ["Tuesday", "0"], ["Tuesday", "100"], ["Tuesday", "95"], ["Wednesday", "35"], ["Wednesday", "34"], ["Thursday", "2"], ["Thursday", "0"], ["Friday", "5"], ["Friday", "4"], ["Saturday", "55"], ["Saturday", "56"], ["Sunday", "55"], ["Sunday", "666"]... | introductory | https://www.codewars.com/kata/55b1fd84a24ad00b32000075 |
def am_I_afraid(day,num):
| 16 |
4,509 | Your task is to validate rhythm with a meter.
_________________________________________________
Rules:
1. Rhythmic division requires that in one whole note (1) there are two half notes (2) or four quarter notes (4) or eight eighth notes (8).
Examples: 1 = 2 + 2, 1 = 4 + 4 + 4 + 4 ...
Note that: 2 = 4 + 4, 4 = 8 + 8... | ["def is_valid_bar(bar, meter):\n total = 0\n for n in bar:\n n = int(n)\n if n & (n - 1):\n return False\n total += 1.0 / n\n return total == meter\n\ndef validate_rhythm(meter, score):\n n, d = meter\n if d & (d - 1):\n return \"Invalid rhythm\"\n bars = score.... | {"fn_name": "validate_rhythm", "inputs": [[["8", "8"], "1|22|4444|88888888"], [["4", "4"], "1|22|4444|88888888"], [["2", "2"], "1|22|4444|88888888"], [["3", "4"], "24|444|888888"], [["4", "8"], "2|44|8888"], [["1", "2"], "2|44|8888"], [["6", "4"], "222|444444|884884884"], [["1", "1"], "1"], [["5", "8"], "888|448|82|88"... | introductory | https://www.codewars.com/kata/57091b473f1008c03f001a2a |
def validate_rhythm(meter, score):
| 16 |
4,516 | Make a program that takes a value (x) and returns "Bang" if the number is divisible by 3, "Boom" if it is divisible by 5, "BangBoom" if it divisible by 3 and 5, and "Miss" if it isn't divisible by any of them.
Note: Your program should only return one value
Ex: Input: 105 --> Output: "BangBoom"
Ex: Input: 9 --> Output... | ["def multiple(x):\n return 'Bang' * (x % 3 == 0) + 'Boom' * (x % 5 == 0) or 'Miss'", "def multiple(x):\n if x % 15 == 0: return \"BangBoom\"\n if x % 5 == 0: return \"Boom\"\n if x % 3 == 0: return \"Bang\"\n return \"Miss\"", "def multiple(x):\n val = ''\n if x % 3 == 0:\n val += 'Bang'\n ... | {"fn_name": "multiple", "inputs": [["3"], ["98"], ["65"], ["23"], ["15"], ["4"], ["2"], ["45"], ["90"], ["21"], ["7"], ["6"], ["10003823"], ["712"], ["985"], ["164523"]], "outputs": [["Bang"], ["Miss"], ["Boom"], ["Miss"], ["BangBoom"], ["Miss"], ["Miss"], ["BangBoom"], ["BangBoom"], ["Bang"], ["Miss"], ["Bang"], ["Mis... | introductory | https://www.codewars.com/kata/55a8a36703fe4c45ed00005b |
def multiple(x):
| 16 |
4,518 | Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1.
Examples:
"Wally" => 0
"Where's Wally" => 8
"Where's Waldo" => -1
"DWally Wallyd .Wally" => -... | ["from re import compile\n\ndef wheres_wally(string):\n m = compile('(^|.*[\\s])(Wally)([\\.,\\s\\']|$)').match(string)\n return m.start(2) if m else -1", "import re\n\ndef wheres_wally(string):\n return next((m.start() for m in re.finditer(r'((?<= )W|^W)ally\\b', string)), -1)", "from re import search\ndef wh... | {"fn_name": "wheres_wally", "inputs": [[""], ["wAlly"], ["DWally"], [".Wally"], ["Wallyd"], ["wally mollyWally Wallybrolly 'Wally"], ["Walley ,Wally -Wally ;Wally +Wally :Wally"], ["Walley Wally, Wally- Wally: Wally+ Wally:"], ["12Wally Wally01 W.ally"], ["Where's Waldo"], ["Wally Wally"], ["Where's Wally"], ["Hi Wally... | introductory | https://www.codewars.com/kata/55f91a98db47502cfc00001b |
def wheres_wally(string):
| 16 |
4,521 | Vasya wants to climb up a stair of certain amount of steps (Input parameter 1). There are 2 simple rules that he has to stick to.
1. Vasya can climb 1 or 2 steps at each move.
2. Vasya wants the number of moves to be a multiple of a certain integer. (Input parameter 2).
### Task:
What is the `MINIMAL` number of moves... | ["def numberOfSteps(steps, m):\n if (steps < m):\n return -1\n \n \n if (steps % 2 == 0 and (steps / 2) % m == 0):\n return (steps / 2)\n \n \n return (steps / 2) + m - ((steps / 2) % m)\n", "def numberOfSteps(steps, m):\n return next((n for n in range((steps+1)//2, steps+1) if n % m =... | {"fn_name": "numberOfSteps", "inputs": [["10", "2"], ["3", "5"], ["29", "7"], ["2", "2"], ["1", "2"], ["10000", "3"], ["10000", "10"], ["9999", "3"], ["9999", "2"], ["9999", "10"], ["9999", "9"], ["18", "10"], ["19", "10"], ["20", "10"], ["4608", "5"], ["5", "2"]], "outputs": [["6"], ["-1"], ["21"], ["2"], ["-1"], ["50... | introductory | https://www.codewars.com/kata/55251c0d2142d7b4ab000aef |
def numberOfSteps(steps, m):
| 16 |
4,523 | In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit sum.
solve(10) = 9
solve(48) = 48. Note that 39 is also an option, ... | ["def solve(n):\n x = str(n)\n res = [x] + [str(int(x[:i]) - 1) + '9' * (len(x) - i) for i in range(1, len(x))]\n return int(max(res, key=lambda x: (sum(map(int, x)), int(x))))", "def dig_sum(n):\n return sum(map(int, str(n)))\n\ndef solve(n):\n candidates = [n] + [ n // 10**i * 10**i - 1 for i in range(... | {"fn_name": "solve", "inputs": [["79320"], ["99004"], ["99088"], ["99737"], ["29652"], ["100"], ["2"], ["39188"], ["10"], ["999999999992"], ["19930"], ["110"], ["1199"], ["120"], ["18"], ["72694"]], "outputs": [["78999"], ["98999"], ["98999"], ["98999"], ["28999"], ["99"], ["2"], ["38999"], ["9"], ["999999999989"], ["1... | introductory | https://www.codewars.com/kata/5b162ed4c8c47ea2f5000023 |
def solve(n):
| 16 |
4,572 | Given a string (`str`) containing a base-10 integer between `0` and `10000`, convert the integer to its binary representation. At that point, obtain a count of the maximum amount of consecutive 0s. From there, return the count in written form with a capital letter.
In the very first example, we have an argument of `"9... | ["import re\nls = [\"Zero\",\"One\",\"Two\",\"Three\",\"Four\",\"Five\",\"Six\",\"Seven\",\"Eight\",\"Nine\",\"Ten\",\"Eleven\",\"Twelve\",\"Thirteen\"]\ndef max_consec_zeros(n):\n return ls[max(map(lambda x:len(x),re.findall(r'0*',bin(int(n))[2:])))]", "import re\n\ndef max_consec_zeros(n):\n return 'zero one tw... | {"fn_name": "max_consec_zeros", "inputs": [["33"], ["77"], ["160"], ["180"], ["256"], ["992"], ["1024"], ["2017"], ["2048"], ["3050"], ["4096"], ["6144"], ["6656"], ["7188"], ["8192"], ["9999"]], "outputs": [["Four"], ["Two"], ["Five"], ["Two"], ["Eight"], ["Five"], ["Ten"], ["Four"], ["Eleven"], ["One"], ["Twelve"], [... | introductory | https://www.codewars.com/kata/59decdf40863c76ae3000080 |
def max_consec_zeros(n):
| 16 |
4,590 | Create an OR function, without use of the 'or' keyword, that takes an list of boolean values and runs OR against all of them.
Assume there will be between 1 and 6 variables, and return None for an empty list. | ["def alt_or(lst):\n return any(lst) if lst else None", "def alt_or(lst): return bool(sum(lst)) if lst else None", "def alt_or(a):\n return any(a) if a else None ", "def alt_or(lst):\n return eval(str(lst).replace(',', '|'))[0] if lst else None", "def alt_or(a):\n if a: return any(a)", "def alt_or(lst):\n ... | {"fn_name": "alt_or", "inputs": [[[false, false, false, false, false, false]], [[false, false, false, true, false, true]], [[false, false, true, true, true, false]], [[false, true, true, false, false, false]], [[false, true, true, false, true, false]], [[true, false, true, false, true, true]], [[true, true, true, false... | introductory | https://www.codewars.com/kata/58f625e20290fb29c3000056 |
def alt_or(lst):
| 16 |
4,611 | #Description
Everybody has probably heard of the animal heads and legs problem from the earlier years at school. It goes:
```βA farm contains chickens and cows. There are x heads and y legs. How many chickens and cows are there?β ```
Where x <= 1000 and y <=1000
#Task
Assuming there are no other types of animals, ... | ["def animals(heads, legs):\n chickens, cows = 2*heads-legs/2, legs/2-heads\n if chickens < 0 or cows < 0 or not chickens == int(chickens) or not cows == int(cows):\n return \"No solutions\"\n return chickens, cows", "def animals(heads, legs):\n chickens = heads * 2 - legs / 2\n cows = heads - chi... | {"fn_name": "animals", "inputs": [["72", "200"], ["116", "282"], ["12", "24"], ["6", "24"], ["344", "872"], ["158", "616"], ["25", "555"], ["12", "25"], ["54", "956"], ["5455", "54956"], ["0", "0"], ["-1", "-1"], ["500", "0"], ["0", "500"], ["-45", "5"], ["5", "-55"]], "outputs": [[["44", "28"]], [["91", "25"]], [["12"... | introductory | https://www.codewars.com/kata/574c5075d27783851800169e |
def animals(heads, legs):
| 16 |
4,636 | ---
# Hint
This Kata is an extension of the earlier ones in this series. Completing those first will make this task easier.
# Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type words...
# Keyboard
The screen "keyboard" la... | ["H, W = 6, 8\nKEYBOARD = [ \"abcde123fghij456klmno789pqrst.@0uvwxyz_/\\u000e \",\n \"ABCDE123FGHIJ456KLMNO789PQRST.@0UVWXYZ_/\\u000e \",\n \"^~?!'\\\"()-:;+&%*=<>\u20ac\u00a3$\u00a5\u00a4\\\\[]{},.@\u00a7#\u00bf\u00a1\\u000e\\u000e\\u000e_/\\u000e \"]\nMAP = [ {c: (i//W, i%W) for i,c i... | {"fn_name": "tv_remote", "inputs": [["your"], ["work"], ["Β£theseΒ£"], ["A/A/A/A/"], ["MISSISSIPPI"], ["^"], ["^,@/_"], ["mΒ‘$$Β‘$$Β‘ppΒ‘"], ["Your"], ["Xoo ooo ooo"], ["ooX ooo ooo"], ["ooo ooo Xoo"], ["ooo ooo ooX"], ["Pack My Box With Five Dozen Liquor Jugs."], [" "], [" x X "]], "outputs": [["21"], ["18"], ["57... | introductory | https://www.codewars.com/kata/5b3077019212cbf803000057 |
def tv_remote(words):
| 16 |
4,643 | You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`.
A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also return false.
Please also keep in mind that a valid post code **cann... | ["def zipvalidate(postcode):\n return len(postcode) == 6 and postcode.isdigit() and postcode[0] not in \"05789\"", "import re\n\ndef zipvalidate(postcode):\n return bool(re.fullmatch(r\"[12346]\\d{5}\", postcode))", "def zipvalidate(p):\n return p.isdigit() and 100000 < int(p) < 699999 and p[0] != \"5\"\n \... | {"fn_name": "zipvalidate", "inputs": [["142784"], ["642784"], ["111"], ["1111111"], ["AA5590"], [""], ["\n245980"], ["245980\n"], ["245980a"], [" 310587 "], ["555555"], ["775255"], ["875555"], ["012345"], ["968345"], ["@68345"]], "outputs": [[true], [true], [false], [false], [false], [false], [false], [false], [false],... | introductory | https://www.codewars.com/kata/552e45cc30b0dbd01100001a |
def zipvalidate(postcode):
| 16 |
4,645 | > If you've finished this kata, you can try the [more difficult version](https://www.codewars.com/kata/5b256145a454c8a6990000b5).
## Taking a walk
A promenade is a way of uniquely representing a fraction by a succession of βleft or rightβ choices.
For example, the promenade `"LRLL"` represents the fraction `4/7`.
... | ["def promenade(choices):\n \n def compute(): return l+r,m+s\n \n l,m, r,s = 1,0, 0,1\n for c in choices:\n if c=='L': l,m = compute()\n else: r,s = compute()\n \n return compute()", "def promenade(choices):\n l, m = (1, 0)\n r, s = (0, 1)\n for choice in choices:\n ... | {"fn_name": "promenade", "inputs": [[""], ["L"], ["R"], ["LRLL"], ["LLRLR"], ["RRRLRRR"], ["LLLLLLLLLL"], ["RLRLRLRRLRLL"], ["LLRRLRRLRLLL"], ["LRRLLRLLRLRR"], ["LLLRRRLLLRLL"], ["RRLRRRLLRLRR"], ["RRRRLLRLLRLR"], ["LLRLRLLRLLRL"], ["LRLLRRRRLLRR"], ["RLRRLRRRRRRR"]], "outputs": [[["1", "1"]], [["1", "2"]], [["2", "1"]... | introductory | https://www.codewars.com/kata/5b254b2225c2bb99c500008d |
def promenade(choices):
| 16 |
4,660 | 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 return 0<=(now_hour-start_hour)%24<(end_hour-start_hour)%24\n", "def can_i_play(now_hour, start_hour, end_hour):\n if start_hour < end_hour:\n return start_hour <= now_hour < end_hour\n return start_hour <= now_hour or now_hour < end_hour\n", "def ca... | {"fn_name": "can_i_play", "inputs": [["9", "10", "11"], ["12", "12", "13"], ["13", "10", "15"], ["14", "9", "14"], ["20", "21", "1"], ["21", "21", "6"], ["17", "15", "3"], ["0", "22", "1"], ["1", "22", "1"], ["3", "23", "2"], ["20", "0", "23"], ["9", "20", "11"], ["23", "23", "0"], ["0", "20", "23"], ["4", "0", "3"], [... | introductory | https://www.codewars.com/kata/59ca888aaeb284bb8f0000aa |
def can_i_play(now_hour, start_hour, end_hour):
| 16 |
4,672 | In this Kata, you will create a function that converts a string with letters and numbers to the inverse of that string (with regards to Alpha and Numeric characters). So, e.g. the letter `a` will become `1` and number `1` will become `a`; `z` will become `26` and `26` will become `z`.
Example: `"a25bz"` would become `... | ["import re\ndef AlphaNum_NumAlpha(string):\n return re.sub( r'[0-9]{1,2}|[a-z]', lambda x:str(ord(x.group() )-96) if x.group().isalpha() else chr(int(x.group())+96) , string)\n \n #\\w\n", "import re\nfrom string import ascii_lowercase\n\ndef repl(m):\n x = m.group()\n if x.isdigit():\n return a... | {"fn_name": "AlphaNum_NumAlpha", "inputs": [["25abcd26"], ["18zyz14"], ["a1b2c3d4"], ["5a8p17"], ["w6aa4ct24m5"], ["17dh"], ["18zzz14"], ["y17kg5et11"], ["h15q4pc6yw23nmx19y"], ["p16k11o25x7m6m20ct9"], ["4n3fk22en17ekve"], ["iwantamemewar"], ["7h15cc9s23l11k10sd5"], ["13"], ["7k7k7sg3jvh16d"], ["youaredonegoodforyou"]]... | introductory | https://www.codewars.com/kata/5995ceb5d4280d07f6000822 |
def AlphaNum_NumAlpha(string):
| 16 |
4,674 | To participate in a prize draw each one gives his/her firstname.
Each letter of a firstname
has a value which is its rank in the English alphabet. `A` and `a` have rank `1`, `B` and `b` rank `2` and so on.
The *length* of the firstname is added to the *sum* of these ranks hence a number `som`.
An array of random ... | ["def rank(st, we, n):\n if not st:\n return \"No participants\"\n \n if n>len(we):\n return \"Not enough participants\"\n\n name_score = lambda name,w: w*(len(name)+sum([ord(c.lower())-96for c in name]))\n \n scores= [name_score(s,we[i]) for i,s in enumerate(st.split(','))]\n \n s... | {"fn_name": "rank", "inputs": [["Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin", ["4", "2", "1", "4", "3", "1", "2"], "4"], ["Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", ["1", "3", "5", "5", "3", "6"], "2"], ["Lagon,Lily", ["1", "5"], "2"], ["Elijah,Michael,Avery,Sophia,Samantha", ["2", "1", "5", "2", "2"], "3"... | introductory | https://www.codewars.com/kata/5616868c81a0f281e500005c |
def rank(st, we, n):
| 16 |
4,735 | #### Task:
Your job here is to write a function (`keepOrder` in JS/CoffeeScript, `keep_order` in Ruby/Crystal/Python, `keeporder` in Julia), which takes a sorted array `ary` and a value `val`, and returns the lowest index where you could insert `val` to maintain the sorted-ness of the array. The input array will alway... | ["from bisect import bisect_left as keep_order", "from bisect import bisect_left\n\ndef keep_order(arr, val):\n return bisect_left(arr, val)", "def keep_order(ary, val):\n for i, x in enumerate(ary):\n if x >= val:\n return i\n return len(ary)", "def keep_order(arr, val):\n for i in range(... | {"fn_name": "keep_order", "inputs": [[["1", "2", "3", "4", "7"], "5"], [["1", "2", "3", "4", "7"], "0"], [["1", "1", "2", "2", "2"], "2"], [["1", "2", "3", "4"], "5"], [["1", "2", "3", "4"], "-1"], [["1", "2", "3", "4"], "2"], [["1", "2", "3", "4"], "0"], [["1", "2", "3", "4"], "1"], [["1", "2", "3", "4"], "3"], [[], "... | introductory | https://www.codewars.com/kata/582aafca2d44a4a4560000e7 |
def keep_order(ary, val):
| 16 |
4,746 | # How much is the fish! (- Scooter )
The ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes.
## Task
Take all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the result as an integer.
## Input
The input is always a string, which can... | ["from functools import reduce\nVALID = frozenset('abcdefABCDEF')\n\n\ndef fisHex(s):\n return reduce(lambda b, c: b ^ c, (int(a, 16) for a in s if a in VALID), 0)\n", "def fisHex(name):\n # fish is 15\n hexdict={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}\n res=0\n for c in name.upper():\n if c in... | {"fn_name": "fisHex", "inputs": [["pufferfish"], ["puffers"], ["balloonfish"], ["honey toads"], [""], ["African lungfish"], ["Aholehole"], ["Airbreathing catfish"], ["Airsac catfish"], ["Alewife"], ["Alligatorfish"], ["Asiatic glassfish"], ["Atlantic saury"], ["Australian grayling"], ["Australian lungfish"], ["Australi... | introductory | https://www.codewars.com/kata/5714eb80e1bf814e53000c06 |
def fisHex(name):
| 16 |
0 | An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, ... | ["s = input()\nn = len(s)\nind = -1\nf = False\nfor i in range(n):\n if s[i] == '[':\n f = True\n elif s[i] == ':':\n if f:\n ind = i\n break\nbind = -1\nf = False\nfor i in range(n-1,-1,-1):\n if s[i] == ']':\n f = True\n elif s[i] == ':':\n if f:\n ... | {"inputs": ["[||]][[]\n", ":a::[vd|vwq|r:][]:|::\n", "|]\n", "]:]:fcl|]a::::[z|q[|jw\n", ":z::vy[lcyjoq\n", ":]]:d\n", "rszfx:pf|h]:e:wi[\n", "|bvff||:m]:|i|::p|[\n", "zr:s]ocaf:|ruqd:::|lbek[:y[gb::k|y:\n", "ty||gbbe:fnga::]|m]z:][c:a[:|ijl:orl::b[t\n", "||b]h::x|]p\n", "nf:ve:ri:riubcmfx]ib]j:qqa\n", "s|:[|j|[oouk:::... | interview | https://codeforces.com/problemset/problem/1101/B | 16 | |
1 | Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
-----Input-----
The first line contains the positive inte... | ["num = list(map(int, input()))\nbest = num[:]\nfor i in range(-1, -len(num) - 1, -1):\n if num[i] == 0:\n continue\n num[i] -= 1\n for j in range(i + 1, 0):\n num[j] = 9\n if sum(num) > sum(best):\n best = num[:]\ns = ''.join(map(str, best)).lstrip('0')\nprint(s)\n", "s_num = input()\n... | {"inputs": ["59999154\n", "999999999999990999\n", "99088\n", "12\n", "140\n", "158\n", "1609\n", "171\n", "2209\n", "261\n", "2690\n", "289\n", "9929\n", "9982\n", "998999\n", "2999902\n"], "outputs": ["59998999\n", "999999999999989999\n", "98999\n", "9\n", "99\n", "99\n", "999\n", "99\n", "1999\n", "199\n", "1999\n", ... | interview | https://codeforces.com/problemset/problem/770/B | 16 | |
2 | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | ["def main():\n s = input()\n n = len(s)\n t = int(str(int(s[0]) + 1) + '0' * (n - 1))\n\n print(t - int(s))\n\nmain()\n", "s = input()\nx = int(s)\ny = int(str(int(s[0]) + 1) + '0' * (len(s) - 1))\nprint(y - x)", "n = int(input())\n\nfor i in range(0,11):\n for j in range(1,10):\n m = j*10**i\n ... | {"inputs": ["1000000000\n", "1091\n", "190\n", "7\n", "15\n", "47\n", "56\n", "64\n", "109\n", "800\n", "8000\n", "801\n", "8080\n", "90010\n", "9080\n", "90800\n"], "outputs": ["1000000000\n", "909\n", "10\n", "1\n", "5\n", "3\n", "4\n", "6\n", "91\n", "100\n", "1000\n", "99\n", "920\n", "9990\n", "920\n", "9200\n"]} | interview | https://codeforces.com/problemset/problem/808/A | 16 | |
3 | You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters yo... | ["from collections import defaultdict as dd\nimport math\ndef nn():\n\treturn int(input())\n\ndef li():\n\treturn list(input())\n\ndef mi():\n\treturn list(map(int, input().split()))\n\ndef lm():\n\treturn list(map(int, input().split()))\n\n\nn, q=mi()\n\nints=[]\n\n\nfor _ in range(q):\n\tst, end=mi()\n\tints.append((... | {"inputs": ["6 3\n1 6\n1 3\n4 6\n", "10 4\n1 2\n1 2\n3 10\n3 10\n", "1000 3\n1 1\n1 1\n1 1\n", "9 3\n2 2\n1 6\n3 9\n", "10 6\n1 2\n2 3\n1 2\n5 6\n5 8\n10 10\n", "103 7\n3 3\n2 3\n1 2\n1 1\n2 3\n3 3\n2 3\n", "88 3\n1 3\n1 5\n3 8\n", "8 3\n1 4\n5 8\n2 7\n", "6 3\n1 3\n4 5\n5 6\n", "10 4\n2 8\n1 5\n4 7\n2 8\n", "10 4\n2 9... | interview | https://codeforces.com/problemset/problem/1132/C | 16 | |
4 | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to kno... | ["x=int(input())\nh,m=list(map(int,input().split()))\ndef ok(mm):\n while mm<0: mm+=1440\n hh=mm//60\n mm=mm%60\n return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7\nfor y in range(999):\n if ok(h*60+m-y*x):\n print(y)\n return\n", "def lucky(x):\n return (x % 10 == 7)\nx = int(input())\nh, m = list(ma... | {"inputs": ["50\n01 59\n", "45\n07 25\n", "15\n13 10\n", "55\n03 30\n", "2\n06 58\n", "1\n00 01\n", "5\n01 55\n", "11\n00 10\n", "30\n00 30\n", "59\n00 48\n", "2\n07 23\n", "60\n00 06\n", "4\n00 04\n", "1\n00 53\n", "5\n05 00\n", "15\n00 07\n"], "outputs": ["10\n", "0\n", "21\n", "11\n", "390\n", "4\n", "96\n", "3\n", ... | interview | https://codeforces.com/problemset/problem/916/A | 16 | |
5 | Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this se... | ["n, pos, l, r = map(int, input().split())\n\nif l > 1 and r < n:\n if l <= pos and pos <= r:\n if pos - l < r - pos:\n print(pos - l + 1 + r - l + 1)\n else:\n print(r - pos + 1 + r - l + 1)\n elif pos > r:\n print(pos - r + 1 + r - l + 1)\n else:\n print(l - ... | {"inputs": ["100 50 2 100\n", "10 8 3 7\n", "8 5 2 7\n", "10 10 4 6\n", "100 100 1 1\n", "6 6 4 4\n", "10 9 5 9\n", "86 36 8 70\n", "100 69 39 58\n", "100 4 2 5\n", "100 65 58 60\n", "11 8 4 9\n", "5 5 4 5\n", "4 4 1 2\n", "12 12 5 5\n", "7 4 2 6\n"], "outputs": ["49\n", "7\n", "9\n", "8\n", "100\n", "4\n", "6\n", "92\... | interview | https://codeforces.com/problemset/problem/915/B | 16 | |
6 | You are fighting with Zmei Gorynich β a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!
$m$
Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $cur... | ["for _ in range(int(input())):\n n, x = list(map(int, input().split()))\n A = []\n for _1 in range(n):\n d, h = list(map(int, input().split()))\n A.append([d, h])\n A.sort(reverse=True)\n if A[0][0] >= x:\n print(1)\n else:\n x -= A[0][0]\n mz = 0\n for d, h in... | {"inputs": ["1\n1 5\n5 6\n", "1\n1 1\n1 2\n", "1\n1 100\n100 101\n", "1\n1 1\n10 20\n", "1\n1 2\n3 2\n", "1\n2 5\n10 10\n2 1\n", "1\n1 9\n10 9\n", "2\n1 1\n2 1\n1 1\n2 1\n", "1\n3 10\n11 20\n12 20\n13 20\n", "1\n1 1\n3 4567\n", "1\n1 5\n6 9\n", "1\n7 745132167\n928769069 893298383\n653090177 337257634\n815624998 996403... | interview | https://codeforces.com/problemset/problem/1217/B | 16 | |
7 | Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that ba... | ["n, m = map(int, input().split())\nif (m >= n): print(n)\nelse:\n c = n - m\n l = 0\n r = 10 ** 18\n while r - l > 1:\n md = (r + l) // 2\n if (1 + md) * md // 2 < c:\n l = md\n else:\n r = md\n print(r + m)", "n, m = map(int, input().split())\n\ndef calc(n):\n... | {"inputs": ["1000000000000000000 1000000000000000000\n", "1 1000000000000000000\n", "762078938126917525 107528\n", "828545340972193305 1027686877\n", "946697532222325132 16179805162\n", "810365749050428005 176443295773423092\n", "326385530977846185 399823373917798976\n", "500000000500004245 4242\n", "328584130811799021... | interview | https://codeforces.com/problemset/problem/785/C | 16 | |
8 | Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the fir... | ["cards=list(input().split())\nlm=[0]*9\nlp=[0]*9\nls=[0]*9\nfor item in cards:\n if item[1]=='m':\n lm[int(item[0])-1]+=1\n elif item[1]=='p':\n lp[int(item[0])-1]+=1\n else :\n ls[int(item[0])-1]+=1\nif max(lm)==3 or max(lp)==3 or max(ls)==3:\n print(0)\nelse :\n flag=0\n def se... | {"inputs": ["9s 4s 3m\n", "8p 6s 4p\n", "5m 3p 8m\n", "4s 1p 8s\n", "8m 5s 6p\n", "5m 4s 6s\n", "3s 5m 1p\n", "6m 2s 2m\n", "6s 4p 1s\n", "2s 2p 2p\n", "7p 7m 7s\n", "1s 2p 3s\n", "2p 3s 4p\n", "3m 6m 7m\n", "3s 5s 7s\n", "3s 5s 1s\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "... | interview | https://codeforces.com/problemset/problem/1191/B | 16 | |
9 | Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs ... | ["from sys import stdin, stdout\n\nk = int(stdin.readline())\nn, m = map(int, stdin.readline().split())\nleft, right, down, up = [], [], [], []\ncoordinates = []\n\nfor i in range(k):\n x1, y1, x2, y2 = map(int, stdin.readline().split())\n \n if x1 == x2:\n if y1 < y2:\n coordinates.append((x... | {"inputs": ["1\n1 2\n1 2 1 1\n0 0 0 0\n", "1\n1 7\n1 6 1 7\n0 0 0 0\n", "1\n4 4\n3 2 3 3\n0 0 0 0\n", "1\n4 5\n1 2 2 2\n0 0 0 0\n", "1\n1 6\n1 2 1 3\n0 0 0 0\n", "2\n3 7\n3 6 3 5\n2 4 2 3\n0 1 0 1\n", "2\n5 2\n1 1 1 2\n2 2 3 2\n1 0 1 0\n", "1\n3 3\n2 3 3 3\n0 0 0 0\n", "3\n4 5\n2 4 1 4\n1 3 1 2\n2 1 1 1\n2 1 2 0\n", "2... | interview | https://codeforces.com/problemset/problem/818/C | 16 | |
10 | On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlingsΒ β 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
-----Input-----
The first line of the input ... | ["n=int(input())\nr=n%7\nd=n//7\nprint(2*d+max(0,r-5),2*d+min(r,2))\n", "minday = maxday = 0\n\nfor i in range(int(input())) :\n k = i % 7\n if k == 0 or k == 1 : maxday += 1\n if k == 5 or k == 6 : minday += 1\n\nprint(minday, maxday)", "__author__ = 'Andrey'\nn = int(input())\nk = n // 7\nc = n % 7\nprint(2 ... | {"inputs": ["1\n", "8\n", "20\n", "89\n", "88\n", "990\n", "988\n", "9993\n", "9991\n", "9981\n", "99993\n", "99980\n", "999997\n", "999994\n", "999989\n", "234120\n"], "outputs": ["0 1\n", "2 3\n", "5 6\n", "24 26\n", "24 26\n", "282 284\n", "282 283\n", "2854 2856\n", "2854 2856\n", "2851 2852\n", "28568 28570\n", "2... | interview | https://codeforces.com/problemset/problem/670/A | 16 | |
11 | Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a a... | ["from fractions import gcd\ndef lcm(a, b):\n return a*b//gcd(a, b)\nn, a, b, p, q = list(map(int, input().split(' ')))\nred = n//a\nblue = n//b\nif (p<q):\n red -= n//lcm(a, b)\nelse:\n blue -= n//lcm(a, b)\n\nprint(p*red+q*blue)\n", "3\n# Copyright (C) 2016 Sayutin Dmitry.\n#\n# This program is free software... | {"inputs": ["2 1 3 3 3\n", "894 197 325 232 902\n", "100000 3 9 1 2\n", "1200 4 16 2 3\n", "100 4 6 12 15\n", "24 4 6 10 100\n", "12 2 4 5 9\n", "20 4 2 10 1\n", "2000 20 30 3 5\n", "24 4 6 1 1\n", "1000000000 9 15 10 10\n", "100000 4 6 12 14\n", "1000000000 1 1 999999999 999999999\n", "1000000 32 16 2 5\n", "100 2 4 1... | interview | https://codeforces.com/problemset/problem/678/C | 16 | |
12 | Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.
The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement a... | ["n = int(input())\nA = input()\nx = A.count('G')\nnum_1 = 0\nnum_2 = 0\nmax_num = 0\nflag = 0\nfor i in range(n):\n if A[i] == 'G' and flag == 0:\n num_1 += 1\n elif A[i] == 'G' and flag == 1:\n num_2 += 1\n elif A[i] == 'S' and flag == 0:\n flag = 1\n else:\n if num_1 + num_2 +... | {"inputs": ["10\nGGGSGGGSGG\n", "4\nGGGG\n", "11\nSGGGGGSSSSG\n", "8\nGSSSGGGG\n", "94\nGGSSGGSGGSSSSSGSSSGGSSSSSGSGGGGSGSGSGSGSGSSSSGGGSSGSSSSGSSSSSSSSSGSSSGGSSGGSGSSGSGGGGSGGGSSSSS\n", "26\nGGSSSSGSSSSSSSGSSSSSSGSSGS\n", "10\nSSSSGGSGGG\n", "21\nSSSGGGSGGGSSSGGGGGGGG\n", "10\nSSGGGSSGGS\n", "9\nGGGSSGGGG\n", "7\nSGGS... | interview | https://codeforces.com/problemset/problem/1082/B | 16 | |
13 | Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.
The situation is complicated by the dependence of online courses, for each course there is a list of those that must be pas... | ["#This code is dedicated to Vlada S.\n\nclass Course:\n\tdef __init__(self, reqs, number):\n\t\tself.reqs = list(map(int, reqs.split()[1:]))\n\t\tself.available = False\n\t\tself.in_stack = False\n\t\tself.number = number\n\nn, k = list(map(int, input().split()))\nrequirements = list(map(int, input().split()))\ncourse... | {"inputs": ["9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n", "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2\n", "2 1\n2\n0\n1 1\n", "3 3\n3 2 1\n0\n0\n0\n", "3 2\n3 1\n1 3\n0\n0\n", "4 4\n3 1 4 2\n1 2\n1 3\n1 2\n0\n", "4 1\n4\n2 2 4\n0\n1 2\n0\n", "5 2\n1 3\n0\n2 4 5\n0\n1 2\n2 1 2\n", "5 3\n2 5 1\n1 2\n0\n0\n1 5\n0\n", "6... | interview | https://codeforces.com/problemset/problem/770/C | 16 | |
14 | Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, append it to the end of arr... | ["import sys\n\n#f = open('input', 'r')\nf = sys.stdin\nn,k = list(map(int, f.readline().split()))\na = list(map(int, f.readline().split()))\naset = set(a)\nst = []\nfailed = False\nai = 0\napp = []\nfor p in range(1, n+1):\n if p in aset:\n while ai < k and (len(st)==0 or st[-1]!=p):\n st.append(a[ai])\n ... | {"inputs": ["5 2\n3 4\n", "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3\n", "10 5\n2 10 5 8 4\n", "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\n", "40 36\n27 33 34 40 16 39 1 10 9 12 8 37 17 7 24 30 2 31 13 23 20 18 29 21 4 28 25 35 6 22 3... | interview | https://codeforces.com/problemset/problem/911/E | 16 | |
15 | Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that ... | ["import sys\na,b,c=map(int,input().split())\nif c==0:\n if a==b:\n print('YES')\n else:\n print('NO')\n return\nif (b-a)%c==0 and (b-a)//c>=0:\n print('YES')\nelse:\n print('NO')", "a, b, c = list(map(int, input().split()))\nif c != 0:\n if c * (b - a) >= 0 and (b - a) % c == 0:\n ... | {"inputs": ["1000000000 -1000000000 5\n", "119057893 -516914539 -39748277\n", "-2 -1 -2\n", "-2 2 -2\n", "-1 -2 -1\n", "-1 2 -2\n", "0 -2 -2\n", "0 -2 1\n", "0 0 -2\n", "0 1 -2\n", "1 -1 -2\n", "2 -2 1\n", "2 -1 -2\n", "2 2 -2\n", "2 2 1\n", "10 9 -1\n"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "Y... | interview | https://codeforces.com/problemset/problem/675/A | 16 | |
16 | A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; ")... | ["cnt1 = int(input())\ncnt2 = int(input())\ncnt3 = int(input())\ncnt4 = int(input())\nif cnt1 != cnt4:\n\tprint(0)\n\treturn\n\nif (cnt3 != 0 and cnt1 == 0):\n\tprint(0)\n\treturn\n\nprint(1)", "cnt = [int(input()) for _ in range(4)]\n\nif cnt[0] != cnt[3]:\n\tprint(0)\nelif cnt[2] > 0 and cnt[0] == 0:\n\tprint(0)\nels... | {"inputs": ["3\n1\n4\n3\n", "1000000000\n999999999\n1000000000\n1000000000\n", "925\n22\n24\n111\n", "2\n2\n6\n2\n", "0\n0\n3\n0\n", "1\n0\n10000000\n1\n", "1\n5\n10\n1\n", "2\n2\n9\n2\n", "1\n1\n3\n1\n", "1\n900\n900\n1\n", "0\n3\n4\n0\n", "5\n1\n50\n5\n", "1\n1\n50\n1\n", "1\n47\n47\n1\n", "2\n1\n45\n2\n", "23\n0\n49... | interview | https://codeforces.com/problemset/problem/1132/A | 16 | |
17 | Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k + 1, the (k + 1)-th spectator stands and th... | ["def read_ints():\n\treturn [int(i) for i in input().split()]\n\nn, k, t = read_ints()\nif t <= k:\n\tprint(t)\nelif t > n:\n\tprint(k + n - t)\nelse:\n\tprint(k)", "def list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input(... | {"inputs": ["10 5 7\n", "840585600 770678331 788528791\n", "330543750 243917820 205522400\n", "418386749 1915035 197248338\n", "100 100 99\n", "10 6 11\n", "4 3 6\n", "4 4 4\n", "10 10 18\n", "15 3 10\n", "10 3 12\n", "20 5 20\n", "13 10 14\n", "41 3 3\n", "1000000000 1000000000 1400000000\n", "10 6 15\n"], "outputs": ... | interview | https://codeforces.com/problemset/problem/851/A | 16 | |
18 | Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this charact... | ["from collections import deque\nS = input()\nmn = [ 300 for i in range( len( S ) ) ]\nfor i in range( len( S ) - 1, -1, -1 ):\n if i == len( S ) - 1:\n mn[ i ] = ord( S[ i ] )\n else:\n mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) )\nans = \"\"\ndq = deque()\nfor i in range( len( S ) ):\n dq.append( ord( S[ i ] ... | {"inputs": ["dacb\n", "aabaa\n", "aaaaaa\n", "aaaaaa\n", "ccdece\n", "eecade\n", "aaaaaaa\n", "bbababa\n", "cbbcccc\n", "aabaaabbb\n", "caaaccccb\n", "abbcdbddb\n", "bdbeeccdd\n", "cbaabcaacc\n", "dbdccdcacd\n", "cdeabdbbad\n"], "outputs": ["abcd\n", "aaaab\n", "aaaaaa\n", "aaaaaa\n", "cccede\n", "acdeee\n", "aaaaaaa\n... | interview | https://codeforces.com/problemset/problem/797/C | 16 | |
19 | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases... | ["import sys\ninput = sys.stdin.readline\n\nT = int(input())\nfor _ in range(T):\n n = int(input())\n lastP = 0\n lastC = 0\n works = True\n for _ in range(n):\n p, c = list(map(int, input().split()))\n pDiff = p-lastP\n cDiff = c-lastC\n if 0 <= cDiff <= pDiff:\n p... | {"inputs": ["6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n", "1\n2\n10 1\n11 3\n", "1\n2\n100 0\n101 2\n", "1\n3\n2 1\n4 1\n5 3\n", "1\n2\n3 0\n5 5\n", "1\n2\n5 0\n7 3\n", "2\n3\n0 0\n100 0\n104 5\n3\n0 0\n100 0\n104 4\n", "1\n2\n1 0\n3 3\n", "1\n2... | interview | https://codeforces.com/problemset/problem/1334/A | 16 | |
20 | Karen is getting ready for a new school day!
[Image]
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time... | ["s = input()\nh = int(s[:2])\nm = int(s[3:])\n\ndef ispalin(h, m):\n s = \"%02d:%02d\"%(h,m)\n return s == s[::-1]\n\nfor d in range(999999):\n if ispalin(h, m):\n print(d)\n break\n m+= 1\n if m == 60:\n h = (h+1)%24\n m = 0\n", "def f(x, y):\n xx = str(x)\n if len(xx)... | {"inputs": ["12:22\n", "11:11\n", "04:41\n", "11:12\n", "08:15\n", "06:16\n", "10:10\n", "17:25\n", "09:20\n", "20:02\n", "23:01\n", "21:20\n", "23:30\n", "18:53\n", "19:08\n", "02:19\n"], "outputs": ["69\n", "0\n", "69\n", "69\n", "106\n", "225\n", "61\n", "157\n", "41\n", "0\n", "31\n", "62\n", "2\n", "69\n", "54\n",... | interview | https://codeforces.com/problemset/problem/816/A | 16 | |
21 | 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... | ["read = lambda: list(map(int, input().split()))\nn = int(input())\na = list(read())\nx, y = a.index(1), a.index(n)\nans = max(x, y, n - x - 1, n - y - 1)\nprint(ans)\n", "n = int(input())\na = list(map(int, input().split()))\ni, j = sorted([a.index(1), a.index(n)])\nprint(max(j, n - i - 1))\n", "n = int(input())\nL = ... | {"inputs": ["5\n4 5 1 3 2\n", "5\n1 4 5 2 3\n", "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25\n", "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26\n", "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8\n", "5... | interview | https://codeforces.com/problemset/problem/676/A | 16 | |
22 | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
[Image] English alphabet
You are given... | ["import sys, math\ns=input()\npal='AHIMOoTUVvWwXxY'\nn=len(s)\nl=0\nr=n-1\nflag=True\nfir='pq'\nsec='bd'\nwhile l<=r:\n if s[l]==s[r] and s[l] in pal:\n l+=1\n r-=1\n continue\n elif s[l]==s[r]:\n flag=False\n break\n elif (s[l] in fir) and (s[r] in fir):\n l+=1\n ... | {"inputs": ["iiii\n", "l\n", "AAA\n", "OuO\n", "AA\n", "BAAAB\n", "UA\n", "NpOqN\n", "lll\n", "viv\n", "AiiiA\n", "dd\n", "NAN\n", "AiA\n", "XHX\n", "lOl\n"], "outputs": ["NIE\n", "NIE\n", "TAK\n", "NIE\n", "TAK\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "NIE\n", "TAK\n", "NIE\n"]} | interview | https://codeforces.com/problemset/problem/691/B | 16 | |
23 | You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
-----Input-----
The first line contains integer a (1 β€ a β€ 10^18). The second lin... | ["a = list(input())\nb = int(input())\na.sort()\na = a[::-1]\nprefix = \"\"\nwhile(len(a) > 0):\n\tfor i in range(len(a)):\n\t\tnum = prefix + a[i] + \"\".join(sorted(a[:i] + a[i + 1:]))\n\t\tif (int(num) <= b):\n\t\t\tprefix += a[i]\n\t\t\ta = a[:i] + a[i+1:]\n\t\t\tbreak\nprint(prefix)\n", "fact_ = [1] * 50\n\n\ndef ... | {"inputs": ["12345\n21344\n", "14362799391220361\n45160821596433661\n", "5200000000234\n5200000000311\n", "7901\n7108\n", "19260817\n20011213\n", "3053\n5004\n", "3208899\n3228811\n", "8388731334391\n4710766672578\n", "1230\n1200\n", "241285\n207420\n", "481287\n826607\n", "90\n94\n", "6\n9\n", "87\n810\n", "533\n335\n... | interview | https://codeforces.com/problemset/problem/915/C | 16 | |
24 | Alice and Bob play 5-in-a-row game. They have a playing field of size 10 Γ 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins imm... | ["s = [ [ c for c in input() ] for i in range(10) ]\ndef win():\n for i in range(10):\n for j in range(10):\n ok = True\n for k in range(5):\n if j+k>9: ok = False\n elif s[i][j+k] != 'X': ok = False\n if ok: return True\n ok = True\n for k in range(5):\n if i+k>9: ok =... | {"inputs": ["..........\n......OOO.\n..........\n..........\n..........\n.....O....\n......X...\n.......X..\n........X.\n.........X\n", ".....OOOO.\n..........\n..........\n..........\n..........\n..........\n........X.\n.......X..\n......X...\n.....X....\n", ".........X\n........X.\n.......X..\n......X...\n..........\... | interview | https://codeforces.com/problemset/problem/825/B | 16 | |
25 | You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically... | ["#!/usr/bin/env python3\n\ndef main():\n import sys\n\n readln = sys.stdin.readline\n try:\n while True:\n n, k = list(map(int, input().split()))\n a = [['0'] * n for i in range(n)]\n i = j = 0\n while k > 0:\n if i == j:\n a... | {"inputs": ["3 3\n", "1 6\n", "1 9\n", "1 14\n", "1 19\n", "1 24\n", "3 7\n", "3 12\n", "3 15\n", "3 21\n", "4 24\n", "5 5\n", "5 6\n", "5 8\n", "5 20\n", "5 22\n"], "outputs": ["1 1 0 \n1 0 0 \n0 0 0 \n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "1 1 1 \n1 1 0 \n1 0 1 \n", "-1\n", "-1\n", "-1\n", "-1\n", "1 1 1 0 0 \n1... | interview | https://codeforces.com/problemset/problem/803/A | 16 | |
26 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | ["from math import log\nfrom decimal import Decimal\n\ns = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y']\n\nx, y, z = list(map(Decimal, input().split()))\n\nf = []\nf += [(Decimal(log(x)) * (y ** z), 0)]\nf += [(Decimal(log(x)) * (z ** y), -1)]\nf += [(Decimal(log(x)) * (y * ... | {"inputs": ["1.5 1.7 2.5\n", "113.9 125.2 88.8\n", "104.6 184.4 82.3\n", "81.7 171.9 4.4\n", "0.9 4.6 3.4\n", "1.1 3.1 4.9\n", "3.7 2.2 4.8\n", "1.7 4.5 4.2\n", "4.1 3.5 4.5\n", "0.2 0.7 0.6\n", "1.0 0.3 1.1\n", "0.2 0.6 0.3\n", "0.4 0.2 0.3\n", "3.0 3.0 3.1\n", "200.0 200.0 1.0\n", "0.2 0.3 0.1\n"], "outputs": ["(z^x)... | interview | https://codeforces.com/problemset/problem/621/D | 16 | |
27 | You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard.
Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the end of the string.
Besides, at most once you may perform one addit... | ["n = int(input())\nst = input()\nans = n\nnow = ''\nma = 0\nfor i in range(n // 2):\n now += st[i]\n t = ''\n for j in range(i + 1, 2 * i + 2):\n t += st[j]\n if t == now:\n ma = i\nprint(ans - ma)\n", "n = int(input())\nstrng = input().strip()\nres = len(strng)\nst = len(strng)//2\nwhile st>... | {"inputs": ["10\nababababab\n", "9\nzabcdabcd\n", "17\nababababzabababab\n", "7\ndabcabc\n", "16\naaaaaabbaaaaaabb\n", "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "9\nbaaaabaaa\n", "8\naabcabca\n", "99\nlhgjlskfgldjgadhdjjgskgakslflalhjfgfaaalkfdfgdkdffdjkjddfgdhalklhsgslskfdhsfjlhgajlgdfllhlsdhlhadaa\n", "5\nabcab\n", "66\nl... | interview | https://codeforces.com/problemset/problem/954/B | 16 | |
28 | The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to re... | ["n = int(input())\nt = [1] + [0] * n\nb, a = d = [], []\nh, s = [], []\n\nfor i in range(n):\n f, k = input().split()\n d[int(k)].append(f)\n\nm = len(a)\nfor i in a:\n if i.isdigit() and i[0] != '0':\n j = int(i)\n if 0 < j <= m:\n t[j] = 1\n elif m < j <= n:\n t[j]... | {"inputs": ["5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n", "3\nz1nwrd 1\nt0xrja 0\n106qy1 0\n", "1\nabbdf7 1\n", "3\nt0dfz3 0\n3 0\n1 1\n", "5\n5 1\nz9zr7d 0\ne8rwo4 1\nrfpjp6 0\ngz6dhj 0\n", "5\n1 1\nx2miqh 1\n3 0\n2 0\n1rq643 0\n", "5\n1 1\nnoidnv 0\n3 1\nx3xiiz 0\n1lfa9v 0\n", "3\n1 1\n7ph5fw 1\ntfxz1j 1\n", "4\n1wp56i 1\n2... | interview | https://codeforces.com/problemset/problem/858/E | 16 | |
29 | Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of las... | ["x=int(input())\ndef s(a):\n r=0\n while a>0:\n r+=a%10\n a//=10\n return r\ndef d(a,b):\n r=0\n for i in range(6):\n if a%10!=b%10:\n r += 1\n a//=10\n b//=10\n return r\nc=6\nfor i in range(1000000):\n if s(i%1000)==s(i//1000):\n c=min(c,d(x,i))\nprint(c)\n", "s = input()\n\nans = 6\n\n... | {"inputs": ["651894\n", "000444\n", "101488\n", "111993\n", "766100\n", "977330\n", "123789\n", "989304\n", "301679\n", "010339\n", "000900\n", "201984\n", "002667\n", "788024\n", "042762\n", "023977\n"], "outputs": ["1\n", "2\n", "3\n", "2\n", "2\n", "2\n", "3\n", "3\n", "2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n"... | interview | https://codeforces.com/problemset/problem/845/B | 16 | |
30 | The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of ... | ["from math import gcd\ndef powmod(a,b,m):\n a%=m\n r=1\n while b:\n if b&1:r=r*a%m\n a=a*a%m\n b>>=1\n return r\n\ndef f(n):\n r=[]\n if (n&1)==0:\n e=0\n while (n&1)==0:n>>=1;e+=1\n yield (2,e)\n p=3\n while n>1:\n if p*p>n:p=n\n if n%p:\n p+=2\n continue\n e=1;n//=p\n while n%p==0:n//=p;e+=1\n yield (... | {"inputs": ["5 2\n", "12 1\n", "12 5\n", "1260 1121\n", "99999999999971 53\n", "99999999999898 79\n", "99999999999898 89\n", "99999999999726 103\n", "97821761637600 79\n", "97821761637600 963761198291\n", "97821761637600 963761198251\n", "97821761637600 97821761637491\n", "7420738134810 200560489999\n", "7420738134810 ... | interview | https://codeforces.com/problemset/problem/1027/G | 16 | |
31 | ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.
In Udayland,... | ["m = 10** 6 + 3\n\nn, k = list(map(int, input().split()))\np = 1\nfor i in range(n):\n p *= 2\n if p > k:\n break\nif p < k:\n print('1 1')\n return\n\ngcd = tmp = k - 1\nwhile tmp:\n gcd -= tmp % 2\n tmp //= 2\nb = pow(2, (k - 1) * n - gcd, m)\na = 1\nmem = [-1]*100\nfor i in range(1, k):\n ... | {"inputs": ["59 576460752303423489\n", "2016 2016\n", "841928147887146057 620004\n", "160986032904427725 153429\n", "88268234087903158 290389\n", "565690379013964030 914981\n", "180838095407578776 715935\n", "782215240494010889 417929\n", "904600330829364045 969618\n", "532376674825779019 113292273466542585\n", "452811... | interview | https://codeforces.com/problemset/problem/711/E | 16 | |
32 | In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the N... | ["\"\"\"\nCodeforces Good Bye 2016 Contest Problem B\n\nAuthor : chaotic_iak\nLanguage: Python 3.5.2\n\"\"\"\n\n################################################### SOLUTION\n\ndef main():\n latitude = 0\n n, = read()\n for i in range(n):\n l, d = read(str)\n l = int(l)\n if latitude == 0:... | {"inputs": ["2\n576 South\n576 North\n", "4\n149 South\n17607 West\n18306 South\n18455 North\n", "4\n6549 East\n5118 North\n12198 East\n5118 South\n", "8\n19264 South\n10516 North\n3319 East\n17401 East\n1620 West\n2350 West\n6243 North\n2505 North\n", "8\n15392 South\n7290 West\n2096 West\n14093 East\n5802 South\n2094... | interview | https://codeforces.com/problemset/problem/750/B | 16 | |
33 | You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L β€ x β€ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' β₯ 0.
-----Input-----
The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 β€ 2Β·10^9, - 2Β·10^9 β€ b_1, b_2, L, R β€ 2Β·... | ["import sys, collections\n\ndef gcd(a, b):\n if b == 0: return a\n return gcd(b, a % b)\n\ndef lcm(a, b):\n return a // gcd(a, b) * b\n\ndef extgcd(a, b):\n if b == 0: return 1, 0\n x, y = extgcd(b, a % b)\n return y, x - a // b * y\n\ndef prime_factor(n):\n res = collections.defaultdict(int)\n\n ... | {"inputs": ["4 2963 394 577593 125523962 628140505\n", "1 -2000000000 1 -2000000000 -2000000000 2000000000\n", "999999999 999999998 1000000000 999999999 1 10000\n", "1 -2000000000 2 2000000000 -2000000000 2000000000\n", "2 -1500000000 4 -1499999999 1600000000 1700000000\n", "1 -9 2 -10 -10 -9\n", "2 -1000000000 2 -9999... | interview | https://codeforces.com/problemset/problem/710/D | 16 | |
34 | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one β into b pieces.
Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat... | ["n, a, b = map(int, input().split())\nans = 0\nfor i in range(1, n):\n ans = max(ans, min(a // i, b // (n - i)))\nprint(ans)", "n,a,b = [int(x) for x in input().split()]\nmxmn = max(min(a//i,b//(n-i)) for i in range(1,n))\nprint(mxmn)\n", "n, a, b = map(int, input().split())\n\nans = -1\nfor x in range(1, min(n, a)... | {"inputs": ["10 10 31\n", "10 98 99\n", "6 7 35\n", "4 7 20\n", "14 95 1\n", "3 94 79\n", "3 3 3\n", "41 34 67\n", "5 20 8\n", "2 4 2\n", "5 5 12\n", "18 100 50\n", "5 6 8\n", "17 100 79\n", "13 6 7\n", "4 2 9\n"], "outputs": ["3\n", "19\n", "7\n", "6\n", "1\n", "47\n", "1\n", "2\n", "5\n", "2\n", "3\n", "8\n", "2\n", ... | interview | https://codeforces.com/problemset/problem/911/B | 16 | |
35 | The flag of Berland is such rectangular field n Γ m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each col... | ["n,m=list(map(int,input().split()))\nf=[input() for _ in range(n)]\ndef clr(ss):\n cc = None\n for s in ss:\n for c in s:\n if cc is None:\n cc = c\n elif cc != c:\n return None\n return cc\nif n%3 == 0:\n s = set()\n for i in range(0,n,n//3):\n... | {"inputs": ["4 3\nBRG\nBRG\nBRG\nBRG\n", "3 3\nBRG\nBRG\nBRG\n", "3 1\nB\nR\nB\n", "3 3\nRBR\nRBR\nRBR\n", "1 6\nRRRRRR\n", "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBB... | interview | https://codeforces.com/problemset/problem/837/B | 16 | |
36 | Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:
[Image] [Image] Ayrat is searching through the field. He started at point (... | ["def f(n):\n\tleft, right = -1, n + 1\n\twhile right - left > 1:\n\t\tmid = (left + right) // 2\n\t\tx = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)\n\t\tif x > n:\n\t\t\tright = mid\n\t\telse:\n\t\t\tleft = mid\n\tif left >= 0:\n\t\tmid = left\n\t\tx = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)\n\t\tn -= x\n\treturn (n, l... | {"inputs": ["60\n", "826594\n", "854460\n", "23\n", "25\n", "29\n", "261252157843454379\n", "781520406700253046\n", "622704061396296670\n", "108364135632524999\n", "565840809656836956\n", "177207687885798058\n", "498549006180463098\n", "379604878823574823\n", "633227154929081648\n", "2\n"], "outputs": ["8 0\n", "-769 5... | interview | https://codeforces.com/problemset/problem/615/E | 16 | |
37 | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of dama... | ["a, b, c = list(map(int, input().split()))\np = [0] * 100000\np[0] = 1\np[a] = 1\np[b] = 1\nfor i in range(c + 1):\n if p[i]:\n p[i + a] = 1\n p[i + b] = 1\nif p[c]:\n print('Yes')\nelse:\n print('No')\n", "# You lost the game.\na,b,c = list(map(int, input().split()))\n\nT = [not((c-a*k)%b) for ... | {"inputs": ["20 5 57\n", "22 24 866\n", "32 4 62\n", "37 15 789\n", "38 68 1870\n", "44 42 2005\n", "48 65 917\n", "54 67 3181\n", "62 1 501\n", "62 50 2775\n", "80 43 1864\n", "76 69 4122\n", "97 31 3761\n", "17 43 68\n", "3 2 1\n", "1 4 3\n"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "Ye... | interview | https://codeforces.com/problemset/problem/633/A | 16 | |
38 | Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you... | ["def main():\n\tn, l = map(int, input().split())\n\n\tx = list(map(int, input().split()))\n\ty = list(map(int, input().split()))\n\n\tx.append(x[0] + l)\n\ty.append(y[0] + l)\n\n\ta = [x[i + 1] - x[i] for i in range(n)]\n\tb = [y[i + 1] - y[i] for i in range(n)]\n\n\tfor i in range(n):\n\t\tif (a == b[i:] + b[:i]):\n\... | {"inputs": ["7 81\n0 12 19 24 25 35 59\n1 8 13 14 24 48 70\n", "8 20\n0 1 2 3 5 6 14 15\n1 2 10 11 16 17 18 19\n", "9 18\n1 3 6 8 11 12 13 16 17\n0 2 5 6 7 10 11 13 15\n", "19 25\n0 1 2 3 5 7 9 10 12 13 16 17 18 19 20 21 22 23 24\n0 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 21 22 24\n", "19 91\n5 17 18 20 22 25 26 31 32 33... | interview | https://codeforces.com/problemset/problem/761/B | 16 | |
39 | A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1 \leq l \leq r \leq |s|$) of a string $s = s_{1}s_{2} \ldots ... | ["s = input()\nmx = 0\nn = len(s)\nfor l in range(n):\n for r in range(l, n):\n if s[l:r+1] != s[l:r+1][::-1]:\n mx = max(mx, r - l + 1)\nprint(mx)", "ans = 0\ns = input()\nn = len(s)\nfor i in range(n):\n for j in range(i + 1, n + 1):\n t = s[i:j]\n if t != t[::-1]:\n a... | {"inputs": ["oftmhcmclgyqaojljoaqyglcmchmtfo\n", "oftmhcmclgyqaojllbotztajglsmcilv\n", "gxandbtgpbknxvnkjaygommzqitqzjfalfkk\n", "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf\n", "aaaaabaaaaa\n", "abcdaaa\n", "aaholaa\n", "aaabaaa\n", "babb\n", "abcaa\n", "aaaaaabaaaaa\n", "aaaaabcbaaaaa\n", "aacbca\n", "cccaaccc\n", "abb... | interview | https://codeforces.com/problemset/problem/981/A | 16 | |
40 | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ... | ["'''input\n5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n'''\nn = int(input())\nx = []\nf = 0\nfor _ in range(n):\n\ta, b = list(map(int, input().split()))\n\tif a != b:\n\t\tf = 1\n\tx.append(a)\nif f == 1:\n\tprint(\"rated\")\nelif sorted(x)[::-1] == x:\n\tprint(\"maybe\")\nelse:\n\tprint(\"unrated\")\n\... | {"inputs": ["10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423\n", "2\n3 2\n3 2\n", "2\n1600 1600\n1400 1400\n", "2\n3 1\n9 8\n", "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699\n", "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900\n", "3\n3 2\n3 3\n3 3\n", "2\n2 2\n2... | interview | https://codeforces.com/problemset/problem/807/A | 16 | |
41 | You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
-----Input-----
The first line contains integer n (1 β€ n β€ 2Β·10^5) β length of the array a. The sec... | ["inf = 10 ** 6\nn = int(input())\na = list(map(int, input().split()))\ndist = [inf] * n\nfor i in range(len(a)):\n if not a[i]:\n dist[i] = 0\n cur = 1\n i1 = i\n while i1 - 1 > - 1 and a[i1 - 1] != 0:\n dist[i1 - 1] = min(dist[i1 - 1], cur)\n i1 -= 1\n c... | {"inputs": ["9\n2 1 0 3 0 0 3 2 4\n", "5\n0 1 2 3 4\n", "30\n0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "3\n0 0 0\n", "5\n0 0 0 0 -1000000000\n", "5\n0 0 1000000000 0 0\n", "6\n0 0 1000000000 1000000000 -1000000000 -1000000000\n", "6\n0 0 0 0 -1000000000 1000000000\n", "7\n0 0... | interview | https://codeforces.com/problemset/problem/803/B | 16 | |
42 | You are given a binary string $s$.
Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring.
The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$.
For example, the cyclic... | ["n=int(input())\ns=[c=='1' for c in input()]\nm=len(s)\nz=[[0,0]]\nfor c in s:\n ind = z[-1][c]\n z[-1][c] = len(z)\n z.append(z[ind][:])\nassert(len(z) == m+1)\nz[m][0] = z[m][1] = m # make it sticky\n\n# how many things match directly\ndp = [0 for _ in range(m+1)]\ndp[0] = 1\nfor i in range(n):\n ndp = [0 for _ in r... | {"inputs": ["17\n011100101100110\n", "11\n10100000100\n", "31\n101\n", "31\n11011101110000011100\n", "6\n101111\n", "37\n1000101000000000011101011111010011\n", "36\n000000000011111111111111111111111111\n", "40\n000010101101010011111101011110010011\n", "40\n0010\n", "40\n1110\n", "40\n1101\n", "40\n0011\n", "40\n000\n",... | interview | https://codeforces.com/problemset/problem/1038/F | 16 | |
43 | You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 ... | ["from math import *\n# stores counterclockwise angle between vector (1,0) and each vector in a\na = []\nn = int(input())\nfor i in range(n):\n x,y = list(map(int,input().split()))\n # calculate counterclockwise angle between (1,0) and this vector\n t = acos(x/sqrt(x**2+y**2))\n a.append((i+1,[2*pi-t,t][y>=... | {"inputs": ["4\n-7061 -5800\n-3471 -9470\n-7639 2529\n5657 -6522\n", "2\n0 1\n0 -1\n", "4\n-1 0\n0 -1\n-1 1\n1 0\n", "3\n1 0\n-1 1\n-1 -1\n", "6\n1 1\n-1 -1\n0 20\n100 1\n-100 0\n100 -1\n", "3\n-100 1\n100 0\n-100 -1\n", "4\n-1 0\n0 -2\n-3 3\n4 0\n", "3\n1 -1\n1 0\n0 1\n", "3\n5 5\n-5 0\n5 -5\n", "4\n-6427 -6285\n-5386... | interview | https://codeforces.com/problemset/problem/598/C | 16 | |
44 | Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.
Vasiliy's car is not new β it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will ... | ["d, k, a, b, t = list(map(int, input().split()))\n\nt1 = d * b\nt2 = d * a + ((d - 1) // k) * t\nt3 = max(0, d - k) * b + min(k, d) * a\ndd = d % k\nd1 = d - dd\nt4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b\n\nprint(min([t1, t2, t3, t4]))\n", "from random import randint\nd, k, a, b, t = list(map(int, input().split... | {"inputs": ["857863230070 37311 545046 657309 991732\n", "1000000000000 1 1 4 1\n", "100 110 1 2 100000\n", "100 120 1 2 300\n", "100 1000 1 10 1000\n", "1 2 1 2 1\n", "11 12 3 4 5\n", "1 100 2 200 900\n", "10 100 5 6 1000\n", "100 123 1 2 1007\n", "100 120 1 2 516\n", "4 6 1 2 100\n", "1686604166 451776 534914 885584 ... | interview | https://codeforces.com/problemset/problem/702/D | 16 | |
45 | You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by the... | ["n, k = map(int, input().split())\ndiv = []\ni = 1\nn1 = n\nwhile i * i <= n:\n if n % i == 0:\n div.append(i)\n div.append(n // i)\n i += 1\ndiv.sort()\nmx = -1\nfor i in range(len(div)):\n a = div[i] * k * (k + 1) // 2\n if a <= n:\n mx = div[i]\nif mx == -1:\n print(-1)\nelse:\n ... | {"inputs": ["479001600 4\n", "3000000021 2\n", "10000000000 100000000\n", "1000 4294967295\n", "12344321 1\n", "1 6\n", "2 6\n", "2 8\n", "3 8\n", "5 2\n", "5 7\n", "5 9\n", "6 6\n", "7 9\n", "7 10\n", "8 3\n"], "outputs": ["47900160 95800320 143700480 191600640\n", "1000000007 2000000014\n", "-1\n", "-1\n", "12344321\... | interview | https://codeforces.com/problemset/problem/803/C | 16 | |
46 | After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integersΒ β the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column ... | ["ct=0\na, b = list(map(int, input().split(' ')))\nx=[0]*5\nfor i in range(1, b+1):\n x[i%5]+=1\nfor i in range(1, a+1):\n ct+=x[(0-i)%5]\nprint(ct)\n", "#!/usr/bin/env python3\n\ntry:\n while True:\n n, m = list(map(int, input().split()))\n a = [0] * 5\n b = [0] * 5\n for i in rang... | {"inputs": ["1 1000000\n", "944 844\n", "31 29\n", "171591 13322\n", "827388 966812\n", "110364 356449\n", "636358 355531\n", "202311 358998\n", "918012 688747\n", "117564 753732\n", "3 9\n", "54 43\n", "14 9\n", "21 3\n", "4 3\n", "4 9\n"], "outputs": ["200000\n", "159348\n", "180\n", "457187060\n", "159985729411\n", ... | interview | https://codeforces.com/problemset/problem/682/A | 16 | |
47 | You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0.
You may choose at most one consecutive subarr... | ["N, X = list(map(int, input().split()))\nA = [int(a) for a in input().split()]\n\ndp = [[0]*4 for _ in range(N+1)]\n\nfor i in range(1, N+1):\n dp[i][0] = max(dp[i-1][0] + A[i-1], 0)\n dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0])\n dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1])\n dp[i][3] = max(dp[i-1]... | {"inputs": ["12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n", "5 0\n10 -5 10 -4 7\n", "5 0\n1 -1 -2 3 -4\n", "12 0\n516886745 863558529 725534320 -476894082 -367873680 984444967 -179610789 -226927004 -433201102 -328480313 836969657 -860311698\n", "4 -2\n-1 1 -2 -3\n", "5 -1\n-2 -4 5 -3 -4\n", "5 0\n100 -1 -2 -3 5\n", "1 1\n1\n", "8 ... | interview | https://codeforces.com/problemset/problem/1155/D | 16 | |
48 | Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n Γ m multiplication table, where the element on the intersection of the i-th row and j-th column equals iΒ·j (the rows and ... | ["def main():\n from math import sqrt\n m, n, k = list(map(int, input().split()))\n if n < m:\n n, m = m, n\n lo, hi = 1, k + 1\n while lo + 1 < hi:\n mid = (lo + hi) // 2\n t = mid - 1\n v = min(int(sqrt(t)), m)\n tn, tm = (t - 1) // m, t // n\n vv = [t // i for... | {"inputs": ["2 2 4\n", "4 1796 2564\n", "4 25555 45556\n", "5 17136 9220\n", "3 355632 94220\n", "12 28 127\n", "48 40 937\n", "25 1155 9981\n", "41 246624 2596292\n", "366 45769 5885721\n", "4313 40 86640\n", "2115 384 385536\n", "2930 491026 923941798\n", "37107 4 28350\n", "118728 168631 16269281609\n", "283422 4077... | interview | https://codeforces.com/problemset/problem/448/D | 16 | |
49 | Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the $k$-th digit of this sequence.
-----Input-----
The fir... | ["k = int(input())\n\nif k<=9:\n print(k)\nelse:\n num_arr = [9*(i+1)* 10**i for i in range(11)]\n\n index = 0\n\n while True:\n if k<=num_arr[index]:\n break\n else:\n k -= num_arr[index]\n index += 1\n\n digit = index+1\n k += digit-1\n\n\n num = k//... | {"inputs": ["9\n", "2885\n", "3000\n", "7000\n", "9990\n", "9996\n", "10000\n", "1000000\n", "10000000000\n", "1000000000000\n", "8888888888\n", "788888888\n", "788888896\n", "68888887\n", "523452345325\n", "213412341\n"], "outputs": ["9\n", "9\n", "2\n", "2\n", "2\n", "7\n", "7\n", "1\n", "1\n", "1\n", "9\n", "9\n", "... | interview | https://codeforces.com/problemset/problem/1177/B | 16 | |
50 | Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!
In the morning, there are $n$ opportunities to buy shares. The $i$-th of them allows to buy as many shares as you want, each at the pri... | ["n, m, r = map(int, input().split())\nS = list(map(int, input().split()))\nB = list(map(int, input().split()))\nx = min(S)\ny = max(B)\ncnt = r % x\nact = r // x\ncnt += act * y\nprint(max(r, cnt))", "n, m, r = map(int, input().split())\nA = min(list(map(int, input().split())))\nB = max(list(map(int, input().split()))... | {"inputs": ["1 1 36\n5\n7\n", "5 3 20\n5 4 3 2 1\n6 7 1000\n", "28 29 1000\n555 962 781 562 856 700 628 591 797 873 950 607 526 513 552 954 768 823 863 650 984 653 741 548 676 577 625 902\n185 39 223 383 221 84 165 492 79 53 475 410 314 489 59 138 395 346 91 258 14 354 410 25 41 394 463 432 325\n", "1 10 10\n2\n4 5 10 ... | interview | https://codeforces.com/problemset/problem/1150/A | 16 | |
51 | Π ΠΠ΅ΡΠ»ΡΠ½Π΄ΡΠΊΠΎΠΌ Π³ΠΎΡΡΠ΄Π°ΡΡΡΠ²Π΅Π½Π½ΠΎΠΌ ΡΠ½ΠΈΠ²Π΅ΡΡΠΈΡΠ΅ΡΠ΅ Π»ΠΎΠΊΠ°Π»ΡΠ½Π°Ρ ΡΠ΅ΡΡ ΠΌΠ΅ΠΆΠ΄Ρ ΡΠ΅ΡΠ²Π΅ΡΠ°ΠΌΠΈ Π½Π΅ Π²ΡΠ΅Π³Π΄Π° ΡΠ°Π±ΠΎΡΠ°Π΅Ρ Π±Π΅Π· ΠΎΡΠΈΠ±ΠΎΠΊ. ΠΡΠΈ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΠ΅ Π΄Π²ΡΡ
ΠΎΠ΄ΠΈΠ½Π°ΠΊΠΎΠ²ΡΡ
ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΠΉ ΠΏΠΎΠ΄ΡΡΠ΄ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Π° ΠΎΡΠΈΠ±ΠΊΠ°, Π² ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠ΅ ΠΊΠΎΡΠΎΡΠΎΠΉ ΡΡΠΈ Π΄Π²Π° ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ ΡΠ»ΠΈΠ²Π°ΡΡΡΡ Π² ΠΎΠ΄Π½ΠΎ. ΠΡΠΈ ΡΠ°ΠΊΠΎΠΌ ΡΠ»ΠΈΡΠ½ΠΈΠΈ ΠΊΠΎΠ½Π΅Ρ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΡΠΎΠΎΠ±ΡΠ΅Π½ΠΈΡ ΡΠΎΠ²ΠΌΠ΅ΡΠ°Π΅ΡΡΡ Ρ Π½Π°ΡΠ°Π»ΠΎΠΌ Π²ΡΠΎΡΠΎΠ³ΠΎ. ΠΠΎΠ½Π΅ΡΠ½ΠΎ, ΡΠΎΠ²ΠΌΠ΅ΡΠ΅Π½ΠΈΠ΅ ΠΌΠΎ... | ["s = input()\nt = 0\nif len(s)%2==0:\n n = (len(s)-1)//2+1\nelse:\n n = (len(s)-1)//2\nfor i in range(n, len(s)-1):\n a = i\n b = len(s)-i-1\n if s[:a+1]==s[b:]:\n print('YES')\n print(s[:a+1])\n t = 1\n break\nif t==0:\n print('NO')", "a = input()\nif len(a)//2*2 == len(a... | {"inputs": ["zaz\n", "kkhuskkhusk\n", "esxwpesxwpesxwp\n", "ddoaxeaddoaxeaddoaxea\n", "ejfrayejfrayejfrayejfr\n", "qqgedqkewrelydzqqgedqkewrelydzq\n", "mtphoncwmtphoncwmtphoncwmtphoncw\n", "mnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnv\n", "awxmegcmrkzawxmegcmrkzawxmegcmrkzawxmegcmr\n", "sqdrmjqbfbmjmqfbcemrjtsqdrmjqbfbmjmqf... | interview | https://codeforces.com/problemset/problem/646/B | 16 | |
52 | Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are... | ["n = int(input())\nres = set()\nfor r in range(100):\n a = 1\n b = 2**(r + 1) - 3\n c = -2 * n\n d = b * b - 4 * a * c\n if d < 0:\n continue\n le = 0\n ri = d\n while le < ri:\n c = (le + ri) // 2\n if c * c < d:\n le = c + 1\n else:\n ri = c\n... | {"inputs": ["2\n", "314\n", "13\n", "105\n", "210\n", "255\n", "5460\n", "321730048\n", "38927073\n", "529914\n", "520088094975\n", "72315871219375\n", "5180726200\n", "431105316312401832\n", "434351073512812035\n", "402653184\n"], "outputs": ["-1\n", "-1\n", "-1\n", "15\n", "21\n120\n", "136\n256\n", "105\n1456\n", "-... | interview | https://codeforces.com/problemset/problem/325/B | 16 | |
53 | A string a of length m is called antipalindromic iff m is even, and for each i (1 β€ i β€ m) a_{i} β a_{m} - i + 1.
Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}... | ["from collections import Counter\n\nr = lambda: list(map(int, input().split()))\n\ndef main():\n\tn, = r()\n\ts = input()\n\tcost = list(r())\n\n\tans = 0\n\n\tcnt = Counter()\n\n\tfor i in range(n // 2):\n\t\tif s[i] == s[n - 1 - i]:\n\t\t\tans += min(cost[i], cost[n - 1 - i])\n\t\t\tcnt[s[i]] += 1\n\ttotal = sum(cnt... | {"inputs": ["8\nabacabac\n1 1 1 1 1 1 1 1\n", "100\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 74 94 42 22 43 4 41 88 87 44 85 76 20 5 5 36 50 90 78 63 84 93 47 33 ... | interview | https://codeforces.com/problemset/problem/884/F | 16 | |
54 | Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally ... | ["w,m=map(int,input().split())\n\nbb=True\n\nwhile(m>0 and bb):\n\tx=m%w\n\tif x==1:m-=1\n\telif x==w-1:m+=1\n\telif x!=0:bb=False\n\tm//=w\n\t\nif bb:print(\"YES\")\nelse:print(\"NO\")", "def f(w, m):\n\tif m == 0:\n\t\treturn True\n\tif m % w == 0:\n\t\treturn f(w, m // w)\n\tif (m - 1) % w == 0:\n\t\treturn f(w, (m ... | {"inputs": ["5077 5988\n", "5 41503906\n", "5 90332031\n", "91 8189\n", "27 14349609\n", "441890232 441890232\n", "48433217 48433216\n", "6 688005966\n", "3 130070951\n", "3 100000000\n", "3 100000002\n", "3 100000003\n", "2 1\n", "2 536870912\n", "3 26\n", "1000000000 1000000000\n"], "outputs": ["NO\n", "YES\n", "NO\n... | interview | https://codeforces.com/problemset/problem/552/C | 16 | |
55 | Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As t... | ["from collections import defaultdict\n\ndef solve(n, k):\n as_bin = bin(n)[2:]\n cnt = defaultdict(int)\n cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'})\n curr_len = len(cnt)\n curr_pow = len(as_bin) - 1\n\n if curr_len > k:\n return None\n\n while True:\n ne... | {"inputs": ["1 2\n", "192 4\n", "1656 5\n", "26076 8\n", "859274728393799260 30\n", "861753457928049532 30\n", "281474976710656 5\n", "901283150305558530 5\n", "287632104387196918 50\n", "141012366262272 1\n", "337790572680259391 29\n", "828935109688089201 59\n", "128233154575908599 39\n", "846113779983498737 9\n", "2 ... | interview | https://codeforces.com/problemset/problem/916/B | 16 | |
56 | Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (co... | ["n, t = list(map(int,input().split()))\ng = [[0.0] * i for i in range(1,n+1)]\n\n\nfor _ in range(t):\n g[0][0] += 1.0\n for i in range(n):\n for j in range(i+1):\n spill = max(0, g[i][j] - 1.0)\n g[i][j] -= spill\n if i < n - 1:\n g[i + 1][j] += spill / 2\n... | {"inputs": ["10 10000\n", "10 1022\n", "10 1024\n", "1 2\n", "7 128\n", "3 1\n", "4 14\n", "6 64\n", "7 126\n", "8 1\n", "9 513\n", "9 511\n", "9 200\n", "10 689\n", "3 4\n", "1 3\n"], "outputs": ["55\n", "53\n", "55\n", "1\n", "28\n", "1\n", "8\n", "21\n", "26\n", "1\n", "45\n", "45\n", "41\n", "53\n", "3\n", "1\n"]} | interview | https://codeforces.com/problemset/problem/676/B | 16 | |
57 | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | ["n = int(input())\npoints = [[int(x) for x in input().split()] for _ in range(n)]\nif n <= 1:\n\tprint(-1)\n\treturn\ndx = [1e9, -1e9]\ndy = [1e9, -1e9]\nfor x, y in points:\n\tdx[0] = min(dx[0], x)\n\tdx[1] = max(dx[1], x)\n\tdy[0] = min(dy[0], y)\n\tdy[1] = max(dy[1], y)\narea = (dx[1] - dx[0]) * (dy[1] - dy[0])\nif... | {"inputs": ["2\n-559 894\n314 127\n", "4\n-64 -509\n-64 960\n634 -509\n634 960\n", "1\n720 -200\n", "1\n-841 -121\n", "3\n-318 831\n450 31\n-318 31\n", "3\n0 0\n0 1\n1 0\n", "3\n0 0\n1 0\n1 1\n", "3\n1 1\n1 3\n3 1\n", "3\n0 0\n0 5\n5 5\n", "4\n0 1\n0 0\n1 0\n1 1\n", "3\n0 0\n10 0\n0 10\n", "3\n1 5\n2 2\n2 5\n", "3\n0 1... | interview | https://codeforces.com/problemset/problem/596/A | 16 | |
58 | Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.
Determine a minimal number of wooden bars which are needed t... | ["'''input\n6\n4\n2\n'''\n\ndef list_input():\n return list(map(int,input().split()))\ndef map_input():\n return map(int,input().split())\ndef map_string():\n return input().split()\n \ndef f(n,a,b,left,cnta = 4,cntb = 2):\n\tif(cnta == 0 and cntb == 0): return 0\n\tif(cnta < 0 or cntb < 0): return 10000000000... | {"inputs": ["20\n5\n6\n", "1\n1\n1\n", "3\n2\n1\n", "604\n356\n239\n", "80\n57\n31\n", "951\n225\n352\n", "380\n108\n356\n", "34\n5\n17\n", "162\n105\n160\n", "56\n37\n10\n", "324\n284\n26\n", "186\n98\n104\n", "5\n4\n2\n", "8\n4\n2\n", "100\n100\n50\n", "10\n4\n6\n"], "outputs": ["2\n", "6\n", "4\n", "4\n", "5\n", "2\... | interview | https://codeforces.com/problemset/problem/910/B | 16 | |
59 | You have an array a consisting of n integers. Each integer from 1 to n appears exactly once in this array.
For some indices i (1 β€ i β€ n - 1) it is possible to swap i-th element with (i + 1)-th, for other indices it is not possible. You may perform any number of swapping operations any order. There is no limit on the ... | ["n = int(input())\na = list(map(int,input().split()))\np = input()\nm = 0\nsuc = True\nfor i in range(n-1):\n m = max(m,a[i])\n if p[i] == '0' and m>(i+1):\n suc = False\n break\nif suc:\n print('YES')\nelse:\n print('NO')\n", "import getpass\nimport sys\nimport math\n\n\ndef ria():\n retu... | {"inputs": ["6\n1 2 5 3 4 6\n01010\n", "6\n1 6 3 4 5 2\n01110\n", "4\n1 3 4 2\n001\n", "6\n1 4 3 5 6 2\n01101\n", "10\n5 2 7 9 1 10 3 4 6 8\n111101000\n", "4\n3 1 2 4\n101\n", "4\n1 4 2 3\n010\n", "5\n3 1 5 2 4\n1011\n", "4\n2 1 4 3\n100\n", "5\n3 1 4 5 2\n1001\n", "3\n2 3 1\n10\n", "10\n6 5 9 4 3 2 8 10 7 1\n111111110... | interview | https://codeforces.com/problemset/problem/920/C | 16 | |
60 | A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats... | ["seat = input()\ntime_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3}\ncol = seat[-1]\nrow = int(seat[:-1])\nrow -= 1\n\nblocks_to_serve = row // 4\ntime = (6 * 2 + 4) * blocks_to_serve\n\nif row % 2 == 1:\n time += 6 + 1\n\ntime += time_to[col]\n\nprint(time)\n", "# You lost the game.\ns = str(input())\nl = ... | {"inputs": ["3b\n", "3f\n", "999999998a\n", "999999999f\n", "1000000000b\n", "100001d\n", "999999999999999997d\n", "999999999999999997f\n", "999999999999999998e\n", "1000000000000000000c\n", "999999999999999992a\n", "999999999999999992c\n", "999999999999999993d\n", "999999999999999994c\n", "999999999999999995f\n", "999... | interview | https://codeforces.com/problemset/problem/725/B | 16 | |
61 | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers.
-----Input-----
The first line... | ["n, bx = list(map(int, input().split()))\nx1 = list(map(int, input().split()))\nx = 0\nfor i in range(n):\n\tx *= bx\n\tx += x1[i]\n\nn, by = list(map(int, input().split()))\ny1 = list(map(int, input().split()))\ny = 0\nfor i in range(n):\n\ty *= by\n\ty += y1[i]\n\nif x == y:\n\tprint('=')\nelif x < y:\n\tprint('<')\... | {"inputs": ["2 2\n1 0\n2 3\n1 0\n", "2 2\n1 0\n1 3\n1\n", "4 7\n3 0 6 6\n3 11\n7 10 10\n", "2 4\n3 3\n2 15\n1 0\n", "2 35\n1 0\n2 6\n5 5\n", "2 40\n2 0\n5 13\n4 0 0 0 0\n", "5 3\n1 0 0 0 0\n4 27\n1 0 0 0\n", "10 38\n16 19 37 32 16 7 14 33 16 11\n10 39\n10 27 35 15 31 15 17 16 38 35\n", "7 39\n28 16 13 25 19 23 4\n7 38\... | interview | https://codeforces.com/problemset/problem/602/A | 16 | |
62 | Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.
BitLGM and Bi... | ["from math import *\nn=int(input())\nif n==3:\n li=list(map(int,input().split()))\n ans=0\n flag=0\n for i in li:\n ans^=i\n if ans==0:\n print(\"BitAryo\")\n else:\n print(\"BitLGM\")\nelif n==2:\n li=list(map(int,input().split()))\n li.sort()\n phi=(1+sqrt(5))/2\n c... | {"inputs": ["3\n1 2 1\n", "2\n9 10\n", "2\n41 29\n", "3\n103 286 100\n", "3\n244 241 295\n", "2\n218 142\n", "3\n134 244 95\n", "2\n159 98\n", "2\n144 233\n", "2\n251 155\n", "2\n15 9\n", "2\n124 194\n", "3\n222 129 95\n", "3\n70 45 107\n", "2\n298 281\n", "2\n299 299\n"], "outputs": ["BitLGM\n", "BitLGM\n", "BitLGM\n"... | interview | https://codeforces.com/problemset/problem/282/D | 16 | |
63 | Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck.
After receiving... | ["n,k=map(int,input().split())\nl=list(map(int,input().split()))\npf=[]\nneeded=[]\nfor i in range(2,40000):\n\tif k%i==0:\n\t\tpf.append(i)\n\t\tc=0\n\t\twhile k%i==0:\n\t\t\tk//=i\n\t\t\tc+=1\n\t\tneeded.append(c)\nif k>1:\n\tpf.append(k)\n\tneeded.append(1)\npfl=len(pf)\ncnt=[[0]*n for i in range(pfl)]\nfor i in ran... | {"inputs": ["100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\n", "2 999634589\n31607 31627\n", "1 7\n2\n", "1 10\n3\n", "2 5\n1 1\n", "2 7\n1 4\n", "3 1\n1 1 1\n... | interview | https://codeforces.com/problemset/problem/818/E | 16 | |
64 | One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} β lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloon... | ["alpha = [chr(ord('a')+i) for i in range(26)]\nn,k = list(map(int,input().split()))\ns = input()\narr = [s.count(alpha[i]) for i in range(26)]\n\nprint('YES' if max(arr) <= k else 'NO')\n", "n, k = map(int, input().split())\ns = input()\nd = {}\n\nfor el in s:\n if el in d:\n d[el] += 1\n else:\n d... | {"inputs": ["6 3\naacaab\n", "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii\n", "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdt... | interview | https://codeforces.com/problemset/problem/841/A | 16 | |
65 | You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
-----Input-----
The first line contains positive integer n (2 β€ n β€ 10^5) β size of the given array. The second... | ["n = int(input())\nA = [int(x) for x in input().split()]\nmn = min(A)\n\nI = [i for i in range(len(A)) if A[i] == mn]\nmindiff = min(I[i]-I[i-1] for i in range(1,len(I)))\nprint(mindiff)\n", "n = int(input())\nz = list(map(int, input().split()))\nfor i in range(n):\n z[i] = [z[i], i]\nz.sort()\nans = 1e9\nfor i in ... | {"inputs": ["5\n5 5 1 2 1\n", "3\n1000000000 1000000000 1000000000\n", "5\n1 3 2 3 1\n", "6\n1 2 2 2 2 1\n", "10\n2 2 2 3 3 1 3 3 3 1\n", "10\n1 3 2 4 5 5 4 3 2 1\n", "8\n1 2 2 2 1 2 2 2\n", "5\n3 3 1 2 1\n", "5\n4 4 2 5 2\n", "11\n2 2 2 2 2 2 1 1 2 2 2\n", "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n", "20\n2 2 2 2 2 ... | interview | https://codeforces.com/problemset/problem/911/A | 16 | |
66 | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.
[Image]
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.... | ["from fractions import gcd\n\nt,w,b = map(int,input().split())\nper = w*b//gcd(w,b)\ncan = (t//per+1)*min(w,b)-1\nif t%per<min(w,b):\n can-=min(w,b)\n can+=t%per+1\ng = gcd(can,t)\ncan//=g\nt//=g\nprint(str(can)+\"/\"+str(t))", "\nfrom fractions import gcd\na, b, c = list(map(int, input().split(' ')))\nl = b * c... | {"inputs": ["5814 31 7\n", "257593781689876390 32561717 4411677\n", "94268 714 345\n", "3898439 96326 71937\n", "329245015 1173508 8918834\n", "321076647734423976 7 7\n", "111319886766128339 7862842484895022 3003994959686829\n", "118289676 570846883 570846883\n", "917148533938841535 47 344459175789842163\n", "955944 12... | interview | https://codeforces.com/problemset/problem/592/C | 16 | |
67 | Nauuo is a girl who loves writing comments.
One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.
It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also another $z$ persons who would vote, but you don't know whether the... | ["x, y, z = map(int, input().split())\nif z == 0:\n if x == y:\n print('0')\n elif x > y:\n print('+')\n else:\n print('-')\nelse:\n if x > y + z:\n print('+') \n elif x + z < y:\n print('-')\n else:\n print('?')", "x, y, z = map(int, input().split())\nbest = ... | {"inputs": ["1 1 0\n", "0 0 1\n", "88 88 0\n", "100 0 100\n", "19 90 4\n", "58 97 4\n", "52 14 10\n", "80 29 11\n", "79 42 12\n", "60 33 15\n", "21 31 14\n", "58 83 39\n", "0 87 13\n", "5 3 3\n", "7 3 5\n", "5 1 6\n"], "outputs": ["0", "?", "0", "?", "-", "-", "+", "+", "+", "+", "?", "?", "-", "?", "?", "?"]} | interview | https://codeforces.com/problemset/problem/1173/A | 16 | |
68 | Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U β move from $(x, y)$ to $(x, y + 1)$; D β move from $(x, y)$ to $(x, y - 1)$; L β move from $(x, y)$ to $(x - 1, y)$; R β move from $(x, y)$ to $(x + 1... | ["# \nimport collections, atexit, math, sys, bisect \n\nsys.setrecursionlimit(1000000)\ndef getIntList():\n return list(map(int, input().split())) \n\ntry :\n #raise ModuleNotFoundError\n import numpy\n def dprint(*args, **kwargs):\n print(*args, **kwargs, file=sys.stderr)\n dprint('debug ... | {"inputs": ["1\nR\n1 0\n", "1\nR\n0 1\n", "10\nURLRLURLRL\n0 -2\n", "2\nRL\n-2 0\n", "13\nUDLUUDUULDDLR\n0 -1\n", "85\nURDDUUURDLURUDDRUDURUDDURUDLRDLLURDLDDLUDRDLDDLLRLUDLLRURUDULDURUDDRRUDULDLDUDLDDRDRL\n1 -8\n", "3\nLLD\n-2 -1\n", "55\nURRDRLLDRURDLRRRDRLRUURLRDRULURLULRURDULLDDDUUULLDRLLUD\n-6 -3\n", "4\nLURR\n0 0\... | interview | https://codeforces.com/problemset/problem/1073/C | 16 | |
69 | You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010...
Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of so... | ["t=int(input())\nfor i in ' '*t:\n n,x=map(int,input().split())\n s=input()\n L=[0]\n for i in s:\n if i=='0':L.append(L[-1]+1)\n else:L.append(L[-1]-1)\n L.pop(0)\n k=L[-1]\n c=0\n if x==0:c+=1\n if k>0:\n for i in L:\n if i%k==x%k and i<=x:c+=1\n prin... | {"inputs": ["1\n5 0\n01010\n", "1\n3 -1\n100\n", "1\n2 -1\n11\n", "1\n5 0\n00111\n", "1\n3 1\n010\n", "1\n6 2\n110000\n", "8\n9 0\n000111010\n15 5\n111010101100001\n11 0\n01010000010\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 -4\n01011101110100000\n17 -1\n00010101010101001\n", "8\n9 0\n000111010\n17 ... | interview | https://codeforces.com/problemset/problem/1295/B | 16 | |
70 | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the r... | ["s = input().split()\nk = int(s[1])\ns = s[0]\nif s.count('0') < k:\n if s.count('0') > 0:\n print(len(s) - 1)\n else:\n print(len(s))\n return\nhave = 0\nits = 0\nfor i in range(len(s) - 1, -1, -1):\n its += 1\n if s[i] == '0':\n have += 1\n if have == k:\n print(its - ha... | {"inputs": ["0 1\n", "10 1\n", "1010101010 7\n", "10001000 3\n", "10001000 4\n", "10001000 8\n", "1000000001 1\n", "1000000001 9\n", "1000 1\n", "309500 5\n", "44000 1\n", "320005070 6\n", "1011 2\n", "200 3\n", "1100000 6\n", "1003 3\n"], "outputs": ["0\n", "0\n", "9\n", "0\n", "1\n", "7\n", "1\n", "9\n", "0\n", "5\n"... | interview | https://codeforces.com/problemset/problem/779/B | 16 | |
71 | On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.
Seating in the class looks like a rectangle, where n rows with m pupils in each.
The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of t... | ["n, m, k, x, y = list(map(int, input().split()))\n\nans = [[0] * m for x in range(n)]\n\nonebig = (2*n-2)*m or m\n\noo = k // onebig\n\nfor i in range(n):\n for j in range(m):\n if i == 0 or i == n-1:\n ans[i][j] += oo\n k -= oo\n else:\n ans[i][j] += 2*oo\n ... | {"inputs": ["100 100 1000000000 16 32\n", "2 4 6 1 3\n", "2 5 36 1 3\n", "5 2 9 5 1\n", "2 1 1 1 1\n", "5 2 2 4 1\n", "1 1 1 1 1\n", "11 82 414861345 1 24\n", "18 83 706805205 1 17\n", "9 64 756016805 7 55\n", "7 32 461672865 4 11\n", "92 80 20 9 69\n", "63 22 1321 61 15\n", "76 74 1 38 39\n", "81 41 100000000000000000... | interview | https://codeforces.com/problemset/problem/758/C | 16 | |
72 | After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination... | ["turns = int(input())\ns0 = input()\ns1 = input()\ns2 = input()\n\nd0 = dict()\nd1 = dict()\nd2 = dict()\n\nalphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'\nfor char in alphabet:\n\td0[char] = 0\n\td1[char] = 0\n\td2[char] = 0\n\nfor char in s0:\n\td0[char] += 1\nfor char in s1:\n\td1[char] += 1\nfor... | {"inputs": ["1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb\n", "3\naaaaaaa\naaaabbb\nabcdefg\n", "3\naaaabb\naabcde\nabcdef\n", "3\naaaaaa\naaaaaa\nabcdef\n", "4\naaabbb\naabdef\nabcdef\n", "3\naaaaa\nabcda\nabcde\n", "3\naaaaaa\naabbcc\naabbcc\n", "3\nAAAAAA\nAAAAAB\nABCDEF\n", "3\naaaabb\naaabcd\nabcdef\n", "1\naacb\nabcd\na... | interview | https://codeforces.com/problemset/problem/979/B | 16 | |
73 | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_0 pages, at second... | ["read = lambda: map(int, input().split())\nc, v0, v1, a, l = read()\ncur = 0\ncnt = 0\nwhile cur < c:\n cur = max(0, cur - l)\n cur += min(v1, v0 + a * cnt)\n cnt += 1\nprint(cnt)", "c,v0,v1,a,l = map(int,input().split())\ncnt = 0\nans = 0\nv = v0\nwhile(cnt < c):\n\tcnt += v\n\tif(ans != 0):\n\t\tcnt -= l\n\... | {"inputs": ["1000 999 1000 1000 998\n", "1000 2 2 5 1\n", "1000 1 1000 1000 0\n", "1000 2 1000 802 0\n", "528 11 84 3 9\n", "1 5 5 1 1\n", "19 10 11 0 2\n", "1 2 3 0 0\n", "1000 5 9 5 0\n", "5 3 10 0 2\n", "8 3 5 1 0\n", "100 1 2 1000 0\n", "1 2 2 0 1\n", "7 3 6 2 2\n", "1000 500 900 100 300\n", "7 3 5 3 2\n"], "output... | interview | https://codeforces.com/problemset/problem/820/A | 16 | |
74 | Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 β€ i β€ k), such that
1 β€ k β€ 3
p_... | ["import math\n\nn=int(input())\n\ndef prime(p):\n if p == 1:\n return False\n fl=True\n for i in range(2,math.ceil(p**0.5) + 1):\n if p % i == 0:\n fl=False\n return fl\n\ndef sum_of_primes(k):\n fl=True\n for i in range((k // 2) + 1):\n if prime(i) and prime(k-i):\n ... | {"inputs": ["9\n", "7\n", "13\n", "19\n", "21\n", "867773\n", "784533\n", "9675\n", "999995339\n", "409449117\n", "182982365\n", "199998345\n", "199991935\n", "999995529\n", "999991797\n", "501148647\n"], "outputs": ["2\n2 7", "1\n7", "1\n13", "1\n19", "2\n2 19", "1\n867773", "3\n3 17 784513", "3\n3 11 9661", "3\n5 43 ... | interview | https://codeforces.com/problemset/problem/584/D | 16 | |
75 | You are given a description of a depot. It is a rectangular checkered field of n Γ m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column... | ["n, m = list(map(int, input().split()))\np = []\nans = 0\nfor i in range(n):\n s = input()\n ans += s.count('*')\n p.append(s)\ndp = []\nfor i in range(n):\n dp.append([0] * m)\nfor i in range(n):\n col = p[i].count('*')\n for t in range(m):\n dp[i][t] = col\nfor i in range(m):\n col = 0\n ... | {"inputs": ["1 10\n**********\n", "10 10\n..........\n..........\n.**....***\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "4 4\n*...\n*...\n....\n****\n", "4 4\n..*.\n....\n...*\n....\n", "2 2\n**\n**\n", "3 3\n...\n...\n...\n", "3 2\n.*\n*.\n.*\n", "3 3\n***\n.*.\n.*.\n", "3 ... | interview | https://codeforces.com/problemset/problem/699/B | 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.