source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/modified-numbers-and-queries0904/1 | Solve the following coding problem using the programming language python:
Find the sum of all the numbers between the range l and r. Here each number is represented by the sum of its distinct prime factors.
Note: For example, 6 is represented by 5 because 6 has two prime factors 2 and 3 and 2 + 3 = 5.
Example 1:
Inpu... | ```python
class Solution:
ans = 0
def sumOfAll(self, l, r):
sum1 = 0
ans = 0
for i in range(l, r + 1):
n = i
factors = []
d = 2
while d * d <= n:
while n % d == 0:
factors.append(d)
n //= d
d += 1
if n > 1:
factors.append(n)
self.ans += sum([*set(factors)])
return self... | vfc_141018 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/modified-numbers-and-queries0904/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "l = 1, r = 2",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "l = 1, r = 6",
"output": "17",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/move-the-coins/problem | Solve the following coding problem using the programming language python:
Alice and Bob are playing a game, defined below:
There is an undirected tree graph with $n$ nodes that has the following properties:
Each node has $c_i$ golden coins.
Node $\mbox{1}$ is root of the tree.
The parent node of some node $\mbox{u... | ```python
from collections import deque
n = int(input())
G = [[int(c), 0, []] for c in input().strip().split()]
G[0][2].append(0)
parity = [True for i in range(n)]
order = [[-1, -1] for i in range(n)]
for i in range(n - 1):
(v1, v2) = (int(v) - 1 for v in input().strip().split())
G[v1][2].append(v2)
G[v2][2].append(... | vfc_141019 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/move-the-coins/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n0 2 2 1 3 2\n1 2\n1 3\n3 4\n3 5\n4 6\n3\n6 2\n4 1\n3 6\n",
"output": "NO\nYES\nINVALID\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/the-strange-function/problem | Solve the following coding problem using the programming language python:
One of the most important skills a programmer needs to learn early on is the ability to pose a problem in an abstract way. This skill is important not just for researchers but also in applied fields like software engineering and web development.... | ```python
from math import gcd
def parseInput(f):
return [f(x) for x in input().split()]
n = int(input())
array = parseInput(int)
stack = []
answer = float('-inf')
for number in array:
for i in range(len(stack)):
stack[i][0] = gcd(abs(stack[i][0]), abs(number))
stack[i][1] += number
if number > stack[i][2]:
... | vfc_141023 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/the-strange-function/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n10 -5 5 20\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n7 12 24 6 5\n",
"output": "144\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/549/H | Solve the following coding problem using the programming language python:
The determinant of a matrix 2 × 2 is defined as follows:$\operatorname{det} \left(\begin{array}{ll}{a} & {b} \\{c} & {d} \end{array} \right) = a d - b c$
A matrix is called degenerate if its determinant is equal to zero.
The norm ||A|| of a m... | ```python
from decimal import *
getcontext().prec = 50
(a, b) = list(map(int, input().split()))
(c, d) = list(map(int, input().split()))
answer = None
for k in range(1 << 4):
le = Decimal(0)
rg = Decimal(10 ** 11)
def f(t):
fi = a
if k & 1:
fi += t
else:
fi -= t
fi *= d + t if k & 1 << 1 else d - t
... | vfc_141027 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/549/H",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n3 4\n",
"output": "0.2000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 0\n0 1\n",
"output": "0.5000000000\n",
"type": "stdin_stdout"
},
{
"fn_name... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/boundary-elements-of-matrix1102/1 | Solve the following coding problem using the programming language python:
Given an nxn matrix .In the given matrix, you have to find the boundary elements of the matrix.
Example 1:
Input: [[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
Output: 1 2 3 4 6 7 8 9
Example 2:
Input: [[1, 2]
[3, 4]]
Output: 1 2 3... | ```python
class Solution:
def BoundaryElements(self, m):
l = []
a = len(m)
b = len(m[0])
for i in range(a):
for j in range(b):
if i == 0 or i == a - 1:
l.append(m[i][j])
elif j == 0 or j == b - 1:
l.append(m[i][j])
return l
``` | vfc_141032 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/boundary-elements-of-matrix1102/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "[[1, 2, 3] \r\n [4, 5, 6] \r\n [7, 8, 9]]",
"output": "1 2 3 4 6 7 8 9",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "[[1, 2]\r\n [3, 4]]",
"output": "1 2 3 4",
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A binary search tree can be unbalanced depending on features of data. For example, if we insert $n$ elements into a binary search tree in ascending order, the tree become a list, leading to long search times. One of strategies is to randomly shu... | ```python
from random import random
from collections import deque
from copy import deepcopy
import sys
input = sys.stdin.readline
class Treap:
def __init__(self, iterable=None):
self.root = None
if iterable:
self._construct(iterable)
def _construct(self, iterable):
for it in iterable:
self.insert(it)
... | vfc_141037 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "16\ninsert 35 99\ninsert 3 80\ninsert 1 53\ninsert 14 25\ninsert 80 76\ninsert 42 3\ninsert 102 47\ninsert 21 12\ninsert 7 10\ninsert 6 90\nprint\nfind 21\nfind 22\ndelete 35\ndelete 99\nprint",
"output": " 1 3 6 7 14 21 35 4... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/days-of-our-lives3300/1 | Solve the following coding problem using the programming language python:
Given a month with arbitrary number of days, N, and an integer K representing the day with which it starts. ie- 1 for Monday, 2 for Tuesday and so on. Find the number of times each day (Monday, Tuesday, ..., Sunday) appears in the month.
Exa... | ```python
class Solution:
def daysOfWeeks(self, N, K):
v = [N // 7, N // 7, N // 7, N // 7, N // 7, N // 7, N // 7]
N = N % 7
i = 0
while N:
a = (K - 1 + i) % 7
v[a] += 1
i += 1
N -= 1
return v
``` | vfc_141041 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/days-of-our-lives3300/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 31 , K = 1",
"output": "5 5 5 4 4 4 4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 28, K = 5",
"output": "5 5 5 4 4 4 4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1199/C | Solve the following coding problem using the programming language python:
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If th... | ```python
from collections import *
from math import *
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = Counter(a)
a.sort()
val = [0 for i in range(400005)]
a = list(set(a))
a.sort()
n1 = len(a)
val[0] = d[a[0]]
for i in range(1, n1):
val[i] = val[i - 1] + d[a[i]]
m = n1
for m in range(n1, 0,... | vfc_141047 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1199/C",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n2 2 2 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 5011007... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Printf{}, Pappu Bhujia, mon_ki_onkh are playing Counter Strike 1.6 . Printf{} and Pappu Bhujia are in the same team (Counter Terrorists) and mon_ki_onkh is in the opposite team (Terrorists). It is a 2 on 1 round. The players playing have enough ... | ```python
def ans(n):
i= 2
xor = 0
check=0
while(i**2<=n):
if n%i==0:
check+=1
count=0
while(n%i==0):
n/=i
count+=1
if check==1:
xor = count
else:
xor ^= count
i+=1
if n > 1:
xor^=1
return xor
def primeFactorisation(n):
primeFactors = []
i= 2
while(i**2<=n):
if n%i==0:
... | vfc_141051 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\n379021\n495229\n957265\n705005\n696225\n884161\n695189\n950999\n234481\n281555\n413827\n888162\n131913\n913010\n97587\n160374\n519461\n886906\n464051\n356105\n762361\n140113\n723801\n500701\n415466\n226273\n432648\n215851\n558... | |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/13eb74f1c80bc67d526a69b8276f6cad1b8c3401/1 | Solve the following coding problem using the programming language python:
A special compression mechanism can arbitrarily delete 0 or more characters and replace them with the deleted character count.
Given two strings, S and T where S is a normal string and T is a compressed string, determine if the compressed string... | ```python
class Solution:
def checkCompressed(self, S, T):
c = 0
j = 0
k = 0
for i in range(len(T)):
if ord('0') <= ord(T[i]) <= ord('9'):
c = c * 10 + int(T[i])
else:
j = j + c
c = 0
if j >= len(S):
return 0
if S[j] != T[i]:
return 0
j += 1
j = j + c
if j != len(S)... | vfc_141055 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/13eb74f1c80bc67d526a69b8276f6cad1b8c3401/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"GEEKSFORGEEKS\"\r\nT = \"G7G3S\"",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/reverse-each-word-in-a-given-string1001/1 | Solve the following coding problem using the programming language python:
Given a String. Reverse each word in it where the words are separated by dots.
Example 1:
Input:
S = "i.like.this.program.very.much"
Output:
i.ekil.siht.margorp.yrev.hcum
Explanation:
The words are reversed as
follows:"i" -> "i","like"->"ekil"... | ```python
class Solution:
def reverseWords(self, s):
mm = s.split('.')
list1 = [i[::-1] for i in mm]
return '.'.join(list1)
``` | vfc_141056 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/reverse-each-word-in-a-given-string1001/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"i.like.this.program.very.much\"",
"output": "i.ekil.siht.margorp.yrev.hcum",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"pqr.mno\"",
"output": "rqp.onm",
"type": "s... |
taco | verifiable_code | https://www.hackerrank.com/challenges/py-the-captains-room/problem | Solve the following coding problem using the programming language python:
Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms.
One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families c... | ```python
from collections import Counter
K = int(input())
rooms = list(map(int, input().split()))
roomsspec = Counter(rooms)
cap = [elem for elem in roomsspec if roomsspec[elem] != K]
print(cap[0])
``` | vfc_141057 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/py-the-captains-room/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2 \n",
"output": "8\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given t... | ```python
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve(t):
(N, T, K) = map(int, readline().split())
if N == T == K == 0:
return False
G = [[] for i in range(N)]
E = []
res = 0
for i in range(N - 1):
(a, b, c) = map(int, readline().split())
res += c
E.append((c, a - 1, b - 1... | vfc_141065 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "10.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 2 0\n1 2 1\n1\n2\n4 3 2\n1 2 1\n1 3 2\n1 4 3\n2\n3\n4\n0 0 0",
"output": "Case 1: 0\nCase 2: 3\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/BATTERYLOW | Solve the following coding problem using the programming language python:
Chef's phone shows a Battery Low notification if the battery level is 15 \% or less.
Given that the battery level of Chef's phone is X \%, determine whether it would show a Battery low notification.
------ Input Format ------
- First line w... | ```python
t = int(input())
for i in range(t):
a = int(input())
if a <= 15:
print('Yes')
else:
print('No')
``` | vfc_141069 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BATTERYLOW",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n15\n3\n65",
"output": "Yes\nYes\nNo",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/incomplete-array3859/1 | Solve the following coding problem using the programming language python:
Given an array A containing N integers.Find out how many elements should be added such that all elements between the maximum and minimum of the array is present in the array.
Example 1:
Input:
N=5
A=[205,173,102,324,957]
Output:
851
Explanation:... | ```python
class Solution:
def countElements(self, N, A):
A.sort()
ma = A[N - 1]
mi = A[0]
sum = 0
for i in range(N - 1):
if A[i + 1] == A[i] + 1:
continue
if A[i] == A[i + 1]:
continue
sum = sum + A[i + 1] - A[i] - 1
return sum
``` | vfc_141073 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/incomplete-array3859/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N=5\nA=[205,173,102,324,957]",
"output": "851",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/114/D | Solve the following coding problem using the programming language python:
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with ... | ```python
from functools import cmp_to_key
def calc_lcp(s, sa):
rank = [0 for _ in range(len(s))]
for i in range(len(s)):
rank[sa[i]] = i
lcp = [0 for _ in range(len(s) - 1)]
h = 0
for i in range(len(s)):
if rank[i] < len(s) - 1:
while max(i, sa[rank[i] + 1]) + h < len(s) and s[i + h] == s[sa[rank[i] + 1] ... | vfc_141078 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/114/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "abcdefghijklmnopqrstuvwxyz\nabc\nxyz\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "fcgbeabagggfdbacgcaagfbdddefdbcfccfacfffebdgececdabfceadecbgdgdbdadcgfbbaaabcccdefabdf... |
taco | verifiable_code | https://www.hackerrank.com/challenges/newyear-present/problem | Solve the following coding problem using the programming language python:
Nina received an odd New Year's present from a student: a set of $n$ unbreakable sticks. Each stick has a length, $\boldsymbol{l}$, and the length of the $i^{\mbox{th}}$ stick is $\boldsymbol{l_{i-1}}$. Deciding to turn the gift into a lesson, N... | ```python
import math
import os
import random
import re
import sys
import collections
def choose(n, k):
if k > n:
return 0
k = min(k, n - k)
(num, den) = (1, 1)
for i in range(k):
num *= n - i
den *= i + 1
return num // den
def squareCount(l):
counter = collections.Counter(l)
l = tuple(counter.keys())
c... | vfc_141082 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/newyear-present/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n4 5 1 5 1 9 4 5 \n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n1 2 3 4 5 6 \n",
"output": "0 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Example
Input
4
5
8
58
85
Output
2970.000000000
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from itertools import permutations
from math import acos, sin, cos, pi
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
R = [int(readline()) for i in range(N)]
R.sort(reverse=1)
ans = 0
for l in range(3, N + 1):
for rs in permutations(R[:l]):
C = [r... | vfc_141086 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n5\n8\n58\n152",
"output": "5181.000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n5\n8\n55\n152",
"output": "4945.500000000000000\n",
"type": "stdin_stdout"... | |
taco | verifiable_code | Solve the following coding problem using the programming language python:
I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After le... | ```python
from math import atan2, degrees
def calc(dx, dy, d, w, a):
if dx ** 2 + dy ** 2 > a ** 2:
return 0
t = degrees(atan2(dy, dx))
for i in range(2):
if w - d / 2 <= t + 360 * i <= w + d / 2:
return 1
return 0
while 1:
(H, R) = map(int, input().split())
if H == R == 0:
break
HS = [list(map(int, in... | vfc_141090 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"output": "6\nNA\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/INVLIS | Solve the following coding problem using the programming language python:
Petya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,…,an$a_1, \ldots, a_n$ such that every nu... | ```python
for _ in range(int(input())):
(n, k) = [int(c) for c in input().split()]
a = [int(c) for c in input().split()]
ls = a
if n == 1:
print('YES')
print(1)
continue
if k == 1:
print('NO')
continue
if k == 2 and n > 2:
if ls[0] != ls[1] - 1:
print('NO')
continue
ans = [0 for i in range(n + ... | vfc_141099 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/INVLIS",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n3 2\n1 2\n2 1\n1\n",
"output": "YES\n2 3 1\nNO\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1198/A | Solve the following coding problem using the programming language python:
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of $n$ non-negative integers.
If ... | ```python
from collections import *
from math import *
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = Counter(a)
a.sort()
val = [0 for i in range(400005)]
a = list(set(a))
a.sort()
n1 = len(a)
val[0] = d[a[0]]
for i in range(1, n1):
val[i] = val[i - 1] + d[a[i]]
m = n1
for m in range(n1, 0,... | vfc_141103 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1198/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n2 1 2 3 4 3\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1585/D | Solve the following coding problem using the programming language python:
Petya has an array of integers $a_1, a_2, \ldots, a_n$. He only likes sorted arrays. Unfortunately, the given array could be arbitrary, so Petya wants to sort it.
Petya likes to challenge himself, so he wants to sort array using only $3$-cycles... | ```python
def is_even_perm(a):
count = 0
for i in range(len(a)):
while a[i] != i + 1:
j = a[i] - 1
(a[i], a[j]) = (a[j], a[i])
count += 1
return count % 2 == 0
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
if n == 1 or len(a) > len(set(a)):
print('YES')
... | vfc_141107 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1585/D",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1\n1\n2\n2 2\n2\n2 1\n3\n1 2 3\n3\n2 1 3\n3\n3 1 2\n4\n2 1 4 3\n",
"output": "YES\nYES\nNO\nYES\nNO\nYES\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/EOOPR | Solve the following coding problem using the programming language python:
“I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!”
Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and... | ```python
t = int(input())
for _ in range(t):
(x, y) = map(int, input().split())
if y > x:
if (y - x) % 2 != 0:
print(1)
elif (y - x) // 2 % 2 != 0:
print(2)
else:
print(3)
elif x == y:
print(0)
elif (x - y) % 2 == 0:
print(1)
else:
print(2)
``` | vfc_141111 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/EOOPR",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n0 5\n4 -5\n0 10000001\n",
"output": "1\n2\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/817/A | Solve the following coding problem using the programming language python:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values x... | ```python
from __future__ import division, print_function
MOD = 998244353
mod = 10 ** 9 + 7
def prepare_factorial():
fact = [1]
for i in range(1, 100005):
fact.append(fact[-1] * i % mod)
ifact = [0] * 100005
ifact[100004] = pow(fact[100004], mod - 2, mod)
for i in range(100004, 0, -1):
ifact[i - 1] = i * ifac... | vfc_141115 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/817/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "0 0 0 6\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 1 3 6\n1 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/simple-interest3457/1 | Solve the following coding problem using the programming language python:
Given three integers P,R and T, denoting Principal, Rate of Interest and Time period respectively.Compute the simple Interest.
Example 1:
Input:
P=100
R=20
T=2
Output:
40.00
Explanation:
The simple interest on 100 at a rate
of 20% across 2 time ... | ```python
class Solution:
def simpleInterest(self, A, B, C):
return A * B * C / 100
``` | vfc_141120 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/simple-interest3457/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "P=100\r\nR=20\r\nT=2",
"output": "40.00",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "P=999\r\nR=9\r\nT=9",
"output": "809.19",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/574/C | Solve the following coding problem using the programming language python:
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars.
Each play... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
for i in range(n):
while arr[i] % 2 == 0:
arr[i] /= 2
while arr[i] % 3 == 0:
arr[i] /= 3
print('Yes' if all((arr[0] == arr[i] for i in range(n))) else 'No')
``` | vfc_141122 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/574/C",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n49 42\n",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612... |
taco | verifiable_code | https://codeforces.com/problemset/problem/409/E | Solve the following coding problem using the programming language python:
$\text{A}$
-----Input-----
The input contains a single floating-point number x with exactly 6 decimal places (0 < x < 5).
-----Output-----
Output two integers separated by a single space. Each integer should be between 1 and 10, inclusive... | ```python
from math import sqrt
eps = 1e-05
def check(a, h, x):
return abs(x * sqrt(4 * h * h + a * a) - a * h) < eps
def main():
x = float(input())
for a in range(1, 11):
for h in range(1, 11):
if check(a, h, x):
print(a, h)
return
main()
``` | vfc_141126 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/409/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1.200000\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2.572479\n",
"output": "10 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible.
INPUT
First l... | ```python
T = int(input())
def isPal(pal):
for i in range(len(pal)-1):
temp = pal[i:len(pal)]
if(temp == temp[::-1]):
return i
return -1
for i in range(T):
pal = input()
index = isPal(pal)
if(index == -1):
print(len(pal)+len(pal)-1)
else:
print(len(pal)+index)
``` | vfc_141130 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii",
"output": "38\n51\n9\n1\n77\n95",
... | |
taco | verifiable_code | https://www.codechef.com/problems/AMMEAT | Solve the following coding problem using the programming language python:
Andrew likes meatballs very much.
He has N plates of meatballs, here the i^{th} plate contains P_{i} meatballs. You need to find the minimal number of plates Andrew needs to take to his trip to Las Vegas, if he wants to eat there at least M meat... | ```python
import math as ma
for _ in range(int(input())):
(n, m) = map(int, input().split())
l = list(map(int, input().split()))
s = sum(l)
l.sort()
k = -1
while s >= m:
l.pop(0)
s = sum(l)
k += 1
if n - k > n:
print('-1')
else:
print(n - k)
``` | vfc_141134 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/AMMEAT",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n4 7\n1 2 3 4",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/java-delete-alternate-characters4036/1 | Solve the following coding problem using the programming language python:
Given a string S as input. Delete the characters at odd indices of the string.
Example 1:
Input: S = "Geeks"
Output: "Ges"
Explanation: Deleted "e" at index 1
and "k" at index 3.
Example 2:
Input: S = "GeeksforGeeks"
Output: "GesoGes"
Explanati... | ```python
class Solution:
def delAlternate(ob, S):
return S[::2]
``` | vfc_141138 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/java-delete-alternate-characters4036/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"Geeks\"",
"output": "\"Ges\"",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"GeeksforGeeks\"",
"output": "\"GesoGes\"",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/955/B | Solve the following coding problem using the programming language python:
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to... | ```python
s = input()
cnt = [0 for i in range(26)]
for el in s:
cnt[ord(el) - ord('a')] += 1
tps = 0
nos = 0
for i in range(26):
if cnt[i] > 0:
tps += 1
if cnt[i] > 1:
nos += 1
def f():
if tps > 4:
return False
if tps < 2:
return False
if tps == 2:
if nos < 2:
return False
return True
if tps == 3... | vfc_141139 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/955/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ababa\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "zzcxx\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/2ac2f925b836b0625d848a0539ffd3d2d2995f92/1 | Solve the following coding problem using the programming language python:
Given a string S containing lowercase english alphabet characters. The task is to calculate the number of distinct strings that can be obtained after performing exactly one swap.
In one swap,Geek can pick two distinct index i and j (i.e 1 < i < ... | ```python
class Solution:
def countStrings(self, S):
ans = 0
dict = {}
n = len(S)
any = 0
for i in range(n):
if not S[i] in dict:
dict[S[i]] = 1
ans += i
else:
any = 1
ans += i - dict[S[i]]
dict[S[i]] += 1
return ans + any
``` | vfc_141143 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/2ac2f925b836b0625d848a0539ffd3d2d2995f92/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"geek\"",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"ab\"",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/divisor-product2236/1 | Solve the following coding problem using the programming language python:
Given a number N, find the product of all the divisors of N (including N).
Example 1:
Input :
N = 6
Output:
36
Explanation:
Divisors of 6 : 1, 2, 3, 6
Product = 1*2*3*6 = 36
Example 2:
Input :
N = 5
Output:
5
Explanation:
Divisors of 5 : 1,... | ```python
class Solution:
def divisorProduct(self, N):
mod = 10 ** 9 + 7
ans = 1
for i in range(1, int(math.sqrt(N)) + 1):
if N % i == 0:
if N // i == i:
ans = ans * i % mod
else:
ans = ans * i % mod
ans = ans * N // i % mod
return ans
``` | vfc_141144 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/divisor-product2236/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 6",
"output": "36",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5",
"output": "5",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1491/B | Solve the following coding problem using the programming language python:
There is a graph of $n$ rows and $10^6 + 2$ columns, where rows are numbered from $1$ to $n$ and columns from $0$ to $10^6 + 1$:
Let's denote the node in the row $i$ and column $j$ by $(i, j)$.
Initially for each $i$ the $i$-th row has exactly... | ```python
for _ in range(int(input())):
(n, u, v) = map(int, input().split())
obstacle = list(map(int, input().split()))
cost = 0
diff = 0
for i in range(n - 1):
if abs(obstacle[i + 1] - obstacle[i]) > diff:
diff = abs(obstacle[i + 1] - obstacle[i])
if diff == 0:
print(min(2 * v, u + v))
elif diff == 1:
... | vfc_141146 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1491/B",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2\n",
"output": "7\n3\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 100 2\n1000000 1000000\n",
"output": "4\n",
"type": "stdin_std... |
taco | verifiable_code | https://codeforces.com/problemset/problem/292/A | Solve the following coding problem using the programming language python:
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC.
For that, he asked to give hi... | ```python
n = int(input())
l = []
for i in range(n):
(c, t) = map(int, input().split())
l.append((c, t))
queue = l[0][1]
z = queue
for i in range(1, n):
queue = queue - min(l[i][0] - l[i - 1][0], queue)
queue = queue + l[i][1]
z = max(z, queue)
print(l[-1][0] + queue, z)
``` | vfc_141150 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/292/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n2 1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1000000 10\n",
"output": "1000010 10\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1038/B | Solve the following coding problem using the programming language python:
Find out if it is possible to partition the first $n$ positive integers into two non-empty disjoint sets $S_1$ and $S_2$ such that:$\mathrm{gcd}(\mathrm{sum}(S_1), \mathrm{sum}(S_2)) > 1$
Here $\mathrm{sum}(S)$ denotes the sum of all elements ... | ```python
n = int(input())
if n == 1 or n == 2:
print('No')
else:
print('Yes')
print(n // 2, end=' ')
for i in range(2, n + 1, 2):
print(i, end=' ')
print()
print(n - n // 2, end=' ')
for i in range(1, n + 1, 2):
print(i, end=' ')
``` | vfc_141158 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1038/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "No",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n",
"output": "Yes\n1 2\n2 1 3 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
taco | verifiable_code | https://codeforces.com/problemset/problem/400/A | Solve the following coding problem using the programming language python:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game ... | ```python
from functools import reduce
def sol(l):
if not 'X' in l:
return '0'
l = l.replace('O', '0').replace('X', '1')
res = ['%ix%i' % (12 // i, i) for i in (12, 6, 4, 3, 2, 1) if reduce(lambda x, y: x & y, [int(l[i * j:i * j + i], 2) for j in range(12 // i)], -1)]
return '%i %s' % (len(res), ' '.join(res))
n... | vfc_141162 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/400/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/ALETHIO | Solve the following coding problem using the programming language python:
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia"... | ```python
str = input()
l = len(str)
p = 1
maxm = 0
for i in range(0, l):
ans2 = ''
ans1 = ''
if ord(str[i]) >= 65 and ord(str[i]) <= 90:
p = 0
j = i - 1
while True:
if j >= 0:
if ord(str[j]) >= 65 and ord(str[j]) <= 90:
break
else:
ans1 = ans1 + str[j]
j = j - 1
else:
break
... | vfc_141166 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/ALETHIO",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "06454\nInput2:\nC0D3C43F\n",
"output": "6454\nOutput2:\n3943\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/PBK12020/problems/ITGUY18 | Solve the following coding problem using the programming language python:
The chef is placing the laddus on the large square plat. The plat has the side of length N. Each laddu takes unit sq.unit area. Cheffina comes and asks the chef one puzzle to the chef as, how many squares can be formed in this pattern with all s... | ```python
t = int(input())
while t:
m = int(input())
print(int(m * (m + 1) * (2 * m + 1) / 6))
t -= 1
``` | vfc_141170 | {
"difficulty": "unknown_difficulty",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/PBK12020/problems/ITGUY18",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1\n2\n",
"output": "1\n5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/903/D | Solve the following coding problem using the programming language python:
Let's denote a function
$d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$
You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_... | ```python
from collections import defaultdict
n = int(input())
a = map(int, input().split())
m = defaultdict(lambda : 0)
(ans, total) = (0, 0)
for (i, num) in enumerate(a):
ans -= total
ans += i * num
ans -= m[num - 1]
ans += m[num + 1]
m[num] += 1
total += num
print(ans)
``` | vfc_141174 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/903/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n6 6 5 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/-matchsticks-game4906/1 | Solve the following coding problem using the programming language python:
Two friends, A and B, are playing the game of matchsticks. In this game, a group of N matchsticks is placed on the table. The players can pick any number of matchsticks from 1 to 4 (both inclusive) during their chance. The player who takes the l... | ```python
class Solution:
def matchGame(self, n):
if n % 5 == 0:
return -1
else:
return n % 5
``` | vfc_141180 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/-matchsticks-game4906/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 48",
"output": "3",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-unset-bits-in-a-given-range1216/1 | Solve the following coding problem using the programming language python:
Given a non-negative number n and two values l and r. The problem is to count the number of unset bits in the range l to r in the binary representation of n, i.e. to count unset bits from the rightmost lth bit to the rightmost rth bit.
Example... | ```python
class Solution:
def countUnsetBits(self, n, l, r):
binary = bin(n).replace('0b', '')[::-1]
ans = binary[l - 1:r].count('0')
return ans
``` | vfc_141181 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-unset-bits-in-a-given-range1216/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 42, l = 2, r = 5",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 80, l = 1, r = 4",
"output": "4",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Grey Worm has learnt that Daario Naharis's Second Sons have combined with his Unsullied to improve Daenerys's strength. The combined army is standing in a big line. You are given information of their arrangement by a string s. The string s consi... | ```python
noOfTestCases = int(input())
def isPossible(string):
countOfU = 0
countOfS = 0
for s in string:
if(s == 'S'):
countOfS += 1
else:
countOfU += 1
if(countOfS > countOfU + 1 or countOfU > countOfS + 1):
return -1
firstStringToCompare = ""
secondStringToCompare = ""
for i in range(... | vfc_141182 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "100\nUUUUSUSUUUSSUSUUSUSSSUUUUUSUUUUSSSUUUUSSSSSSSSSSS\nSSUSUUUUSSUSUUUSSUUUSUUUUSSUSSSSUUSSSS\nSSUUSSUUUUUUSUSUSUSUSSSSSSSUSUUSUSUUUUSSSUSSSSUSSUSSUSSSUSUUUUUSUUUSSUUSUUS\nUS\nUUSUUSUUUSSSUUSSUUUUUUSUSUUUUUUSUUSSSSSSSSSSSSS\nSUUUU... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/triplets/problem | Solve the following coding problem using the programming language python:
There is an integer array $\boldsymbol{d}$ which does not contain more than two elements of the same value. How many distinct ascending triples ($d[i]<d[j]<d[k],i<j<k$) are present?
Input format
The first line contains an integer, $N$, denot... | ```python
root = 1
last_level = 262144
tree_1 = [0 for i in range(last_level * 2 + 1)]
tree_2 = [0 for i in range(last_level * 2 + 1)]
tri = [0 for i in range(100048)]
def less_than(x, tab):
index = root
sum = 0
c_level = last_level
while index < x + last_level:
if x < c_level // 2:
index *= 2
else:
inde... | vfc_141186 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/triplets/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n1 1 2 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/158/D | Solve the following coding problem using the programming language python:
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculpt... | ```python
n = int(input())
s = list(map(int, input().split()))
max = 0
for i in range(n):
max += s[i]
for i in range(2, n):
if n % i == 0 and n // i >= 3:
for j in range(i):
sum = 0
x = j
while x < n:
sum += s[x]
x += i
if sum > max:
max = sum
print(max)
``` | vfc_141195 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/158/D",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12\n1 1 1 1 1 1 1 -1000 1 1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "13\n6 7 8 2 5 1 -9 -6 9 10 8 9 -8\n",
"output": "42\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
DM of Bareilly wants to make Bareilly a smart city. So, one point amongst his management points is to arrange shops. He starts by arranging the bakery shops linearly, each at a unit distance apart and assigns them a number depending on its owne... | ```python
'''
# 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!'
t=eval(input())
while t>0:
t-=1
n=eval(input())
s=input()
m=[]
for i in range(n-1):
d=1
for j in range(i+1,n):
if s[i]==s[j]:
m.append(d)... | vfc_141199 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n12345\n5\n12321\n7\n1234514",
"output": "-1\n2\n3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n11\n15879142531\n15\n158754597589217\n5\n11111\n9\n989819898",
"output": "3\n... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/327/A | Solve the following coding problem using the programming language python:
Iahub got bored, so he invented a game to be played on paper.
He writes n integers a_1, a_2, ..., a_{n}. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips... | ```python
def main():
n = int(input())
arr = list(map(int, input().split()))
count = 0
for i in range(n):
k = arr.count(1)
for j in arr[i:]:
if j == 1:
k -= 1
else:
k += 1
count = max(count, k)
return count
print(main())
``` | vfc_141203 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/327/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 0 0 1 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 0 0 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/5bfe93cc7f5a214bc6342709c78bc3dceba0f1c1/1 | Solve the following coding problem using the programming language python:
There are N bowls containing cookies. In one operation, you can take one cookie from any of the non-empty bowls and put it into another bowl. If the bowl becomes empty you discard it. You can perform the above operation any number of times. You ... | ```python
from typing import List
class Solution:
def getMaximum(self, N: int, arr: List[int]) -> int:
sum = 0
for i in arr:
sum = sum + i
for i in range(N, 0, -1):
if sum % i == 0:
return i
``` | vfc_141212 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/5bfe93cc7f5a214bc6342709c78bc3dceba0f1c1/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 3\narr[] = {3, 1, 5}",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 4\narr[] = {1, 2, 6, 5}",
"output": "2",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/122/B | Solve the following coding problem using the programming language python:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
One day Petya was deliver... | ```python
s = input()
s = s.strip('0')
four = s.count('4')
seven = s.count('7')
if '4' not in s and '7' not in s:
print(-1)
elif four >= seven:
print('4')
else:
print('7')
``` | vfc_141214 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/122/B",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "94894948577777777884888\n",
"output": "7\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1092/B | Solve the following coding problem using the programming language python:
There are $n$ students in a university. The number of students is even. The $i$-th student has programming skill equal to $a_i$.
The coach wants to form $\frac{n}{2}$ teams. Each team should consist of exactly two students, and each student sh... | ```python
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
c = 0
for i in range(1, n, 2):
c += l[i] - l[i - 1]
print(c)
``` | vfc_141222 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1092/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n5 10 2 3 14 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 100\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1070/A | Solve the following coding problem using the programming language python:
You are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s.
Input
The first line contains two positive integers d and s (1 ≤ d ≤ 500, 1 ≤ s ≤ 5000) separated by space.
... | ```python
import os
import sys
from io import BytesIO, IOBase
_print = print
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 e... | vfc_141226 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1070/A",
"time_limit": "3.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 5000\n",
"output": "69999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1147/B | Solve the following coding problem using the programming language python:
Inaka has a disc, the circumference of which is $n$ units. The circumference is equally divided by $n$ points numbered clockwise from $1$ to $n$, such that points $i$ and $i + 1$ ($1 \leq i < n$) are adjacent, and so are points $n$ and $1$.
The... | ```python
def check(k, g):
for i in g:
a = (i[0] + k) % n
b = (i[1] + k) % n
if not (min(a, b), max(a, b)) in g:
return False
return True
(n, m) = [int(i) for i in input().split()]
g = set()
for i in range(m):
(a, b) = [int(i) for i in input().split()]
a -= 1
b -= 1
g.add((min(a, b), max(a, b)))
for i in... | vfc_141230 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1147/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12 6\n1 3\n3 7\n5 7\n7 11\n9 11\n11 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9 6\n4 5\n5 6\n7 8\n8 9\n1 2\n2 3\n",
"output": "Yes\n",
"type": "stdin... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/count-the-reversals0401/1 | Solve the following coding problem using the programming language python:
Given a string S consisting of only opening and closing curly brackets '{' and '}', find out the minimum number of reversals required to convert the string into a balanced expression.
A reversal means changing '{' to '}' or vice-versa.
Example 1... | ```python
def countRev(s):
stack = []
n = len(s)
for i in range(n):
if s[i] == '{':
stack.append('{')
elif len(stack) == 0 or stack[-1] == '}':
stack.append('}')
else:
stack.pop()
t1 = 0
for i in stack:
if i == '}':
t1 += 1
else:
break
t2 = len(stack) - t1
if (t1 + t2) % 2 == 0:
if t1 ... | vfc_141234 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/count-the-reversals0401/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": "countRev",
"input": "S = \"}{{}}{{{\"",
"output": "3",
"type": "function_call"
},
{
"fn_name": "countRev",
"input": "S = \"{{}{{{}{{}}{{\"",
"output": "-1",
"type": "function_call"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/HMAPPY | Solve the following coding problem using the programming language python:
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
Appy loves balloons! She wants you to give her balloons on each of $N$ consecutive days (numbered $1$ through $N$); let's denote the number o... | ```python
(N, M) = input().split()
(N, M) = (int(N), int(M))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
low = 0
high = A[0] * B[0]
for day in range(1, N):
high = max(high, A[day] * B[day])
while low < high:
mid = (low + high) // 2
bal = 0
for day in range(N):
if B[day] != 0:
bal +=... | vfc_141235 | {
"difficulty": "medium_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/HMAPPY",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3 \n1 2 3 4 5\n1 2 3 4 5",
"output": "15",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/FRCTNS | Solve the following coding problem using the programming language python:
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
For positive integers $a$ and $b$, we say that a fraction $\frac{a}{b}$ is *good* if it is equal to $\frac{m}{m+1}$ for some positive intege... | ```python
import math
import sys
import random
import array as arr
import numpy as np
from sys import stdin, stdout
from collections import OrderedDict
from collections import defaultdict
from collections import deque
import heapq as hq
def get_input():
return list(map(int, input().split()))
def single_input():
ret... | vfc_141239 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/FRCTNS",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5",
"output": "8",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/496/B | Solve the following coding problem using the programming language python:
You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9... | ```python
from itertools import chain
C = 0
def main():
input()
ls = list(map(int, input()))
n = len(ls)
a = ls[-1]
for (stop, b) in enumerate(ls):
if b != a:
break
else:
print('0' * n)
return
ls = ls[stop:] + ls[:stop]
(a, l) = (ls[0], [])
start = ma = tail = 0
for (stop, b) in enumerate(ls):
if ... | vfc_141243 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/496/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n579\n",
"output": "024\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n2014\n",
"output": "0142\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/find-nk-th-node-in-linked-list/1 | Solve the following coding problem using the programming language python:
Given a singly linked list and a number k. Write a function to find the (N/k)^{th} element, where N is the number of elements in the list. We need to consider ceil value in case of decimals.
Input:
The first line of input contains an integer T d... | ```python
def fractionalNodes(head, k):
last = head
count = 0
while last and last.next:
count += 1
last = last.next
curr = head
ind = count // k
for i in range(ind):
head = head.next
return head
``` | vfc_141247 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/find-nk-th-node-in-linked-list/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\r\n\r\n6\r\n\r\n1 2 3 4 5 6\r\n\r\n2\r\n\r\n5\r\n\r\n2 7 9 3 5\r\n\r\n3",
"output": "3\r\n\r\n7",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/recursive-sequence1611/1 | Solve the following coding problem using the programming language python:
A function f is defined as follows F(N)= (1) +(2*3) + (4*5*6) ... N. Given an integer N the task is to print the F(N)th term.
Example 1:
Input: N = 5
Output: 365527
Explaination: F(5) = 1 + 2*3 + 4*5*6 + 7*8*9*10
+ 11*12*13*14*15 = 365527.
Your... | ```python
class Solution:
def sequence(self, N):
self.ans = 0
def recursion(digits, count):
if digits > N:
return
temp = 1
for i in range(digits):
temp *= count
count += 1
self.ans += temp
recursion(digits + 1, count)
recursion(1, 1)
return self.ans
``` | vfc_141248 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/recursive-sequence1611/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 5",
"output": "366527",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/biconnected-graph2528/1 | Solve the following coding problem using the programming language python:
Given a graph with n vertices, e edges and an array arr[] denoting the edges connected to each other, check whether it is Biconnected or not.
Note: The given graph is Undirected.
Example 1:
Input:
n = 2, e = 1
arr = {0, 1}
Output:
1
Explanatio... | ```python
class Solution:
def dfs(self, adj, v, p=-1):
if self.ans:
return
self.marked[v] = 1
self.low[v] = self.time
self.tin[v] = self.time
self.time += 1
children = 0
for w in adj[v]:
if w == p:
continue
if self.marked[w]:
self.low[v] = min(self.low[v], self.tin[w])
else:
self... | vfc_141253 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/biconnected-graph2528/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 2, e = 1\r\narr = {0, 1}",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 3, e = 2\r\narr = {0, 1, 1, 2}",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/433/A | Solve the following coding problem using the programming language python:
Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Th... | ```python
n = int(input())
s = [int(i) for i in input().split()]
(n1, n2) = (0, 0)
for i in range(n):
if s[i] == 200:
n2 += 1
else:
n1 += 1
a = (n2 - n2 // 2) * 200
b = n2 // 2 * 200
while n1:
if b <= a:
b += 100
else:
a += 100
n1 -= 1
if a == b:
print('YES')
else:
print('NO')
``` | vfc_141254 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/433/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n100 200 100\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n100 100 100 200\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/ef5111156686a3136c6a0df8bbda17f952947e17/1 | Solve the following coding problem using the programming language python:
Given a valid expression containing only binary operators '+', '-', '*', '/' and operands, remove all the redundant parenthesis.
A set of parenthesis is said to be redundant if, removing them, does not change the value of the expression.
Note: T... | ```python
class Solution:
def removeBrackets(self, s):
stack = []
priority = []
ops = []
for c in s:
if c == '(':
ops.append(c)
elif c == ')':
op2 = stack.pop()
pri = priority.pop()
op = ops.pop()
while op != '(':
if op == '+' or op == '-':
pri = min(pri, 1)
elif op =... | vfc_141258 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/ef5111156686a3136c6a0df8bbda17f952947e17/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "Exp = (A*(B+C))",
"output": "A*(B+C)",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "Exp = A+(B+(C))",
"output": "A+B+C",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/92/A | Solve the following coding problem using the programming language python:
There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to... | ```python
(n, m) = [int(x) for x in input().split()]
m %= int(n * (n + 1) / 2)
for i in range(1, n):
if m < i:
break
m -= i
print(m)
``` | vfc_141261 | {
"difficulty": "easy",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/92/A",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "36 6218\n",
"output": "14",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "46 7262\n",
"output": "35",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Problem statement
Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed f... | ```python
import bisect
import sys
sys.setrecursionlimit(10000)
a = []
def f(a, bin, n):
if bin > n:
return
if bin:
a += [bin]
f(a, bin * 10 + 2, n)
f(a, bin * 10 + 8, n)
def g(n, p):
m = -1 << 20
x = bisect.bisect_left(a, n)
if x != len(a) and a[x] == n:
m = 1
if a[p] ** 2 > n:
return m
if n % a[p] ... | vfc_141265 | {
"difficulty": "unknown_difficulty",
"memory_limit": "268.435456 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "-1",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://www.codechef.com/problems/SUBINC | Solve the following coding problem using the programming language python:
Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing.
A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$.
A subarray $A[i, j]$ is non-decreasing if $A... | ```python
t = int(input())
for i in range(t):
N = int(input())
st = input().split()
L = []
for x in st:
L.append(int(x))
n = 1
cnt = 1
for p in range(1, N):
if L[p] < L[p - 1]:
n += 1
cnt = 1
else:
cnt += 1
n += cnt
p += 1
print(n)
``` | vfc_141269 | {
"difficulty": "medium",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/SUBINC",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n4\n1 4 2 3\n1\n5\n",
"output": "6\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4\n1 2 2 3\n1\n5",
"output": "10\n1\n",
"type": "stdin_stdout"
},
{
"fn... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/convertible-string2643/1 | Solve the following coding problem using the programming language python:
Given two strings check whether first string could be converted to the second string but the conditions are:
1.If the character is at odd place you can swap this character with the characters only at the odd places in the given first string.
... | ```python
class Solution:
def EqualString(self, s, t):
if len(s) != len(t):
return 0
else:
(a, b, c, d) = ([], [], [], [])
n = len(s)
for i in range(0, n, 2):
a.append(s[i])
b.append(t[i])
for i in range(1, n, 2):
c.append(s[i])
d.append(t[i])
a.sort()
b.sort()
c.sort()
... | vfc_141273 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/convertible-string2643/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "geeks for",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "skeeg geeks",
"output": "1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1525/E | Solve the following coding problem using the programming language python:
Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has $n$ cities. In order to conquer new lands he plans to build one Monument in each city. The game is... | ```python
ans = 0
(n, m) = map(int, input().split())
mod = 998244353
a = [list(map(int, input().split())) for i in range(n)]
fac = 1
for i in range(1, n + 1):
fac *= i
inv = pow(fac, mod - 2, mod)
for j in range(m):
na = sorted([a[i][j] for i in range(n)])
now = 1
able = 0
for i in range(n):
while len(na) > 0 an... | vfc_141274 | {
"difficulty": "hard",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1525/E",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"output": "166374062\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1205/D | Solve the following coding problem using the programming language python:
You are given a tree with n nodes. You have to write non-negative integers on its edges so that the following condition would be satisfied:
For every two nodes i, j, look at the path between them and count the sum of numbers on the edges of thi... | ```python
import math
n = int(input())
if n == 1:
print()
else:
edge = [list(map(int, input().split())) for i in range(1, n)]
g = {}
for (x, y) in edge:
if x not in g:
g[x] = []
if y not in g:
g[y] = []
g[x].append(y)
g[y].append(x)
def find_centroid(g):
p = {}
size = {}
p[1] = -1
Q = [1]
... | vfc_141278 | {
"difficulty": "very_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1205/D",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n8 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n",
"output": "2 8 1\n9 2 1\n7 2 2\n3 2 3\n10 8 5\n5 10 5\n6 5 5\n1 8 20\n4 1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 1\n5 ... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Everybody knows that the capital of Bergeria is connected to banson by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Bergeria are a bit peculiar, becau... | ```python
def F():
a, v = list(map(float, input().split()))
l, d, w = list(map(float, input().split()))
if v <= w or w * w >= 2 * a * d:
if v * v <= 2 * a * l:
return v / 2 / a + l / v
else:
return (2 * l / a) ** .5
else:
if v * v - w * w >= (l - d) * 2 * a:
t = ((w * w + 2 * a * (l - d)) ** .5 - w) ... | vfc_141282 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n2 1 3",
"output": "8.965874696353",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 70\n200 170 40",
"output": "2.500000000000",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/21/B | Solve the following coding problem using the programming language python:
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.
Write the program which finds the number of points in the intersection of two ... | ```python
(a1, b1, c1) = [int(i) for i in input().split()]
(a2, b2, c2) = [int(i) for i in input().split()]
if c1 != c2 and (a1 == 0 and b1 == 0) and (a2 == 0 and b2 == 0):
print(0)
elif a1 == 0 and b1 == 0 and (c1 == 0) or (a2 == 0 and b2 == 0 and (c2 == 0)):
print(-1)
elif a1 == 0 and b1 == 0 and (c1 != 0) or ((a2 ... | vfc_141286 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/21/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 -1 1\n0 0 0\n",
"output": "-1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1209/D | Solve the following coding problem using the programming language python:
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are $n$ snacks flavors, numbered wit... | ```python
def find_parent(u):
if par[u] != u:
par[u] = find_parent(par[u])
return par[u]
(n, k) = map(int, input().split())
l = []
par = [0] + [i + 1 for i in range(n)]
g = []
rank = [1] * (n + 1)
ans = 0
for i in range(k):
(a, b) = map(int, input().split())
(z1, z2) = (find_parent(a), find_parent(b))
if z1 != z... | vfc_141290 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1209/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n1 2\n4 3\n1 4\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/ada-noise2029/1 | Solve the following coding problem using the programming language python:
You are given a message string S consisting of lowercase English alphabet letters. "ada" is a noise word and all the words that can be formed by adding “da” any number of times at the end of any noise word is also considered as a noise word. For... | ```python
class Solution:
def updateString(self, S):
noise = ''
output = ''
i = 0
j = 0
while i < len(S):
if S[i:i + 3] == 'ada':
output += S[j:i]
j = i
i += 3
while S[i:i + 2] == 'da':
i += 2
noise += S[j:i]
j = i
else:
i += 1
output += S[j:i]
return output + nois... | vfc_141298 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/ada-noise2029/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"heyadadahiadahi\"",
"output": "\"heyhihiadadaada\"",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"heyheyhello\"",
"output": "\"heyheyhello\"",
"type": "stdin_stdout"... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/sum-of-leaf-nodes-at-min-level/1 | Solve the following coding problem using the programming language python:
Given a Binary Tree of size N, find the sum of all the leaf nodes that are at minimum level of the given binary tree.
Example 1:
Input:
1
/ \
2 3
/ \ \
4 5 8
/ \
7 2
Output:
sum = ... | ```python
class Solution:
def minLeafSum(self, root):
def t(rt, lev):
nonlocal sum1, mini
if rt is None:
return None
if rt.left is None and rt.right is None:
if lev < mini:
sum1 = rt.data
mini = lev
elif lev == mini:
sum1 += rt.data
t(rt.left, lev + 1)
t(rt.right, lev + 1)... | vfc_141299 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-leaf-nodes-at-min-level/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n / \\\n 2 3\n / \\ \\\n 4 5 8 \n / \\ \n 7 2",
"output": "13",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n / \\\n 2 3\n ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1036/F | Solve the following coding problem using the programming language python:
Consider some positive integer $x$. Its prime factorization will be of form $x = 2^{k_1} \cdot 3^{k_2} \cdot 5^{k_3} \cdot \dots$
Let's call $x$ elegant if the greatest common divisor of the sequence $k_1, k_2, \dots$ is equal to $1$. For examp... | ```python
from math import sqrt, log2
from sys import stdin
from bisect import bisect
import time
def all_primes(n):
res = []
for i in range(1, n + 1):
prime = True
for j in range(2, min(int(sqrt(i)) + 2, i)):
if i % j == 0:
prime = False
break
if prime:
res.append(i)
return res
def count_pow_n... | vfc_141300 | {
"difficulty": "very_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1036/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4\n2\n72\n10\n",
"output": "2\n1\n61\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n576460752303423487\n",
"output": "576460751543338132\n",
"type": "stdin_stdout"
... |
taco | verifiable_code | Solve the following coding problem using the programming language python:
A fraction whose numerator is 1 and whose denominator is a positive integer is called a unit fraction. A representation of a positive rational number p/q as the sum of finitely many unit fractions is called a partition of p/q into unit fractions... | ```python
from fractions import gcd
def solve(p, q, a, n, l=1):
ans = 1 if p == 1 and q <= a and (q >= l) else 0
denom = max(l, q // p)
p_denom = denom * p
while n * q >= p_denom and denom <= a:
(p_, q_) = (p_denom - q, q * denom)
if p_ <= 0:
denom += 1
p_denom += p
continue
gcd_ = gcd(p_, q_)
p_ ... | vfc_141304 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3 120 3\n2 3 300 3\n2 3 299 3\n2 3 12 3\n2 3 12000 7\n54 795 12000 7\n2 4 300 1\n2 1 200 5\n2 4 54 2\n0 0 0 0",
"output": "4\n7\n6\n2\n42\n1\n1\n9\n3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/963/B | Solve the following coding problem using the programming language python:
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges c... | ```python
from collections import defaultdict, deque
import sys
import bisect
import math
input = sys.stdin.readline
mod = 1000000007
def bfs(root, count):
q = deque([root])
vis.add(root)
while q:
vertex = q.popleft()
for child in graph[vertex]:
if ans[child] == 0:
ans[child] = count + 1
count += 1
... | vfc_141312 | {
"difficulty": "hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/963/B",
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"output": "YES\n11\n6\n16\n7\n8\n13\n10\n14\n2\n21\n18\n20\n19\n3\n12\n4\n9\n5\n15\n17\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://www.codechef.com/problems/PRESUFOP | Solve the following coding problem using the programming language python:
You are given two arrays A and B, each of size N. You can perform the following types of operations on array A.
Type 1: Select any prefix of A and increment all its elements by 1.
Type 2: Select any suffix of A and increment all its elements by... | ```python
def presufop():
for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
(op1, op2) = (b[0] - a[0], 0)
(res1, res2) = (0, 0)
for i in range(n):
if op1 + op2 < b[i] - a[i]:
op2 += b[i] - a[i] - op1 - op2
elif op1 + op2 > b[i] ... | vfc_141320 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/PRESUFOP",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n5\n2 3 5 1 2\n4 3 6 2 3\n4\n0 0 0 0\n1 2 2 1\n3\n1 2 3\n1 2 2",
"output": "3\n2\n-1",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/BUY1GET1 | Solve the following coding problem using the programming language python:
One day Alice visited Byteland to purchase jewels for her upcoming wedding anniversary.
In Byteland, every Jewelry shop has their own discount methods to attract the customers. One discount method called Buy1-Get1 caught Alice's attention. That ... | ```python
import math
for i in range(int(input())):
x = input().strip()
x1 = set(x)
c = 0
for k in x1:
c += math.ceil(x.count(k) / 2)
print(c)
``` | vfc_141324 | {
"difficulty": "easy",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/BUY1GET1",
"time_limit": "1 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nssss\nssas\nsa\ns",
"output": "2\n3\n2\n1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\nssss\nrsas\nsa\ns",
"output": "2\n3\n2\n1\n",
"type": "stdin_stdout"
},
{
... |
taco | verifiable_code | https://www.hackerrank.com/challenges/xor-matrix/problem | Solve the following coding problem using the programming language python:
Consider a zero-indexed matrix with $m$ rows and $n$ columns, where each row is filled gradually. Given the first row of the matrix, you can generate the elements in the subsequent rows using the following formula:
$a_{i,j}=a_{i-1,j}\oplus a_{i... | ```python
(n, m) = map(int, input().split())
ar = tuple(map(int, input().split()))
i = 1
m -= 1
while m:
if m & 1:
j = i % n
ar = tuple((ar[pos] ^ ar[(pos + j) % n] for pos in range(n)))
m >>= 1
i <<= 1
print(*ar)
``` | vfc_141328 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/xor-matrix/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 2\n6 7 1 3\n",
"output": "1 6 2 5\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/305/C | Solve the following coding problem using the programming language python:
Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order.
Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum ... | ```python
n = int(input())
I = list(map(int, input().split()))
a = []
for val in I:
a.append(val)
la = len(a)
b = []
c = []
d = -1
for i in range(0, la):
if i == 0 or a[i] != a[i - 1]:
b.append(a[i])
c.append(1)
d = d + 1
else:
c[d] = c[d] + 1
d = d + 1
tot = 0
idx = 0
for i in range(0, d):
while idx < b[i]... | vfc_141332 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/305/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
taco | verifiable_code | https://www.hackerrank.com/challenges/lexicographic-steps/problem | Solve the following coding problem using the programming language python:
Krishnakant is standing at $(0,0)$ in the Cartesian plane. He wants to go to the point $(x,y)$ in the same plane using only horizontal and vertical moves of $1$ unit. There are many ways of doing this, and he is writing down all such ways. Each ... | ```python
import math
def paths(n, m):
if min(n, m) < 0:
return 0
return math.factorial(n + m) / math.factorial(n) / math.factorial(m)
T = int(input())
for cs in range(T):
res = []
(N, M, K) = [int(x) for x in input().split()]
(x, y) = (0, 0)
while (x, y) != (N, M):
n = paths(N - x - 1, M - y)
if x + 1 <= ... | vfc_141341 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/lexicographic-steps/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 2 2\n2 2 3\n",
"output": "HVVH\nVHHV\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1228/A | Solve the following coding problem using the programming language python:
You have two integers $l$ and $r$. Find an integer $x$ which satisfies the conditions below:
$l \le x \le r$. All digits of $x$ are different.
If there are multiple answers, print any of them.
-----Input-----
The first line contains two... | ```python
import sys
(l, r) = map(int, input().split())
for i in range(l, r + 1):
if list(set(str(i))) == list(str(i)):
print(i)
sys.exit()
print(-1)
``` | vfc_141345 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1228/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "121 130\n",
"output": "123\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "98766 100000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
taco | verifiable_code | https://www.hackerrank.com/challenges/mathematical-expectation/problem | Solve the following coding problem using the programming language python:
Let's consider a random permutation p_{1}, p_{2}, ..., p_{N} of numbers 1, 2, ..., N and calculate the value F=(X_{2}+...+X_{N-1})^{K}, where X_{i} equals 1 if one of the following two conditions holds: p_{i-1} < p_{i} > p_{i+1} or p_{i-1} > p_{... | ```python
import sys
from fractions import gcd, Fraction
from itertools import permutations
DN = 11
DA = [2, 20, 90, 108, 240, 552, 328, 640, 420, 1428, 1652, 2660, 658, 1960, 1890, 3192, 504, 2268, 3892, 5656, 3038, 8204, 6426, 11592, 922, 3676, 5454, 8208, 3456, 9612, 7988, 14144, 420, 2352, 5348, 7280, 6202, 15820, ... | vfc_141349 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/mathematical-expectation/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1000\n",
"output": "1996 / 3\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Hierarchical Democracy
The presidential election in Republic of Democratia is carried out through multiple stages as follows.
1. There are exactly two presidential candidates.
2. At the first stage, eligible voters go to the polls of his/her e... | ```python
N = int(input())
def rec():
global now, l
if s[now].isdigit():
res = 0
while now < l and s[now].isdigit():
res = 10 * res + int(s[now])
now += 1
return (res + 1) // 2
else:
g = []
while now < l and s[now] == '[':
now += 1
g.append(rec())
now += 1
g.sort()
return sum(g[:(len(g)... | vfc_141353 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "8.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n[[133][4567][89]]\n[[5][3][7][3][9]]\n[[[99][59][63][85][51]][[1539][7995][467]][[51][57][79][99][3][91][59]]]\n[[[37][95][31][77][15]][[43][5][5][5][85]][[71][3][51][89][29]][[57][95][5][69][31]][[99][59][65][73][31]]]\n[[[[9][... | |
taco | verifiable_code | https://www.hackerrank.com/challenges/smart-number/problem | Solve the following coding problem using the programming language python:
In this challenge, the task is to debug the existing code to successfully execute all provided test files.
A number is called a smart number if it has an odd number of factors. Given some numbers, find whether they are smart numbers or not.
De... | ```python
import math
def is_smart_number(num):
val = int(math.sqrt(num))
if num == val ** 2:
return True
return False
for _ in range(int(input())):
num = int(input())
ans = is_smart_number(num)
if ans:
print('YES')
else:
print('NO')
``` | vfc_141357 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/smart-number/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1\n2\n7\n169\n",
"output": "YES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/npr4253/1 | Solve the following coding problem using the programming language python:
Write a program to calculate _{n}P^{r}. _{n}P^{r} represents n permutation r and value of _{n}P^{r }is (n!) / (n-r)!.
Example 1:
Input: n = 2, r = 1
Output: 2
Explaination: 2!/(2-1)! = 2!/1! = (2*1)/1 = 2.
Example 2:
Input: n = 3, r = 3
Output: ... | ```python
class Solution:
def nPr(self, n, r):
(f1, f2) = (1, 1)
for i in range(1, n + 1):
f1 = f1 * i
for j in range(1, n - r + 1):
f2 = f2 * j
return f1 // f2
``` | vfc_141365 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/npr4253/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "n = 2, r = 1",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "n = 3, r = 3",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.codechef.com/problems/KSIZEGCD | Solve the following coding problem using the programming language python:
Note the unusual time limit in this problem.
You are given an array A of N positive integers.
The *power* of a subarray A[L, R] (1≤ L≤ R ≤ N) having size (R-L+1) is defined as \gcd(A_{L}, A_{(L+1)}, \ldots, A_{R}), where \gcd denotes the [gre... | ```python
import sys
input = sys.stdin.readline
from math import gcd
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = [0] * (n + 1)
gcds = {}
sm = 0
for x in a:
new_gcds = {x: 1}
for g in gcds.keys():
G = gcd(x, g)
if G not in new_gcds:
new_gcds[G] = gcds[g] +... | vfc_141366 | {
"difficulty": "very_hard",
"memory_limit": "50000 bytes",
"memory_limit_bytes": null,
"problem_url": "https://www.codechef.com/problems/KSIZEGCD",
"time_limit": "0.5 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n4\n5 5 5 5\n4\n4 2 3 1\n3\n6 10 15\n5\n2 6 3 9 24\n5\n3 11 7 2 5\n",
"output": "5 5 5 5\n4 2 1 1\n15 5 1\n24 3 3 3 1\n11 1 1 1 1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/valid-substring0624/1 | Solve the following coding problem using the programming language python:
Given a string S consisting only of opening and closing parenthesis 'ie '(' and ')', find out the length of the longest valid(well-formed) parentheses substring.
NOTE: Length of the smallest valid substring ( ) is 2.
Example 1:
Input: S = "(()(... | ```python
class Solution:
def findMaxLen(ob, s):
(open, close, ans) = (0, 0, 0)
for i in s:
if i == '(':
open += 1
else:
close += 1
if close == open:
ans = max(ans, close + open)
elif close > open:
open = close = 0
open = close = 0
for i in range(len(s) - 1, -1, -1):
if '(' == s... | vfc_141371 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/valid-substring0624/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "S = \"(()(\"",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "S = \"()(())(\"",
"output": "6",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/1183/F | Solve the following coding problem using the programming language python:
One important contest will take place on the most famous programming platform (Topforces) very soon!
The authors have a pool of $n$ problems and should choose at most three of them into this contest. The prettiness of the $i$-th problem is $a_i... | ```python
def calc(X, Y):
if len(Y) == 3:
return sum(Y)
for x in X:
for y in Y:
if y % x == 0:
break
else:
return calc([i for i in X if i != x], sorted(Y + [x])[::-1])
return sum(Y)
for _ in range(int(input())):
N = int(input())
A = sorted(set([int(a) for a in input().split()]))[::-1]
print(max(ca... | vfc_141372 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1183/F",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n4\n5 6 15 30\n4\n10 6 30 15\n3\n3 4 6\n",
"output": "30\n31\n10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n5\n30 30 15 10 6\n",
"output": "31\n",
"type": "stdin_stdo... |
taco | verifiable_code | https://codeforces.com/problemset/problem/559/A | Solve the following coding problem using the programming language python:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimete... | ```python
from sys import stdin, stdout
input = stdin.readline
t = 1
for _ in range(t):
a = [int(x) for x in input().split()]
k = a[0] + a[1] + a[2]
ans = k * k - (a[0] * a[0] + a[2] * a[2] + a[4] * a[4])
print(ans)
``` | vfc_141376 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/559/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1 1 1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1 2 1 2 1 2\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/k-closest-elements3619/1 | Solve the following coding problem using the programming language python:
Given a sorted array, arr[] of N integers, and a value X. Find the K closest elements to X in arr[].
Keep the following points in mind:
If X is present in the array, then it need not be considered.
If there are two elements with the same diff... | ```python
import heapq
class Solution:
def printKClosest(self, arr, n, k, x):
max_heap = []
for i in range(n):
if arr[i] == x:
continue
if len(max_heap) < k:
(diff, val) = (-abs(arr[i] - x), -arr[i])
heapq.heappush(max_heap, (diff, val))
else:
(diff, val) = max_heap[0]
if abs(arr[i] ... | vfc_141380 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/k-closest-elements3619/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "N = 13\r\narr[] = {12, 16, 22, 30, 35, 39, 42, \r\n 45, 48, 50, 53, 55, 56}\r\nK = 4, X = 35",
"output": "39 30 42 45",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "N = 5\r\nArr[] =... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1693/A | Solve the following coding problem using the programming language python:
We have an array of length $n$. Initially, each element is equal to $0$ and there is a pointer located on the first element.
We can do the following two kinds of operations any number of times (possibly zero) in any order:
If the pointer is no... | ```python
def ss(l):
n = len(l)
if sum(l) != 0:
return 'No'
t = 0
li = n - 1
while li >= 0 and l[li] == 0:
li -= 1
for i in range(n):
t += l[i]
if t <= 0 and i < li:
return 'No'
return 'Yes'
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
print(ss(l))
``` | vfc_141381 | {
"difficulty": "easy",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1693/A",
"time_limit": "1 second"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0\n",
"output": "No\nYes\nNo\nNo\nYes\nYes\nYes\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/number-of-positive-integral-solutions2115/1 | Solve the following coding problem using the programming language python:
You are given an equation of the form x_{1}+x_{2}+...+x_{N}=K. You need to find the total number of positive integral solutions of this equation.
Example 1:
Input: s = a+b=5
Output: 4
Explanation: (4,1) , (1,4) , (2,3) , (3,2)
Example 2:
Input... | ```python
class Solution:
def posIntSol(self, s):
i = 0
pcnt = 0
while s[i] != '=':
if s[i] == '+':
pcnt += 1
i += 1
r = pcnt + 1
n = ''
i += 1
while i < len(s):
n += s[i]
i += 1
n = int(n)
n = n - r
if n <= 0:
return 0
cnt = 0
num = 1
den = 1
while cnt < n:
num = num... | vfc_141385 | {
"difficulty": "medium",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/number-of-positive-integral-solutions2115/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "s = a+b=5",
"output": "4",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "s = a+b=1",
"output": "0",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://codeforces.com/problemset/problem/405/D | Solve the following coding problem using the programming language python:
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.
There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teache... | ```python
import sys
def solve():
n = int(input())
s = 1000000
xset = set(map(int, input().split()))
res = set()
wantother = 0
for i in range(1, s + 1):
opposite = s - i + 1
if i in xset:
if opposite not in xset:
res.add(opposite)
else:
wantother += 1
wantother /= 2
for i in range(1, s + 1):
... | vfc_141386 | {
"difficulty": "medium_hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/405/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 4 5\n",
"output": "3\n999996 999997 1000000 \n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
Let's Start Simple Write a programe to Sum of two Decimal Value.
SAMPLE INPUT
12.25
3.60
SAMPLE OUTPUT
15.85
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
c=eval(input())
b=eval(input())
a=b+c
print(("{0:.2f}".format(a)))
``` | vfc_141390 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "12.25\n3.60",
"output": "105.00",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "255.25\n133.95",
"output": "15.85",
"type": "stdin_stdout"
}
]
} | |
taco | verifiable_code | https://codeforces.com/problemset/problem/476/D | Solve the following coding problem using the programming language python:
Dreamoon likes to play with sets, integers and $gcd$. $\operatorname{gcd}(a, b)$ is defined as the largest positive integer that divides both a and b.
Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if ... | ```python
l = input().split(' ')
n = int(l[0])
k = int(l[1])
print((6 * n - 1) * k)
for i in range(n):
print(str((6 * i + 1) * k) + ' ' + str((6 * i + 2) * k) + ' ' + str((6 * i + 3) * k) + ' ' + str((6 * i + 5) * k))
``` | vfc_141394 | {
"difficulty": "hard",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/476/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n",
"output": "5\n1 3 4 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n",
"output": "22\n2 6 8 10\n14 18 20 22\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | Solve the following coding problem using the programming language python:
problem
There are n islands in JOI, and each island is numbered from 1 to n. Currently, the JOI country is developing a route network connecting each island.
You work at a ticket center that handles ship tickets. There are many people in JOI w... | ```python
INF = 2147483647
while True:
(n, k) = map(int, input().split())
if n == 0:
break
fee = [[INF for j in range(101)] for i in range(101)]
for i in range(n + 1):
fee[i][i] = 0
for i in range(k):
v = list(map(int, input().split()))
(a, b) = (v[1], v[2])
if v[0] == 1:
e = v[3]
if fee[a][b] > e:... | vfc_141398 | {
"difficulty": "unknown_difficulty",
"memory_limit": "134.217728 megabytes",
"memory_limit_bytes": null,
"problem_url": null,
"time_limit": "1.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n1 3 1 10\n0 2 3\n1 2 2 20\n1 1 2 5\n0 3 2\n1 1 3 7\n1 2 1 9\n0 2 3\n5 16\n1 1 2 343750\n1 1 3 3343\n1 1 4 347392\n1 1 5 5497\n1 2 3 123394\n1 2 4 545492\n1 2 5 458\n1 3 4 343983\n1 3 5 843468\n1 4 5 15934\n0 2 1\n0 4 1\n0 3 2\... | |
taco | verifiable_code | https://codeforces.com/problemset/problem/1701/C | Solve the following coding problem using the programming language python:
There are $n$ workers and $m$ tasks. The workers are numbered from $1$ to $n$. Each task $i$ has a value $a_i$ — the index of worker who is proficient in this task.
Every task should have a worker assigned to it. If a worker is proficient in th... | ```python
def moze(v, r, n):
s = 0
for i in range(n):
if r[i] - v < 0:
s += (-r[i] + v) // 2
else:
s -= r[i] - v
if s >= 0:
return True
return False
def nadji(r, n, m):
l = (m - 1) // n + 1
right = 2 * l
iz = -1
while l <= right:
sredina = (l + right) // 2
if moze(sredina, r, n):
right = sre... | vfc_141402 | {
"difficulty": "medium",
"memory_limit": "256 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1701/C",
"time_limit": "2 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 4\n1 2 1 2\n2 4\n1 1 1 1\n5 5\n5 1 3 2 4\n1 1\n1\n",
"output": "2\n3\n1\n1\n",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://www.hackerrank.com/challenges/floor-ceil-and-rint/problem | Solve the following coding problem using the programming language python:
=====Function Descriptions=====
floor
The tool floor returns the floor of the input element-wise.
The floor of x is the largest integer i where i≤x.
import numpy
my_array = numpy.array([1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9])
print numpy... | ```python
import numpy
np_ar = numpy.array(list(map(float, input().split())), float)
print(numpy.floor(np_ar))
print(numpy.ceil(np_ar))
print(numpy.rint(np_ar))
``` | vfc_141406 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://www.hackerrank.com/challenges/floor-ceil-and-rint/problem",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9",
"output": "[1. 2. 3. 4. 5. 6. 7. 8. 9.]\n[ 2. 3. 4. 5. 6. 7. 8. 9. 10.]\n[ 1. 2. 3. 4. 6. 7. 8. 9. 10.]",
"type": "stdin_stdout"
}
]
} |
taco | verifiable_code | https://practice.geeksforgeeks.org/problems/4b7ff87c26ed23b3f63c25c611690213d44fb6aa/1 | Solve the following coding problem using the programming language python:
Given a Binary Tree having positive and negative nodes. Find the maximum sum of a level in the given Binary Tree.
Example 1:
Input :
4
/ \
2 -5
/ \ / \
-1 3 -2 6
Output: ... | ```python
class Solution:
def maxLevelSum(self, root):
d = {}
def preo(root, l):
if root == None:
return root
try:
d[l] += root.data
except:
d.__setitem__(l, root.data)
preo(root.left, l + 1)
preo(root.right, l + 1)
return root
preo(root, 0)
m = -10000000
try:
i = 0
whil... | vfc_141411 | {
"difficulty": "easy",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://practice.geeksforgeeks.org/problems/4b7ff87c26ed23b3f63c25c611690213d44fb6aa/1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\r\n / \\\r\n 2 -5\r\n / \\ / \\\r\n -1 3 -2 6",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\r\n / \\\r\n 2 ... |
taco | verifiable_code | https://codeforces.com/problemset/problem/1586/D | Solve the following coding problem using the programming language python:
It turns out that the meaning of life is a permutation p_1, p_2, …, p_n of the integers 1, 2, …, n (2 ≤ n ≤ 100). Omkar, having created all life, knows this permutation, and will allow you to figure it out using some queries.
A query consists o... | ```python
import sys
from sys import stdout
import os
ii = 0
_inp = b''
def getchar():
global ii, _inp
if ii >= len(_inp):
_inp = os.read(0, 4096)
ii = 0
if not _inp:
return b' '[0]
ii += 1
return _inp[ii - 1]
def input():
c = getchar()
if c == b'-'[0]:
x = 0
sign = 1
else:
x = c - b'0'[0]
sign ... | vfc_141417 | {
"difficulty": "medium_hard",
"memory_limit": "256.0 megabytes",
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1586/D",
"time_limit": "2.0 seconds"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1 4 2\n",
"output": "4\n? 2 1 1 1\n1\n? 1 2 2 2\n1\n? 1 2 1 1\n2\n? 2 1 2 2\n0\n? 1 1 2 1\n0\n? 2 2 1 2\n1\n? 1 1 1 2\n1\n? 2 2 2 1\n2\n! 3 1 4 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.