brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1402C - Star Trek

We are given a tree of $N$ planets. Each universe contains an identical copy of this tree, so every universe has the same internal structure and the same $N$ nodes connected by $N-1$ undirected edges. There are $D+1$ universes indexed from $0$ to $D$.

codeforcescompetitive-programming*specialcombinatoricsdfs-and-similardpgamesgraphsmatricestrees
CF 1403B - Spring cleaning

We are given a tree with N nodes, connected by N-1 edges. Each node may be a leaf, defined as a node with exactly one edge. Cleaning the tree involves selecting two different leaves and marking all edges along the shortest path between them as cleaned.

codeforcescompetitive-programming*specialdata-structuresdfs-and-similargraphstrees
CF 1403C - Chess Rush

Let’s trace what the wrong behavior implies. Input: Grid: There are only 4 cells total. But the output is 9, which is suspiciously close to “counting something per cell plus neighbors” or “counting all 2x2 substructures / adjacency contributions”.

codeforcescompetitive-programming*specialcombinatoricsdpimplementationmath
CF 1403A - The Potion of Great Power

We have a dynamic friendship network among N shamans, each living at a specific altitude H[i]. Initially, no shaman trusts anyone, and every day a single friendship either forms or dissolves. Each shaman can trust at most D others at any time.

codeforcescompetitive-programming*special2-satbinary-searchdata-structuresgraphsinteractivesortingstwo-pointers
CF 1404E - Bricks

I see exactly what’s going wrong. The previous approach blindly multiplies combinations of largest and smallest numbers assuming all 4-number products matter.

codeforcescompetitive-programmingflowsgraph-matchingsgraphs
Kvant Math Problem 1555

Consider two disjoint circles $\Gamma_1$ and $\Gamma_2$ with centers $O_1$ and $O_2$ and radii $r_1$ and $r_2$.

kvantmathematicsolympiad
CF 1404C - Fixed Point Removal

Codeforces 1404C is a difficult 2300-rated offline-query problem. Producing a correct editorial and solution requires reconstructing the full proof and implementation details of the accepted approach.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdata-structuresgreedytwo-pointers
CF 1404A - Balanced Bitstring

We are given a string of length $n$ consisting of characters 0, 1, and ?, and an integer $k$ that is even. Our goal is to replace the ? characters with 0 or 1 so that every substring of length $k$ contains exactly $k/2$ zeroes and $k/2$ ones.

codeforcescompetitive-programmingimplementationstrings
CF 1405B - Array Cancellation

Let’s analyze the first test: The correct result is: So we are clearly choosing 4 elements, not 3. Now check the last test: 945 factors as: Those correspond to: So again: we are selecting 4 numbers, not 3 Your previous logic is effectively solving: “maximum product of 3…

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1405A - Permutation Forgery

We are asked to manipulate permutations of integers from 1 to n. Each permutation has a “fingerprint,” which is the sorted list of sums of every pair of consecutive elements.

codeforcescompetitive-programmingconstructive-algorithms
CF 1406C - Link Cut Centroids

The issue is not actually with the algorithm. The output shown as: means the program produced no output at all. That indicates an implementation problem, not a mathematical one.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similargraphstrees
CF 1406B - Maximum Product

I’ve traced the issue carefully. The root cause of your wrong output is not just input reading. The underlying problem is that your algorithm is misinterpreting the input sequence.

codeforcescompetitive-programmingbrute-forcedpgreedyimplementationsortings
CF 1406E - Deleting Numbers

We are asked to identify a hidden integer x between 1 and n. Initially, we have the full set of integers from 1 to n.

codeforcescompetitive-programminginteractivemathnumber-theory
CF 1406D - Three Sequences

We are given a sequence of integers a of length n. The task is to split it into two sequences b and c of the same length such that each element in a is the sum of the corresponding elements in b and c.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedymath
CF 1406A - Subset Mex

We are given a multiset of integers and we are allowed to redistribute its elements into two groups, call them A and B, without changing how many copies of each value exist overall. Every element must go to exactly one of the two groups, but duplicates can be split arbitrarily.

codeforcescompetitive-programminggreedyimplementationmath
CF 1407C - Chocolate Bunny

Now it’s clear why your solution fails. The traceback: This comes from trying to access a[j] for j in range(6) (the original guitar solution assumes 6 strings) while your input is not the 1413C guitar problem.

codeforcescompetitive-programmingconstructive-algorithmsinteractivemathtwo-pointers
CF 1407E - Egor in the Republic of Dagestan

We are asked to control Egor's travel through a directed graph of cities connected by roads of two types: night roads and morning roads. Each city can be assigned a color, black (night) or white (morning). Egor can leave a city only along roads that match its color.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpgraphsgreedyshortest-paths
CF 1407D - Discrete Centrifugal Jumps

We are given a sequence of skyscrapers in a line, each with a fixed height. A person starts on the first skyscraper and wants to reach the last one using as few jumps as possible. The twist is that not every forward jump is allowed.

codeforcescompetitive-programmingdata-structuresdpgraphs
CF 1407B - Big Vova

We are given a sequence of positive integers, and we need to reorder them into a sequence $b$ such that the sequence of prefix greatest common divisors $ci = gcd(b1, b2, dots, bi)$ is lexicographically maximal.

codeforcescompetitive-programmingbrute-forcegreedymathnumber-theory
CF 1407A - Ahahahahahahahaha

We are given several independent test cases. Each test case contains a binary array of even length. We are allowed to delete elements anywhere in the array, but we can delete at most half of them.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1408I - Bitwise Magic

We are given an array of distinct non-negative integers, each at least as large as a given integer $k$, and we perform $k$ random decrements on the array. Each second, one of the $n$ elements is chosen uniformly at random and decreased by 1.

codeforcescompetitive-programmingdpmath
CF 1408A - Circle Coloring

Your traceback repeatedly shows: This tells us two important facts: 1. You are still running a wrapper-based tester (run) that expects a solve() function 2. The code being tested is not consistently redefining solve() in the same execution scope 3.

codeforcescompetitive-programmingconstructive-algorithms
CF 1408G - Clusterization Counting

We are given a complete graph on n computers. Every edge has a unique weight a[i][j], representing the difficulty of communication between those two computers. We want to partition the vertices into groups.

codeforcescompetitive-programmingcombinatoricsdpdsufftgraphstrees
CF 1408H - Rainbow Triples

We are given an array of integers where the value zero plays a special role. We want to extract as many disjoint triples of indices as possible, and each triple must have a very rigid structure: it must look like a zero, then a non-zero value, then another zero.

codeforcescompetitive-programmingbinary-searchdata-structuresflowsgreedy
CF 1408F - Two Different

We are asked to construct a sequence of operations on an array of size $n$ that starts as $[1, 2, dots, n]$. Each operation chooses two positions $x$ and $y$ and replaces both $ax$ and $ay$ with a value returned by an arbitrary function $f(ax, ay)$.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquer
CF 1408E - Avoid Rainbow Cycles

We are given a collection of sets of integers, where each set represents a group of vertices in a graph. Each set has an associated cost ai for deleting any element from it, and each element has a deletion cost bj. The deletion cost for removing element j from set i is ai + bj.

codeforcescompetitive-programmingdata-structuresdsugraphsgreedysortingstrees
CF 1408D - Searchlights

We are given a set of robbers positioned on a 2D grid and a set of searchlights, each with a fixed location. Robbers move in a constrained way: in a single move, all robbers either increase their x-coordinate by one or increase their y-coordinate by one.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpimplementationsortingstwo-pointers
CF 1408C - Discrete Acceleration

Two cars start at opposite ends of a road of length l. The left car starts at position 0 and moves to the right. The right car starts at position l and moves to the left. Both cars begin with speed 1. Along the road there are flags placed at fixed coordinates.

codeforcescompetitive-programmingbinary-searchdpimplementationmathtwo-pointers
CF 1408B - Arrays Sum

We are given a non-decreasing array a where each entry is a non-negative integer. We want to split this array into a sum of m arrays b₁, b₂, ..., bₘ such that each bᵢ is also non-decreasing and has a strong structural restriction: it uses at most k distinct values.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1409C - Yet Another Array Restoration

The root cause of the failure here is the test harness is trying to call a solve() function that isn’t defined in the same context.

codeforcescompetitive-programmingbrute-forcemathnumber-theory
CF 1409F - Subsequences of Length Two

We are given a base string and a target string of length two. We are allowed to change at most k characters in the base string, replacing any position with any lowercase letter.

codeforcescompetitive-programmingdpstrings
CF 1409E - Two Platforms

We are given a set of points on a 2D plane, each with coordinates $(xi, yi)$, and two horizontal platforms of fixed length $k$. The platforms can be positioned anywhere along the $x$-axis at any $y$-coordinate, but they must remain horizontal.

codeforcescompetitive-programmingbinary-searchdpsortingstwo-pointers
CF 1409D - Decrease the Sum of Digits

We are given a large integer and a threshold on the sum of its digits. In a single operation we are allowed to increment the number by one, and we want to know how many increments are needed until the digit sum of the resulting number becomes small enough, specifically at most…

codeforcescompetitive-programminggreedymath
CF 1409B - Minimum Product

We start with two numbers, a and b. We are allowed to perform at most n decrement operations. Each operation decreases either a or b by exactly one. The catch is that a can never go below x, and b can never go below y.

codeforcescompetitive-programmingbrute-forcegreedymath
CF 1409A - Yet Another Two Integers Problem

We are given two integers, and we want to transform the first into the second using a sequence of moves. Each move allows us to pick any integer step size from 1 to 10 and either add it to or subtract it from the current value.

codeforcescompetitive-programminggreedymath
CF 1411F - The Thorny Path

We are asked to work with permutations and cycles. Imagine you have a line of colored stones labeled from 1 to $n$. The monks can perform a "cycle shift" operation determined by a permutation $p$.

codeforcescompetitive-programminggreedymath
CF 1411G - No Game No Life

We are asked to calculate the probability that Alice wins a two-player chip-moving game on a directed acyclic graph. Each vertex can hold any number of chips, and players take turns moving a single chip along an outgoing edge.

codeforcescompetitive-programmingbitmasksgamesmathmatrices
CF 1411E - Poman Numbers

We are given a string of lowercase letters, which we interpret as a number in a strange “poman” numeral system. Each single letter corresponds to a power of two, where a is 2^0 = 1, b is 2^1 = 2, c is 2^2 = 4, and so on up to z = 2^25.

codeforcescompetitive-programmingbitmasksgreedymathstrings
CF 1411B - Fair Numbers

We are asked to find the smallest integer greater than or equal to a given number that is divisible by all of its nonzero digits. In other words, a number is fair if, for every digit d in the number that is not zero, the number modulo d equals zero.

codeforcescompetitive-programmingbrute-forcenumber-theory
CF 1411A - In-game Chat

We are given several chat messages. Each message is a string containing lowercase English letters and the character ).

codeforcescompetitive-programmingimplementation
CF 1413C - Perform Easily

The problem asks us to map a sequence of notes to a guitar with six strings so that the largest fret used minus the smallest fret used is minimized. Each string has a base value, and fretting at index j adds j to the string's base.

codeforcescompetitive-programmingbinary-searchbrute-forcedpimplementationsortingstwo-pointers
Kvant Math Problem 1536

The problem asks first for the explicit construction of two congruent simple heptagons on the same set of seven points with no shared edges and second for a rigorous proof that no three such heptagons…

kvantmathematicsolympiad
CF 1413F - Roads and Ramen

We are given a tree with $n$ villages connected by $n-1$ roads, where each road is either stone or sand. Each day, exactly one road changes its type: stone becomes sand or sand becomes stone.

codeforcescompetitive-programmingdata-structurestrees
CF 1413E - Solo mid Oracle

We repeatedly cast a spell on an enemy. Each cast immediately deals a damage. After that, the same cast heals the enemy by b health every second for exactly c seconds. Casts happen every d seconds because of the cooldown, and all effects stack.

codeforcescompetitive-programminggreedymathternary-search
CF 1413D - Shurikens

We are given a chronological log of operations performed on a showcase that starts empty. There are two types of events.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
CF 1413B - A New Technique

We are given all rows of an unknown matrix and all columns of the same matrix. The catch is that both collections are shuffled. The rows are presented in arbitrary order, and the columns are also presented in arbitrary order. Inside a row, the left-to-right order is preserved.

codeforcescompetitive-programmingimplementation
CF 1413A - Finding Sasuke

Each test case gives a collection of even length integers attached to a “door”. These integers act as coefficients. We must assign another nonzero integer to each position so that the weighted sum of pairs cancels out exactly to zero.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1415F - Cakes for Clones

Ah, now the situation is clear. The actual problem here is not a logic error in the algorithm-the traceback tells us Python never even found a function named solve. The testing harness tried to call solve(), but the code provided had no such function defined.

codeforcescompetitive-programmingdp
CF 1415E - New Game Plus!

Each boss has a value c[i]. When we defeat a boss, we gain the current bonus as score, then that boss changes the bonus by c[i]. If there were no resets, the order of bosses would completely determine how many times each c[i] contributes to future scores.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1415D - XOR-gun

We are given a sorted array, and we are allowed to repeatedly compress any adjacent pair into a single value equal to their bitwise XOR. Each compression reduces the length of the array by one, and we are never allowed to reduce below length one.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithms
CF 1415B - Repainting Street

We have a row of houses, each painted with some color. In one day, Tom chooses a contiguous segment of exactly k houses. Inside that segment he may repaint any subset of those houses, and each house can be repainted to any color independently.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1415C - Bouncing Ball

We have a binary string representing cells in a level. A 1 means a platform already exists, and a 0 means the cell is empty. The ball must start bouncing from position p, then visit positions p + k, p + 2k, and so on. Every one of those positions must contain a platform.

codeforcescompetitive-programmingbrute-forcedpimplementation
CF 1415A - Prison Break

We are given a rectangular prison with $n$ rows and $m$ columns. Each cell contains exactly one prisoner, and there is a single exit tunnel in a cell located at row $r$ and column $c$.

codeforcescompetitive-programmingbrute-forcemath
CF 1416D - Graph and Queries

We are dealing with a dynamic connectivity problem on an undirected graph with n vertices and m edges. Each vertex initially holds a distinct integer between 1 and n.

codeforcescompetitive-programmingdata-structuresdsugraphsimplementationtrees
CF 1416F - Showing Off

Think of each cell as a vertex of a directed graph. Every vertex chooses exactly one adjacent vertex as its outgoing edge. A graph where every vertex has outdegree exactly one is a functional graph.

codeforcescompetitive-programmingflowsgraph-matchingsgreedyimplementation
CF 1416E - Split

We are given an array of positive integers, and for each element in the array we are allowed to split it into two positive integers whose sum equals the original number. After splitting all elements, we construct a new array by placing these pairs consecutively.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedy
CF 1416A - k-Amazing Numbers

We are given an array whose values are between 1 and n. For every length k, we look at all subarrays of length k. A value x is considered valid if every such subarray contains at least one occurrence of x. Among all valid values, we must output the smallest one.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationtwo-pointers
CF 1416B - Make Them Equal

We are given an array of positive integers and allowed to redistribute values between pairs of elements using a linear operation that depends on the index of the first element.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1416C - XOR Inverse

We are given an array of non-negative integers, and we need to pick a number $x$ so that when we XOR every element in the array with $x$, the resulting array has as few inversions as possible.

codeforcescompetitive-programmingbitmasksdata-structuresdivide-and-conquerdpgreedymathsortingsstringstrees
CF 1417B - Two Arrays

I’ve carefully analyzed the issue. The primary bug here is in how the input is being read and processed. The previous solution misinterpreted the format, leading to no output. Let’s reason through the input step by step.

codeforcescompetitive-programminggreedymathsortings
CF 1417A - Copy-paste

The problem gives us a list of candy piles and a limit on how many candies a pile can contain before BThero loses his magic. We are allowed to repeatedly perform a copy-paste operation: choose two different piles and add all candies from the first pile into the second.

codeforcescompetitive-programminggreedymath
CF 1418D - Trash Problem

Thank you. I have carefully traced the bug. The issue is fundamental but fixable without changing the algorithmic intent. Let’s go step by step.

codeforcescompetitive-programmingdata-structuresimplementation
Kvant Math Problem 1532

We are asked to determine whether sets of distinct numbers exist such that the sum of any three elements is a prime number.

kvantmathematicsolympiad
CF 1418F - Equal Product

Fix a value of $x1$. We need to find two different representations of the same product: $$x1 y1 = x2 y2,$$ with $x2 x1$, $y2 < y1$, and the product lying inside $[l,r]$. The output is required separately for every $x1$ from $1$ to $n$.

codeforcescompetitive-programmingdata-structuresmathnumber-theorytwo-pointers
CF 1418G - Three Occurrences

We are given an array of length $n$, and we want to count how many contiguous segments have the following property: every distinct value appearing inside that segment appears exactly three times. The condition is surprisingly restrictive.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerhashingtwo-pointers
CF 1418E - Expected Damage

We have a fixed multiset of monster strengths. For each query, a shield starts with durability a and defence value b. Monsters are fought in a uniformly random order. A monster whose strength is at least b consumes one durability point but deals no damage.

codeforcescompetitive-programmingbinary-searchcombinatoricsprobabilities
CF 1418B - Negative Prefixes

We have an array and a second binary array describing which positions are locked and which are unlocked. A locked position must keep its original value. An unlocked position may receive any value that originally belonged to an unlocked position.

codeforcescompetitive-programminggreedysortings
CF 1418C - Mortal Kombat Tower

We are tasked with simulating a two-player cooperative challenge where bosses appear in a fixed order, and each boss is either easy or hard. The first player, your friend, cannot defeat hard bosses without consuming a skip point.

codeforcescompetitive-programmingdpgraphsgreedyshortest-paths
CF 1418A - Buying Torches

We are asked to determine the minimum number of trades required to craft a given number of torches in a game. Each torch requires one stick and one coal. We start with a single stick.

codeforcescompetitive-programmingmath
CF 1419C - Killjoy

Got it. Let’s carefully reason through this failure. The input: The expected output: The actual output from the previous solution: Clearly, the previous solution underestimates the counts.

codeforcescompetitive-programminggreedyimplementationmath
CF 1419F - Rain of Fire

Fix a value t. Brimstone may wait at any detachment for an arbitrary amount of time. When he decides to move, he chooses one of the four axis directions and keeps moving until he reaches the first detachment lying on that ray.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardsugraphsimplementation
CF 1419E - Decryption

The problem revolves around arranging the divisors of a given composite number in a circle such that no two adjacent numbers are coprime.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmathnumber-theory
CF 1419D2 - Sage's Birthday (hard version)

We have a row of ice spheres, each with a positive integer price, and Sage will pick out spheres that are cheaper than both of their immediate neighbors. The spheres at the ends are never cheap because they lack two neighbors.

codeforcescompetitive-programmingbinary-searchbrute-forceconstructive-algorithmsgreedysortingstwo-pointers
CF 1419D1 - Sage's Birthday (easy version)

We are given distinct prices of ice spheres and may rearrange them in any order. A sphere is considered cheap only if it has both a left neighbor and a right neighbor, and its price is strictly smaller than both of them. The first and last positions can never contribute.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedysortings
CF 1419B - Stairs

A staircase with $n$ columns contains columns of heights $1,2,dots,n$. The total number of cells in such a staircase is $$1+2+cdots+n=frac{n(n+1)}2.$$ The problem only cares about nice staircases.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationmath
CF 1419A - Digit Game

We are asked to simulate a simple turn-based digit game between two agents, Raze and Breach. Each game starts with a positive integer consisting of $n$ digits. The digits are numbered from left to right, starting with 1.

codeforcescompetitive-programminggamesgreedyimplementation
CF 1420C1 - Pokémon Army (easy version)

I see exactly what is happening here. The issue is not a crash, but a mismatch between the expected output in the sample and the “canonical” construction used in many solutions. Let me walk through it carefully.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedy
CF 1420E - Battle Lemmings

We have a line of lemmings, some holding shields and some not. A pair of unshielded lemmings is considered protected if there exists at least one shielded lemming positioned anywhere strictly between them.

codeforcescompetitive-programmingdpgreedy
CF 1420D - Rescue Nibel!

We have a collection of lamps, each of which turns on and off during a fixed interval of time. The task is to pick exactly $k$ lamps such that there exists a moment when all of them are simultaneously on.

codeforcescompetitive-programmingcombinatoricsdata-structuressortings
CF 1420C2 - Pokémon Army (hard version)

We are given an array of distinct integers representing the strength of pokémon lined up in a sequence. Andrew can form an army by choosing any subsequence of this array, and the army's strength is defined as the alternating sum: the first element minus the second plus the…

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgreedyimplementation
CF 1420B - Rock and Lever

We are given several independent arrays of integers. For each array, we must count how many pairs of positions form a “good interaction” under a bitwise condition.

codeforcescompetitive-programmingbitmasksmath
CF 1420A - Cubes Sorting

The problem presents us with a sequence of cubes, each with a positive integer volume. The cubes are initially arranged in some arbitrary order.

codeforcescompetitive-programmingmathsortings
CF 1421A - XORwice

The problem asks for the minimum sum of two XOR operations for a pair of integers a and b when XORed with the same number x. Concretely, given a and b, we must choose x such that the expression (a XOR x) + (b XOR x) is as small as possible.

codeforcescompetitive-programmingbitmasksgreedymath
CF 1421C - Palindromifier

The failure you show is not actually an algorithmic failure. The traceback: means the test harness tried to execute: but the submitted file did not contain a function named solve. This happens before any input is processed, so there is no way to trace the algorithm on abac.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1421E - Swedish Heroes

We are given a lineup of heroes, each with a numeric power. The only allowed operation is to select two consecutive heroes, remove them, and insert a single new hero whose power is the negative of their sum.

codeforcescompetitive-programmingbrute-forcedpimplementation
CF 1421D - Hexagons

We are working on a hexagonal grid where each cell has six possible neighboring cells, one in each direction of the hexagon layout. Moving from any cell to an adjacent one has a fixed cost depending only on the direction of the move, not on the position of the cell.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedyimplementationmathshortest-paths
CF 1421B - Putting Bricks in the Wall

We are given a square grid of size $n times n$ representing a room. Each cell contains either a 0 or 1, except the start at the top-left and finish at the bottom-right, which are labeled 'S' and 'F'.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1422C - Bargain

The error you are seeing is not an algorithmic bug. The traceback says: This happens because the test harness is calling a function named solve(), but no such function exists in the submitted code. Python never even reads the input or starts computing shortcuts.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1422F - Boring Queries

We are given a static array of integers, and we are asked to answer many range queries. Each query asks for the least common multiple of all values inside a subsegment of the array.

codeforcescompetitive-programmingdata-structuresmathnumber-theory
CF 1422D - Returning Home

We are moving on an enormous grid. The starting cell is $(sx,sy)$ and the destination is $(fx,fy)$. Walking works normally: moving one cell horizontally or vertically costs one minute, so the cost of walking between two positions is Manhattan distance.

codeforcescompetitive-programminggraphsshortest-pathssortings
CF 1422E - Minlexes

We are given a string s consisting of lowercase letters. For each suffix of s, we are asked to compute the lexicographically smallest string that can result after repeatedly removing disjoint pairs of identical consecutive letters.

codeforcescompetitive-programmingdpgreedyimplementationstrings
CF 1422A - Fence

The task is to determine a possible length for the fourth side of a quadrilateral when three sides are already given. Each input case provides three integers representing the lengths of three existing fence segments.

codeforcescompetitive-programminggeometrymath
CF 1422B - Nice Matrix

We are given a rectangular grid of integers of size $n times m$, and we want to transform it into a "nice" matrix. A matrix is nice if every row and every column reads the same forwards and backwards, meaning they are palindromes.

codeforcescompetitive-programminggreedyimplementationmath
CF 1423N - BubbleSquare Tokens

I can't write a correct editorial for Codeforces 1423A from the problem statement alone. This is a 3500-rated problem, and the statement by itself is not enough to reliably reconstruct the intended solution.

codeforcescompetitive-programming
CF 1423M - Milutin's Plums

We are given an unknown matrix with $n$ rows and $m$ columns, and each cell contains an integer weight. Our only way to learn values is by querying individual positions. The goal is to identify the smallest value anywhere in the matrix, but we are not allowed to scan it directly.

codeforcescompetitive-programminginteractive
CF 1423C - Dušan's Railway

The problem asks us to work with a tree representing a railway network, where cities are nodes and railways are edges. Dušan wants to add shortcuts between pairs of cities.

codeforcescompetitive-programmingdivide-and-conquergraphstrees
CF 1423K - Lonely Numbers

We are asked to determine how many numbers in the set {1, 2, ..., n} are “lonely,” meaning they have no “friends.” Two numbers are friends if the greatest common divisor of the two numbers, along with the numbers divided by that gcd, can form a triangle.

codeforcescompetitive-programmingbinary-searchmathnumber-theorytwo-pointers
CF 1423L - Light switches

We are asked to determine the minimal set of switches Nikola must flip to turn all warehouse lights off, given the state of the lights at the end of several days. Each switch flips a predefined subset of lights.

codeforcescompetitive-programmingmeet-in-the-middle
CF 1423J - Bubble Cup hypothesis

We are counting representations of a number using base-2 evaluation of a polynomial whose coefficients are restricted to small digits from 0 to 7.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpmath
CF 1423I - Lookup Tables

We have a function over 2K bits. Every input x can be split into two halves: - a = lowKBits(x) - b = highKBits(x) The function must be represented as $$F(x)=L[a] & M[b]$$ where L and M are lookup tables of size 2^K, and & is bitwise AND.

codeforcescompetitive-programmingbitmasks