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
fc15856b0b1fce8b88f14daf45f5346a
Painting Fence
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from o...
{"inputs": ["5\n2 2 1 2 1", "2\n2 2", "1\n5", "5\n2 2 1 2 2", "5\n2 2 1 5 1", "1\n1", "1\n1000000000", "2\n999635584 999595693", "10\n3 3 6 4 2 3 2 2 3 3", "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4", "6\n100 100 100 100 100 1", "7\n5 5 1 5 5 4 1", "4\n3 4 5 6", "4\n2 3 4 5", "8\n5000 5000 5 5000 5000 5000 5000 5000", "10\n4 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
Okay, let's try to figure out this problem. So, the problem is about finding the minimum number of strokes needed to paint a fence made up of vertical planks. The brush can make vertical or horizontal strokes, and each stroke must cover a continuous area. Hmm. First, let's understand the problem. Each plank is 1m wide...
To solve this problem, we need to determine the minimum number of strokes required to paint a fence represented by vertical planks of varying heights. The brush can make vertical strokes covering an entire plank or horizontal strokes covering contiguous segments of planks at the same height level. ### Approach The key...
false
Code is incorrect.
fc1b001cfed3da5734fdd1993f262d18
Demiurges Play Again
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on *n* nodes, *m* of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves...
{"inputs": ["5\n1 2\n1 3\n2 4\n2 5", "6\n1 2\n1 3\n3 4\n1 5\n5 6", "1", "2\n1 2", "3\n1 2\n1 3", "10\n1 2\n1 3\n3 4\n3 5\n4 6\n1 7\n3 8\n2 9\n6 10", "50\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n2...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's tackle this problem. So, the problem is about a game played on a tree where two players take turns moving a piece from the root down to a leaf. The goal is to determine the maximum and minimum possible outcomes when the numbers in the leaves are optimally arranged by the two Demiurges. Hmm. Let's start by ...
To solve this problem, we need to determine the maximum and minimum possible outcomes of a game played on a rooted tree where two players move optimally. The goal is to rearrange the numbers in the leaves such that the outcome is maximized for one player and minimized for the other. ### Approach 1. **Tree Structure**:...
false
Code is incorrect.
fc3f5cc330553f4dda9bd40e698161f3
Quantity of Strings
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly *n*, based on the alphabet of size *m*. Any its substring with length equal to *k* is a palindrome. How many such strings exist? Your task ...
{"inputs": ["1 1 1", "5 2 4", "7 4 20", "8 13 9", "10 23 9", "10 25 8", "997 1752 1000", "784 1 1999", "341 9 342", "777 1 777", "542 13 542", "1501 893 1501", "1321 95 2", "2000 1000 3", "1769 849 1000", "1000 2 1", "345 1777 1", "1999 2000 2000", "1984 1847 1992", "2000 2000 2000", "1451 239 1451", "2000 2000 1", "12...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
15
codeforces
Okay, let's try to solve this problem. Hmm, the problem says we need to count the number of strings of length n, using an alphabet of size m, such that every substring of length k is a palindrome. And the answer has to be modulo 1e9+7. Alright. First, I need to understand the conditions. Let's break it down. For a str...
To solve this problem, we need to count the number of valid strings of length `n` using an alphabet of size `m` such that every substring of length `k` is a palindrome. The result should be computed modulo \(10^9 + 7\). ### Approach 1. **Edge Cases Handling**: - If `k > n`, there are no valid substrings of length `...
true
fc5b374c0c467d1243d8dce71f849633
Remove Duplicates
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. The first line contains a single integer $n$ ($1 \le n \...
{"inputs": ["6\n1 5 5 1 6 1", "5\n2 4 2 4 4", "5\n6 6 6 6 6", "7\n1 2 3 4 2 2 3", "9\n100 100 100 99 99 99 100 100 100", "27\n489 489 487 488 750 230 43 645 42 42 489 42 973 42 973 750 645 355 868 112 868 489 750 489 887 489 868", "40\n151 421 421 909 117 222 909 954 227 421 227 954 954 222 421 227 421 421 421 151 421 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
191
codeforces
Okay, let's see. The problem is about removing duplicates from an array, but keeping only the rightmost occurrence of each element. So the order of the remaining elements should be the same as their last occurrence in the original array. Hmm. Wait, the example makes sense. For the first sample input: 1 5 5 1 6 1. The ...
To solve this problem, we need to remove duplicate elements from an array such that only the rightmost occurrence of each element is retained, while maintaining the relative order of the remaining elements as they appeared in the original array. ### Approach 1. **Identify Last Occurrences**: First, we determine the la...
true
fc7661143e4b4a08461bb4de57185e76
Connecting Universities
Treeland is a country in which there are *n* towns connected by *n*<=-<=1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2*k* universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network...
{"inputs": ["7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6", "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8", "41 3\n11 10 15 35 34 6\n28 2\n25 3\n9 4\n11 5\n7 6\n24 7\n19 8\n1 9\n34 10\n23 11\n17 12\n32 13\n32 14\n32 15\n33 16\n8 17\n19 18\n40 19\n15 20\n6 21\n41 22\n35 23\n13 24\n6 25\n22 26\n4 27\n31 28\n34 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
7
codeforces
Okay, let's try to figure out this problem. So the task is to pair up 2k universities such that the sum of the distances between each pair is maximized. All right, so the main question is, how do we pair them to get the maximum total distance? Hmm, first, I remember that in tree structures, the maximum distance betwee...
To solve this problem, we need to pair universities in a tree structure such that the total distance between each pair is maximized. The approach involves leveraging the tree's properties to efficiently compute the maximum possible sum of distances. ### Approach 1. **Tree Structure**: The problem involves a tree where...
true
fc7f2f0fe3c4df9f28490f80781ce3fe
The Tag Game
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of *n* vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex *x* (*x*<=≠<=1). The moves are made in turns, Bob go...
{"inputs": ["4 3\n1 2\n2 3\n2 4", "5 2\n1 2\n2 3\n3 4\n2 5", "2 2\n2 1", "3 3\n2 1\n3 1", "3 3\n1 2\n3 2", "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8", "10 7\n8 7\n2 8\n2 3\n10 6\n4 6\n4 1\n10 5\n7 5\n9 8", "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6", "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
13
codeforces
Okay, let's try to understand the problem. So Alice and Bob are playing a modified tag game on a tree. The tree is rooted at vertex 1. Alice starts at the root, and Bob starts at some vertex x (which isn't the root). Bob goes first. Each move, a player can either stay or move to a neighboring vertex. The game ends when...
To solve this problem, we need to determine the maximum number of moves Alice and Bob will make in a modified tag game played on an undirected rooted tree. Alice starts at the root (vertex 1) and Bob starts at a given vertex x. Bob moves first, and both players can either stay or move to a neighboring vertex. The game ...
true
fc8112700bb19b73b5f2cb0b6e677aac
Robot Arm
Roger is a robot. He has an arm that is a series of *n* segments connected to each other. The endpoints of the *i*-th segment are initially located at points (*i*<=-<=1,<=0) and (*i*,<=0). The endpoint at (*i*<=-<=1,<=0) is colored red and the endpoint at (*i*,<=0) is colored blue for all segments. Thus, the blue endpo...
{"inputs": ["5 4\n1 1 3\n2 3 90\n2 5 48\n1 4 1", "1 1\n2 1 302", "50 50\n1 41 261\n2 47 324\n1 41 256\n1 31 339\n2 23 116\n2 44 184\n2 32 115\n1 40 301\n2 40 303\n1 29 309\n2 49 348\n2 47 356\n1 41 263\n2 42 276\n1 45 135\n1 33 226\n2 31 166\n1 50 171\n2 47 166\n2 50 284\n2 25 324\n2 48 307\n2 41 176\n1 50 353\n1 45 32...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's see. I need to solve this programming problem. Let's read through the problem statement carefully. So the problem is about Roger's robotic arm, which consists of n segments. Each segment i has endpoints at (i-1, 0) and (i, 0) initially. The red end is at (i-1, 0) and the blue at (i, 0). The blue of segment...
To solve this problem, we need to track the position of the blue endpoint of the last segment of Roger's robotic arm after each operation. The operations include extending a segment in its current direction and rotating a segment along with all subsequent segments around its red endpoint. The solution involves efficien...
false
Code is incorrect.
fc94946d03aa4b544ec22213ebaed643
Jury Size
In 2013, the writers of Berland State University should prepare problems for *n* Olympiads. We will assume that the Olympiads are numbered with consecutive integers from 1 to *n*. For each Olympiad we know how many members of the jury must be involved in its preparation, as well as the time required to prepare the prob...
{"inputs": ["2\n5 23 1 2\n3 13 2 3", "3\n12 9 2 1\n12 8 1 3\n12 8 2 2", "1\n1 10 1 13", "3\n3 16 25 1\n3 15 9 34\n3 14 90 87", "4\n2 15 52 53\n2 15 35 81\n2 15 39 96\n2 14 87 7", "5\n3 6 40 89\n3 4 24 64\n2 28 83 1\n3 3 15 32\n3 8 54 28", "10\n8 8 4 18\n8 10 100 36\n8 9 17 51\n8 10 90 8\n8 10 64 45\n8 10 90 81\n8 11 20...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
Okay, I need to solve this programming problem. Let's read the problem statement carefully. The problem is about scheduling jury members to prepare for multiple Olympiads such that no jury member works on two different Olympiads on the same day. The goal is to find the minimum number of jury members required. So, eac...
To solve this problem, we need to determine the minimum number of jury members required to prepare for multiple Olympiads such that no jury member works on two different Olympiads on the same day. The solution involves calculating overlapping intervals of preparation periods and finding the maximum number of jury membe...
true
fcc1dd7c8d355e18d211514350671eac
Curriculum Vitae
Hideo Kojima has just quit his job at Konami. Now he is going to find a new place to work. Despite being such a well-known person, he still needs a CV to apply for a job. During all his career Hideo has produced *n* games. Some of them were successful, some were not. Hideo wants to remove several of them (possibly zer...
{"inputs": ["4\n1 1 0 1", "6\n0 1 0 0 1 0", "1\n0", "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "100\n0 0 1 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
Okay, so I need to solve this problem where Hideo wants to leave as many games in his CV as possible, but he can't have a 0 (unsuccessful) right after a 1 (successful). Let's think about how to approach this. The problem statement says that after removing some elements, the resulting array should not have any 0 follow...
To solve this problem, we need to determine the maximum number of games Hideo Kojima can leave in his CV such that no unsuccessful game (0) comes right after a successful game (1). The solution involves finding the longest valid subsequence where all 0s appear before any 1s. ### Approach 1. **Problem Analysis**: The v...
true
fccff7b6eaf8ac7a2e50f9817666b74d
Flowers
We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some of them white and some of them red. But, for a dinner to be tasty...
{"inputs": ["3 2\n1 3\n2 3\n4 4", "1 1\n1 3", "1 2\n64329 79425"], "outputs": ["6\n5\n5", "14", "0"]}
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
Okay, let's try to figure out this problem. So, the problem is about counting the number of valid dinner sequences that Marmot can eat. The valid sequences are those where white flowers are in groups of exactly size k. Red flowers can be any number. And we need to count all possible sequences with lengths between a and...
To solve this problem, we need to determine the number of valid sequences Marmot can eat between a given range of flowers, where each sequence adheres to the rule that white flowers must be in groups of exactly size k. The solution involves dynamic programming to precompute the number of valid sequences and prefix sums...
true
fcd19da2696717da4756587afbd33c82
Epic Game
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
{"inputs": ["3 5 9", "1 1 100", "23 12 16", "95 26 29", "73 32 99", "1 1 1", "41 12 65", "13 61 100", "100 100 10", "12 24 26", "73 21 96", "17 22 81", "14 88 97", "42 81 17", "34 36 19", "21 87 12", "97 92 98", "49 25 62", "29 17 44", "10 1 10", "99 98 100", "100 100 1", "11 99 55", "8 13 21", "34 55 89", "21 34 55", ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
780
codeforces
Okay, let's see. We need to determine who wins the game between Simon and Antisimon based on the given a, b, and n. The rules are a bit specific. So, Simon starts first. Each turn, the player takes stones equal to the GCD of their own fixed number and the current number of stones left. The player who can't take the r...
To solve this problem, we need to simulate a game where two players, Simon and Antisimon, take turns removing stones from a heap based on the greatest common divisor (GCD) of their fixed number and the current number of stones in the heap. The player who cannot take the required number of stones loses. Simon starts fir...
true
fcf8b343a907be0b2bab4149edfec28a
Valhalla Siege
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. T...
{"inputs": ["5 5\n1 2 1 2 1\n3 10 1 1 1", "4 4\n1 2 3 4\n9 1 10 6", "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "1 1\n56563128\n897699770", "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
129
codeforces
Okay, let's tackle this problem. Hmm, the problem statement is a bit complex, but I'll try to break it down step by step. So, the setup is that we have n warriors in a line. Each has a certain strength a_i, which is the number of arrows they can take before falling. Every minute, Lagertha's warriors shoot k_i arrows. ...
To solve this problem, we need to determine the number of standing warriors after each minute of battle, considering that warriors are revived if all of them are defeated at the end of a minute. The solution involves efficiently tracking the cumulative arrows shot and using prefix sums to determine the number of warrio...
false
Code is incorrect.
fd02ef2593cc46942a3abcb5c85a76c8
Case of Matryoshkas
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can...
{"inputs": ["3 2\n2 1 2\n1 3", "7 3\n3 1 3 7\n2 2 5\n2 4 6", "1 1\n1 1", "3 2\n1 2\n2 1 3", "5 3\n1 4\n3 1 2 3\n1 5", "8 5\n2 1 2\n2 3 4\n1 5\n2 6 7\n1 8", "10 10\n1 5\n1 4\n1 10\n1 3\n1 7\n1 1\n1 8\n1 6\n1 9\n1 2", "20 6\n3 8 9 13\n3 4 14 20\n2 15 17\n3 2 5 11\n5 7 10 12 18 19\n4 1 3 6 16", "50 10\n6 17 21 31 42 45 49...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
36
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. So, the problem is about matryoshka dolls (those Russian nesting dolls). The initial state is k chains of these dolls, and we need to get them into a single chain where each doll is nested into the next one in order (1→2→3…→n). Each oper...
To solve this problem, we need to determine the minimum time required to assemble a single chain of matryoshka dolls from an initial configuration of multiple chains. The goal is to form a chain where each doll is nested inside the next one in ascending order (1→2→3→...→n). ### Approach 1. **Identify the Longest Conse...
true
fd0688f764c0b19252d911aef21b9a3b
AND-permutations
Given an integer *N*, find two permutations: 1. Permutation *p* of numbers from 1 to *N* such that *p**i*<=≠<=*i* and *p**i*<=&amp;<=*i*<==<=0 for all *i*<==<=1,<=2,<=...,<=*N*. 1. Permutation *q* of numbers from 1 to *N* such that *q**i*<=≠<=*i* and *q**i*<=&amp;<=*i*<=≠<=0 for all *i*<==<=1,<=2,<=...,<=*N*. &amp;...
{"inputs": ["3", "6", "100000", "15", "16", "17", "1", "2", "4", "5", "7", "8", "9", "10", "31", "32", "33", "63", "64", "65", "127", "128", "129", "255", "256", "257", "511", "512", "513", "1023", "1024", "1025", "2047", "2048", "2049", "4095", "4096", "4097", "8191", "8192", "8193", "16383", "16384", "16385", "32767"...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's try to figure out this problem. The problem asks to generate two permutations p and q for a given integer N. Each permutation must satisfy that for every i from 1 to N, p_i is not equal to i, and p_i AND i equals 0. Similarly for q. Wait, wait, the description is a bit confusing. Let me read it again. Ah r...
To solve this problem, we need to generate two permutations for a given integer \( N \). The first permutation \( p \) must satisfy \( p_i \neq i \) and \( p_i \& i = 0 \) for all \( i \). The second permutation \( q \) must satisfy \( q_i \neq i \) and \( q_i \& i \neq 0 \) for all \( i \). ### Approach 1. **Permut...
false
Code is incorrect.
fd06e19867352ee76d0b1a3b9ab11217
Ann and Books
In Ann's favorite book shop are as many as *n* books on math and economics. Books are numbered from 1 to *n*. Each of them contains non-negative number of problems. Today there is a sale: any subsegment of a segment from *l* to *r* can be bought at a fixed price. Ann decided that she wants to buy such non-empty subs...
{"inputs": ["4 1\n1 1 1 2\n1 1 1 1\n4\n1 2\n1 3\n1 4\n3 4", "4 0\n1 2 1 2\n0 0 0 0\n1\n1 4", "10 10\n2 1 1 1 1 1 1 1 1 2\n0 10 10 0 0 10 10 10 10 0\n10\n4 10\n3 7\n9 9\n2 9\n10 10\n5 5\n2 2\n6 8\n3 4\n1 3", "10 -10\n1 2 1 2 1 1 2 2 2 1\n7 7 10 3 7 10 6 8 0 1\n10\n2 6\n10 10\n6 9\n5 8\n7 10\n2 7\n2 9\n2 7\n5 6\n2 8", "1...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
2
codeforces
Okay, let's see. I need to solve this programming problem. Let's read the problem carefully. So the problem is about Ann wanting to buy a subsegment of books from a given segment [l, r]. The subsegment must satisfy that the total number of math problems minus the economics problems is exactly k. For each query, we hav...
To solve this problem, we need to determine the number of subsegments within specified ranges where the difference between the number of math problems and economics problems is exactly k. This problem can be efficiently solved using Mo's algorithm, which allows us to handle multiple range queries by maintaining a dynam...
true
fd09090ef729ff93446db38cf1352d0b
Autocomplete
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
{"inputs": ["next\n2\nnextpermutation\nnextelement", "find\n4\nfind\nfindfirstof\nfindit\nfand", "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "kudljmxcse\n4\nkudljmxcse\nszjebdoad\nchz\na", "ntqwpa\n5\nvvepyowvn\nntqwpakay\nhh\nygiafasda\nntqwpadm", "aflb\n6\nsaej\nujxsiijg\npp\nhgoprw\ncp\nnt", "dzwzyj\n7\nwvixktp\...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
135
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. The task is to find the lexicographically smallest address that starts with a given prefix s. If none of the addresses start with s, then output s itself. Otherwise, pick the smallest one lex order and output that. So the steps I need t...
To solve this problem, we need to determine the lexicographically smallest address from a list of visited pages that starts with a given prefix. If no such address exists, we simply return the given prefix. ### Approach 1. **Read Input**: First, we read the prefix string `s` and the number of visited pages `n`. Then, ...
true
fd0a5d9f400dd636829e4e517f91376f
Friends and Presents
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends. In addition, the...
{"inputs": ["3 1 2 3", "1 3 2 3", "916200 69682 2 3", "808351 17767 433 509", "8851 901 20897 26183", "5099 2895 16273 29473", "5099 2895 16273 29473", "4969 694 293 2347", "683651932 161878530 2 5", "325832598 637961741 2 3", "999999999 1 2 3", "11006 976 6287 9007", "150064728 173287472 439 503", "819712074 101394406...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
33
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. The problem is about finding the minimal number v such that we can present cnt1 distinct numbers to the first friend and cnt2 to the second. All numbers presented must be unique. Also, the first friend can't have numbers divisible by x, ...
To solve this problem, we need to determine the minimum number \( v \) such that we can present distinct positive integers to two friends, adhering to their respective constraints. The first friend does not like numbers divisible by a prime \( x \), and the second friend does not like numbers divisible by a prime \( y ...
true
fd147d05260e80bd25ba2a334bf9f277
Comparing Two Long Integers
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can r...
{"inputs": ["9\n10", "11\n10", "00012345\n12345", "0123\n9", "0123\n111", "9\n9", "0\n0000", "1213121\n1213121", "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
93
codeforces
Okay, I need to write a Python function that compares two very large numbers given as strings. The input can have leading zeros, and the numbers can be up to 1e6 digits long. So I can't convert them to integers directly because that would be impossible for such large numbers. So I have to compare them as strings. Firs...
To solve this problem, we need to compare two very large integers provided as strings, which may contain leading zeros. The goal is to determine which number is greater, smaller, or if they are equal. Direct conversion to integers is impractical due to their potential size, so we handle them as strings. ### Approach 1...
true
fd1ce315ca7b872f90047714c866c036
Inventory
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the...
{"inputs": ["3\n1 3 2", "4\n2 2 3 3", "1\n2", "3\n3 3 1", "5\n1 1 1 1 1", "5\n5 3 4 4 2", "5\n19 11 8 8 10", "15\n2 2 1 2 1 2 3 3 1 3 2 1 2 3 2", "18\n3 11 5 9 5 4 6 4 5 7 5 1 8 11 11 2 1 9", "42\n999 863 440 1036 1186 908 330 265 382 417 858 286 834 922 42 569 79 158 312 1175 1069 188 21 1207 985 375 59 417 256 595 73...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
88
codeforces
Okay, let's see. I need to solve this problem where I have to renumber the inventory items so that they form a permutation of 1 to n, changing as few elements as possible. Hmm. The goal is to find the minimal number of changes. So first, I need to figure out which numbers are already in the correct position and can sta...
To solve this problem, we need to renumber the inventory items such that they form a permutation of numbers from 1 to n, changing as few items as possible. The goal is to maximize the use of existing valid numbers (those that are already unique and within the range 1 to n) and replace the rest with the smallest possibl...
false
Code is incorrect.
fd83dbf0a860282e31913add3b44f5c3
Permutations
A permutation is a sequence of integers from 1 to *n* of length *n* containing each number exactly once. For example, (1), (4,<=3,<=5,<=1,<=2), (3,<=2,<=1) are permutations, and (1,<=1), (4,<=3,<=1), (2,<=3,<=4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine tha...
{"inputs": ["9\n1 2 3 1 2 1 4 2 5", "4\n4 3 2 1", "4\n1 2 2 3", "1\n1", "1\n2", "5\n1 1 1 1 1", "3\n2 1 1", "6\n3 3 2 2 1 1", "2\n1000 1", "5\n2 2 1 1 3", "10\n2 1 2 4 6 1 5 3 7 1", "10\n4 1 2 1 3 3 1 2 2 1", "10\n1 2 5 1 1 1 4 1 3 2", "20\n2 7 3 8 4 6 3 7 6 4 13 5 1 12 1 10 2 11 5 9", "20\n1 1 1 2 3 1 5 9 5 8 4 6 7 3 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
19
codeforces
Okay, I need to solve this problem where I have to split a mixed array into several permutations. Each permutation must contain all numbers from 1 up to its size, exactly once. The task is to assign each element in the array to a permutation, and output the labels. If it's not possible, output -1. Let me start by unde...
To solve this problem, we need to determine if a given array can be split into several permutations such that each element of the array belongs to exactly one permutation. If possible, we should output the number of permutations and the corresponding labels for each element in the array. If not, we should output -1. #...
true
fd8886c6850c1ea1e514d52a6f360e82
Autocompletion
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e...
{"inputs": ["snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.", "'co-co-co, codeforces?!'", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the thunder\nlightning ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's see. The problem is about calculating the minimum number of keyboard clicks Arcady needs to type a given text. The key here is figuring out when he can use autocompletion to save clicks. So, every time he's typing a word, the editor might offer an autocompletion option based on the current prefix and previo...
To solve this problem, we need to determine the minimum number of keyboard clicks required for Arcady to type a given text using an autocompletion feature. The autocompletion feature suggests a word based on the current prefix if it is unique among previously typed words. The goal is to leverage this feature optimally ...
false
Code is incorrect.
fd92b19e89743bc74823f16a399a7d87
none
Hamed has recently found a string *t* and suddenly became quite fond of it. He spent several days trying to find all occurrences of *t* in other strings he had. Finally he became tired and started thinking about the following problem. Given a string *s* how many ways are there to extract *k*<=≥<=1 non-overlapping subst...
{"inputs": ["ababa\naba", "welcometoroundtwohundredandeightytwo\nd", "ddd\nd", "vnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssnssn\nnssnssns", "kpjmawawawawawawawawawawawawawawawawawawawawawawaw\nwawawawa", "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\nvvvvvvvv", "a\na", "a\naa", "a\nb", "ababababab\nabab"], "ou...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
Okay, I need to solve this programming problem. Let's read the problem carefully. The problem is about finding the number of ways to extract k non-overlapping substrings from string s such that each of them contains the string t as a substring. And then sum this for all possible k >=1. Wait, no, the problem says the n...
To solve this problem, we need to count the number of ways to extract non-overlapping substrings from a given string `s` such that each substring contains another string `t` as a substring. The result should be computed modulo \(10^9 + 7\). ### Approach 1. **Find Occurrences**: First, identify all starting positions o...
false
Code is incorrect.
fdd530dfaa50125be7d4251073dd47dd
Hiring Staff
A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least *k* people must work in the store. Berland has a law that determines the order of working days and non-worki...
{"inputs": ["4 3 2", "3 3 1", "5 5 3", "7 6 8", "8 3 2", "5 1 1", "6 5 1", "2 1 1", "2 2 1", "3 1 1", "3 2 1", "3 3 1", "4 1 1", "4 2 1", "4 3 1", "4 4 1", "183 1 1", "284 282 1", "359 358 1", "801 801 1", "1000 1 1", "1000 999 1", "1000 1000 1", "2 1 2", "2 2 2", "3 1 2", "3 2 2", "3 3 2", "4 1 2", "4 2 2", "4 3 2", "...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
6
codeforces
Okay, let's try to tackle this problem. So the task is to find the minimum number of employees Vitaly needs to hire such that every day from day 1 onwards has at least k workers, and on each day, at least one of the workers has the key. The key starts with the first employee on their first day. Also, each employee work...
To solve this problem, we need to determine the minimum number of employees Vitaly should hire such that the store operates normally every day from day 1 onwards with at least `k` employees working each day, and the key is always present with one of the employees. Each employee works for `n` consecutive days followed b...
true
fde4f9235dd44012d3470d60a923de13
Sereja and Intervals
Sereja is interested in intervals of numbers, so he has prepared a problem about intervals for you. An interval of numbers is a pair of integers [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*m*). Interval [*l*1,<=*r*1] belongs to interval [*l*2,<=*r*2] if the following condition is met: *l*2<=≤<=*l*1<=≤<=*r*1<=≤<=*r*2. Sereja w...
{"inputs": ["1 1 1", "3 5 1", "2 3 3", "11 79 54", "18 46 26", "8 96 61", "154 5 3", "34 22 8", "29 27 7", "12 68 35", "23 12 10", "6 42 23", "143 645 43", "14 724 55", "166 36 1", "273 41 17", "54 806 191", "6159 7 7", "115 624 37", "8 967 200", "112 440 258", "490 119 1", "745 116 85", "52 978 871", "37 746 303", "10...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this problem. Let's read it carefully. The problem is about counting the number of valid sequences of intervals under certain conditions. Let's break down the requirements. First, each sequence has n intervals. Each interval is [l_i, r_i], where 1 ≤ l_i ≤ r_i ≤ m. The conditions are: 1. No inte...
To solve this problem, we need to count the number of valid sequences of intervals that meet specific criteria. The intervals must be pairwise non-containing and at least one interval must contain a given value `x`. The solution involves dynamic programming with Fenwick trees to efficiently compute the number of valid ...
true
feaa637b31fdce3c496608b4398a079b
Tricky Function
Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of the problem before the contest. Because he wants to make sure Iahub will be t...
{"inputs": ["4\n1 0 0 -1", "2\n1 -1", "100\n-57 -64 83 76 80 27 60 76 -80 -56 52 72 -17 92 -96 87 41 -88 94 89 12 42 36 34 -100 -43 -42 62 3 87 -69 -6 -27 -59 -7 5 -90 -23 63 -87 -60 -92 -40 54 -16 -47 67 -64 10 33 -19 53 -7 -62 16 -74 -36 4 -75 -55 92 3 -22 43 -30 48 -27 88 -58 41 36 8 -40 -30 -18 16 22 -66 -91 -46 48...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
4
codeforces
Okay, let's tackle this problem. So, we need to find the minimum value of f(i,j) for all i not equal to j. And f(i,j) is defined as (i-j)^2 plus g(i,j)^2. The function g is calculated by that pseudo-code they provided. Let me parse that. The pseudo-code for g is: compute s = a[i] + a[i+1] + ... + a[j] (the sum from i ...
To solve this problem, we need to find the minimum value of the function \( f(i, j) \) for all pairs \( i \) and \( j \) where \( i \neq j \). The function \( f(i, j) \) is defined as \( (i-j)^2 + g(i, j)^2 \), where \( g(i, j) \) is calculated using the sum of elements from \( i \) to \( j \) (inclusive) multiplied by...
false
Code is incorrect.
feb6b1e03e665a72ca3cb3f0ccfc5ca2
Two Arithmetic Progressions
You are given two arithmetic progressions: *a*1*k*<=+<=*b*1 and *a*2*l*<=+<=*b*2. Find the number of integers *x* such that *L*<=≤<=*x*<=≤<=*R* and *x*<==<=*a*1*k*'<=+<=*b*1<==<=*a*2*l*'<=+<=*b*2, for some integers *k*',<=*l*'<=≥<=0. The only line contains six integers *a*1,<=*b*1,<=*a*2,<=*b*2,<=*L*,<=*R* (0<=&lt;<=*a...
{"inputs": ["2 0 3 3 5 21", "2 4 3 0 6 17", "2 0 4 2 -39 -37", "1 9 3 11 49 109", "3 81 5 72 -1761 501", "8 -89 20 67 8771 35222", "1 -221 894 86403 -687111 141371", "1 -1074 271 17741 -2062230 1866217", "3 2408 819 119198 -8585197 7878219", "1 341 8581 3946733 -59420141 33253737", "1 10497 19135 2995296 -301164547 -18...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
9
codeforces
Okay, let's tackle this problem. So, the task is to find the number of integers x in the range [L, R] that can be expressed in two ways: as part of the first arithmetic progression and the second one. Each progression is defined by a1 * k' + b1 and a2 * l' + b2, where k' and l' are non-negative integers. So x has to be...
To solve this problem, we need to find the number of integers \( x \) within a given range \([L, R]\) that can be expressed as elements of both given arithmetic progressions. Each progression is defined by parameters \( a \) and \( b \), where the elements are \( a \cdot k + b \) for non-negative integers \( k \). ###...
false
Code is incorrect.
febea4f23d6799418a46ea0af82f70af
Permutation
You are given a permutation of numbers from 1 to *n*. Determine whether there's a pair of integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=*n*; *a*<=≠<=*b*) such that the element (note, that it is usual division, not integer one) is between *a* and *b* in this permutation. First line consists of a single integer *n* (1<=≤<=*n*...
{"inputs": ["4\n1 3 4 2", "5\n1 5 2 4 3", "100\n17 41 19 23 46 16 10 31 82 12 77 32 11 71 83 25 98 18 34 59 13 73 80 65 37 22 6 2 24 5 94 42 51 63 52 92 97 26 93 38 36 87 64 70 14 43 68 85 33 44 74 89 56 1 69 88 20 49 48 21 84 90 7 47 39 55 81 86 76 57 3 62 15 78 100 60 61 66 91 30 58 35 99 96 54 27 79 9 29 50 45 72 75...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this problem where I have to determine if there exists a pair of integers a and b in a permutation such that the element (a + b)/2 is between them in the permutation. Wait, let me read the problem again carefully. The problem says: Given a permutation of numbers from 1 to n, check if there's a pa...
To solve this problem, we need to determine if there exists a pair of integers \(a\) and \(b\) in a given permutation such that the element \((a + b)/2\) is between \(a\) and \(b\) in the permutation. ### Approach The key insight here is to check for each element \(m\) in the permutation if there exists a pair of ele...
false
Code is incorrect.
fed340b160e4eb32c6a5954134630705
Hierarchy
Nick's company employed *n* people. Now Nick needs to build a tree hierarchy of «supervisor-surbodinate» relations in the company (this is to say that each employee, except one, has exactly one supervisor). There are *m* applications written in the following form: «employee *a**i* is ready to become a supervisor of emp...
{"inputs": ["4\n7 2 3 1\n4\n1 2 5\n2 4 1\n3 4 1\n1 3 5", "3\n1 2 3\n2\n3 1 2\n3 1 3", "1\n2\n0", "2\n5 3\n4\n1 2 0\n1 2 5\n1 2 0\n1 2 7", "3\n9 4 5\n5\n3 2 4\n1 2 4\n3 2 8\n1 3 5\n3 2 5", "3\n2 5 9\n5\n3 1 7\n2 1 1\n2 1 6\n2 1 2\n3 1 5", "3\n6 2 9\n5\n1 2 10\n3 1 4\n1 2 5\n1 2 2\n3 1 4", "4\n10 6 7 4\n5\n1 3 1\n3 4 1\n...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
85
codeforces
Okay, so I need to solve this programming problem. Let's read the problem carefully. The task is to build a tree hierarchy where each employee except one has exactly one supervisor. The applications from employees are such that a supervisor has a qualification greater than or equal to their subordinate. Each applicati...
To solve this problem, we need to build a tree hierarchy of supervisor-subordinate relations in a company with the minimum possible cost. The hierarchy must be such that each employee, except one, has exactly one supervisor. The solution involves determining the minimum cost using a combination of Edmonds' algorithm fo...
false
Code is incorrect.
fee1c0d82e0df1ec46bbb228704921c3
Relatively Prime Graph
Let's call an undirected graph $G = (V, E)$ relatively prime if and only if for each edge $(v, u) \in E$  $GCD(v, u) = 1$ (the greatest common divisor of $v$ and $u$ is $1$). If there is no edge between some pair of vertices $v$ and $u$ then the value of $GCD(v, u)$ doesn't matter. The vertices are numbered from $1$ to...
{"inputs": ["5 6", "6 12", "572 99643", "571 99403", "100 3043", "10 31", "1 1", "2 1", "100000 1", "100000 99999", "100000 100000", "1000 100000", "572 99644", "571 99404", "100 3044", "10 32", "100000 99998", "55910 88645", "72050 72069", "53599 55493", "56557 100000", "1001 100000", "50000 100000", "530 100000", "46...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
28
codeforces
Okay, I need to solve this problem where I have to construct a connected undirected graph that is relatively prime. The vertices are numbered from 1 to n, and each edge must connect two vertices whose GCD is 1. Also, the graph must have exactly m edges and be connected. If it's not possible, output "Impossible". First...
To solve this problem, we need to construct a connected undirected graph with `n` vertices and `m` edges such that every edge connects vertices with a greatest common divisor (GCD) of 1. If it's not possible to create such a graph, we should output "Impossible". ### Approach 1. **Check Feasibility**: - The minimum...
false
Code is incorrect.
fef0dc43ecff47f600561e8599217ddf
Bookshelves
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the ne...
{"inputs": ["10 4\n9 14 28 1 7 13 15 29 2 31", "7 3\n3 14 15 92 65 35 89", "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16", "20 15\n927353279298143 655102800384382 40376603048780 1008958973042960 1123049780860278 853122601026128 154596679092462 2000...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
12
codeforces
Okay, let's see. We need to find the maximum possible bitwise AND of the sums of k shelves, where the books are split into consecutive groups. Each shelf must have at least one book. Hmm. So the problem is about splitting the array into exactly k consecutive parts, each non-empty, compute the sum for each part, then t...
To solve this problem, we need to find the maximum possible bitwise AND of the sums of exactly `k` consecutive shelves of books. Each shelf must contain at least one book. The approach involves using a bitwise greedy algorithm combined with dynamic programming to efficiently determine the maximum achievable bitwise AND...
true
fefe761d353a35a1825f8de3622e0e44
Phone numbers
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three...
{"inputs": ["6\n549871", "7\n1198733", "2\n74", "2\n33", "3\n074", "3\n081", "4\n3811", "5\n21583", "8\n33408349", "9\n988808426", "10\n0180990956", "15\n433488906230138", "22\n7135498415686025907059", "49\n2429965524999668169991253653390090510755018570235", "72\n49192533778411177050014761988172752557003973550743936062...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
157
codeforces
Okay, I need to solve this problem where I have to split a phone number into groups of two or three digits, separated by hyphens. Let's think about how to approach this. So, the input is a string of n digits. The output should be any valid grouping where each group is either two or three digits. The groups must cover ...
To solve this problem, we need to split a given phone number into groups of two or three digits such that the groups are separated by hyphens. The goal is to find any valid grouping that covers all the digits exactly once. ### Approach The approach to solve this problem involves the following steps: 1. **Check if the ...
true
ff10d04958977d2d3ed41f2c817605a8
String Compression
Ivan wants to write a letter to his friend. The letter is a string *s* consisting of lowercase Latin letters. Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string *s* instea...
{"inputs": ["aaaaaaaaaa", "abcab", "cczabababab", "kbyjorwqjk", "baaabbbaba", "aaaaaaaaaa", "cbbbcccbbc", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "hltcdvuobkormkxkbmpfjniilublkrckmvvxemcyietgxcyjgrjwsdsgsfmoqnmbxozfavxopklhldhnsjpxhejxaxuctxeifglx", "agdmd...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
3
codeforces
Okay, I need to solve this problem where I have to find the minimal compressed version length of a given string. Let me think about how to approach this. The problem says that the compressed version is a sequence of (c_i, s_i) pairs. Each c_i is the number of times s_i is repeated. The goal is to split the original st...
To solve this problem, we need to find the minimum possible length of a compressed version of a given string. The compressed version consists of sequences where each part is repeated a certain number of times. The goal is to minimize the total length of these compressed sequences. ### Approach 1. **Dynamic Programming...
true
ff140e99d830432ae85962a533046d13
Feed the cat
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are...
{"inputs": ["19 00\n255 1 100 1", "17 41\n1000 6 15 11", "16 34\n61066 14 50 59", "18 18\n23331 86 87 41", "10 48\n68438 8 18 29", "08 05\n63677 9 83 25", "00 00\n100000 100 100 100", "20 55\n100000 100 100 100", "23 59\n100000 100 100 100", "00 00\n1 100 100 100", "21 26\n33193 54 97 66", "20 45\n33756 24 21 1", "14 3...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
144
codeforces
Okay, let's try to figure out how to solve this problem. Hmm. So Andrew needs to buy buns to feed his cat. The goal is to find the minimum cost possible. Let's see the details. First, the cat's hunger starts at H and increases by D each minute. Andrew can buy buns any time. The cost of each bun is C, but after 20:00 (...
To solve this problem, we need to determine the minimum amount of money Andrew has to spend to feed his cat, considering that the cat's hunger increases over time and there is a discount on buns starting from 20:00. The solution involves calculating the cost of buying buns immediately and comparing it with the cost of ...
true
ff421c3540ee1df661234b450f1c7093
Chip Play
Let's consider the following game. We have a rectangular field *n*<=×<=*m* in size. Some squares of the field contain chips. Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right. The player may choose a chip and make a move with it. The...
{"inputs": ["4 4\nDRLD\nU.UL\n.UUR\nRDDL", "2 2\nRD\nUL", "5 5\nUD..L\nRRD..\n..RDD\nUUL..\nDDLRR", "10 10\n.L.....R..\n.........U\n..D....D..\n.R......L.\n....L.....\n.........D\n......U...\nD....R....\n...U......\n........L.", "17 13\n...LD.UR.RUU.\nLDLULDUDRRDRL\nDD.RRLRUR.UD.\nRU...D...LD..\n.UR.R...URUUD\n.RURD.RL...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, let's see. The problem is about a game where chips on a grid are arranged with arrows pointing directions. When you select a chip, it starts a chain of removals. The goal is to find the maximum points possible in one move (which is the number of chips deleted) and how many such moves achieve this maximum. Hmm. S...
To solve this problem, we need to determine the maximum number of points a player can receive in one move and the number of such moves in a game where chips on a grid are removed based on their directional arrows. Each move starts with selecting a chip, which triggers a chain of removals according to the arrows on the ...
true
ff63427e0a246e9a8c857186864b88ce
k-String
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string. You are given a string...
{"inputs": ["2\naazz", "3\nabcabcabz", "1\na", "2\nabba", "2\naaab", "7\nabacaba", "5\naaaaa", "3\naabaaaaabb", "2\naaab", "2\nbabac", "3\nbbbccc", "2\naa", "250\ncecececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececec...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
324
codeforces
Okay, let's tackle this problem. So the task is to reorder the characters of a string such that the result is a k-string. A k-string is one that can be formed by concatenating k copies of some substring. Hmm. So for example, if k is 2, then the final string must be like "abab" where the substring is "ab" repeated twice...
To solve this problem, we need to determine if we can reorder a given string such that it becomes a k-string. A k-string is defined as a string that can be formed by concatenating k copies of a substring. If possible, we should output the reordered string; otherwise, we should return -1. ### Approach 1. **Check Length...
true
ff80a5b10d8a65e60f520fb16ca6252b
none
Fox Ciel is participating in a party in Prime Kingdom. There are *n* foxes there (include Fox Ciel). The i-th fox is *a**i* years old. They will have dinner around some round tables. You want to distribute foxes such that: 1. Each fox is sitting at some table. 1. Each table has at least 3 foxes sitting around it. 1...
{"inputs": ["4\n3 4 8 9", "5\n2 2 2 2 2", "12\n2 3 4 5 6 7 8 9 10 11 12 13", "24\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25", "4\n2 2 9973 9967", "30\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31", "20\n76 38 74 176 106 134 12 88 66 178 63 105 199 99 29 67 135 ...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
1
codeforces
Okay, I need to solve this problem where I have to distribute foxes into tables such that each table has at least 3 foxes, and every two adjacent foxes (including the first and last) around the table have a sum that's a prime number. Let's think through how to approach this. First, the problem constraints are pretty t...
To solve this problem, we need to distribute foxes around tables such that each table has at least 3 foxes and the sum of ages of any two adjacent foxes around each table is a prime number. The solution involves leveraging graph theory and bipartite matching to form valid cycles. ### Approach 1. **Prime Check**: Preco...
false
Code is incorrect.
ff9235cd44659116788a8be5c260fa52
Lucky Permutation
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a lexicographically *k*-th permutation of integers from 1 to *n*. Determine ...
{"inputs": ["7 4", "4 7", "7 1", "7 5040", "10 1023", "7 7477", "10 10000", "3 7", "27 1", "40 8544", "47 1", "47 8547744", "50 1000000000", "64 87", "98 854555", "100 1", "9985 5888454", "1 1", "1 2", "2 1000000000", "10 1000000000", "20 1000000000", "777777 1", "777777 2", "777474 10000", "1000000000 1", "777777777 5...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
5
codeforces
Okay, let's tackle this problem. Hmm, the task is to find the number of positions i in the k-th permutation of 1..n where both i and the element at that position (a_i) are lucky numbers. Lucky numbers are those consisting of only 4 and 7 digits. First, I need to understand the problem correctly. So, the steps are: gen...
To solve this problem, we need to determine how many lucky numbers exist in the k-th permutation of integers from 1 to n, where both the index and the element at that index are lucky numbers. Lucky numbers are those that consist only of the digits 4 and 7. ### Approach 1. **Generate Lucky Numbers**: Generate all lucky...
false
Code is incorrect.
ffffc0199ae7229539d28ba0d02e9047
Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes...
{"inputs": ["revive", "ee", "kitayuta", "evima", "a", "yutampo", "fft", "shuseki", "lsdijfjisl", "ewcdcwerp", "noon", "add", "iq", "hogloid", "yosupo", "stat", "level", "iwiwi", "racecar", "dog", "squirrel", "slime", "palindrome", "nqwcvcwqn", "lsdijfjisl", "jewiiwefj", "vnwmvvmonv", "zennyuu", "mrtoudai", "z", "babccb...
UNKNOWN
[ "PYTHON3" ]
CODEFORCES
108
codeforces
Okay, let's see. The problem is to insert exactly one lowercase letter into the given string s so that the resulting string becomes a palindrome. If possible, output the palindrome, else output NA. Hmm. First, I need to think about how to approach this. Since the string can be up to 10 characters long, trying all poss...
To solve this problem, we need to determine if we can insert exactly one lowercase English letter into a given string to make it a palindrome. A palindrome reads the same forwards and backwards. If possible, we should return the resulting palindrome; otherwise, we return "NA". ### Approach 1. **Generate All Possible I...
true