problem_id
stringlengths
32
32
name
stringlengths
2
112
problem
stringlengths
200
14k
test_cases
stringlengths
33
79.2M
difficulty
stringclasses
34 values
language
listlengths
1
1
source
stringclasses
15 values
num_solutions
int64
1
1.12M
starter_code
stringlengths
0
1.47k
subset
stringclasses
4 values
reasoning
stringlengths
1.09k
133k
deepseek_solution
stringlengths
60
15k
correctness
bool
2 classes
reason
stringclasses
3 values
ae083f1956b67b67e4911b0d0a0c0ecf
Preparing for Merge Sort
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 one sorted array. Ivan represent his array with increasing sequences with...
{"inputs": ["5\n1 3 2 5 4", "4\n4 3 2 1", "4\n10 30 50 101", "1\n1", "1\n200000", "2\n1 2", "2\n2 1", "2\n1 200000", "2\n200000 1", "10\n71550121 446173607 640274071 402690754 802030518 598196518 796619138 96204862 983359971 799843967", "3\n1 100 1000000000", "3\n1000000000 100 1"], "outputs": ["1 3 5 \n2 4 ", "4 \n3 \...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
32
codeforces
Okay, I need to solve this problem where Ivan's algorithm splits the array into increasing sequences according to a specific process. Let's read the problem statement carefully. So the algorithm is: while there are unused numbers, iterate left to right, and collect numbers that are either the first unused or greater t...
To solve this problem, we need to determine how Ivan's array can be split into increasing sequences according to a specific algorithm. The algorithm repeatedly forms increasing sequences by iterating through the array from left to right, collecting unused numbers that form an increasing sequence in each pass. The goal ...
true
ae0fdc5010d3494e36f04cc00ad43570
Cutting
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
{"inputs": ["6 4\n1 2 5 10 15 20", "4 10\n1 3 2 4", "6 100\n1 2 3 4 5 6", "2 100\n13 78", "10 1\n56 56 98 2 11 64 97 41 95 53", "10 100\n94 65 24 47 29 98 20 65 6 17", "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
234
codeforces
Okay, let's see. The problem is about cutting a sequence of integers into segments where each segment has an equal number of even and odd numbers. And we need to do this with the maximum number of cuts possible without exceeding the budget B. The cost of each cut is the absolute difference between the two adjacent elem...
To solve this problem, we need to determine the maximum number of cuts that can be made on a sequence of integers such that each resulting segment has an equal number of even and odd integers, while staying within a given budget for the cost of the cuts. ### Approach 1. **Identify Valid Cut Positions**: Traverse the s...
true
ae1ae244542fda4e96c524e9b099768c
President and Roads
Berland has *n* cities, the capital is located in city *s*, and the historic home town of the President is in city *t* (*s*<=≠<=*t*). The cities are connected by one-way roads, the travel time for each of the road is a positive integer. Once a year the President visited his historic home town *t*, for which his motorc...
{"inputs": ["6 7 1 6\n1 2 2\n1 3 10\n2 3 7\n2 4 8\n3 5 3\n4 5 2\n5 6 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 100", "2 2 1 2\n1 2 1\n1 2 2", "2 1 1 2\n1 2 1", "3 3 1 3\n1 2 10\n2 3 10\n1 3 19", "4 3 1 4\n1 2 1\n2 3 1\n3 4 1", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 2", "4 4 1 4\n1 2 1\n2 3 1\n3 4 1\n1 3 1", "6 6 1 6\n1 2 2\n2 3 4\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's tackle this problem. Hmm. The problem statement is a bit complex, so I need to parse it carefully. So, the task is for each road, determine whether it's part of all shortest paths from s to t. If not, can we repair it (increase or decrease its length, but not below 1) such that it becomes part of every sho...
To solve this problem, we need to determine if each road in Berland is part of all shortest paths from the capital city to the President's historic home town. If not, we need to check if it can be repaired to be part of all shortest paths with the minimum cost. ### Approach 1. **Compute Shortest Paths**: Use Dijkstra'...
false
Code is incorrect.
ae4d4ce41de468ab0ba2162a03886e45
Imbalance Value of a Tree
You are given a tree *T* consisting of *n* vertices. A number is written on each vertex; the number written on vertex *i* is *a**i*. Let's denote the function *I*(*x*,<=*y*) as the difference between maximum and minimum value of *a**i* on a simple path connecting vertices *x* and *y*. Your task is to calculate . The f...
{"inputs": ["4\n2 2 3 1\n1 2\n1 3\n1 4"], "outputs": ["6"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, so I've got this programming problem to solve. Let's read through it carefully. The problem is about a tree where each vertex has a number, and we need to calculate the sum of I(x, y) for all pairs of vertices x and y, where I(x,y) is the difference between the maximum and minimum values on the path between x and...
To solve this problem, we need to compute the sum of differences between the maximum and minimum values on all simple paths in a tree. Given the constraints, an efficient approach is necessary to avoid an O(n^2) solution. ### Approach 1. **Problem Analysis**: The key insight is to split the problem into two parts: sum...
true
ae50d398ed874b0841e12d0650f2eb68
Harry Potter and Three Spells
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams o...
{"inputs": ["100 200 250 150 200 250", "100 50 50 200 200 100", "100 10 200 20 300 30", "0 0 0 0 0 0", "1 1 0 1 1 1", "1 0 1 2 1 2", "100 1 100 1 0 1", "1 1 2 2 1 1", "4 4 1 3 1 4", "3 3 2 1 4 4", "5 1 2 9 1 10", "63 65 21 41 95 23", "913 0 0 0 0 0", "0 333 0 0 0 0", "842 538 0 0 0 0", "0 0 536 0 0 0", "324 0 495 0 0 0...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
21
codeforces
Okay, let's tackle this problem step by step. So, the goal is to determine if it's possible to get an infinite amount of gold starting from a finite amount of sand. If that's possible, we print "Ron"; otherwise, "Hermione". Hmm, the problem revolves around three transformations. Let's think about how these transforma...
To solve this problem, we need to determine if it is possible to generate an infinite amount of gold starting from a finite amount of sand using three specific spells. The solution involves checking several conditions to see if any combination of the spells can lead to an infinite increase in gold. ### Approach The ap...
true
ae7533016ff1ec3e7dabb9774657d2da
Orientation of Edges
Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices. Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans: 1. to orient each undirected edge in one of two possible directions to maximiz...
{"inputs": ["2 2 1\n1 1 2\n2 2 1", "6 6 3\n2 2 6\n1 4 5\n2 3 4\n1 4 1\n1 3 1\n2 2 3", "5 5 5\n2 5 3\n1 2 3\n1 4 5\n2 5 2\n1 2 1", "13 18 9\n2 3 10\n1 12 10\n1 11 4\n2 2 8\n1 5 1\n1 7 12\n1 5 13\n1 9 7\n1 10 11\n2 3 12\n1 9 2\n1 3 9\n1 8 12\n2 11 3\n1 3 1\n1 8 4\n2 9 11\n1 12 13", "5 10 2\n2 2 4\n1 1 2\n2 2 3\n1 3 1\n1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, I need to solve this problem where I have to find two orientations for the undirected edges in a graph such that one maximizes the number of reachable vertices from s and the other minimizes it. Let's break this down. First, let's understand the problem. The graph has both directed and undirected edges. For each...
To solve this problem, we need to determine two different orientations for the undirected edges in a graph such that one maximizes the number of vertices reachable from a given vertex *s*, and the other minimizes it. The solution involves two main steps: one for maximizing the reachable vertices and another for minimiz...
false
Code is incorrect.
aeabf288c17b785fce5cd0529c46eca2
none
Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, которые пришли вовремя, вам предстоит определить номер опоздавшего бра...
{"inputs": ["3 1", "2 1", "2 3", "1 2", "1 3", "3 2"], "outputs": ["2", "3", "1", "3", "2", "1"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
57
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. So, there are three brothers numbered 1, 2, 3. One of them is late, and the other two arrived on time. The input gives two distinct integers a and b (each between 1 and 3, and different), which are the numbers of the brothers w...
To solve this problem, we need to determine which of the three brothers arrived late based on the given numbers of the two brothers who arrived on time. The solution involves a straightforward mathematical approach to identify the missing brother's number. ### Approach 1. **Understand the Problem**: Three brothers are...
true
aecef1b89d6a39bf7b952679007eaaa3
Generous Kefa
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his...
{"inputs": ["4 2\naabb", "6 3\naacaab", "2 2\nlu", "5 3\novvoo", "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "100...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
374
codeforces
Okay, let's see. The problem is to determine if Kefa can distribute all the balloons to his friends such that no friend gets two balloons of the same color. Hmm. So each friend can have at most one balloon of each color. Wait, no, wait. Wait, the problem says a friend will be upset if they get two balloons of the same ...
To solve this problem, we need to determine if Kefa can distribute all his balloons to his friends such that no friend receives two balloons of the same color. Each friend can receive at most one balloon of each color. The key insight is that if any color appears more times than there are friends, it's impossible to di...
true
aee0924b4cca049564aa0eadf0161593
Naughty Stone Piles
There are *n* piles of stones of sizes *a*1,<=*a*2,<=...,<=*a**n* lying on the table in front of you. During one move you can take one pile and add it to the other. As you add pile *i* to pile *j*, the size of pile *j* increases by the current size of pile *i*, and pile *i* stops existing. The cost of the adding opera...
{"inputs": ["5\n2 3 4 1 1\n2\n2 3", "2\n2 9\n5\n4 10 7 3 4", "1\n7\n4\n6 2 3 3", "2\n7 10\n2\n2 4", "1\n10\n5\n5 3 7 7 1", "1\n2\n5\n7 3 9 8 1", "4\n8 10 4 4\n3\n7 8 1", "2\n7 9\n1\n9", "3\n4 5 4\n2\n10 2", "3\n1 6 8\n1\n6", "2\n9 3\n1\n6", "5\n9 5 7 3 3\n1\n3", "2\n7 4\n1\n7", "4\n7 4 1 7\n3\n6 8 3", "3\n3 7 3\n1\n5",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's tackle this problem. Hmm, the task is to find the minimum cost for each query k, which represents the maximum number of times a pile can be added to. The cost is the sum of the sizes of the piles being moved. So the goal is to merge all piles into one with the minimal total cost, considering that each pile ...
To solve this problem, we need to determine the minimum cost required to merge all stone piles into one pile for each query value of k. The cost of merging a pile into another is the size of the pile being merged, and each pile can be merged into another pile at most k times. ### Approach 1. **Sort the Piles**: First,...
true
aef94126262696add047250d8bd2e8b3
Comparing Strings
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
{"inputs": ["ab\nba", "aa\nab", "a\nza", "vvea\nvvae", "rtfabanpc\natfabrnpc", "mt\ntm", "qxolmbkkt\naovlajmlf", "b\ng", "ab\naba", "ba\na", "a\nab", "a\naa", "a\nz", "aabb\nbbaa", "ab\nbd", "bac\ndae", "abc\nakl", "cb\naa", "abaab\naabba", "aab\naaa", "abcde\nedcba", "abab\nbaba", "ab\nbac", "abcd\naqcb", "abc\nbad", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
225
codeforces
Okay, I need to solve this problem where I have to determine if two given genomes belong to the same race. The condition is that by swapping exactly two characters in the first genome, we can get the second genome. Hmm, right. First, let's understand the problem. The two genomes must be the same length, right? Because...
To solve this problem, we need to determine if two given genomes belong to the same race of dwarves. Two genomes belong to the same race if we can swap exactly two characters in the first genome to make it identical to the second genome. ### Approach 1. **Check Lengths**: If the two genomes have different lengths, the...
true
aefa85430ea1173192e6b6f9c74fd279
Stock Trading
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next *n* days and wants to design...
{"inputs": ["10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9", "2 1\n2\n1"], "outputs": ["15", "21", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this problem where Manao wants to maximize his profit from stock trading with certain constraints. Let's read the problem carefully. The constraints are: he can own at most one share at a time. He can buy or sell once per day. And he can make at most k buy orders. Each trade is buying on day i an...
To solve this problem, we need to maximize the profit from trading stocks under the constraints of being able to make at most `k` non-overlapping trades. Each trade consists of buying a stock on a certain day and selling it on a subsequent day, and you can only hold one share at a time. ### Approach 1. **Identify Vall...
false
Code is incorrect.
af5f04d22de82fd87cf9bb229eab8480
Coupons and Discounts
The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial. As the training sessions lasts for several hours, teams become hungry. Thu...
{"inputs": ["4\n1 2 1 2", "3\n1 0 1", "3\n1 3 1", "3\n2 0 2", "1\n179", "10\n0 0 5 9 9 3 0 0 0 10", "3\n3 2 3", "1\n0", "2\n0 0", "10\n0 0 0 0 0 0 0 0 0 0", "1\n1", "1\n2", "1\n3", "1\n10000", "2\n10000 10000", "3\n2 2 2", "10\n3 3 3 2 2 2 2 2 2 3", "100\n2 3 2 3 3 3 3 3 3 2 2 2 2 2 2 3 2 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
Okay, let's see. The problem is about determining whether Sereja can order the exact number of pizzas each day using only the two types of discounts. The discounts are such that each day he can buy pizzas either as pairs (two per discount) or use coupons that span two consecutive days (so two pizzas in total for those ...
To solve this problem, we need to determine if Sereja can order the exact number of pizzas each day using only two types of discounts: buying two pizzas on the same day (discount) and using coupons that cover two consecutive days. The key challenge is to ensure that no coupons are active after the last day. ### Approa...
false
Code is incorrect.
af6fd1f8b47ad4a8cb5edd3e6f27bd47
Big Secret
Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence $a_1, \ldots, a_n$. In order to not reveal the secret earlier than needed, Vitya encrypted the answer and obtained the sequence $b_1, \ldots, b_n$ using the foll...
{"inputs": ["3\n1 2 3", "6\n4 7 7 12 31 61", "1\n4", "2\n531 108", "5\n3 1 1 7 1", "10\n10 1 1 1 1 1 3 6 7 3", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 7 7 7 7 15 15 31"], "outputs": ["No", "Yes\n4 12 7 31 7 61 ", "Yes\n4 ", "Yes\n108 531 ", "Yes\n1 3 1 7 1 ", "No", "Yes\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. So the problem is about finding a permutation of the given array b such that when we compute the a_i's as the prefix XOR of the permutation, the a sequence is strictly increasing. If no such permutation exists, output No. Otherwise, outp...
To solve this problem, we need to find a permutation of the given array such that the sequence formed by the prefix XOR of the permutation is strictly increasing. The solution involves grouping elements by their highest set bit and processing these groups in a specific order to ensure the resulting sequence meets the r...
false
Code is incorrect.
af8e776ecce3012c92468d9f26c336ae
Polycarp and Div 3
Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there will be $m+1$ parts in tot...
{"inputs": ["3121", "6", "1000000000000000000000000000000000", "201920181", "4", "10", "11", "12", "13", "31", "14139582796", "1670000", "604500", "40041", "10000170"], "outputs": ["2", "1", "33", "4", "0", "1", "0", "1", "1", "1", "6", "5", "5", "2", "5"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
38
codeforces
Okay, let's tackle this problem. The goal is to find the maximum number of parts we can split the given number into, such that each part is divisible by 3 and doesn't have leading zeros unless it's a single zero. Hmm, right. First, I remember that a number is divisible by 3 if the sum of its digits is divisible by 3. ...
To solve this problem, we need to find the maximum number of vertical cuts in a given number such that each resulting part is divisible by 3 and does not have leading zeros unless it is a single zero. The solution involves dynamic programming and tracking the sum of digits modulo 3 to efficiently determine valid splits...
false
Code is incorrect.
afb4ecc56a557ebea6c5c2cc817dade9
New Year Permutation
User ainta has a permutation *p*1,<=*p*2,<=...,<=*p**n*. As the New Year is coming, he wants to make his permutation as pretty as possible. Permutation *a*1,<=*a*2,<=...,<=*a**n* is prettier than permutation *b*1,<=*b*2,<=...,<=*b**n*, if and only if there exists an integer *k* (1<=≤<=*k*<=≤<=*n*) where *a*1<==<=*b*1,...
{"inputs": ["7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000", "5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010", "7\n1 7 6 4 2 3 5\n0000100\n0000010\n0000001\n0000000\n1000000\n0100000\n0010000", "15\n6 1 2 7 9 13 14 8 4 5 3 12 10 15 11\n000100100100100\n000010010010010\n000001001001001...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
Okay, let's see. I need to find the lexicographically smallest permutation possible by swapping elements according to the given adjacency matrix A. The problem says that we can swap two elements only if A[i][j] is 1, and this can be done multiple times as long as the swaps are connected through the allowed swaps. So th...
To solve this problem, we need to find the lexicographically smallest permutation possible by swapping elements according to a given adjacency matrix. The key insight is to determine the connected components of the graph formed by the adjacency matrix and then rearrange elements within each component to achieve the sma...
true
afc137fa5a962d684a56715dbca760b3
Building Bridge
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines *x*<==<=*a* and *x*<==<=*b* (0<=&lt;<=*a*<=&lt;<=*b*). The west village lies i...
{"inputs": ["3 2 3 5\n-2 -1 4\n-1 2\n7 3", "1 1 10 20\n5\n-5\n1", "2 2 1 2\n-1 10\n8 9\n3 7", "10 20 50 60\n-96 -75 32 37 42 43 44 57 61 65\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 25 32 51 73 88 94 100\n138 75 132 116 49 43 96 166 96 161 146 112 195 192 201 186 251 254 220 227"], "outputs": ["2 2", "1 1", "1 1", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's see. I need to find the pair of points Ai and Bj such that the total distance from O to Ai, then Ai to Bj (the bridge), plus the length lj of the path from Bj to the eastern village is minimized. Hmm. So the total distance is |OAi| + |AiBj| + lj. Oh right, O is (0,0), Ai is (a, yi), Bj is (b, y'j). So OAi ...
To solve this problem, we need to determine the optimal points on the west and east banks of a river to build a bridge such that the total distance between the two villages is minimized. The distance includes the path from the west village to the bridge, the bridge itself, and the path from the bridge to the east villa...
true
afd400a266998a37cdf2ef78c5bccf81
New Year and Counting Cards
Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a c...
{"inputs": ["ee", "z", "0ay1", "0abcdefghijklmnopqrstuvwxyz1234567896", "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b", "01234567890123456789012345678901234567890123456789", "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb", "cjw2dwmr10pku4yxohe0wglktd", "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6", "kaq7jyialrfp4ilkni90e...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
516
codeforces
Okay, let's see. The problem is about determining the minimum number of cards to flip to check if all cards satisfy a certain condition. The condition is that if a card has a vowel on one side, then the other side must be an even digit. So, the main goal is to find out which cards could potentially violate this conditi...
To solve this problem, we need to determine the minimum number of cards to flip in order to verify that all cards satisfy the condition: "If a card has a vowel on one side, then it has an even digit on the other side." ### Approach 1. **Understanding the Problem**: The key insight is that we need to check cards that ...
true
afe46d2a54a9a4ad277b0a9335a8c557
Level Generation
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level. Ivan decided that there should be exactly *n**i* vertices in the graph representing level *i*, and the edges have to be bidirectional. ...
{"inputs": ["3\n3\n4\n6", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "1\n212055293", "1\n508427854", "1\n398561321", "1\n322647200", "1\n827388716", "1\n596007358"], "outputs": ["2\n3\n6", "0\n1\n2\n3\n4\n6\n7\n8\n10\n12", "424069398", "1016791932", "797066176", "645243594", "1654696074", "1191945664"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's tackle this problem. The task is to find, for each n_i, the maximum number of edges in a graph where at least half of them are bridges. And we need to do this efficiently because the input size is up to 1e5 and n_i can be as big as 2e9. Hmm. So first, I need to understand the structure of such a graph. Bri...
To solve this problem, we need to determine the maximum number of edges in a graph with `n` vertices such that at least half of the edges are bridges. Bridges are edges that, if removed, would increase the number of connected components in the graph. ### Approach 1. **Understanding Bridges and Graph Structure**: Brid...
false
Code is incorrect.
aff24e43df4b5d490c24e19139f73783
Secret
The Greatest Secret Ever consists of *n* words, indexed by positive integers from 1 to *n*. The secret needs dividing between *k* Keepers (let's index them by positive integers from 1 to *k*), the *i*-th Keeper gets a non-empty set of words with numbers from the set *U**i*<==<=(*u**i*,<=1,<=*u**i*,<=2,<=...,<=*u**i*,<=...
{"inputs": ["11 3", "5 2", "2 2", "3 2", "6 2", "1000000 333333", "999999 333334", "9 3", "365561 47560", "950059 292110", "20354 1334", "365561 143151", "119057 33031", "189351 39909", "773849 154607", "950059 419028", "844143 181133", "942846 251898", "13141 3789", "20354 8642", "999999 333333", "18 6", "10 2"], "out...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's tackle this problem step by step. So the problem is to partition n words into k subsets such that each subset meets certain conditions. The main conditions are that the subsets are non-overlapping, cover all words, and each subset's elements do not form an arithmetic progression. Also, each subset must have...
To solve this problem, we need to partition the set of words into subsets such that each subset meets specific conditions. The conditions are that each subset must be non-empty, the union of all subsets must cover all words, and no subset can form an arithmetic progression. ### Approach 1. **Check Feasibility**: If t...
false
Code is incorrect.
aff9b4bab8c8ff94a6fa629c6d9832f9
Appleman and Easy Task
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells...
{"inputs": ["3\nxxo\nxox\noxx", "4\nxxxo\nxoxo\noxox\nxxxx", "1\no", "2\nox\nxo", "2\nxx\nxo", "3\nooo\noxo\nxoo", "3\nxxx\nxxo\nxxo", "4\nxooo\nooxo\noxoo\nooox", "4\noooo\noxxo\nxoxo\noooo", "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxo...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
235
codeforces
Okay, let's see. The problem is to determine whether every cell on the checkerboard has an even number of adjacent 'o's. Hmm. So for each cell, we need to check all four possible adjacent cells (up, down, left, right) and count how many of them are 'o'. Then, each of these counts must be even. If even one cell has an o...
To solve this problem, we need to determine if every cell on an n×n checkerboard has an even number of adjacent cells containing the character 'o'. Adjacent cells are those that share a side (up, down, left, right). ### Approach 1. **Input Reading**: Read the input which consists of multiple test cases. Each test cas...
true
b01311449213ba97ff7f23f86f7275cb
Magic Trick
Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal dec...
{"inputs": ["2 2", "4 4", "1 2", "2 1", "10 10", "1000 1000", "1 1", "987 123", "999 999", "1 999", "998 1", "2 987", "555 543", "321 123", "2 3", "461 1000", "678 231"], "outputs": ["0.6666666666666666", "0.4000000000000000", "1.0000000000000000", "0.5000000000000000", "0.1818181818181818", "0.0019980019980020", "1", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
26
codeforces
Okay, let's try to figure out this problem. So, the problem is about calculating the probability that Alex's magic trick is successful, assuming he just picks a card at random. Let me break it down step by step. First, the setup: Alex has m identical decks, each with n different cards. These are all mixed together. Th...
To solve this problem, we need to determine the probability that Alex's magic trick is successful under the assumption that he randomly picks a card from the deck. The deck is formed by selecting n cards from m identical decks, each containing n unique cards. The key insight is to compute the expected probability that ...
false
Code is incorrect.
b01d89e844d20a28c22cf2f507f6bb34
Bots
Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based. In each turn, one of the players makes a move (it doesn’t matter which pl...
{"inputs": ["2", "1", "3", "4", "5", "6", "7", "8", "9", "10", "99", "999", "9999", "99999", "999999", "524287", "131071", "178481", "524288", "1000000"], "outputs": ["19", "5", "69", "251", "923", "3431", "12869", "48619", "184755", "705431", "407336794", "72475737", "703593269", "879467332", "192151599", "295397547",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
Okay, let's try to figure out this problem. So, the question is about finding the number of possible game states that Sasha and Ira's algorithm needs to analyze. The key points are that each state is unique (no revisiting), and in the optimal strategy, each bot makes exactly N moves. Hmm. Let's break down the problem...
To solve this problem, we need to determine the number of possible game states that Sasha and Ira's algorithm needs to analyze. The key insight is that each state is unique and can be represented by the number of moves each bot has made, which forms a grid structure. The goal is to compute the total number of such stat...
true
b03c79ea04736d01575a9c3b6cc57f36
Vlad and Cafes
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
{"inputs": ["5\n1 3 2 1 2", "6\n2 1 2 2 4 1", "1\n0", "1\n200000", "2\n2018 2017", "5\n100 1000 1000 1000 1000", "8\n200000 1 200000 1 200000 1 200000 2", "5\n20000 1 2 3 4", "2\n200000 1", "3\n2 100 2", "2\n10 1", "11\n1 1 1 1 1 1 1 1 1 1 1", "3\n5 5 5", "2\n5 1"], "outputs": ["3", "2", "0", "200000", "2018", "100", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
215
codeforces
Okay, let's see. The problem is to find the cafe that Vlad hasn't visited for the longest time, right? So, the last occurrence of each cafe in the list determines when he last visited it. We need to find the cafe whose last occurrence is the earliest possible. So among all the last occurrences of each cafe, we need to ...
To solve this problem, we need to determine the cafe that Vlad hasn't visited for the longest time. This is equivalent to finding the cafe whose last visit occurred earliest in the sequence of his visits. ### Approach 1. **Track Last Occurrences**: As we iterate through the list of cafes Vlad visited, we keep track o...
true
b076fa79c40c941c6131eeb39a5cd55c
Password Check
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
{"inputs": ["abacaba", "X12345", "CONTEST_is_STARTED!!11", "1zA__", "1zA_", "zA___", "1A___", "z1___", "0", "_", "a", "D", "_", "?", "?", "._,.!.,...?_,!.", "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.", "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!", "XZX", "R", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
269
codeforces
Okay, I need to solve this problem. Let's read the requirements carefully. So the task is to check if a password meets certain complexity conditions. Let me see the conditions again. The password must satisfy all these four conditions: 1. Length is at least 5 characters. 2. Contains at least one uppercase English lett...
To solve this problem, we need to determine if a given password meets specific complexity requirements. The password must be checked for its length and the presence of at least one uppercase letter, one lowercase letter, and one digit. ### Approach The solution involves reading the input password and verifying the fo...
true
b0812b4eedab563aed52cf35f6846cfd
MUH and Cube Walls
Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got hold of lots of wooden cubes somewhere. They started making cube towers by placing the cubes one on top of the other. They defined multiple towers standing in a line as a wall. A wall can consist of towers of di...
{"inputs": ["13 5\n2 4 5 5 4 3 2 2 2 3 3 2 1\n3 4 4 3 2", "5 1\n8 71 1 24 2\n31", "6 3\n2 2 2 2 2 2\n5 5 5", "1 1\n576560149\n691846236", "10 5\n5 10 8 10 11 9 11 12 10 15\n4 2 4 5 3", "10 10\n6 8 1 2 5 1 4 24 2 4\n6 8 1 2 5 1 4 24 2 4", "10 10\n6 8 1 2 5 1 14 24 12 4\n7 9 2 3 6 2 15 25 13 5", "8 4\n1 2 3 4 5 6 7 8\n10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
Okay, I need to solve this programming problem. Let's read the question carefully. The problem is about finding the number of segments in the bears' wall (which has n towers) that match a certain pattern from Horace's elephant wall (which has w towers). The twist here is that the matching is not exact; instead, the re...
To solve this problem, we need to determine how many segments of the bears' wall match the sequence of the elephant's wall after adjusting for vertical shifts. The key insight is that the relative differences between consecutive elements in the walls must be the same for a match to occur. ### Approach 1. **Difference ...
true
b08dbd26974567078cb495691437a90d
Fox And Two Dots
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this: Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors. The key of this game is to find a cycle that contain dots...
{"inputs": ["3 4\nAAAA\nABCA\nAAAA", "3 4\nAAAA\nABCA\nAADA", "4 4\nYYYR\nBYBY\nBBBY\nBBBY", "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB", "2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ", "2 2\nAA\nAA", "2 2\nAA\nAB", "3 3\nAAA\nABA\nAAA", "3 3\nAAA\nABA\nABA", "10 10\nEGFJGJKGEI\nAKJHBGHIHF\nJBABBCFGEJ\nCJDJHJJK...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
29
codeforces
Okay, I need to solve this problem where I have to determine if there's a cycle in a grid of characters. The cycle has to meet certain conditions: same color, at least four dots, forming a loop where each consecutive (including last and first) are adjacent. Hmm. First, let's think about how to approach this. The probl...
To solve this problem, we need to determine if there exists a cycle of at least 4 cells in a grid where each cell in the cycle has the same color and each adjacent cell (including the first and last) shares an edge. ### Approach 1. **Problem Analysis**: The problem is akin to finding cycles in a graph where each cell ...
true
b0b0128b58e825ce948d38812c7c807b
Magic Box
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0,<=0,<=0), and the opposite one is at point (*x*1...
{"inputs": ["2 2 2\n1 1 1\n1 2 3 4 5 6", "0 0 10\n3 2 3\n1 2 3 4 5 6", "0 1 2\n1 1 1\n634728 627299 454463 927148 298618 186257", "5 2 -4\n1 1 1\n279519 704273 181008 670653 198973 996401", "5 5 0\n3 1 3\n832224 636838 995053 211585 505442 341920", "-1 -9 14\n9 8 10\n172575 215800 344296 98651 566390 47011", "95892 794...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's see. So the problem is about determining which faces of a box Vasya can see from his position, and then summing the corresponding a values. The box is axis-aligned, with one corner at (0,0,0) and the opposite at (x1, y1, z1). The faces each have a number in the center, and the arrangement of the a_i's is gi...
To solve this problem, we need to determine which faces of a box Vasya can see from his given position and sum the corresponding numbers on those faces. The box is axis-aligned with one vertex at (0, 0, 0) and the opposite vertex at (x1, y1, z1). Each face of the box has a number written on it, and we need to check whi...
true
b0bb2cceffae753ad0c44398af1d35b6
Tree Folding
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, ..., *b**k*. Additionally, vertices *a*1, ..., *a**k*, *b*1, ..., *b**k* must not have any neighbou...
{"inputs": ["6\n1 2\n2 3\n2 4\n4 5\n1 6", "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7", "2\n1 2", "3\n3 1\n1 2", "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 4", "11\n11 9\n6 7\n7 1\n8 11\n5 6\n3 5\n9 3\n10 8\n2 4\n4 10", "10\n4 2\n7 4\n2 6\n2 5\n4 8\n10 3\n2 9\n9 1\n5 10", "11\n8 9\n2 7\n1 11\n3 2\n9 1\n8 5\n8 6\n5 4\n4 10\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's try to figure out this problem. So, the task is to determine if we can transform a given tree into a path using certain operations, and if possible, find the shortest possible path length. Hmm, the operations allowed are a bit tricky. Let me parse the problem again. The operation allows choosing a vertex v...
To solve this problem, we need to determine if a given tree can be transformed into a path using specific merging operations and, if possible, find the shortest possible path length. The merging operation allows us to combine two disjoint paths of equal length starting from the same vertex, provided certain conditions ...
false
Code is incorrect.
b0cebf1428f9b491c8ffc03cbc5489db
New Year and Arbitrary Arrangement
You are given three integers *k*, *p**a* and *p**b*. You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability *p**a*<=/<=(*p**a*<=+<=*p**b*), add 'a' to the end of the sequence. Otherwise (with probability *p**b*<=/<=(*p**...
{"inputs": ["1 1 1", "3 1 4", "1000 123456 654321", "305 337309 378395", "108 531040 908573", "575 39377 68346", "66 199449 266025", "781 817338 452871", "99 534023 117289", "156 78149 46740", "57 339480 774350", "270 967166 795005", "628 446579 365440", "97 119368 2062", "757 869978 224540", "892 777143 664073", "177 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
10
codeforces
Okay, let's try to understand this problem. So, we need to calculate the expected number of 'ab' subsequences in a sequence generated by adding 'a's and 'b's with certain probabilities. The process stops when there are at least k such 'ab' subsequences. The output should be the expected value modulo 1e9+7, represented ...
To solve this problem, we need to determine the expected number of 'ab' subsequences in a sequence generated by adding characters 'a' and 'b' with given probabilities. The process stops when the number of 'ab' subsequences reaches or exceeds a given threshold \( k \). The solution involves dynamic programming with memo...
false
Code is incorrect.
b103e357a8b3fc76da8f96346971ffdc
none
На тренировку по подготовке к соревнованиям по программированию пришли *n* команд. Тренер для каждой команды подобрал тренировку, комплект задач для *i*-й команды занимает *a**i* страниц. В распоряжении тренера есть *x* листов бумаги, у которых обе стороны чистые, и *y* листов, у которых только одна сторона чистая. При...
{"inputs": ["2 3 5\n4 6", "2 3 5\n4 7", "6 3 5\n12 11 12 11 12 11", "1 4 3\n12", "10 1 17\n3 1 1 2 1 3 4 4 1 4", "3 6 3\n2 5 9", "7 26 8\n5 11 8 10 12 12 3", "11 5 85\n19 20 6 7 6 2 1 5 8 15 6", "7 7 2\n5 2 4 2 4 1 1", "8 5 10\n1 7 2 5 2 1 6 5", "10 27 34\n11 8 11 5 14 1 12 10 12 6", "4 2 2\n1 2 3 1", "5 1 45\n7 14 15 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's tackle this problem. So, the goal is to determine the maximum number of teams that can have all their problem sets printed given the available sheets. Let's see the problem statement again to make sure I understand everything correctly. We have n teams, each with a_i pages. The coach has x sheets that can ...
To solve this problem, we need to determine the maximum number of teams that can have their problem sets printed given the available sheets of paper. The challenge is to efficiently use both types of sheets (double-sided and single-sided) to maximize the number of teams that can be accommodated. ### Approach 1. **Prob...
false
Code is incorrect.
b1100d048e7ba28e17212b983fbf3967
Optimal Number Permutation
You have array *a* that contains all integers from 1 to *n* twice. You can arbitrary permute any numbers in *a*. Let number *i* be in positions *x**i*,<=*y**i* (*x**i*<=&lt;<=*y**i*) in the permuted array *a*. Let's define the value *d**i*<==<=*y**i*<=-<=*x**i* — the distance between the positions of the number *i*. P...
{"inputs": ["2", "1", "3", "4", "10", "100", "1232", "1233", "100000", "499998", "499999", "500000", "45464", "44444", "1134", "1234"], "outputs": ["1 1 2 2", "1 1", "1 3 1 2 2 3", "1 3 3 1 2 4 2 4", "1 3 5 7 9 9 7 5 3 1 2 4 6 8 10 8 6 4 2 10", "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
Okay, let's try to figure out this problem. So, the task is to permute an array that contains each number from 1 to n exactly twice. The goal is to arrange them such that the sum of the distances between the two occurrences of each number is minimized. Hmm, right. First, I need to understand what the distance di is. ...
To solve this problem, we need to permute an array containing each integer from 1 to n exactly twice such that the sum of the distances between the two occurrences of each integer is minimized. ### Approach The key insight is that the minimal distance between two occurrences of an integer is 1, which happens when the...
false
Code is incorrect.
b11ca1b50948f0baad8c094d14768791
Arrival of the General
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their...
{"inputs": ["4\n33 44 11 22", "7\n10 10 58 31 63 40 76", "2\n88 89", "5\n100 95 100 100 88", "7\n48 48 48 48 45 45 45", "10\n68 47 67 29 63 71 71 65 54 56", "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92", "3\n1 2 1", "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14", "35\n37 41 46 39 47 39 44 47 44 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
399
codeforces
Okay, let's see. I need to find the minimum number of swaps required to make the first element the maximum in the array and the last element the minimum. The swaps are only between adjacent elements, so each swap takes one second. Hmm. So the steps would be: first, find the position of the maximum element in the arra...
To solve this problem, we need to determine the minimum number of adjacent swaps required to arrange soldiers such that the first soldier is the tallest and the last soldier is the shortest. The solution involves efficiently moving the tallest and shortest soldiers to their respective positions while considering potent...
true
b12bd65b3396aa552b938e40b123297a
Lust
A false witness that speaketh lies! You are given a sequence containing *n* integers. There is a variable *res* that is equal to 0 initially. The following process repeats *k* times. Choose an index from 1 to *n* uniformly at random. Name it *x*. Add to *res* the multiply of all *a**i*'s such that 1<=≤<=*i*<=≤<=*n*, ...
{"inputs": ["2 1\n5 5", "1 10\n80", "2 2\n0 0", "9 4\n0 11 12 9 20 7 8 18 2", "5 1\n14 2 0 0 1", "2 4\n0 16", "7 2\n0 9 4 0 7 14 4", "10 3\n12 15 19 16 19 0 4 3 5 11", "3 3\n18 7 17", "8 3\n20 15 1 4 20 16 6 12", "7 405871919\n4 4 12 5 7 10 10", "2 753394402\n3 15", "2 34825250\n10 12", "5 585751779\n18 17 6 12 11", "7...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's tackle this problem. Hmm, the problem statement says that we have a sequence of n integers and we perform k operations. Each operation involves selecting a random index x, adding the product of all elements except a_x to res, then subtracting 1 from a_x. We need to find the expected value of res after k ste...
To solve this problem, we need to compute the expected value of a sequence of operations on an array of integers. The operations involve randomly selecting an index, updating the array, and accumulating a result based on the product of all elements except the selected one. The challenge lies in efficiently computing th...
true
b13c3679b0567a34b479291087a98757
Suitable Replacement
You are given two strings *s* and *t* consisting of small Latin letters, string *s* can also contain '?' characters. Suitability of string *s* is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all...
{"inputs": ["?aa?\nab", "??b?\nza", "abcd\nabacaba", "mqwstphetbfrsyxuzdww\nrutseqtsbh", "????????????????????\nxwkxsxlrre", "fzjqgrgzzzghrwgwhfjq\nggwfrjzzqh", "ng?\nvu", "???\nb", "??a?\na", "c?aa???a?cdcc??\nabcadbaccb", "cc?cdb?????b?cc?b?\ncabdacd", "ccaaa?bc?baccbccccbca?cccab??aacccbaac?bccacc?accccaccbcbbcbc\nc...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
18
codeforces
Okay, so I need to solve this programming problem. Let's read the problem statement carefully. The task is to replace all the '?' characters in string s with lowercase letters such that the 'suitability' of s is maximized. The suitability is the maximum number of non-overlapping occurrences of string t that can be fou...
To solve this problem, we need to replace all '?' characters in a string `s` with lowercase letters such that the maximum number of non-overlapping occurrences of string `t` can be formed after any possible permutation of `s`. The goal is to maximize this number, known as the suitability of `s`. ### Approach 1. **Char...
false
Code is incorrect.
b15447fdee4f739dae59e58f8f36f1ae
Mahmoud and a Message
Mahmoud wrote a message *s* of length *n*. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disappeared while writing the string. That's because this magical paper doesn't allow character number *i* in the English...
{"inputs": ["3\naab\n2 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\nabcdeabcde\n5 5 5 5 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "10\naaaaaaaaaa\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "55\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n1000 1000 1000 1000 1000 1000 1000 1000 1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's tackle this problem. Hmm, the problem seems a bit involved, but I'll break it down step by step. So, the problem is about splitting a string into substrings such that each substring meets certain conditions based on the characters it contains. The conditions are that for each character in the substring, th...
To solve this problem, we need to split a string into substrings such that each substring adheres to constraints based on the maximum allowed length for each character. We need to determine three things: the number of valid ways to split the string, the maximum length of any substring in a valid split, and the minimum ...
true
b1636b10d82c8f683a812bbdcddcadef
Dynamic Problem Scoring
Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends...
{"inputs": ["2\n5 15 40 70 115\n50 45 40 30 15", "3\n55 80 10 -1 -1\n15 -1 79 60 -1\n42 -1 13 -1 -1", "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62", "4\n-1 20 40 77 119\n30 10 73 50 107\n21 29 -1 64 98\n117 65 -1 -1 -1", "2\n33 15 51 7 101\n41 80 40 13 46", "9\n57 52 60 56 91\n32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. So, the problem is about Vasya trying to cheat in a programming competition by creating fake accounts to adjust the maximum points for problems so that his score becomes higher than Petya's. The goal is to find the minimum numb...
To solve this problem, we need to determine the minimum number of fake accounts Vasya needs to create in order to ensure his score is strictly higher than Petya's in a programming competition with dynamic scoring. The scoring depends on the ratio of participants who solved a problem to the total number of participants,...
true
b17e773c2574469d872c482f71085b89
Greedy Arkady
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ...
{"inputs": ["20 4 5 2", "30 9 4 1", "2 2 1 1", "42 20 5 29", "1000000000000000000 135 1000000000000000 1000", "100 33 100 100", "1000000000 1000000000 1000000000 1000", "1000000000 32428 1000000000 1000", "1000000000 324934 1000 1000", "1000000000000000000 32400093004 10000000 1000", "885 2 160 842", "216 137 202 208",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
105
codeforces
Okay, let's see. I need to find the maximum number of candies Arkady can receive by choosing a valid x. The constraints are that x can't be greater than M, and each person can't receive candies more than D times. Hmm, the problem says that the process is cyclic. So, for a chosen x, the total number of candies used is...
To solve this problem, we need to determine the maximum number of candies Arkady can receive by choosing a valid integer \( x \) under the constraints that \( x \) cannot exceed \( M \) and no person can receive candies more than \( D \) times. The solution involves systematically exploring possible values of \( x \) a...
true
b189968890f87cf088faa76aca366947
The Child and Zoo
Of course our child likes walking in a zoo. The zoo has *n* areas, that are numbered from 1 to *n*. The *i*-th area contains *a**i* animals in it. Also there are *m* roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area usin...
{"inputs": ["4 3\n10 20 30 40\n1 3\n2 3\n4 3", "3 3\n10 20 30\n1 2\n2 3\n3 1", "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7", "10 14\n594 965 90 327 549 206 514 993 803 635\n1 2\n1 3\n3 4\n2 5\n5 6\n5 7\n4 8\n4 9\n5 10\n10 4\n7 8\n2 6\n6 4\n5 4", "10 19\n15704 19758 26631 25050 22778 15041 8487 26...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. The problem is about a zoo with n areas connected by m roads. Each area has a certain number of animals. The child considers all simple paths from p to q (p != q) and for each path, writes down the minimum number of animals in ...
To solve this problem, we need to determine the average value of the maximum possible minimum number of animals on all simple paths between every pair of distinct areas in a zoo. The solution involves using a Union-Find (Disjoint Set Union) data structure to efficiently compute the required values. ### Approach 1. **U...
true
b1a7683f8f490dfff73965d4604a89df
Lawnmower
You have a garden consisting entirely of grass and weeds. Your garden is described by an *n*<=×<=*m* grid, with rows numbered 1 to *n* from top to bottom, and columns 1 to *m* from left to right. Each cell is identified by a pair (*r*,<=*c*) which means that the cell is located at row *r* and column *c*. Each cell may ...
{"inputs": ["4 5\nGWGGW\nGGWGG\nGWGGG\nWGGGG", "3 3\nGWW\nWWW\nWWG", "1 1\nG", "4 3\nGWW\nWWW\nWWW\nWWG", "6 5\nGWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW", "3 5\nGGWWW\nWWWWW\nWWWGG", "20 1\nG\nG\nW\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nW\nG\nW\nG\nG", "2 2\nGG\nGW", "1 20\nGGGGWGGGGWWWWGGGWGGG", "3 112\nGGWGGWWGGGWWGWWG...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
Okay, let's see. I need to find the minimum number of moves required to mow all the weeds in the garden. The lawnmower starts at (1,1) facing right. The movement is a bit tricky. Each move makes you go in the direction you're facing and then flip direction. Oh right, and after each move, the direction flips. So, the di...
To solve this problem, we need to determine the minimum number of moves required to mow all the weeds in a grid, starting from the top-left corner and facing right. The mower alternates direction after each move, moving left or right. The challenge is to cover all weed cells efficiently while adhering to the movement c...
false
Code is incorrect.
b1fa9f7905495c93b5d17875a9e6c3ae
none
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings *s* and *t* have the same length *n*, then the function *h*(*s*,<=*t*) is defined as the number of posi...
{"inputs": ["1\nC", "2\nAG", "3\nTTT", "4\nGACT", "1\nT", "2\nAG", "3\nGCA", "5\nACGTC", "15\nAGCGAATCCCATTGT", "20\nTAAGCGACCAGGTGCTTTAC", "30\nCCTTTCGGGGCGCGTTGGCCTTTGTCCTGC", "318\nTATCAATCGGTACGTGCGCATCATTGTCAATCGGGCTTCATGGCTTGCGGGCGCTACCCGAGGGGAAGCTGCGGACAGGTAGGTAAGATACACACGAACCAAACGGAGTTATGTTGGATAAATTGGCTGGAAGGGC...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
17
codeforces
Okay, let's try to understand this problem. So, the task is to find the number of strings t that maximize the Vasya distance ρ(s, t). The Vasya distance is defined as the maximum h(s', t) where s' is any cyclic shift of s. Hmm, right. Wait, what's a cyclic shift? Oh right, for example, if s is "AG", the cyclic shifts ...
To solve this problem, we need to determine the number of strings \( t \) such that the Vasya distance from a given string \( s \) is maximized. The Vasya distance is defined as the maximum number of positions where any cyclic shift of \( s \) matches \( t \). ### Approach 1. **Understand the Problem**: The goal is to...
true
b21a9aed6384dfd606028423fd6a57da
Masha and geometric depression
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=&gt;<=1 the respective term satisfi...
{"inputs": ["3 2 30 4\n6 14 25 48", "123 1 2143435 4\n123 11 -5453 141245", "123 1 2143435 4\n54343 -13 6 124", "3 2 25 2\n379195692 -69874783", "3 2 30 3\n-691070108 -934106649 -220744807", "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
14
codeforces
Okay, let's tackle this problem step by step. Hmm, the problem is about a geometric progression where certain terms are skipped if they're bad. We need to find out how many terms Masha will write on the board, considering the absolute value limit and the bad numbers. Oh right, and there's a possibility of infinite term...
To solve this problem, we need to determine how many terms of a geometric progression Masha will write on the board, considering that she skips terms that are "bad" and stops when the absolute value of a term exceeds a given limit. Additionally, we need to handle cases where the number of terms could be infinite. ### ...
false
Code is incorrect.
b23d4e1c4186e101d28a0d2f197f29d7
Plate Game
You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located with...
{"inputs": ["5 5 2", "6 7 4", "100 100 1", "1 1 100", "13 7 3", "23 7 3", "9 9 2", "13 13 2", "21 21 10", "20 21 10", "20 20 10", "9 13 2", "19 7 3", "19 19 10", "19 20 10", "19 21 10", "1 100 1", "2 100 1", "3 100 1", "100 100 49", "100 100 50", "100 100 51", "100 99 50", "4 10 5", "8 11 2", "3 12 5", "14 15 5", "61 2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
98
codeforces
Okay, let's see. So the problem is about a game where two players take turns placing plates on a table. The plates can't overlap, but they can touch. The player who can't make a move loses. We need to determine whether the first or second player will win if both play optimally. First, I need to understand the conditio...
To solve this problem, we need to determine which player will win a game where two players take turns placing plates on a rectangular table. The player who cannot make a move loses. Both players play optimally, and we need to decide if the first player or the second player will win. ### Approach 1. **Problem Analysis*...
false
Code is incorrect.
b26cb8af6d3796ecce005a0e74a69acd
Help Vasilisa the Wise 2
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
{"inputs": ["3 7\n4 6\n5 5", "11 10\n13 8\n5 16", "1 2\n3 4\n5 6", "10 10\n10 10\n10 10", "5 13\n8 10\n11 7", "12 17\n10 19\n13 16", "11 11\n17 5\n12 10", "12 11\n11 12\n16 7", "5 9\n7 7\n8 6", "10 7\n4 13\n11 6", "18 10\n16 12\n12 16", "13 6\n10 9\n6 13", "14 16\n16 14\n18 12", "16 10\n16 10\n12 14", "11 9\n12 8\n11 9...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
155
codeforces
Okay, let's see. I need to solve this problem where we have a 2x2 grid of gems, and each cell has a unique number from 1 to 9. The rows, columns, and diagonals must sum up to specific values given as input. The task is to find such a grid or output -1 if it's impossible. Hmm. Let's break down the problem. The input gi...
To solve this problem, we need to determine the correct placement of gems in a 2x2 grid such that the sums of the rows, columns, and diagonals match the given input values. Each gem must be a unique number from 1 to 9. ### Approach 1. **Sum Check**: First, we check if the sums of the rows, columns, and diagonals are c...
true
b27355b98f1c7abb80f3cf7c1f7f8bcf
Fafa and the Gates
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (...
{"inputs": ["1\nU", "6\nRURUUR", "7\nURRRUUU", "100\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR", "7\nURURRUR", "15\nRUURRRRURRUUUUU", "6\nUURRRU", "7\nRRRRRRR", "2\nUR", "2\nUU"], "outputs": ["0", "1", "2", "3", "1", "3", "1", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
64
codeforces
Okay, let's see. I need to find out how many times Fafa pays a silver coin when moving through the gates. The problem says that each time he passes through a gate, he has to pay one coin. But wait, there's a catch. If he visits a gate without moving from one kingdom to another, he doesn't pay. And he starts at (0,0), w...
To solve this problem, we need to determine the number of silver coins Fafa needs to pay when passing through gates along the wall between two kingdoms. The wall is built along the line x = y, and each gate is located at an integer point on this line. Fafa starts at the origin (0, 0) and follows a sequence of moves. A ...
true
b29987a03c17f317e1680bc7d76d8422
Vasya and String
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original strin...
{"inputs": ["4 2\nabba", "8 1\naabaabaa", "1 0\na", "1 1\nb", "1 0\nb", "1 1\na", "10 10\nbbbbbbbbbb", "10 2\nbbbbbbbbbb", "10 1\nbbabbabbba", "10 10\nbbabbbaabb", "10 9\nbabababbba", "10 4\nbababbaaab", "10 10\naabaaabaaa", "10 10\naaaabbbaaa", "10 1\nbaaaaaaaab", "10 5\naaaaabaaaa", "10 4\naaaaaaaaaa", "100 10\nbbbbb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
233
codeforces
Okay, so I need to solve this problem where Vasya can change up to k characters in a string of a's and b's to maximize the beauty, which is the maximum length of a substring with all same characters. The input gives n, k, and the string. The output is the maximum beauty possible. Hmm, let's think about how to approach...
To solve this problem, we need to determine the maximum length of a substring consisting of the same character ('a' or 'b') that can be achieved by changing up to `k` characters in the given string. This problem can be efficiently solved using a sliding window technique to explore both possible target characters ('a' a...
true
b2fd1c4297cbc9c1b1dd2d009ad3ee81
K-special Tables
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects. Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f...
{"inputs": ["4 1", "5 3", "1 1", "2 1", "2 2", "500 1", "3 1", "3 2", "3 3", "4 2", "4 3", "4 4", "5 1", "5 2", "5 4", "5 5", "6 1", "6 2", "6 3", "6 4", "6 5", "6 6", "500 500", "500 250", "94 3", "22 4", "15 12", "37 35", "87 51", "15 4", "183 2", "103 6", "131 11", "193 186", "117 109", "116 91", "140 79", "350 14",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
68
codeforces
Okay, I need to find a k-special table for given n and k. Let's think about what the problem is asking. First, the table must be n x n, containing each number from 1 to n² exactly once. Each row is in increasing order, and the sum of the k-th column must be as large as possible. The main goal is to maximize the sum o...
To solve this problem, we need to generate an n×n matrix that meets specific criteria to be considered k-special. The matrix must contain each integer from 1 to n² exactly once, each row must be sorted in increasing order, and the sum of the k-th column must be maximized. ### Approach The key to maximizing the sum of ...
false
Code is incorrect.
b30741b23947b318b5d31bcc60129d38
Erasing Substrings
You are given a string *s*, initially consisting of *n* lowercase Latin letters. After that, you perform *k* operations with it, where . During *i*-th operation you must erase some substring of length exactly 2*i*<=-<=1 from *s*. Print the lexicographically minimal string you may obtain after performing *k* such opera...
{"inputs": ["adcbca", "abacabadabacaba", "a", "b"], "outputs": ["aba", "aabacaba", "a", "b"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's try to figure out how to solve this problem. So, the problem is about performing k operations on a string s. Each operation requires deleting a substring of exactly 2*i - 1 characters in the i-th step. Wait, wait. Wait, the problem statement says during the i-th operation, we erase a substring of length exa...
To solve this problem, we need to find the lexicographically smallest string possible after performing a series of operations on the input string. Each operation involves removing a substring of a specific length, determined by the step number. The challenge is to determine the optimal way to remove these substrings to...
false
Code is incorrect.
b3188abe3b8beeaaa413f315936812bc
Slightly Decreasing Permutations
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The ...
{"inputs": ["5 2", "3 0", "3 2", "1 0", "2 0", "2 1", "10 4", "56893 5084", "6 3", "1 0", "310 186", "726 450", "438 418", "854 829", "214 167", "85705 56268", "11417 4583", "53481 20593", "79193 77281", "42607 42144", "100000 0", "100000 99999", "100000 53860", "4 0", "4 1", "4 2", "4 3", "3 1"], "outputs": ["1 5 2 4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
207
codeforces
Okay, I need to find a permutation of length n with exactly k decreasing coefficients. The decreasing coefficient is the number of times an element is greater than the next one. So for example, in the sample input where n=5 and k=2, the output is 1 5 2 4 3. Let's check that: 5>2, 4>3. So two decreases. That's correct. ...
To solve this problem, we need to generate a permutation of length `n` such that it has exactly `k` decreasing coefficients. A decreasing coefficient is defined as the number of positions `i` where the element at `i` is greater than the element at `i+1`. ### Approach The approach to solve this problem involves constru...
false
Code is incorrect.
b3754923cc8c78966e744fe77b658aa0
Jeff and Removing Periods
Cosider a sequence, consisting of *n* integers: *a*1, *a*2, ..., *a**n*. Jeff can perform the following operation on sequence *a*: - take three integers *v*, *t*, *k* (1<=≤<=*v*,<=*t*<=≤<=*n*; 0<=≤<=*k*; *v*<=+<=*tk*<=≤<=*n*), such that *a**v* = *a**v*<=+<=*t*, *a**v*<=+<=*t* = *a**v*<=+<=2*t*, ..., *a**v*<=+<=*t*(*k...
{"inputs": ["5\n2 2 1 1 2\n5\n1 5\n1 1\n2 2\n1 3\n2 3", "10\n2 1 3 3 3 3 1 3 1 1\n10\n4 8\n2 10\n1 10\n4 4\n1 3\n2 4\n6 7\n1 9\n2 5\n1 1", "15\n3 3 2 2 1 2 4 1 3 1 1 3 1 4 1\n15\n4 10\n8 9\n12 12\n7 9\n11 12\n1 1\n4 10\n12 13\n2 2\n3 5\n5 6\n1 1\n2 3\n2 4\n7 14", "20\n3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1 2 3 1\n20\n13 17\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's try to understand this problem. So the task is to compute the beauty of a subarray for multiple queries. The beauty is the minimum number of operations needed to delete all elements from the sequence. Each operation allows Jeff to remove a set of elements forming an arithmetic progression with step t and le...
To solve this problem, we need to determine the minimum number of operations required to delete all elements from a given subarray for multiple queries. Each operation allows removing elements that form an arithmetic progression (AP) of indices with the same value, followed by permuting the remaining elements. ### App...
true
b38f225bf9f5e181525a2b18b9c782a3
Clique in the Divisibility Graph
As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices of this subset are conn...
{"inputs": ["8\n3 4 6 8 10 18 21 24", "5\n2 3 4 8 16", "2\n10 20", "2\n10 21", "5\n250000 333333 500000 666666 1000000", "50\n1 2 5 7 9 14 19 24 25 29 31 34 37 40 43 44 46 53 54 57 58 59 60 61 62 64 66 68 69 70 72 75 78 79 80 81 82 84 85 86 87 88 89 90 91 92 93 94 96 98", "20\n1 2 4 8 16 32 64 128 256 512 1024 2048 409...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
Okay, I need to solve this problem where I have to find the maximum clique in a divisibility graph. Let's think about what the problem says. The clique here is a subset of the numbers where every pair is connected by an edge, which in this case means that one divides the other. So, the maximum clique is the largest pos...
To solve this problem, we need to determine the size of the maximum clique in a divisibility graph for a given set of positive integers. A clique in this context is a subset of numbers where each pair of numbers is connected by an edge, meaning one divides the other. The goal is to find the largest such subset. ### Ap...
true
b3b6ae12716c1573c491359fc2544ce2
Love Rescue
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long. This story c...
{"inputs": ["3\nabb\ndad", "8\ndrpepper\ncocacola", "1\nh\np", "2\nxc\nda", "3\nbab\naab", "15\nxrezbaoiksvhuww\ndcgcjrkafntbpbl", "3\nbaa\nbba", "10\ndaefcecfae\nccdaceefca", "10\nfdfbffedbc\ncfcdddfbed", "100\nbltlukvrharrgytdxnbjailgafwdmeowqvwwsadryzquqzvfhjnpkwvgpwvohvjwzafcxqmisgyyuidvvjqljqshflzywmcccksk\njmgilz...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
Okay, let's see. I need to find the minimum number of spells that Tolya's grandmother needs to buy so that she can make the two strings equal. Each spell is a pair (c1, c2) which allows converting c1 to c2 and vice versa on both strings. The goal is to have the same letters in both strings after applying these transfor...
To solve this problem, we need to determine the minimum number of spells required to make the letterings on Valya's pullover and Tolya's t-shirt identical. Each spell allows bidirectional transformation between two characters. The goal is to find the minimal set of spells such that all differing characters in the two s...
false
Code is incorrect.
b3c73f74dc012f6f249628bcecbe8894
Strange Radiation
*n* people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all peop...
{"inputs": ["2 999\n400000 1 2\n500000 1 1", "2 1000\n400000 500 1\n600000 500 2", "2 99999\n500 1 1\n499 10000 2", "26 10\n495492 7 1\n256604 5 2\n511773 3 2\n590712 4 1\n206826 7 2\n817878 4 2\n843915 1 1\n349160 3 1\n351298 4 1\n782251 8 2\n910928 4 1\n662354 4 2\n468621 2 2\n466991 7 2\n787303 6 2\n221623 8 2\n3435...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's see. I need to find the minimum time t such that when placing a bomb at some position, there's at least one person reaching 0 and another reaching 1e6 by time t. The bomb's rays (left and right) can speed up people if they are moving in the same direction as the ray when they meet. The rays move at speed s,...
To solve this problem, we need to determine the minimum time `t` such that placing a bomb at some coordinate allows at least one person to reach coordinate 0 and another person to reach coordinate 1e6 by time `t`. The solution involves a binary search approach combined with interval merging to efficiently check feasibl...
false
Code is incorrect.
b3e02bf738ea0166342afd572bed02f8
Plus and xor
Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions ...
{"inputs": ["142\n76", "638\n126", "1639\n1176", "12608\n0", "104066\n104066", "1024996\n990106", "1215996781\n108302929", "1870807699\n259801747", "339671107814\n208405902980", "1367480970723947\n584615739735395", "9992164445234764941\n8162963574901971597"], "outputs": ["33 109", "256 382", "-1", "6304 6304", "0 10406...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
Okay, let's see. The problem is to find two non-negative integers X and Y that satisfy two conditions. The first condition is that X + Y equals A. The second condition is that X XOR Y equals B. Also, X needs to be the smallest possible among all possible solutions. If there's no solution, we output -1. Hmm, right. So,...
To solve this problem, we need to find two non-negative integers \( X \) and \( Y \) that satisfy the conditions \( X + Y = A \) and \( X \oplus Y = B \) (where \(\oplus\) denotes the bitwise XOR operation). Additionally, \( X \) should be the smallest possible value among all valid solutions. If no such pair exists, w...
true
b41aff4b8c6e0ade8d4f97f7ee1a8118
New Bus Route
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d...
{"inputs": ["4\n6 -3 0 4", "3\n-2 0 2", "2\n1 2", "2\n1000000000 -1000000000", "5\n-979619606 -979619602 -979619604 -979619605 -979619603", "5\n-799147771 -799147773 -799147764 -799147774 -799147770", "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 5532...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
213
codeforces
Okay, let's see. The problem is to find the minimal distance between any two cities and the number of pairs that have this minimal distance. Hmm. So first, I need to process the input, which is a list of integers representing the coordinates of cities. Since all coordinates are distinct, there's no duplicates to worry ...
To solve this problem, we need to determine the minimal distance between any two cities and the number of pairs of cities that have this minimal distance. The approach involves sorting the city coordinates and analyzing consecutive elements to find the minimal distance efficiently. ### Approach 1. **Sort the Coordinat...
true
b49dba691f82dec9bff8965c7101a5d8
A polyline
The input contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=10,<=0<=≤<=*b*<=≤<=22·*a*<=-<=1) separated by a single space. Output two integers separated by a single space. Sample Input 1 0 2 15 4 160 Sample Output 0 0 3 0 12 12
{"inputs": ["1 0", "2 15", "4 160", "3 14", "10 2", "2 0", "2 15", "2 7", "2 6", "2 9", "3 0", "3 63", "3 51", "3 17", "3 63", "4 0", "4 255", "4 74", "4 236", "4 41", "5 0", "5 1023", "5 205", "5 186", "5 939", "6 0", "6 4095", "6 498", "6 3835", "6 2531", "7 0", "7 16383", "7 8518", "7 124", "7 8898", "8 0", "8 65535...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
Okay, let's try to figure out this problem. So the task is to write a Python function that takes two integers a and b as input and outputs two integers. The sample inputs and outputs might give some clues. Let's look at the samples: Sample Input 1: 1 0 → Output 0 0 Sample Input 2: 2 15 → Output 3 0 Sample Input 3:4 16...
To solve this problem, we need to generate an executable Python function that processes two integers, `a` and `b`, and outputs two integers based on a specific pattern observed in the grid formed by the binary representation of `b`. The solution involves analyzing the grid structure and counting certain properties of t...
false
Code is incorrect.
b4cb240302791e8ce80d244ae2e55014
Book of Evil
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains *n* settlements numbered from 1 to *n*. Moving through the swamp is very difficult, so people tramped exactly *n*<=-<=1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possi...
{"inputs": ["6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6", "2 2 1\n2 1\n1 2", "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
Okay, let's see. The problem is to find all possible settlements where the Book of Evil could be located, given that certain settlements are affected. The Book's damage range is d, so any settlement within distance d from the Book's location will be affected. But since the affected settlements we know (p1, p2,... pm) m...
To solve this problem, we need to determine which settlements in a swampy area could potentially contain the Book of Evil, given that certain settlements are affected by its damage. The Book's damage range is specified, and we need to find all settlements such that all affected settlements are within this range. ### A...
true
b4d511f706e2bc8c6f024a955cc31d15
Sorting the Coins
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then...
{"inputs": ["4\n1 3 4 2", "8\n6 8 3 4 7 2 1 5", "1\n1", "11\n10 8 9 4 6 3 5 1 11 7 2", "11\n10 8 9 4 3 5 1 11 7 2 6", "100\n1 72 43 50 58 87 10 94 29 51 99 86 92 80 36 31 9 100 85 59 66 30 3 78 17 73 93 37 57 71 45 15 24 2 64 44 65 22 38 79 23 8 16 52 98 97 96 95 91 90 89 88 84 83 82 81 77 76 75 74 70 69 68 67 63 62 61...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
34
codeforces
Okay, let's try to understand the problem. We have coins that start all out of circulation. Then, step by step, we replace some coins (as per the given positions) to be in circulation. After each replacement, we need to compute the hardness of ordering according to Dima's algorithm. The hardness is the number of steps ...
To solve this problem, we need to determine the hardness of ordering a sequence of coins after each step of adding a new coin in circulation. The hardness is defined as the number of passes required to sort the coins such that all out-of-circulation coins are on the left and all in-circulation coins are on the right us...
false
Code is incorrect.
b4d9105ef9a9a251914f6909fd51454d
Remembering Strings
You have multiset of *n* strings of the same length, consisting of lowercase English letters. We will say that those strings are easy to remember if for each string there is some position *i* and some letter *c* of the English alphabet, such that this string is the only string in the multiset that has letter *c* in pos...
{"inputs": ["4 5\nabcde\nabcde\nabcde\nabcde\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1", "4 3\nabc\naba\nadc\nada\n10 10 10\n10 1 10\n10 10 10\n10 1 10", "3 3\nabc\nada\nssa\n1 1 1\n1 1 1\n1 1 1", "5 2\naa\naa\nab\nbb\nbb\n1 100\n100 100\n1 1\n100 100\n100 1", "3 3\nabc\nabc\nabc\n1 100 100\n100 1 100\n100 100 1", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's tackle this problem. So the task is to find the minimum cost to modify the given strings such that each string has a unique position and character that distinguishes it from all others. Hmm. First, I need to understand the problem correctly. Each string in the multiset must have at least one position where...
To solve this problem, we need to determine the minimum cost required to modify a multiset of strings such that each string has a unique identifier in the form of a position and a character. This identifier ensures that no other string in the multiset has the same character at the same position. ### Approach 1. **Prob...
false
Code is incorrect.
b4eb2890c5643e69ebc890ea4edc66eb
Parity Game
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 you try to turn *a* into *b* using two types of operations: - Write *...
{"inputs": ["01011\n0110", "0011\n1110", "11111\n111111", "0110011\n01100110", "10000100\n011110", "1\n0", "0\n00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
30
codeforces
Okay, let's try to figure out this problem. So, the task is to determine whether we can transform string a into string b using the given operations. The two operations are: appending the parity of a to the end, or removing the first character. Hmm. First, I need to understand the operations better. Let's break them do...
To solve this problem, we need to determine if we can transform string `a` into string `b` using two operations: appending the parity bit of the current string to its end or removing the first character of the string. The parity bit is 1 if the number of 1s in the string is odd, otherwise 0. ### Approach The solution ...
true
b4efdc24295286054870ab19e37d0e4b
Cutlet
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2*n* seconds, in particular, it should be fried for *n* seconds on one side and *n* seconds on the other side. Arkady has already got a frying pan and turn o...
{"inputs": ["10 2\n3 5\n11 13", "10 3\n3 5\n9 10\n11 13", "20 1\n3 19", "10 1\n0 20", "10 1\n0 1", "10 1\n10 10", "10 2\n4 4\n14 14", "1 1\n0 0", "10 5\n3 3\n5 5\n8 8\n13 13\n16 16", "10 7\n0 0\n2 6\n8 10\n12 12\n14 14\n17 17\n19 19", "100 10\n18 18\n30 30\n37 37\n59 59\n83 83\n90 90\n141 141\n149 149\n173 173\n189 189...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's tackle this problem. Hmm. So, the problem is about frying a cutlet that needs to be cooked n seconds on each side. The total time is 2n seconds. But Arkady can only flip the cutlet during certain intervals. We need to find out if it's possible to flip the cutlet such that the total time on each side is exac...
To solve this problem, we need to determine if Arkady can fry a cutlet for exactly `n` seconds on each side using the given intervals when he can flip the cutlet. The solution must also find the minimum number of flips required if possible. ### Approach 1. **Check for 1 Flip**: The simplest case is flipping the cutlet...
false
Code is incorrect.
b4f01cf990c7577c3d9702ff5433b451
Maximum Questions
Vasya wrote down two strings *s* of length *n* and *t* of length *m* consisting of small English letters 'a' and 'b'. What is more, he knows that string *t* has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions. Suddenly in the morning, Vasya found that somebody spoiled ...
{"inputs": ["5\nbb?a?\n1", "9\nab??ab???\n3", "6\nab??ab\n4", "14\n?abaa?abb?b?a?\n3", "17\nb??a?abbbaaababba\n4", "1\nb\n1", "3\nb?a\n1", "12\naba?bbaaabbb\n1", "43\n????aabaababa?aaaa?abbbabbb?ab??baabbbbbabb\n5", "36\nbbaa??aab?aabbb?ba?b?bba?bbaa??bb?ab\n4", "14\na?a?b????b?ba?\n3", "47\na??a??abbaaa?a??aaabaa?abbb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. So, the problem is about Vasya's two strings, s and t. The string t is of the form "abab...", meaning that the odd positions are 'a's and even positions are 'b's. However, s has some characters replaced with '?'. We can replace...
To solve this problem, we need to maximize the number of non-overlapping occurrences of a pattern string `t` in a given string `s` after replacing some '?' characters in `s` with 'a' or 'b'. Additionally, among all possible replacements that achieve this maximum number of occurrences, we need to find the one with the m...
false
Code is incorrect.
b4f150096d024711c692c784f8da6959
Hometask
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of digits, your task is to find the maximum integer that you can mak...
{"inputs": ["1\n0", "11\n3 4 5 4 5 3 5 3 4 4 0", "8\n3 2 5 1 5 2 2 3", "12\n5 3 3 3 2 5 5 1 2 1 4 1", "8\n5 5 4 1 5 5 5 3", "12\n3 1 2 3 2 0 2 2 2 0 2 3", "12\n5 1 4 4 2 1 7 7 4 2 5 1", "5\n3 6 1 6 2", "11\n3 9 9 6 4 3 6 4 9 6 0", "5\n9 6 6 6 1", "10\n2 0 0 0 0 0 0 0 0 0", "10\n1 0 0 0 0 0 0 0 0 0", "5\n1 1 0 0 0", "5\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's try to solve this problem. The task is to find the maximum possible number using a given set of digits that is divisible by 2, 3, and 5. If it's not possible, return -1. Hmm. Wait, divisible by 2, 3, and 5. Oh right, that means it must be divisible by their least common multiple. So the number must be divi...
To solve this problem, we need to find the largest possible integer that can be formed from a given set of digits such that the number is divisible by 2, 3, and 5. If no such number can be formed, we should return -1. The key insight is that the number must end in 0 (to be divisible by 2 and 5) and the sum of its digit...
true
b50a323239599a39079a5be33a3b8d55
Change-free
Student Arseny likes to plan his life for *n* days ahead. He visits a canteen every day and he has already decided what he will order in each of the following *n* days. Prices in the canteen do not change and that means Arseny will spend *c**i* rubles during the *i*-th day. There are 1-ruble coins and 100-ruble notes ...
{"inputs": ["5 42\n117 71 150 243 200\n1 1 1 1 1", "3 0\n100 50 50\n1 3 2", "5 42\n117 71 150 243 200\n5 4 3 2 1", "5 32\n83 13 61 34 31\n7 5 6 8 8", "14 138\n479 330 487 127 170 55 122 480 331 434 447 246 104 263\n1 1 1 1 1 1 1 1 1 1 1 1 1 1", "1 0\n49\n2", "1 100\n51\n2", "1 50\n51\n100000", "20 148\n469 474 336 120 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's try to figure out this problem. So, the task is to determine how Arseny should pay each day to minimize the total dissatisfaction of the cashier. The dissatisfaction depends on the number of coins and notes the cashier gives back as change. Oh right, because he has to pay in such a way that the cashier give...
To solve this problem, we need to determine how Arseny should pay each day to minimize the total dissatisfaction of the cashier. The cashier's dissatisfaction is influenced by the number of notes and coins given as change, and Arseny can use coins received in change for subsequent days. The goal is to strategically pay...
false
Code is incorrect.
b52e1bb705348e452f7a8fab3f31c955
Filya and Homework
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc...
{"inputs": ["5\n1 3 3 2 1", "5\n1 2 3 4 5", "2\n1 2", "3\n1 2 3", "3\n1 1 1", "2\n1 1000000000", "4\n1 2 3 4", "10\n1 1 1 1 1 2 2 2 2 2", "2\n4 2", "4\n1 1 4 7", "3\n99999999 1 50000000", "1\n0", "5\n0 0 0 0 0", "4\n4 2 2 1", "3\n1 4 2", "3\n1 4 100", "3\n2 5 11", "3\n1 4 6", "3\n1 2 4", "3\n1 2 7", "5\n1 1 1 4 5", "2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
159
codeforces
Okay, let's see. I need to solve this problem where Filya has to make all elements of an array equal by adding x to some, subtracting x from others, or leaving some as is. The question is whether such an x exists. First, let's understand the problem. The array can have elements modified by either +x, -x, or stay the s...
To solve this problem, we need to determine if it's possible to make all elements of an array equal by adding or subtracting a fixed integer x to some elements. The solution involves checking the number of unique elements in the array and their arrangement. ### Approach 1. **Identify Unique Elements**: Extract the uni...
true
b534f7c7d0bc5fa08e541dd75d932c2c
Prizes, Prizes, more Prizes
Vasya, like many others, likes to participate in a variety of sweepstakes and lotteries. Now he collects wrappings from a famous chocolate bar "Jupiter". According to the sweepstake rules, each wrapping has an integer written on it — the number of points that the participant adds to his score as he buys the bar. After ...
{"inputs": ["3\n3 10 4\n2 4 10 15 20", "4\n10 4 39 2\n3 5 10 11 12", "1\n45\n1 2 3 4 5", "1\n50\n1 2 4 5 6", "1\n6\n1 2 4 6 7", "1\n11\n1 2 3 6 8", "45\n54672703 354223499 798425228 192616902 934526477 130046515 120969797 1128116 221465324 487958664 211577865 653388287 538234 467693667 387627267 811104156 26715905 1085...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully and understand what's required. So, the problem is about Vasya collecting points from chocolate bar wrappings and exchanging them for prizes. The prizes are of different costs, and he uses a greedy strategy. I need to calculate how many o...
To solve this problem, we need to determine how many prizes Vasya can collect by exchanging his points according to a greedy strategy. The goal is to process each chocolate bar's points, accumulate them, and then exchange them for the most expensive possible prizes until no more points can be exchanged. ### Approach 1...
false
Code is incorrect.
b55445c6d760c93b19a016fc27f199d0
Snow Footprints
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave...
{"inputs": ["11\n.RRRLLLLL..", "4\n.RL.", "3\n.L.", "3\n.R."], "outputs": ["7 5", "3 2", "2 1", "2 3"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
101
codeforces
Okay, let's tackle this problem. So, the task is to find possible starting (s) and ending (t) positions of Alice's path based on the footprints left on the road. The road is divided into n blocks, each either with an L, R, or . (no footprint). The rules are that moving from i to i+1 leaves an R on i, and moving from i ...
To solve this problem, we need to determine the starting and ending positions of a path on a snowy road based on the footprints left behind. The footprints can either be 'R' (right) or 'L' (left), and each new footprint overwrites the previous one. The solution involves analyzing the sequence of footprints to deduce th...
false
Code is incorrect.
b56f70fce31dc3a7f2ae03d2a68d63b7
Mathematical Analysis Rocks!
Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to *n*. Each student *i* (1<=≤<=*i*<=≤<=*n*) has a best friend *p*[*i*] (1<=≤<=*p*[*i*]<=≤<=*n*). In fact, e...
{"inputs": ["4\n2 1 4 3\n3 4 2 1", "5\n5 2 3 1 4\n1 3 2 4 5", "2\n1 2\n2 1", "1\n1\n1", "2\n1 2\n1 2", "3\n2 3 1\n1 2 3", "3\n1 2 3\n2 1 3", "3\n1 2 3\n1 2 3", "4\n1 2 3 4\n2 1 4 3", "5\n4 1 2 5 3\n2 3 5 1 4", "10\n2 9 1 7 6 8 5 4 10 3\n6 8 5 1 9 10 2 3 4 7", "10\n5 9 7 1 4 10 3 6 2 8\n8 3 9 10 6 5 2 1 7 4", "10\n9 10 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
55
codeforces
Okay, let's tackle this problem. Hmm, we need to find the permutation p based on the sequences a (third day) and b (fourth day). Let's understand what's happening here. So, the students pass their notebooks each day according to p. On day 1, everyone has their own. On day 2, each student gives their notebook to p[i], ...
To solve this problem, we need to determine the permutation array `p` representing the best friend relationships among students based on the given sequences `a` (third day) and `b` (fourth day). The key insight is that each element in `a` and `b` can be derived from applying the permutation `p` multiple times. Specific...
true
b577e53a353f5d81e069f5c1079023ae
I.O.U.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The...
{"inputs": ["5 3\n1 2 10\n2 3 1\n2 4 1", "3 0", "4 3\n1 2 1\n2 3 1\n3 1 1", "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\n5 17 8\n6 9 9\n6 16 2\n6 19 9\n7 14 6\n8 9 3\n8 16 10\n9 11 7\n9 17 8\n11 13 8\n11 17 17\n11 19 1\n15 20 2\n17 20 1", "20 36\n1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
99
codeforces
Okay, let's try to understand this problem. So, we have a group of n friends, and some debts between them. Our goal is to rearrange these debts in such a way that the total sum of all debts is minimized, but the net effect for each person remains the same. That means, after rearrangement, each person's total owed (what...
To solve this problem, we need to optimize the debts among a group of friends such that the total sum of all debts is minimized while maintaining the same net balance for each person. The key insight is to compute the net balance for each person and then determine the minimal sum of debts required to settle these balan...
true
b596102013f72cefd7ac7e1ee3b233f1
Ravioli Sort
Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you... You come up with...
{"inputs": ["3\n1 2 3", "3\n3 1 2", "1\n13", "10\n67 67 67 67 67 67 67 67 67 67", "10\n16 17 16 15 14 15 16 17 16 15", "4\n54 54 54 55", "3\n68 67 67", "5\n46 46 47 46 45", "4\n14 15 15 16", "6\n59 59 60 60 59 58", "3\n40 40 40", "4\n90 91 90 91", "10\n9 9 9 10 10 9 8 8 9 9", "3\n22 23 24", "9\n71 71 70 70 71 70 69 70 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
31
codeforces
Okay, let's see. I need to determine whether the described ravioli sorting algorithm will correctly sort a given array. The problem says that if two adjacent stacks differ in height by two or more, the top ravioli of the taller one slides down. So this can change the stacks during the sorting process, which might affec...
To solve this problem, we need to determine if the described ravioli sorting algorithm will correctly sort the given array in non-decreasing order. The algorithm involves repeatedly removing the tallest stack of ravioli and adjusting the remaining stacks to prevent sliding of ravioli between adjacent stacks with signif...
false
Code is incorrect.
b599781f151d50775bd909266a6d2d84
Steps
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
{"inputs": ["4 5\n1 1\n3\n1 1\n1 1\n0 -2", "10 10\n1 2\n1\n-1 0", "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5", "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n20 3\n-1 -16\n0 2\n-1 1\n20 0\n-1 1", "1000 2000\n226 566\n20\n0 -100\n-100 100\n100 0\n42 0\n-100 -79\n-66 -16\n0 -7\n-1 0\n0 10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
90
codeforces
Okay, let's tackle this problem. Hmm. So the task is to calculate the total number of steps Vasya takes based on the given vectors. Let me understand the problem step by step. The setup is that Vasya starts at a certain position in a grid. For each vector in the list, he moves as many steps as possible in that directi...
To solve this problem, we need to determine the maximum number of valid steps Vasya can take in each direction specified by the given vectors, without moving out of the yard. The solution involves calculating the maximum steps for each vector direction and summing them up. ### Approach 1. **Input Reading**: Read the y...
true
b5c7aed54daabe4e21c9ed4af7d7a6e1
Abracadabra
Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: - On the first step the string consists of a single character "a". - On the *k*-th step Polycarpus concatenates two copies of the string obtained on the (*k*<=-<=1)-th step, while inserting the *k*-th characte...
{"inputs": ["3 6 1 4", "1 1 4 4", "2 2 6 6", "73426655 594361930 343984155 989446962", "169720415 312105195 670978284 671296539", "1 1 1 1", "1 1 2 3", "2 3 1 1", "4 5 6 7", "5 6 5 10", "20 59 93 97", "59 797 761 863", "3563 8248 1195 5811", "26733 47464 19138 46248", "183307 582175 813247 925985", "42765 7043311 39308...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
Okay, let's see. The problem is to find the longest common substring between two substrings of the string generated by Polycarpus after 30 steps. The input gives the ranges for the two substrings, but the catch is that the actual string is huge—after 30 steps, it's 2^30 -1 characters long. So we can't generate it direc...
To solve this problem, we need to determine the length of the longest common substring between two given substrings of a recursively constructed string. The string is built using a specific algorithm, and due to its enormous size after 30 steps, we must analyze the structure efficiently without generating the entire st...
false
Code is incorrect.
b5d91d162d7adcda8d76b38528f7d618
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
{"inputs": ["3\n0 2 7\n2 0 9\n7 9 0", "3\n1 2 7\n2 0 9\n7 9 0", "3\n0 2 2\n7 0 9\n7 9 0", "3\n0 1 1\n1 0 1\n1 1 0", "2\n0 0\n0 0", "1\n0", "1\n1", "2\n0 1000000000\n1000000000 0", "5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "2\n0 1\n1 0", "4\n0 3 7 6\n3 0 4 9\n7 4 0 2\n6 9 2 0", "3\n0 1 2\n1 0 2\n2 2 0"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, so I need to solve this problem where given a distance matrix, I have to determine if it's possible that this matrix represents a weighted tree. The tree's edges must have positive integer weights. Hmm, let's think about the properties a distance matrix must have to come from a tree. First, I remember that in a ...
To solve this problem, we need to determine if a given distance matrix can be derived from a weighted tree with positive integer weights. The solution involves checking several properties of the matrix and then attempting to construct a tree that matches the given distances. ### Approach 1. **Initial Checks**: - **...
true
b5dc46e82fa44550d2c5ae0bef993f26
Messages
There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any mome...
{"inputs": ["4 5 5 3 5\n1 5 5 4", "5 3 1 1 3\n2 2 2 1 1", "5 5 3 4 5\n1 2 3 4 5", "1 6 4 3 9\n2", "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3", "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 260 349 89",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
107
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. So, the problem is about Vasya receiving messages over time, and each message's value decreases over time. He can read them at any time after receiving, and each minute, his bank account gets C multiplied by the number of unrea...
To solve this problem, we need to determine the maximum amount of money Vasya's bank account can hold after T minutes, considering the cost of each message decreases over time and the bank account gains money based on the number of unread messages each minute. ### Approach 1. **Understanding the Problem**: Each messag...
true
b5deae704fa7e015b4155280c24f9733
Count Good Substrings
We call a string good, if after merging all the consecutive equal characters, the resulting string is palindrome. For example, "aabba" is good, because after the merging step it will become "aba". Given a string, you have to find two values: 1. the number of good substrings of even length; 1. the number of good sub...
{"inputs": ["bb", "baab", "babb", "babaa", "baabbbb", "babbbbbaaabaabbabbabbababbaaba", "baabaababaabbaabaaabbbaaaaaabbbabaaaabbbaaaaaaaaabbaabbbaabbaabbaabbababbbbbaaabbaabaaaaabaababbbbababaabaababbbaabbbaabbbbaaaabaabbbaabbbbbabbbabbabaaaabbbabbbaabaaaabbbbabbbababbabaaaabbabababbaaaaaabaabaaaaabbbbabbabbababaaaaabb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
Okay, so I need to solve this problem where I have to count the number of good substrings in a given string. The definition of a good substring is that after merging all consecutive equal characters, the resulting string is a palindrome. For example, "aabba" becomes "aba" after merging, which is a palindrome. So my tas...
To solve this problem, we need to count the number of good substrings of even and odd lengths in a given string. A substring is considered good if, after merging all consecutive equal characters, the resulting string is a palindrome. This translates to finding substrings where the number of transitions between characte...
false
Code is incorrect.
b60b41ba80a849c2e35814b18f11ad83
Bear and Compressing
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of *q* possible operations. Limak can perform them in any order...
{"inputs": ["3 5\nab a\ncc c\nca a\nee c\nff d", "2 8\naf e\ndc d\ncc f\nbc b\nda b\neb a\nbb b\nff c", "6 2\nbb a\nba a", "2 5\nfe b\nbb a\naf b\nfd b\nbf c", "3 4\neb b\nbd a\ncd d\nbb b", "3 36\nab b\nbb a\naf c\nbd b\ncd a\nff c\nce a\nae a\ncb a\nba a\nad d\ndb a\nbf a\nbe a\ncc b\ndc a\nbc a\nca e\naa e\nec b\nac...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
77
codeforces
Okay, let's tackle this problem. Hmm. So, the problem is about counting the number of possible starting strings of length n that can be reduced to the single character 'a' through a series of operations. Each operation allows replacing the first two characters of the current string with a single character, provided the...
To solve this problem, we need to determine how many initial strings of length `n` (composed of the first six letters of the English alphabet) can be transformed into the string "a" using a given set of operations. Each operation allows replacing the first two characters of the string with a single character if they ma...
true
b6301df465da106d16a20b6a53b96e3b
Mahmoud and Ehab and the even-odd game
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab'...
{"inputs": ["1", "2", "10000", "33333", "5", "1000000000", "999999999", "123123123", "22222221", "22222220", "3", "4", "6", "7", "8", "9", "10", "536870912", "536870913", "536870911"], "outputs": ["Ehab", "Mahmoud", "Mahmoud", "Ehab", "Ehab", "Mahmoud", "Ehab", "Ehab", "Ehab", "Mahmoud", "Ehab", "Mahmoud", "Mahmoud", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
224
codeforces
Okay, let's see. We need to determine who wins the even-odd game between Mahmoud and Ehab based on the initial number n. The rules are a bit tricky. So Mahmoud goes first. On his turn, he must subtract an even number a (1 ≤ a ≤ current n, and a is even). Then Ehab's turn, he subtracts an odd number a under the same con...
To solve this problem, we need to determine the winner of the even-odd game between Mahmoud and Ehab based on the initial number \( n \). The game rules dictate that Mahmoud starts first and must subtract an even number, while Ehab subtracts an odd number on his turn. The player who cannot make a move loses. ### Appro...
true
b63cf6da05f344b33246dec66bd7e951
The Time
You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes. Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedi...
{"inputs": ["23:59\n10", "20:20\n121", "10:10\n0", "12:34\n10000", "00:00\n10000", "00:00\n1440", "23:59\n8640", "10:01\n0", "04:05\n0", "02:59\n1", "05:15\n10", "03:10\n20", "09:11\n0", "19:00\n0", "23:59\n1", "11:59\n1", "19:34\n566", "00:01\n59", "03:30\n0", "22:30\n30", "22:50\n70", "05:12\n0", "09:20\n40", "15:04\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
186
codeforces
Okay, I need to solve this problem where given a time in hh:mm format and a number of minutes a, I have to find the time after adding those minutes. Let's think about how to approach this. First, let's parse the input. The input has two lines. The first line is the current time, like "23:59", and the second line is th...
To solve this problem, we need to determine the time after a given number of minutes have passed from a specified start time in 24-hour format. The solution involves converting the start time into total minutes, adding the given minutes, and then converting the result back into the 24-hour format. ### Approach 1. **Pa...
true
b6507c39ea5f74da765fc7a4061089ca
Gerald's Hexagon
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He pain...
{"inputs": ["1 1 1 1 1 1", "1 2 1 2 1 2", "2 4 5 3 3 6", "45 19 48 18 46 21", "66 6 65 6 66 5", "7 5 4 8 4 5", "3 2 1 4 1 2", "7 1 7 3 5 3", "9 2 9 3 8 3", "1 6 1 5 2 5", "41 64 48 61 44 68", "1 59 2 59 1 60", "30 36 36 32 34 38", "50 40 46 38 52 34", "4 60 4 60 4 60", "718 466 729 470 714 481", "131 425 143 461 95 473...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
147
codeforces
Okay, I need to solve this programming problem. Let me read the problem carefully. So the problem is about a hexagon with all angles equal. Each side is an integer, and after drawing lines parallel to the sides, it's split into small triangles of 1 cm sides. We need to find the number of these triangles. Hmm. The sam...
To solve this problem, we need to determine the number of unit equilateral triangles that form a given equiangular hexagon. The hexagon's sides are integer lengths, and we need to count the triangles formed by lines parallel to the hexagon's sides. ### Approach 1. **Understanding the Hexagon Structure**: The hexagon i...
true
b6672363faf5a42cbddc6ff649f205ea
Group of Students
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ...
{"inputs": ["5\n3 4 3 2 1\n6 8", "5\n0 3 3 4 2\n3 10", "2\n2 5\n3 6", "3\n0 1 0\n2 10", "5\n2 2 2 2 2\n5 5", "10\n1 1 1 1 1 1 1 1 1 1\n1 10", "10\n1 1 1 1 1 1 1 1 1 1\n5 5", "6\n0 0 1 1 0 0\n1 6", "7\n3 2 3 3 2 1 1\n5 10", "4\n1 0 0 100\n1 100", "100\n46 6 71 27 94 59 99 82 5 41 18 89 86 2 31 35 52 18 1 14 54 11 28 83 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
95
codeforces
Okay, let's see. I need to solve this programming problem. Let's read the problem carefully. The task is to find a passing rate k such that when students are split into two groups based on their scores (those below k go to beginner, those >=k go to intermediate), both groups have sizes within x and y inclusive. If the...
To solve this problem, we need to determine the passing rate \( k \) such that students are divided into two groups (beginner and intermediate) with each group's size within a specified range \([x, y]\). The solution involves calculating the sizes of the groups for each possible passing rate and checking if they meet t...
true
b672c0578e56eba7e555c45884a47834
Vasya the Hipster
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
{"inputs": ["3 1", "2 3", "7 3", "100 100", "4 10", "6 10", "6 11", "10 40", "11 56", "34 30", "33 33", "100 45", "100 23", "45 12", "1 1", "1 100", "100 1", "68 59", "45 99", "99 100", "100 98", "59 12", "86 4", "68 21", "100 11", "100 10", "15 45", "11 32", "34 96", "89 89"], "outputs": ["1 1", "2 0", "3 2", "100 0",...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
958
codeforces
Okay, let's try to solve this problem. Hmm, the problem says that Vasya wants to wear different colored socks each day for as long as possible, and then switch to wearing same colored socks. We need to find two numbers: the maximum days he can wear different colors, and then the days he can wear same colors afterwards....
To solve this problem, we need to determine the maximum number of days Vasya can wear fashionable socks of different colors and the subsequent number of days he can wear socks of the same color until he runs out of socks or can't form a pair. ### Approach 1. **Different Colored Socks**: The maximum number of days Vasy...
true
b69966fa1be3df61ae53f6d11ed7ea9a
Dima and Two Sequences
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*). Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that...
{"inputs": ["1\n1\n2\n7", "2\n1 2\n2 3\n11", "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5 3 10 4 4 6 9 9 3 2 6 6\n4 3 8 4 4 2 4 6 6 3 3 5 8 4 1 6 2 7 6 1 6 10 7 9 2 9 2 9 10 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's tackle this problem. Hmm, what's the question again? So, Dima has two sequences of points, each with n points. He wants to combine them into a sequence of 2n points such that the x-coordinates are non-decreasing. Also, each point from the original sequences must be used exactly once. And we need to count th...
To solve this problem, we need to count the number of distinct sequences of length 2n that can be formed by interleaving points from two given sequences such that the x-coordinates of the resulting sequence are non-decreasing. The result should be computed modulo a given integer m. ### Approach 1. **Combine Points**: ...
false
Code is incorrect.
b6f07197a8fc3bc347b904acb9b96107
Xenia and Ringroad
Xenia lives in a city that has *n* houses built along the main ringroad. The ringroad houses are numbered 1 through *n* in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1. As a result, she's got *m* things to do. In order to complete...
{"inputs": ["4 3\n3 2 3", "4 3\n2 3 3", "2 2\n1 1", "2 2\n1 2", "2 2\n1 2", "100 100\n56 46 1 47 5 86 45 35 81 1 31 70 67 70 62 99 100 47 44 33 78 35 32 37 92 12 95 18 3 22 54 24 22 90 25 22 78 88 51 92 46 84 15 29 28 40 8 5 93 68 77 47 45 76 85 39 84 94 52 69 93 64 31 60 99 17 51 59 62 37 46 47 86 60 88 14 68 22 47 93...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
89
codeforces
Okay, let's see. The problem is about Xenia moving around a ringroad with houses numbered 1 to n in a clockwise direction. She starts at house 1 and has to complete m tasks in order. Each task i requires her to be at house a_i, and she can only do task i after all previous tasks are done. The question is to find the mi...
To solve this problem, we need to determine the minimum time Xenia requires to complete all her tasks while moving along a one-way ringroad in a clockwise direction. Each task must be completed in the given order, and moving between adjacent houses takes one unit of time. ### Approach 1. **Understanding Movement**: Si...
true
b70de8293485a4fce89810f0c6ad4733
Tricky Sum
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. Th...
{"inputs": ["2\n4\n1000000000", "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "100\n901\n712\n3\n677\n652\n757\n963\n134\n205\n888\n847\n283\n591\n984\n1\n61\n540\n986\n950\n729\n104\n244\n500\n461\n251\n685\n631\n803\n526\n600\n1000\n899\n411\n219\n597\n342\n771\n348\n507\n775\n454\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
261
codeforces
Okay, I need to solve this problem where I have to calculate the sum of all integers from 1 to n, but subtract all the powers of two. Let's think about this step by step. First, let's understand the example. For n=4, the sum is 1 - 2 + 3 -4. Because 1, 2, 4 are powers of two (2^0, 2^1, 2^2). So their contributions are...
To solve this problem, we need to calculate the sum of all integers from 1 to n, but subtract all the powers of two from the sum. The solution involves efficiently computing the sum of integers up to n and adjusting for the powers of two. ### Approach 1. **Sum of Integers**: The sum of all integers from 1 to n can be ...
false
Code is incorrect.
b713b03e6099d1ef6f57349f4ce7e41e
Chloe and the sequence
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad. Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq...
{"inputs": ["3 2", "4 8", "5 27", "7 44", "15 18432", "20 259676", "30 671088640", "38 137438953472", "1 1", "3 3", "4 12", "8 224", "13 1368", "16 49152", "19 1024", "24 15204352", "27 6586544", "31 536870912", "38 94489280512", "42 215268308020", "42 3452074721280", "46 34394312982528", "48 133865540681728", "49 7654...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
237
codeforces
Okay, let's see. So the problem is about generating a sequence through some steps and then finding the k-th element after n-1 steps. The sample input for n=3 and k=2 gives output 2. Let me try to understand how the sequence is built. The initial step is the sequence [1]. Then each step appends the current sequence to ...
To solve this problem, we need to determine the value of the element at position \( k \) in a sequence generated through a specific recursive process after \( n-1 \) steps. The sequence starts with a single element [1] and grows by appending itself with the next smallest unused positive integer in the middle at each st...
true
b7238b46f51e396406ba4766796bbe9e
DZY Loves Chemistry
DZY loves chemistry, and he enjoys mixing chemicals. DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ...
{"inputs": ["1 0", "2 1\n1 2", "3 2\n1 2\n2 3", "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7", "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12\n2 15\n5 17\n5 14\n6 14\n12 20\n7 20\n1 6\n1 7\n2 19\n14 17\n1 10\n11 15\n9 18\n2 12", "30 30\n7 28\n16 26\n14 24\n16 18\n20 29\n4 28\n19 21\n8 26\n1 25\n14 22\n13 23\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
60
codeforces
Okay, let's see. So the problem is about finding the maximum possible danger when adding chemicals into a test tube in a certain order. The danger starts at 1. Each time you add a chemical, if there's at least one chemical already in the tube that reacts with it, the danger doubles. Otherwise, it stays the same. We nee...
To solve this problem, we need to determine the maximum possible danger when pouring chemicals into a test tube in an optimal order. The danger starts at 1 and doubles each time a chemical is added that reacts with any already present in the tube. The goal is to find the optimal order to maximize the danger. ### Appro...
true
b7309b7ebc8cd521bc6f78479feeec2b
Flipping Game
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*) and flips all values *a**k* for which their positions are in...
{"inputs": ["5\n1 0 0 1 0", "4\n1 0 0 1", "1\n1", "1\n0", "8\n1 0 0 0 1 0 0 0", "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "23\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "100\n0 1 0 1 1 1 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 1 0 0 1 1 1 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
167
codeforces
Okay, let's see. The problem is about flipping a subarray (a consecutive sequence of elements) in a binary array (elements are 0s and 1s) to get the maximum number of 1s after exactly one flip. We have to choose which subarray to flip such that this maximum is achieved. Hmm. So the initial approach is to figure out, f...
To solve this problem, we need to determine the maximum number of 1s that can be obtained after flipping exactly one subarray in a given binary array. The approach involves transforming the problem into finding the maximum subarray sum using Kadane's algorithm, which efficiently computes this in linear time. ### Appro...
true
b7615d17dd2c5e3883a3b7d1502b8c28
Tavas and SaDDas
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
{"inputs": ["4", "7", "77", "4", "474744", "777774", "447", "774", "4", "4447747", "7747474", "4444", "4447", "7", "4", "4447744", "77474", "7747", "444", "7", "7774477", "4477774", "7444", "7474747", "77", "774477", "7", "47", "747777", "444444444", "777777777", "477477447", "777744747"], "outputs": ["1", "2", "6", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
524
codeforces
Okay, let's see. I need to find the 1-based index of a given lucky number when all lucky numbers are sorted in increasing order. Lucky numbers are those that consist only of 4 and 7 digits. So, for example, 4 is first, 7 is second, then 44, 47, 74, 77, etc. Hmm, the problem is to determine the position of the input nu...
To solve this problem, we need to determine the 1-based index of a given lucky number when all lucky numbers are sorted in increasing order. Lucky numbers are those that consist only of the digits 4 and 7. The approach involves converting the problem into a binary representation problem where each digit (4 or 7) is tre...
true
b762206307f1cbfb8fb8c9bee5981ae9
Is it rated?
Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before ...
{"inputs": ["6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "2\n1 1\n1 1", "2\n4126 4126\n4126 4126", "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
505
codeforces
Okay, let's tackle this problem. So, the task is to determine if a contest is rated, unrated, or maybe. Hmm. Let's read the problem statement carefully. The problem says that the participants are given in order from top to bottom of the standings. So, the first participant is the highest ranked, then the next, etc. Ea...
To solve this problem, we need to determine if a Codeforces round is rated, unrated, or if it's impossible to determine based on the participants' ratings before and after the round. The solution involves checking specific conditions derived from the problem statement. ### Approach 1. **Check for Rated Round**: If any...
true
b78c48bd93b78adcb886a8bf17ea0d92
Dasha and Puzzle
Dasha decided to have a rest after solving the problem. She had been ready to start her favourite activity — origami, but remembered the puzzle that she could not solve. The tree is a non-oriented connected graph without cycles. In particular, there always are *n*<=-<=1 edges in a tree with *n* vertices. The puzzle ...
{"inputs": ["7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "6\n1 2\n2 3\n2 4\n2 5\n2 6", "4\n1 2\n2 3\n3 4", "10\n2 9\n9 3\n3 10\n9 4\n9 6\n9 5\n2 7\n2 1\n2 8", "10\n2 5\n5 6\n6 1\n6 7\n6 8\n5 10\n5 3\n2 9\n2 4", "8\n7 8\n8 2\n2 4\n8 6\n8 5\n7 3\n7 1", "10\n10 9\n9 3\n3 4\n4 5\n5 1\n1 8\n8 2\n2 6\n6 7", "12\n1 5\n5 7\n7 4\n4 6\n4 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
Okay, I need to solve this problem where I have to determine if a given tree can be embedded on a 2D grid such that each edge is either horizontal or vertical, and no two edges (other than adjacent ones sharing a vertex) cross each other. If possible, output the coordinates of each vertex. Let's think through how to ap...
To solve this problem, we need to determine if a given tree can be embedded on a 2D grid such that each edge is either horizontal or vertical, and no two edges (other than adjacent ones sharing a vertex) cross each other. If possible, we need to output the coordinates of each vertex. ### Approach 1. **Check Validity**...
false
Code is incorrect.
b7a803bd3143ed90bd6acb94d848ca80
Bank Robbery
A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the *i*-th safe f...
{"inputs": ["5 3 7\n8\n4 7 5 5 3 6 2 8", "6 5 7\n5\n1 5 7 92 3", "3 2 4\n1\n3", "5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6", "7 3 10\n5\n3 3 3 3 3", "3 2 5\n4\n1 3 4 5", "3 2 4\n1\n1", "6 4 8\n1\n4", "2 1 3\n1\n3"], "outputs": ["4", "0", "1", "8", "0", "2", "0", "0", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
221
codeforces
Okay, let's try to figure out this problem. So, Oleg is at position a, and there are two guards at positions b and c. The guards are at positions such that b is <= a and c is >= a. So, Oleg can't go to any safe that's <=b or >=c. He can only move between safes that are strictly between b and c. Wait, no. Because the pr...
To solve this problem, we need to determine the maximum number of banknotes Oleg can collect from the safes, given the constraints imposed by the positions of the security guards. Oleg can only move within a specific range of safes, avoiding the guards' positions. ### Approach 1. **Identify Allowed Range**: Oleg can o...
true
b7bb00724e30ca5e030171a98d9c0d0c
Polo the Penguin and Houses
Little penguin Polo loves his home village. The village has *n* houses, indexed by integers from 1 to *n*. Each house has a plaque containing an integer, the *i*-th house has a plaque containing integer *p**i* (1<=≤<=*p**i*<=≤<=*n*). Little penguin Polo loves walking around this village. The walk looks like that. Firs...
{"inputs": ["5 2", "7 4", "8 5", "8 1", "10 7", "12 8", "50 2", "100 8", "1000 8", "999 7", "685 7", "975 8", "475 5", "227 6", "876 8", "1000 1", "1000 2", "1000 3", "1000 4", "1000 5", "1000 6", "657 3", "137 5", "8 8", "9 8", "1 1", "2 1", "2 2", "3 3", "473 4"], "outputs": ["54", "1728", "16875", "823543", "3176523...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
23
codeforces
Okay, let's try to understand this problem. So, we need to calculate the number of possible ways to assign plaques (p_i) to each house such that three conditions are satisfied. First, let's parse the conditions: 1. Any house from 1 to k must eventually reach house 1 when following the plaques. So, starting at any x ...
To solve this problem, we need to determine the number of valid ways to assign plaques to houses such that three specific conditions are met. The solution involves calculating two main parts: the valid configurations for the first k houses and the valid configurations for the remaining houses. ### Approach 1. **Unders...
true
b7ce3faab689d1f84c1a04272bc4d6e8
Classroom Watch
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ...
{"inputs": ["21", "20", "1", "2", "3", "100000001", "1000000000", "999999979", "9", "10", "11", "39", "66", "75", "100", "101", "2014", "999999994"], "outputs": ["1\n15", "0", "0", "1\n1", "0", "2\n99999937\n100000000", "1\n999999932", "2\n999999899\n999999908", "0", "1\n5", "1\n10", "1\n33", "1\n60", "0", "1\n86", "2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
172
codeforces
Okay, so I need to solve this programming problem. Let's read the problem carefully again. The problem says that given a number n, which is the result of x plus the sum of the digits of x. We have to find all possible x's that satisfy this equation. Then output the count of such x's and the x's in sorted order. If th...
To solve this problem, we need to determine all possible values of \( x \) such that \( x \) plus the sum of its digits equals a given number \( n \). The solution must efficiently find these values and handle large values of \( n \) up to \( 10^9 \). ### Approach 1. **Understanding the Problem**: We need to find all ...
true
b7d07bbf111bba1f3ecb254e4e9c03d1
Isomorphic Strings
You are given a string *s* of length *n* consisting of lowercase English letters. For two given strings *s* and *t*, say *S* is the set of distinct characters of *s* and *T* is the set of distinct characters of *t*. The strings *s* and *t* are isomorphic if their lengths are equal and there is a one-to-one mapping (bi...
{"inputs": ["7 4\nabacaba\n1 1 1\n1 4 2\n2 1 3\n2 4 3", "1 2\nz\n1 1 1\n1 1 1", "36 4\naababcbbcbczaaawwwwwaaaabbbbtestbest\n1 7 6\n13 18 5\n23 26 3\n29 33 4", "4 1\nabac\n1 2 3", "5 10\ncaabc\n5 4 1\n5 4 1\n1 5 1\n4 2 2\n1 3 1\n5 5 1\n4 4 1\n4 3 2\n1 4 1\n5 1 1", "10 30\naccbaaccac\n6 8 3\n2 9 1\n6 8 3\n10 5 1\n6 2 2\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
Okay, so I need to solve this problem where for multiple queries, I have to check if two substrings of a given string are isomorphic. The problem seems a bit tricky because the number of queries and the string length can be up to 2e5, which is pretty large. So any brute-force approach is definitely not going to work he...
To solve this problem, we need to determine if two substrings of a given string are isomorphic. Two strings are isomorphic if there exists a bijection between the sets of characters such that each character in one string maps to a corresponding character in the other string while preserving the order and structure. ##...
false
Code is incorrect.
b7d321c69eff68ca61b821eff8437223
Median
A median in an array with the length of *n* is an element which occupies position number after we sort the elements in the non-decreasing order (the array elements are numbered starting with 1). A median of an array (2,<=6,<=1,<=2,<=3) is the number 2, and a median of array (0,<=96,<=17,<=23) — the number 17. We defi...
{"inputs": ["3 10\n10 20 30", "3 4\n1 2 3", "2 2\n3 2", "5 1\n1 1 2 1 2", "5 4\n5 5 4 3 5", "10 2\n2 2 1 3 2 1 2 1 1 3", "10 55749\n46380 58202 54935 26290 18295 83040 6933 89652 75187 93963", "10 809\n949 31 175 118 640 588 809 398 792 743", "50 1\n1 2 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 2 2 2 2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
27
codeforces
Okay, let's see. So the problem is to find the minimum number of elements Petya needs to add to an array so that the median becomes x. Hmm. The initial array can't be changed, only added to. And the added elements can be any integers between 1 and 1e5, including duplicates. Wait, first, I need to understand what the m...
To solve this problem, we need to determine the minimum number of elements to add to an array so that its median becomes a specified value \( x \). The median is defined as the element at position \(\left\lfloor \frac{n+1}{2} \right\rfloor\) (1-based index) after sorting the array. ### Approach 1. **Sort the Initial A...
true
b7dcd21ec503ab2edf961df1c3ec9de6
k-rounding
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. W...
{"inputs": ["375 4", "10000 1", "38101 0", "123456789 8", "1 0", "2 0", "100 0", "1000000000 0", "160 2", "3 0", "10 0", "1 1", "2 1", "3 1", "4 1", "5 1", "6 1", "7 1", "8 1", "9 1", "10 1", "11 1", "12 1", "16 2", "2 2", "1 2", "5 2", "15 2", "36 2", "1 8", "8 8", "96 8", "175 8", "9999995 8", "999999999 8", "1234567...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
250
codeforces
Okay, let's see. I need to find the k-rounding of a given number n. The k-rounding is the smallest x such that x is divisible by n and ends with at least k zeros. So x must be a multiple of n and also a multiple of 10^k, right? Because ending with k zeros means it's divisible by 10^k. But wait, maybe not exactly. Becau...
To solve this problem, we need to find the smallest positive integer \( x \) such that \( x \) is divisible by a given integer \( n \) and ends with at least \( k \) zeros. This is known as the \( k \)-rounding of \( n \). ### Approach The key insight is that the smallest \( x \) which meets the criteria must be the l...
true
b7f25d647ca43fead8becd81059cb693
Bear in the Field
Our bear's forest has a checkered field. The checkered field is an *n*<=×<=*n* table, the rows are numbered from 1 to *n* from top to bottom, the columns are numbered from 1 to *n* from left to right. Let's denote a cell of the field on the intersection of row *x* and column *y* by record (*x*,<=*y*). Each cell of the ...
{"inputs": ["5 1 2 0 1 2", "1 1 1 -1 -1 2", "1 1 1 1 1 0", "2 2 1 -2 -2 5", "1000000000 1 1 1 1 1000000000000000000", "1000000000 1 2 -100 -100 1", "3 2 2 -100 -100 2", "1000000000 1000000000 1000000000 100 -100 1000000000000000000", "907122235 107269653 309181328 26 -64 242045007473044676", "804 658 177 -95 37 9", "2 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's see. The problem is about simulating the bear's movement on a grid over t seconds. But given that t can be up to 1e18, simulating each step one by one is impossible. So we need a mathematical approach to find patterns or formulas that can calculate the position after t steps without iterating through each s...
To solve this problem, we need to determine the final position of a bear after it moves across an n×n grid for t seconds. The bear's movement is influenced by its speed, which changes dynamically based on the number of raspberry bushes it eats each second. Given the constraints, a direct simulation approach is infeasib...
false
Code is incorrect.
b7fb6e57a6651eb7e580fa89cf2c426c
Cutting Rectangle
A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectangles were of $n$ different types. Two rectangles are different if at least o...
{"inputs": ["1\n1 1 9", "2\n2 3 20\n2 4 40", "2\n1 2 5\n2 3 5"], "outputs": ["3", "6", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's see. I need to solve this programming problem. Hmm. Let me read the problem carefully again. So the problem is about cutting a big rectangle into smaller rectangles using some horizontal and vertical cuts. After the cuts, there are n different types of rectangles. Each type has a specific width, height, an...
To solve this problem, we need to determine the number of valid pairs (A, B) such that a given set of smaller rectangles can be formed by cutting a larger rectangle of dimensions A and B using horizontal and vertical cuts. The solution involves checking the constraints on the dimensions and counts of the smaller rectan...
false
Code is incorrect.
b81d6b2d5370a2792e2da862c3adb452
Two Squares
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ...
{"inputs": ["0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "2 2 4 2 4 4 2 4\n0 3 3 6 6 3 3 0", "-5 -5 5 -5 5 5 -5 5\n-5 7 0 2 5 7 0 12", "-5 -5 5 -5 5 5 -5 5\n-5 12 0 7 5 12 0 17", "-5 -5 5 -5 5 5 -5 5\n6 0 0 6 -6 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
54
codeforces
Okay, I need to solve this problem where I have to determine if two squares intersect. One square is axis-aligned, and the other is rotated 45 degrees. The input gives both squares as four pairs of coordinates each, in order. The output is "YES" or "NO" based on whether they intersect. Hmm. Let's think about how to ap...
To solve this problem, we need to determine if two given squares intersect. One square is aligned with the coordinate axes, and the other is rotated 45 degrees. The solution involves checking for intersections using the Separating Axis Theorem (SAT), which helps determine if there exists a line (axis) that separates th...
true
b82293c0815f13d9f04492522106193c
Cows and Sequence
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: 1. Add the integer *x**i* to the first *a**i* elements of the sequence. 1. Append an integer *k**i* to the end of ...
{"inputs": ["5\n2 1\n3\n2 3\n2 1\n3", "6\n2 1\n1 2 20\n2 2\n1 2 -3\n3\n3", "1\n1 1 1", "1\n2 1", "2\n2 1\n1 2 1", "5\n2 1\n1 2 1\n2 1\n2 1\n1 2 1", "5\n1 1 7\n1 1 7\n1 1 7\n2 5\n1 2 2", "5\n1 1 -48\n1 1 19\n1 1 -35\n2 -67\n1 2 -13", "1\n1 1 0", "1\n2 0", "5\n2 -980\n1 2 -156\n2 641\n2 -253\n2 -514"], "outputs": ["0.500...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
22
codeforces
Okay, I need to solve this programming problem. Let me read the problem statement carefully. So, the problem is about Bessie and the cows performing operations on a sequence. The sequence starts with [0]. Then there are n operations, each of which is one of three types. After each operation, we have to output the aver...
To solve this problem, we need to efficiently handle three types of operations on a sequence and compute the average of the sequence after each operation. The operations include adding a value to the first few elements, appending an element to the end, and removing the last element. The challenge is to perform these op...
true
b85848958f173f58de6def1bf136ec8e
A Heap of Heaps
Andrew skipped lessons on the subject 'Algorithms and Data Structures' for the entire term. When he came to the final test, the teacher decided to give him a difficult task as a punishment. The teacher gave Andrew an array of *n* numbers *a*1, ..., *a**n*. After that he asked Andrew for each *k* from 1 to *n*<=-<=1 to...
{"inputs": ["5\n1 5 4 3 2", "6\n2 2 2 2 2 2", "2\n0 0", "2\n1 2", "2\n10 -1", "5\n934 235 171 111 197", "100\n0 1 1 1 0 0 0 2 1 2 2 1 2 2 2 0 0 2 1 2 0 1 1 0 2 0 1 2 2 0 2 0 1 0 1 2 0 2 1 1 0 1 0 1 0 0 1 2 2 2 2 1 1 1 0 2 1 0 0 0 0 0 1 0 2 0 1 0 0 2 0 2 2 1 0 2 2 0 2 0 2 1 2 1 1 1 0 2 1 0 2 1 1 2 1 2 0 1 2 2", "2\n-492...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. The task is: for each k from 1 to n-1, build a k-ary heap based on the given array and count how many elements violate the min-heap property. The violation occurs when a child is less than its parent. So for each k, iterate through all e...
To solve this problem, we need to determine the number of elements in a k-ary heap that violate the min-heap property for each k from 1 to n-1. The min-heap property is violated if a child element is smaller than its parent. ### Approach 1. **Understanding Parent-Child Relationship**: For each element `v` in a k-ary h...
true