brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 102439G - Sequence exploration

We start with the string 1. Each next term is obtained by reading the previous term from left to right, grouping equal consecutive digits, and replacing every group by two digits: its length followed by the digit itself.

codeforcescompetitive-programming
CF 102439D - Light show

There are (n) lightbulbs, so a configuration of the club is a binary vector of length (n). A switch is another binary vector. Pressing a switch means XORing its vector with the current configuration, because every bulb whose corresponding bit is one gets toggled.

codeforcescompetitive-programming
CF 102439B - Varvara and matrix

We have an (n times m) matrix whose entries are integers from (0) to (k). A zero marks an unknown cell, and the special condition is that every row and every column contains at most one zero. We must replace every zero independently by either (A) or (B).

codeforcescompetitive-programming
CF 102452J - Junior Mathematician

For every positive integer x, look at its decimal digits. If those digits are d1, d2, ..., dk, define f(x) as the sum of di dj over every pair of different positions with i < j. We need to count the integers in [L, R] for which x and f(x) have the same remainder modulo m.

codeforcescompetitive-programming
CF 102452I - Incoming Asteroids

We maintain one nondecreasing counter for every observatory. A member joins at some point in time, chooses at most three distinct observatories, and asks for a total of at least y minutes from those observatories.

codeforcescompetitive-programming
CF 102452H - Hold the Line

We have an array of (N) trenches. A trench is initially empty, and each trench can receive a soldier at most once. When a soldier is placed at position (x), that position permanently gets a height (h). A query gives a position interval ([L,R]) and an enemy height (H).

codeforcescompetitive-programming
CF 102452G - Game Design

We have to construct a rooted tree whose root represents the base. Every leaf contains a monster, and that monster travels toward the root.

codeforcescompetitive-programming
CF 102452D - Defining Labels

The labels form an ordered sequence of strings. For a chosen base (k), exactly (k) decimal digits are allowed: (10-k, 11-k, ldots, 9). Labels are first ordered by length, and within the same length they are ordered lexicographically using those allowed digits.

codeforcescompetitive-programming
CF 102452A - Axis of Symmetry

We have a collection of axis-aligned rectangles whose interiors never overlap. Rectangles may touch along edges or at points, so the final figure can be one connected shape, several disconnected shapes, or a shape with holes.

codeforcescompetitive-programming
CF 102700N - Name this problem

Jolany has a year consisting of n days. On each day she can try the time machine once. If the machine succeeds, she immediately reaches her next birthday.

codeforcescompetitive-programming
CF 102700J - Java exam

Each student points to exactly one favorite partner. If we draw an edge from a student to their favorite partner, the anti-symmetry condition means that there cannot be a directed cycle involving two different students.

codeforcescompetitive-programming
CF 102700C - Cipher count

The key observation is that two different key strings do not necessarily represent two different Vigenère ciphers. If a key is itself a repetition of a shorter string, extending either key periodically produces exactly the same sequence of shifts.

codeforcescompetitive-programming
CF 102697024 - Missed Basketball Game

Two basketball teams played a game, and we are given enough statistics to reconstruct each team's final score. For each team, the input gives the total number of made baskets, the number of those baskets that were three-pointers, and the number of free throws.

codeforcescompetitive-programming
CF 102697005 - Fizz Buzz

We are given one integer N, with 1 <= N <= 1000. We must classify that number according to divisibility by 3 and 5. If N is divisible by both 3 and 5, the required output is FizzBuzz. If it is divisible only by 3, we print Fizz. If it is divisible only by 5, we print Buzz.

codeforcescompetitive-programming
CF 102503Q - Og and Ug

We have a rooted tree with node 1 as its root. Each node has an ordered list of children. The program maintains a deque of pairs (node, i), where i tells us which child of that node should be processed next. When a pair is removed from the right end, its node is printed.

codeforcescompetitive-programming
CF 102503N - Holy Smokes

The angels define a fixed holiness value for every cigarette. The useful way to look at the process is to forget the angels themselves and examine the binary representation of the cigarette index. Consider cigarette (x), and write (y=x-1).

codeforcescompetitive-programming
CF 102503A - Vincent Adultman

We have four people with heights v, a, r, and p. We must choose exactly three of them and stack those three people together. The resulting height is the sum of their three individual heights. The rollercoaster accepts the resulting person if that sum is at least h.

codeforcescompetitive-programming
CF 102471M - Value

We choose some indices from 1 through n. Every chosen index i contributes ai to the score. There is one kind of interaction between chosen indices: if both i and j are chosen and j = i^k for some integer k 1, then bj is subtracted once.

codeforcescompetitive-programming
CF 102471K - All Pair Maximum Flow

The graph is drawn inside a convex polygon whose vertices are numbered cyclically. Every polygon side is present, and additional diagonals may be added, but the diagonals never cross except at common endpoints. Each edge has a nonnegative capacity.

codeforcescompetitive-programming
CF 102471J - Permutation

We have a permutation of the numbers from 1 to n, and an integer c. An operation looks at exactly c+1 consecutive positions. If the smallest value in that interval is at one endpoint, that endpoint is kept fixed and the other c values may be rearranged arbitrarily.

codeforcescompetitive-programming
CF 102460C - Are They All Integers?

We have a sorted array of positive integers (A), with (3 le n le 50). We must decide whether every choice of three distinct positions (i,j,k) satisfies [ frac{A[i]-A[j]}{A[k]} in mathbb Z.

codeforcescompetitive-programming
CF 102460G - Optimal Selection

We have an array of (n) distinct values, but we are not given the values themselves. Instead, before the selection algorithm starts, we already know the result of some comparisons. For every given pair ((x,y)), we know that (a[x] < a[y]).

codeforcescompetitive-programming
CF 102448H - Hellcife is on fire

Think of each city as a vertex and each road as an undirected weighted edge. City (v) has an additional delay (Tv): once the fire reaches (v), the city does not become completely burnt immediately. It takes another (Tv) seconds. Initially, several cities are ignited at time (0).

codeforcescompetitive-programming
CF 102443F - Isosceles triangles

A regular polygon has all vertices equally spaced around a circle. We must count every triangle whose three vertices come from the polygon and whose side lengths contain at least one equal pair. The key difficulty is that the polygon can have as many as 10 9 vertices.

codeforcescompetitive-programming
CF 102443H - Planet Nine

The register starts at a and must end at b. There are only two kinds of events. An addition increases the register by a positive multiple of 9, while a deletion removes some leading decimal digits, and every removed digit must be 1.

codeforcescompetitive-programming
CF 102431C - Mr. Panda and Typewriter

We need to construct a fixed array (S) from left to right. At any point, we may type one new element, copy any substring that already exists on the paper into a clipboard, or append the entire clipboard to the paper. Typing costs (X), copying costs (Y), and every paste costs (Z).

codeforcescompetitive-programming
CF 102471G - Happiness

Pang is one of n teams in a ten-problem ICPC contest. The other n - 1 teams have fixed final results. Pang knows a subset of the ten problems, and solving a known problem takes a fixed amount of time and incurs a fixed number of rejected submissions before acceptance.

codeforcescompetitive-programming
CF 102471C - Dirichlet $k$-th root

We work with arrays indexed by positive integers, but multiplication of arrays is not ordinary elementwise multiplication. For two functions (f) and (g), their Dirichlet convolution at (n) is [ (fg)(n)=sum{dmid n}f(d)g(n/d).

codeforcescompetitive-programming
CF 102470J - Stammering Aliens

For each test case, we have a lowercase string s and an integer m. We need to find the longest contiguous substring that occurs at least m times in s. Occurrences are allowed to overlap.

codeforcescompetitive-programming
CF 102470I - Happy Telephones

Each telephone call occupies a continuous time interval. A call is described by its two endpoints, its starting time S and its ending time S + D, where D is its duration. The phone numbers themselves do not affect the answer.

codeforcescompetitive-programming
CF 102470F - Haunted Graveyard

The graveyard is a rectangular grid with W H cells. John starts at (0, 0) and wants to reach (W - 1, H - 1). A normal walk from one cell to an adjacent cell costs exactly one second. Some cells are blocked by gravestones, so they cannot be entered.

codeforcescompetitive-programming
CF 102470E - Genetics

The DNA is a circular sequence in which every nucleotide type appears exactly twice, while the two occurrences may have either the same face, such as a ... a, or opposite faces, such as a ... A.

codeforcescompetitive-programming
CF 102465C - Crosswords

We need to construct an N × M character grid. Every row must be one of the B horizontal words, each of length M, and every column must be one of the A vertical words, each of length N. A word may be reused any number of times.

codeforcescompetitive-programming
CF 102461C - Advertisement Profit

We start with exactly 10,000 subscribers. There are two kinds of videos. A regular video increases the subscriber count by its ai and gives no direct revenue.

codeforcescompetitive-programming
CF 102448I - Ivan and the swimming pool

We have an (N times M) grid. Each cell contains the maximum depth that can be excavated at that location before hitting rock. We must choose exactly (S) cells to form the pool. The chosen cells must be connected through shared sides, and the pool has one uniform depth.

codeforcescompetitive-programming
CF 102448F - Finally, christmas!

Each building is an axis aligned rectangle standing on the same horizontal baseline. A building is described by its left coordinate (Li), right coordinate (Ri), and height (Hi), so it occupies the interval from (Li) to (Ri) and rises to height (Hi).

codeforcescompetitive-programming
CF 102443K - RotationAlmostSort

We have an (ntimes n) grid of arbitrary numbers. We are not given the numbers themselves. Instead, we must print a fixed program that will work correctly for every possible initial grid. A program instruction compares two cells.

codeforcescompetitive-programming
CF 102443J - Factory

We are given an (m times n) rectangular map. A cell is either a workshop, written as , or empty, written as .. All workshop cells form one side-connected region, and there are no enclosed empty regions inside it.

codeforcescompetitive-programming
CF 102443C - Fermat's Last Theorem

The program considers every quadruple (a, b, c, n) of positive integers with n = 3. Its ordering has two levels. First, quadruples are grouped by the largest value among their four coordinates. Inside one such group, they are sorted lexicographically by (a, b, c, n).

codeforcescompetitive-programming
CF 102440H - Policeman from Rublevka

We have an integer array (a1,dots,an), where each element describes the difficulty of one solved crime. Lesha wants to remove one existing element (ap) and insert two new integer values (q) and (r). The resulting array has (n+1) elements.

codeforcescompetitive-programming
CF 102440I - Shuffle one more time

The shuffle algorithm itself is missing from the supplied statement. It appears as an image, and the exact operations used to update the 32-bit seed determine the entire solution, including how the seed is recovered from the given permutation.

codeforcescompetitive-programming
CF 102440G - Раскраски

The sheet is an (n times m) rectangular grid of cells. A final drawing is simply a subset of cells that have been colored. The coloring process starts at any cell, and every newly colored cell has to share a side with the previously colored cell.

codeforcescompetitive-programming
CF 102440C - A + B = C

We are given exactly three integers, and we may reorder them. The goal is to print an ordering x y z such that x + y = z. If no permutation has this property, we print -1 -1 -1. Any valid ordering is accepted. The input values satisfy -2^63 < ai < 2^63.

codeforcescompetitive-programming
CF 102437B - Breaking the Code

We start with a string s of length n. We may repeatedly delete one character, but only a character currently occupying one of the first two or one of the last two positions can be removed. After exactly n-k deletions, the remaining characters form the password.

codeforcescompetitive-programming
CF 102431I - Mr. Panda and Blocks

There are (n) colors. For every unordered pair of colors ((i,j)), including the self-pair ((i,i)), there is exactly one domino-shaped block whose two unit cubes have those colors. Thus the input does not describe an existing arrangement.

codeforcescompetitive-programming
CF 102431F - Ferry

There are three islands, A, B, and C, and the ferry is forced to move cyclically in the order A, B, C, A, and so on. Every visitor starts at A and has a fixed destination, either B or C. A visitor also has a seasickness limit t.

codeforcescompetitive-programming
CF 102503F - Ulam Spiral

The grid contains positive integers arranged in a square spiral around 1. The coordinates are centered at 1, with the first coordinate increasing upward and the second increasing to the right. Thus 2 is at (0,1), 3 at (1,1), 4 at (1,0), and so on.

codeforcescompetitive-programming
CF 1024792 - Превышение скорости

We have a road split into (n) consecutive sections. Section (i) has length (li) and a speed limit (vi). A car enters the road at time (s), leaves it at time (t), and we know nothing about its exact speed on individual sections.

codeforcescompetitive-programming
CF 102471I - Moon

We have fixed points a 1 ​ ,…,a n ​ on the unit sphere. A new point a 0 ​ is chosen uniformly from the sphere. We ask whether all n+1 points can fit inside one closed hemisphere.

codeforcescompetitive-programming
CF 102471H - King

We have a sequence (b1,b2,ldots,bn) of nonzero residues modulo a prime (p). A King sequence is a subsequence whose consecutive values are obtained by multiplying by one fixed nonzero residue (q).

codeforcescompetitive-programming
CF 102471D - Fire

Root the tree at vertex 1. Pang starts at the root and must eventually cast his magic exactly once at every vertex.

codeforcescompetitive-programming
CF 102471A - City

We have an n×m rectangular grid of unit squares. Its grid points have integer coordinates, so there are (n+1)(m+1) points in total.

codeforcescompetitive-programming
CF 102465E - Rounding

We have P places, and exactly 10,000 people each chose one place. If a place was chosen by c people, its true percentage is [ frac{c}{100}% ] because 10,000 people make every percentage step exactly 0.01. The agency did not report these exact percentages.

codeforcescompetitive-programming
CF 102465F - Paris by Night

We have (N) monuments. Monument (i) has coordinates ((xi,yi)) and a positive grade (gi). Morgane chooses two distinct monuments as the endpoints of a line.

codeforcescompetitive-programming
CF 102465A - City of Lights

We have N lights numbered from 1 through N. Initially every light is on. Each of the k commands contains a positive integer x, and that command toggles every light whose number is a multiple of x. A toggled light changes from on to off or from off to on.

codeforcescompetitive-programming
CF 102461A - Expression Formatting

The input is a valid arithmetic expression written without spaces. Its operands are single lowercase letters, and the expression may contain the binary operators +, -, , / together with parentheses.

codeforcescompetitive-programming
CF 102460K - Length of Bundle Rope

We have a collection of packages, and each package has a positive size. A bundling operation chooses exactly two current bundles, joins them into one new bundle, and consumes rope whose length equals the sum of the two bundle sizes.

codeforcescompetitive-programming
CF 102460L - Largest Quadrilateral

We have up to 4096 points in the plane, and we may choose four of them as the vertices of a quadrilateral. The four points do not have to be distinct as coordinates because the input itself may contain duplicates, and degenerate quadrilaterals are allowed.

codeforcescompetitive-programming
CF 102460F - Miss Sloane

For every senator we have an integer (ai), and the final agreement happens exactly when the gcd of all current (ai) values is greater than 1. Sloane may choose a senator once and divide that senator's value by any divisor (d) satisfying (dle k).

codeforcescompetitive-programming
CF 102458C - Daniel's game

We have an array A of n non-negative integers and a budget M. For every non-empty contiguous subarray A[l..r], Andy may increase its elements, but the total amount added cannot exceed M. His goal is to make the chosen subarray non-decreasing.

codeforcescompetitive-programming
CF 102458A - Daniel and Perpendophobia

The geometric story becomes much simpler if we look only at coordinates. Suppose Daniel has already recorded a point (u, v). A mine (x, y) must be avoided whenever x = u or y = v, because the segment joining the two points is then vertical or horizontal.

codeforcescompetitive-programming
CF 102448E - Everybody loves acai

Each restaurant gives Gabriel an integer (k), representing the maximum amount of açaí he can put into his bowl. He wants the largest positive integer not exceeding (k) whose proper divisors add up exactly to the number itself. If no such number exists, the answer is (-1).

codeforcescompetitive-programming
CF 102443G - Too Many Hyphens

We have a string made only of + and -. We may insert curly braces anywhere, without changing the original characters.

codeforcescompetitive-programming
CF 102443A - Attractive Flowers

For every flower type, the bouquet can contain some number of flowers of that type, and whenever a type is used, its chosen count must be odd. We want the largest possible total number of flowers.

codeforcescompetitive-programming
CF 102441C - Partial Sums

We start with an (n times m) binary matrix (A0). One operation replaces every cell by the parity of the rectangle from the upper-left corner to that cell.

codeforcescompetitive-programming
CF 102441A - Template for Search

We are given a pattern containing lowercase letters, ?, and . A lowercase letter must appear literally, ? can represent any one lowercase letter, and can represent any sequence of lowercase letters, including the empty sequence.

codeforcescompetitive-programming
CF 102440F - Football championship

We have friends numbered from (1) to (n), and friend (i) contributes exactly (i) strength to whichever of three teams receives them. Every friend must belong to exactly one team, and the three team sums must be equal.

codeforcescompetitive-programming
CF 102440A - Домашняя акула

We have a sequence of food units, where each position stores a food type. The shark can eat exactly k units in one feeding, and all those units must have the same type. A chosen interval is successful if all food inside it can be partitioned into groups of exactly k equal types.

codeforcescompetitive-programming
CF 102437I - Road building

We have an initially empty (n times m) grid. A move consists of choosing an axis-aligned rectangle whose cells are all still empty and whose area is at most (s), then marking every cell of that rectangle as built.

codeforcescompetitive-programming
CF 102437A - Блэк \& Уайт

There are (n) cities arranged around a circle and one capital in the middle. The only possible roads are the (n) circular roads between consecutive outer cities and the (n) spokes from the capital to the outer cities. Some roads may be absent.

codeforcescompetitive-programming
CF 102436B - Trie Minimization

We are given a collection of lowercase strings. We may replace individual letters, with every replacement costing one operation. After all replacements, we build an ordinary trie from the resulting strings. The goal is not to minimize the number of replacements directly.

codeforcescompetitive-programming
CF 102436C - Painting Plan

We have (n) segments on a number line. The original endpoints have been lost as pairs. We only know all (2n) endpoint coordinates, sorted into an array (x1 < x2 < dots < x{2n}), and we know that the union of the original segments has total length exactly (k).

codeforcescompetitive-programming
CF 102431J - Wire-compatible Protocol buffer

A protobuf message is a sequence of encoded fields. The field name never appears on the wire. What identifies a field is its numeric tag, and the wire type tells the decoder how many bytes belong to that field.

codeforcescompetitive-programming
CF 102431L - Spiral Matrix

We have an (n times m) rectangular grid of booths. Lee may choose any booth as the starting point and any of the four initial directions. After that, every move is either straight ahead or a single right turn followed by one step.

codeforcescompetitive-programming
CF 102431G - Game on the Tree

We have a tree rooted at vertex 1, with a token initially at vertex 1. Panda moves first. On every turn after the first, the player must move the token farther than the opponent moved on the preceding turn. A player who has no legal move loses.

codeforcescompetitive-programming
CF 102431B - Infimum of Paths

Each directed edge carries one decimal digit from 0 through 9. A path is interpreted as a decimal fraction from left to right, but each new digit is divided by another factor of 10. For example, a path with edge weights 3, 1, 3 has value [ frac{3+frac{1+frac{3}{10}}{10}}{10}=0.

codeforcescompetitive-programming
CF 102431K - Russian Dolls on the Christmas Tree

We have a rooted tree with (n) vertices. Vertex (i) contains doll (i), and vertex (1) is the root. For every vertex (v), we look at the entire subtree rooted at (v), collect all dolls there, and try to nest as many of them as possible.

codeforcescompetitive-programming
CF 102431H - Mr. Panda and SAD

We have several string pieces, and we may concatenate them in any order. The score of the resulting string is the number of times the consecutive three characters SAD appear.

codeforcescompetitive-programming
CF 102431E - Non-Maximum Suppression

Each detection is a square of the same side length S. Its position is determined by the bottom-left corner (x, y), and it has a distinct confidence score. NMS processes these detections from highest score to lowest score.

codeforcescompetitive-programming
CF 102431D - Pulse Nova

We need to choose the center of a circle of fixed radius (R). For every input line, we measure how much of that infinite line lies inside the circle, and add these lengths over all lines. The task is to find the maximum possible sum.

codeforcescompetitive-programming
CF 102431A - Kick Start

For each test case, we have the 2019 schedule of Kick Start rounds and a date representing today. The scheduled dates can appear in any order. We need to find the scheduled date that comes strictly after today and is as early as possible.

codeforcescompetitive-programming
CF 102436E - Stamp

We are given an h × w stamp. A cell containing X paints the paper cell directly underneath it, while a . is transparent. The stamp can be translated, but it cannot be rotated.

codeforcescompetitive-programming
CF 102436D - Subset ``AND''

We need to construct a set of integers, each using at most s bits, such that if we take the bitwise AND of every non-empty subset of the set, exactly k different values appear.

codeforcescompetitive-programming
CF 102436A - Cool Water

We have a water cooler with two buttons. Pressing the red button gives exactly a milliliters of water at 100°C, while pressing the blue button gives exactly b milliliters at 0°C.

codeforcescompetitive-programming
CF 102437C - Единая сеть

We have a connected undirected graph whose edges form a cactus: every road belongs to at most one simple cycle. Each city must receive one of three transmitter types, and adjacent cities must receive different types.

codeforcescompetitive-programming
CF 102440L - Разделение кроликов

We have rabbits numbered from (1) to (n), and every rabbit must receive one of two labels, (0) or (1). The labels cannot be chosen arbitrarily. Whenever (b) divides (a), the labels must satisfy [ f(a)=f(b) text{OR} f(a/b).

codeforcescompetitive-programming
CF 102440K - Абсолютная абсолютность массива

We have a binary array. Its absolute value is the absolute difference between the number of ones and the number of zeros. After changing one contiguous segment, including the possibility of changing nothing, we want the largest absolute value that can be obtained.

codeforcescompetitive-programming
CF 102440J - Delivery in the city of the future

Think of every grid cell as a vertex of a graph. A direct teleportation is an edge between two vertices when they lie in the same row or column, contain the same letter, and there is at least one more occurrence of that same letter strictly between them.

codeforcescompetitive-programming
CF 102440E - The Hitchhiker's Guide to the Galaxy

There is a direct contradiction between the supplied problem statement and its sample output, so a correct editorial cannot be written from the statement exactly as given.

codeforcescompetitive-programming
CF 102440D - Петя и массив

We have an array (a) and a nonnegative threshold (k). A subarray is called beautiful if, after deleting at most one element from it, its maximum minus its minimum can be made at most (k).

codeforcescompetitive-programming
CF 102440B - Перестановку на прокачку

We start with a permutation p of the numbers from 1 to n. We may delete any elements, but the remaining elements must stay in their original order, so every possible result is a subsequence of the permutation.

codeforcescompetitive-programming
CF 102441I - Cutting

We start with a positive integer written in decimal notation. A cut chooses a position between two digits, so the number is split into two non-empty decimal parts. After interpreting both parts as integers, we replace the original number with their absolute difference.

codeforcescompetitive-programming
CF 102441H - Not A + B

For each test case, we receive two positive integers a and b. We have to print some integer c between 1 and 50 such that c is different from a + b. There is no requirement to find the smallest or largest valid value, so any value satisfying the condition is accepted.

codeforcescompetitive-programming
CF 102441K - Chess Positions

We need to print an arbitrary 8 by 8 chessboard containing queens, bishops, knights, rooks, or empty cells. White pieces are uppercase and black pieces are lowercase.

codeforcescompetitive-programming
CF 102441J - Paternity Testing

We have a rooted tree with vertex 1 as the root. Vertices are numbered from 1 to (n). For a query interval ([l,r]), every vertex (v) with (lle vle r) contributes the number of vertices from the same interval that lie in the subtree of (v).

codeforcescompetitive-programming
CF 102441G - Sum of Distances in Cactus

We have a connected cactus graph with up to (10^5) vertices. A cactus is sparse and has a particularly useful structure: every biconnected component is either a single bridge or one simple cycle.

codeforcescompetitive-programming
CF 102441F - Random XOR

We have an array a of n integers. Each element is independently selected with probability P = X / Y. The selected elements are XORed together, producing a random integer s. If nothing is selected, the XOR is zero.

codeforcescompetitive-programming
CF 102441E - Very Simple Sum

For every ordered quadruple of indices ((x,y,z,w)), we form two values. The first is the ordinary sum [ S=ax+ay+az+aw, ] and the second is the bitwise XOR [ X=bxoplus byoplus bzoplus bw.

codeforcescompetitive-programming
CF 102441D - Lis on Circle

There are (n) players sitting around a circle, numbered from (1) to (n). Player (1) gets the first turn, then player (2), and so on, wrapping from (n) back to (1). Each player owns several cards, and every card has an integer value.

codeforcescompetitive-programming
CF 102441B - Redistribution of Digits

We have a multiset of nonzero decimal digits. Every occurrence matters, so if the input contains three copies of 7, all three copies must be used exactly once. We also have n upper bounds.

codeforcescompetitive-programming