question
stringlengths
29
14k
solutions
listlengths
1
6.39k
starter_code
stringlengths
0
1.47k
input_output
stringlengths
29
74M
difficulty
stringclasses
6 values
raw_tags
stringlengths
2
281
name
stringlengths
3
105
source
stringclasses
10 values
tags
stringlengths
2
183
skill_types
stringclasses
127 values
url
stringlengths
36
138
time_limit
stringclasses
143 values
date
stringlengths
10
10
picture_num
stringclasses
8 values
memory_limit
stringclasses
28 values
Expected Time Complexity
stringclasses
710 values
task_id
int64
1
25.4k
solution_id
int64
0
0
solution
stringlengths
6
413k
text
stringlengths
123
413k
In Wolf town there are 2 big markets S and T. The distance between these markets is D. Chef Ciel would like to run 2 restaurants in Wolf town, where the first restaurant will be supplied by the market S and the second one will be supplied by the market T. The markets run delivery service without charge within some dist...
[ "for i in range(int(input())):\n\t(a, b, c) = map(int, input().split())\n\tif c > max(a, b):\n\t\tprint(max(0, c - (a + b)))\n\telse:\n\t\tprint(max(0, max(a, b) - c - min(a, b)))\n", "for _ in range(int(input())):\n\t(ds, dt, d) = map(int, input().split())\n\tprint(max(0, d - ds - dt, ds - d - dt, dt - d - ds))\...
{"inputs": ["4\n15 15 50\n15 15 18\n43 88 200\n2013 2013 2013", "4\n15 15 50\n15 15 18\n43 88 200\n2013 1560 2013", "4\n2 15 50\n15 15 18\n43 88 200\n2013 1560 2013", "4\n2 25 50\n15 15 28\n43 88 200\n2013 1798 2013", "4\n2 25 50\n15 12 28\n43 88 200\n2013 1798 2013", "4\n2 25 50\n15 12 28\n43 88 200\n2715 1798 211", "...
MEDIUM_HARD
['Mathematics', 'Basic Maths', 'Algorithms', 'Geometry', 'Constructive', 'ad-hoc']
null
codechef
['Geometry', 'Constructive algorithms', 'Mathematics', 'Ad-hoc']
[]
https://www.codechef.com/problems/CIELDIST
2.013 seconds
2013-01-02
0
50000 bytes
null
25,059
0
for i in range(int(input())): (a, b, c) = map(int, input().split()) if c > max(a, b): print(max(0, c - (a + b))) else: print(max(0, max(a, b) - c - min(a, b)))
# Question In Wolf town there are 2 big markets S and T. The distance between these markets is D. Chef Ciel would like to run 2 restaurants in Wolf town, where the first restaurant will be supplied by the market S and the second one will be supplied by the market T. The markets run delivery service without charge with...
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. Example 1: Input: numerator = 1, denominator = 2 Output: "0.5" Example 2: Input: numerator = 2, denominator = 1 Outpu...
[ "class Solution:\n\n\tdef fractionToDecimal(self, numerator, denominator):\n\t\tif numerator * denominator < 0:\n\t\t\tadd_negative = True\n\t\telse:\n\t\t\tadd_negative = False\n\t\t(numerator, denominator) = (abs(numerator), abs(denominator))\n\t\tinteger_part = int(numerator // denominator)\n\t\tnew_numerator = ...
class Solution: def fractionToDecimal(self, numerator: int, denominator: int) -> str:
{"fn_name": "fractionToDecimal", "inputs": [[1, 2]], "outputs": ["0.5"]}
MEDIUM_HARD
['Math', 'String', 'Hash Table']
null
leetcode
['String algorithms', 'Data structures', 'Mathematics']
['Data structures']
https://leetcode.com/problems/fraction-to-recurring-decimal/
null
null
null
null
null
25,064
0
class Solution: def fractionToDecimal(self, numerator, denominator): if numerator * denominator < 0: add_negative = True else: add_negative = False (numerator, denominator) = (abs(numerator), abs(denominator)) integer_part = int(numerator // denominator) new_numerator = numerator - integer_part * deno...
# Question Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. Example 1: Input: numerator = 1, denominator = 2 Output: "0.5" Example 2: Input: numerator = 2, denominat...
This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x. More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the int...
[ "from random import sample\n\ndef R():\n\treturn map(int, input().split())\n\ndef ask(i):\n\tprint('?', i, flush=True)\n\t(v, nxt) = R()\n\tif v < 0:\n\t\texit()\n\treturn (v, nxt)\n\ndef ans(v):\n\tprint('!', v)\n\texit()\n(n, s, x) = R()\nmv = -1\ni = s\nS = 800\nq = range(1, n + 1)\nif n > S:\n\tq = sample(q, S)...
{"inputs": ["10 3 2\n3 9\n9 -1\n0 7\n6 8\n5 4\n8 2\n1 10\n7 6\n4 5\n2 1\n", "1 1 0\n0 -1\n", "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1\n", "5 3 974128233\n547205043 5\n318213550 1\n122625404 4\n184874700 2\n669820978 -1\n", "1 1 2\n0 -1\n", "1 1 1000000000\n0 -1\n", "5 3 381735506\n469559901 5\n359493082 1\n137017061 4\n2027681...
HARD
['brute force', 'probabilities', 'interactive']
null
codeforces
['Complete search', 'Probability']
['Complete search']
https://codeforces.com/problemset/problem/844/D
1.0 seconds
null
null
256.0 megabytes
null
25,063
0
from random import sample def R(): return map(int, input().split()) def ask(i): print('?', i, flush=True) (v, nxt) = R() if v < 0: exit() return (v, nxt) def ans(v): print('!', v) exit() (n, s, x) = R() mv = -1 i = s S = 800 q = range(1, n + 1) if n > S: q = sample(q, S) if s not in q: q[0] = s for i in...
# Question This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x. More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: value...
Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ideas and algorithms to analyze positions and sequences of moves, as well a...
[ "N = 4\nD = ((1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, 1), (-1, -1), (1, -1), (2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1))\nFIGURES = 'QNBR'\nRANGE = ((0, 8), (8, 16), (4, 8), (0, 4))\n\ndef solve():\n\t(w, b, m) = map(int, input().split())\n\tm -= (m + 1) % 2\n\tfield = [[0] * N for...
{"inputs": ["1\n2 1 1\nN B 2\nQ B 1\nQ A 4\n"], "outputs": ["YES\n"]}
MEDIUM
['Algorithms - Recursion']
null
hackerrank
['Complete search']
['Complete search']
https://www.hackerrank.com/challenges/simplified-chess-engine/problem
null
null
1
null
null
25,060
0
N = 4 D = ((1, 0), (0, 1), (-1, 0), (0, -1), (1, 1), (-1, 1), (-1, -1), (1, -1), (2, 1), (1, 2), (-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, -2), (2, -1)) FIGURES = 'QNBR' RANGE = ((0, 8), (8, 16), (4, 8), (0, 4)) def solve(): (w, b, m) = map(int, input().split()) m -= (m + 1) % 2 field = [[0] * N for _ in range(N)] ...
# Question Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ideas and algorithms to analyze positions and sequences of move...
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column...
[ "def main():\n\t(n, m) = list(map(int, input().split()))\n\t(xx, yy, walls, t) = ([0] * n, [0] * m, set(), 0)\n\tfor x in range(n):\n\t\tfor (y, c) in enumerate(input()):\n\t\t\tif c == '*':\n\t\t\t\tt += 1\n\t\t\t\tif t == n + m:\n\t\t\t\t\tprint('NO')\n\t\t\t\t\treturn\n\t\t\t\twalls.add((x, y))\n\t\t\t\txx[x] +=...
{"inputs": ["3 4\n.*..\n....\n.*..\n", "3 3\n..*\n.*.\n*..\n", "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "1 10\n**********\n", "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n", "10 10\n........
MEDIUM
['implementation']
null
codeforces
['Implementation']
[]
https://codeforces.com/problemset/problem/699/B
null
2019-12-31
null
null
null
25,065
0
def main(): (n, m) = list(map(int, input().split())) (xx, yy, walls, t) = ([0] * n, [0] * m, set(), 0) for x in range(n): for (y, c) in enumerate(input()): if c == '*': t += 1 if t == n + m: print('NO') return walls.add((x, y)) xx[x] += 1 yy[y] += 1 for (x, a) in enumerate(xx): ...
# Question You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls i...
Given a Circular Linked List of size N. The task is to delete the given node (excluding the first and last node) in the circular linked list and then print the reverse of the circular linked list. Example 1: Input: 5 2 5 7 8 10 8 Output: 10 7 5 2 Explanation: After deleting 8 from the given circular linked list, it...
[ "def deleteNode(head, key):\n\ttemp = head\n\twhile True:\n\t\tif temp.next.data == key:\n\t\t\ttemp.next = temp.next.next\n\t\t\tbreak\n\t\telse:\n\t\t\ttemp = temp.next\n\ndef reverse(head):\n\tlast = head\n\tcurr = head\n\twhile last.next != head:\n\t\tlast = last.next\n\tprev = last\n\twhile curr != last:\n\t\t...
#User function Template for python3 ''' class Node: def __init__(self, data): self.data = data self.next = None ''' # Function to delete a given node from the list def deleteNode(head, key): #your code goes here #Function to reverse the list def reverse(head): #your co...
{"inputs": ["5\n2 5 7 8 10\n8", "4\n1 7 8 10\n8"], "outputs": ["10 7 5 2", "10 7 1"]}
EASY
['Data Structures', 'circular-linked-list', 'circular linked list', 'Linked List']
null
geeksforgeeks
['Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/deletion-and-reverse-in-linked-list/1
null
null
0
null
25,071
0
def deleteNode(head, key): temp = head while True: if temp.next.data == key: temp.next = temp.next.next break else: temp = temp.next def reverse(head): last = head curr = head while last.next != head: last = last.next prev = last while curr != last: tmp = curr.next curr.next = prev prev = c...
# Question Given a Circular Linked List of size N. The task is to delete the given node (excluding the first and last node) in the circular linked list and then print the reverse of the circular linked list. Example 1: Input: 5 2 5 7 8 10 8 Output: 10 7 5 2 Explanation: After deleting 8 from the given circular link...
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Given two array of integers(`arr1`,`arr2`). Your task is going to find a pair of numbers(an element in arr1, and another element in arr2), their difference...
[ "def max_and_min(arr1, arr2):\n\tdiffs = [abs(x - y) for x in arr1 for y in arr2]\n\treturn [max(diffs), min(diffs)]\n", "def max_and_min(arr1, arr2):\n\tarr1.sort()\n\tarr2.sort()\n\ti = 0\n\tdifference = []\n\twhile i < len(arr1):\n\t\tlocal = []\n\t\tfor element in arr2:\n\t\t\tlocal_dif = abs(arr1[i] - elemen...
def max_and_min(arr1,arr2):
{"fn_name": "max_and_min", "inputs": [[[3, 10, 5], [20, 7, 15, 8]], [[3], [20]], [[3, 10, 5], [3, 10, 5]], [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]], "outputs": [[[17, 2]], [[17, 17]], [[7, 0]], [[9, 1]]]}
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/583c5469977933319f000403
null
null
null
null
null
25,075
0
def max_and_min(arr1, arr2): diffs = [abs(x - y) for x in arr1 for y in arr2] return [max(diffs), min(diffs)]
# Question >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Given two array of integers(`arr1`,`arr2`). Your task is going to find a pair of numbers(an element in arr1, and another element in arr2), thei...
This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ of length $n$ consisting of integers from $1$ to $n$. The sequence may conta...
[ "MOD = 10 ** 9 + 7\nN = 200001\nfact = [1]\nfor i in range(1, N + 1):\n\tfact.append(fact[-1] * i % MOD)\n\ndef nCr(n, r):\n\tif n <= r:\n\t\treturn n == r\n\ta = fact[n]\n\tb = fact[n - r] * fact[r] % MOD\n\tb = pow(b, MOD - 2, MOD)\n\treturn a * b % MOD\nimport math\nimport bisect\nfor i in range(int(input())):\n...
{"inputs": ["4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", "4\n4 3 2\n1 2 4 3\n4 3 2\n1 1 1 1\n1 3 1\n1\n10 3 2\n5 6 1 3 2 9 8 1 2 4\n"], "outputs": ["2\n6\n1\n20\n", "1\n1\n1\n", "2\n4\n0\n15\n"]}
MEDIUM_HARD
['combinatorics', 'math', 'implementation', 'binary search', 'two pointers', 'sortings']
null
codeforces
['Sorting', 'Combinatorics', 'Amortized analysis', 'Implementation', 'Mathematics']
['Sorting', 'Amortized analysis']
https://codeforces.com/problemset/problem/1462/E2
4 seconds
2020-12-15
0
256 megabytes
null
25,073
0
MOD = 10 ** 9 + 7 N = 200001 fact = [1] for i in range(1, N + 1): fact.append(fact[-1] * i % MOD) def nCr(n, r): if n <= r: return n == r a = fact[n] b = fact[n - r] * fact[r] % MOD b = pow(b, MOD - 2, MOD) return a * b % MOD import math import bisect for i in range(int(input())): (n, m, k) = map(int, input()...
# Question This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ of length $n$ consisting of integers from $1$ to $n$. The sequen...
# Is the string uppercase? ## Task ```if-not:haskell,csharp,javascript,coffeescript,elixir,forth,go,dart,julia,cpp,reason,typescript,racket,ruby Create a method `is_uppercase()` to see whether the string is ALL CAPS. For example: ``` ```if:haskell,reason,typescript Create a method `isUpperCase` to see whether the str...
[ "def is_uppercase(inp):\n\treturn inp.isupper()\n", "def is_uppercase(inp):\n\treturn inp.upper() == inp\n", "is_uppercase = str.isupper\n", "def is_uppercase(inp):\n\tif inp.isupper():\n\t\treturn True\n\telse:\n\t\treturn False\n", "def is_uppercase(inf):\n\treturn str.isupper(inf)\n", "def is_uppercase...
def is_uppercase(inp):
{"fn_name": "is_uppercase", "inputs": [], "outputs": []}
EASY
['Strings', 'Fundamentals']
null
codewars
['String algorithms', 'Fundamentals']
[]
https://www.codewars.com/kata/56cd44e1aa4ac7879200010b
null
null
null
null
null
25,067
0
def is_uppercase(inp): return inp.isupper()
# Question # Is the string uppercase? ## Task ```if-not:haskell,csharp,javascript,coffeescript,elixir,forth,go,dart,julia,cpp,reason,typescript,racket,ruby Create a method `is_uppercase()` to see whether the string is ALL CAPS. For example: ``` ```if:haskell,reason,typescript Create a method `isUpperCase` to see whe...
Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one upward movement. There are N stairs between ground and next floor....
[ "for _ in range(int(input())):\n\tN = int(input())\n\tif N % 2 == 0:\n\t\tprint(N // 2 + 1)\n\telse:\n\t\tprint((N - 1) // 2 + 1)\n", "for _ in range(int(input())):\n\tn = int(input())\n\tprint(n // 2 + 1)\n", "for t in range(int(input())):\n\tn = int(input())\n\tprint(int(n / 2) + 1)\n", "t = int(input())\nw...
{"inputs": [["1", "3"]], "outputs": [["2"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/PBK12020/problems/ITGUY20
null
null
null
null
null
25,077
0
for _ in range(int(input())): N = int(input()) if N % 2 == 0: print(N // 2 + 1) else: print((N - 1) // 2 + 1)
# Question Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one upward movement. There are N stairs between ground and...
## Task To charge your mobile phone battery, do you know how much time it takes from 0% to 100%? It depends on your cell phone battery capacity and the power of the charger. A rough calculation method is: ``` 0% --> 85% (fast charge) (battery capacity(mAh) * 85%) / power of the charger(mA) 85% --> 95% (decreasing ch...
[ "calculate_time = lambda b, c: round(b / float(c) * 1.3 + 0.0001, 2)\n", "CHARGE_CONFIG = ((0.85, 1), (0.1, 0.5), (0.05, 0.2))\n\ndef calculate_time(battery, charger):\n\treturn round(0.0001 + sum((battery * pb / (charger * pc) for (pb, pc) in CHARGE_CONFIG)), 2)\n", "def calculate_time(battery, charger):\n\tre...
def calculate_time(battery,charger):
{"fn_name": "calculate_time", "inputs": [[1000, 500], [1500, 500], [2000, 1000], [5000, 1000], [1000, 5000], [3050, 2600]], "outputs": [[2.6], [3.9], [2.6], [6.5], [0.26], [1.53]]}
EASY
['Puzzles']
null
codewars
['Ad-hoc']
[]
https://www.codewars.com/kata/57ea0ee4491a151fc5000acf
null
null
null
null
null
25,078
0
calculate_time = lambda b, c: round(b / float(c) * 1.3 + 0.0001, 2)
# Question ## Task To charge your mobile phone battery, do you know how much time it takes from 0% to 100%? It depends on your cell phone battery capacity and the power of the charger. A rough calculation method is: ``` 0% --> 85% (fast charge) (battery capacity(mAh) * 85%) / power of the charger(mA) 85% --> 95% (d...
Madhav went to Riya's Birthday Party. He was a geek so he had no idea regarding which gift she'l like. So he took an array of integers with him. The array followed a particular order. First element of array is 1. Second element of array is 6. Other elements of the array are two less than the mean of the number precedin...
[ "x=eval(input())\nfor i in range(x):\n\tn=eval(input())\n\tprint(1+( ( 4 * ((n*(n-1))/2))%1000000007 + (n-1)%1000000007) %1000000007)\n", "t=int(input())\nM=10**9+7\nfor i in range(t):\n\tn=int(input())\n\tn=n%M\n\tx=(2*n)%M-1\n\tans=(n*x)%M\n\tprint(ans)\n", "for _ in range(int(input())):\n\tn=int(input())\n\t...
{"inputs": [], "outputs": []}
EASY
['Math', 'Algorithms']
riyas-birthday-party-1
hackerearth
['Mathematics']
[]
null
null
null
null
null
null
25,080
0
x=eval(input()) for i in range(x): n=eval(input()) print(1+( ( 4 * ((n*(n-1))/2))%1000000007 + (n-1)%1000000007) %1000000007)
# Question Madhav went to Riya's Birthday Party. He was a geek so he had no idea regarding which gift she'l like. So he took an array of integers with him. The array followed a particular order. First element of array is 1. Second element of array is 6. Other elements of the array are two less than the mean of the num...
We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T. ...
[ "for _ in range(int(input())):\n\tbi = input().strip()\n\tdp = [0 if i < 2 else len(bi) for i in range(6)]\n\tfor c in bi:\n\t\tif c == '1':\n\t\t\tdp[3] = min(dp[3], dp[0])\n\t\t\tdp[0] += 1\n\t\t\tdp[5] = min(dp[5], dp[2])\n\t\t\tdp[2] += 1\n\t\t\tdp[4] += 1\n\t\telse:\n\t\t\tdp[2] = min(dp[2], dp[1])\n\t\t\tdp[1...
{"inputs": [["4", "010111101", "1011100001011101", "0110", "111111"]], "outputs": [["2", "3", "0", "0"]]}
VERY_HARD
['dynamic-programming', 'brute-force', 'cook113', 'easy', 'kmaaszraa']
null
codechef
['Dynamic programming', 'Complete search']
['Dynamic programming', 'Complete search']
https://www.codechef.com/problems/PRFYIT
1 seconds
2019-12-15
0
50000 bytes
null
25,081
0
for _ in range(int(input())): bi = input().strip() dp = [0 if i < 2 else len(bi) for i in range(6)] for c in bi: if c == '1': dp[3] = min(dp[3], dp[0]) dp[0] += 1 dp[5] = min(dp[5], dp[2]) dp[2] += 1 dp[4] += 1 else: dp[2] = min(dp[2], dp[1]) dp[1] += 1 dp[4] = min(dp[4], dp[3]) dp[3] ...
# Question We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string wil...
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? - For every i (1≤i≤n), the sum of the terms from the 1-st through i-t...
[ "N = int(input())\nA = [int(_) for _ in input().split()]\n\ndef calc(A, y):\n\tresult = abs(A[0] - y)\n\tt = y\n\tif t == 0:\n\t\treturn 10 ** 30\n\tfor a in A[1:N]:\n\t\ttt = t + a\n\t\tif t * tt >= 0:\n\t\t\tm = -t // abs(t)\n\t\t\tresult += abs(m - tt)\n\t\t\ttt = m\n\t\tt = tt\n\treturn result\nresult = min(cal...
{"inputs": ["4\n1 -3 1 0\n", "5\n3 -6 4 -5 7\n", "6\n-1 4 3 2 -5 4\n"], "outputs": ["4\n", "0\n", "8\n"]}
MEDIUM_HARD
[]
null
atcoder
[]
[]
https://atcoder.jp/contests/arc072/tasks/arc072_a
null
null
null
null
null
25,069
0
N = int(input()) A = [int(_) for _ in input().split()] def calc(A, y): result = abs(A[0] - y) t = y if t == 0: return 10 ** 30 for a in A[1:N]: tt = t + a if t * tt >= 0: m = -t // abs(t) result += abs(m - tt) tt = m t = tt return result result = min(calc(A, A[0]), calc(A, -1), calc(A, +1)) print...
# Question You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? - For every i (1≤i≤n), the sum of the terms from the 1-st...
We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result. -----Constraints----- - K is an integer between 1 and 100 (inclusive). - S is a ...
[ "K = int(input())\nS = str(input())\nif K >= len(S):\n\tprint(S)\nelse:\n\tprint(S[0:K] + '...')\n", "k = int(input())\nS = input()\nif len(S) > k:\n\tS = S[:k] + '...'\nprint(S)\n", "K = int(input())\nS = input()\nif len(S) <= K:\n\tprint(S)\nelse:\n\tfor i in range(K):\n\t\tprint(S[i], end='')\n\tprint('...')...
{"inputs": ["7\nnikoandsolstice\n", "40\nferelibenterhominesidquodvoluntcredunt\n", "1\nz\n", "2\nz\n", "9\ncfmfbfbnyigsejhwuhs\n", "35\npemetdsjkmxuadhyrsyngoawfywyylglksmprtues\n", "26\newwcjswgwdeijtbfkrlojvygql\n", "27\nohgmguyzmrwntvrxzzwxtxzlbuc\n", "51\neelettrhmmoakwpdmfkrvyhtxxtxrxcdimffomblxtoicov\n", "22\nvy...
EASY
[]
AtCoder Beginner Contest 168 - ... (Triple Dots)
atcoder
[]
[]
https://atcoder.jp/contests/abc168/tasks/abc168_b
2.0 seconds
null
null
1024.0 megabytes
null
25,074
0
K = int(input()) S = str(input()) if K >= len(S): print(S) else: print(S[0:K] + '...')
# Question We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in S, append ... to the end of them, and print the result. -----Constraints----- - K is an integer between 1 and 100 (inclusive)...
Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if fo...
[ "import sys, math\nimport io, os\n\ndef data():\n\treturn sys.stdin.buffer.readline().strip()\n\ndef mdata():\n\treturn list(map(int, data().split()))\n\ndef outl(var):\n\tsys.stdout.write(' '.join(map(str, var)) + '\\n')\n\ndef out(var):\n\tsys.stdout.write(str(var) + '\\n')\nmod = 998244353\nn = int(data())\nl = ...
{"inputs": ["333625\n", "693549\n", "757606\n", "1000000\n", "999228\n", "443013\n", "825195\n", "160945\n", "489857\n", "563368\n", "372544\n", "315936\n", "446167\n", "797112\n", "75417\n", "119444\n", "916542\n", "5\n", "4\n", "101\n", "533946\n", "578405\n", "165973\n", "520592\n", "110815\n", "208619\n", "541831\n...
MEDIUM_HARD
['combinatorics', 'math', 'dp']
null
codeforces
['Dynamic programming', 'Combinatorics', 'Mathematics']
['Dynamic programming']
https://codeforces.com/problemset/problem/1528/B
1.0 seconds
null
null
256.0 megabytes
null
25,082
0
import sys, math import io, os def data(): return sys.stdin.buffer.readline().strip() def mdata(): return list(map(int, data().split())) def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n') def out(var): sys.stdout.write(str(var) + '\n') mod = 998244353 n = int(data()) l = [1] * (n + 1) for i in rang...
# Question Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called...
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate as possible...
[ "def solve(R, r, k):\n\tr = r / R\n\tn = k\n\tanswer = (1 - r) * r / (2 * (n ** 2 * (1 - r) ** 2 + r))\n\tanswer = 2 * R * answer\n\tprint('%.10f' % answer)\nt = int(input())\nfor i in range(t):\n\t(R, r, k) = map(int, input().split())\n\tsolve(R, r, k)\n" ]
{"inputs": ["1\n4 2 2\n", "1\n1000 999 1\n", "1\n7 2 1\n", "1\n1000 1 1\n", "1\n2 1 1\n", "1\n1000 1 1000\n", "1\n8 7 2\n", "1\n1000 998 1000\n", "1\n1000 500 123\n", "1\n1000 1 2\n", "1\n1000 999 2\n", "1\n7 2 2\n", "1\n1100 999 1\n", "1\n8 2 1\n", "1\n1000 2 2\n", "1\n4 1 1\n", "1\n1001 1 1000\n", "1\n16 7 2\n", "1\n...
VERY_HARD
['geometry']
null
codeforces
['Geometry']
[]
https://codeforces.com/problemset/problem/77/E
1.0 seconds
null
null
256.0 megabytes
null
25,085
0
def solve(R, r, k): r = r / R n = k answer = (1 - r) * r / (2 * (n ** 2 * (1 - r) ** 2 + r)) answer = 2 * R * answer print('%.10f' % answer) t = int(input()) for i in range(t): (R, r, k) = map(int, input().split()) solve(R, r, k)
# Question Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate...
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part will be a tree...
[ "MOD = 1000000007\nn = int(input())\np = [int(x) for x in input().split()]\nx = [int(x) for x in input().split()]\nchildren = [[] for x in range(n)]\nfor i in range(1, n):\n\tchildren[p[i - 1]].append(i)\ncount = [(0, 0) for i in range(n)]\nfor i in reversed(range(n)):\n\tprod = 1\n\tfor ch in children[i]:\n\t\tpro...
{"inputs": ["3\n0 0\n0 1 1\n", "6\n0 1 1 0 4\n1 1 0 0 1 0\n", "10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1\n", "5\n0 1 1 3\n0 0 0 1 1\n", "10\n0 1 1 2 4 3 3 3 2\n1 0 1 1 1 0 0 1 1 0\n", "100\n0 0 2 2 0 3 5 0 6 2 0 4 0 2 3 7 8 3 15 19 13 8 18 19 3 14 23 9 6 3 6 17 26 24 20 6 4 27 8 5 14 5 35 31 27 3 41 25 20 14 25 31 49 ...
HARD
['trees', 'dfs and similar', 'dp']
null
codeforces
['Tree algorithms', 'Dynamic programming', 'Graph traversal']
['Dynamic programming']
https://codeforces.com/problemset/problem/461/B
null
2019-12-31
null
null
null
25,087
0
MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1, n): children[p[i - 1]].append(i) count = [(0, 0) for i in range(n)] for i in reversed(range(n)): prod = 1 for ch in children[i]: prod *= count[ch][0] + c...
# Question Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it will split into (k + 1) parts. Note, that each part wi...
You are given an array A consisting of N positive integers. Suppose F(B,X) gives the minimum positive integer Y such that: X divides Y \cdot B_{i} for all (1 ≤ i ≤ |B|). Find the value of F(A,A_{i}) for all (1 ≤ i ≤ N). ------ Input Format ------ - The first line of input contains a single integer T, denoting the...
[ "import math as m\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tA = list(map(int, input().split()))\n\tgcd = A[0]\n\tfor j in A:\n\t\tgcd = m.gcd(j, gcd)\n\tfor j in A:\n\t\tprint(j // gcd, end=' ')\n\tprint()\n", "import math\ntest = int(input())\nfor t in range(test):\n\tn = int(input())\n\tarr =...
{"inputs": ["2\n2\n1 2\n3\n2 2 2\n"], "outputs": ["1 2\n1 1 1\n"]}
MEDIUM
['Mathematics', 'Number Theory', 'GCD']
null
codechef
['Number theory', 'Mathematics']
[]
https://www.codechef.com/problems/DIVISIBLEBY
2 seconds
2022-12-10
0
50000 bytes
null
25,084
0
import math as m t = int(input()) for _ in range(t): n = int(input()) A = list(map(int, input().split())) gcd = A[0] for j in A: gcd = m.gcd(j, gcd) for j in A: print(j // gcd, end=' ') print()
# Question You are given an array A consisting of N positive integers. Suppose F(B,X) gives the minimum positive integer Y such that: X divides Y \cdot B_{i} for all (1 ≤ i ≤ |B|). Find the value of F(A,A_{i}) for all (1 ≤ i ≤ N). ------ Input Format ------ - The first line of input contains a single integer T, ...
### What is simplifying a square root? If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5. ##### The above example: ![simplify_roots_example.png](https://i....
[ "def simplify(n):\n\tfor d in range(int(n ** 0.5), 0, -1):\n\t\tif not n % d ** 2:\n\t\t\tbreak\n\tif d * d == n:\n\t\treturn '%d' % d\n\telif d == 1:\n\t\treturn 'sqrt %d' % n\n\telse:\n\t\treturn '%d sqrt %d' % (d, n // d ** 2)\n\ndef desimplify(s):\n\t(x, _, y) = s.partition('sqrt')\n\treturn int(x or '1') ** 2 ...
def simplify(n):
{"fn_name": "simplify", "inputs": [[1], [2], [3], [8], [15], [16], [18], [20], [24], [32], [4], [7], [9], [10], [12], [13], [14], [50], [80], [200]], "outputs": [["1"], ["sqrt 2"], ["sqrt 3"], ["2 sqrt 2"], ["sqrt 15"], ["4"], ["3 sqrt 2"], ["2 sqrt 5"], ["2 sqrt 6"], ["4 sqrt 2"], ["2"], ["sqrt 7"], ["3"], ["sqrt 10"]...
EASY
['Fundamentals']
null
codewars
['Fundamentals']
[]
https://www.codewars.com/kata/5850e85c6e997bddd300005d
null
null
null
null
null
25,090
0
def simplify(n): for d in range(int(n ** 0.5), 0, -1): if not n % d ** 2: break if d * d == n: return '%d' % d elif d == 1: return 'sqrt %d' % n else: return '%d sqrt %d' % (d, n // d ** 2) def desimplify(s): (x, _, y) = s.partition('sqrt') return int(x or '1') ** 2 * int(y or '1')
# Question ### What is simplifying a square root? If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5. ##### The above example: ![simplify_roots_example.png...
You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side. Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$-th section ...
[ "for _ in range(int(input())):\n\t(n, h) = map(int, input().split())\n\ta = list(map(int, input().split()))\n\tmi = a[0]\n\tma = a[0]\n\ta = a[1:]\n\ts = 1\n\tfor x in a:\n\t\tmi = max(x, mi - h + 1)\n\t\tma = min(x + h - 1, ma + h - 1)\n\t\tif ma < mi:\n\t\t\ts = 0\n\tif mi != a[-1]:\n\t\ts = 0\n\tprint('YES') if ...
{"inputs": ["3\n6 3\n0 0 2 5 1 1\n2 3\n0 2\n3 2\n3 0 2\n", "1\n2 2\n2 8\n", "1\n2 2\n4 8\n", "1\n2 4\n21 56\n", "1\n2 3\n10 0\n", "1\n2 10\n7 4\n", "1\n2 2\n3 9\n", "1\n2 3\n10 2\n", "5\n2 2\n0 0\n2 2\n0 1\n2 2\n1 0\n2 2\n0 2\n2 2\n2 0\n", "1\n2 3\n10 8\n", "1\n2 4\n1 6\n", "1\n2 3\n0 9\n", "1\n2 3\n2 10\n", "1\n2 2\n0...
MEDIUM_HARD
['two pointers', 'greedy', 'implementation', 'dp']
null
codeforces
['Dynamic programming', 'Amortized analysis', 'Implementation', 'Greedy algorithms']
['Dynamic programming', 'Amortized analysis', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1469/C
2 seconds
2020-12-28
1
256 megabytes
null
25,076
0
for _ in range(int(input())): (n, h) = map(int, input().split()) a = list(map(int, input().split())) mi = a[0] ma = a[0] a = a[1:] s = 1 for x in a: mi = max(x, mi - h + 1) ma = min(x + h - 1, ma + h - 1) if ma < mi: s = 0 if mi != a[-1]: s = 0 print('YES') if s == 1 else print('NO')
# Question You want to build a fence that will consist of $n$ equal sections. All sections have a width equal to $1$ and height equal to $k$. You will place all sections in one line side by side. Unfortunately, the ground beneath the fence is not flat. For simplicity, you can think that the ground level under the $i$...
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t...
[ "(x, a, b) = map(int, input().split())\nprint('A' if abs(x - a) < abs(x - b) else 'B')\n", "(x, a, b) = map(int, input().split())\nprint(['B', 'A'][abs(x - a) < abs(x - b)])\n", "(x, a, b) = list(map(float, input().split()))\nif abs(x - a) < abs(x - b):\n\tprint('A')\nelse:\n\tprint('B')\n", "(x, a, b) = map(...
{"inputs": ["5 2 7\n", "1 999 1000\n", "1 999 0000", "1 381 1110", "5 1 7", "1 999 0100", "10 1 7", "1 999 0101", "10 2 7", "1 999 0001", "10 1 9", "1 381 0001", "10 2 9", "1 381 0101", "17 2 9", "1 381 0111", "23 2 9", "1 381 0110", "23 3 9", "23 1 9", "1 213 1110", "23 1 5", "1 213 0110", "16 1 5", "1 213 0010", "16 ...
EASY
[]
AtCoder Beginner Contest 071 - Meal Delivery
atcoder
[]
[]
https://atcoder.jp/contests/abc071/tasks/abc071_a
2.0 seconds
null
null
256.0 megabytes
null
25,089
0
(x, a, b) = map(int, input().split()) print('A' if abs(x - a) < abs(x - b) else 'B')
# Question Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two po...
Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it. Complete the function that receives a string and encrypt it with t...
[ "def simple_transposition(text):\n\treturn text[::2] + text[1::2]\n", "def simple_transposition(text):\n\ttext1 = text[0::2]\n\ttext2 = text[1::2]\n\treturn text1 + text2\n", "def simple_transposition(text):\n\trowOne = True\n\tone = ''\n\ttwo = ''\n\tfor x in text:\n\t\tif rowOne:\n\t\t\tone += x\n\t\telse:\n\...
def simple_transposition(text):
{"fn_name": "simple_transposition", "inputs": [["Sample text"], ["Simple transposition"], ["All that glitters is not gold"], ["The better part of valor is discretion"], ["Conscience does make cowards of us all"], ["Imagination is more important than knowledge"]], "outputs": [["Sml etapetx"], ["Sml rnpstoipetasoiin"], [...
EASY
[]
null
codewars
[]
[]
https://www.codewars.com/kata/57a153e872292d7c030009d4
null
null
null
null
null
25,092
0
def simple_transposition(text): return text[::2] + text[1::2]
# Question Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it. Complete the function that receives a string and encry...
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can ...
[ "from collections import Counter as co\nx = int(input())\ny = list(map(int, input().split()))\nprint(x - max(co(y).values()))\n", "n = int(input())\nc = [int(x) for x in input().split(' ')]\nc.sort()\ni = 0\na = 0\nfor j in range(n):\n\tif c[i] < c[j]:\n\t\ta += 1\n\t\ti += 1\nprint(a)\n", "n = int(input())\na ...
{"inputs": ["7\n10 1 1 1 5 5 3\n", "5\n1 1 1 1 1\n", "6\n300000000 200000000 300000000 200000000 1000000000 300000000\n", "10\n1 2 3 4 5 6 7 8 9 10\n", "1\n1\n", "7\n3 5 2 2 5 2 4\n", "5\n1 5 4 2 3\n", "7\n3 5 2 2 5 2 4\n", "10\n1 2 3 4 5 6 7 8 9 10\n", "1\n1\n", "5\n1 5 4 2 3\n", "6\n300000000 200000000 300000000 2000...
EASY
['data structures', 'combinatorics', 'math', 'two pointers', 'sortings']
null
codeforces
['Combinatorics', 'Amortized analysis', 'Sorting', 'Mathematics', 'Data structures']
['Data structures', 'Sorting', 'Amortized analysis']
https://codeforces.com/problemset/problem/1007/A
null
2019-12-31
null
null
null
25,083
0
from collections import Counter as co x = int(input()) y = list(map(int, input().split())) print(x - max(co(y).values()))
# Question You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 4...
You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of the construction, which is in rectangle shape: N x M. Then in the ...
[ "directions = [(-1, 0), (0, 1), (1, 0), (0, -1)]\ni_cant_do_bitwise_operations = {0: (False, False, False, False), 1: (False, False, False, True), 2: (False, False, True, False), 3: (False, False, True, True), 4: (False, True, False, False), 5: (False, True, False, True), 6: (False, True, True, False), 7: (False, T...
{"inputs": ["6 1\n13\n5\n7\n15\n13\n7\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 11 12 13\n5 15 3 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 8 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 6\n", "4 5\n9 14 11 12 13\n5 15 11 6 ...
MEDIUM
['dfs and similar', 'bitmasks']
null
codeforces
['Bit manipulation', 'Graph traversal']
['Bit manipulation']
https://codeforces.com/problemset/problem/1600/J
1.0 seconds
null
null
256.0 megabytes
null
25,094
0
directions = [(-1, 0), (0, 1), (1, 0), (0, -1)] i_cant_do_bitwise_operations = {0: (False, False, False, False), 1: (False, False, False, True), 2: (False, False, True, False), 3: (False, False, True, True), 4: (False, True, False, False), 5: (False, True, False, True), 6: (False, True, True, False), 7: (False, True, T...
# Question You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of the construction, which is in rectangle shape: N x M. ...
Example Input 2 2 2 1 0 0 0 Output 24
[ "import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools\nsys.setrecursionlimit(10 ** 7)\ninf = 10 ** 20\neps = 1.0 / 10 ** 10\nmod = 10 ** 9 + 7\ndd = [(-1, 0), (0, 1), (1, 0), (0, -1)]\nddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), ...
{"inputs": ["2 2 2 0\n0 0 0", "2 1 2 0\n-1 -1 0", "2 0 2 0\n-1 0 0", "4 2 2 0\n0 0 1", "3 1 2 0\n-1 0 -1", "1 2 1 0\n-2 -1 0", "2 2 3 0\n-1 -1 -1", "1 1 4 0\n0 1 -1", "3 2 0 0\n-1 -1 -1", "1 0 1 0\n0 1 -1", "1 -1 1 0\n0 1 -1", "1 0 0 0\n0 0 -1", "1 1 1 0\n0 0 -1", "1 2 0 0\n0 0 -1", "1 2 4 0\n-1 -1 0", "-1 2 0 0\n-2 0 ...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
5.0 seconds
null
null
268.435456 megabytes
null
25,098
0
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] ...
# Question Example Input 2 2 2 1 0 0 0 Output 24 # Solution ```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ...
Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array only else print $0$. Note: string contains characters in lower case only. ...
[ "t = int(input())\nfor _ in range(t):\n\tS = set(input().strip())\n\tn = int(input().strip())\n\ta = set(input().strip().split(' '))\n\tg = True\n\tfor i in S:\n\t\tif i not in a:\n\t\t\tg = False\n\tif g:\n\t\tprint(1)\n\telse:\n\t\tprint(0)\n", "for _ in range(int(input())):\n\tstring = input().strip()\n\tn = i...
{"inputs": [["3", "abcd", "4", "a b c d", "aabbbcccdddd", "4", "a b c d", "acd", "3", "a b d"]], "outputs": [["1", "1", "0"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/CDGO2021/problems/STRNCHAR
null
null
null
null
null
25,095
0
t = int(input()) for _ in range(t): S = set(input().strip()) n = int(input().strip()) a = set(input().strip().split(' ')) g = True for i in S: if i not in a: g = False if g: print(1) else: print(0)
# Question Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array only else print $0$. Note: string contains characters in lower...
You are a given an array $a$ of length $n$. Find a subarray $a[l..r]$ with length at least $k$ with the largest median. A median in an array of length $n$ is an element which occupies position number $\lfloor \frac{n + 1}{2} \rfloor$ after we sort the elements in non-decreasing order. For example: $median([1, 2, 3, 4]...
[ "import sys\n(n, k) = map(int, input().split())\na = list(map(int, input().split()))\nl = 0\nr = n\nwhile l < r:\n\tif l + 1 == r:\n\t\ttry1 = r\n\t\tflag = 0\n\t\ttmp = 0\n\t\tgrid = [0]\n\t\tfor i in range(n):\n\t\t\tif a[i] >= try1:\n\t\t\t\ttmp += 1\n\t\t\telse:\n\t\t\t\ttmp -= 1\n\t\t\tgrid.append(tmp)\n\t\tlo...
{"inputs": ["5 3\n1 2 3 2 1\n", "4 2\n1 2 3 4\n", "10 7\n9 6 2 4 4 8 4 6 2 1\n", "100 64\n43 30 88 55 14 10 78 99 6 29 10 79 11 96 7 20 37 65 79 78 46 62 37 47 37 60 4 28 24 9 87 4 20 94 47 95 100 13 60 24 34 4 89 63 65 20 11 68 99 47 41 38 37 23 23 13 3 1 39 28 65 95 98 44 64 58 77 11 89 49 58 30 77 20 94 40 15 17 62 ...
HARD
['data structures', 'binary search', 'dp']
null
codeforces
['Dynamic programming', 'Sorting', 'Data structures']
['Dynamic programming', 'Sorting', 'Data structures']
https://codeforces.com/problemset/problem/1486/D
2 seconds
2021-02-18
0
256 megabytes
null
25,088
0
import sys (n, k) = map(int, input().split()) a = list(map(int, input().split())) l = 0 r = n while l < r: if l + 1 == r: try1 = r flag = 0 tmp = 0 grid = [0] for i in range(n): if a[i] >= try1: tmp += 1 else: tmp -= 1 grid.append(tmp) lowestprev = 0 for i in range(k, n + 1): lowestpr...
# Question You are a given an array $a$ of length $n$. Find a subarray $a[l..r]$ with length at least $k$ with the largest median. A median in an array of length $n$ is an element which occupies position number $\lfloor \frac{n + 1}{2} \rfloor$ after we sort the elements in non-decreasing order. For example: $median(...
It is lunch time at the Vibrant Gujarat Summit and all the investors are called for the executive lunch. When Bruce reached the lunch area, he found that the waiter was taking out bowls from a big box containing some amount of golden bowls and other bronze bowls. The bowls were taken out at random. Each dish contains e...
[ "v = eval(input())\n\nprint(int((v*(v-1)/2)**.5)+1)\n", "import math\nn = eval(input())\nprint(int((1 + math.sqrt((1 + (2*n*(n-1)))))/2))\n", "import math\n\nn=input()\nn=int(n)\nn=n*(n-1)\nn=2*n;\nn=n+1\nn=math.sqrt(n) + 1\nn=n/2\nprint(int(n))\n\n", "n=int(input())\ni=1\nprint(int((n*(n-1)/2)**0.5)+1)\n", ...
{"inputs": ["4684660", "120", "1235216565974041", "1070379110497", "31509019101", "159140520", "23661"], "outputs": ["756872327473", "85", "16731", "873430010034205", "22280241075", "3312555", "112529341"]}
UNKNOWN_DIFFICULTY
[]
golden-bowl
hackerearth
[]
[]
null
null
null
null
null
null
25,096
0
v = eval(input()) print(int((v*(v-1)/2)**.5)+1)
# Question It is lunch time at the Vibrant Gujarat Summit and all the investors are called for the executive lunch. When Bruce reached the lunch area, he found that the waiter was taking out bowls from a big box containing some amount of golden bowls and other bronze bowls. The bowls were taken out at random. Each dis...
You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the answer. Examples Input abcbcba Output 21 Input missi...
[ "class StrAlg:\n\n\t@staticmethod\n\tdef sa_naive(s):\n\t\tn = len(s)\n\t\tsa = list(range(n))\n\t\tsa.sort(key=lambda x: s[x:])\n\t\treturn sa\n\n\t@staticmethod\n\tdef sa_doubling(s):\n\t\tn = len(s)\n\t\tsa = list(range(n))\n\t\trnk = s\n\t\ttmp = [0] * n\n\t\tk = 1\n\t\twhile k < n:\n\t\t\tsa.sort(key=lambda x:...
{"inputs": ["abcacbb", "baaaa", "aaabacacb", "mjssissippi", "abbacbb", "baaba", "mjssisrippi", "bcacabaa`", "mjssisripph", "bcacabab`", "b`cabba", "hppirsitsjm", "acacabab`", "bbba`", "`babb", "cbaaada`a", "mjsthspiroh", "cbdbaab`a", "abdaa_`", "`ca`b", "`_adb", "abababddc", "hnripohtqgm", "ccb`ae_ba", "c_abdb^", "d`ad...
UNKNOWN_DIFFICULTY
[]
AtCoder Library Practice Contest - Number of Substrings
atcoder
[]
[]
null
5.0 seconds
null
null
1024.0 megabytes
null
25,102
0
class StrAlg: @staticmethod def sa_naive(s): n = len(s) sa = list(range(n)) sa.sort(key=lambda x: s[x:]) return sa @staticmethod def sa_doubling(s): n = len(s) sa = list(range(n)) rnk = s tmp = [0] * n k = 1 while k < n: sa.sort(key=lambda x: (rnk[x], rnk[x + k]) if x + k < n else (rnk[x], ...
# Question You are given a string of length N. Calculate the number of distinct substrings of S. Constraints * 1 \leq N \leq 500,000 * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output Print the answer. Examples Input abcbcba Output 21 ...
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*. A segment is *good* if it can be divided into at most K segments such that the sum of elements in each of these sub-segments is ...
[ "def build(N, start_index):\n\tup = [[None] * N for _ in range(20)]\n\tup[0] = start_index\n\tfor i in range(1, 20):\n\t\tfor j in range(N):\n\t\t\tp = up[i - 1][j]\n\t\t\tif p == -1:\n\t\t\t\tup[i][j] = -1\n\t\t\telse:\n\t\t\t\tup[i][j] = up[i - 1][p]\n\treturn up\n\ndef call(up, node, K):\n\t(last, jump) = (node,...
{"inputs": ["2\n5 2 5\n1 3 2 1 5\n5 3 5\n5 1 5 1 1"], "outputs": ["4\n4"]}
VERY_HARD
['binary-search', 'present_sir', 'easy', 'binary-lifting', 'ltime98']
null
codechef
['Sorting', 'Tree queries', 'Range queries']
['Sorting', 'Range queries']
https://www.codechef.com/problems/LGSEG
1 seconds
2021-07-29
0
50000 bytes
null
25,105
0
def build(N, start_index): up = [[None] * N for _ in range(20)] up[0] = start_index for i in range(1, 20): for j in range(N): p = up[i - 1][j] if p == -1: up[i][j] = -1 else: up[i][j] = up[i - 1][p] return up def call(up, node, K): (last, jump) = (node, 1) for i in range(19): if node == -1: ...
# Question Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has a sequence A_{1}, A_{2}, \ldots, A_{N}. Let's call a contiguous subsequence of A a *segment*. A segment is *good* if it can be divided into at most K segments such that the sum of elements in each of these sub-...
Given an array of integers arr, you are initially positioned at the first index of the array. In one step you can jump from index i to index: i + 1 where: i + 1 < arr.length. i - 1 where: i - 1 >= 0. j where: arr[i] == arr[j] and i != j. Return the minimum number of steps to reach the last index of the array. Notice ...
[ "from collections import deque\n\nclass Solution:\n\n\tdef minJumps(self, arr: list) -> int:\n\t\tif len(arr) == 1:\n\t\t\treturn 0\n\t\tgraph = {}\n\t\tfor (i, n) in enumerate(arr):\n\t\t\tif n in graph:\n\t\t\t\tgraph[n].append(i)\n\t\t\telse:\n\t\t\t\tgraph[n] = [i]\n\t\tcurs = [0]\n\t\tother = [len(arr) - 1]\n\...
class Solution: def minJumps(self, arr: List[int]) -> int:
{"fn_name": "minJumps", "inputs": [[[100, -23, -23, 404, 100, 23, 23, 23, 3, 404]]], "outputs": [3]}
MEDIUM
['Array', 'Breadth-First Search', 'Hash Table']
null
leetcode
['Data structures', 'Graph traversal']
['Data structures']
https://leetcode.com/problems/jump-game-iv/
null
null
null
null
null
25,093
0
from collections import deque class Solution: def minJumps(self, arr: list) -> int: if len(arr) == 1: return 0 graph = {} for (i, n) in enumerate(arr): if n in graph: graph[n].append(i) else: graph[n] = [i] curs = [0] other = [len(arr) - 1] visited = {0} visited2 = {len(arr) - 1} ste...
# Question Given an array of integers arr, you are initially positioned at the first index of the array. In one step you can jump from index i to index: i + 1 where: i + 1 < arr.length. i - 1 where: i - 1 >= 0. j where: arr[i] == arr[j] and i != j. Return the minimum number of steps to reach the last index of the ar...
Given an array A of integers, we must modify the array in the following way: we choose an i and replace A[i] with -A[i], and we repeat this process K times in total.  (We may choose the same index i multiple times.) Return the largest possible sum of the array after modifying it in this way.   Example 1: Input: A = [4,...
[ "class Solution:\n\n\tdef largestSumAfterKNegations(self, A: List[int], K: int) -> int:\n\t\tA.sort()\n\t\ti = 0\n\t\twhile A[i] < 0 and K > 0:\n\t\t\tA[i] *= -1\n\t\t\ti += 1\n\t\t\tK -= 1\n\t\tif K % 2 == 1 and 0 not in A:\n\t\t\treturn sum(A) - 2 * min(A)\n\t\treturn sum(A)\n", "class Solution:\n\n\tdef larges...
class Solution: def largestSumAfterKNegations(self, A: List[int], K: int) -> int:
{"fn_name": "largestSumAfterKNegations", "inputs": [[[-2, 3, 4], 1], [[4, 2, 3], 1], [[3, -1, 0, 2], 3], [[2, -3, -1, 5, -4], 2]], "outputs": [9, 5, 6, 13]}
EASY
['Array', 'Sorting', 'Greedy']
null
leetcode
['Sorting', 'Data structures', 'Greedy algorithms']
['Sorting', 'Data structures', 'Greedy algorithms']
https://leetcode.com/problems/maximize-sum-of-array-after-k-negations/
null
null
null
null
null
25,106
0
class Solution: def largestSumAfterKNegations(self, A: List[int], K: int) -> int: A.sort() i = 0 while A[i] < 0 and K > 0: A[i] *= -1 i += 1 K -= 1 if K % 2 == 1 and 0 not in A: return sum(A) - 2 * min(A) return sum(A)
# Question Given an array A of integers, we must modify the array in the following way: we choose an i and replace A[i] with -A[i], and we repeat this process K times in total.  (We may choose the same index i multiple times.) Return the largest possible sum of the array after modifying it in this way.   Example 1: In...
Problem statement 2D, who is good at cooking, is trying to make lunch. Cooking requires all N ingredients a_ {0}, a_ {1},…, a_ {N−1}. Now, 2D's refrigerator doesn't contain any ingredients, so I have to go to the supermarket to buy it. At the supermarket, you can buy the material a_ {i} for the price x_ {i} yen. 2D ...
[ "n = int(input())\ndic = {}\nprice = []\nfor i in range(n):\n\t(a, x) = input().split()\n\tdic[a] = i\n\tprice.append(int(x))\nparent = [i for i in range(n)]\n\ndef find(x):\n\tif parent[x] == x:\n\t\treturn x\n\tparent[x] = find(parent[x])\n\treturn parent[x]\nm = int(input())\nfor _ in range(m):\n\t(s, t) = input...
{"inputs": ["2\ntako 2\nyaki 1\n0\ntako yaki", "2\ntako 3\nyaji 1\n-1\noakt yaki", "2\ntako 1\nyaij 1\n-2\noajt yaki", "2\ntako 1\njiay 0\n-2\nouja yakg", "2\npaks 1\naxii -1\n-3\nokua hx`j", "2\npaks 0\naxii -1\n-1\nnkua hx`j", "2\ntako 4\nyaji 1\n0\ntbko yaki", "2\ntbko 6\nyaji 1\n-1\noajs yaki", "2\noakt 1\njiax 5\n...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
134.217728 megabytes
null
25,109
0
n = int(input()) dic = {} price = [] for i in range(n): (a, x) = input().split() dic[a] = i price.append(int(x)) parent = [i for i in range(n)] def find(x): if parent[x] == x: return x parent[x] = find(parent[x]) return parent[x] m = int(input()) for _ in range(m): (s, t) = input().split() (si, ti) = (dic[s]...
# Question Problem statement 2D, who is good at cooking, is trying to make lunch. Cooking requires all N ingredients a_ {0}, a_ {1},…, a_ {N−1}. Now, 2D's refrigerator doesn't contain any ingredients, so I have to go to the supermarket to buy it. At the supermarket, you can buy the material a_ {i} for the price x_ {...
Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \leq 10^{9} holds. The robot is initi...
[ "def E(i, y):\n\tif i == 1:\n\t\treturn 5 * y\n\telse:\n\t\treturn (2 * i + 1) * y\n\ndef ceil(a, b):\n\treturn -(-a // b)\n(N, X) = map(int, input().split())\nx = [int(i) for i in input().split()]\na = [0]\nfor i in range(N):\n\ta.append(a[-1] + x[i])\nans = 10 ** 50\nfor k in range(1, N + 1):\n\ttmp = (N + k) * X...
{"inputs": ["5 1\n1 1856513539 999999998 999999999 1000000000", "16 10\n1 7 12 27 52 75 731 13856 395504 534840 1276551 903860 9384806 19108104 82684732 535447408", "2 100\n1 13", "10 8851025\n38 87 668 4845 22601 65499 90236 790604 4290609 4894746", "16 10\n1 7 12 27 52 75 731 18298 395504 534840 1276551 903860 938480...
UNKNOWN_DIFFICULTY
[]
AtCoder Grand Contest 027 - Garbage Collector
atcoder
[]
[]
null
2.0 seconds
null
null
1024.0 megabytes
null
25,104
0
def E(i, y): if i == 1: return 5 * y else: return (2 * i + 1) * y def ceil(a, b): return -(-a // b) (N, X) = map(int, input().split()) x = [int(i) for i in input().split()] a = [0] for i in range(N): a.append(a[-1] + x[i]) ans = 10 ** 50 for k in range(1, N + 1): tmp = (N + k) * X for i in range(N // k): t...
# Question Snuke has decided to use a robot to clean his room. There are N pieces of trash on a number line. The i-th piece from the left is at position x_i. We would like to put all of them in a trash bin at position 0. For the positions of the pieces of trash, 0 < x_1 < x_2 < ... < x_{N} \leq 10^{9} holds. The ro...
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$-th day he should solve $k$ problems. Polycarp has a list of $n$ ...
[ "def get_num():\n\treturn int(input())\n\ndef print_arr(arr: list):\n\tfor val in arr:\n\t\tprint(val)\n\ndef read_num_list(k):\n\tnum_str = input()\n\treturn [int(v) for v in num_str.split(' ')]\nn = get_num()\nproblems = read_num_list(n)\nproblems = sorted(problems)\ni = 1\nj = 0\nwhile True:\n\tif j >= len(probl...
{"inputs": ["4\n3 1 4 1\n", "3\n1 1 1\n", "5\n1 1 1 2 2\n", "3\n100 100 100\n", "1\n2\n", "2\n2 3\n", "3\n10 10 10\n", "3\n5 6 7\n", "5\n200000 200000 200000 200000 200000\n", "5\n200000 200000 200000 200000 200000\n", "3\n5 6 7\n", "3\n100 100 100\n", "2\n2 3\n", "3\n10 10 10\n", "1\n2\n", "5\n200000 200000 200000 200...
EASY
['data structures', 'greedy', 'sortings']
null
codeforces
['Sorting', 'Data structures', 'Greedy algorithms']
['Sorting', 'Data structures', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1165/B
null
2019-12-31
null
null
null
25,072
0
def get_num(): return int(input()) def print_arr(arr: list): for val in arr: print(val) def read_num_list(k): num_str = input() return [int(v) for v in num_str.split(' ')] n = get_num() problems = read_num_list(n) problems = sorted(problems) i = 1 j = 0 while True: if j >= len(problems): break if i <= probl...
# Question Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$-th day he should solve $k$ problems. Polycarp has a ...
Given a positive integer N and a prime p, the task is to print the largest power of prime p that divides N!. Here N! means the factorial of N = 1 x 2 x 3 . . (N-1) x N. Note that the largest power may be 0 too. Example 1: Input: N = 5 , p = 2 Output: 3 Explanation: 5! = 120. The highest x for which 2^{x} divides 120 ...
[ "class Solution:\n\n\tdef largestPowerOfPrime(self, N, p):\n\t\tsum = 0\n\t\twhile N:\n\t\t\tN //= p\n\t\t\tsum += N\n\t\treturn sum\n", "import math\n\nclass Solution:\n\n\tdef largestPowerOfPrime(self, N, p):\n\t\tsum = 0\n\t\twhile N:\n\t\t\tN /= p\n\t\t\tsum += int(N)\n\t\treturn int(sum)\n", "class Solutio...
#User function Template for python3 class Solution: def largestPowerOfPrime(self, N, p): # code here
{"inputs": ["N = 5 , p = 2", "N = 3 , p = 5"], "outputs": ["3", "0"]}
EASY
['Algorithms', 'Mathematical']
null
geeksforgeeks
['Mathematics']
[]
https://practice.geeksforgeeks.org/problems/largest-power-of-prime4416/1
null
null
0
null
O(log_{p}(N))
25,112
0
class Solution: def largestPowerOfPrime(self, N, p): sum = 0 while N: N //= p sum += N return sum
# Question Given a positive integer N and a prime p, the task is to print the largest power of prime p that divides N!. Here N! means the factorial of N = 1 x 2 x 3 . . (N-1) x N. Note that the largest power may be 0 too. Example 1: Input: N = 5 , p = 2 Output: 3 Explanation: 5! = 120. The highest x for which 2^{x} ...
Note: This kata is inspired by [Convert a Number to a String!](http://www.codewars.com/kata/convert-a-number-to-a-string/). Try that one too. ## Description We need a function that can transform a string into a number. What ways of achieving this do you know? Note: Don't worry, all inputs will be strings, and every ...
[ "def string_to_number(s):\n\treturn int(s)\n", "string_to_number = int\n", "string_to_number = lambda n: int(n)\n", "string_to_number = lambda s: int(s)\n", "def string_to_number(s):\n\ti = int(s)\n\treturn i\n", "def string_to_number(s):\n\tnumber = int(s)\n\treturn number\n", "def string_to_number(s):...
def string_to_number(s):
{"fn_name": "string_to_number", "inputs": [["4"]], "outputs": [[4]]}
EASY
['Strings', 'Fundamentals', 'Parsing']
null
codewars
['String algorithms', 'Fundamentals']
[]
https://www.codewars.com/kata/544675c6f971f7399a000e79
null
null
null
null
null
25,110
0
def string_to_number(s): return int(s)
# Question Note: This kata is inspired by [Convert a Number to a String!](http://www.codewars.com/kata/convert-a-number-to-a-string/). Try that one too. ## Description We need a function that can transform a string into a number. What ways of achieving this do you know? Note: Don't worry, all inputs will be strings...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is experimenting in his kitchen. He has $N$ spices (numbered $0$ through $N-1$) with types $S_{0}, S_{1}, \ldots, S_{N-1}$. You should answer $Q$ queries. Each query is described by two integers $L$ and $R$. I...
[ "def exponent(a, y, m):\n\tif y == 0:\n\t\treturn 1\n\tss = y // 2\n\tan = exponent(a, ss, m)\n\tan = an * an % m\n\tif y % 2 == 0:\n\t\treturn an\n\telse:\n\t\treturn a * an % m\nimport bisect\n(n, q) = map(int, input().split())\nit = list(map(int, input().split()))\na = [1]\nx = 10 ** 9 + 7\nfor i in range(1, n +...
{"inputs": ["5 3\n1 2 3 7 10\n1 1 1 1\n2 1 3 4\n0 0 0 4"], "outputs": ["1\n2\n120"]}
VERY_HARD
['Mathematics', 'Coordinate Compression', 'Algorithms', 'Combinatorics', 'Queries', 'Pre processing', 'Advanced Algorithms', 'Online Queries', 'Square Root Decomposition', 'Permutations & Combinations']
null
codechef
['Square root algorithms', 'Combinatorics', 'Sweep line algorithms', 'Preprocessing', 'Mathematics']
[]
https://www.codechef.com/problems/COOLCHEF
5 seconds
2019-04-29
0
50000 bytes
null
25,117
0
def exponent(a, y, m): if y == 0: return 1 ss = y // 2 an = exponent(a, ss, m) an = an * an % m if y % 2 == 0: return an else: return a * an % m import bisect (n, q) = map(int, input().split()) it = list(map(int, input().split())) a = [1] x = 10 ** 9 + 7 for i in range(1, n + 1): a.append(a[-1] * (i + 1) %...
# Question Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is experimenting in his kitchen. He has $N$ spices (numbered $0$ through $N-1$) with types $S_{0}, S_{1}, \ldots, S_{N-1}$. You should answer $Q$ queries. Each query is described by two integers $L...
problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, and the easternmost post town is post town n. You have decided to depart fro...
[ "(n, m) = map(int, input().split())\naccums = [0]\nfor i in range(n - 1):\n\taccums.append(accums[-1] + int(input()))\nresult = 0\nk = 0\nfor i in range(m):\n\ta = int(input())\n\tresult = (result + abs(accums[k + a] - accums[k])) % 100000\n\tk += a\nprint(result)\n", "(n, m) = map(int, input().split())\nkyori = ...
{"inputs": ["7 5\n2\n1\n2\n3\n2\n1\n2\n-1\n3\n2\n-3", "7 5\n2\n0\n2\n3\n2\n1\n2\n-1\n3\n2\n-3", "7 5\n2\n1\n1\n3\n2\n1\n2\n-1\n1\n2\n-3", "7 5\n2\n1\n1\n0\n2\n1\n2\n-1\n1\n2\n-3", "7 5\n2\n1\n2\n3\n0\n1\n2\n-1\n3\n2\n-1", "7 5\n1\n0\n2\n3\n2\n1\n2\n-1\n3\n1\n-3", "7 5\n2\n0\n1\n0\n2\n1\n2\n-1\n1\n2\n-3", "7 5\n4\n1\n2\...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
8.0 seconds
null
null
134.217728 megabytes
null
25,118
0
(n, m) = map(int, input().split()) accums = [0] for i in range(n - 1): accums.append(accums[-1] + int(input())) result = 0 k = 0 for i in range(m): a = int(input()) result = (result + abs(accums[k + a] - accums[k])) % 100000 k += a print(result)
# Question problem You are a traveler traveling on the JOI Highway. The JOI Highway is a road that extends straight from east to west, and there are n post towns on the JOI Highway. Numbered. The westernmost post town on the JOI highway is post town 1, and the easternmost post town is post town n. You have decided t...
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer n the number that is obtained after successive writing of...
[ "s = input()\n(a, b) = (s.split()[0], s.split()[1])\ndif = len(a) - len(b)\nmask = ''\ntmp = int(a)\ntmp += 1\nt = str(tmp)\nwhile 1:\n\tfor i in t:\n\t\tif i in ['4', '7']:\n\t\t\tmask += i\n\tif mask == b:\n\t\tbreak\n\telse:\n\t\ttmp += 1\n\t\tt = str(tmp)\n\t\tmask = ''\nprint(tmp)\n", "def f(x):\n\ts = '0'\n...
{"inputs": ["39999 4774\n", "40007 74\n", "31975 74\n", "69700 77477\n", "74 77\n", "45679 77777\n", "1 4\n", "40007 74444\n", "740 4\n", "369 47\n", "47 74\n", "4 4\n", "45896 4\n", "76492 447\n", "55557 74\n", "99997 47\n", "77777 77777\n", "474 74\n", "47774 774\n", "1 47774\n", "476 47\n", "47774 47774\n", "44 4\n"...
EASY
['brute force', 'implementation']
null
codeforces
['Implementation', 'Complete search']
['Complete search']
https://codeforces.com/problemset/problem/146/B
2.0 seconds
null
null
256.0 megabytes
null
25,119
0
s = input() (a, b) = (s.split()[0], s.split()[1]) dif = len(a) - len(b) mask = '' tmp = int(a) tmp += 1 t = str(tmp) while 1: for i in t: if i in ['4', '7']: mask += i if mask == b: break else: tmp += 1 t = str(tmp) mask = '' print(tmp)
# Question Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer n the number that is obtained after successiv...
A product-sum number is a natural number N which can be expressed as both the product and the sum of the same set of numbers. N = a1 × a2 × ... × ak = a1 + a2 + ... + ak For example, 6 = 1 × 2 × 3 = 1 + 2 + 3. For a given set of size, k, we shall call the smallest N with this property a minimal product-sum number. T...
[ "def productsum(n):\n\tpass\n\ndef productsum(kmax):\n\n\tdef prodsum2(p, s, c, start):\n\t\tk = p - s + c\n\t\tif k < kmax:\n\t\t\tif p < n[k]:\n\t\t\t\tn[k] = p\n\t\t\tfor i in range(start, kmax // p * 2 + 1):\n\t\t\t\tprodsum2(p * i, s + i, c + 1, i)\n\tkmax += 1\n\tn = [2 * kmax] * kmax\n\tprodsum2(1, 1, 1, 2)\...
def productsum(n):
{"fn_name": "productsum", "inputs": [[3], [6], [12], [2]], "outputs": [[10], [30], [61], [4]]}
MEDIUM_HARD
['Mathematics', 'Algorithms']
null
codewars
['Mathematics']
[]
https://www.codewars.com/kata/5b16bbd2c8c47ec58300016e
null
null
null
null
null
25,123
0
def productsum(n): pass def productsum(kmax): def prodsum2(p, s, c, start): k = p - s + c if k < kmax: if p < n[k]: n[k] = p for i in range(start, kmax // p * 2 + 1): prodsum2(p * i, s + i, c + 1, i) kmax += 1 n = [2 * kmax] * kmax prodsum2(1, 1, 1, 2) return sum(set(n[2:]))
# Question A product-sum number is a natural number N which can be expressed as both the product and the sum of the same set of numbers. N = a1 × a2 × ... × ak = a1 + a2 + ... + ak For example, 6 = 1 × 2 × 3 = 1 + 2 + 3. For a given set of size, k, we shall call the smallest N with this property a minimal product-s...
Given two strings, determine if they share a common substring. A substring may be as small as one character. Example $s1=\text{'and'}$ $s2=\text{'art'}$ These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$. $\textbf{s1}=\textbf{'be'}$ $s2=\text{'cat'}$ These do not share a substr...
[ "a = int(input())\nfor i in range(a):\n\ti = input()\n\tj = input()\n\tsetx = set([a for a in i])\n\tsety = set([y for y in j])\n\tif setx.intersection(sety) == set():\n\t\tprint('NO')\n\telse:\n\t\tprint('YES')\n", "for _ in range(int(input())):\n\ts1 = set(input())\n\ts2 = set(input())\n\tif s1.intersection(s2)...
{"inputs": ["2\nhello\nworld\nhi\nworld\n"], "outputs": ["YES\nNO\n"]}
EASY
['Algorithms - Strings']
null
hackerrank
['String algorithms']
[]
https://www.hackerrank.com/challenges/two-strings/problem
null
null
0
null
null
25,113
0
a = int(input()) for i in range(a): i = input() j = input() setx = set([a for a in i]) sety = set([y for y in j]) if setx.intersection(sety) == set(): print('NO') else: print('YES')
# Question Given two strings, determine if they share a common substring. A substring may be as small as one character. Example $s1=\text{'and'}$ $s2=\text{'art'}$ These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$. $\textbf{s1}=\textbf{'be'}$ $s2=\text{'cat'}$ These do not sh...
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must have z liters of water contained within one or both buckets by the en...
[ "class Solution:\n\n\tdef canMeasureWater(self, x, y, z):\n\t\tif x > y:\n\t\t\t(x, y) = (y, x)\n\t\tif z < 0 or z > x + y:\n\t\t\treturn False\n\t\tif x == 0:\n\t\t\treturn z == y or z == 0\n\t\tif z % x == 0:\n\t\t\treturn True\n\t\tif y % x == 0:\n\t\t\treturn False\n\t\ta = x\n\t\tb = y % x\n\t\twhile a > 1 and...
class Solution: def canMeasureWater(self, x: int, y: int, z: int) -> bool:
{"fn_name": "canMeasureWater", "inputs": [[3, 5, 4]], "outputs": [true]}
MEDIUM_HARD
['Math', 'Breadth-First Search', 'Depth-First Search']
null
leetcode
['Graph traversal', 'Mathematics']
[]
https://leetcode.com/problems/water-and-jug-problem/
null
null
null
null
null
25,127
0
class Solution: def canMeasureWater(self, x, y, z): if x > y: (x, y) = (y, x) if z < 0 or z > x + y: return False if x == 0: return z == y or z == 0 if z % x == 0: return True if y % x == 0: return False a = x b = y % x while a > 1 and b > 1: a = a % b (a, b) = (b, a) if b == 0:...
# Question You are given two jugs with capacities x and y litres. There is an infinite amount of water supply available. You need to determine whether it is possible to measure exactly z litres using these two jugs. If z liters of water is measurable, you must have z liters of water contained within one or both bucke...
# Task You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties: ``` For each i = 1, 2, ... , size of the string: If i-th character is "D", then N can be divided by i If i-th character is "P", then N and i should be rela...
[ "from fractions import gcd\n\ndef DPC_sequence(s):\n\tn = 1\n\tfor (i, c) in enumerate(s, 1):\n\t\tif c == 'D':\n\t\t\tn = n * i // gcd(n, i)\n\t\telif c == 'P':\n\t\t\tif gcd(n, i) != 1:\n\t\t\t\treturn -1\n\t\telif c == 'C':\n\t\t\tif gcd(n, i) in (1, i):\n\t\t\t\treturn -1\n\treturn n\n", "from fractions impor...
def DPC_sequence(s):
{"fn_name": "DPC_sequence", "inputs": [["DDPDD"], ["DDDDPDDCCCDDPDCCPCDCDDPCPCCDDCD"], ["DPCPDPPPDCPDPDPC"], ["DDDDDDCD"], ["CDDDPDDD"], ["DDDDDDPCCDPDPP"]], "outputs": [[20], [15782844], [-1], [-1], [-1], [-1]]}
EASY
['Puzzles']
null
codewars
['Ad-hoc']
[]
https://www.codewars.com/kata/58a3b7185973c23795000049
null
null
null
null
null
25,128
0
from fractions import gcd def DPC_sequence(s): n = 1 for (i, c) in enumerate(s, 1): if c == 'D': n = n * i // gcd(n, i) elif c == 'P': if gcd(n, i) != 1: return -1 elif c == 'C': if gcd(n, i) in (1, i): return -1 return n
# Question # Task You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties: ``` For each i = 1, 2, ... , size of the string: If i-th character is "D", then N can be divided by i If i-th character is "P", then N and i sh...
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$ (both inclusive). He was confused, regarding this problem. So, he...
[ "import math\np = 7 + 10 ** 9\n(n, k) = list(map(int, input().split()))\nc = math.factorial(n + k - 1) // (math.factorial(k) * math.factorial(n - 1))\nprint(c % p)\n", "from math import *\n\ndef printNcR(n, r):\n\tp = 1\n\tk = 1\n\tif n - r < r:\n\t\tr = n - r\n\tif r != 0:\n\t\twhile r:\n\t\t\tp *= n\n\t\t\tk *=...
{"inputs": [["2 5"]], "outputs": [["6"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/PCR12020/problems/BHARAT
null
null
null
null
null
25,139
0
import math p = 7 + 10 ** 9 (n, k) = list(map(int, input().split())) c = math.factorial(n + k - 1) // (math.factorial(k) * math.factorial(n - 1)) print(c % p)
# Question Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$ (both inclusive). He was confused, regarding this pro...
Read problems statements in mandarin chinese, russian and vietnamese as well. Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing against Eibar. These two matches will decide who wins the league title. Real Mad...
[ "T = int(input())\nfor i in range(T):\n\tscores = dict()\n\tfor j in range(4):\n\t\t(team, score) = map(str, input().split(' '))\n\t\tscore = int(score)\n\t\tscores[team] = score\n\tif scores['RealMadrid'] < scores['Malaga'] and scores['Barcelona'] > scores['Eibar']:\n\t\tprint('Barcelona')\n\telse:\n\t\tprint('Rea...
{"inputs": ["2\nBarcelona 2\nMalaga 1\nRealMadrid 1\nEibar 0\nMalaga 3\nRealMadrid 2\nBarcelona 8\nEibar 6"], "outputs": ["RealMadrid\nBarcelona"]}
EASY
['deadwing97', 'cakewalk', 'cook82']
null
codechef
[]
[]
https://www.codechef.com/problems/COOK82A
1 seconds
2017-05-20
0
50000 bytes
null
25,108
0
T = int(input()) for i in range(T): scores = dict() for j in range(4): (team, score) = map(str, input().split(' ')) score = int(score) scores[team] = score if scores['RealMadrid'] < scores['Malaga'] and scores['Barcelona'] > scores['Eibar']: print('Barcelona') else: print('RealMadrid')
# Question Read problems statements in mandarin chinese, russian and vietnamese as well. Today is the final round of La Liga, the most popular professional football league in the world. Real Madrid is playing against Malaga and Barcelona is playing against Eibar. These two matches will decide who wins the league tit...
Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given that he can move to any point on this 2D grid, i.e., the points having positiv...
[ "t = int(input())\n\ndef gcd(a, b):\n\tif b == 0:\n\t\treturn a\n\treturn gcd(b, a % b)\nfor i in range(t):\n\t(a, b, x, y) = map(int, input().split())\n\tif gcd(a, b) == gcd(x, y):\n\t\tprint('YES')\n\telse:\n\t\tprint('NO')\n", "def gcd(a, b):\n\tif a < b:\n\t\t(a, b) = (b, a)\n\twhile b > 0:\n\t\t(a, b) = (b, ...
{"inputs": ["3\n1 1 2 3\n2 1 2 3\n3 3 1 1\n"], "outputs": ["YES\nYES\nNO\n"]}
EASY
['Mathematics - Fundamentals']
null
hackerrank
['Mathematics']
[]
https://www.hackerrank.com/challenges/possible-path/problem
null
null
0
null
null
25,114
0
t = int(input()) def gcd(a, b): if b == 0: return a return gcd(b, a % b) for i in range(t): (a, b, x, y) = map(int, input().split()) if gcd(a, b) == gcd(x, y): print('YES') else: print('NO')
# Question Adam is standing at point $(a,b)$ in an infinite 2D grid. He wants to know if he can reach point $(x,y)$ or not. The only operation he can do is to move to point $(a+b,b),(a,a+b),(a-b,b),\text{or}(a,b-a)$ from some point $(a,b)$. It is given that he can move to any point on this 2D grid, i.e., the points ha...
In the gym, Chef prefers to lift at least $W$ grams during a bench press and if that's impossible, Chef considers his workout to be incomplete and feels bad. The rod weighs $W_{r}$ grams and there are $N$ other weights lying on the floor that weigh $w_{1}, w_{2}, ..., w_{N}$ grams. To maintain balance and to ensure th...
[ "from collections import Counter\ntc = int(input())\nfor _ in range(tc):\n\t(n, w, wr) = map(int, input().split())\n\ta = Counter(list(map(int, input().split())))\n\tif wr >= w:\n\t\tprint('YES')\n\telse:\n\t\td = 0\n\t\tfor i in a:\n\t\t\td += a[i] // 2 * i * 2\n\t\t\tif wr + d >= w:\n\t\t\t\tprint('YES')\n\t\t\t\...
{"inputs": ["3\n2 5 10 \n2 2\n7 100 50\n100 10 10 10 10 10 90 \n6 100 40 \n10 10 10 10 10 10"], "outputs": ["YES\nNO\nYES"]}
MEDIUM_HARD
['Algorithms', 'Greedy', 'Implementation', 'Data Structures', 'Arrays', 'Frequency Arrays']
null
codechef
['Data structures', 'Implementation', 'Greedy algorithms']
['Data structures', 'Greedy algorithms']
https://www.codechef.com/problems/BENCHP
1 seconds
2021-04-02
0
50000 bytes
null
25,125
0
from collections import Counter tc = int(input()) for _ in range(tc): (n, w, wr) = map(int, input().split()) a = Counter(list(map(int, input().split()))) if wr >= w: print('YES') else: d = 0 for i in a: d += a[i] // 2 * i * 2 if wr + d >= w: print('YES') break else: print('NO')
# Question In the gym, Chef prefers to lift at least $W$ grams during a bench press and if that's impossible, Chef considers his workout to be incomplete and feels bad. The rod weighs $W_{r}$ grams and there are $N$ other weights lying on the floor that weigh $w_{1}, w_{2}, ..., w_{N}$ grams. To maintain balance and ...
Kilani is playing a game with his friends. This game can be represented as a grid of size $n \times m$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell). The game is played in rounds. In each round players expand turn by turn: fir...
[ "import sys\nfrom collections import deque as dq\n(h, w, P) = [int(x) for x in input().split()]\nS = [int(x) for x in input().split()]\nboard = []\nfor b in sys.stdin.read():\n\tfor c in b:\n\t\tif c == '.':\n\t\t\tboard.append(-1)\n\t\telif 0 <= ord(c) - 49 <= 9:\n\t\t\tboard.append(ord(c) - 49)\n\t\telif c == '#'...
{"inputs": ["3 3 2\n1 1\n1..\n...\n..2\n", "3 4 4\n1 1 1 1\n....\n#...\n1234\n", "3 4 2\n1 1\n....\n1..2\n....\n", "3 4 2\n2 1\n....\n1..2\n....\n", "4 4 2\n1 1000000000\n....\n....\n..2.\n...1\n", "4 4 2\n1 1000000000\n....\n....\n..1.\n...2\n", "1 1 1\n1\n1\n", "5 5 1\n1\n.....\n.....\n..1..\n.....\n.....\n", "4 7 2\...
HARD
['shortest paths', 'dfs and similar', 'graphs', 'implementation']
null
codeforces
['Graph algorithms', 'Graph traversal', 'Implementation', 'Shortest paths']
[]
https://codeforces.com/problemset/problem/1105/D
null
2019-12-31
null
null
null
25,129
0
import sys from collections import deque as dq (h, w, P) = [int(x) for x in input().split()] S = [int(x) for x in input().split()] board = [] for b in sys.stdin.read(): for c in b: if c == '.': board.append(-1) elif 0 <= ord(c) - 49 <= 9: board.append(ord(c) - 49) elif c == '#': board.append(-2) new_cas...
# Question Kilani is playing a game with his friends. This game can be represented as a grid of size $n \times m$, where each cell is either empty or blocked, and every player has one or more castles in some cells (there are no two castles in one cell). The game is played in rounds. In each round players expand turn ...
Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. The rating for Alice's challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob's challenge is the tri...
[ "import sys\n(a0, a1, a2) = input().strip().split(' ')\n(a0, a1, a2) = [int(a0), int(a1), int(a2)]\n(b0, b1, b2) = input().strip().split(' ')\n(b0, b1, b2) = [int(b0), int(b1), int(b2)]\nA = (a0 > b0) + (a1 > b1) + (a2 > b2)\nB = (a0 < b0) + (a1 < b1) + (a2 < b2)\nprint(A, B)\n", "import sys\n(a0, a1, a2) = input...
{"inputs": ["5 6 7\n3 6 10\n", "17 28 30\n99 16 8\n"], "outputs": ["1 1\n", "2 1\n"]}
EASY
['Algorithms - Warmup']
null
hackerrank
[]
[]
https://www.hackerrank.com/challenges/compare-the-triplets/problem
null
null
0
null
null
25,124
0
import sys (a0, a1, a2) = input().strip().split(' ') (a0, a1, a2) = [int(a0), int(a1), int(a2)] (b0, b1, b2) = input().strip().split(' ') (b0, b1, b2) = [int(b0), int(b1), int(b2)] A = (a0 > b0) + (a1 > b1) + (a2 > b2) B = (a0 < b0) + (a1 < b1) + (a2 < b2) print(A, B)
# Question Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty. The rating for Alice's challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob's challeng...
While performing complex market analysis William encountered the following problem: For a given array $a$ of size $n$ and a natural number $e$, calculate the number of pairs of natural numbers $(i, k)$ which satisfy the following conditions: $1 \le i, k$ $i + e \cdot k \le n$. Product $a_i \cdot a_{i + e} \cdot a_{...
[ "import sys\nisPrime = [True] * int(1000000.0 + 2)\n\ndef solve():\n\tinp = sys.stdin.readline\n\t(n, e) = map(int, inp().split())\n\ta = list(map(int, inp().split()))\n\tw = [True] * n\n\tr = 0\n\tfor i in range(n):\n\t\tif w[i]:\n\t\t\tj = 0\n\t\t\tz = i\n\t\t\tlast = -1\n\t\t\tlast1 = -1\n\t\t\tp = False\n\t\t\t...
{"inputs": ["6\n7 3\n10 2 1 3 1 19 3\n3 2\n1 13 1\n9 3\n2 4 2 1 1 1 1 4 2\n3 1\n1 1 1\n4 1\n1 2 1 1\n2 2\n1 2\n", "10\n10 3\n1 1 921703 876665 1 1 1 1 914189 1\n10 2\n1 1 1 422549 1 1 880667 81267 1 1\n10 2\n1 717091 1 1 1 1 22573 1 4694 1\n10 9\n593041 1 1 1 1 1 954668 1 699271 1\n10 8\n744738 388231 1 436531 1 1 1 1 ...
MEDIUM
['implementation', 'binary search', 'dp', 'schedules', 'two pointers', 'number theory']
null
codeforces
['Sorting', 'Amortized analysis', 'Implementation', 'Number theory', 'Dynamic programming']
['Dynamic programming', 'Sorting', 'Amortized analysis']
https://codeforces.com/problemset/problem/1609/C
2 seconds
2021-11-28
1
256 megabytes
null
25,130
0
import sys isPrime = [True] * int(1000000.0 + 2) def solve(): inp = sys.stdin.readline (n, e) = map(int, inp().split()) a = list(map(int, inp().split())) w = [True] * n r = 0 for i in range(n): if w[i]: j = 0 z = i last = -1 last1 = -1 p = False while z < n: w[z] = False v = a[z] ...
# Question While performing complex market analysis William encountered the following problem: For a given array $a$ of size $n$ and a natural number $e$, calculate the number of pairs of natural numbers $(i, k)$ which satisfy the following conditions: $1 \le i, k$ $i + e \cdot k \le n$. Product $a_i \cdot a_{i + ...
Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the predetermined height of the condominium. The height of each floor ca...
[ "(H, A, B) = map(int, input().split())\nans = 0\nfor k in range(A, B + 1):\n\tif H % k == 0:\n\t\tans += 1\nprint(ans)\n", "(H, A, B) = map(int, input().split())\nc = 0\nfor i in range(A, B + 1):\n\tif H % i == 0:\n\t\tc += 1\nprint(c)\n", "(h, a, b) = map(int, input().split())\nnum = 0\nfor i in range(a, b + 1...
{"inputs": ["101 2 5", "100 2 5", "111 2 5", "000 2 5", "000 2 10", "000 2 12", "000 2 18", "000 2 30", "000 2 51", "000 2 50", "010 2 8", "000 2 8", "100 2 21", "000 2 14", "000 2 16", "000 3 10", "000 3 95", "110 2 81", "000 9 106", "000 9 44", "000 8 17", "000 2 17", "000 2 31", "000 2 23", "000 2 41", "000 2 20", "...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
1.0 seconds
null
null
268.435456 megabytes
null
25,131
0
(H, A, B) = map(int, input().split()) ans = 0 for k in range(A, B + 1): if H % k == 0: ans += 1 print(ans)
# Question Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the predetermined height of the condominium. The height of e...
Your friend gave you a dequeue D as a birthday present. D is a horizontal cylinder that contains a row of N jewels. The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values. In the beginning, you have no jewel in your hands. You can perform at most K operations on D, ...
[ "(n, k) = map(int, input().split())\nv = [int(i) for i in input().split()]\nr = min(n, k)\nans = 0\nfor a in range(r + 1):\n\tfor b in range(r - a + 1):\n\t\tif b >= 1:\n\t\t\tq = v[:a] + v[-b:]\n\t\telse:\n\t\t\tq = v[:a]\n\t\tt = k - a - b\n\t\tm = 0\n\t\tfor i in sorted(q):\n\t\t\tif i < 0 and t > 0:\n\t\t\t\tm ...
{"inputs": ["6 4\n-10 8 2 1 2 6\n", "6 4\n-6 -100 50 -2 -5 -3\n", "6 3\n-6 -100 50 -2 -5 -3\n", "25 22\n-4914956 3823889 1216217 -9302864 -1501144 -9443294 434483 -5719996 -687667 -3548437 5740256 3851980 -4631603 942858 4533097 1140983 -2849317 -6558335 -9825551 -6894413 -8391876 -4121113 828750 2790670 -6249249\n", "...
MEDIUM
[]
AtCoder Beginner Contest 128 - equeue
atcoder
[]
[]
https://atcoder.jp/contests/abc128/tasks/abc128_d
2.0 seconds
null
null
1024.0 megabytes
null
25,111
0
(n, k) = map(int, input().split()) v = [int(i) for i in input().split()] r = min(n, k) ans = 0 for a in range(r + 1): for b in range(r - a + 1): if b >= 1: q = v[:a] + v[-b:] else: q = v[:a] t = k - a - b m = 0 for i in sorted(q): if i < 0 and t > 0: m += abs(i) t -= 1 ans = max(ans, m + s...
# Question Your friend gave you a dequeue D as a birthday present. D is a horizontal cylinder that contains a row of N jewels. The values of the jewels are V_1, V_2, ..., V_N from left to right. There may be jewels with negative values. In the beginning, you have no jewel in your hands. You can perform at most K opera...
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in the country and Manish wants to rob all the banks with minimum am...
[ "for t in range(int(input())):\n\tn = int(input())\n\tl = []\n\tm = []\n\tx = list(map(int, input().split()))\n\tl.append(x)\n\tm.append(list(x))\n\tfor i in range(1, n):\n\t\tx = list(map(int, input().split()))\n\t\tl.append(x)\n\t\ttemp = []\n\t\tfor i in range(4):\n\t\t\ttemp.append(x[i] + min(m[-1][:i] + m[-1][...
{"inputs": [["1", "3", "4 7 2 9", "5 6 4 7", "2 6 4 3"]], "outputs": [["10"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/ICOD2016/problems/ICODE16D
null
null
null
null
null
25,133
0
for t in range(int(input())): n = int(input()) l = [] m = [] x = list(map(int, input().split())) l.append(x) m.append(list(x)) for i in range(1, n): x = list(map(int, input().split())) l.append(x) temp = [] for i in range(4): temp.append(x[i] + min(m[-1][:i] + m[-1][i + 1:])) m.append(temp) print(m...
# Question Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in the country and Manish wants to rob all the banks with...
You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th, (2 \times \...
[ "gcd = lambda a, b: a if b == 0 else gcd(b, a % b)\n(n, m) = map(int, input().split())\ns = input()\nt = input()\nd = gcd(n, m)\nif s[::n // d] == t[::m // d]:\n\tprint(n * m // d)\nelse:\n\tprint(-1)\n", "from fractions import gcd\n(n, m) = map(int, input().split())\ns = input()\nt = input()\ng = gcd(n, m)\nfor ...
{"inputs": ["3 2\nacq\nae", "3 3\nabcdef\nabc", "15 9\ndnsusrayukuaiia\nrujdunuma", "3 4\nasiaukvyartuind\naumnudjus", "15 9\ndnausrayukusiia\ndujrunuma", "1 2\nacq\nae", "4 1\nabq\nae", "15 16\ndnausrayukusiia\ndujrunuma", "1 1\n`br\n`e", "5 4\naiiaukuyarsusod\namtntdjur", "7 3\nabcdef\nabc", "16 9\ndnsusrayukuaiia\nd...
UNKNOWN_DIFFICULTY
[]
AtCoder Grand Contest 028 - Two Abbreviations
atcoder
[]
[]
null
2.0 seconds
null
null
1024.0 megabytes
null
25,126
0
gcd = lambda a, b: a if b == 0 else gcd(b, a % b) (n, m) = map(int, input().split()) s = input() t = input() d = gcd(n, m) if s[::n // d] == t[::m // d]: print(n * m // d) else: print(-1)
# Question You are given a string S of length N and another string T of length M. These strings consist of lowercase English letters. A string X is called a good string when the following conditions are all met: * Let L be the length of X. L is divisible by both N and M. * Concatenating the 1-st, (\frac{L}{N}+1)-th,...
Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note: -100.0 < x < 100.0 n is a 32-bit signed ...
[ "class Solution:\n\n\tdef myPow(self, x, n):\n\t\tif n == 0:\n\t\t\treturn 1\n\t\tif abs(n) == 1:\n\t\t\tif n == 1:\n\t\t\t\treturn x\n\t\t\telse:\n\t\t\t\treturn 1 / x\n\t\tif n > 0:\n\t\t\t(a, b) = (int(n // 2), n % 2)\n\t\telse:\n\t\t\t(a, b) = (-int(-n // 2), -(n % 2))\n\t\ty = self.myPow(x, a)\n\t\tz = self.my...
class Solution: def myPow(self, x: float, n: int) -> float:
{"fn_name": "myPow", "inputs": [[2.0, 10]], "outputs": [1024.0]}
MEDIUM_HARD
['Recursion', 'Math']
null
leetcode
['Mathematics', 'Complete search']
['Complete search']
https://leetcode.com/problems/powx-n/
null
null
null
null
null
25,132
0
class Solution: def myPow(self, x, n): if n == 0: return 1 if abs(n) == 1: if n == 1: return x else: return 1 / x if n > 0: (a, b) = (int(n // 2), n % 2) else: (a, b) = (-int(-n // 2), -(n % 2)) y = self.myPow(x, a) z = self.myPow(x, b) return y * y * z
# Question Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 Output: 9.26100 Example 3: Input: 2.00000, -2 Output: 0.25000 Explanation: 2-2 = 1/22 = 1/4 = 0.25 Note: -100.0 < x < 100.0 n is a 32...
Given an array nums of n elements and q queries . Each query consists of two integers l and r . You task is to find the number of elements of nums[] in range [l,r] which occur atleast k times. Example 1: Input: nums = {1,1,2,1,3}, Queries = {{1,5}, {2,4}}, k = 1 Output: {3,2} Explanation: For the 1st query, from l=1 ...
[ "import math\n\nclass Solution:\n\n\tdef solveQueries(self, nums, Queries, k):\n\t\tanswers = [0] * len(Queries)\n\t\tcount = {}\n\t\tn = int(math.sqrt(len(nums))) + 1\n\t\tq = list(enumerate(Queries))\n\t\tq.sort(key=lambda a: [int(a[1][0] / n), -a[1][1]])\n\t\tcurrentL = 0\n\t\tcurrentR = -1\n\t\tans = 0\n\t\tfor...
#User function Template for python3 class Solution: def solveQueries(self, nums, Queries, k): #Code here
{"inputs": ["nums = {1,1,2,1,3}, Queries = {{1,5},\r\n{2,4}}, k = 1", "nums = {1,2,3,1}, Queries = {{1,4},\r\n{2,4},{4,4}, k = 2"], "outputs": ["{3,2}", "{1,0,0}"]}
MEDIUM_HARD
['Map', 'Sqrt Decomposition', 'Data Structures']
null
geeksforgeeks
['Square root algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/interesting-queries4742/1
null
null
0
null
O(n*sqrt(n)*log(n))
25,135
0
import math class Solution: def solveQueries(self, nums, Queries, k): answers = [0] * len(Queries) count = {} n = int(math.sqrt(len(nums))) + 1 q = list(enumerate(Queries)) q.sort(key=lambda a: [int(a[1][0] / n), -a[1][1]]) currentL = 0 currentR = -1 ans = 0 for i in q: left = i[1][0] - 1 rig...
# Question Given an array nums of n elements and q queries . Each query consists of two integers l and r . You task is to find the number of elements of nums[] in range [l,r] which occur atleast k times. Example 1: Input: nums = {1,1,2,1,3}, Queries = {{1,5}, {2,4}}, k = 1 Output: {3,2} Explanation: For the 1st quer...
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city code a_{i} is k...
[ "import sys\ninf = 1 << 30\n\ndef solve():\n\tn = int(input())\n\ta = [0] + [int(i) for i in input().split()]\n\tmaxi = max(a)\n\tf = [-1] * (maxi + 1)\n\tfor i in range(1, n + 1):\n\t\tif f[a[i]] == -1:\n\t\t\tf[a[i]] = i\n\tl = [-1] * (maxi + 1)\n\tfor i in range(n, 0, -1):\n\t\tif l[a[i]] == -1:\n\t\t\tl[a[i]] =...
{"inputs": ["6\n4 4 2 5 2 3\n", "9\n5 1 3 1 5 2 4 2 5\n", "5\n1558 4081 3591 1700 3232\n", "10\n3838 1368 4825 2068 4755 2048 1342 4909 2837 4854\n", "10\n4764 4867 2346 1449 1063 2002 2577 2089 1566 614\n", "10\n689 3996 3974 4778 1740 3481 2916 2744 294 1376\n", "100\n1628 4511 4814 3756 4625 1254 906 1033 2420 2622 ...
HARD
['implementation', 'dp']
null
codeforces
['Dynamic programming', 'Implementation']
['Dynamic programming']
https://codeforces.com/problemset/problem/811/C
null
2019-12-31
null
null
null
25,136
0
import sys inf = 1 << 30 def solve(): n = int(input()) a = [0] + [int(i) for i in input().split()] maxi = max(a) f = [-1] * (maxi + 1) for i in range(1, n + 1): if f[a[i]] == -1: f[a[i]] = i l = [-1] * (maxi + 1) for i in range(n, 0, -1): if l[a[i]] == -1: l[a[i]] = i dp = [0] * (n + 1) for i in ran...
# Question Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips: Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are already lined up in some order, and for each of them the city cod...
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i. Your task is to count the number of almost identity permutations for given numb...
[ "import math\n\ndef calculate_derangement(fac, n):\n\tans = fac[n]\n\tfor i in range(1, n + 1):\n\t\tif i % 2 == 1:\n\t\t\tans -= fac[n] // fac[i]\n\t\telse:\n\t\t\tans += fac[n] // fac[i]\n\treturn ans\n(n, k) = map(int, input().split())\nfac = [1]\nfor i in range(1, n + 1):\n\tfac.append(fac[i - 1] * i)\nans = 0\...
{"inputs": ["4 1\n", "4 2\n", "5 3\n", "5 4\n", "200 1\n", "200 2\n", "200 3\n", "200 4\n", "400 1\n", "400 2\n", "400 3\n", "400 4\n", "600 1\n", "600 2\n", "600 3\n", "600 4\n", "800 1\n", "800 2\n", "800 3\n", "800 4\n", "1000 1\n", "1000 2\n", "1000 3\n", "1000 4\n", "4 4\n", "1000 2\n", "400 4\n", "200 3\n", "400 ...
MEDIUM_HARD
['combinatorics', 'math', 'dp']
null
codeforces
['Dynamic programming', 'Combinatorics', 'Mathematics']
['Dynamic programming']
https://codeforces.com/problemset/problem/888/D
null
2019-12-31
null
null
null
25,115
0
import math def calculate_derangement(fac, n): ans = fac[n] for i in range(1, n + 1): if i % 2 == 1: ans -= fac[n] // fac[i] else: ans += fac[n] // fac[i] return ans (n, k) = map(int, input().split()) fac = [1] for i in range(1, n + 1): fac.append(fac[i - 1] * i) ans = 0 for i in range(0, k + 1): choose...
# Question A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i. Your task is to count the number of almost identity permutations fo...
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There is a chessboard with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). $M$ squares on this chessboard (numbered $1$ through $M$) are marked. For each valid $i$, the $i$-th of the ...
[ "import sys\nfrom collections import deque\n\ndef eulerian_path(root, adj):\n\tpath = []\n\tstack = [root]\n\twhile stack:\n\t\tu = stack[-1]\n\t\tif len(adj[u]) == 0:\n\t\t\tpath.append(u)\n\t\t\tstack.pop()\n\t\telse:\n\t\t\tv = adj[u][-1]\n\t\t\tadj[u].pop()\n\t\t\tadj[v] = [w for w in adj[v] if w != u]\n\t\t\ts...
{"inputs": ["2\n2 4\n1 1\n1 2\n2 1\n2 2\n1 1\n1 1\n"], "outputs": ["1 3 4 2\n1\n"]}
VERY_HARD
['Data Structures', 'Graphs', 'Bipartite Graphs']
null
codechef
['Graph algorithms', 'Data structures']
['Data structures']
https://www.codechef.com/problems/ROOKPATH
1 seconds
2020-11-27
0
50000 bytes
null
25,143
0
import sys from collections import deque def eulerian_path(root, adj): path = [] stack = [root] while stack: u = stack[-1] if len(adj[u]) == 0: path.append(u) stack.pop() else: v = adj[u][-1] adj[u].pop() adj[v] = [w for w in adj[v] if w != u] stack.append(v) return path def main(): test_...
# Question Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There is a chessboard with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). $M$ squares on this chessboard (numbered $1$ through $M$) are marked. For each valid $i$, the $i...
Implement pow(x, n) % M. In other words, given x, n and M, find (x^{n}) % M. Example 1: Input: x = 3, n = 2, m = 4 Output: 1 Explanation: 3^{2} = 9. 9 % 4 = 1. Example 2: Input: x = 2, n = 6, m = 10 Output: 4 Explanation: 2^{6} = 64. 64 % 10 = 4. Your Task: You don't need to read or print anything. Your task is to co...
[ "class Solution:\n\n\tdef PowMod(self, x, n, m):\n\t\tres = 1\n\t\twhile n > 0:\n\t\t\tif n & 1 != 0:\n\t\t\t\tres = res * x % m % m\n\t\t\tx = x % m * x % m % m\n\t\t\tn = n >> 1\n\t\treturn res\n", "class Solution:\n\n\tdef PowMod(self, x, n, m):\n\t\tresult = 1\n\t\twhile n > 0:\n\t\t\tif n % 2 == 1:\n\t\t\t\t...
#User function Template for python3 class Solution: def PowMod(self, x, n, m): # Code here
{"inputs": ["x = 3, n = 2, m = 4", "x = 2, n = 6, m = 10"], "outputs": ["1", "4"]}
MEDIUM
['Algorithms', 'Binary Search', 'Divide and Conquer']
null
geeksforgeeks
['Sorting', 'Divide and conquer']
['Sorting']
https://practice.geeksforgeeks.org/problems/modular-exponentiation-for-large-numbers5537/1
null
null
0
null
O(log(n))
25,141
0
class Solution: def PowMod(self, x, n, m): res = 1 while n > 0: if n & 1 != 0: res = res * x % m % m x = x % m * x % m % m n = n >> 1 return res
# Question Implement pow(x, n) % M. In other words, given x, n and M, find (x^{n}) % M. Example 1: Input: x = 3, n = 2, m = 4 Output: 1 Explanation: 3^{2} = 9. 9 % 4 = 1. Example 2: Input: x = 2, n = 6, m = 10 Output: 4 Explanation: 2^{6} = 64. 64 % 10 = 4. Your Task: You don't need to read or print anything. Your t...
Given a list A having N positive elements. The task to create another list such as i^{th} element is XOR of all elements of A except A[i]. Example 1: Input: A = [2, 1, 5, 9] Output: 13 14 10 6 Explanation: At first position 1^5^9 = 13 At second position 2^5^9 = 14 At third position 2^1^9 = 10 At last position 2^1^5 = ...
[ "class Solution:\n\n\tdef getXor(self, A, N):\n\t\txor = 0\n\t\tfor i in A:\n\t\t\txor ^= i\n\t\tfor i in range(N):\n\t\t\tA[i] ^= xor\n\t\treturn A\n", "class Solution:\n\n\tdef getXor(self, A, N):\n\t\tans = 0\n\t\tfor i in A:\n\t\t\tans ^= i\n\t\ta = [0] * N\n\t\tfor i in range(N):\n\t\t\ta[i] = ans ^ A[i]\n\t...
#User function Template for python3 class Solution: def getXor(self, A, N): # code here
{"inputs": ["A = [2, 1, 5, 9]", "A = [2, 1]"], "outputs": ["13 14 10 6", "1 2"]}
EASY
['Data Structures', 'Bit Magic']
null
geeksforgeeks
['Bit manipulation', 'Data structures']
['Bit manipulation', 'Data structures']
https://practice.geeksforgeeks.org/problems/xor-of-all-elements0736/1
null
null
0
null
O(N)
25,140
0
class Solution: def getXor(self, A, N): xor = 0 for i in A: xor ^= i for i in range(N): A[i] ^= xor return A
# Question Given a list A having N positive elements. The task to create another list such as i^{th} element is XOR of all elements of A except A[i]. Example 1: Input: A = [2, 1, 5, 9] Output: 13 14 10 6 Explanation: At first position 1^5^9 = 13 At second position 2^5^9 = 14 At third position 2^1^9 = 10 At last posit...
A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code of the $i$-th card is $p_i$. Polycarp has recently read a recommendation th...
[ "try:\n\tn = int(input())\n\tfor i in range(n):\n\t\tcount = 0\n\t\tsub = 0\n\t\tu = int(input())\n\t\tb = []\n\t\tfor j in range(u):\n\t\t\to = str(input())\n\t\t\tb.append(o)\n\t\td = set(b)\n\t\tfor r in d:\n\t\t\tsub = sub + (b.count(r) - 1)\n\t\tcount = count + sub\n\t\tprint(count)\n\t\tfor (er, gh) in enumer...
{"inputs": ["3\n2\n1234\n0600\n2\n1337\n1337\n4\n3139\n3139\n3139\n3139\n", "3\n10\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n0000\n1\n1234\n7\n1234\n4567\n8901\n2345\n6789\n0123\n4567\n", "4\n4\n3139\n3138\n3138\n3137\n4\n3138\n3148\n3148\n3158\n4\n3138\n3238\n3238\n3338\n4\n3138\n4138\n4138\n5138\n", "1\n...
MEDIUM
['greedy', 'implementation']
null
codeforces
['Implementation', 'Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/1263/B
null
2019-12-31
null
null
null
25,121
0
try: n = int(input()) for i in range(n): count = 0 sub = 0 u = int(input()) b = [] for j in range(u): o = str(input()) b.append(o) d = set(b) for r in d: sub = sub + (b.count(r) - 1) count = count + sub print(count) for (er, gh) in enumerate(b): if b.count(gh) == 1: continue els...
# Question A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code of the $i$-th card is $p_i$. Polycarp has recently read a recom...
Consider placing N flags on a line. Flags are numbered through 1 to N. Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D. Decide whether it is possible to place all N flags. If it is possible, print such a configulation. Constraints * 1 \l...
[ "class Two_SAT:\n\n\tdef __init__(self, variable=[]):\n\t\tself.variable = set(variable)\n\t\tself.clause_number = 0\n\t\tself.variable_number = len(variable)\n\t\tself.adjacent_out = {(v, b): set() for v in variable for b in [True, False]}\n\t\tself.adjacent_in = {(v, b): set() for v in variable for b in [True, Fa...
{"inputs": ["3 3\n1 4\n2 5\n0 10", "3 2\n1 5\n2 5\n0 6", "3 3\n1 4\n2 2\n0 10", "3 2\n1 5\n4 5\n0 6", "3 3\n1 4\n2 4\n0 10", "3 3\n1 4\n2 5\n0 16", "3 3\n1 2\n2 4\n-1 9", "3 3\n2 4\n2 1\n0 10", "3 3\n0 4\n2 1\n-1 13", "3 3\n-1 4\n2 1\n-1 5", "0 3\n1 4\n2 5\n0 16", "3 3\n0 4\n3 3\n0 10", "3 3\n0 4\n1 8\n0 6", "3 3\n2 4\...
UNKNOWN_DIFFICULTY
[]
AtCoder Library Practice Contest - Two SAT
atcoder
[]
[]
null
5.0 seconds
null
null
1024.0 megabytes
null
25,150
0
class Two_SAT: def __init__(self, variable=[]): self.variable = set(variable) self.clause_number = 0 self.variable_number = len(variable) self.adjacent_out = {(v, b): set() for v in variable for b in [True, False]} self.adjacent_in = {(v, b): set() for v in variable for b in [True, False]} def add_variabl...
# Question Consider placing N flags on a line. Flags are numbered through 1 to N. Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D. Decide whether it is possible to place all N flags. If it is possible, print such a configulation. Constra...
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes incline...
[ "(n, m, x, y) = map(int, input().split())\nxm = list(map(int, input().split()))\nym = list(map(int, input().split()))\nprint('No War' if max([x] + xm) < min([y] + ym) else 'War')\n", "(n, m, x, y) = map(int, input().split())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nprint('No War'...
{"inputs": ["3 2 10 20\n8 15 13\n16 22\n", "4 2 -48 -1\n-20 -35 -91 -23\n-22 66\n", "5 3 6 8\n-10 3 1 5 -100\n100 6 14\n", "1 1 -100 100\n-99\n99\n", "1 1 -100 100\n99\n-99\n", "99 99 -20 74\n-51 -77 -13 -11 -45 47 -33 13 17 -58 -93 -72 -76 -22 -53 59 -97 53 -47 -64 0 45 -90 36 -25 -91 14 -80 82 -78 -7 24 -54 -87 32 -2...
EASY
[]
AtCoder Beginner Contest 110 - 1 Dimensional World's Tale
atcoder
[]
[]
https://atcoder.jp/contests/abc110/tasks/abc110_b
2.0 seconds
null
null
1024.0 megabytes
null
25,144
0
(n, m, x, y) = map(int, input().split()) xm = list(map(int, input().split())) ym = list(map(int, input().split())) print('No War' if max([x] + xm) < min([y] + ym) else 'War')
# Question Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B bec...
Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of se...
[ "def solve(k, a):\n\tw = sum(a)\n\tans = float('inf')\n\tif k <= w:\n\t\tfor start in range(7):\n\t\t\tfor end in range(start, 8):\n\t\t\t\tif sum(a[start:end]) >= k:\n\t\t\t\t\tans = min(ans, end - start)\n\tfor start in range(7):\n\t\tfor end in range(7):\n\t\t\tx = sum(a[start:])\n\t\t\ty = sum(a[:end + 1])\n\t\...
{"inputs": ["3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n13131313\n1 0 1 0 1 1 1\n", "1\n13131313\n1 0 1 0 1 1 1\n", "3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 1 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n13131313\n1 0 1 0 0 1 1\n", "3\n4\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n1...
MEDIUM
['math']
null
codeforces
['Mathematics']
[]
https://codeforces.com/problemset/problem/1089/G
null
2019-12-31
null
null
null
25,151
0
def solve(k, a): w = sum(a) ans = float('inf') if k <= w: for start in range(7): for end in range(start, 8): if sum(a[start:end]) >= k: ans = min(ans, end - start) for start in range(7): for end in range(7): x = sum(a[start:]) y = sum(a[:end + 1]) z = k - x - y if z >= 0 and z % w == 0: ...
# Question Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the se...
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him. You are given a tree with $N$ vertices numbered $1$ through $N$. Let's denote an edge between vertices $u$ ...
[ "def dfs(u, p):\n\tl = [u]\n\tfor v in g[u]:\n\t\tif v != p:\n\t\t\tr = dfs(v, u)\n\t\t\tif r == 2:\n\t\t\t\treturn 2\n\t\t\tif r == 1:\n\t\t\t\tl.append(v)\n\t\t\t\tif len(l) == 4:\n\t\t\t\t\tout.append(l)\n\t\t\t\t\tl = [u]\n\tif len(l) == 3:\n\t\tout.append(l + [p])\n\treturn len(l)\nt = int(input())\nfor _ in r...
{"inputs": [["2", "4", "1 2", "1 3", "1 4", "7", "1 2", "2 3", "1 4", "4 5", "1 6", "6 7"]], "outputs": [["YES", "1 2 3 4", "NO"]]}
VERY_HARD
['Algorithms', 'BFS', 'Traversals', 'DFS', 'Graph Algos']
null
codechef
['Graph algorithms', 'Graph traversal']
[]
https://www.codechef.com/problems/TREE3
1 seconds
2018-04-20
0
50000 bytes
null
25,170
0
def dfs(u, p): l = [u] for v in g[u]: if v != p: r = dfs(v, u) if r == 2: return 2 if r == 1: l.append(v) if len(l) == 4: out.append(l) l = [u] if len(l) == 3: out.append(l + [p]) return len(l) t = int(input()) for _ in range(t): n = int(input()) g = [[] for _ in range(n + 1)] ...
# Question Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him. You are given a tree with $N$ vertices numbered $1$ through $N$. Let's denote an edge between v...
The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. ...
[ "n = int(input())\nr = n + 1\ni = 2\ns = n ** 0.5\nwhile i <= s:\n\tif n % i == 0:\n\t\tr += n // i\n\t\tn //= i\n\t\ts = n ** 0.5\n\t\ti = 1\n\ti += 1\nprint(r)\n", "from math import sqrt, ceil\nn = int(input())\nc = n\nwhile n > 1:\n\tb = 1\n\tfor v in range(2, ceil(sqrt(n)) + 1):\n\t\tif n % v == 0:\n\t\t\tm =...
{"inputs": ["999161856\n", "999999937\n", "9\n", "999936000\n", "18\n", "33\n", "999999948\n", "13\n", "14\n", "5\n", "48\n", "50\n", "1000\n", "999999000\n", "39\n", "999989760\n", "998244352\n", "1011\n", "222953472\n", "35\n", "49\n", "999997440\n", "1000000000\n", "536870912\n", "32\n", "873453946\n", "999996270\n"...
EASY
['number theory']
null
codeforces
['Number theory']
[]
https://codeforces.com/problemset/problem/177/B1
2.0 seconds
null
null
256.0 megabytes
null
25,137
0
n = int(input()) r = n + 1 i = 2 s = n ** 0.5 while i <= s: if n % i == 0: r += n // i n //= i s = n ** 0.5 i = 1 i += 1 print(r)
# Question The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles...
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them. Chose any two positio...
[ "md = 10 ** 9 + 7\nfact = []\nprod = 1\nfor x in range(1, 100002):\n\tfact.append(prod)\n\tprod *= x\n\tprod %= md\nfor _ in range(int(input())):\n\ts = input()\n\tcounts = [s.count(x) for x in set(s)]\n\tsym4 = 0\n\tsym3 = 0\n\tsym2 = 0\n\tsym1 = 0\n\tsym1choose2 = 0\n\tsym2choose2 = 0\n\tsym1cchoose2 = 0\n\tsym1c...
{"inputs": ["2\nz\nabcd", "2\nz\nabcd"], "outputs": ["0\n144", "0\n144"]}
HARD
['medium', 'march16', 'combinatorics', 'sereja_adm']
null
codechef
['Combinatorics']
[]
https://www.codechef.com/problems/SEATSTR2
1 seconds
2014-10-11
0
50000 bytes
null
25,159
0
md = 10 ** 9 + 7 fact = [] prod = 1 for x in range(1, 100002): fact.append(prod) prod *= x prod %= md for _ in range(int(input())): s = input() counts = [s.count(x) for x in set(s)] sym4 = 0 sym3 = 0 sym2 = 0 sym1 = 0 sym1choose2 = 0 sym2choose2 = 0 sym1cchoose2 = 0 sym1c2choose2 = 0 choose_all = fact[len...
# Question Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them. Chose any...
Given a non-negative number N. The problem is to set the rightmost unset bit in the binary representation of N. If there are no unset bits, then just leave the number as it is. Example 1: Input: N = 6 Output: 7 Explanation: The binary representation of 6 is 110. After setting right most bit it becomes 111 which is 7. E...
[ "class Solution:\n\n\tdef setBit(self, N):\n\t\tif N & N + 1:\n\t\t\treturn N | N + 1\n\t\treturn N\n", "class Solution:\n\n\tdef setBit(self, n):\n\t\tif n & n + 1:\n\t\t\treturn n | n + 1\n\t\treturn n\n", "class Solution:\n\n\tdef setBit(self, N):\n\t\ti = 0\n\t\ta = N\n\t\twhile a & 1:\n\t\t\ti += 1\n\t\t\t...
#User function Template for python3 class Solution: def setBit(self, N): # code here
{"inputs": ["N = 6", "N = 15"], "outputs": ["7", "15"]}
EASY
['Data Structures', 'Bit Magic']
null
geeksforgeeks
['Bit manipulation', 'Data structures']
['Bit manipulation', 'Data structures']
https://practice.geeksforgeeks.org/problems/set-the-rightmost-unset-bit4436/1
null
null
0
null
O(LogN)
25,154
0
class Solution: def setBit(self, N): if N & N + 1: return N | N + 1 return N
# Question Given a non-negative number N. The problem is to set the rightmost unset bit in the binary representation of N. If there are no unset bits, then just leave the number as it is. Example 1: Input: N = 6 Output: 7 Explanation: The binary representation of 6 is 110. After setting right most bit it becomes 111 w...
Kim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room. The room is a grid with H∗W$H*W$ cells, divided into H$H$ rows and W$W$ columns. The cell (i,j)$(i,j)$ is at height A[i][j]$A[i][j]$. Unfort...
[ "def solve(l, r, c, row, col, po):\n\tcount = 0\n\tvisited = set()\n\tstack = set()\n\tstack.add((l[row][col], row, col))\n\twhile stack:\n\t\tele = stack.pop()\n\t\tvisited.add((ele[1], ele[2]))\n\t\tif ele[0] < po:\n\t\t\tcount += 1\n\t\t\tif ele[1] - 1 >= 0 and (ele[1] - 1, ele[2]) not in visited:\n\t\t\t\tif l[...
{"inputs": [["1", "5 5 3", "4 3 9 7 2", "8 6 5 2 8", "1 7 3 4 3", "2 2 4 5 6", "9 9 9 9 9", "3 4 6", "3 2 5", "1 4 9"]], "outputs": [["10", "0", "19"]]}
UNKNOWN_DIFFICULTY
[]
null
codechef
[]
[]
https://www.codechef.com/problems/UWCOI20C
null
null
null
null
null
25,163
0
def solve(l, r, c, row, col, po): count = 0 visited = set() stack = set() stack.add((l[row][col], row, col)) while stack: ele = stack.pop() visited.add((ele[1], ele[2])) if ele[0] < po: count += 1 if ele[1] - 1 >= 0 and (ele[1] - 1, ele[2]) not in visited: if l[ele[1] - 1][ele[2]] < po: stack....
# Question Kim has broken in to the base, but after walking in circles, perplexed by the unintelligible base design of the JSA, he has found himself in a large, empty, and pure white, room. The room is a grid with H∗W$H*W$ cells, divided into H$H$ rows and W$W$ columns. The cell (i,j)$(i,j)$ is at height A[i][j]$A[i]...
It’s well know fact among kitties that digits 4 and 7 are lucky digits. Today, N boxes of fish bites arrived. Each box has a unique integer label on it, ranged between 1 and N, inclusive. The boxes are going to be given away to the kitties in increasing order of their labels. That is, the first box given away will be t...
[ "k = eval(input())\nn = eval(input())\n\ni=1\na=0\nb=0\ncnt=0\n\nwhile(i<=n):\n\ta+=str(i).count('4')\n\tb+=str(i).count('7')\n\tif(a+b>k):\n\t\tcnt+=1\n\t\ta=0\n\t\tb=0\n\ti+=1\nprint(cnt)\n\n", "k = int(input())\nn = int(input())\nlucky = 0\nkc = 0\n\nfor i in range(1, n+1):\n\ts = str(i)\n\tkc += s.count('4')\...
{"inputs": ["3\n7331173", "6\n49503", "3\n285"], "outputs": ["2305411", "6684", "29"]}
EASY
[]
lucky-kitties
hackerearth
[]
[]
null
null
null
null
null
null
25,165
0
k = eval(input()) n = eval(input()) i=1 a=0 b=0 cnt=0 while(i<=n): a+=str(i).count('4') b+=str(i).count('7') if(a+b>k): cnt+=1 a=0 b=0 i+=1 print(cnt)
# Question It’s well know fact among kitties that digits 4 and 7 are lucky digits. Today, N boxes of fish bites arrived. Each box has a unique integer label on it, ranged between 1 and N, inclusive. The boxes are going to be given away to the kitties in increasing order of their labels. That is, the first box given aw...
We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in both values of `f1(n,k)` and `f2(n,k)`. The possible values for ...
[ "def find_f1_eq_f2(n, k):\n\ts = set(range(k))\n\twhile True:\n\t\tn += 1\n\t\ttestn = n\n\t\twhile True:\n\t\t\tf = set(map(int, str(testn)))\n\t\t\tif f <= s:\n\t\t\t\tif f == s:\n\t\t\t\t\treturn n\n\t\t\t\tbreak\n\t\t\ttestn += n\n", "def find_f1_eq_f2(n, k):\n\ts = set(range(k))\n\twhile True:\n\t\tn += 1\n\...
def find_f1_eq_f2(n,k):
{"fn_name": "find_f1_eq_f2", "inputs": [[542, 5], [1750, 6], [14990, 7], [3456, 4], [30500, 3], [62550, 5], [568525, 7], [9567100, 8]], "outputs": [[547], [1799], [14996], [3462], [30501], [62557], [568531], [9567115]]}
EASY
['Data Structures', 'Algorithms', 'Fundamentals', 'Mathematics']
null
codewars
['Fundamentals', 'Data structures', 'Mathematics']
['Data structures']
https://www.codewars.com/kata/5cb99d1a1e00460024827738
null
null
null
null
null
25,166
0
def find_f1_eq_f2(n, k): s = set(range(k)) while True: n += 1 testn = n while True: f = set(map(int, str(testn))) if f <= s: if f == s: return n break testn += n
# Question We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in both values of `f1(n,k)` and `f2(n,k)`. The possible...
Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. The following sequences are not permutations: $[0]$, $[1, 2, 1]$, $[2, 3]$, ...
[ "def test(a):\n\tse = set()\n\tse.add(a[0])\n\tans = [a[0]]\n\tl = 1\n\tfor i in range(1, len(a)):\n\t\tif a[i] == a[i - 1]:\n\t\t\twhile l in se:\n\t\t\t\tl += 1\n\t\t\tans.append(l)\n\t\t\tse.add(l)\n\t\telse:\n\t\t\tans.append(a[i])\n\t\t\tse.add(a[i])\n\t\tif ans[i] > a[i]:\n\t\t\tprint(-1)\n\t\t\treturn\n\tf =...
{"inputs": ["4\n5\n1 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "4\n5\n2 3 4 5 5\n4\n1 1 3 4\n2\n2 2\n1\n1\n", "4\n5\n1 3 4 5 5\n4\n1 1 4 4\n2\n2 2\n1\n1\n", "4\n5\n1 3 3 5 5\n4\n1 1 1 4\n2\n2 2\n1\n1\n", "4\n5\n1 3 4 4 5\n4\n1 1 1 4\n2\n2 2\n1\n1\n", "4\n5\n1 3 3 5 5\n4\n1 1 1 4\n2\n1 2\n1\n1\n", "4\n5\n2 3 3 5 5\n4\n1 1 1...
EASY
['constructive algorithms']
null
codeforces
['Constructive algorithms']
[]
https://codeforces.com/problemset/problem/1227/B
null
2019-12-31
null
null
null
25,153
0
def test(a): se = set() se.add(a[0]) ans = [a[0]] l = 1 for i in range(1, len(a)): if a[i] == a[i - 1]: while l in se: l += 1 ans.append(l) se.add(l) else: ans.append(a[i]) se.add(a[i]) if ans[i] > a[i]: print(-1) return f = False if len(set(ans)) == n: print(' '.join(map(str, an...
# Question Permutation $p$ is a sequence of integers $p=[p_1, p_2, \dots, p_n]$, consisting of $n$ distinct (unique) positive integers between $1$ and $n$, inclusive. For example, the following sequences are permutations: $[3, 4, 1, 2]$, $[1]$, $[1, 2]$. The following sequences are not permutations: $[0]$, $[1, 2, 1]$...
There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platforms on a river, the $i$-th platform has length $c_i$ (so the $i$-th platform...
[ "import os\nimport sys\nfrom io import BytesIO, IOBase\nBUFSIZE = 8192\n\nclass FastIO(IOBase):\n\tnewlines = 0\n\n\tdef __init__(self, file):\n\t\tself._fd = file.fileno()\n\t\tself.buffer = BytesIO()\n\t\tself.writable = 'x' in file.mode or 'r' not in file.mode\n\t\tself.write = self.buffer.write if self.writable...
{"inputs": ["7 3 2\n1 2 1\n", "10 1 11\n1\n", "10 1 5\n2\n", "1000 3 9\n106 118 99\n", "1000 20 8\n3 6 3 4 3 5 3 5 5 5 3 1 3 8 2 4 4 5 3 2\n", "1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n", "5 1 2\n1\n", "1 1 1\n1\n", "2 1 1\n1\n", "4 1 2\n1\n", "15 2 5\n1 1\n", "10 10 1\n1 1 1 1 1 1 1 1 1 1\n", "5 2 1\...
MEDIUM_HARD
['greedy']
null
codeforces
['Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/1256/C
null
2019-12-31
null
null
null
25,149
0
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self)...
# Question There is a river of width $n$. The left bank of the river is cell $0$ and the right bank is cell $n + 1$ (more formally, the river can be represented as a sequence of $n + 2$ cells numbered from $0$ to $n + 1$). There are also $m$ wooden platforms on a river, the $i$-th platform has length $c_i$ (so the $i$...
Let's call an array $a$ consisting of $n$ positive (greater than $0$) integers beautiful if the following condition is held for every $i$ from $1$ to $n$: either $a_i = 1$, or at least one of the numbers $a_i - 1$ and $a_i - 2$ exists in the array as well. For example: the array $[5, 3, 1]$ is beautiful: for $a_1$, t...
[ "import math\nfor _ in range(int(input())):\n\tn = int(input())\n\tif n == 1:\n\t\tprint(1)\n\telse:\n\t\tx = int(math.sqrt(n))\n\t\tif x ** 2 == n:\n\t\t\tprint(x)\n\t\telse:\n\t\t\tprint(x + 1)\n", "for i in range(int(input())):\n\tprint(int((int(input()) - 1) ** 0.5) + 1)\n", "for _ in [0] * int(input()):\n\...
{"inputs": ["4\n1\n8\n7\n42\n", "4\n1\n12\n7\n42\n", "4\n1\n1\n7\n42\n", "4\n1\n12\n7\n35\n", "4\n1\n3\n7\n42\n", "4\n1\n1\n7\n27\n", "4\n1\n12\n13\n35\n", "4\n1\n3\n12\n42\n", "4\n1\n2\n7\n27\n", "4\n2\n3\n7\n27\n", "4\n2\n1\n9\n27\n", "4\n1\n9\n7\n42\n", "4\n1\n10\n1\n42\n", "4\n1\n3\n12\n6\n", "4\n1\n2\n13\n27\n", "...
EASY
['greedy', 'math']
null
codeforces
['Mathematics', 'Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/1550/A
1 second
2021-07-14
0
256 megabytes
null
25,152
0
import math for _ in range(int(input())): n = int(input()) if n == 1: print(1) else: x = int(math.sqrt(n)) if x ** 2 == n: print(x) else: print(x + 1)
# Question Let's call an array $a$ consisting of $n$ positive (greater than $0$) integers beautiful if the following condition is held for every $i$ from $1$ to $n$: either $a_i = 1$, or at least one of the numbers $a_i - 1$ and $a_i - 2$ exists in the array as well. For example: the array $[5, 3, 1]$ is beautiful: ...
Captain Jack loves tables. He wants to know whether you love tables or not. So he asks you to solve the following problem: Given an array A and element m, you have to find the value up to which table of m is present in the array. (example - if the array is 3 4 5 2 4 7 10 6 and value of m is 2 then answer is 6 because w...
[ "'''\n# Read input from stdin and provide input before running code\n\nname = raw_input('What is your name?\\n')\nprint 'Hi, %s.' % name\n'''\n#print 'Hello World!'\nn,m=list(map(int,input().split()))\nl=[int(i) for i in input().split()]\nc=0\nt=m\nfor i in range(1,len(l)+1):\n\t#print i\n\tif m in l:\n\t\tc=m\n\t\...
{"inputs": ["8 3\n2 1 4 5 7 10 11 13", "1000 2\n489 428 166 36 252 484 281 341 72 136 111 40 361 251 477 448 179 460 284 303 258 392 279 481 134 447 407 277 141 301 48 274 152 397 51 235 88 94 83 397 495 14 220 303 270 5 174 366 384 190 384 74 460 449 321 39 171 37 465 462 333 233 412 454 86 78 380 48 458 391 141 119 1...
UNKNOWN_DIFFICULTY
[]
second
hackerearth
[]
[]
null
null
null
null
null
null
25,169
0
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' n,m=list(map(int,input().split())) l=[int(i) for i in input().split()] c=0 t=m for i in range(1,len(l)+1): #print i if m in l: c=m #print c m=i*t #print ...
# Question Captain Jack loves tables. He wants to know whether you love tables or not. So he asks you to solve the following problem: Given an array A and element m, you have to find the value up to which table of m is present in the array. (example - if the array is 3 4 5 2 4 7 10 6 and value of m is 2 then answer is...
Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum. For more clarification Sum for an array A having N element is defined as : abs( A[0] - A[1] ) + abs( A[1] - A[2] ) + abs( A[2] - A[3] ) +............ + abs( A[N-2] - A[N-1] ) Inp...
[ "for tc in range(eval(input())):\n\tn = eval(input())\n\ta = list(map(int,input().split()))\n\tk=ans=0\n\tif n < 3:\n\t\tans=0\n\telse:\n\t\tt=abs(a[0]-a[1])\n\t\tk=t\n\t\tfor i in range(1,n-1):\n\t\t\tt = abs(abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1]))\n\t\t\tif t>k:\n\t\t\t\tk=t\n\t\t\t\tans = i\n\t...
{"inputs": ["5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 1\n3\n7 1 8", "3\n4\n10 20 80 10\n4\n50 50 50 40\n3\n100 20 100", "3\n5\n10 20 40 50 40\n5\n100 100 100 100 101\n6\n100 100 100 100 100 100", "3\n12\n1 30 40 100 100 100 40 90 10 30 1 100 \n7\n100 90 80 1 90 70 80\n6\n1...
EASY
['Implementation']
simple-task
hackerearth
['Implementation']
[]
null
null
null
null
null
null
25,158
0
for tc in range(eval(input())): n = eval(input()) a = list(map(int,input().split())) k=ans=0 if n < 3: ans=0 else: t=abs(a[0]-a[1]) k=t for i in range(1,n-1): t = abs(abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1])) if t>k: k=t ans = i if n > 2 and abs(a[n-1]-a[n-2]) > k: ans = n-...
# Question Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum. For more clarification Sum for an array A having N element is defined as : abs( A[0] - A[1] ) + abs( A[1] - A[2] ) + abs( A[2] - A[3] ) +............ + abs( A[N-2] - A[N-1...
Have you ever had an infinite loop when you ran a hard-working program? It would be convenient to be able to determine in advance whether a program will stop executing without having to execute it. Unfortunately, it is not possible to make such a decision for any program in the programming language you normally use. H...
[ "def solve():\n\tfrom sys import stdin\n\tf_i = stdin\n\tN = int(f_i.readline())\n\tfrom string import ascii_lowercase\n\tnext_line = {}\n\tS = {}\n\tV = {}\n\tline = 0\n\tfor i in range(N):\n\t\tstmt = f_i.readline().split()\n\t\tnext_line[line] = stmt[0]\n\t\tline = stmt[0]\n\t\top = stmt[1]\n\t\tif op == 'ADD' o...
{"inputs": ["3\n111 SET c 1\n12 SUB c c 4\n777 SET a 4", "3\n10 SET c 1\n193 IF c 10\n20 HALT", "6\n10 SET c 1\n20 SET h 5\n100 ADD s s i\n110 SUB i i c\n120 IF i 100\n200 HALT", "3\n10 SET c 1\n193 IF c 11\n20 HALT", "3\n10 SET c 0\n193 IF c 11\n20 HALT", "3\n111 SET c 1\n12 SUB c c 2\n777 SET b 4", "6\n10 SET b 1\n20...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
5.0 seconds
null
null
268.435456 megabytes
null
25,177
0
def solve(): from sys import stdin f_i = stdin N = int(f_i.readline()) from string import ascii_lowercase next_line = {} S = {} V = {} line = 0 for i in range(N): stmt = f_i.readline().split() next_line[line] = stmt[0] line = stmt[0] op = stmt[1] if op == 'ADD' or op == 'SUB': (v1, v2, v3) = stmt[...
# Question Have you ever had an infinite loop when you ran a hard-working program? It would be convenient to be able to determine in advance whether a program will stop executing without having to execute it. Unfortunately, it is not possible to make such a decision for any program in the programming language you nor...
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
[ "import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools\nsys.setrecursionlimit(10 ** 7)\ninf = 10 ** 20\neps = 1.0 / 10 ** 10\nmod = 10 ** 9 + 7\ndd = [(-1, 0), (0, 1), (1, 0), (0, -1)]\nddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]\n\nd...
{"inputs": ["2000 2000\n", "1544 1794\n", "1639 1056\n", "56 48\n", "1066 995\n", "49 110\n", "478 1301\n", "158 772\n", "162 161\n", "83 37\n", "1454 296\n", "500 1304\n", "1307 1247\n", "525 314\n", "359 896\n", "1000 1\n", "2000 1000\n", "1478 194\n", "1903 1612\n", "1610 774\n", "1707 1117\n", "86 1078\n", "2000 1\...
MEDIUM
['number theory', 'combinatorics', 'dp']
null
codeforces
['Number theory', 'Combinatorics', 'Dynamic programming']
['Dynamic programming']
https://codeforces.com/problemset/problem/415/D
1.0 seconds
null
null
256.0 megabytes
null
25,176
0
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 10 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): ret...
# Question Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very expe...
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
[ "n = int(input())\nd = {}\nl = []\nfor _ in range(n):\n\t(name, score) = input().split()\n\tscore = int(score)\n\tl.append((name, score))\n\td[name] = d.get(name, 0) + score\nm = max([x for x in d.values()])\nties = [x for (x, y) in d.items() if y == m]\nif len(ties) == 1:\n\tprint(ties[0])\n\texit()\nelse:\n\td.cl...
{"inputs": ["15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzha...
MEDIUM
['implementation', 'hashing']
null
codeforces
['String algorithms', 'Implementation']
[]
https://codeforces.com/problemset/problem/2/A
1.0 seconds
null
null
64.0 megabytes
null
25,107
0
n = int(input()) d = {} l = [] for _ in range(n): (name, score) = input().split() score = int(score) l.append((name, score)) d[name] = d.get(name, 0) + score m = max([x for x in d.values()]) ties = [x for (x, y) in d.items() if y == m] if len(ties) == 1: print(ties[0]) exit() else: d.clear() for row in l: (na...
# Question The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each...
Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on. Example 1: Input: A[] = {4, 7, 3, 6, 7}; Output: 81 40 41 21 19 22 11 10 9 13 4 7 3 6 7 Explanation: 81 40 41 21 19 22 ...
[ "def getTriangle(arr, n):\n\ts = [[0 for i in range(n)] for j in range(n)]\n\tfor i in range(n):\n\t\ts[n - 1][i] = arr[i]\n\tj = 1\n\twhile j < n:\n\t\tk = j\n\t\tfor i in range(k, n, 1):\n\t\t\ts[n - 1 - j][i] = s[n - j][i] + s[n - j][i - 1]\n\t\tj += 1\n\ta = []\n\ti = n - 1\n\twhile i > -1:\n\t\tfor j in range(...
#User function Template for python3 def getTriangle( arr, n):
{"fn_name": "getTriangle", "inputs": ["A[] = {4, 7, 3, 6, 7};", "A[] = {5, 8, 1, 2, 4, 3, 14}"], "outputs": ["81 40 41 21 19 22 11 10 9 13 4 7 3 6 7", "200 98 102 55 43 59 34 21 22 37 22\n12 9 13 24 13 9 3 6 7 17 5 8 1 2 4 3 14 "]}
EASY
['Data Structures', 'Arrays']
null
geeksforgeeks
['Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/sum-triangle-for-given-array1159/1
null
null
0
null
O(N^{2})
25,174
0
def getTriangle(arr, n): s = [[0 for i in range(n)] for j in range(n)] for i in range(n): s[n - 1][i] = arr[i] j = 1 while j < n: k = j for i in range(k, n, 1): s[n - 1 - j][i] = s[n - j][i] + s[n - j][i - 1] j += 1 a = [] i = n - 1 while i > -1: for j in range(i, n, 1): a.append(s[n - 1 - i][j])...
# Question Given a array, write a program to construct a triangle where last row contains elements of given array, every element of second last row contains sum of below two elements and so on. Example 1: Input: A[] = {4, 7, 3, 6, 7}; Output: 81 40 41 21 19 22 11 10 9 13 4 7 3 6 7 Explanation: 81 40 41 ...
Given an array of N integers and another array R containing Q queries(of l and r). Answer all Q queries asking the number of primes in the subarray ranging from l to r (both inclusive). Note: A is 0-based but the queries will be 1-based. Example 1: Input: N=5,Q=3 A={2,5,6,7,8} R={{1,3},{2,5},{3,3}} Output: 2 2 0 Explan...
[ "class Solution:\n\n\tdef primeRange(self, N, Q, A, R):\n\t\tn = max(A)\n\t\tsieve = [True] * (n + 1)\n\t\tsieve[0] = sieve[1] = False\n\t\tfor i in range(2, int(n ** 0.5) + 1):\n\t\t\tif sieve[i]:\n\t\t\t\tfor j in range(i * i, n + 1, i):\n\t\t\t\t\tsieve[j] = False\n\t\ttree = [0] * (n + 1)\n\n\t\tdef add(pos, va...
#User function Template for python3 class Solution: def primeRange(self,N,Q,A,R): #R is a 2D array of dimensions Qx2 #code here
{"inputs": ["N=5,Q=3\nA={2,5,6,7,8}\nR={{1,3},{2,5},{3,3}}", "N=5,Q=3\nA={1,2,3,4,5}\nR={{1,4},{2,5},{2,3}}"], "outputs": ["2 2 0", "2 3 2"]}
MEDIUM
['Algorithms', 'sieve', 'Mathematical']
null
geeksforgeeks
['Number theory', 'Mathematics']
[]
https://practice.geeksforgeeks.org/problems/pasha-and-primes0438/1
null
null
0
null
O(Max(A[i])*Log(Log (Max(A[i]) )))
25,184
0
class Solution: def primeRange(self, N, Q, A, R): n = max(A) sieve = [True] * (n + 1) sieve[0] = sieve[1] = False for i in range(2, int(n ** 0.5) + 1): if sieve[i]: for j in range(i * i, n + 1, i): sieve[j] = False tree = [0] * (n + 1) def add(pos, val): while pos <= n: tree[pos] += va...
# Question Given an array of N integers and another array R containing Q queries(of l and r). Answer all Q queries asking the number of primes in the subarray ranging from l to r (both inclusive). Note: A is 0-based but the queries will be 1-based. Example 1: Input: N=5,Q=3 A={2,5,6,7,8} R={{1,3},{2,5},{3,3}} Output: ...
Given a binary tree of size N, find its reverse level order traversal. ie- the traversal must begin from the last level. Example 1: Input : 1 / \ 3 2 Output: 3 2 1 Explanation: Traversing level 1 : 3 2 Traversing level 0 : 1 Example 2: Input : 10 / \ 20 30 / \ 40 ...
[ "def reverseLevelOrder(root):\n\ttemp1 = [root]\n\tresult = []\n\twhile temp1:\n\t\ttemp2 = []\n\t\ttemp3 = []\n\t\tfor i in temp1:\n\t\t\ttemp3.append(i.data)\n\t\t\tif i.left:\n\t\t\t\ttemp2.append(i.left)\n\t\t\tif i.right:\n\t\t\t\ttemp2.append(i.right)\n\t\ttemp1 = temp2\n\t\tif temp3:\n\t\t\tresult = temp3 + ...
#User function Template for python3 ''' class Node: def __init__(self,val): self.data = val self.left = None self.right = None ''' def reverseLevelOrder(root): # code here
{"inputs": ["1\r\n / \\\r\n 3 2", "10\r\n / \\\r\n 20 30\r\n / \\ \r\n 40 60"], "outputs": ["3 2 1", "40 60 20 30 10"]}
EASY
['Data Structures', 'Tree']
null
geeksforgeeks
['Tree algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/reverse-level-order-traversal/1
null
null
0
null
O(N)
25,173
0
def reverseLevelOrder(root): temp1 = [root] result = [] while temp1: temp2 = [] temp3 = [] for i in temp1: temp3.append(i.data) if i.left: temp2.append(i.left) if i.right: temp2.append(i.right) temp1 = temp2 if temp3: result = temp3 + result return result
# Question Given a binary tree of size N, find its reverse level order traversal. ie- the traversal must begin from the last level. Example 1: Input : 1 / \ 3 2 Output: 3 2 1 Explanation: Traversing level 1 : 3 2 Traversing level 0 : 1 Example 2: Input : 10 / \ 20 30 ...
Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order. Example 1: Input: N = 7 Arr = {1, 2, 3, 5, 4, 7, 10} Output: 7 5 3 1 2 4 10 Explanation: Array ...
[ "class Solution:\n\n\tdef sortIt(self, arr, n):\n\t\tlist1 = list()\n\t\tlist2 = list()\n\t\tfor i in arr:\n\t\t\tif i % 2 == 0:\n\t\t\t\tlist1.append(i)\n\t\t\telse:\n\t\t\t\tlist2.append(i)\n\t\tlist2.sort(reverse=True)\n\t\tlist1.sort()\n\t\tarr[:] = list2 + list1\n\t\treturn arr\n", "class Solution:\n\n\tdef ...
#User function Template for python3 class Solution: def sortIt(self, arr, n): #code here.
{"inputs": ["N = 7\r\nArr = {1, 2, 3, 5, 4, 7, 10}", "N = 7\r\nArr = {0, 4, 5, 3, 7, 2, 1}"], "outputs": ["7 5 3 1 2 4 10", "7 5 3 1 0 2 4"]}
EASY
['Data Structures', 'Arrays', 'Algorithms', 'Sorting']
null
geeksforgeeks
['Sorting', 'Data structures']
['Sorting', 'Data structures']
https://practice.geeksforgeeks.org/problems/sort-in-specific-order2422/1
null
null
0
null
O(N. Log(N))
25,182
0
class Solution: def sortIt(self, arr, n): list1 = list() list2 = list() for i in arr: if i % 2 == 0: list1.append(i) else: list2.append(i) list2.sort(reverse=True) list1.sort() arr[:] = list2 + list1 return arr
# Question Given an array A of positive integers. Your task is to sort them in such a way that the first part of the array contains odd numbers sorted in descending order, rest portion contains even numbers sorted in ascending order. Example 1: Input: N = 7 Arr = {1, 2, 3, 5, 4, 7, 10} Output: 7 5 3 1 2 4 10 Explana...
Given two BSTs containing N1 and N2 distinct nodes respectively and given a value x. Your task is to complete the function countPairs(), that returns the count of all pairs from both the BSTs whose sum is equal to x. Example 1: Input: BST1: 5 / \ 3 7 / \ / \ 2 4 6 8 BST2: 10 ...
[ "class Solution:\n\n\tdef inorder(self, root):\n\t\tans = []\n\t\tcurr = root\n\t\twhile curr:\n\t\t\tif curr.left is None:\n\t\t\t\tans.append(curr.data)\n\t\t\t\tcurr = curr.right\n\t\t\telse:\n\t\t\t\tpred = curr.left\n\t\t\t\twhile pred.right and pred.right != curr:\n\t\t\t\t\tpred = pred.right\n\t\t\t\tif pred...
#User function Template for python3 ''' # Tree Node class Node: def __init__(self, val): self.right = None self.data = val self.left = None ''' class Solution: def countPairs(self, root1, root2, x): #code here.
{"inputs": ["BST1:\n 5\n / \\\n 3 7\n / \\ / \\\n 2 4 6 8\n\nBST2:\n 10\n / \\\n 6 15\n / \\ / \\\n 3 8 11 18\n\nx = 16", "BST1:\n 1\n \\\n 3\n /\n 2\nBST2:\n 3\n / \\\n 2 4\n / \n1\n\nx = 4"], "outputs": ["3", "3"]}
EASY
['Data Structures', 'Binary Search Tree', 'Algorithms', 'Traversal']
null
geeksforgeeks
['Data structures', 'Graph traversal', 'Range queries']
['Data structures', 'Range queries']
https://practice.geeksforgeeks.org/problems/brothers-from-different-root/1
null
null
0
null
O(N)
25,181
0
class Solution: def inorder(self, root): ans = [] curr = root while curr: if curr.left is None: ans.append(curr.data) curr = curr.right else: pred = curr.left while pred.right and pred.right != curr: pred = pred.right if pred.right is None: pred.right = curr curr = curr....
# Question Given two BSTs containing N1 and N2 distinct nodes respectively and given a value x. Your task is to complete the function countPairs(), that returns the count of all pairs from both the BSTs whose sum is equal to x. Example 1: Input: BST1: 5 / \ 3 7 / \ / \ 2 4 6 8 BST2: ...
Polycarp got an array of integers $a[1 \dots n]$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $a_1=a_2=\dots=a_n$). In one operation, he can take some indices in the array and increase the elements of the array a...
[ "from collections import Counter\nfrom math import ceil, floor, log, gcd\nimport bisect as bs\nimport sys\ninput = sys.stdin.readline\ninp_lis = lambda : list(map(int, input().split()))\ninp_multi = lambda : map(int, input().split())\ninp_int = lambda : int(input().strip())\nfor _ in range(int(input().strip())):\n\...
{"inputs": ["3\n6\n3 4 2 4 1 2\n3\n1000 1002 998\n2\n12 11\n", "1\n31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"], "outputs": ["3\n4\n1\n", "0\n"]}
EASY
['math']
null
codeforces
['Mathematics']
[]
https://codeforces.com/problemset/problem/1624/A
2 seconds
2022-01-10
0
256 megabytes
null
25,178
0
from collections import Counter from math import ceil, floor, log, gcd import bisect as bs import sys input = sys.stdin.readline inp_lis = lambda : list(map(int, input().split())) inp_multi = lambda : map(int, input().split()) inp_int = lambda : int(input().strip()) for _ in range(int(input().strip())): n = inp_int() ...
# Question Polycarp got an array of integers $a[1 \dots n]$ as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become $a_1=a_2=\dots=a_n$). In one operation, he can take some indices in the array and increase the elements of...
Given a function that takes a binary string. The task is to return the longest size of contiguous substring containing only ‘1’. Input: The first line of input contains an integer T denoting the no of test cases.Then T test cases follow. Each test case contains a string S. Output: For each test case return the maximum ...
[ "def maxlength(s):\n\tc = 0\n\tl = []\n\tfor i in s:\n\t\tif i == '1':\n\t\t\tc += 1\n\t\telse:\n\t\t\tl.append(c)\n\t\t\tc = 0\n\tl.append(c)\n\treturn max(l)\n", "def maxlength(s):\n\ts = s.split('0')\n\ta = 0\n\tfor i in s:\n\t\ta = max(a, len(i))\n\treturn a\n", "def maxlength(s):\n\tl = s.split('0')\n\tmax...
#User function Template for python3 def maxlength(s): #add code here
{"fn_name": "maxlength", "inputs": ["2\r\n\r\n110\r\n\r\n11101110"], "outputs": ["2\r\n3"]}
EASY
['Data Structures', 'Strings']
null
geeksforgeeks
['String algorithms', 'Data structures']
['Data structures']
https://practice.geeksforgeeks.org/problems/longest-substring-containing-1/1
null
null
0
null
25,187
0
def maxlength(s): c = 0 l = [] for i in s: if i == '1': c += 1 else: l.append(c) c = 0 l.append(c) return max(l)
# Question Given a function that takes a binary string. The task is to return the longest size of contiguous substring containing only ‘1’. Input: The first line of input contains an integer T denoting the no of test cases.Then T test cases follow. Each test case contains a string S. Output: For each test case return ...
Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also nonnegative. She would like to research more about this function and has...
[ "n = int(input())\nl = list(map(int, input().split()))\np = [0] * n\ntemp = ~l[0]\nfor i in range(1, n):\n\tp[i] = temp\n\ttemp &= ~l[i]\ntemp = ~l[-1]\nans = [-1, -float('inf')]\nfor i in range(n - 2, -1, -1):\n\tif i != 0:\n\t\tp[i] &= temp\n\t\ttemp &= ~l[i]\n\t\tp[i] &= l[i]\n\t\tif ans[1] < p[i]:\n\t\t\tans[0]...
{"inputs": ["4\n4 0 11 6\n", "1\n13\n", "5\n315479581 954336048 124252105 880492165 179952043\n", "2\n151282707 316934479\n", "5\n809571641 29322377 935888946 833709370 2457463\n", "1\n901418150\n", "2\n512483 512483\n", "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553...
MEDIUM
[]
null
codeforces
[]
[]
https://codeforces.com/problemset/problem/1300/C
null
null
null
null
null
25,175
0
n = int(input()) l = list(map(int, input().split())) p = [0] * n temp = ~l[0] for i in range(1, n): p[i] = temp temp &= ~l[i] temp = ~l[-1] ans = [-1, -float('inf')] for i in range(n - 2, -1, -1): if i != 0: p[i] &= temp temp &= ~l[i] p[i] &= l[i] if ans[1] < p[i]: ans[0] = i ans[1] = p[i] else: p[i...
# Question Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also nonnegative. She would like to research more about this func...
Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is equal to the minimal index i < j ≤ n, such that p_j > p_i. If there is no su...
[ "import sys\nfrom array import array\nfrom typing import List, Tuple, TypeVar, Generic, Sequence, Union\n\ndef input():\n\treturn sys.stdin.buffer.readline().decode('utf-8')\n\ndef main():\n\tt = int(input())\n\tans = ['-1'] * t\n\tfor ti in range(t):\n\t\tn = int(input())\n\t\ta = [0] + list(map(int, input().split...
{"inputs": ["6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n", "10\n4\n2 4 4 5\n4\n2 -1 4 -1\n4\n4 5 5 5\n4\n2 3 4 5\n4\n2 3 4 5\n4\n-1 3 4 5\n4\n-1 3 4 5\n4\n3 3 4 5\n4\n3 5 5 5\n4\n5 4 5 5\n", "10\n4\n2 4 4 5\n4\n2 -1 4 -1\n4\n4 5 5 5\n4\n2 3 4 5\n4\n4 3 4 5\n4\n-1 3 4 5\n4\n-1 3 4 5\n4\n3 3 4 5\n4\n...
HARD
['data structures', 'greedy', 'math', 'dfs and similar', 'graphs', 'sortings', 'constructive algorithms']
null
codeforces
['Graph algorithms', 'Graph traversal', 'Constructive algorithms', 'Sorting', 'Greedy algorithms', 'Mathematics', 'Data structures']
['Sorting', 'Data structures', 'Greedy algorithms']
https://codeforces.com/problemset/problem/1159/E
1.0 seconds
null
null
256.0 megabytes
null
25,191
0
import sys from array import array from typing import List, Tuple, TypeVar, Generic, Sequence, Union def input(): return sys.stdin.buffer.readline().decode('utf-8') def main(): t = int(input()) ans = ['-1'] * t for ti in range(t): n = int(input()) a = [0] + list(map(int, input().split())) p = [0] * (n + 1) ...
# Question Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is equal to the minimal index i < j ≤ n, such that p_j > p_i. If th...
In this kata you will be given a sequence of the dimensions of rectangles ( sequence with width and length ) and circles ( radius - just a number ). Your task is to return a new sequence of dimensions, sorted ascending by area. For example, ```python seq = [ (4.23, 6.43), 1.23, 3.444, (1.342, 3.212) ] # [ rectangle...
[ "def sort_by_area(seq):\n\n\tdef func(x):\n\t\tif isinstance(x, tuple):\n\t\t\treturn x[0] * x[1]\n\t\telse:\n\t\t\treturn 3.14 * x * x\n\treturn sorted(seq, key=func)\n", "from math import pi as PI\n\ndef circle(r):\n\treturn r * r * PI\n\ndef rect(a, b):\n\treturn a * b\n\ndef getArea(r):\n\treturn rect(*r) if ...
def sort_by_area(seq):
{"fn_name": "sort_by_area", "inputs": [[[]]], "outputs": [[[]]]}
EASY
['Mathematics', 'Algorithms', 'Geometry', 'Fundamentals', 'Sorting']
null
codewars
['Geometry', 'Fundamentals', 'Sorting', 'Mathematics']
['Sorting']
https://www.codewars.com/kata/5a1ebc2480171f29cf0000e5
null
null
null
null
null
25,190
0
def sort_by_area(seq): def func(x): if isinstance(x, tuple): return x[0] * x[1] else: return 3.14 * x * x return sorted(seq, key=func)
# Question In this kata you will be given a sequence of the dimensions of rectangles ( sequence with width and length ) and circles ( radius - just a number ). Your task is to return a new sequence of dimensions, sorted ascending by area. For example, ```python seq = [ (4.23, 6.43), 1.23, 3.444, (1.342, 3.212) ] #...
A sequence of $n$ numbers is called permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] — are not. Kristina had a permutation $p$ of $n$ elements. She wrote it on the whiteboard $n$ tim...
[ "from sys import stdin\ninput = stdin.readline\nt = int(input())\nfor _ in range(t):\n\tn = int(input())\n\tperms = []\n\tfor _ in range(n):\n\t\tperms.append(list(input().split()))\n\tstart = None\n\tif perms[0][0] == perms[1][0] or perms[0][0] == perms[2][0]:\n\t\tstart = perms[0][0]\n\telse:\n\t\tstart = perms[1...
{"inputs": ["5\n4\n4 2 1\n4 2 3\n2 1 3\n4 1 3\n3\n2 3\n1 3\n1 2\n5\n4 2 1 3\n2 1 3 5\n4 2 3 5\n4 1 3 5\n4 2 1 5\n4\n2 3 4\n1 3 4\n1 2 3\n1 2 4\n3\n2 1\n1 3\n2 3\n", "1\n4\n4 2 1\n4 2 3\n2 1 3\n4 1 3\n"], "outputs": ["4 2 1 3 \n1 2 3 \n4 2 1 3 5 \n1 2 3 4 \n2 1 3 \n", "4 2 1 3 \n"]}
EASY
['brute force', 'math', 'implementation']
null
codeforces
['Mathematics', 'Implementation', 'Complete search']
['Complete search']
https://codeforces.com/problemset/problem/1790/C
3 seconds
2023-01-27
0
256 megabytes
null
25,186
0
from sys import stdin input = stdin.readline t = int(input()) for _ in range(t): n = int(input()) perms = [] for _ in range(n): perms.append(list(input().split())) start = None if perms[0][0] == perms[1][0] or perms[0][0] == perms[2][0]: start = perms[0][0] else: start = perms[1][0] for perm in perms: if...
# Question A sequence of $n$ numbers is called permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] — are not. Kristina had a permutation $p$ of $n$ elements. She wrote it on the whiteb...
There are two types of soup: type A and type B. Initially we have N ml of each type of soup. There are four kinds of operations: Serve 100 ml of soup A and 0 ml of soup B Serve 75 ml of soup A and 25 ml of soup B Serve 50 ml of soup A and 50 ml of soup B Serve 25 ml of soup A and 75 ml of soup B When we serve some so...
[ "class Solution:\n\n\tdef soupServings(self, N: int) -> float:\n\t\tif N > 5000:\n\t\t\treturn 1\n\n\t\t@lru_cache(None)\n\t\tdef dp(a, b):\n\t\t\tif a <= 0 and b <= 0:\n\t\t\t\treturn 0.5\n\t\t\tif a <= 0:\n\t\t\t\treturn 1\n\t\t\tif b <= 0:\n\t\t\t\treturn 0\n\t\t\treturn (dp(a - 100, b) + dp(a - 75, b - 25) + dp...
class Solution: def soupServings(self, N: int) -> float:
{"fn_name": "soupServings", "inputs": [[50]], "outputs": [0.625]}
MEDIUM
['Math', 'Dynamic Programming', 'Probability and Statistics']
null
leetcode
['Dynamic programming', 'Mathematics', 'Probability']
['Dynamic programming']
https://leetcode.com/problems/soup-servings/
null
null
null
null
null
25,192
0
class Solution: def soupServings(self, N: int) -> float: if N > 5000: return 1 @lru_cache(None) def dp(a, b): if a <= 0 and b <= 0: return 0.5 if a <= 0: return 1 if b <= 0: return 0 return (dp(a - 100, b) + dp(a - 75, b - 25) + dp(a - 50, b - 50) + dp(a - 25, b - 75)) / 4 return d...
# Question There are two types of soup: type A and type B. Initially we have N ml of each type of soup. There are four kinds of operations: Serve 100 ml of soup A and 0 ml of soup B Serve 75 ml of soup A and 25 ml of soup B Serve 50 ml of soup A and 50 ml of soup B Serve 25 ml of soup A and 75 ml of soup B When we s...
Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times: * Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise. Constraints * 1 \leq X \leq ...
[ "from math import gcd\nX = int(input())\ng = gcd(X, 360)\nprint(360 // g)\n", "import math\nn = int(input())\nprint(int(n * 360 / math.gcd(n, 360) / n))\n", "X = int(input())\nK = 0\nwhile X * K % 360 != 0 or K == 0:\n\tK += 1\nprint(K)\n", "from math import gcd\nn = int(input())\nans = 360 // gcd(n, 360)\npr...
{"inputs": ["155", "2", "297", "408", "643", "810", "928", "1780", "33", "70", "4", "1368", "1035", "222", "12", "180", "760", "54", "690", "285", "684", "2640", "60", "1080", "107", "77", "118", "3", "71", "562", "791", "593", "1329", "578", "96", "134", "214", "34", "67", "117", "5", "389", "1504", "1162", "1369", "9...
UNKNOWN_DIFFICULTY
[]
AtCoder Grand Contest 046 - Takahashikun The Strider
atcoder
[]
[]
null
2.0 seconds
null
null
1024.0 megabytes
null
25,189
0
from math import gcd X = int(input()) g = gcd(X, 360) print(360 // g)
# Question Takahashi is standing on a two-dimensional plane, facing north. Find the minimum positive integer K such that Takahashi will be at the starting position again after he does the following action K times: * Go one meter in the direction he is facing. Then, turn X degrees counter-clockwise. Constraints * 1 ...
There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows R_{i} and a non-empty subset of columns C_{i} are chosen. For each row r in R_{i} and each column c in C_{i}, the intersection ...
[ "def main():\n\t(n, m) = list(map(int, input().split()))\n\t(aa, bb) = ([{i for (i, c) in enumerate(input()) if c == '#'} for _ in range(n)], [])\n\tfor a in aa:\n\t\tif a:\n\t\t\tfor b in bb:\n\t\t\t\tc = a & b\n\t\t\t\tif c and a != b:\n\t\t\t\t\tprint('No')\n\t\t\t\t\treturn\n\t\t\tbb.append(a)\n\tprint('Yes')\n...
{"inputs": ["5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n", "5 5\n..#..\n..#..\n#####\n..#..\n..#..\n", "5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n", "9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n", "10 10\n..........\n..........\n..........\n..........\n.#.......#\n#...
EASY
['greedy', 'implementation']
null
codeforces
['Implementation', 'Greedy algorithms']
['Greedy algorithms']
https://codeforces.com/problemset/problem/924/A
null
2019-12-31
null
null
null
25,188
0
def main(): (n, m) = list(map(int, input().split())) (aa, bb) = ([{i for (i, c) in enumerate(input()) if c == '#'} for _ in range(n)], []) for a in aa: if a: for b in bb: c = a & b if c and a != b: print('No') return bb.append(a) print('Yes') def __starting_point(): main() __starting_poi...
# Question There is a rectangular grid of n rows of m initially-white cells each. Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows R_{i} and a non-empty subset of columns C_{i} are chosen. For each row r in R_{i} and each column c in C_{i}, the i...
Number of tanka Wishing to die in the spring under the flowers This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirty-one sounds of 5, 7, 5, 7, and 7. By the way, the number 57577 c...
[ "def solve(N):\n\tk = 0\n\trng = 0\n\tfor i in range(54):\n\t\tif cl[i] < N <= cl[i + 1]:\n\t\t\tk = i + 2\n\t\t\trng2 = cl[i]\n\t\t\trng = cl[i + 1] - cl[i]\n\tposrng = (N - rng2) % (rng // 9)\n\tperrng = (N - rng2) // (rng // 9) + 1\n\tif posrng == 0:\n\t\tposrng = rng // 9\n\t\tperrng -= 1\n\tans = [perrng]\n\tf...
{"inputs": ["1\n2\n3\n390\n216\n1546\n314159265358979323\n0", "1\n2\n2\n390\n1124\n1546\n314159265358979323\n0", "1\n2\n3\n390\n216\n1546\n31125328462643205\n0", "1\n2\n2\n390\n1124\n1546\n211760204581026131\n0", "1\n2\n3\n104\n216\n1546\n31125328462643205\n0", "1\n0\n2\n390\n1124\n1546\n211760204581026131\n0", "1\n3\n...
UNKNOWN_DIFFICULTY
[]
null
aizu
[]
[]
null
8.0 seconds
null
null
268.435456 megabytes
null
25,195
0
def solve(N): k = 0 rng = 0 for i in range(54): if cl[i] < N <= cl[i + 1]: k = i + 2 rng2 = cl[i] rng = cl[i + 1] - cl[i] posrng = (N - rng2) % (rng // 9) perrng = (N - rng2) // (rng // 9) + 1 if posrng == 0: posrng = rng // 9 perrng -= 1 ans = [perrng] for i in range(k - 1): if i == k - 2: ...
# Question Number of tanka Wishing to die in the spring under the flowers This is one of the famous tanka poems that Saigyo Hoshi wrote. Tanka is a type of waka poem that has been popular in Japan for a long time, and most of it consists of five phrases and thirty-one sounds of 5, 7, 5, 7, and 7. By the way, the nu...
Given a number N. Find out the nearest number which is a perfect square and also the absolute difference between them. Example 1: Input: N = 25 Output: 25 0 Explanation: Since 25 is a perfect square, it is the closest perfect square to itself and absolute difference is 25-25=0. Example 2: Input: N = 1500 Output: 1521...
[ "class Solution:\n\n\tdef nearestPerfectSquare(self, N):\n\t\timport math\n\t\tb = int(math.sqrt(N))\n\t\ts1 = b ** 2\n\t\ts2 = (b + 1) ** 2\n\t\td1 = N - s1\n\t\td2 = s2 - N\n\t\tif d1 < d2:\n\t\t\treturn (s1, d1)\n\t\treturn (s2, d2)\n", "class Solution:\n\n\tdef nearestPerfectSquare(self, N):\n\t\ti = 1\n\t\tw...
#User function Template for python3 class Solution: def nearestPerfectSquare(self,N): #code here(return list of two numbers)
{"inputs": ["N = 25", "N = 1500"], "outputs": ["25 0", "1521 21"]}
EASY
['Algorithms', 'Numbers', 'Mathematical']
null
geeksforgeeks
['Mathematics']
[]
https://practice.geeksforgeeks.org/problems/are-you-perfect4926/1
null
null
0
null
O(sqrt(N))
25,194
0
class Solution: def nearestPerfectSquare(self, N): import math b = int(math.sqrt(N)) s1 = b ** 2 s2 = (b + 1) ** 2 d1 = N - s1 d2 = s2 - N if d1 < d2: return (s1, d1) return (s2, d2)
# Question Given a number N. Find out the nearest number which is a perfect square and also the absolute difference between them. Example 1: Input: N = 25 Output: 25 0 Explanation: Since 25 is a perfect square, it is the closest perfect square to itself and absolute difference is 25-25=0. Example 2: Input: N = 1500 ...
You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array. If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that item must be ...
[ "def complete_series(a):\n\treturn list(range(max(a) + 1)) if len(a) == len(set(a)) else [0]\n", "def complete_series(seq):\n\tfrom collections import Counter\n\tif Counter(seq).most_common()[0][1] > 1:\n\t\treturn [0]\n\treturn [i for i in range(max(seq) + 1)]\n", "def complete_series(seq):\n\treturn list(rang...
def complete_series(seq):
{"fn_name": "complete_series", "inputs": [[[0, 1]], [[1, 4, 6]], [[3, 4, 5]], [[2, 1]], [[1, 4, 4, 6]]], "outputs": [[[0, 1]], [[0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5]], [[0, 1, 2]], [[0]]]}
EASY
['Arrays', 'Fundamentals', 'Lists']
null
codewars
['Fundamentals', 'Data structures']
['Data structures']
https://www.codewars.com/kata/580a4001d6df740d61000301
null
null
null
null
null
25,196
0
def complete_series(a): return list(range(max(a) + 1)) if len(a) == len(set(a)) else [0]
# Question You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array. If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that i...
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r...
[ "import collections\n\nclass Graph:\n\n\tdef __init__(self, n, dir):\n\t\tself.node_cnt = n\n\t\tself.__directed = dir\n\t\tself.__adjList = []\n\t\tfor i in range(n):\n\t\t\tself.__adjList.append([])\n\n\tdef addEdge(self, u, v):\n\t\tself.__adjList[u].append(v)\n\t\tif not self.__directed:\n\t\t\tself.__adjList[v...
{"inputs": ["6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n", "2 2 1\n2 1\n1 2\n", "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\...
HARD
['trees', 'dfs and similar', 'dp', 'divide and conquer']
null
codeforces
['Tree algorithms', 'Dynamic programming', 'Graph traversal', 'Divide and conquer']
['Dynamic programming']
https://codeforces.com/problemset/problem/337/D
null
2019-12-31
null
null
null
25,198
0
import collections class Graph: def __init__(self, n, dir): self.node_cnt = n self.__directed = dir self.__adjList = [] for i in range(n): self.__adjList.append([]) def addEdge(self, u, v): self.__adjList[u].append(v) if not self.__directed: self.__adjList[v].append(u) def getDistances(self, st...
# Question Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is p...