input
stringlengths
52
10.1k
response
stringlengths
14
289k
test_cases
stringlengths
124
74M
difficulty
stringclasses
3 values
id
int64
1.6k
9.51k
problem_pass_rate
float64
0
1
test_case_pass_rates
listlengths
4
1.44k
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed. There are $n$ students, each of them has a unique id (from $1$ to $n$). Thomas's id is $1$. ...
def main(): n = int(input()) scores = [] for i in range(n): a = list(map(int, input().split())) tot = sum(a) scores.append((-tot, i)) scores.sort() for i in range(n): if scores[i][1] == 0: print(i + 1) main()
[{"input": "1\n0 0 0 0\n", "output": "1\n"}, {"input": "1\n15 71 57 86\n", "output": "1\n"}, {"input": "6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0\n", "output": "1\n"}, {"input": "5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99\n", "output": "2\n"}, {"...
competition
2,193
0.25
[ 0.65, 0.6, 0.5, 0.5, 0.35, 0.3, 0.25, 0.25 ]
Fox Ciel studies number theory. She thinks a non-empty set S contains non-negative integers is perfect if and only if for any $a, b \in S$ (a can be equal to b), $(a \text{xor} b) \in S$. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or). Please calculate the number of perfe...
from math import factorial MOD = 10**9+7 k = int(input()) bink = list(map(int, bin(k)[2:])) N = len(bink) # dp[i][j][k] = first i bits, j bases, # k = 1 if maxor matches k, 0 else dp = [[[0,0] for j in range(i+2)] for i in range(N+1)] dp[0][0][1] = 1 for i in range(1, N+1): for j in range(i+1): # k = 0 ...
[{"input": "1\n", "output": "2\n"}, {"input": "0\n", "output": "1\n"}, {"input": "2\n", "output": "3\n"}, {"input": "3\n", "output": "5\n"}, {"input": "9\n", "output": "19\n"}, {"input": "992170945\n", "output": "128578494\n"}, {"input": "985629174\n", "output": "785871406\n"}, {"input": "941492387\n", "output": "63713...
competition
8,762
0
[ 0.25, 0.25, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Berkomnadzor — Federal Service for Supervision of Communications, Information Technology and Mass Media — is a Berland federal executive body that protects ordinary residents of Berland from the threats of modern internet. Berkomnadzor maintains a list of prohibited IPv4 subnets (blacklist) and a list of allowed IPv4 ...
#!/usr/bin/env python3 # Copied solution import collections import sys import traceback class Input(object): def __init__(self): self.fh = sys.stdin def next_line(self): while True: line = sys.stdin.readline() if line == '\n': continue retur...
[{"input": "9\n-0.0.0.23\n+0.0.0.20/32\n+0.0.0.17\n+0.0.0.30/32\n+0.0.0.13/32\n+0.0.0.4\n+0.0.0.12\n+0.0.0.15/32\n+0.0.0.8/31\n", "output": "1\n0.0.0.22/31\n"}, {"input": "9\n-0.0.0.10/32\n-0.0.0.14/31\n-0.0.0.15/32\n-0.0.0.5/32\n-0.0.0.11/32\n-0.0.0.3\n-0.0.0.0/30\n-0.0.0.8/31\n-0.0.0.6/31\n", "output": "1\n0.0.0.0/0\...
competition
8,704
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0...
At a break Vanya came to the class and saw an array of $n$ $k$-bit integers $a_1, a_2, \ldots, a_n$ on the board. An integer $x$ is called a $k$-bit integer if $0 \leq x \leq 2^k - 1$. Of course, Vanya was not able to resist and started changing the numbers written on the board. To ensure that no one will note anythi...
from collections import defaultdict n, k = list(map(int, input().split())) a = [0] + list(map(int, input().split())) h = defaultdict(int) for i in range(n): a[i + 1] ^= a[i] for i in range(n + 1): h[min(a[i] ^ ((1 << k) - 1), a[i])] += 1 ans = 0 for x, t in list(h.items()): a = t // 2 b = t - a ans += a * (a - 1) ...
[{"input": "1 1\n1\n", "output": "1"}, {"input": "1 30\n405246759\n", "output": "1"}, {"input": "1 29\n266408128\n", "output": "1"}, {"input": "1 1\n0\n", "output": "1"}, {"input": "2 1\n1 0\n", "output": "2"}, {"input": "1 2\n3\n", "output": "1"}, {"input": "1 25\n0\n", "output": "1"}, {"input": "2 1\n1 1\n", "output"...
interview
6,281
0
[ 0.25, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.1, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river. "To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino. "See? The clouds are coming." Kanno gazes into the distance. "That can't be better...
# Codeforces Round #487 (Div. 2)import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) import bisect N,L,WM = getIntList() z = {} z[-1] = {1:[], -1:[]} z[0] = {1:[],...
[{"input": "1 100000000 98765432\n73740702 1\n", "output": "0\n"}, {"input": "2 5 1\n-2 1\n5 -1\n", "output": "1\n"}, {"input": "9 25000000 989\n-100000000 -1\n-75000000 1\n75000000 1\n50000000 -1\n-50000000 1\n0 1\n25000000 1\n-25000000 -1\n100000000 -1\n", "output": "11\n"}, {"input": "5 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7...
interview
6,771
0
[ 0.35, 0.2, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0, 0 ]
In AtCoder City, there are three stations numbered 1, 2, and 3. Each of these stations is operated by one of the two railway companies, A and B. A string S of length 3 represents which company operates each station. If S_i is A, Company A operates Station i; if S_i is B, Company B operates Station i. To improve the tra...
S = list(map(str,input())) if S[0] != S[1] or S[1] != S[2]: print("Yes") else: print("No")
[{"input": "BAA\n", "output": "Yes\n"}, {"input": "ABB\n", "output": "Yes\n"}, {"input": "AAB\n", "output": "Yes\n"}, {"input": "BBA\n", "output": "Yes\n"}, {"input": "BBB\n", "output": "No\n"}, {"input": "BAB\n", "output": "Yes\n"}, {"input": "ABA\n", "output": "Yes\n"}, {"input": "AAA\n", "output": "No\n"}]
introductory
9,399
0.35
[ 0.75, 0.75, 0.75, 0.7, 0.65, 0.65, 0.65, 0.6 ]
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible. A polyline defined by points p_1, p_2, p_3, p_4 consists of the line seg...
import math n, m = list(map(int, input().split())) if n == 0 : print(0, 1) print(0, m) print(0, 0) print(0, m - 1) elif m == 0 : print(1, 0) print(n, 0) print(0, 0) print(n - 1, 0) else : l = math.sqrt((n - 1) ** 2 + m ** 2) + math.sqrt(n ** 2 + m ** 2) + math.sqrt(n ** 2 + (m - 1)...
[{"input": "1 1\n", "output": "1 1\n0 0\n1 0\n0 1\n"}, {"input": "555 1\n", "output": "555 1\n0 0\n555 0\n0 1\n"}, {"input": "3 3\n", "output": "3 3\n0 0\n3 0\n0 3\n"}, {"input": "2 2\n", "output": "2 2\n0 0\n2 0\n0 2\n"}, {"input": "1000 2\n", "output": "1000 2\n0 0\n1000 0\n0 2\n"}, {"input": "100 3\n", "output": "10...
interview
5,239
0
[ 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
Convert integers to binary as simple as that. You would be given an integer as a argument and you have to return its binary form. To get an idea about how to convert a decimal number into a binary number, visit here. **Notes**: negative numbers should be handled as two's complement; assume all numbers are integers sto...
def to_binary(n): return "{:0b}".format(n & 0xffffffff)
[{"input": [999999], "output": ["11110100001000111111"]}, {"input": [7], "output": ["111"]}, {"input": [5], "output": ["101"]}, {"input": [4], "output": ["100"]}, {"input": [3], "output": ["11"]}, {"input": [2], "output": ["10"]}, {"input": [10], "output": ["1010"]}, {"input": [1000], "output": ["1111101000"]}, {"input...
introductory
4,531
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Create a function that interprets code in the esoteric language **Poohbear** ## The Language Poohbear is a stack-based language largely inspired by Brainfuck. It has a maximum integer value of 255, and 30,000 cells. The original intention of Poohbear was to be able to send messages that would, to most, be completely ...
from operator import add, mul, floordiv as fdiv, pow def poohbear(s): def updateMem(func, v): mem[p] = func(mem.get(p, 0), v) % 256 braces, stack = {}, [] for i,c in enumerate(s): if c == 'W': stack.append(i) if c == 'E': braces[i] = stack[-1] braces[stack.pop(...
[{"input": ["cW>LQQT+P<pE"], "output": [""]}, {"input": ["W>UQLIPNPPP45vSDFJLLIPNPqwVMT<E"], "output": [""]}, {"input": ["LLILQQLcYYD"], "output": [""]}, {"input": ["NNN++-NTTTTT+PN"], "output": ["0001!33"]}, {"input": ["LQTcQAP>pQBBTAI-PA-PPL+P<BVPAL+T+P>PL+PBLPBP<DLLLT+P"], "output": ["Hello World!"]}, {"input": ["LQ...
introductory
2,744
0
[ 0.35, 0.35, 0.35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips x - 1 consecutive bricks, then he paints the x-...
import fractions x, y, a, b = list(map(int, input().split())) d = fractions.gcd(x, y) d = x * y // d print(b // d - (a - 1) // d)
[{"input": "3 2 5 5\n", "output": "0"}, {"input": "2 3 7 7\n", "output": "0"}, {"input": "1000 1000 1 20\n", "output": "0"}, {"input": "819 1000 10000 1000000\n", "output": "1"}, {"input": "555 777 1 1000000\n", "output": "257"}, {"input": "45 125 93451125 100000000\n", "output": "5821"}, {"input": "4 6 20 201\n", "out...
interview
5,733
0.05
[ 0.85, 0.8, 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ]
Alice lives on a flat planet that can be modeled as a square grid of size $n \times n$, with rows and columns enumerated from $1$ to $n$. We represent the cell at the intersection of row $r$ and column $c$ with ordered pair $(r, c)$. Each cell in the grid is either land or water. [Image] An example planet with $n = 5...
n = int(input()) r1, c1 = map(int, input().split()) r2, c2 = map(int, input().split()) a = [['1'] * (n + 2)] for _ in range(n): s = input() d = ['1'] for i in s: d.append(i) d.append('1') a.append(d) a.append(['1'] * (n + 2)) s = [] f = [] q = [[r1, c1]] while q: x, y = q.pop() a[x][...
[{"input": "1\n1 1\n1 1\n0\n", "output": "0\n"}, {"input": "5\n1 3\n5 3\n00000\n11110\n00000\n01111\n00000\n", "output": "0\n"}, {"input": "5\n1 1\n5 5\n00001\n11111\n00111\n00110\n00110\n", "output": "10\n"}, {"input": "7\n4 5\n1 2\n0001000\n0111110\n0110110\n1100011\n0110110\n0111110\n0001000\n", "output": "5\n"}, {"...
interview
7,009
0
[ 0.2, 0.05, 0.05, 0, 0, 0, 0, 0 ]
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
T=int(input()) answer=[] for t in range(T): A,B=input().split() A=int(A) B=int(B) x=0 if(A>B): r=B B=A A=r while(A>0 and B>0): r=B//A x+=r r*=A B=B-r if(A>B): r=B B=A A=r answer.append(x) for...
[{"input": "1\n536870912 32\n", "output": "16777216\n"}, {"input": "3\n1000000000 1\n1000000000 1\n1 100000000\n", "output": "1000000000\n1000000000\n100000000\n"}, {"input": "2\n4 17\n7 987654321\n", "output": "8\n141093479\n"}, {"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 98765432...
interview
7,363
0.15
[ 0.35, 0.2, 0.15, 0.15 ]
Given are three positive integers A, B, and C. Compute the following value modulo 998244353: \sum_{a=1}^{A} \sum_{b=1}^{B} \sum_{c=1}^{C} abc -----Constraints----- - 1 \leq A, B, C \leq 10^9 -----Input----- Input is given from standard input in the following format: A B C -----Output----- Print the value modulo 998...
A,B,C=map(int,input().split()) mod=998244353 ans=A*(A+1)*B*(B+1)*C*(C+1)//8 print(ans%mod)
[{"input": "88 395 518\n", "output": "572699487\n"}, {"input": "198 235 277\n", "output": "518269127\n"}, {"input": "1 2 3\n", "output": "18\n"}, {"input": "693 299 737\n", "output": "373149185\n"}, {"input": "682152024 451794315 2028038\n", "output": "579633067\n"}, {"input": "264704198 120999147 136987925\n", "output...
interview
7,087
0.1
[ 0.3, 0.3, 0.3, 0.1, 0.1, 0.1, 0.1, 0.1 ]
This is related to my other Kata about cats and dogs. # Kata Task I have a cat and a dog which I got as kitten / puppy. I forget when that was, but I do know their current ages as `catYears` and `dogYears`. Find how long I have owned each of my pets and return as a list [`ownedCat`, `ownedDog`] NOTES: * Results ar...
def owned_cat_and_dog(cy, dy): cat = 0 if cy < 15 else 1 if cy < 24 else 2 + (cy - 24) // 4 dog = 0 if dy < 15 else 1 if dy < 24 else 2 + (dy - 24) // 5 return [cat, dog]
[{"input": [9, 7], "output": [[0, 0]]}, {"input": [56, 64], "output": [[10, 10]]}, {"input": [27, 27], "output": [[2, 2]]}, {"input": [26, 26], "output": [[2, 2]]}, {"input": [25, 25], "output": [[2, 2]]}, {"input": [24, 24], "output": [[2, 2]]}, {"input": [19, 17], "output": [[1, 1]]}, {"input": [18, 21], "output": [[...
introductory
3,542
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
There are N mountains ranging from east to west, and an ocean to the west. At the top of each mountain, there is an inn. You have decided to choose where to stay from these inns. The height of the i-th mountain from the west is H_i. You can certainly see the ocean from the inn at the top of the westmost mountain. For t...
N = int(input()) H = list(map(int,input().split())) top = H[0] cnt = 1 for i in range(1,N): if top <= H[i]: cnt += 1 top = H[i] print(cnt)
[{"input": "1\n1\n", "output": "1\n"}, {"input": "2\n75 26\n", "output": "1\n"}, {"input": "20\n98 90 80 71 65 63 56 51 49 48 45 43 42 39 36 34 33 29 4 2\n", "output": "1\n"}, {"input": "20\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n", "output": "20\n"}, {"input": "5\n9 5 6 8 4\n"...
introductory
9,318
0.55
[ 0.95, 0.8, 0.8, 0.8, 0.75, 0.75, 0.7, 0.65, 0.65, 0.65, 0.6, 0.6 ]
Let $s$ be some string consisting of symbols "0" or "1". Let's call a string $t$ a substring of string $s$, if there exists such number $1 \leq l \leq |s| - |t| + 1$ that $t = s_l s_{l+1} \ldots s_{l + |t| - 1}$. Let's call a substring $t$ of string $s$ unique, if there exist only one such $l$. For example, let $s = ...
n,k=list(map(int,input().split())) x=(n-(k-1)+1)//2 STR="0"*(x-1)+"1" ANS=STR*(n//x+1) print(ANS[:n])
[{"input": "1 1\n", "output": "1"}, {"input": "6 6\n", "output": "111111"}, {"input": "5 5\n", "output": "11111"}, {"input": "4 4\n", "output": "1111"}, {"input": "3 3\n", "output": "111"}, {"input": "2 2\n", "output": "11"}, {"input": "5 3\n", "output": "01010"}, {"input": "3 1\n", "output": "010"}, {"input": "87 43\n...
competition
8,995
0
[ 0.35, 0.15, 0.15, 0.15, 0.15, 0.15, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15...
import sys f = sys.stdin #f = open("input.txt", "r") a = [list(map(int, i.split())) for i in f.read().strip().split("\n")] def solve(): s = a[0][2] + a[2][0] for i in range(1, s): a[0][0] = i a[2][2] = s-i if sum(a[0]) == sum(a[2]): break a[1][1] = sum(a[0]) - sum(a[1]) ...
[{"input": "0 1 1\n1 0 1\n1 1 0\n", "output": "1 1 1\n1 1 1\n1 1 1\n"}, {"input": "0 99978 99920\n99950 0 99918\n99948 99890 0\n", "output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964\n"}, {"input": "0 99626 99582\n99766 0 99258\n99442 99398 0\n", "output": "99328 99626 99582\n99766 99512 99258\n99442 993...
interview
6,112
0
[ 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
## Objective Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Write a function that takes `n` and returns it's sXORe. ## Examples | n | sXORe n |---------|-------- | 0 | 0 ...
def sxore(n): return [n, 1, n + 1, 0][n % 4]
[{"input": [9999999999999999999999999], "output": [0]}, {"input": [50], "output": [51]}, {"input": [2], "output": [3]}, {"input": [1], "output": [1]}, {"input": [1000001], "output": [1]}, {"input": [1000000], "output": [1000000]}, {"input": [0], "output": [0]}]
introductory
4,628
0
[ 0, 0, 0, 0, 0, 0, 0 ]
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have long been recognized out of date, so the decision was made to asphal...
n = int(input()) h = [False] * n v = [False] * n result = [ ] for i in range(n * n): a, b = list(map(int, input().split())) a -= 1 b -= 1 if not h[a] and not v[b]: h[a] = v[b] = True result.append(i + 1) print(' '.join(map(str, result)))
[{"input": "1\n1 1\n", "output": "1 \n"}, {"input": "2\n1 1\n1 2\n2 1\n2 2\n", "output": "1 4 \n"}, {"input": "9\n9 9\n5 5\n8 8\n3 3\n2 2\n6 6\n4 4\n1 1\n7 7\n8 4\n1 4\n1 5\n5 7\n7 8\n7 1\n1 7\n8 7\n7 5\n3 7\n5 6\n7 3\n5 2\n3 6\n7 4\n9 6\n5 8\n9 7\n6 3\n7 9\n1 2\n4 5\n6 2\n5 3\n7 2\n1 6\n4 1\n6 1\n8 9\n2 3\n3 9\n2 9\n5...
interview
6,839
0.1
[ 0.4, 0.25, 0.2, 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 ]
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is ...
def __starting_point(): n = int( input() ) maxX = [-1]*100005 for _ in range(n): px,py = [int(x) for x in input().split()] maxX[py] = max( maxX[py] , px ) #print( maxX[:2] ) w = [int(x) for x in input().split()] p = [-1]*100005 p[0] = 0 wdict = dict() wdict[0] = ...
[{"input": "1\n0 0\n0\n", "output": "YES\n0 0\n"}, {"input": "2\n0 0\n1 0\n-1 0\n", "output": "NO\n"}, {"input": "31\n0 0\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 0\n1 1\n1 2\n1 3\n1 4\n1 5\n2 0\n2 1\n2 2\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n-8 1 4 -11 0 -4 -10 3 4 -5 -9 8 7 6 2 -2 -...
interview
6,636
0
[ 0.45, 0.4, 0.35, 0.35, 0.3, 0.25, 0.2, 0.05, 0.05, 0.05, 0, 0, 0, 0 ]
There are $n$ pillars aligned in a row and numbered from $1$ to $n$. Initially each pillar contains exactly one disk. The $i$-th pillar contains a disk having radius $a_i$. You can move these disks from one pillar to another. You can take a disk from pillar $i$ and place it on top of pillar $j$ if all these condition...
n = int(input()) a = list(map(int, input().split())) idx = list(range(n)) idx.sort(key=lambda i: a[i], reverse=True) imin = imax = idx[0] for i in idx[1:]: if i == imin - 1 or i == imax + 1: imin = min(imin, i) imax = max(imax, i) else: print('NO') return print('YES')
[{"input": "6\n6 5 4 3 1 2\n", "output": "NO\n"}, {"input": "6\n3 1 2 6 5 4\n", "output": "NO\n"}, {"input": "4\n2 1 4 3\n", "output": "NO\n"}, {"input": "10\n1 2 4 3 5 10 9 8 7 6\n", "output": "NO\n"}, {"input": "5\n3 1 5 4 2\n", "output": "NO\n"}, {"input": "5\n2 1 5 4 3\n", "output": "NO\n"}, {"input": "5\n3 4 5 1 2...
interview
6,377
0
[ 0.55, 0.55, 0.55, 0.55, 0.5, 0.5, 0.45, 0.45, 0.4, 0.35, 0.35, 0.35, 0.25, 0.25, 0.25, 0.25, 0.15, 0.15 ]
###Story Sometimes we are faced with problems when we have a big nested dictionary with which it's hard to work. Now, we need to solve this problem by writing a function that will flatten a given dictionary. ###Info Python dictionaries are a convenient data type to store and process configurations. They allow you to s...
def flatten(dictionary): stack = [((), dictionary)] result = {} while stack: path, current = stack.pop() for k, v in current.items(): if v == {}: result["/".join((path + (k,)))] = ""; if isinstance(v, dict): stack.append((path + (k,), v...
[{"input": [{"key": {"deeper": {"more": {"enough": "value"}}}}], "output": [{"key/deeper/more/enough": "value"}]}, {"input": [{"key": "value"}], "output": [{"key": "value"}]}, {"input": [{"job": {"1": "scout", "2": "worker", "3": "writer", "4": "reader", "5": "learner"}, "name": {"nick": {}, "last": "Drone", "first": "...
introductory
2,908
0
[ 0, 0, 0, 0, 0, 0, 0 ]
You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array. -----Input----- The first line...
def main(): s, k = map(int, input().split()) n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) if (a[n - 1] < b[-m]): print("YES") else: print("NO") main()
[{"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7\n", "output": "NO\n"}, {"input": "3 3\n2 2\n1 2 3\n1 2 3\n", "output": "NO\n"}, {"input": "5 2\n3 1\n1 1 1 1 1\n2 2\n", "output": "YES\n"}, {"input": "3 4\n2 2\n5 6 7\n1 2 3 4\n", "output": "NO\n"}, {"input": "3 3\n1 1\n3 3 3\n2 2 2\n", "output": "NO\n"}, {"input": "1 1\n1 1\n...
interview
6,232
0
[ 0.65, 0.6, 0.55, 0.55, 0.55, 0.55, 0.5, 0.5, 0.5, 0.45, 0.45, 0.4, 0.35, 0.3, 0.3, 0.2, 0.2, 0.15, 0.1, 0.05, 0.05 ]
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower...
def mat(shape, inital_val=None): if len(shape) > 1: return [mat(shape[1:], inital_val) for _ in range(shape[0])] else: return [inital_val] * shape[0] def main(): n, m = [int(x) for x in input().split()] graph = [{} for _ in range(n)] for _ in range(m): v, u, c ...
[{"input": "8 20\n2 4 a\n1 8 a\n1 2 v\n8 4 h\n1 7 w\n5 4 h\n2 8 h\n7 4 i\n4 3 w\n6 8 l\n1 4 v\n1 3 g\n5 3 b\n1 6 a\n7 3 w\n6 4 f\n6 7 g\n7 8 n\n5 8 g\n2 6 j\n", "output": "BAAAAAAA\nBBAAAABA\nBBBBBBBB\nBAABAABA\nBAAABABA\nBAAAABAA\nBAAAAABA\nBAAABABB\n"}, {"input": "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\...
competition
2,239
0
[ 0, 0, 0, 0, 0 ]
Vasya owns a cornfield which can be defined with two integers $n$ and $d$. The cornfield can be represented as rectangle with vertices having Cartesian coordinates $(0, d), (d, 0), (n, n - d)$ and $(n - d, n)$. [Image] An example of a cornfield with $n = 7$ and $d = 2$. Vasya also knows that there are $m$ grasshopp...
n, d = list(map(int, input().split())) for i in range(int(input())): x, y = list(map(int, input().split())) print(('YES' if x+y in range(d, n + n - d + 1) and x-y in range(-d, d + 1) else 'NO'));
[{"input": "2 1\n50\n1 2\n2 1\n0 1\n0 1\n1 2\n1 2\n2 1\n0 1\n0 1\n2 1\n1 0\n0 1\n1 0\n1 2\n0 1\n0 1\n0 1\n1 0\n1 0\n1 2\n2 1\n1 0\n0 1\n1 0\n0 1\n1 2\n2 1\n2 1\n0 1\n2 1\n0 1\n2 1\n2 1\n2 1\n1 2\n1 2\n0 1\n0 1\n2 1\n2 1\n2 1\n0 1\n2 1\n1 0\n1 0\n0 1\n1 0\n0 1\n0 1\n1 0\n", "output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\n...
interview
6,448
0
[ 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.1, 0.05, 0, 0, 0, 0, 0 ]
La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes. -----Constraints----- - N is an integer betwee...
N=int(input()) ans ="No" for i in range(N//4+1): for j in range(N//7+1): if 4*i + 7*j == N: ans = "Yes" print(ans)
[{"input": "4\n", "output": "Yes\n"}, {"input": "8\n", "output": "Yes\n"}, {"input": "56\n", "output": "Yes\n"}, {"input": "40\n", "output": "Yes\n"}, {"input": "20\n", "output": "Yes\n"}, {"input": "1\n", "output": "No\n"}, {"input": "16\n", "output": "Yes\n"}, {"input": "12\n", "output": "Yes\n"}, {"input": "100\n", ...
introductory
9,113
0.1
[ 0.75, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6, 0.6, 0.55, 0.5, 0.4, 0.3, 0.3, 0.25 ]
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height $h$, and there is a moving platform on each height $x$ from $1$ to $h$. Each platform is either hidden inside the cliff or moved out. At first, there are $n$ moved out...
import sys import math from collections import defaultdict from itertools import combinations from itertools import permutations input = lambda : sys.stdin.readline().rstrip() read = lambda : list(map(int, input().split())) def write(*args, sep="\n"): for i in args: sys.stdout.write("{}".format(i) + sep) INF = fl...
[{"input": "1\n3 2\n3 2\n", "output": "1\n"}, {"input": "4\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n1 1\n1\n", "output": "0\n1\n2\n0\n"}, {"input": "4\n1 1\n1\n3 2\n3 1\n8 6\n8 7 6 5 3 2\n9 6\n9 8 5 4 3 1\n", "output": "0\n0\n1\n2\n"}, {"input": "28\n8 4\n8 7 6 3\n8 5\n8 7 6 3 1\n8 5\n8 7 6 3 2\n8 6\n8 7 6 3 2 1\...
interview
7,340
0
[ 0.35, 0, 0, 0 ]
It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets. You have to write a function that returns a list of statements that are contained within brackets given a string. If the value entere...
import re REGEX = re.compile(r'\[(.*?)\]') def bracket_buster(strng): try: return REGEX.findall(strng) except TypeError: return 'Take a seat on the bench.'
[{"input": [{"3": 4}], "output": ["Take a seat on the bench."]}, {"input": [false], "output": ["Take a seat on the bench."]}, {"input": [[1, 2, 3]], "output": ["Take a seat on the bench."]}, {"input": [23.45], "output": ["Take a seat on the bench."]}, {"input": ["logger?]?system...12.12.133333 at [12-32-1432-16]"], "ou...
introductory
3,337
0
[ 0, 0, 0, 0, 0, 0, 0, 0 ]
Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \leq B \leq C \leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A \leq x \leq B \leq y \leq C \leq z \leq D$ holds? Yuri is prepari...
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): a, b, c, d = nm() m = 10**6 + 10 ...
[{"input": "500000 500000 500000 500000\n", "output": "1\n"}, {"input": "1 2 2 5\n", "output": "3\n"}, {"input": "1 2 3 4\n", "output": "4\n"}, {"input": "98317 181655 318381 472773\n", "output": "822189244343120\n"}, {"input": "90528 225462 336895 417903\n", "output": "1043176084391535\n"}, {"input": "89222 306288 442...
interview
5,738
0
[ 0.2, 0.15, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t...
from collections import namedtuple from operator import itemgetter Friend = namedtuple("Friend", "m s") n, d = list(map(int, input().split())) f = [ ] for i in range(n): f.append(Friend(*list(map(int, input().split())))) f.sort(key=itemgetter(0)) left = 0 cur = f[0].s result = cur for i, fr in enumerate(f[1:],...
[{"input": "1 1000000000\n15 12\n", "output": "12\n"}, {"input": "3 1\n801 10101\n802 134509124\n801 1\n", "output": "134509124\n"}, {"input": "5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n", "output": "3989899086\n"}, {"input": "4 5\n75 5\n0 100\n150 20\n75 1\n", "output": "100\n"}, {"input": "3 3\...
interview
6,573
0
[ 0.5, 0.35, 0.3, 0.3, 0.3, 0.25, 0.15, 0.1, 0, 0, 0, 0, 0, 0, 0 ]
Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this kata.
def reverse_alternate(string): return " ".join(y[::-1] if x%2 else y for x,y in enumerate(string.split()))
[{"input": [" "], "output": [""]}, {"input": ["This is not a test "], "output": ["This si not a test"]}, {"input": ["This is a test "], "output": ["This si a tset"]}, {"input": ["Reverse this string, please!"], "output": ["Reverse siht string, !esaelp"]}, {"input": ["I really hope it works this time..."], "out...
introductory
4,100
0
[ 1, 0, 0, 0, 0, 0, 0 ]
Elections in Berland are coming. There are only two candidates — Alice and Bob. The main Berland TV channel plans to show political debates. There are $n$ people who want to take part in the debate as a spectator. Each person is described by their influence and political views. There are four kinds of political views:...
n=int(input()) a=[];b=[];c=[];d=[] for i in range(n): opt,num=[int(x) for x in input().split()] if opt==0: a.append(num) if opt==10: b.append(num) if opt==1: c.append(num) if opt==11: d.append(num) ans=0 ans+=sum(d) b.sort(reverse=True) c.sort(reverse=True) if len(b)<...
[{"input": "4\n00 10\n00 3\n00 16\n00 13\n", "output": "0\n"}, {"input": "1\n00 4\n", "output": "0\n"}, {"input": "1\n00 1\n", "output": "0\n"}, {"input": "3\n00 5000\n00 5000\n00 5000\n", "output": "0\n"}, {"input": "1\n00 5000\n", "output": "0\n"}, {"input": "2\n00 1\n10 1\n", "output": "0\n"}, {"input": "1\n10 5000\...
competition
8,836
0
[ 0.3, 0.3, 0.3, 0.25, 0.25, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
import collections as col import itertools as its import sys import operator from bisect import bisect_left, bisect_right from copy import copy, deepcopy from math import factorial as fact class Solver: def __init__(self): pass def solve(self): n, t, k, d = list(map(int, input().split())) ...
[{"input": "1000 22 79 552\n", "output": "NO\n"}, {"input": "9 6 6 3\n", "output": "YES\n"}, {"input": "882 2 21 219\n", "output": "NO\n"}, {"input": "8 6 4 5\n", "output": "YES\n"}, {"input": "428 13 6 272\n", "output": "YES\n"}, {"input": "342 69 50 425\n", "output": "NO\n"}, {"input": "3 2 1 1\n", "output": "YES\n"}...
competition
8,707
0.05
[ 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.5...
Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible improvements he can think of during the day (he now prefers to sleep at nigh...
def main(): def countchildren(graph,vert,memo,pard=None): dumi=0 for child in graph[vert]: if child!=pard: if len(graph[child])==1: memo[child]=0 else: memo[child]=countchildren(graph,child,memo,vert)[0] ...
[{"input": "2\n2 1\n", "output": "1\n"}, {"input": "4\n1 2\n2 3\n3 4\n", "output": "7\n"}, {"input": "4\n1 2\n1 3\n1 4\n", "output": "6\n"}, {"input": "3\n2 1\n3 2\n", "output": "3\n"}, {"input": "10\n2 3\n3 9\n6 3\n9 8\n9 10\n4 8\n3 1\n3 5\n7 1\n", "output": "67\n"}]
competition
2,235
0
[ 0.05, 0, 0, 0, 0 ]
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '$\rightarrow$', and the arguments and the result of the implication are written as '0' (false) and '1'...
x = int(input()) seq = list(map(int, input().split(' '))) if seq == [0]: print("YES") print(0) elif seq == [0, 0]: print("NO") elif seq == [1, 0]: print("YES") print('1->0') elif seq == [0, 0, 0]: print("YES") print("(0->0)->0") elif seq == [1, 0, 0]: print("NO") elif seq[x-1] == ...
[{"input": "5\n1 1 1 1 1\n", "output": "NO\n"}, {"input": "4\n1 1 1 1\n", "output": "NO\n"}, {"input": "3\n1 1 1\n", "output": "NO\n"}, {"input": "2\n1 1\n", "output": "NO\n"}, {"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "NO\n"}, {"input": "6\n1 1 1 1 0 0\n", "output": "NO\n"}, {"input": "5\n1 ...
interview
5,174
0
[ 0.3, 0.3, 0.3, 0.3, 0.3, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.05, 0, 0,...
# Sentence Smash Write a function that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word. **Be careful, there shouldn't be a space at the beginning or the end of the sente...
def smash(words): return " ".join(words)
[{"input": [[]], "output": [""]}, {"input": [["this", "is", "a", "really", "long", "sentence"]], "output": ["this is a really long sentence"]}, {"input": [["hello"]], "output": ["hello"]}, {"input": [["hello", "world"]], "output": ["hello world"]}, {"input": [["hello", "amazing", "world"]], "output": ["hello amazing wo...
introductory
3,819
0
[ 0, 0, 0, 0, 0 ]
One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... -----Input----- The only line of input data contain...
res = 0 val = 0 sub = False for c in input()+'+': if c == '+' or c == '-': if sub: val *= -1 res += val val = 0 sub = (c == '-') val *= 10 val += ord(c) - ord('0') print(res)
[{"input": "8-7+6-5+4-3+2-1-0\n", "output": "4\n"}, {"input": "5-9-1-3+6+4-7+8-2\n", "output": "1\n"}, {"input": "97+67+12+9+42+45+13\n", "output": "-2265\n"}, {"input": "9-8+7-6+5-4+3-2+1-0\n", "output": "-45\n"}, {"input": "9-109-22+23-87+27-40+10\n", "output": "2211\n"}, {"input": "66-165-34+209+76\n", "output": "-2...
introductory
9,104
0
[ 0.3, 0.25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams. After practice competition, participant number i got a score of a_{i}. Tea...
a = list(map(int, input().split())) s = sum(a) for i in range(6): for j in range(i): for k in range(j): ss = a[i] + a[j] + a[k] if ss == s - ss: print('YES') return print('NO')
[{"input": "417 666 978 553 271 488\n", "output": "NO\n"}, {"input": "353 313 327 470 597 31\n", "output": "NO\n"}, {"input": "20 10 1 2 3 44\n", "output": "NO\n"}, {"input": "100 496 1 1 1 1\n", "output": "NO\n"}, {"input": "10 10 1 1 1 37\n", "output": "NO\n"}, {"input": "1 6 6 1 20 2\n", "output": "NO\n"}, {"input":...
interview
5,395
0
[ 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.8, 0.75, 0.75, 0.75, 0.75, 0.5, 0.45, 0.25, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0....
In this Kata, you will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows. ```Haskell Solve("*'&ABCDabcde12345") = [4,5,5,3]. --the order is: uppercase letters, lowercase, numbers and special characters. ``` ...
def solve(s): uc, lc, num, sp = 0, 0, 0, 0 for ch in s: if ch.isupper(): uc += 1 elif ch.islower(): lc += 1 elif ch.isdigit(): num += 1 else: sp += 1 return [uc, lc, num, sp]
[{"input": ["bgA5<1d-tOwUZTS8yQ"], "output": [[7, 6, 3, 2]]}, {"input": ["RYT'>s&gO-.CM9AKeH?,5317tWGpS<*x2ukXZD"], "output": [[15, 8, 6, 9]]}, {"input": ["P*K4%>mQUDaG$h=cx2?.Czt7!Zn16p@5H"], "output": [[9, 9, 6, 9]]}, {"input": ["Codewars@codewars123.com"], "output": [[1, 18, 3, 2]]}, {"input": ["@mw>0=QD-iAx!rp9TaG?...
introductory
4,691
0
[ 0, 0, 0, 0, 0, 0 ]
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one...
n, m = map(int,input().split()) for i in range(m): a, *b = map(int,input().split()) b = set(b) for j in b: if -j in b: break else: print("YES") break else: print("NO")
[{"input": "4 2\n3 -1 1 2\n3 -2 4 3\n", "output": "YES\n"}, {"input": "1 2\n2 1 1\n2 -1 -1\n", "output": "YES\n"}, {"input": "4 2\n1 -3\n4 -2 3 2 -3\n", "output": "YES\n"}, {"input": "4 1\n3 1 1 -1\n", "output": "NO\n"}, {"input": "10000 1\n2 -6748 6748\n", "output": "NO\n"}, {"input": "1 2\n2 1 -1\n2 -1 -1\n", "output...
interview
5,901
0
[ 0.35, 0.35, 0.3, 0.3, 0.3, 0.3, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.1, 0.1 ]
Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers. Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position ...
n,m,k=map(int,input().split()) print(m*(m-1)//2) for i in range(n): a=list(map(int,input().split())) if k==0: for i in range(m): for j in range(i+1,m): print(i+1,j+1) else: for i in range(m): for j in range(i+1,m): print(j+1,i+1)
[{"input": "2 1 0\n1\n2\n", "output": "0\n"}, {"input": "1 1 1\n1\n", "output": "0\n"}, {"input": "1 1 0\n1\n", "output": "0\n"}, {"input": "2 5 0\n836096 600367 472071 200387 79763\n714679 505282 233544 157810 152591\n", "output": "10\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n"}, {"input": "2 2 1\n2 1\n3 1\n"...
interview
7,213
0
[ 0.35, 0.35, 0.35, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0 ]
You have a set of $n$ weights. You know that their masses are $a_1$, $a_2$, ..., $a_n$ grams, but you don't know which of them has which mass. You can't distinguish the weights. However, your friend does know the mass of each weight. You can ask your friend to give you exactly $k$ weights with the total mass $m$ (both...
from collections import defaultdict def calcBinomials(N): nonlocal binom N += 1 binom = [[0]*N for _ in range(N)] for n in range(N): binom[n][0] = binom[n][n] = 1 for k in range(1, n): binom[n][k] = binom[n-1][k] + binom[n-1][k-1] n = int(input()) a = list(map(int, input()....
[{"input": "1\n1\n", "output": "1\n"}, {"input": "2\n1 1\n", "output": "2\n"}, {"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\n", "output": "1\n"}, {"input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
competition
8,927
0
[ 0.65, 0.45, 0.35, 0.35, 0.3, 0.25, 0.25, 0.15, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition. The binary number returned should be a string.
def add_binary(a,b): return bin(a+b)[2:]
[{"input": [51, 12], "output": ["111111"]}, {"input": [5, 9], "output": ["1110"]}, {"input": [4096, 1], "output": ["1000000000001"]}, {"input": [2, 2], "output": ["100"]}, {"input": [100, 100], "output": ["11001000"]}, {"input": [10, 10], "output": ["10100"]}, {"input": [1, 1], "output": ["10"]}, {"input": [1, 0], "out...
introductory
3,674
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ...
import math, re, itertools as it;prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0;gcd = lambda a, b: gcd(b, a % b) if b else a;fact = lambda x: x * fact(x - 1) if x else 1;bino = lambda n, k: fact(n) / fact(k) / fact(n - k);fib11 = lambda n: 1 if n < 2 else fib11(n - 1) + fib11(n -...
[{"input": "0 0 0\n1\n2 USB\n", "output": "0 0\n"}, {"input": "0 0 0\n1\n1 USB\n", "output": "0 0\n"}, {"input": "1 0 0\n1\n862644246 PS/2\n", "output": "0 0\n"}, {"input": "3 0 3\n0\n", "output": "0 0\n"}, {"input": "48810 78876 100000\n0\n", "output": "0 0\n"}, {"input": "1 1 1\n1\n6 PS/2\n", "output": "1 6\n"}, {"in...
interview
5,776
0
[ 0.6, 0.6, 0.45, 0.3, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.1, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1): [Image] Maxim asks you to count, how many numbers m (1 ≤ m ≤ n) are there, such that the sum of values in the cells in the row number m + 1 of the resulting matrix equals t. Expression (x xor y...
n, t = map(int, input().split()) s = bin(n + 2)[2:] l = len(s) if t & (t - 1): ans = 0 else: t = t.bit_length() f = [[0] * (l + 1) for i in range(l + 1)] for i in range(l + 1): f[i][0] = f[i][i] = 1 for j in range(1, i): f[i][j] = f[i - 1][j - 1] + f[i - 1][j] ans = c =...
[{"input": "1 1\n", "output": "1\n"}, {"input": "3 3\n", "output": "0\n"}, {"input": "1000000000000 1000000000000\n", "output": "0\n"}, {"input": "79375582 67108864\n", "output": "0\n"}, {"input": "62695452 33554432\n", "output": "0\n"}, {"input": "58797441 33554432\n", "output": "0\n"}, {"input": "543649338 175236010\...
competition
8,804
0
[ 0.25, 0.2, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
##Task: You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.* ##Examples: pattern(4): 1234 234 34 4 pattern(6): 123456 23456 3456 456 5...
pattern = lambda n: "\n".join(["".join([str(y) for y in range(x + 1, n + 1)]) for x in range(n)]);
[{"input": [5], "output": ["12345\n2345\n345\n45\n5"]}, {"input": [2], "output": ["12\n2"]}, {"input": [1], "output": ["1"]}, {"input": [0], "output": [""]}, {"input": [-25], "output": [""]}]
introductory
3,077
0
[ 0, 0, 0, 0, 0 ]
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the following type: "Given string s, determine if the memory of the mech...
import sys u = [] t = set() p1 = 127 m1 = 1000000007 p2 = 131 m2 = 1000000009 pow1 = [1] + [0] * 600005 pow2 = [1] + [0] * 600005 for i in range(1, 600005): pow1[i] = (pow1[i-1] * p1) % m1 pow2[i] = (pow2[i-1] * p2) % m2 def hash1(n): hsh = 0 for i in range(len(n)): hsh += pow1[i] * ord(n...
[{"input": "0 0\n", "output": ""}, {"input": "1 1\nbbbbbbbaaaabbbbbaabbbba\naaabbbabbbbbbbaabbabbbb\n", "output": "NO\n"}, {"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n", "output": "YES\nNO\nNO\n"}, {"input": "9 9\ncaccbcacabccba\naacbcbcaabacbcbcba\nbabccaaacccacbb\ncaaabcaacbababbabbb\nabbaccacabacaaaa\nbcc...
interview
7,186
0.15
[ 0.85, 0.8, 0.45, 0.35, 0.35, 0.2 ]
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is at least one digit in the string, There is at least one lowercase (small) letter of the Latin alphabet in the string, There...
import math, re, itertools as it;prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0;gcd = lambda a, b: gcd(b, a % b) if b else a;fact = lambda x: x * fact(x - 1) if x else 1;bino = lambda n, k: fact(n) / fact(k) / fact(n - k);fib11 = lambda n: 1 if n < 2 else fib11(n - 1) + fib11(n -...
[{"input": "3 1\nj\n#\n0\n", "output": "0\n"}, {"input": "10 2\n#y\njc\n#6\n#0\nt7\ns7\nd#\nn2\n#7\n&3\n", "output": "1\n"}, {"input": "5 2\n&e\n#j\n&&\n*2\n94\n", "output": "1\n"}, {"input": "3 4\n1**2\na3*0\nc4**\n", "output": "1\n"}, {"input": "3 1\nr\n&\n6\n", "output": "0\n"}, {"input": "3 1\n&\n7\no\n", "output":...
interview
5,950
0
[ 0.25, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. -----Input----- The first line of inpu...
n = input() good = True while n != '' and good: if n.endswith('144'): n = n[:-3] elif n.endswith('14'): n = n[:-2] elif n.endswith('1'): n = n[:-1] else: good = False print('YES' if good else 'NO')
[{"input": "9\n", "output": "NO\n"}, {"input": "9999\n", "output": "NO\n"}, {"input": "441231\n", "output": "NO\n"}, {"input": "15\n", "output": "NO\n"}, {"input": "12\n", "output": "NO\n"}, {"input": "11110111\n", "output": "NO\n"}, {"input": "1000000000\n", "output": "NO\n"}, {"input": "144244144\n", "output": "NO\n"...
interview
5,476
0
[ 0.85, 0.85, 0.75, 0.75, 0.75, 0.75, 0.75, 0.7, 0.65, 0.65, 0.6, 0.6, 0.6, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.5, 0.5, 0.5, 0.45, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.35, 0.35, 0.35, 0.35, 0.35, 0.3, 0.3, 0.3, ...
You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e. $\sum_{i = 1}^{k} a_{x_{i}} \neq \sum_{i = 1}^{k} b_{x_{i}}$...
n, a = int(input()), [int(i) for i in input().split()] b, m = a[:], dict() b.sort() for i in range(len(b) - 1): m[b[i]] = b[i + 1] m[b[-1]] = b[0] for i in range(len(a)): a[i] = m[a[i]] if len(set(b)) == n: print(*a) else: print(-1)
[{"input": "2\n1 2\n", "output": "2 1 \n"}, {"input": "1\n10000000\n", "output": "10000000 \n"}, {"input": "3\n1 3 2\n", "output": "3 2 1 \n"}, {"input": "5\n1 3 4 5 2\n", "output": "5 2 3 4 1 \n"}, {"input": "4\n3 1 2 4\n", "output": "2 4 1 3 \n"}, {"input": "4\n1000 100 10 1\n", "output": "100 1 1000 10\n"}, {"input"...
competition
2,353
0
[ 0.35, 0.35, 0.15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city a_{i}. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned ...
def main(): _, k, m = [int(x) for x in input().split()] a = [] last = ("-1", 0) a.append(last) for ai in input().split(): if last[0] == ai: last = (ai, last[1]+1) a[-1] = last else: last = (ai, 1) a.append(last) if last[1] == k...
[{"input": "2 4 1\n1 1\n", "output": "2\n"}, {"input": "10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n", "output": "10000000000\n"}, {"input": "1 9 10\n1\n", "output": "1\n"}, {"input": "1 1000000000 1000000000\n100000\n", "output": "0\n"}, {"input": "1 10 10\n1\n", "output": "0\n"}, {"input": "5 3 3\n1 2 2 1 1\n", "output": "...
interview
6,900
0
[ 0.25, 0.2, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0 ]
You are given two positive integers ```a``` and ```b```. You can perform the following operations on ```a``` so as to obtain ```b``` : ``` (a-1)/2 (if (a-1) is divisible by 2) a/2 (if a is divisible by 2) a*2 ``` ```b``` will always be a power of 2. You are to write a function ```operation(a,b)``` that effici...
from math import log2 def operation(a,b, n = 0): while log2(a) % 1: n += 1 a //= 2 return n + abs(log2(a/b))
[{"input": [4, 1], "output": [2]}, {"input": [4, 16], "output": [2]}, {"input": [3, 8], "output": [4]}, {"input": [2, 4], "output": [1]}, {"input": [1, 4], "output": [2]}, {"input": [1, 1], "output": [0]}]
introductory
4,264
0
[ 0, 0, 0, 0, 0, 0 ]
You are organizing a boxing tournament, where $n$ boxers will participate ($n$ is a power of $2$), and your friend is one of them. All boxers have different strength from $1$ to $n$, and boxer $i$ wins in the match against boxer $j$ if and only if $i$ is stronger than $j$. The tournament will be organized as follows: ...
from heapq import heappush, heappop N = int(input()) A = [int(a) for a in input().split()] for i in range(N): if A[i] < 0: k = i break A = [0] + [0 if i < k else A[i] for i in range(N) if i != k] ans = A.pop() H = [] while N > 2: N //= 2 for i in range(N): heappush(H, A.pop()) a...
[{"input": "2\n1000000000 -1\n", "output": "0"}, {"input": "4\n3 9 1 -1\n", "output": "0"}, {"input": "4\n1 -1 1 1\n", "output": "1"}, {"input": "2\n-1 1000000000\n", "output": "1000000000"}, {"input": "8\n280146049 211186644 583862529 565354172 35049432 509879809 -1 27382352\n", "output": "27382352"}, {"input": "8\n-1...
interview
6,043
0
[ 0.45, 0.25, 0.2, 0.15, 0.1, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You can choose any non-negative integer $D$ (i.e. $D \ge 0$), and for each $a_i$ you can: add $D$ (only once), i. e. perform $a_i := a_i + D$, or subtract $D$ (only once), i. e. perform $a_i := a_i - D$, or leave the value of $a_i$ unchan...
def main(): n = int(input()) a = list(sorted(set(map(int, input().split())))) if len(a) > 3: print(-1) elif len(a) == 1: print(0) elif len(a) == 2: d = a[1] - a[0] if d & 1: print(d) else: print(d >> 1) else: d = a[1] - a[0]...
[{"input": "1\n100\n", "output": "0\n"}, {"input": "4\n4 4 4 4\n", "output": "0\n"}, {"input": "5\n1 1 1 1 1\n", "output": "0\n"}, {"input": "4\n1 1 1 1\n", "output": "0\n"}, {"input": "3\n1 1 1\n", "output": "0\n"}, {"input": "2\n1 1\n", "output": "0\n"}, {"input": "3\n3 7 2\n", "output": "-1\n"}, {"input": "5\n7 6 5 ...
introductory
9,004
0
[ 0.65, 0.55, 0.5, 0.5, 0.5, 0.5, 0.45, 0.4, 0.4, 0.4, 0.4, 0.4, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, ...
Kurohashi has never participated in AtCoder Beginner Contest (ABC). The next ABC to be held is ABC N (the N-th ABC ever held). Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same. What is the earliest ABC where Kurohashi can make his debut? -----Constraints----- - 10...
N = int(input()) list_ = [111,222,333,444,555,666,777,888,999] for i in list_: if i >= N: print(i) return
[{"input": "999\n", "output": "999\n"}, {"input": "555\n", "output": "555\n"}, {"input": "111\n", "output": "111\n"}, {"input": "998\n", "output": "999\n"}, {"input": "554\n", "output": "555\n"}, {"input": "750\n", "output": "777\n"}, {"input": "680\n", "output": "777\n"}, {"input": "626\n", "output": "666\n"}, {"input...
introductory
9,309
0.25
[ 0.5, 0.5, 0.5, 0.45, 0.45, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4 ]
The final match of the Berland Football Cup has been held recently. The referee has shown $n$ yellow cards throughout the match. At the beginning of the match there were $a_1$ players in the first team and $a_2$ players in the second team. The rules of sending players off the game are a bit different in Berland footba...
a1=int(input()) a2=int(input()) k1=int(input()) k2=int(input()) n=int(input()) ans1=0 ans2=0 if k1<k2: ans1+=min(n//k1,a1) ans1+=(n-ans1*k1)//k2 else : ans1+=min(n//k2,a2) ans1+=(n-ans1*k2)//k1 ans2=max(0,n-(k1-1)*a1-(k2-1)*a2) print(ans2,ans1)
[{"input": "1\n1\n7\n1\n2\n", "output": "0 1\n"}, {"input": "1000\n1000\n1000\n1000\n998\n", "output": "0 0\n"}, {"input": "8\n2\n6\n7\n34\n", "output": "0 5\n"}, {"input": "7\n6\n2\n6\n11\n", "output": "0 5\n"}, {"input": "2\n3\n5\n1\n8\n", "output": "0 4\n"}, {"input": "1\n7\n2\n3\n5\n", "output": "0 2\n"}, {"input":...
interview
5,533
0
[ 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of $n$ vertices. Each vertex $i$ has its own value $a_i$. All vertices are connected in series by edges. Formally, for every $1 \leq i < n$ there is an edge between the vertices of $i$ and $i+1$. Denote the function $f(l, r)$, w...
n = int(input()) v = [0] + [int(e) for e in input().split()] ans = 0 for a, b in zip(v[:-1], v[1:]): if a < b: ans += (b-a)*(n-b+1) else: ans += b*(a-b) print(ans)
[{"input": "1\n1\n", "output": "1"}, {"input": "9\n1 9 1 1 4 5 9 9 1\n", "output": "60"}, {"input": "6\n5 4 1 6 4 3\n", "output": "33"}, {"input": "4\n3 2 1 4\n", "output": "12"}, {"input": "4\n2 1 1 3\n", "output": "11"}, {"input": "44\n42 44 4 24 29 17 32 30 30 9 28 9 22 16 20 41 17 19 41 23 28 19 38 44 1 34 41 34 19...
interview
6,509
0
[ 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books). Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that are similar. However, in each string there are a few characters tha...
def spot_diff(s1, s2): return [i for i in range(len(s1)) if s1[i] != s2[i]]
[{"input": ["www.youtube.com/zedaphplays", "www.twitter.com/zedaphplays"], "output": [[4, 5, 6, 8, 9, 10]]}, {"input": ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba"], "output": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]]}, {"input": ["abcdefg", "abcqetg...
introductory
2,820
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
In this Kata, you will be given two numbers, n and k and your task will be to return the k-digit array that sums to n and has the maximum possible GCD. For example, given `n = 12, k = 3`, there are a number of possible `3-digit` arrays that sum to `12`, such as `[1,2,9], [2,3,7], [2,4,6], ...` and so on. Of all the po...
def solve(n,k): maxGcd = 2*n // (k * (k+1)) for gcd in range(maxGcd, 0, -1): last = n-gcd * k*(k-1)//2 if not last % gcd: return [gcd*x if x != k else last for x in range(1,k+1)] return []
[{"input": [276, 12], "output": [[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 78]]}, {"input": [24, 6], "output": [[1, 2, 3, 4, 5, 9]]}, {"input": [24, 5], "output": [[1, 2, 3, 4, 14]]}, {"input": [24, 4], "output": [[2, 4, 6, 12]]}, {"input": [24, 3], "output": [[4, 8, 12]]}, {"input": [18, 5], "output": [[1, 2, 3, 4, 8]...
introductory
4,253
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing: - A level-0 burger is a patty. - A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) b...
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline n,x = list(map(int, input().split())) a,p = [1],[1] for i in range(n): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) def f(n, x): if n == 0: return 0 if x <= 0 else 1 elif x <= 1 + a[n - 1]: return f(n - 1, x - 1) ...
[{"input": "1 1\n", "output": "0\n"}, {"input": "50 50\n", "output": "0\n"}, {"input": "40 267599839143\n", "output": "133799919575\n"}, {"input": "50 604208208396631\n", "output": "302104104198311\n"}, {"input": "50 2251799813685297\n", "output": "1125899906842625\n"}, {"input": "50 2251799813685247\n", "output": "112...
interview
6,528
0
[ 0.55, 0.2, 0.15, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ]
You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}. The initial term is A, and the common difference is B. That is, s_i = A + B \times i holds. Consider the integer ...
import copy import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().rstrip() # ignore trailing spaces L,A,B,mod = na() low = 1 high = 10 def matpow(M, v, e, mod): A = copy.deepcopy(M) w = copy.deepcopy(v) while e > 0: ...
[{"input": "1 999999999999999999 999999999999999999 998244353\n", "output": "716070897\n"}, {"input": "5 3 4 10007\n", "output": "5563\n"}, {"input": "4 8 1 1000000\n", "output": "891011\n"}, {"input": "7343 44375369427231 136194167038156 841293953\n", "output": "336830166\n"}, {"input": "461491 67429808854595636 20172...
interview
5,739
0
[ 0.35, 0.2, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are given a set of n elements indexed from 1 to n. The weight of i-th element is w_{i}. The weight of some subset of a given set is denoted as $W(S) =|S|\cdot \sum_{i \in S} w_{i}$. The weight of some partition R of a given set into k subsets is $W(R) = \sum_{S \in R} W(S)$ (recall that a partition of a given set i...
n, k = list(map(int, input().split())) MOD = 10**9+7 def fast_modinv(up_to, M): ''' Fast modular inverses of 1..up_to modulo M. ''' modinv = [-1 for _ in range(up_to + 1)] modinv[1] = 1 for x in range(2, up_to + 1): modinv[x] = (-(M//x) * modinv[M%x])%M return modinv maxn = 2*10**5 + 1...
[{"input": "1 1\n1\n", "output": "1\n"}, {"input": "1 1\n1000000000\n", "output": "1000000000\n"}, {"input": "6 6\n7384 9123 5220 849 7169 1516\n", "output": "31261\n"}, {"input": "5 5\n1546 1477 962 7095 8934\n", "output": "20014\n"}, {"input": "4 4\n9900 6535 5489 1853\n", "output": "23777\n"}, {"input": "3 3\n4062 8...
interview
6,111
0
[ 0.15, 0.15, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should return a string of 3 actions. if you have harvested apples, you woul...
def buy_or_sell(pairs, harvested_fruit): currentFruit = harvested_fruit actions = list() for pair in pairs: if currentFruit not in pair: return 'ERROR' if currentFruit == pair[0]: actions.append('buy') currentFruit = pair[1] ...
[{"input": [[["orange", "apple"], ["pear", "orange"], ["pear", "apple"]], "apple"], "output": [["sell", "sell", "buy"]]}, {"input": [[["orange", "apple"], ["pear", "orange"], ["apple", "pear"]], "apple"], "output": [["sell", "sell", "sell"]]}, {"input": [[["orange", "apple"], ["pear", "orange"], ["apple", "paer"]], "ap...
introductory
4,345
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number ...
N = int(input()) H = [int(i) for i in input().split()] count = 0 ans = 0 for i in range(N-1): if(H[i] >= H[i+1]): count += 1 else: ans = max(ans,count) count = 0 print(max(ans,count))
[{"input": "100000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...
introductory
9,170
0.2
[ 0.7, 0.7, 0.55, 0.4, 0.3, 0.3, 0.3, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.2, 0.2 ]
On vacations n pupils decided to go on excursion and gather all together. They need to overcome the path with the length l meters. Each of the pupils will go with the speed equal to v_1. To get to the excursion quickly, it was decided to rent a bus, which has seats for k people (it means that it can't fit more than k p...
import sys n, l, v1, v2, k = list(map(int, input().split())) n = (n + k - 1) // k if n == 1: print(l / v2) return L, R = 0, l for i in range(100): M = (L + R) / 2 S = l - M T = M * (n * 2 - 1)- l if T * v1 > S * v2: R = M else: L = M print(M / v2 + S / v1)
[{"input": "1 1 999999999 1000000000 1\n", "output": "0.0000000010\n"}, {"input": "10000 1 999999999 1000000000 10000\n", "output": "0.0000000010\n"}, {"input": "10000 1 999999999 1000000000 1\n", "output": "0.0000000010\n"}, {"input": "1 1000000000 999999999 1000000000 1\n", "output": "1.0000000000\n"}, {"input": "100...
competition
8,822
0
[ 0.5, 0.45, 0.4, 0.4, 0.25, 0.25, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.1, 0.1, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array). You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix. If the name has a length of 0, return `"name must be at least one letter"` ## ...
from math import ceil def matrixfy(s): if not s: return "name must be at least one letter" x = ceil(len(s)**.5) it = iter(s.ljust(x*x,'.')) return [ [next(it) for _ in range(x)] for _ in range(x)]
[{"input": ["G"], "output": [[["G"]]]}, {"input": ["Franklin"], "output": [[["F", "r", "a"], ["n", "k", "l"], ["i", "n", "."]]]}, {"input": ["Frank"], "output": [[["F", "r", "a"], ["n", "k", "."], [".", ".", "."]]]}, {"input": ["Bill"], "output": [[["B", "i"], ["l", "l"]]]}, {"input": ["Beyonce"], "output": [[["B", "e"...
introductory
4,110
0
[ 0, 0, 0, 0, 0, 0 ]
Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally. Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work out if you make it home safely. 15 bumps or under, return "Woohoo!...
def bumps(road): return "Woohoo!" if road.count("n") <= 15 else "Car Dead"
[{"input": ["nnnnnnnnnnnnnnnnnnnnn"], "output": ["Car Dead"]}, {"input": ["n"], "output": ["Woohoo!"]}, {"input": ["_nnnnnnn_n__n______nn__nn_nnn"], "output": ["Car Dead"]}, {"input": ["______n___n_"], "output": ["Woohoo!"]}]
introductory
3,568
0
[ 0, 0, 0, 0 ]
You are given a sequence $b_1, b_2, \ldots, b_n$. Find the lexicographically minimal permutation $a_1, a_2, \ldots, a_{2n}$ such that $b_i = \min(a_{2i-1}, a_{2i})$, or determine that it is impossible. -----Input----- Each test contains one or more test cases. The first line contains the number of test cases $t$ ($1...
from sys import stdin,stderr def rl(): return [int(w) for w in stdin.readline().split()] def solve(n, b): f = [True for i in range(2*n+1)] for x in b: if not f[x]: return [-1] f[x] = False a = [] for x in b: a.append(x) for y in range(x+1, 2*n+1): ...
[{"input": "9\n11\n1 12 17 18 21 13 4 6 22 15 5\n11\n20 18 14 10 12 8 1 17 13 22 7\n11\n18 9 22 16 11 5 2 6 15 20 14\n11\n22 4 2 5 9 6 17 7 21 13 1\n11\n1 15 13 8 22 5 4 18 9 19 2\n11\n21 2 8 13 1 19 20 18 7 5 12\n11\n12 9 14 20 8 15 1 11 5 4 7\n11\n12 6 16 2 7 1 15 9 18 11 17\n11\n10 1 7 6 13 18 20 14 21 8 22\n", "out...
interview
5,742
0
[ 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are connec...
R = lambda: map(int, input().split()) n = int(input()) dp = [0] * (10**6 + 1) for x in R(): dp[x] = 1 for i in range(10**6, -1, -1): if dp[i]: for x in range(i + i, 10**6 + 1, i): if dp[x]: dp[i] = max(dp[i], dp[x] + 1) print(max(dp))
[{"input": "1\n1\n", "output": "1\n"}, {"input": "2\n1 3\n", "output": "2\n"}, {"input": "3\n16 64 256\n", "output": "3\n"}, {"input": "2\n7 343\n", "output": "2\n"}, {"input": "2\n10 21\n", "output": "1\n"}, {"input": "2\n1 1000000\n", "output": "2\n"}, {"input": "20\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 1...
interview
6,060
0
[ 0.3, 0.25, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0 ]
Given is a three-digit integer N. Does N contain the digit 7? If so, print Yes; otherwise, print No. -----Constraints----- - 100 \leq N \leq 999 -----Input----- Input is given from Standard Input in the following format: N -----Output----- If N contains the digit 7, print Yes; otherwise, print No. -----Sample Inpu...
N=int(input()) X=N%10 y=N//10 Y=y%10 Z=N//100 if X==7 or Y==7 or Z==7: print("Yes") else: print("No")
[{"input": "999\n", "output": "No\n"}, {"input": "777\n", "output": "Yes\n"}, {"input": "767\n", "output": "Yes\n"}, {"input": "521\n", "output": "No\n"}, {"input": "477\n", "output": "Yes\n"}, {"input": "123\n", "output": "No\n"}, {"input": "117\n", "output": "Yes\n"}, {"input": "100\n", "output": "No\n"}, {"input": "...
introductory
9,331
0.95
[ 1, 1, 1, 1, 1, 1, 1, 1, 0.95, 0.95, 0.95 ]
As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}. Snuke, an employee, would like to play with this sequence. Specifically, he would like to repeat the following operation as many times as possible: For every i satisfyin...
n = int(input()) a = list(map(int,input().split())) cnt = 0 for i in range(n): while True: if a[i]%2==0: a[i]=a[i]//2 cnt +=1 else: break print(cnt)
[{"input": "4\n631 577 243 199\n", "output": "0\n"}, {"input": "3\n5 2 4\n", "output": "3\n"}, {"input": "10000\n857576448 482942464 685840896 77316096 440142336 62545920 816600576 56761856 413433344 911709696 67991040 521700352 689439744 593764864 286524416 233751552 796622848 62162944 846440960 13967872 770568704 799...
introductory
9,224
0.45
[ 0.65, 0.55, 0.5, 0.5, 0.5, 0.5, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45 ]
You are given a string $s$ of length $n$ consisting only of lowercase Latin letters. A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not. Your task is to calculate the number of ways to remove exactly one substring from...
input() s = input() r1 = 1 f = s[0] for c in s: if c != f: break r1 += 1 r2 = 1 p = s[-1] for c in s[::-1]: if c != p: break r2 += 1 if f == p: print((r1 * r2) % 998244353) else: print((r1 + r2 - 1) % 998244353)
[{"input": "3\nabc\n", "output": "3"}, {"input": "2\naz\n", "output": "3"}, {"input": "5\nabcde\n", "output": "3"}, {"input": "5\naaacc\n", "output": "6"}, {"input": "4\nhack\n", "output": "3"}, {"input": "4\nabcd\n", "output": "3"}, {"input": "4\nabaa\n", "output": "6\n"}, {"input": "15\naabbsorrybbabbb\n", "output": ...
interview
6,057
0
[ 0.15, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
In this Kata, you will remove the left-most duplicates from a list of integers and return the result. ```python # Remove the 3's at indices 0 and 3 # followed by removing a 4 at index 1 solve([3, 4, 4, 3, 6, 3]) # => [4, 6, 3] ``` More examples can be found in the test cases. Good luck!
def solve(arr): re = [] for i in arr[::-1]: if i not in re: re.append(i) return re[::-1]
[{"input": [[3, 4, 4, 3, 6, 3]], "output": [[4, 6, 3]]}, {"input": [[1, 2, 3, 4]], "output": [[1, 2, 3, 4]]}, {"input": [[1, 2, 1, 2, 1, 2, 3]], "output": [[1, 2, 3]]}, {"input": [[1, 1, 4, 5, 1, 2, 1]], "output": [[4, 5, 2, 1]]}]
introductory
2,853
0
[ 0, 0, 0, 0 ]
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has n servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name of ...
n, m = map(int, input().split()) a = {} for i in range(n): x, y = input().split() a[y] = x for i in range(m): x, y = input().split() print(x, y, "#" + a[y.replace(';', '')])
[{"input": "8 5\nfhgkq 5.19.189.178\nphftablcr 75.18.177.178\nxnpcg 158.231.167.176\ncfahrkq 26.165.124.191\nfkgtnqtfoh 230.13.13.129\nt 101.24.94.85\nvjoirslx 59.6.179.72\ntwktmskb 38.194.117.184\nrvzzlygosc 26.165.124.191;\ndcsgxrkgv 101.24.94.85;\nyvmyppn 59.6.179.72;\ngpdjjuq 75.18.177.178;\nvdviz 101.24.94.85;\n",...
interview
6,701
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
We have the first value of a certain sequence, we will name it ```initVal```. We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence. ``` E.g: patternL = [k1, k2, k3, k4]``` The terms of the sequence will be such values that: ```python term1 = initVal term2...
from itertools import cycle def sumDig_nthTerm(initVal, patternL, nthTerm): for c, i in enumerate(cycle(patternL), 2): initVal += i if c == nthTerm: return sum(int(v) for v in str(initVal))
[{"input": [1000, [2, 2, 5, 8], 2550], "output": [14]}, {"input": [1000, [2, 2, 5, 8], 25500], "output": [26]}, {"input": [100, [2, 2, 5, 8], 78], "output": [11]}, {"input": [100, [2, 2, 5, 8], 6], "output": [11]}, {"input": [100, [2, 2, 5, 8], 50], "output": [9]}, {"input": [100, [2, 2, 5, 8], 15], "output": [11]}, {"...
introductory
4,105
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter! The President of Berland was forced to leave only k of the currently existing n subway stations. The subway stations are located on a straight lin...
from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x],str(x+1)) for x in range(n)]) k = int(stdin.readline()) sums = [0] for x in a: sums.append(sums[-1]+x[0]) total = 0 s = 0 for x in range(k): total += a[x][0]*x-s s += a[x][0] low = total low...
[{"input": "3\n-100000000 0 100000000\n2\n", "output": "1 2 "}, {"input": "7\n10 -6 0 -5 -2 -8 7\n2\n", "output": "2 4 "}, {"input": "7\n-5 1 3 2 -9 -1 -4\n3\n", "output": "2 4 3 "}, {"input": "6\n9 8 4 -4 -6 -8\n2\n", "output": "2 1 "}, {"input": "6\n8 -7 1 5 -8 4\n3\n", "output": "3 6 4 "}, {"input": "5\n11 21 30 40 ...
interview
6,444
0
[ 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly x bacteria in the box at some moment. What is the minimu...
n = int(input()) ans = 1 while n != 1: if n % 2 == 1: ans += 1 n -= 1 else: n //= 2 print(ans)
[{"input": "2\n", "output": "1\n"}, {"input": "3\n", "output": "2\n"}, {"input": "7\n", "output": "3\n"}, {"input": "536870911\n", "output": "29\n"}, {"input": "6\n", "output": "2\n"}, {"input": "5\n", "output": "2\n"}, {"input": "1\n", "output": "1\n"}, {"input": "536870910\n", "output": "28\n"}, {"input": "4\n", "out...
interview
5,709
0.05
[ 0.65, 0.6, 0.55, 0.45, 0.3, 0.25, 0.25, 0.2, 0.2, 0.2, 0.15, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ]
Sasha is taking part in a programming competition. In one of the problems she should check if some rooted trees are isomorphic or not. She has never seen this problem before, but, being an experienced participant, she guessed that she should match trees to some sequences and then compare these sequences instead of tree...
h = int(input()) a = list(map(int, input().split())) w, q = [], [] p = r = 0 for i in a: for j in range(i): w.append(r) q.append(r - (j and p > 1)) p = i r += i if w == q: print('perfect') else: print('ambiguous') print(*w) print(*q)
[{"input": "2\n1 1 1\n", "output": "perfect\n"}, {"input": "10\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "perfect\n"}, {"input": "2\n1 2 2\n", "output": "ambiguous\n0 1 1 3 3\n0 1 1 3 2\n"}, {"input": "123\n1 1 1 3714 1 3739 1 3720 1 1 3741 1 1 3726 1 3836 1 3777 1 1 3727 1 1 3866 1 3799 1 3785 1 3693 1 1 3667 1 3930 1 3849...
competition
2,033
0
[ 0.15, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implement the features. Being the good programmer you are, you carefully p...
def fight_resolve(d, a): return -1 if d.islower() == a.islower() else d if d.lower() + a.lower() in "ka sp as pk" else a
[{"input": ["k", "s"], "output": [-1]}, {"input": ["k", "A"], "output": ["k"]}, {"input": ["a", "a"], "output": [-1]}, {"input": ["S", "A"], "output": [-1]}, {"input": ["K", "a"], "output": ["K"]}, {"input": ["K", "A"], "output": [-1]}]
introductory
4,121
0
[ 0, 0, 0, 0, 0, 0 ]
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and Vertex b_i. Consider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy all of the following M restrictions? - The i-th (1 \leq i \leq M) restrict...
from collections import defaultdict def dfs(s, t): visited = 0 q = [(s, 0)] while q: v, used = q.pop() if v == t: return used visited |= used for lb, u in graph[v]: if lb & visited: continue q.append((u, used | lb)) n = ...
[{"input": "7\n2 1\n1 4\n5 3\n3 7\n6 4\n4 7\n20\n3 5\n5 7\n2 6\n1 4\n1 3\n3 4\n1 2\n2 3\n4 7\n1 5\n4 5\n5 6\n1 7\n4 6\n3 6\n2 4\n2 5\n1 6\n3 7\n2 7\n", "output": "1\n"}, {"input": "7\n1 3\n2 6\n4 3\n3 7\n6 5\n5 7\n20\n5 7\n1 7\n2 6\n6 7\n4 5\n3 7\n1 5\n2 5\n1 4\n3 4\n1 6\n2 4\n5 6\n2 7\n4 6\n1 2\n3 6\n3 5\n1 3\n4 7\n",...
interview
5,990
0
[ 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of second** the height of the ball. For example with `v = 15 km/h` the de...
""" h = vt-0.5gt^2 let h = 0 [that is, when the ball has returned to the ground] => 0 = vt-0.5gt^2 => 0.5gt^2 = vt => 0.5gt = v => t = 2v/g - the total time the ball is in the air. => t at max height = v/g """ def max_ball(v0): return round(10*v0/9.81/3.6)
[{"input": [99], "output": [28]}, {"input": [85], "output": [24]}, {"input": [52], "output": [15]}, {"input": [45], "output": [13]}, {"input": [37], "output": [10]}, {"input": [16], "output": [5]}, {"input": [14], "output": [4]}, {"input": [137], "output": [39]}, {"input": [136], "output": [39]}, {"input": [127], "outp...
introductory
4,443
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine ...
s=input() ans=0 i=1 past=int(s[0]) c=1 ans=1 while(i<len(s)): if(int(s[i])+past==9): c+=1 past=int(s[i]) else: if(c%2==1 and c!=1): ans*=(c//2+1) c=1 past=int(s[i]) i+=1 if(c!=1 and c%2==1): ans*=(c//2+1) print(ans)
[{"input": "1\n", "output": "1\n"}, {"input": "123456789\n", "output": "1\n"}, {"input": "12191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912191219121912...
interview
6,435
0
[ 0.3, 0.15, 0.15, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0 ]
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()) bb=True while(m>0 and bb): x=m%w if x==1:m-=1 elif x==w-1:m+=1 elif x!=0:bb=False m//=w if bb:print("YES") else:print("NO")
[{"input": "10 8\n", "output": "NO\n"}, {"input": "8 28598\n", "output": "NO\n"}, {"input": "5 131944448\n", "output": "NO\n"}, {"input": "41 2966964\n", "output": "NO\n"}, {"input": "4 9083\n", "output": "NO\n"}, {"input": "4 556522107\n", "output": "NO\n"}, {"input": "1000 999999998\n", "output": "NO\n"}, {"input": "...
interview
5,054
0
[ 0.75, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6...
Polycarpus participates in a competition for hacking into a new secure messenger. He's almost won. Having carefully studied the interaction protocol, Polycarpus came to the conclusion that the secret key can be obtained if he properly cuts the public key of the application into two parts. The public key is a long inte...
def main(): s, x, pfx = input(), 0, [] a, b = list(map(int, input().split())) try: for i, c in enumerate(s, 1): x = (x * 10 + ord(c) - 48) % a if not x and s[i] != '0': pfx.append(i) except IndexError: pass x, p, i = 0, 1, len(s) for stop i...
[{"input": "8552104774\n973 76\n", "output": "NO\n"}, {"input": "4261508098904115227\n52546339 6430\n", "output": "NO\n"}, {"input": "3415280033041307294\n15179 79809921\n", "output": "NO\n"}, {"input": "16375289070073689\n33903290 216\n", "output": "NO\n"}, {"input": "15203400\n38 129\n", "output": "NO\n"}, {"input": ...
interview
5,694
0
[ 0.55, 0.5, 0.5, 0.5, 0.5, 0.5, 0.3, 0.2, 0.15, 0.15, 0.15, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
# Introduction and Warm-up (Highly recommended) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) ___ # Task **_Given_** an *array/list [] of integers* , **_Construct_** a *product array **_Of same size_** Such That prod[i] is equal to The Product of all the e...
from operator import mul from functools import reduce def product_array(numbers): tot = reduce(mul,numbers) return [tot//n for n in numbers]
[{"input": [[3, 27, 4, 2]], "output": [[216, 24, 162, 324]]}, {"input": [[16, 17, 4, 3, 5, 2]], "output": [[2040, 1920, 8160, 10880, 6528, 16320]]}, {"input": [[13, 10, 5, 2, 9]], "output": [[900, 1170, 2340, 5850, 1300]]}, {"input": [[12, 20]], "output": [[20, 12]]}]
introductory
3,759
0
[ 0, 0, 0, 0 ]
There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i. N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particular about which chairs they sit in. Specifically, the i-th person wishes to ...
import sys input=sys.stdin.readline N,M=list(map(int,input().split())) # N: 処理する区間の長さ INF = 2**31-1 LV = (M+2-1).bit_length() N0 = 2**LV data = [0]*(2*N0) lazy = [0]*(2*N0) def gindex(l, r): L = (l + N0) >> 1; R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (R & -R).bi...
[{"input": "4 4\n0 3\n2 3\n1 3\n3 4\n", "output": "0\n"}, {"input": "6 6\n1 6\n1 6\n1 5\n1 5\n2 6\n2 6\n", "output": "2\n"}, {"input": "3 1\n1 2\n1 2\n1 2\n", "output": "2\n"}, {"input": "7 6\n0 7\n1 5\n3 6\n2 7\n1 6\n2 6\n3 7\n", "output": "2\n"}]
competition
2,266
0
[ 0.1, 0.05, 0.05, 0 ]
The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can...
from copy import deepcopy n,m = map(int,input().split()) a = list(map(int,input().split())) b = [list(map(int,input().split())) for i in range(m)] best1 = -1 best2 = -1 best3 = [] for i in range(n): tmp = 0 tmp2 = 0 tmp3 = [] c = deepcopy(a) for j in range(m): x,y = b[j] x-=1;y-=1 ...
[{"input": "1 5\n9\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "0\n0\n\n"}, {"input": "1 50\n5\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\...
introductory
9,078
0
[ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$. The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there is an edge $u \to v$ in the graph. This action takes $1$ second. Graph tran...
import sys input = sys.stdin.readline import heapq mod=998244353 n,m=list(map(int,input().split())) E=[[] for i in range(n+1)] E2=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E2[y].append(x) TIME=[1<<29]*(n+1) TIME[1]=0 def shuku(x,y): return (x<<20...
[{"input": "2 1\n2 1\n", "output": "2\n"}, {"input": "50 49\n1 3\n6 46\n47 25\n11 49\n47 10\n26 10\n12 38\n45 38\n24 39\n34 22\n36 3\n21 16\n43 44\n45 23\n2 31\n26 13\n28 42\n43 30\n12 27\n32 44\n24 25\n28 20\n15 19\n6 48\n41 7\n15 17\n8 9\n2 48\n33 5\n33 23\n4 19\n40 31\n11 9\n40 39\n35 27\n14 37\n32 50\n41 20\n21 13\...
competition
2,204
0
[ 0.05, 0, 0, 0, 0, 0, 0 ]
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$? -----Input----- The only line of the input contains...
n, m =list(map(int, input().split())) if m % n != 0: print( m // n + 1) else: print(m // n)
[{"input": "1 1000000000\n", "output": "1000000000"}, {"input": "100000 1\n", "output": "1"}, {"input": "1 30\n", "output": "30"}, {"input": "83 361125900\n", "output": "4350915"}, {"input": "8 750191967\n", "output": "93773996"}, {"input": "8 550991517\n", "output": "68873940"}, {"input": "7 236413222\n", "output": "3...
interview
5,366
0.35
[ 0.65, 0.6, 0.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.4, 0.4, 0.4, 0.4, ...
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n. Each man has at most one father but may have arbitrary number of sons. Man number A is considered to b...
n, m = map(int, input().split()) adj = [[] for _ in range(n)] cp = [-1] * n for i in range(m): p, c = map(int, input().split()) adj[p - 1].append(c - 1) cp[c - 1] = p - 1 pres = [i - 1 for i in map(int, input().split())] level = [0] * n from collections import deque def bfs(v): q = deque([v]) whi...
[{"input": "4 3\n4 3\n3 2\n2 1\n3 4 4 4\n", "output": "-1"}, {"input": "4 3\n1 2\n2 3\n3 4\n1 1 3 2\n", "output": "-1"}, {"input": "4 3\n1 2\n2 3\n3 4\n1 1 1 2\n", "output": "-1"}, {"input": "3 2\n1 2\n2 3\n1 2 1\n", "output": "-1"}, {"input": "1 0\n1\n", "output": "1\n1\n"}, {"input": "2 1\n2 1\n2 2\n", "output": "1\n...
interview
7,065
0
[ 0.15, 0.15, 0.15, 0.15, 0.1, 0.05, 0, 0 ]
Given is an integer N. Takahashi chooses an integer a from the positive integers not greater than N with equal probability. Find the probability that a is odd. -----Constraints----- - 1 \leq N \leq 100 -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the probabili...
def readinput(): n=int(input()) return n def main(n): if n%2==0: return 0.5 else: return (n//2+1)/n def __starting_point(): n=readinput() ans=main(n) print(ans) __starting_point()
[{"input": "98\n", "output": "0.5000000000\n"}, {"input": "96\n", "output": "0.5000000000\n"}, {"input": "90\n", "output": "0.5000000000\n"}, {"input": "64\n", "output": "0.5000000000\n"}, {"input": "4\n", "output": "0.5000000000\n"}, {"input": "2\n", "output": "0.5000000000\n"}, {"input": "100\n", "output": "0.5000000...
introductory
9,218
0.05
[ 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.2, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 ]
Truncate the given string (first argument) if it is longer than the given maximum length (second argument). Return the truncated string with a `"..."` ending. Note that inserting the three dots to the end will add to the string length. However, if the given maximum string length num is less than or equal to 3, then t...
def truncate_string(s,n): return s if len(s)<=n else s[:n if n<=3 else n-3]+'...'
[{"input": ["pippi", 3], "output": ["pip..."]}, {"input": ["Seems like you have passed the final test. Congratulations", 53], "output": ["Seems like you have passed the final test. Congrat..."]}, {"input": ["Peter Piper picked a peck of pickled peppers", 14], "output": ["Peter Piper..."]}, {"input": ["I like ice-cream....
introductory
4,529
0
[ 0, 0, 0, 0, 0, 0, 0, 0 ]
Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive integer, in the vertex i she wrote a_{i}. Moreover, the girl wrote a positive integer to every edge of the tree (possibly, different integers on different edges). Let's define dist(v, u) as the sum of the i...
import sys import threading from bisect import bisect_left n = int(input()) a = list(map(int, input().split())) e = {} g = [[] for i in range(n)] d = [0]*(n+5) ans = [0]*n p = [0]*(n+5) for i in range(n-1): c, w = map(int, input().split()) c-= 1 g[c].append(i+1) e[i+1] = w ...
[{"input": "1\n1\n", "output": "0\n"}, {"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1000000000\n2 1000000000\n3 1000000000\n4 1000000000\n5 1000000000\n", "output": "1 1 1 1 1 0\n"}, {"input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n1 1000000000\n2 1000000000\n3...
competition
8,997
0
[ 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $E = \sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$. You have to perform exactly k_1 operations on array A and exactly k_2 operations on array B. In one operation, you have to choose one element of the array and increase or decrea...
n, k1, k2 = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) r = sorted([abs(a[i] - b[i]) for i in range(n)], reverse=True) for it in range(k1 + k2): if r[0] == 0: r[0] = 1 else: r[0] -= 1 for i in range(n - 1): if r[i] <...
[{"input": "2 0 0\n1 2\n2 3\n", "output": "2"}, {"input": "5 5 5\n0 0 0 0 0\n0 0 0 0 0\n", "output": "0"}, {"input": "2 2 0\n3 3\n3 3\n", "output": "0"}, {"input": "1 1000 0\n1000000\n1000000\n", "output": "0"}, {"input": "2 1 3\n2 2\n2 2\n", "output": "0"}, {"input": "1 0 6\n0\n0\n", "output": "0"}, {"input": "1 0 100...
competition
8,918
0
[ 0.6, 0.55, 0.55, 0.4, 0.35, 0.3, 0.3, 0.25, 0.15, 0.15, 0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
We define the score of permutations of combinations, of an integer number (the function to obtain this value:```sc_perm_comb```) as the total sum of all the numbers obtained from the permutations of all the possible combinations of its digits. For example we have the number 348. ```python sc_perm_comb(348) = 3 + 4 + 8 ...
from itertools import permutations def sc_perm_comb(num): sNum = str(num) return sum({ int(''.join(p)) for d in range(1, len(sNum)+1) for p in permutations(sNum, d) })
[{"input": [6], "output": [6]}, {"input": [348], "output": [3675]}, {"input": [340], "output": [1631]}, {"input": [333], "output": [369]}, {"input": [0], "output": [0]}]
introductory
3,669
0
[ 0, 0, 0, 0, 0 ]
*This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.* --- [Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) moves on a regular grid of squares that are coloured either b...
move = [lambda p: (p[0]+1, p[1]), lambda p: (p[0], p[1]+1), lambda p: (p[0]-1, p[1]), lambda p: (p[0], p[1]-1)] start, loop, size = 9977, 104, 12 def langtons_ant(n): pos, d, black, res = (0, 0), 0, set(), 0 if n > start: x = (n - start)%loop res = size * (n-start-x)//loop n = start + x...
[{"input": [2], "output": [2]}, {"input": [1], "output": [1]}, {"input": [10], "output": [6]}, {"input": [100], "output": [20]}, {"input": [1000], "output": [118]}, {"input": [10000], "output": [720]}, {"input": [100000], "output": [11108]}, {"input": [1000000], "output": [114952]}, {"input": [10000000], "output": [115...
introductory
4,332
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
See the following triangle: ``` ____________________________________ 1 2 4 2 3 6 9 6 3 4 8 12 16 12 8 4 5 10 15 20 25 20 15 10 5 ___________________________________ ``` The tot...
def mult_triangle(n): total = (n * (n + 1) / 2)**2 odds = ((n + 1) // 2)**4 return [total, total - odds, odds]
[{"input": [5], "output": [[225, 144, 81]]}, {"input": [50], "output": [[1625625, 1235000, 390625]]}, {"input": [4], "output": [[100, 84, 16]]}, {"input": [3], "output": [[36, 20, 16]]}, {"input": [2], "output": [[9, 8, 1]]}, {"input": [1], "output": [[1, 0, 1]]}, {"input": [10], "output": [[3025, 2400, 625]]}]
introductory
3,265
0
[ 0, 0, 0, 0, 0, 0, 0 ]
Peter has a sequence of integers a_1, a_2, ..., a_{n}. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive). At that, Peter never chooses any element as the beginning of the se...
mod = 10**9 + 7 n, h = map(int, input().split()) a = list(map(int, input().split())) dp = [[0 for j in range(h + 1)] for i in range (n + 1)] dp[0][0] = 1 for i in range(1, n + 1): need = h - a[i - 1] if need < 0: break if need == 0: dp[i][0] = dp[i - 1][0] else: dp[i][need] = (dp[i - 1][need] + dp[i - 1][need...
[{"input": "1 349\n348\n", "output": "1\n"}, {"input": "1 2000\n2000\n", "output": "1\n"}, {"input": "5 1\n1 1 1 1 1\n", "output": "1\n"}, {"input": "3 6\n5 6 5\n", "output": "1\n"}, {"input": "3 4\n4 3 2\n", "output": "0\n"}, {"input": "9 4\n2 3 2 2 2 3 3 3 2\n", "output": "0\n"}, {"input": "6 3\n2 1 2 2 1 2\n", "outp...
interview
6,306
0
[ 0.2, 0.2, 0.15, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0, 0, 0 ]
You will be given two strings `a` and `b` consisting of lower case letters, but `a` will have at most one asterix character. The asterix (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase letters. No other character of string `a` can be replaced. If it is possible to replace the asterix i...
from fnmatch import fnmatch def solve(a, b): return fnmatch(b, a)
[{"input": ["s*", "s"], "output": [true]}, {"input": ["codewar*s", "codewars"], "output": [true]}, {"input": ["code*warrior", "codewars"], "output": [false]}, {"input": ["code*s", "codewars"], "output": [true]}, {"input": ["c", "c"], "output": [true]}, {"input": ["aaa*aaa", "aaa"], "output": [false]}, {"input": ["aaa*"...
introductory
3,306
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
## Your Job Find the sum of all multiples of `n` below `m` ## Keep in Mind * `n` and `m` are natural numbers (positive integers) * `m` is **excluded** from the multiples ## Examples
def sum_mul(n, m): if m>0 and n>0: return sum(range(n, m, n)) else: return 'INVALID'
[{"input": [7, 7], "output": [0]}, {"input": [7, 2], "output": [0]}, {"input": [4, 123], "output": [1860]}, {"input": [4, -7], "output": ["INVALID"]}, {"input": [21, 3], "output": [0]}, {"input": [2, 2], "output": [0]}, {"input": [2, 10], "output": [20]}, {"input": [2, 0], "output": ["INVALID"]}, {"input": [123, 4567],...
introductory
2,995
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]