source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 138 | problem_statement stringlengths 219 13.2k | gold_standard_solution stringlengths 0 413k | problem_id stringlengths 5 10 | metadata dict | verification_info dict |
|---|---|---|---|---|---|---|---|
apps | verifiable_code | 2058 | Solve the following coding problem using the programming language python:
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the... | ```python
import heapq
n = int(input())
d = list(map(int,input().split()))
pq = [-d[0]]
heapq.heapify(pq)
ans = 0
for i in range(1,n):
temp = i - d[i]
heapq.heappush(pq,temp)
if heapq.nsmallest(1,pq)[0] < temp:
ans += temp - heapq.nsmallest(1,pq)[0]
heapq.heappushpop(pq,temp)
print(ans)
``` | vfc_5778 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/713/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n2 1 5 11 5 9 11\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n5 4 3 2 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"fn_name": null... |
apps | verifiable_code | 2059 | Solve the following coding problem using the programming language python:
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p_1, p_2, ..., p_{n} for his birthday.
Jeff hates inversions in sequences. An inversion in sequence a_1, a_2, ..., a_{n} is a... | ```python
n = int(input())
inp = input()
seq = inp.split(' ')
seq = [ abs(int(x)) for x in seq ]
Max = max(seq)
nxt = [0] * n
cnt = [0] * n
pos = [n] * (Max+1)
for i in range(n-1, -1, -1):
nxt[i] = pos[seq[i]]
pos[seq[i]] = i
for i in range(0, Max+1):
j = pos[i]
while(j<n):
front = sum(cnt[0:j])... | vfc_5782 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/351/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n-2 0 -1 0 -1 2 1 0 -1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
apps | verifiable_code | 2060 | Solve the following coding problem using the programming language python:
Evlampiy has found one more cool application to process photos. However the application has certain limitations.
Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k... | ```python
def f(m):
nonlocal dp, sdp
l = 0
for i in range(n):
while l < n and v[l] < v[i] - m:
l += 1
if l - 1 > i - k:
dp[i] = False
else:
dp[i] = (sdp[i - k + 1] != sdp[l - 1])
sdp[i + 1] = sdp[i] + (1 if dp[i] else 0)
return dp[n - 1... | vfc_5786 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/883/I",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2\n50 110 130 40 120\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n2 3 4 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": ... |
apps | verifiable_code | 2061 | Solve the following coding problem using the programming language python:
We have three stones at points (0, 0), (1,0), and (0,1) on a two-dimensional plane.
These three stones are said to form an L when they satisfy the following conditions:
- Each of the stones is at integer coordinates.
- Each of the stones is ad... | ```python
import sys
input = sys.stdin.readline
def solve(ax,ay,bx,by,cx,cy):
x = ax+bx+cx
y = ay+by+cy
x -= x//3+1
y -= y//3+1
if x==y:
return x if 0 <= x <= 1 else abs(x)+1
else:
return max(abs(x), abs(y))
T = int(input())
for _ in range(T):
ax,ay,bx,by,cx,cy = map(int,in... | vfc_5790 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://atcoder.jp/contests/arc109/tasks/arc109_d",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n3 2 2 2 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n0 0 1 0 0 1\n1 0 0 1 1 1\n2 -1 1 -1 1 0\n1 -2 2 -1 1 -1\n-1 2 0 2 -1 3\n-1 -2 -2 -2 -2 -3\n-2 4 -3 3 -2 ... |
apps | verifiable_code | 2062 | Solve the following coding problem using the programming language python:
There are N people, conveniently numbered 1 through N.
We want to divide them into some number of groups, under the following two conditions:
- Every group contains between A and B people, inclusive.
- Let F_i be the number of the groups conta... | ```python
def main():
mod = 10**9+7
inv_n = [0]*1001
nCr = [[1]*(i+1) for i in range(1001)]
for i in range(1001):
inv_n[i] = pow(i, mod-2, mod)
for i in range(2, 1001):
for j in range(1, i):
nCr[i][j] = (nCr[i-1][j-1]+nCr[i-1][j]) % mod
n, a, b, c, d = list(map(int, i... | vfc_5794 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://atcoder.jp/contests/arc067/tasks/arc067_c",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1 3 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 2 3 1 3\n",
"output": "105\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
apps | verifiable_code | 2063 | Solve the following coding problem using the programming language python:
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows... | ```python
rd = lambda: list(map(int, input().split()))
def root(x):
if f[x]!=x: f[x] = root(f[x])
return f[x]
n, m = rd()
N = list(range(n))
f = list(N)
lang = [0]*n
for i in N: lang[i] = set(rd()[1:])
for i in N:
for j in N[:i]:
rj = root(j)
if lang[rj].intersection(lang[i]):
f[rj] = i
lang... | vfc_5798 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/277/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n",
"output": "2\n",
"ty... |
apps | verifiable_code | 2064 | Solve the following coding problem using the programming language python:
3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl fro... | ```python
import sys
readline = sys.stdin.readline
N, Q = list(map(int, readline().split()))
state = [[False]*(N+2) for _ in range(2)]
cnt = 0
Ans = [None]*Q
for qu in range(Q):
r, c = list(map(int, readline().split()))
r -= 1
c -= 1
state[r][c] = not state[r][c]
res = state[r-1][c-1] + state[r-1... | vfc_5802 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1292/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"output": "Yes\nNo\nNo\nNo\nYes\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n2 1\n1 2\n",
"output": "Yes\nNo\n",
"type": "stdin_stdout"... |
apps | verifiable_code | 2065 | Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art.
The main exhibit is a construction of n matryoshka dolls that can be nested one into another. The matryoshka... | ```python
n, k = [int(c) for c in input().split()]
a = []
for i in range(k):
ak = [int(c) for c in input().split()]
a.append(ak[1:])
total = k - 1
for ak in a:
if ak[0] == 1:
j = 1
while j <= len(ak) - 1:
if ak[j] != ak[j-1] + 1:
break
j += 1
... | vfc_5806 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/555/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n2 1 2\n1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 3\n3 1 3 7\n2 2 5\n2 4 6\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"fn_... |
apps | verifiable_code | 2066 | Solve the following coding problem using the programming language python:
In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and mod... | ```python
import os
import random
import sys
from typing import List, Dict
class Int:
def __init__(self, val):
self.val = val
def get(self):
return self.val + 111
class Unique:
def __init__(self):
self.s = set()
def add(self, val : int):
self.s.add(val)
def __co... | vfc_5810 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/594/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n0 1 3 7 15 31\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n73 37\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2067 | Solve the following coding problem using the programming language python:
One Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have a superior.
We will ca... | ```python
n = int(input())
t = [list(map(int, input().split())) for q in range(n)]
t[0][0] = 0
n += 1
u = [-1e7] * n
v = [0] * n
for i, (j, a) in list(enumerate(t, 1))[::-1]:
u[i] = max(u[i], v[i] + a)
v[j], u[j] = max(v[j] + v[i], u[j] + u[i]), max(v[j] + u[i], u[j] + v[i])
print(u[1])
``` | vfc_5814 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/533/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n-1 42\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2068 | Solve the following coding problem using the programming language python:
The Fair Nut is going to travel to the Tree Country, in which there are $n$ cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent a car ... | ```python
import sys
readline = sys.stdin.readline
from collections import Counter
def getpar(Edge, p):
N = len(Edge)
par = [0]*N
par[0] = -1
par[p] -1
stack = [p]
visited = set([p])
while stack:
vn = stack.pop()
for vf in Edge[vn]:
if vf in visited:
... | vfc_5818 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1083/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 3 3\n1 2 2\n1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n6 3 2 5 0\n1 2 10\n2 3 3\n2 4 1\n1 5 1\n",
"output": "7\n",
"type": "stdin_stdout"
... |
apps | verifiable_code | 2069 | Solve the following coding problem using the programming language python:
You are given an array $a$ of $n$ integers.
You want to make all elements of $a$ equal to zero by doing the following operation exactly three times: Select a segment, for each number in this segment we can add a multiple of $len$ to it, where ... | ```python
n=int(input())
L=list(map(int,input().split()))
if n==1:
print(1,1)
print(0)
print(1,1)
print(0)
print(1,1)
print(-L[0])
else:
print(1,n-1)
for i in range(n-1):print(L[i]*(n-1),end=' ')
print()
print(n,n)
print(-L[n-1])
print(1,n)
for i in range(n-1):print(-... | vfc_5822 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1396/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 2 4\n",
"output": "1 4\n-4 -12 -8 0\n1 3\n3 9 6 \n4 4\n-4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n34688642\n",
"output": "1 1\n-34688642\n1 1\n0\n1 1\n0\n",
"... |
apps | verifiable_code | 2070 | Solve the following coding problem using the programming language python:
Karen has just arrived at school, and she has a math test today! [Image]
The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S... | ```python
#!/usr/bin/env pypy3
import math
def make_nCr_mod(max_n=2*10**5 + 100, mod=10**9 + 7):
fact, inv_fact = [0] * (max_n + 1), [0] * (max_n + 1)
fact[0] = 1
for i in range(max_n):
fact[i + 1] = fact[i] * (i + 1) % mod
inv_fact[-1] = pow(fact[-1], mod - 2, mod)
for i in reversed(rang... | vfc_5826 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/815/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 6 9 12 15\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n3 7 5 2\n",
"output": "1000000006\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
apps | verifiable_code | 2071 | Solve the following coding problem using the programming language python:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are n watchmen on a plane, the i-th watchman is located at point (x_{i}, y_{i}).
They need to arrange a plan, but... | ```python
from collections import Counter
n = int(input())
points = Counter([tuple(map(int, input().split(' '))) for i in range(n)])
x, y = Counter([k for k, v in points.elements()]), Counter([v for k, v in points.elements()])
ans = sum([v*(v-1)//2 for k, v in list(x.items())])+sum([v*(v-1)//2 for k, v in list(y.item... | vfc_5830 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/650/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 1\n7 5\n1 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2072 | Solve the following coding problem using the programming language python:
Edo has got a collection of n refrigerator magnets!
He decided to buy a refrigerator and hang the magnets on the door. The shop can make the refrigerator with any size of the door that meets the following restrictions: the refrigerator door mus... | ```python
from sys import*
#
def check(u, d, l, r):
used = [pointsx[i][1] for i in range(l)]
used += [pointsx[-1 - i][1] for i in range(r)]
used += [pointsy[i][1] for i in range(u)]
used += [pointsy[-1 - i][1] for i in range(d)]
if len(set(used)) > k:
return DOHERA
dx = pointsx[-1 - r][0... | vfc_5834 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/594/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 1\n1 1 2 2\n2 2 3 3\n3 3 4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 1\n1 1 2 2\n1 9 2 10\n9 9 10 10\n9 1 10 2\n",
"output": "64\n",
"type": "stdin... |
apps | verifiable_code | 2073 | Solve the following coding problem using the programming language python:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x_1, x_2, ..., x_{k} (k > 1) is such maximum element x_{j}, that the following inequality holds: $x_{j} \neq \opera... | ```python
def maximum_xor_secondary(sequence):
stack, answer = [], 0
for x in sequence:
while stack:
answer = max(answer, stack[-1] ^ x)
if stack[-1] > x:
break
else:
stack.pop()
stack.append(x)
return answer
size, num = ... | vfc_5838 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/280/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n5 2 1 4 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n9 8 3 5 7\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2074 | Solve the following coding problem using the programming language python:
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.
You need to permute the array elements so that value $\sum_{i = 1}^{n - k}|A [ i ] - A [ i + k ]|$ became minimal possible. In pa... | ```python
INF = 10 ** 18 + 179
[n, k], a = [list(map(int, input().split())) for x in range(2)]
a.sort()
dp, l = [[0] * (k - n % k + 1) for x in range(n % k + 1)], n // k
for i in range(n % k + 1):
for j in range(k - n % k + 1):
pos = i * (l + 1) + j * l
dp[i][j] = min((dp[i - 1][j] + a[pos - 1] - a[... | vfc_5842 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/571/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n1 2 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 2\n3 -5 3 -5 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2075 | Solve the following coding problem using the programming language python:
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be w_{i}, then 0 < w_1 ≤ w_2 ≤ ... ≤... | ```python
rd = lambda: list(map(int, input().split()))
rd()
a = sorted(rd(), reverse=True)
b = sorted(rd(), reverse=True)
if len(a) > len(b): print("YES"); return
for i in range(len(a)):
if a[i] > b[i]: print("YES"); return
print("NO")
``` | vfc_5846 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/297/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3 3\n2 2 2\n1 1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2076 | Solve the following coding problem using the programming language python:
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.
We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors... | ```python
n = int(input())
p = [tuple(map(int, input().split())) for i in range(n)]
def d(a, b):
return (a[0]-b[0], a[1]-b[1], a[2]-b[2], a[3]-b[3], a[4]-b[4])
def m(a, b):
t = 0
for i in range(5):
t += a[i] * b[i]
return t
good_points = []
for i in range(n):
good = True
for j in ran... | vfc_5850 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/850/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n",
"output... |
apps | verifiable_code | 2077 | Solve the following coding problem using the programming language python:
Little X has n distinct integers: p_1, p_2, ..., p_{n}. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: If number x belongs to set A, then number a - x must also belong to set A. If number ... | ```python
from collections import defaultdict
def solve(n, a, b, xs):
group = [None] * n
id_ = {x: i for i, x in enumerate(xs)}
if a == b:
for x in xs:
if a - x not in id_:
return False
group = [0] * n
else:
for i, x in enumerate(xs):
if g... | vfc_5854 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/468/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5 9\n2 3 4 5\n",
"output": "YES\n0 0 1 1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 3 4\n1 2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name... |
apps | verifiable_code | 2078 | Solve the following coding problem using the programming language python:
One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.
A positive integer $a$ is initially on the screen. The player can put a coin into the machine and then add $1$ to or subtract ... | ```python
def main():
n = int(input())
a = list(map(int, (x for x in input())))
b = list(map(int, (x for x in input())))
x = [0] * (n - 1)
x[0] = b[0] - a[0]
for i in range(1, n - 1):
x[i] = b[i] - a[i] - x[i - 1]
if a[n - 1] + x[n - 2] != b[n - 1]:
print(-1)
return
... | vfc_5858 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1120/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n223\n322\n",
"output": "2\n1 1\n2 -1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n20\n42\n",
"output": "2\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"fn_n... |
apps | verifiable_code | 2079 | Solve the following coding problem using the programming language python:
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. Y... | ```python
q = int(input())
def full_way(u):
res = set()
while u >= 1:
res.add(u)
u //= 2
return res
def get_way(u, v):
res1 = full_way(u)
res2 = full_way(v)
m = max(res1 & res2)
res = set()
for x in res1 | res2:
if x > m:
res.add(x)
retur... | vfc_5862 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/696/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\n1 3 4 30\n1 4 1 2\n1 3 6 8\n2 4 3\n1 6 1 40\n2 3 7\n2 2 4\n",
"output": "94\n0\n32\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n2 666077344481199252 881371880336470888\n",
"... |
apps | verifiable_code | 2080 | Solve the following coding problem using the programming language python:
Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems.
There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer tak... | ```python
import sys
n_discounts = int(sys.stdin.readline())
discount_values = [int(x) for x in sys.stdin.readline().split()]
n_items = int(sys.stdin.readline())
item_values = [int(x) for x in sys.stdin.readline().split()]
min_discount_req = 10000000
for discount_value in discount_values:
min_discount_req = min(m... | vfc_5866 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/261/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n2\n4\n50 50 100 100\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3\n5\n50 50 50 50 50\n",
"output": "150\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2081 | Solve the following coding problem using the programming language python:
Nikita likes tasks on order statistics, for example, he can easily find the $k$-th number in increasing order on a segment of an array. But now Nikita wonders how many segments of an array there are such that a given number $x$ is the $k$-th num... | ```python
from math import pi
from cmath import exp
def fft(a, lgN, rot=1): # rot=-1 for ifft
N = 1<<lgN
assert len(a)==N
rev = [0]*N
for i in range(N):
rev[i] = (rev[i>>1]>>1)+(i&1)*(N>>1)
A = [a[rev[i]] for i in range(N)]
h = 1
while h<N:
w_m = exp((0+1j) * rot * (pi / h))
for k in range(0, ... | vfc_5870 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/993/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n",
"output": "6 5 4 0 0 0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 6\n-5 9\n",
"output": "1 2 0 ",
"type": "stdin_stdout"
},
{
"fn_name": ... |
apps | verifiable_code | 2082 | Solve the following coding problem using the programming language python:
Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play.
At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2... | ```python
MOD = 998244353
n = int(input())
a = list(map(int, input().split()))
tot = sum(a)
def inv(x):
return pow(x, MOD - 2, MOD)
l = [0, pow(n, tot, MOD) - 1]
for i in range(1, tot):
aC = i
cC = (n - 1) * (tot - i)
curr = (aC + cC) * l[-1]
curr -= tot * (n - 1)
curr -= aC * l[-2]
cur... | vfc_5874 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1349/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5... |
apps | verifiable_code | 2083 | Solve the following coding problem using the programming language python:
Levko loves array a_1, a_2, ... , a_{n}, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
Increase all elements fro... | ```python
n, m = map(int, input().split())
a = [10**9 for _ in range(n)]
extra = [0 for _ in range(n)]
query = list()
for _ in range(m):
t, l, r, x = map(int, input().split())
l -= 1
r -= 1
query.append((t, l, r, x))
if t == 1:
for j in range(l, r + 1):
extra[j] += x
... | vfc_5878 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/360/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"output": "YES\n8 7 4 7 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"o... |
apps | verifiable_code | 2084 | Solve the following coding problem using the programming language python:
Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is dir... | ```python
import heapq
def coor_neighbor(coor, dxs, dys):
x, y = coor
for dx in dxs:
for dy in dys:
yield x + dx, y + dy
def coor_bottoms(coor):
return coor_neighbor(coor, (-1, 0, 1), (-1, ))
def coor_tops(coor):
return coor_neighbor(coor, (-1, 0, 1), (1, ))
def coor_sibs(coor... | vfc_5882 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/521/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 1\n1 0\n0 1\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n",
"output": "2930\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2085 | Solve the following coding problem using the programming language python:
You are given n strings s_1, s_2, ..., s_{n} consisting of characters 0 and 1. m operations are performed, on each of them you concatenate two existing strings into a new one. On the i-th operation the concatenation s_{a}_{i}s_{b}_{i} is saved i... | ```python
from sys import stdin, stdout
K = 20
def findAllStrings(s):
n = len(s)
sDict = {}
for i in range(1,K+1):
sDict[i]=set()
for x in range(n-i+1):
sDict[i].add(s[x:x+i])
return sDict
n = int(stdin.readline().rstrip())
stringDicts = []
stringEnd = []
stringBegin = []
... | vfc_5886 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/868/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n01\n10\n101\n11111\n0\n3\n1 2\n6 5\n4 4\n",
"output": "1\n2\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n01\n1\n0011\n0\n01\n6\n5 5\n3 2\n4 2\n6 7\n5 1\n9 7\n",
"output":... |
apps | verifiable_code | 2086 | Solve the following coding problem using the programming language python:
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with $n$ elements. The $i$-th element is $a_i$ ($i$ = $1, 2, \ldots, n$). He gradually takes the first two leftmost elements f... | ```python
import sys
input = sys.stdin.readline
from collections import deque
N, Q = list(map(int, input().split()))
que = deque([int(a) for a in input().split()])
ma = max(que)
X = []
k = -1
c = 0
while c <= k+N+5:
a = deque.popleft(que)
b = deque.popleft(que)
X.append((a, b))
c += 1
if a >... | vfc_5890 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1179/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 3\n1 2 3 4 5\n1\n2\n10\n",
"output": "1 2\n2 3\n5 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 0\n0 0\n",
"output": "",
"type": "stdin_stdout"
},
{
"fn_n... |
apps | verifiable_code | 2087 | Solve the following coding problem using the programming language python:
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms.
Va... | ```python
3
import sys
n, l, r, ql, qr = list(map(int, sys.stdin.readline().strip().split()))
w = [int(x) for x in sys.stdin.readline().strip().split()]
s = [0]
for i in range(0, n):
s.append(s[-1] + w[i])
def cost(left):
right = n - left
diff = left - right
bonus = 0
if diff > 0: # left part is... | vfc_5894 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/354/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 4 4 19 1\n42 3 99\n",
"output": "576\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 7 2 3 9\n1 2 3 4\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"fn_na... |
apps | verifiable_code | 2088 | Solve the following coding problem using the programming language python:
Genos recently installed the game Zuma on his phone. In Zuma there exists a line of n gemstones, the i-th of which has color c_{i}. The goal of the game is to destroy all the gemstones in the line as quickly as possible.
In one second, Genos is... | ```python
n = int(input())
C = list(map(int, input().split()))
dp = [[0]*n for _ in range(n)]
for i in range(n) :
dp[i][i] = 1
for i in range(n-2, -1, -1) :
for j in range(i+1, n) :
dp[i][j] = 1 + dp[i+1][j]
if C[i] == C[i+1] : dp[i][j] = min( dp[i][j], 1 + (dp[i+2][j] if i+2 < n else 0) )
... | vfc_5898 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/607/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input"... |
apps | verifiable_code | 2089 | Solve the following coding problem using the programming language python:
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or... | ```python
from operator import __or__, __and__, __xor__
from sys import stdin, stdout
n, b, c = int(stdin.readline()), 0, 1023
m = {'|': __or__, '&': __and__, '^': __xor__}
for i in range(n):
t, v = [i for i in stdin.readline().split()]
b = m[t](b, int(v))
c = m[t](c, int(v))
x, o, a = 0, 0, 1023
for i in r... | vfc_5902 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/878/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n| 3\n^ 2\n| 1\n",
"output": "2\n| 3\n^ 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n& 1\n& 3\n& 5\n",
"output": "1\n& 1\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2090 | Solve the following coding problem using the programming language python:
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour you can go along this road either from city a t... | ```python
from itertools import combinations_with_replacement
from collections import deque
#sys.stdin = open("input_py.txt","r")
n, m = map(int, input().split())
G = [ [] for i in range(n)]
for i in range(m):
x, y = map(int, input().split())
x-=1; y-=1
G[x].append(y)
G[y].append(x)
def BFS(s):
... | vfc_5906 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/543/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n3 5 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 4\n1 2\n2 3\n3 4\n4 5\n1 3 2\n2 4 2\n",
"output": "1\n",
"type": "stdin... |
apps | verifiable_code | 2091 | Solve the following coding problem using the programming language python:
Sereja has a bracket sequence s_1, s_2, ..., s_{n}, or, in other words, a string s of length n, consisting of characters "(" and ")".
Sereja needs to answer m queries, each of them is described by two integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ ... | ```python
import sys
input = sys.stdin.readline
s = input()
M = int(input())
def next_pow_2(n):
p = 1
while p < n:
p <<= 1
return p
def represented_range(node, size):
l = node
r = node
while l < size:
l = 2*l
r = 2*r + 1
return l-size, r-size
class SegTree:
... | vfc_5910 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/380/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n",
"output": "0\n0\n2\n10\n4\n6\n6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "(((((()((((((((((()((()(((((\n1\n8 15\n",
"... |
apps | verifiable_code | 2092 | Solve the following coding problem using the programming language python:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konsta... | ```python
n = int(input())
if n % 2:
print("contest")
else:
print("home")
``` | vfc_5914 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/765/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"output": "home\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n",
"output": "contest\n",
... |
apps | verifiable_code | 2093 | Solve the following coding problem using the programming language python:
Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into o... | ```python
n = int(input())
from bisect import bisect_left
a = list(map(int, input().split()))
ss = []
ms = []
for i in range(n):
k = a[i]
ind = bisect_left(ms, -k)
if ind == len(ms):
ss.append([])
ms.append(0)
ss[ind].append(k)
ms[ind] = -k
for s in ss:
print(' '.join([str(i) ... | vfc_5918 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/847/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 3 2 5 4\n",
"output": "1 3 5 \n2 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n4 3 2 1\n",
"output": "4 \n3 \n2 \n1 \n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2094 | Solve the following coding problem using the programming language python:
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately... | ```python
def main():
import sys
input = sys.stdin.readline
n = int(input())
arr = input()
one = arr.count('n')
zero = arr.count('z')
ans = [1] * one + [0] * zero
print(*ans)
return 0
main()
``` | vfc_5922 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1220/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\nezor\n",
"output": "0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\nnznooeeoer\n",
"output": "1 1 0 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2095 | Solve the following coding problem using the programming language python:
A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p_1, p_2, ..., p_... | ```python
input()
A = list(map(int, input().split(' ')))
root=-1
for i,a in enumerate(A) :
if i == a-1 :
root = i
break
v = [False]*len(A)
if root>-1 :
v[root]=True
ans= 0
for i,a in enumerate(A) :
if v[i] :
continue
v[i]= True
l=[i]
a-=1
while not v[a] :
l.ap... | vfc_5926 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/698/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n2 3 3 4\n",
"output": "1\n2 3 4 4 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 2 2 5 3\n",
"output": "0\n3 2 2 5 3 \n",
"type": "stdin_stdout"
},
{
"f... |
apps | verifiable_code | 2096 | Solve the following coding problem using the programming language python:
You are given a sequence a_1, a_2, ..., a_{n} consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequenc... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(input())
b=list(map(int,input().split()))
bb=sorted(b)
c={bb[i]:i for i in range(n)}
a=[c[b[i]] for i in range(n)]
vis=[0]*n
out=[]
for i in range(n):
if vis[i]: continue
vis[i]=1
newlist=[i]
while a[newlist[-1]]!=i:
... | vfc_5930 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/843/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6\n3 2 1 6 5 4\n",
"output": "4\n2 1 3\n1 2\n2 4 6\n1 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n83 -75 -49 11 37 62\n",
"output": "1\n6 1 2 3 4 5 6\n",
"type": "stdi... |
apps | verifiable_code | 2097 | Solve the following coding problem using the programming language python:
DZY loves planting, and he enjoys solving tree problems.
DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge ... | ```python
n = int(input())
edges = [[int(x) for x in input().split()] for i in range(n-1)]
edges = sorted(edges)
use_count = [0]+[int(input()) for i in range(n)]
lo,hi = 0,10000
def getpar(par,u):
if par[par[u]] == par[u]:
return par[u]
par[u] = getpar(par,par[u])
return par[u]
def unite(par,sz,use,... | vfc_5934 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/444/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n",
"output": "3\n",
"type": "stdin_stdou... |
apps | verifiable_code | 2098 | Solve the following coding problem using the programming language python:
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the numbe... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,m=list(map(int,input().split()))
party=[[] for _ in range(m+5)]
pc=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1])
choose=[0]*n
for i in range(n):
party[pc[i][0]].append(i)
want=10**18
for i in range(1,n+... | vfc_5938 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1019/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 2\n1 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n",
"output": "500\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2099 | Solve the following coding problem using the programming language python:
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}.
Your task is to find such permutation ... | ```python
3
import sys
def __starting_point():
n, k = list(map(int, sys.stdin.readline().split()))
l = []
i = 1
j = k + 1
while i <= j:
l.append(str(i))
i += 1
if j > i:
l.append(str(j))
j -= 1
for i in range(k+2, n+1):
l.append(str(... | vfc_5942 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/482/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 2\n",
"output": "1 3 2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 1\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": ... |
apps | verifiable_code | 2100 | Solve the following coding problem using the programming language python:
There are $n$ water tanks in a row, $i$-th of them contains $a_i$ liters of water. The tanks are numbered from $1$ to $n$ from left to right.
You can perform the following operation: choose some subsegment $[l, r]$ ($1\le l \le r \le n$), and r... | ```python
n = int(input())
l = list(map(int, input().split()))
stack = []
for v in l:
currVal = v
currSize = 1
div = v
while stack:
nex, nexS, nDiv = stack[-1]
if div < nDiv:
currSize += nexS
currVal += nex
stack.pop()
div = currVal... | vfc_5946 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1299/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n7 5 5 7\n",
"output": "5.666666667\n5.666666667\n5.666666667\n7.000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n7 8 8 10 12\n",
"output": "7.000000000\n8.000000000\n8... |
apps | verifiable_code | 2101 | Solve the following coding problem using the programming language python:
Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph.
It is an undirected weighted ... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
N, M = list(map(int, input().split()))
D = [{} for _ in range(N)]
for _ in range(M):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
D[a][b] = 1
D[b][a] = 1
L = [i-1 for i in range(N)]
R = [i+1 for i in range(N)]
F = [0] * N
... | vfc_5950 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1242/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 0\n",
"output": "0\n",
"type": "stdin_stdout"
... |
apps | verifiable_code | 2102 | Solve the following coding problem using the programming language python:
John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3.
A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, s... | ```python
k = int(input())
p = [['0'] * 100 for j in range(100)]
g = lambda n: n * (n * n - 1) // 6
i = n = 0
while g(n + 1) <= k: n += 1
while i < n + 1:
for j in range(i): p[i][j] = p[j][i] = '1'
i += 1
k -= g(n)
g = lambda n: n * n - n >> 1
while k:
n = 0
while g(n + 1) <= k: n += 1
for j in rang... | vfc_5954 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/232/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n",
"output": "3\n011\n101\n110\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "10\n",
"output": "5\n01111\n10111\n11011\n11101\n11110\n",
"type": "stdin_stdout"
},
{... |
apps | verifiable_code | 2103 | Solve the following coding problem using the programming language python:
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of n narrow islands located in a row. For more com... | ```python
#!/usr/bin/env python
# 556D_fug.py - Codeforces.com 556D Fug quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses... | vfc_5958 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/555/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n",
"output": "Yes\n2 3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n11 14\n17 18\n2 9\n",
"output": "No\n",
"type": "stdin_stdou... |
apps | verifiable_code | 2104 | Solve the following coding problem using the programming language python:
Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.
Strictly speaking, it makes a photo of all points with coordinates... | ```python
#
import collections, atexit, math, sys
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )
sys.setrecursionlimit(1000000)
def getIntList():
return list(map(int, input().split()))
import bisect
try :
#raise ModuleNotFoundError
import numpy
def dp... | vfc_5962 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1012/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n4 1 3 2 3 2 1 3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n5 8 5 5 7 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2105 | Solve the following coding problem using the programming language python:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.
... | ```python
3
n = int(input())
a = [True] * (n + 2)
for i in range(2, n + 2):
if not a[i]:
continue
j = i * i
while j < n + 2:
a[j] = False
j += i
if n <= 2:
print(1)
else:
print(2)
print(' '.join('1' if x else '2' for x in a[2:]))
``` | vfc_5966 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/776/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2\n1 1 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n",
"output": "2\n1 1 2 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"in... |
apps | verifiable_code | 2106 | Solve the following coding problem using the programming language python:
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top ... | ```python
p, n = [], int(input())
a = b = 0
for i in range(n):
t = list(map(int, input().split()))
k = t[0] // 2 + 1
a += sum(t[1: k])
if t[0] & 1:
p.append(t[k])
b += sum(t[k + 1: ])
else: b += sum(t[k: ])
p.sort(reverse = True)
print(a + sum(p[0 :: 2]), b + sum(p[1 :: 2]))
``` | vfc_5970 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/388/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 100\n2 1 10\n",
"output": "101 10\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n9 2 8 6 5 9 4 7 1 3\n",
"output": "30 15\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2107 | Solve the following coding problem using the programming language python:
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Ups... | ```python
def main():
s = input()
l = len(s)
pretty_count = 0
for i in range(l):
left_paren_count = 0
right_paren_count = 0
wild_count = 0
for j in range(i, l):
if s[j] == '(':
left_paren_count += 1
elif s[j] == ')':
... | vfc_5974 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/917/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "((?))\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "??()??\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "??... |
apps | verifiable_code | 2108 | Solve the following coding problem using the programming language python:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two po... | ```python
import sys
s1, s2 = input().split()
n = int(input())
for _ in range(n):
print(s1, s2)
killed, new = input().split()
if s1 == killed:
s1 = new
else:
s2 = new
print(s1, s2)
``` | vfc_5978 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/776/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2109 | Solve the following coding problem using the programming language python:
10^{10^{10}} participants, including Takahashi, competed in two programming contests.
In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th.
The score of a participant is the product of his/her ranks in the two ... | ```python
def i1():
return int(input())
def i2():
return [int(i) for i in input().split()]
q=i1()
import math
y=[]
for i in range(q):
y.append(i2())
for a,b in y:
x=a*b
c=int(math.sqrt(x))
if c**2==x:
c-=1
z=2*c
if c>0 and (x//c)==c:
z-=1
if c>0 and x%c==0 and (x//c-1)==c:
z-=1
if a<=c:
z-=1
if... | vfc_5982 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://atcoder.jp/contests/arc094/tasks/arc094_b",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n",
"output": "1\n12\n4\n11\n14\n57\n31\n671644785\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "99\n207579013 207579013\n3... |
apps | verifiable_code | 2110 | Solve the following coding problem using the programming language python:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2^{w}_{i} pounds. In each step, Duff can lift some of the remaining weights and throw them... | ```python
n = int(input())
a = [int(x) for x in input().split()]
l = [0] * (10**6 + 100)
for x in a:
l[x] += 1
cur = 0
ans = 0
for x in l:
cur += x
if cur % 2:
ans += 1
cur //= 2
print(ans)
``` | vfc_5986 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/587/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 2 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n0 1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"... |
apps | verifiable_code | 2111 | Solve the following coding problem using the programming language python:
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i} — ... | ```python
import itertools
import bisect
n, A, cf, cm, m = [int(x) for x in input().split()]
skills = [int(x) for x in input().split()]
sorted_skills = list(sorted((k, i) for i, k in enumerate(skills)))
bottom_lift = [0 for i in range(n)]
for i in range(1, n):
bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills... | vfc_5990 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/613/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 5 10 1 5\n1 3 1\n",
"output": "12\n2 5 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 5 10 1 339\n1 3 1\n",
"output": "35\n5 5 5 \n",
"type": "stdin_stdout"
},
... |
apps | verifiable_code | 2112 | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ d... | ```python
n = int(input())
l = list(map(int, input().split()))
inv = 0
out = 0
mult = 1
for i in range(32):
curr = dict()
opp = 0
same = 0
for v in l:
if v ^ 1 in curr:
if v & 1:
opp += curr[v ^ 1]
else:
same += curr[v ^ 1]
... | vfc_5994 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1416/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 1 3 2\n",
"output": "1 0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "9\n10 7 9 10 7 5 5 3 5\n",
"output": "4 14\n",
"type": "stdin_stdout"
},
{
"fn_name"... |
apps | verifiable_code | 2113 | Solve the following coding problem using the programming language python:
Jeff has become friends with Furik. Now these two are going to play one quite amusing game.
At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p_1, p_2, ..., p_{n}. Then the guys take... | ```python
3
import sys
class CumTree:
def __init__(self, a, b):
self.a = a
self.b = b
self.count = 0
if a == b:
return
mid = (a + b) // 2
self.levo = CumTree(a, mid)
self.desno = CumTree(mid+1, b)
def manjsi(self, t):
if... | vfc_5998 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/351/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 2\n",
"output": "0.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n3 5 2 4 1\n",
"output": "13.000000\n",
"type": "stdin_stdout"
},
{
"fn_name": nu... |
apps | verifiable_code | 2114 | Solve the following coding problem using the programming language python:
DZY loves Physics, and he enjoys calculating density.
Almost everything has density, even a graph. We define the density of a non-directed graph (nodes and edges of the graph have some values) as follows: $\left\{\begin{array}{ll}{\frac{v}{e}} ... | ```python
"""
Codeforces Round 254 Div 1 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2... | vfc_6002 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/444/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 0\n1\n",
"output": "0.000000000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 1\n1 2\n1 2 1\n",
"output": "3.000000000000000\n",
"type": "stdin_stdout"
},
{... |
apps | verifiable_code | 2115 | Solve the following coding problem using the programming language python:
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d... | ```python
def Search(L,aa,x):
a=aa
b=len(L)
while(b-a>1):
i=(b+a)//2
if(L[i]>x):
b=i
elif(L[i]<x):
a=i
else:
return (i+1)-aa-1
return b-aa-1
import math
n,d=list(map(int,input().split()))
P=list(map(int,input().split()))
ans=0
for i ... | vfc_6006 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/251/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 3\n1 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2\n-3 -2 -1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2116 | Solve the following coding problem using the programming language python:
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose ... | ```python
m = int(input())
s = input().strip()
sa = [0] * len(s)
for i in range(len(s)):
sa[i] = ord(s[i]) - ord('a')
sa = [-1] + sa + [-1]
def check_value(sa, m, threshold):
prev_ind = 0
for i in range(len(sa)):
if sa[i] <= threshold:
if i - prev_ind <= m:
prev_ind = i
else:
return False
return ... | vfc_6010 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/724/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\ncbabc\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\nabcab\n",
"output": "aab\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
apps | verifiable_code | 2117 | Solve the following coding problem using the programming language python:
Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high.
[Image... | ```python
def read_data():
n = int(input())
hs = list(map(int, input().split()))
return n, hs
def solve(n, hs):
left = get_left_index(n, hs)
right = get_right_index(n, hs)
vals = [[] for i in range(n)]
for h, l, r in zip(hs, left, right):
vals[r - l - 2].append(h)
min_hs = []
... | vfc_6014 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/547/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "10\n1 2 3 4 5 4 3 2 1 6\n",
"output": "6 4 4 3 3 2 2 1 1 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n524125987 923264237 374288891\n",
"output": "923264237 524125987 374288... |
apps | verifiable_code | 2118 | Solve the following coding problem using the programming language python:
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile conta... | ```python
n = int(input())
arr = [int(input()) for i in range(n)]
b = [0 for i in range(n)]
s = 0
for i in range(n):
j = int((arr[i] << 1) ** 0.5)
if j * (j + 1) > (arr[i] << 1):
j -= 1
s ^= j
if s != 0:
print('NO')
else:
print('YES')
``` | vfc_6018 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/768/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n5\n",
"output": "NO",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n1\n2\n",
"output": "YES",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n... |
apps | verifiable_code | 2119 | Solve the following coding problem using the programming language python:
You are given an array consisting of n non-negative integers a_1, a_2, ..., a_{n}.
You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array a... | ```python
__author__ = 'Think'
n=int(input())
aints=[int(i) for i in input().split()]
permutes=[int(i)-1 for i in input().split()]
results=[0]
rebuilt={}
m=0
for numby in range(n-1, 0, -1):
p=permutes[numby]
below=False
above=False
if p-1 in rebuilt:
below=True
if p+1 in rebuilt:
above=True
if above and belo... | vfc_6022 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/722/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 2 5\n3 4 1 2\n",
"output": "5\n4\n3\n0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n4 2 3 5 1\n",
"output": "6\n5\n5\n1\n0\n",
"type": "stdin_stdout"
... |
apps | verifiable_code | 2120 | Solve the following coding problem using the programming language python:
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: Add the integer x_{i} to the first a_{i} el... | ```python
n = int(input())
a, b = [0] * (n + 2), [0] * (n + 2)
s, l = 0, 1
p = [0] * n
for i in range(n):
t = list(map(int, input().split()))
if t[0] == 1:
b[t[1] - 1] += t[2]
s += t[1] * t[2]
elif t[0] == 2:
a[l] = t[1]
l += 1
s += t[1]
else:
l -= 1
... | vfc_6026 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/283/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n2 1\n3\n2 3\n2 1\n3\n",
"output": "0.500000\n0.000000\n1.500000\n1.333333\n1.500000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3\n",
"output":... |
apps | verifiable_code | 2121 | Solve the following coding problem using the programming language python:
There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is h... | ```python
# -*- coding: utf-8 -*-
from time import perf_counter
from sys import stdin
def run(n, s):
m = 0
small = n // 2
for big in range(n-1, (n+1)//2-1, -1):
while small >= 0 and s[small] > s[big] / 2:
small -= 1
if small == -1:
break
#print(small, big)
... | vfc_6030 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/372/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2122 | Solve the following coding problem using the programming language python:
Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time.
Polycarp is good at marketing, so he has already collec... | ```python
from bisect import bisect_left, insort_left
a = []
n = int(input())
for _ in range(n):
#print(a)
s, d = list(map(int, input().split()))
if len(a) == 0:
print(s, s+d - 1)
a.append((s, s + d - 1))
continue
p = bisect_left(a, (s, s + d - 1))
#print('p', p)
ok = Tru... | vfc_6034 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/730/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n9 2\n7 3\n2 4\n",
"output": "9 10\n1 3\n4 7\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n",
"o... |
apps | verifiable_code | 2123 | Solve the following coding problem using the programming language python:
Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want t... | ```python
def evens(A):
n = len(A)
l = n//2-1; r = n//2
if len(A)%2 == 1: l+= 1
ans = [max(A[l], A[r])]
while r < n-1:
l-= 1; r+= 1
ans.append(max(ans[-1], A[l], A[r]))
return ans
def interleave(A, B):
q = []
for i in range(len(B)): q+= [A[i], B[i]]
if len(A) != len(... | vfc_6038 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/794/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2 3 5\n",
"output": "3 3 5 5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1000000000 1000000000 1000000000 1000000000 1\n",
"output": "1000000000 1000000000 1000000000 100... |
apps | verifiable_code | 2124 | Solve the following coding problem using the programming language python:
Niwel is a little golden bear. As everyone knows, bears live in forests, but Niwel got tired of seeing all the trees so he decided to move to the city.
In the city, Niwel took on a job managing bears to deliver goods. The city that he lives in ... | ```python
from collections import defaultdict, deque
adj = defaultdict(lambda: defaultdict(lambda: 0))
def bfs(graph, inicio, destino, parent):
parent.clear()
queue = deque()
queue.append([inicio, float("Inf")])
parent[inicio] = -2
while (len(queue)):
current, flow = queue.popleft()
... | vfc_6042 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/653/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 4 3\n1 2 2\n2 4 1\n1 3 1\n3 4 2\n",
"output": "1.5000000000\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 11 23\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n1 3 4\n2 4 5\n3 5 6\n1 4 2\n2 5 3\n1 5 2\... |
apps | verifiable_code | 2125 | Solve the following coding problem using the programming language python:
Wherever the destination is, whoever we meet, let's render this song together.
On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen tha... | ```python
# http://codeforces.com/problemset/problem/848/B
from collections import defaultdict
def get_dest(start, w, h):
if start[0] == 1:
return (str(start[1]), str(h))
else:
return (str(w), str(start[1]))
n, w, h = [int(x) for x in input().split()]
dancers = []
groups = defaultdict(list)
... | vfc_6046 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/848/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n",
"output": "4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3 2 3\n1 1 2\n2 ... |
apps | verifiable_code | 2126 | Solve the following coding problem using the programming language python:
For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisibl... | ```python
def Sieve(n):
ret = []
divlis = [-1] * (n+1)
flag = [True] * (n+1)
flag[0] = False
flag[1] = False
ind = 2
while ind <= n:
if flag[ind]:
ret.append(ind)
ind2 = ind ** 2
while ind2 <= n:
flag[ind2] = False
... | vfc_6050 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1349/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n10 24 40 80\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"i... |
apps | verifiable_code | 2127 | Solve the following coding problem using the programming language python:
There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two char... | ```python
class DisjointSet(object):
def __init__(self, n):
self.parent = list(range(n))
self.rank = [0] * n
self.num = n # number of disjoint sets
def union(self, x, y):
self._link(self.find_set(x), self.find_set(y))
def _link(self, x, y):
if x == y:
r... | vfc_6054 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/553/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": n... |
apps | verifiable_code | 2128 | Solve the following coding problem using the programming language python:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows ... | ```python
__author__ = 'Pavel Mavrin'
n = int(input())
a = [int(x) for x in input().split()]
s = 0
res = 0
for i in a:
if i == 0:
res += s
else:
s += 1
print(res)
``` | vfc_6058 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/383/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n0 0 1 0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 0 1 0 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
apps | verifiable_code | 2129 | Solve the following coding problem using the programming language python:
Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $n$ stations, enumerated from $1$ through $n$. The train occupies one station at a time and travels around the network of stations in a circ... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
mii=lambda:list(map(int,input().split()))
n,m=mii()
a=[0 for _ in range(n)]
c=[123456 for _ in range(n)]
for _ in range(m):
u,v=mii()
u%=n
v%=n
if v<u: v+=n
a[u]+=1
if c[u]>v: c[u]=v
ans=[]
for i in list(range(1,n))+[0]... | vfc_6062 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1129/A2",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n",
"output": "10 9 10 10 9 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 3\n1 2\n1 2\n1 2\n",
"output": "5 6 \n",
"type": "stdin_st... |
apps | verifiable_code | 2130 | Solve the following coding problem using the programming language python:
Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed th... | ```python
3
import sys
from functools import lru_cache
MOD = 1000000007
cnk = [[1 for i in range(1001)] for j in range(1001)]
for i in range(1, 1001):
for j in range(1, i):
cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j]
k = int(input())
cs = [int(input()) for i in range(k)]
ans = 1
sm = 0
for c in cs:
... | vfc_6066 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/553/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2\n2\n1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1\n2\n3\n4\n",
"output": "1680\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2131 | Solve the following coding problem using the programming language python:
There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An... | ```python
m = 1000000007
n = int(input())
a = list(map(int, input().split()))
print(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m)
``` | vfc_6070 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1025/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n-1 -1 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 -1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
apps | verifiable_code | 2132 | Solve the following coding problem using the programming language python:
Nauuo is a girl who loves drawing circles.
One day she has drawn a circle and wanted to draw a tree on it.
The tree is a connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$.
Nauuo wants t... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, sys.stdin.rea... | vfc_6074 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1172/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 2\n1 3\n2 4\n",
"output": "16",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 2\n1 3\n1 4\n",
"output": "24",
"type": "stdin_stdout"
},
{
"fn_name": null,... |
apps | verifiable_code | 2133 | Solve the following coding problem using the programming language python:
There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slot... | ```python
strings = int(input())
count = [0 for x in range(7)]
for k in range(strings):
s = input()
for index in range(7):
if s[index] == '1':
count[index] += 1
print(max(count))
``` | vfc_6078 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/847/G",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n0101010\n1010101\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n0101011\n0011001\n0110111\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2134 | Solve the following coding problem using the programming language python:
Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values writ... | ```python
from collections import defaultdict, deque
n = int(input())
adj = [[] for _ in range(n)]
v = [0] * n
l = list(map(int, input().split()))
for i, f in enumerate(l):
adj[f - 1].append(i + 1)
s = list(map(int, input().split()))
Q = deque([(0, s[0], s[0])])
ans = 0
flag = False
possible = True
while Q and p... | vfc_6082 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1098/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 1 1 1\n1 -1 -1 -1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 2 3 1\n1 -1 2 -1 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2135 | Solve the following coding problem using the programming language python:
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they sh... | ```python
from time import time
opposite = {
'N': 'S',
'S': 'N',
'E': 'W',
'W': 'E'
}
otr = str.maketrans(opposite)
bits = {
'N': 0,
'S': 1,
'E': 2,
'W': 3,
}
Q = 4294967291
def combine(h, v, q):
return (h<<2 | v) % q
def combinel(h, v, q, s):
return (v*s + h) % q
def f... | vfc_6086 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/607/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "7\nNNESWW\nSWSWSW\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\nNN\nSS\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2136 | Solve the following coding problem using the programming language python:
You are given a Young diagram.
Given diagram is a histogram with $n$ columns of lengths $a_1, a_2, \ldots, a_n$ ($a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$). [Image] Young diagram for $a=[3,2,2,2,1]$.
Your goal is to find the largest number ... | ```python
import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
BW = [0, 0]
for i in range(N):
a = A[i]
BW[i%2] += a//2
BW[(i+1)%2] += -(-a//2)
print(min(BW))
``` | vfc_6090 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1268/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n3 2 2 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n1 1 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2137 | Solve the following coding problem using the programming language python:
Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beaut... | ```python
n, k = map(int, input().split())
t = set(map(int, input().split()))
y = x = min(t)
t = list(t)
while True:
for i in t:
if i % x > k: x = i // (i // x + 1)
if y == x: break
y = x
print(y)
``` | vfc_6094 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/354/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "6 1\n3 6 10 12 13 16\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 3\n8 21 52 15 77\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"fn_name... |
apps | verifiable_code | 2138 | Solve the following coding problem using the programming language python:
You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then ... | ```python
print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO')
``` | vfc_6098 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/297/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "01011\n0110\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "0011\n1110\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2139 | Solve the following coding problem using the programming language python:
You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$).
Let's sort $p$ in non-d... | ```python
import sys
from sys import stdin
def modfac(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
in... | vfc_6102 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1444/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n1 4\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 1 2 1\n",
"output": "12",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
apps | verifiable_code | 2140 | Solve the following coding problem using the programming language python:
While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so tha... | ```python
n = int(input())
b = list(map(int, input().split()))
m, M = min(b), max(b)
if m == M:
if M == 0:
print('YES')
print(' '.join(['1' for i in range(n)]))
else:
print('NO')
else:
print('YES')
pos = list([i for i in range(n) if b[i] == M and b[i - 1] < M])[0]
a = [0 ... | vfc_6106 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1028/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n1 3 1 0\n",
"output": "YES\n7 3 8 7 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2141 | Solve the following coding problem using the programming language python:
Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from $1$ to $n$. Each of its vertices also has an integer $a_i$ written on it. For each vertex $i$, Evlampiy calculated $c_i$ — the number of vertices $j$ in the subtree of... | ```python
import sys
readline = sys.stdin.readline
def parorder(Edge, p):
N = len(Edge)
par = [0]*N
par[p] = -1
stack = [p]
order = []
visited = set([p])
ast = stack.append
apo = order.append
while stack:
vn = stack.pop()
apo(vn)
for vf in Edge[vn]:
... | vfc_6110 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1286/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n2 0\n0 2\n2 0\n",
"output": "YES\n1 3 2 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n0 1\n1 3\n2 1\n3 0\n2 0\n",
"output": "YES\n2 5 3 1 4 \n",
"type": "stdin_stdout"... |
apps | verifiable_code | 2142 | Solve the following coding problem using the programming language python:
Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to... | ```python
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
ans = [0]*n
for i in range(n):
for j in range(n):
if j!=i:
ans[i] |= a[i][j]
print(ans[i],end = ' ')
``` | vfc_6114 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/245/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1\n-1\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"output": "18 18 0 ",
"type": "stdin_stdout"
},
{
"fn_name":... |
apps | verifiable_code | 2143 | Solve the following coding problem using the programming language python:
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can b... | ```python
from bisect import *
n, tc, td = [int(i) for i in input().split()]
fc = []
fd = []
mbc = 0
mbd = 0
for _ in range(n):
b, p, ft = input().split()
b, p = int(b), int(p)
f = (p, b)
if ft == 'C':
if p <= tc:
fc.append(f)
mbc = max(mbc, b)
else:
if p <= ... | vfc_6118 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/799/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 7 6\n10 8 C\n4 3 C\n5 6 D\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 4 5\n2 5 C\n2 1 D\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
... |
apps | verifiable_code | 2144 | Solve the following coding problem using the programming language python:
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers.
There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the inte... | ```python
def main():
k = int(input())
n = []
a = []
for i in range(k):
line = [int(x) for x in input().split()]
ni = line[0]
ai = []
n.append(ni)
a.append(ai)
for j in range(ni):
ai.append(line[1 + j])
answer, c, p = solve(k, n, a)
if... | vfc_6122 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1242/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n",
"output": "Yes\n7 2\n2 3\n5 1\n10 4\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2\n2 3 -2\n2 -1 5\n",
"output": "No\n",
"type": "stdin_st... |
apps | verifiable_code | 2145 | Solve the following coding problem using the programming language python:
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string... | ```python
s = input()
t = input()
n = len(s)
m = len(t)
t = t + '$' + s
p = [0] * (n + m + 1)
k = 0
for i in range(1, n + m + 1):
while k > 0 and t[k] != t[i]:
k = p[k - 1]
if t[k] == t[i]:
k += 1
p[i] = k
ans = [0] * n
sums = [0] * (n + 1)
curs = 0
was = False
j = 0
MOD = 10 ** 9 + 7
fo... | vfc_6126 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/494/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "ababa\naba\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "welcometoroundtwohundredandeightytwo\nd\n",
"output": "274201\n",
"type": "stdin_stdout"
},
... |
apps | verifiable_code | 2146 | Solve the following coding problem using the programming language python:
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.
In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.
Du will chat in the group fo... | ```python
import sys
readline = sys.stdin.readline
N, D, M = map(int, readline().split())
A = list(map(int, readline().split()))
Am = [a for a in A if a > M]
Ao = [a for a in A if a <= M]
Am.sort(reverse = True)
Ao.sort(reverse = True)
Cam = Am[:]
Cao = Ao[:]
for i in range(1, len(Cam)):
Cam[i] += Cam[i-1]
for i ... | vfc_6130 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1394/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5 2 11\n8 10 15 23 5\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n",
"output": "195\n",
"type":... |
apps | verifiable_code | 2147 | Solve the following coding problem using the programming language python:
Ziota found a video game called "Monster Invaders".
Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns.
For the sake of simplicity, we only consider two different types of monsters and t... | ```python
n,r1,r2,r3,D = map(int,input().split())
state = [0,0] # after odd number of 2 (1st), or not (2nd)
a = list(map(int,input().split()))
# First element
# Choosing P~P + A
state[0] = r1 * a[0] + r3
# Choosing L + P later or all P
state[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D)
# Second to Second Last ele... | vfc_6134 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1396/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "4 1 3 4 3\n3 2 5 1\n",
"output": "34",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 2 4 4 1\n4 5 1 2\n",
"output": "31",
"type": "stdin_stdout"
},
{
"fn_name": n... |
apps | verifiable_code | 2148 | Solve the following coding problem using the programming language python:
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains ... | ```python
import sys
def binpow(a, n, p):
res = 1
while n > 0:
if n % 2 == 1:
res = (res * a) % p
a = (a * a) % p
n >>= 1
return res
def main():
result = []
t = int(sys.stdin.readline())
for line in sys.stdin.readlines():
p, q, b = list(map(int,... | vfc_6138 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/983/A",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2\n6 12 10\n4 3 10\n",
"output": "Finite\nInfinite\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n",
"output": "Finite\nFinite\nFinite\nInfinite\n",... |
apps | verifiable_code | 2149 | Solve the following coding problem using the programming language python:
You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\... | ```python
n, m = map(int, input().split())
a = set(map(int, input().split()))
y = 2 ** n
mk = [0] * (2 * y)
cur = 0
for x in a:
if mk[x]: continue
mk[x] = 1
st = [x]
while st:
u = st.pop()
if u < y:
if not mk[y + u]:
mk[y + u] = 1
st.append(y... | vfc_6142 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/986/C",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "2 3\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5 5\n5 19 10 20 12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
... |
apps | verifiable_code | 2150 | Solve the following coding problem using the programming language python:
In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ ... | ```python
import sys
input = sys.stdin.readline
MOD = 987654103
n = int(input())
t = input()
place = []
f1 = []
e1 = []
s = []
curr = 0
count1 = 0
for i in range(n):
c = t[i]
if c == '0':
if count1:
e1.append(i - 1)
if count1 & 1:
s.append(1)
c... | vfc_6146 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1320/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n",
"output": "Yes\nYes\nNo\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0\n1\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},... |
apps | verifiable_code | 2151 | Solve the following coding problem using the programming language python:
You are given an array $a$ of $n$ integers and an integer $s$. It is guaranteed that $n$ is odd.
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the med... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
med=a[n//2]
ans=0
if med>s:
for i in range(n//2+1):
if a[i]>s:
ans+=a[i]-s
elif med<s:
for i in range(n//2,n):
if s>a[i]:
... | vfc_6150 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1037/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 8\n6 5 8\n",
"output": "2",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "7 20\n21 15 12 11 20 19 12\n",
"output": "6",
"type": "stdin_stdout"
},
{
"fn_name": nul... |
apps | verifiable_code | 2152 | Solve the following coding problem using the programming language python:
This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems.
Christmas is coming, and our protagonist, Bob, is preparing a spectacular ... | ```python
# 素因数分解
def prime_decomposition(n):
i = 2
table = []
while i * i <= n:
while n % i == 0:
n //= i
table.append(i)
i += 1
if n > 1:
table.append(n)
return table
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().sp... | vfc_6154 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/1254/B1",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "... |
apps | verifiable_code | 2153 | Solve the following coding problem using the programming language python:
In order to fly to the Moon Mister B just needs to solve the following problem.
There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles.
W... | ```python
#!/usr/bin/env python3
from collections import defaultdict
DEBUG = False
def main():
if DEBUG:
test()
n = int(input())
paths = cycles(n)
print(len(paths))
for p in paths:
print('%d %s' % (len(p), ' '.join([str(v) for v in p])))
def cycles(n):
"""Builds a set of... | vfc_6158 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/819/E",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3\n",
"output": "2\n3 1 2 3\n3 1 2 3\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "5\n",
"output": "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n",
"type": "s... |
apps | verifiable_code | 2154 | Solve the following coding problem using the programming language python:
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this ... | ```python
k, q = list(map(int, input().split()))
t = [0] * (k + 1)
t[1] = 1
d = [0]
n = i = 1
while i < 1001:
if 2000 * t[k] > i - 1e-7:
d.append(n)
i += 1
else:
t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)]
n += 1
for i in range(q): print(d[int(inp... | vfc_6162 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/768/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "1 1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "2 2\n1\n2\n",
"output": "2\n2\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"inpu... |
apps | verifiable_code | 2155 | Solve the following coding problem using the programming language python:
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout a... | ```python
def main():
n, m = list(map(int, input().split()))
aa = []
for _ in range(n):
row = list(map(int, input().split()))
row.append(0)
aa.append(row)
aa.append([0] * (m + 1))
d1, d2, d3, d4 = ([[0] * (m + 1) for _ in range(n + 1)] for _ in (1, 2, 3, 4))
for i in rang... | vfc_6166 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/429/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "3 3\n100 100 100\n100 1 100\n100 100 100\n",
"output": "800",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 1... |
apps | verifiable_code | 2156 | Solve the following coding problem using the programming language python:
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they... | ```python
n = int(input())
ans = 'YES\n'
for i in range(n):
x1, y1, x2, y2 = map(int, input().split())
res = (x1 & 1) * 2 + (y1 & 1) + 1
ans += str(res) + '\n'
print(ans)
``` | vfc_6170 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/763/B",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n",
"output": "YES\n1\n4\n3\n2\n3\n3\n2\n1\n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "1\n0 0 1 1\... |
apps | verifiable_code | 2157 | Solve the following coding problem using the programming language python:
You are given a set Y of n distinct positive integers y_1, y_2, ..., y_{n}.
Set X of n distinct positive integers x_1, x_2, ..., x_{n} is said to generate set Y if one can transform X to Y by applying some number of the following two operation ... | ```python
def main():
from heapq import heapify, heapreplace
input()
s = set(map(int, input().split()))
xx = [-x for x in s]
heapify(xx)
while True:
x = -xx[0]
while x != 1:
x //= 2
if x not in s:
s.add(x)
heapreplace(xx, -x... | vfc_6174 | {
"difficulty": "competition",
"memory_limit": null,
"memory_limit_bytes": null,
"problem_url": "https://codeforces.com/problemset/problem/722/D",
"time_limit": "None"
} | {
"language": "python",
"test_cases": [
{
"fn_name": null,
"input": "5\n1 2 3 4 5\n",
"output": "4 5 2 3 1 \n",
"type": "stdin_stdout"
},
{
"fn_name": null,
"input": "6\n15 14 3 13 1 12\n",
"output": "12 13 14 7 3 1 \n",
"type": "stdin_stdout"
},
{... |
Subsets and Splits
Random Hard Python Problems
Retrieves a random sample of 10 hard difficulty questions along with their answers and problem IDs, providing basic filtering but limited analytical value.