brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1821D - Black Cells

We have a huge one-dimensional grid of cells, indexed from 0 to $10^{18}-1$. Each cell starts white, and we control a pointer initially at cell 0. The pointer can move one step to the right at a time.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymath
CF 1821E - Rearrange Brackets

We are given a sequence of parentheses that is already regular, meaning it can be fully matched into pairs without any leftover. The sequence could be something like ()(), ((())), or more complex nestings.

codeforcescompetitive-programmingbrute-forcedpgreedysortingsstrings
CF 1821C - Tear It Apart

Thanks for providing the new failing sample. This is a different problem from the earlier input parsing bug. The code now runs, but produces wrong output, so it is a logic error in the algorithm itself. Let's analyze carefully.

codeforcescompetitive-programmingbrute-forceimplementationmathstrings
CF 1821B - Sort the Subarray

We are given two arrays of integers, the original array a and a modified array a'. The modification consists of selecting a contiguous subarray of a and sorting it in non-descending order to produce a'.

codeforcescompetitive-programmingbrute-forcegreedy
CF 1821A - Matching

We are given a string consisting of digits and question marks. Each question mark represents an unknown digit, and we want to count all positive integers that can be formed by replacing the question marks with digits such that the resulting number has no leading zeros.

codeforcescompetitive-programmingcombinatoricsmath
CF 1822G2 - Magic Triples (Hard Version)

We are asked to count the number of triples of indices in an array where each triple is "magic" according to a multiplicative pattern. Specifically, a triple $(i, j, k)$ is magic if $aj$ is some integer multiple $b$ of $ai$ and $ak$ is the same multiple $b$ of $aj$.

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1822G1 - Magic Triples (Easy Version)

We are given a sequence of integers and asked to count the number of triples of indices $(i, j, k)$ such that each index is distinct and there exists a positive integer $b$ where multiplying the value at $i$ by $b$ gives the value at $j$, and multiplying the value at $j$ by…

codeforcescompetitive-programmingbrute-forcedata-structuresmathnumber-theory
CF 1822C - Bun Lover

Each person contributes one of three things: A fixed seat request consumes exactly one seat and pins structure. A -1 person can always be used to extend a segment outward from the current left boundary.

codeforcescompetitive-programmingmath
CF 1822F - Gardening Friends

We are given a tree rooted at vertex 1, where every edge has the same length. The “cost” of the tree is simply how far the farthest vertex is from the current root. Because all edges have identical weight, this cost is just the height of the tree times the edge length.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpgraphstrees
CF 1822E - Making Anti-Palindromes

We are given a string consisting of lowercase English letters, and we want to transform it into an anti-palindrome using the minimum number of character swaps.

codeforcescompetitive-programminggreedymathstrings
CF 1822D - Super-Permutation

We are given a sequence of integers from 1 to n arranged in some order, and we interpret it as a permutation. From this permutation, we construct a running sum array where each position stores the prefix sum of the permutation, reduced modulo n.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1822A - TubeTube Feed

The feed can be thought of as a linear list of videos, each with two attributes: how long it takes to watch and how enjoyable it is. Mushroom Filippov starts at the first video and can move rightwards through the list, spending one second per step to skip to the next item.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1822B - Karina and Array

We are given an array of integers and we are allowed to delete any subset of elements while preserving the relative order of what remains.

codeforcescompetitive-programminggreedymathsortings
CF 1823F - Random Walk

We are given a tree where a chip performs a random walk that stops only when it reaches a designated target vertex $t$.

codeforcescompetitive-programmingdpgraphsmathprobabilitiestrees
CF 1823B - Sort with Step

I have carefully analyzed the failures. The previous solutions were trying to use “next greater/previous greater element” to compute contributions, but that approach is not the correct algorithm for the Easy Version of Codeforces 1827B1.

codeforcescompetitive-programmingbrute-forcemathsortings
CF 1823D - Unique Palindromes

We are asked to construct a string of length n such that certain prefixes of the string contain exactly a given number of unique palindromic substrings. Each prefix is defined by a length xi, and the number of unique palindromes it should contain is ci.

codeforcescompetitive-programmingconstructive-algorithmsmathstrings
CF 1823E - Removing Graph

We are asked to determine the winner in a two-player game played on a special type of graph. The graph has each vertex of degree exactly 2, which immediately tells us that every connected component is either a cycle or a simple loop. There are no self-loops or multiple edges.

codeforcescompetitive-programmingbrute-forcedpgamesgraphsmath
CF 1823C - Strongly Composite

We are given several test cases. In each test case, there is an array of integers, and the total product of all numbers in this array is fixed.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1823A - A-characteristic

We are asked to construct an array of length $n$ consisting only of 1s and -1s such that the number of pairs of indices $i < j$ with equal elements (both 1 or both -1) is exactly $k$. This number of pairs is referred to as the array's $A$-characteristic.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 1824E - LuoTianyi and Cartridge

We are given a tree with n vertices, where each vertex has two attributes, ai and bi. Each edge also has two attributes, cj and dj.

codeforcescompetitive-programmingdata-structurestrees
CF 1824A - LuoTianyi and the Show

We have a row of m seats and n people who want to occupy them, each with a fixed type of preference. Some people insist on sitting at a specific numbered seat.

codeforcescompetitive-programminggreedyimplementation
CF 1824D - LuoTianyi and the Function

We are given an array of integers a of length n, indexed from 1. For any subarray defined by indices i through j, we define a function g(i, j) as the largest integer x such that the set of elements from position i to j is contained in the set of elements from x to j.

codeforcescompetitive-programmingdata-structures
CF 1824C - LuoTianyi and XOR-Tree

We are given a tree with n vertices, each labeled with a non-negative integer. The root is vertex 1. The goal is to modify as few vertex values as possible so that the XOR of values along every path from the root to any leaf equals zero.

codeforcescompetitive-programmingdata-structuresdfs-and-similardpdsugreedytrees
CF 1824B1 - LuoTianyi and the Floating Islands (Easy Version)

We are given a tree with $n$ nodes representing islands. On this tree, $k$ distinct nodes are chosen uniformly at random to host people. For any fixed configuration of these $k$ nodes, every island can compute the total distance to all chosen nodes.

codeforcescompetitive-programmingcombinatoricsmathprobabilitiestrees
CF 1824B2 - LuoTianyi and the Floating Islands (Hard Version)

We are given a tree with $n$ nodes. Then we choose $k$ distinct nodes uniformly at random, and place one “person” on each of them.

codeforcescompetitive-programmingcombinatoricsdfs-and-similarmathprobabilitiestrees
CF 1825E - LuoTianyi and XOR-Tree

We are given a rooted tree with n vertices, each labeled with a non-negative integer. The root is vertex 1. We are allowed to change the value of any vertex to any non-negative integer, and our goal is to minimize the number of changes required so that the bitwise XOR of the…

codeforcescompetitive-programmingdata-structuresdpdsugreedytrees
CF 1825D1 - LuoTianyi and the Floating Islands (Easy Version)

We are given a tree with $n$ nodes, representing islands connected by $n-1$ bidirectional routes. From this tree, we randomly choose $k$ distinct nodes, where $k le 3$. These chosen nodes represent the locations of people.

codeforcescompetitive-programmingcombinatoricsdpmathtrees
CF 1825D2 - LuoTianyi and the Floating Islands (Hard Version)

We have a set of $n$ islands connected in a tree structure. That means any two islands are connected by exactly one path, and there are $n-1$ edges. LuoTianyi wants to meet $k$ friends, each located on a distinct island.

codeforcescompetitive-programmingcombinatoricsdfs-and-similarmathtrees
CF 1825C - LuoTianyi and the Show

We are given a row of seats numbered from 1 to $m$ and $n$ people arriving in a show. Each person has a preferred seating type: they either want to sit immediately to the left of the leftmost occupied seat, immediately to the right of the rightmost occupied seat, or in a…

codeforcescompetitive-programminggreedysortings
CF 1825B - LuoTianyi and the Table

We are given a flat list of n m integers and asked to fill them into an n-by-m table. After filling, we compute a sum over all submatrices that start at the top-left corner (1,1) and end at each position (i,j).

codeforcescompetitive-programminggreedymath
CF 1825A - LuoTianyi and the Palindrome String

We are given a string that is guaranteed to be a palindrome. The task is to find the longest subsequence of this string that is not a palindrome.

codeforcescompetitive-programminggreedystrings
CF 1826B - Lunatic Never Content

I have carefully examined the problem and the previous attempts. The algorithm itself - iterating over all subarrays, keeping a running currentmin and currentmax, and adding currentmax - currentmin - is correct for the easy version of the problem.

codeforcescompetitive-programmingmathnumber-theory
CF 1826F - Fading into Fog

We are asked to find a set of hidden points on a 2D plane using queries that return projections of all points onto a line of our choice. Each query gives us the locations of these projections along the line, with slight precision errors.

codeforcescompetitive-programminggeometryinteractivemathprobabilities
CF 1826E - Walk the Runway

We are given a sequence of runway shows across multiple cities, each with its own ranking of models. There are n models and m cities. Each model has a profit value, and each city gives a rating to each model.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresdpgraphsimplementationsortings
CF 1826D - Running Miles

We are given a linear street with n sights, each at a specific mile marker from the start. Each sight has an associated beauty score.

codeforcescompetitive-programmingbrute-forcedpgreedy
CF 1826C - Dreaming of Freedom

We have a group of n programmers who are repeatedly voting to choose a single favorite among m algorithms. Each round, every programmer casts a vote for one of the remaining options.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1826A - Trust Nobody

We are given a group of people where each person makes a claim about the minimum number of liars in the group. Each person either always tells the truth or always lies. Our task is to decide whether these claims are consistent and, if so, to determine a possible number of liars.

codeforcescompetitive-programmingbrute-forcegreedyimplementationsortings
CF 1827E - Bus Routes

The original logic did the following: 1. Read all intervals and sorted them by left endpoint. 2. Merged overlapping intervals into merged blocks. 3. Marked all positions covered by merged blocks as used. 4. Counted "free positions" (free = used.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdfs-and-similargreedytrees
CF 1827F - Copium Permutation

We are given a permutation of length $n$. We are allowed to take the suffix starting at position $k+1$ and freely rearrange it, while keeping the prefix $a1 ldots ak$ fixed in place.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgreedy
CF 1827D - Two Centroids

We are asked to process a dynamic tree that grows one node at a time. Initially, the tree has a single node labeled 1. Each query adds a new node and connects it to an existing node, forming a tree incrementally.

codeforcescompetitive-programmingdata-structuresdfs-and-similargreedytrees
CF 1827C - Palindrome Partition

We are given a string consisting of lowercase Latin letters, and we are asked to count its “beautiful” substrings. A substring is beautiful if it is an even palindrome or can be partitioned into smaller even palindromes.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdphashingstrings
CF 1827B1 - Range Sorting (Easy Version)

We are asked to compute a “beauty” metric for all subarrays of a given array of distinct integers. The beauty of a subarray is the minimum total time needed to sort it using range-sort operations.

codeforcescompetitive-programmingbinary-searchdpdsugreedytreestwo-pointers
CF 1827B2 - Range Sorting (Hard Version)

We are given an array of distinct integers and asked to compute, for every contiguous subarray, the minimum total time required to sort it using range-sort operations.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedy
CF 1827A - Counting Orders

We are given two arrays, a and b, each of length n. The elements in a are all distinct, while b may contain repeated numbers. The task is to count the number of ways we can reorder the elements of a so that after reordering, for every index i, the condition a[i] b[i] holds.

codeforcescompetitive-programmingcombinatoricsmathsortingstwo-pointers
CF 1828E - Palindrome Partition

The solution correctly generalizes the serial test from pairs to $k$-tuples by grouping the sequence into disjoint blocks of length $k$, ensuring independence under the null hypothesis.

codeforcescompetitive-programmingdata-structuresdphashingstrings
CF 1828F - Two Centroids

We are given a tree that grows incrementally: it starts with vertex 1, and each subsequent vertex is attached to some existing vertex in the tree. For each insertion, we are asked how many extra vertices we must add to make the tree have exactly two centroids.

codeforcescompetitive-programmingdfs-and-similar
CF 1828D1 - Range Sorting (Easy Version)

We are asked to compute a cumulative measure of "beauty" over all subarrays of a given array of distinct integers.

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresdpdsugreedy
CF 1828D2 - Range Sorting (Hard Version)

We are asked to compute a "beauty" measure for every subarray of a given array of distinct integers. The array can be large, up to 300,000 elements, and the total across all test cases is bounded by the same number.

codeforcescompetitive-programmingbinary-searchdata-structuresdpgreedy
CF 1828C - Counting Orders

The solution correctly generalizes the serial test from pairs to $k$-tuples by grouping the sequence into disjoint blocks of length $k$, ensuring independence under the null hypothesis.

codeforcescompetitive-programmingbinary-searchcombinatoricssortings
CF 1828A - Divisible Array

We are asked to construct an array for each test case, where the array length is fixed to a given integer $n$. Each position $i$ in the array must contain a value that is a multiple of $i$, and every value must stay within a small fixed range up to 1000.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1828B - Permutation Swap

We are given a permutation of integers from 1 to n in some arbitrary order. Our task is to sort the permutation into ascending order by repeatedly swapping pairs of elements that are exactly k positions apart, for some fixed k.

codeforcescompetitive-programmingmathnumber-theory
CF 1829G - Hits Different

The structure in this problem is a fixed pyramid of numbered cans, where each position in the pyramid contains a square number.

codeforcescompetitive-programmingdata-structuresdpimplementationmath
CF 1829H - Don't Blame Me

We are given an array where every element is a small integer, specifically a 6-bit value. From this array, we can choose any non-empty subsequence, meaning we pick any subset of indices while preserving order, although order does not actually matter for the bitwise operation.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmath
CF 1829F - Forever Winter

We are given a graph generated by a simple "snowflake" process. There is a central vertex, then $x$ vertices connected directly to the center, and then $y$ vertices connected to each of the $x$ outer vertices.

codeforcescompetitive-programmingdfs-and-similargraphsmath
CF 1829E - The Lakes

We are given a two-dimensional grid representing terrain, where each cell contains a non-negative integer indicating the depth of water at that location.

codeforcescompetitive-programmingdfs-and-similardsugraphsimplementation
CF 1829D - Gold Rush

We start with a single pile containing n gold nuggets. The only allowed move takes one existing pile and splits it into exactly two smaller piles, with a strict structure: one of the new piles must be exactly twice the size of the other.

codeforcescompetitive-programmingbrute-forcedfs-and-similardpimplementation
CF 1829B - Blank Space

The solution correctly generalizes the serial test from pairs to $k$-tuples by grouping the sequence into disjoint blocks of length $k$, ensuring independence under the null hypothesis.

codeforcescompetitive-programmingimplementation
CF 1829C - Mr. Perfectly Fine

Victor has two independent skills he wants to acquire, and each book he can read either teaches him skill 1, skill 2, both, or none. Every book also has a time cost.

codeforcescompetitive-programmingbitmasksgreedyimplementation
CF 1829A - Love Story

We are given a fixed reference string, “codeforces”, and for each test case we receive another string of the same length, exactly 10 lowercase letters. The task is to compare these two strings position by position and count how many positions contain different characters.

codeforcescompetitive-programmingimplementationstrings
Kvant Math Problem 2709

The problem can be formulated in graph-theoretic terms.

kvantmathematicsolympiad
CF 1831F - Mex Tree

We are asked to maximize the sum of MEX values over all paths in a tree where each node can be colored either 0 or 1. A path is defined as the unique simple path between any two nodes, including paths that start and end at the same node.

codeforcescompetitive-programmingbrute-forcedptrees
CF 1831E - Hyperregular Bracket Strings

We are asked to count bracket sequences of length $n$ that are globally regular, while also being locally regular on certain specified subintervals. The input gives us the length $n$ and a list of $k$ intervals $[li, ri]$.

codeforcescompetitive-programmingcombinatoricsdata-structureshashingmathnumber-theorysortingstwo-pointers
CF 1831D - The BOSS Can Count Pairs

We are given two arrays a and b of equal length n. The task is to count the number of index pairs (i, j) with i < j such that the product of the a elements at those indices equals the sum of the corresponding b elements: a[i] a[j] = b[i] + b[j].

codeforcescompetitive-programmingbinary-searchbrute-forcedata-structuresmath
CF 1831A - Twin Permutations

We are given a permutation a of length n, which means it contains all integers from 1 to n exactly once in some order. Our task is to construct another permutation b of the same length such that the sequence formed by summing corresponding elements, ai + bi, is non-decreasing.

codeforcescompetitive-programmingconstructive-algorithms
CF 1831B - Array merging

We are given two arrays, a and b, of the same length n. The task is to form a new array c of length 2n by successively taking the first element of either array until both are exhausted.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 1831C - Copil Copac Draws Trees

We are given a tree with $n$ vertices, described as a list of $n-1$ edges. Copil Copac draws the tree step by step: he always starts with vertex 1, then repeatedly scans the list of edges in order, drawing any vertex connected to a previously drawn vertex.

codeforcescompetitive-programmingdfs-and-similardpgraphstrees
CF 1832F - Zombies

Each entrance in this problem behaves like a stream of zombies arriving over a long time interval. For every minute in the range $[0, x)$, exactly one zombie attempts to pass through each entrance.

codeforcescompetitive-programmingbinary-searchdp
CF 1832E - Combinatorics Problem

We are asked to compute a transformed array from a pseudo-randomly generated sequence using binomial coefficients.

codeforcescompetitive-programmingbrute-forcecombinatoricsdp
CF 1832C - Contrast Value

We are given an array and a specific measure of how “change-heavy” it is: the sum of absolute differences between consecutive elements. This value captures how much the array oscillates as we walk through it left to right.

codeforcescompetitive-programminggreedyimplementation
CF 1832D2 - Red-Blue Operations (Hard Version)

We are given an array of integers, initially colored red. On each operation, you pick a single element. If it is red, you increase it by the operation number and switch it to blue. If it is blue, you decrease it by the operation number and switch it back to red.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedyimplementationmath
CF 1832D1 - Red-Blue Operations (Easy Version)

We have an array of integers, each initially painted red, and a sequence of operations numbered from one onwards. On operation number $i$, if we pick a red element, it increases by $i$ and turns blue; if we pick a blue element, it decreases by $i$ and turns red.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmath
CF 1832A - New Palindrome

We are asked to determine whether a palindrome string can be rearranged to form a different palindrome. A palindrome is a string that reads the same forwards and backwards, like "abba" or "racecar".

codeforcescompetitive-programmingstrings
CF 1832B - Maximum Sum

We are given an array of distinct integers and must perform exactly k deletion operations. In each operation we can either remove the largest element or remove the two smallest elements together.

codeforcescompetitive-programmingbrute-forcesortingstwo-pointers
CF 1833G - Ksyusha and Chinchilla

We are given a tree, and we are allowed to remove edges. After removing some edges, the remaining connected components must each consist of exactly three vertices, and each such component must itself still be a tree.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardpdsugreedyimplementationtrees
CF 1833F - Ira and Flamenco

We are given an array of student skill levels, and we want to count how many ways we can choose exactly m students to form a group under two simultaneous constraints.

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsdata-structuresimplementationmathsortingstwo-pointers
CF 1833B - Restore the Weather

We are given two arrays of the same length. One array represents predicted temperatures for each day, and the other contains the actual temperatures, but the actual values are shuffled and their ordering is lost.

codeforcescompetitive-programminggreedysortings
CF 1833E - Round Dance

We are given a group of people at a festival, each of whom remembers exactly one neighbor in a round dance. Each dance is a closed cycle where every participant has exactly two neighbors, but we only know one neighbor per person.

codeforcescompetitive-programmingdfs-and-similardsugraphsshortest-paths
CF 1833D - Flipper

We are given a permutation of integers from 1 to $n$. Our goal is to perform a two-part operation exactly once to produce the lexicographically largest permutation possible.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedy
CF 1833C - Vlad Building Beautiful Array

We are given an array of positive integers, and the task is to construct a new array of the same length where all elements are positive and have the same parity, either all odd or all even.

codeforcescompetitive-programminggreedymath
CF 1833A - Musical Puzzle

We are given a target melody, which is just a string over the alphabet {a, b, c, d, e, f, g}. Vlad cannot directly build this string in arbitrary chunks. Instead, he can only record pieces of length exactly two characters, like "ab" or "gg".

codeforcescompetitive-programmingimplementationstrings
CF 1834D - Survey in Class

We have a classroom of n students and m topics. Each student has learned a continuous range of topics, from li to ri. When the teacher asks about a topic, each student either raises or lowers their hand depending on whether they know the topic.

codeforcescompetitive-programmingbrute-forcedata-structuresgreedyimplementationsortings
CF 1834F - Typewriter

The solution correctly identifies what the “improved KS test” is trying to do: it replaces the unweighted empirical process by a variance-stabilized version, dividing by the binomial standard deviation $sqrt{F(x)(1-F(x))}$.

codeforcescompetitive-programmingbrute-forcemath
CF 1834E - MEX of LCM

We are asked to find the smallest positive integer that cannot appear as the least common multiple of any contiguous subarray of a given array. The input consists of multiple test cases.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationmathnumber-theory
CF 1834A - Unit Array

Investigate the "improved" KS test suggested in the answer to exercise 6. Let $X1, X2, ldots, Xn$ be independent observations drawn from a continuous distribution function $F(x)$.

codeforcescompetitive-programminggreedymath
CF 1834C - Game with Reversing

We are given two strings of equal length. In a turn-based game, Alice can modify any single character in either string, while Bob can take an entire string and reverse it.

codeforcescompetitive-programminggamesgreedymathstrings
CF 1834B - Maximum Strength

Fedya has a collection of materials, each represented by a positive integer indicating its strength. He can combine two materials into a weapon, and the weapon's strength is the sum of the absolute differences between corresponding digits of the two numbers, aligned from the…

codeforcescompetitive-programminggreedymath
CF 1835F - Good Graph

Investigate the "improved" KS test suggested in the answer to exercise 6. Let $X1, X2, ldots, Xn$ be independent observations drawn from a continuous distribution function $F(x)$.

codeforcescompetitive-programmingbitmasksdfs-and-similargraph-matchingsgraphsimplementation
CF 1835E - Old Mobile

We are asked to compute the expected number of button presses needed to type a number on an old mobile device with an unfamiliar keyboard. The keyboard has $m$ digit buttons and a backspace. Jan, the user, cannot distinguish which button is which until he presses it.

codeforcescompetitive-programmingcombinatoricsdpprobabilities
CF 1835D - Doctor's Brown Hypothesis

We have a directed graph representing planets connected by wormholes. Each planet has exactly one battleship. The rebels want to pick either a single ship or a pair of ships that can move for exactly k hours along wormholes.

codeforcescompetitive-programmingdfs-and-similargraphsmathnumber-theory
CF 1835B - Lottery

The proposed solution directly addresses the exercise by analyzing the asymptotic behavior of the finite-$n$ Kolmogorov-Smirnov distribution.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedymathtwo-pointers
CF 1835C - Twin Clusters

We are given a sequence of galaxies, each with a certain number of stars. The total number of galaxies in a test case is always a power of two, specifically $2^{k+1}$. Each galaxy has a star count between 0 and $4^k - 1$.

codeforcescompetitive-programmingbitmasksbrute-forceconstructive-algorithmsmathprobabilities
CF 1835A - k-th equality

We are asked to enumerate all equalities of the form a + b = c where a, b, and c are positive integers with exactly A, B, and C digits respectively.

codeforcescompetitive-programmingbrute-forceimplementationmath
CF 1836F - Doctor's Brown Hypothesis

We are working with a directed graph where nodes represent planets and edges represent wormholes between them. Each edge takes exactly one hour to traverse.

codeforcescompetitive-programmingdfs-and-similargraphsmathnumber-theory
CF 1836E - Twin Clusters

We are given a sequence of integers for each test case, and we are allowed to look at any contiguous segment of this sequence. For any segment, we define its value as the bitwise XOR of all elements inside it.

codeforcescompetitive-programmingconstructive-algorithmsmeet-in-the-middleprobabilities
CF 1836B - Astrophysicists

Input: This means: - t = 3 - Each test case consists of a single line containing two integers - So the test cases are: - (10, 2) - (10, 3) - (3, 4) The expected output: This indicates each test case produces two outputs per line or multiple values per case, not a single integer.

codeforcescompetitive-programminggreedymath
CF 1836D - Lottery

There are already n participants, each holding a number in the range [0, m]. Then a new participant, Bytek, joins last and chooses his own number. A random target integer t is drawn uniformly from [0, m]. After that, winners are chosen by distance to t: the k closest tickets win.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
CF 1836C - k-th equality

We are asked to enumerate all valid equations of the form a + b = c, but with strict digit-length constraints: a must have exactly A digits, b exactly B digits, and c exactly C digits. None of the numbers may start with zero, and all three values must be positive integers.

codeforcescompetitive-programmingbrute-forcegreedyimplementationmath
CF 1836A - Destroyer

Each robot reports a single integer that describes how many robots stand in front of it in its own line. The twist is that we are not told how many lines exist or which robot belongs to which line.

codeforcescompetitive-programmingimplementationsortings
CF 1837F - Editorial for Two

The error you are seeing, StopIteration, happens because the code is trying to consume more integers from the input iterator than exist.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedyimplementation
CF 1837E - Playoff Fixing

We are asked to arrange a single-elimination tournament for $2^k$ teams where each team has a strict ranking: team 1 is the strongest, team $2^k$ is the weakest, and a stronger team always beats a weaker one.

codeforcescompetitive-programmingcombinatoricstrees