brain

tamnd's digital brain — notes, problems, research

41700 notes

CF 2204C - Spring

Each test case describes three periodic visitors to a spring. Alice arrives every $a$ days, Bob every $b$ days, and Carol every $c$ days. On any day in the range from day $1$ to day $m$, some subset of them may arrive depending on divisibility of the day number.

codeforcescompetitive-programmingmathnumber-theory
CF 2204B - Right Maximum

We are given an array of integers and asked to simulate a very specific removal process. In each operation, we look at the current array, find the maximum element, and if multiple elements share that maximum, we choose the rightmost one.

codeforcescompetitive-programminggreedy
CF 2205G - Simons and Diophantus Equation

We are asked to count the number of ordered triples of integers $(i, j, k)$ in the range $[0, m]$ such that the equation $(i oplus j) cdot x + (j oplus k) cdot y = n$ has an integer solution for $x$ and $y$. Here $oplus$ is the bitwise XOR.

codeforcescompetitive-programmingbitmasksbrute-forcedata-structuresmathnumber-theory
CF 2205F - Simons and Reconstructing His Roads

We are given a rectangular grid representing a city, with intersections at coordinates $(i,j)$. Streets only exist between neighboring intersections, either horizontally or vertically. Each street has an integer weight and may or may not be allowed for reconstruction.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresdsugraphs
CF 2205E - Simons and Dividing the Rhythm

We are asked to count how many arrays $S$ exist such that, after a single sequence of independent subarray reversals, the resulting array equals a given array $T$.

codeforcescompetitive-programmingcombinatoricsdata-structuresdpdsumathstring-suffix-structuresstrings
CF 2205D - Simons and Beating Peaks

We are asked to transform a permutation of integers into a "cool" array. An array is cool if no element in the middle of a triplet is the maximum among its neighbors. In other words, the array must have no peaks, where a peak is a value larger than both its immediate neighbors.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpgreedyimplementationtrees
CF 2205A - Simons and Making It Beautiful

We are given a permutation p of length n. An index i is called ugly if it is the first time the maximum value is reached at that position. More formally, i is ugly if p[i] is equal to the maximum of p[1..i].

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 2205B - Simons and Cakes for Success

We are asked to help Simons divide cakes among his friends. More formally, for a given number of friends $n$, we need to find the smallest positive integer $k$ such that $k^n$ is divisible by $n$. The input consists of multiple test cases, each specifying the number of friends.

codeforcescompetitive-programmingimplementationmath
CF 2205C - Simons and Posting Blogs

We are given several independent scenarios. In each one, there are several “blogs”, and each blog contains an ordered list of user IDs.

codeforcescompetitive-programminggreedysortings
CF 2206L - Onion

We are given a large set of points on a two-dimensional plane, constructed using a simple linear function modulo $n$. Specifically, each point has coordinates $(x, y)$ where $x$ ranges from $0$ to $n-1$, and $y = (a cdot x + b) bmod n$.

codeforcescompetitive-programming
CF 2206M - Deformed Balance

We are given a parenthesis string $S$, and we are allowed to add some parentheses in front of it and some at the end.

codeforcescompetitive-programming
CF 2206K - Time Display Stickers

We are given a collection of digit stickers as a string. Each character represents one sticker of that digit. The goal is to assemble as many valid time displays in the format HH:MM, where HH is a two-digit hour between 00 and 11 inclusive, and MM is a two-digit minute between…

codeforcescompetitive-programmingbinary-search
CF 2206J - Worldwide Playlist

We are given a music playlist of n unique songs arranged in some initial order a. The app plays the songs in a circular fashion: after the last song, it starts over from the first. Separately, we have a desired listening sequence b of the same n songs.

codeforcescompetitive-programmingmath
CF 2206E - Parallel Sums

We are given a sequence of n integers A = [a1, a2, ..., an], but we do not know A itself. Instead, we are provided with a sequence of parallel sums of length n - m + 1, where each sum is the sum of m consecutive elements of A. Formally, the sums are si = ai + a{i+1} + ...

codeforcescompetitive-programmingdata-structuresgeometry
CF 2206I - Growth Factor

We are counting how many ways we can build a sequence of integers when each position has an upper limit, and each element must divide the next one. More concretely, at position i we choose a value bi that cannot exceed ai.

codeforcescompetitive-programmingcombinatoricsdpmathnumber-theory
CF 2206H - Reflect Sort

We are given an integer array and a somewhat unusual operation that allows us to “reflect” values around a chosen pivot element.

codeforcescompetitive-programmingnumber-theory
CF 2206G - Extra Transition

We are given a connected undirected graph on $n$ vertices, where vertex $1$ is a start and vertex $n$ is a finish.

codeforcescompetitive-programminggraphs
CF 2206D - Christmas Tree Un-decoration

We are given a rooted tree where vertex 1 is the root, and every node carries a pile of ornaments. The only way we are allowed to remove ornaments is by selecting a vertex $u$, and then subtracting one ornament from every node on the path from the root to $u$, as long as that…

codeforcescompetitive-programmingdata-structuresdptrees
CF 2206F - Minesweeper String

We are given a string of digits, each representing a cell in a conceptual 1D array of length $n$. Each digit either corresponds to some mines if it is non-zero, or an empty cell if it is zero.

codeforcescompetitive-programmingfftnumber-theory
CF 2206C - Upside Down Dijkstra

We are given a connected undirected graph with $n$ vertices and $m$ edges, where each edge connects two vertices but its weight is unknown.

codeforcescompetitive-programmingdfs-and-similar
CF 2206B - Subtree Removal Game

We are given a rooted tree with nodes numbered from 1 to $n$, rooted at node 1. Each node may either have an integer written on it (leaves) or be empty (internal nodes).

codeforcescompetitive-programmingbinary-searchgamestrees
CF 2206A - Compare Suffixes

We are tasked with sorting the suffixes of a hidden string $S$ using an interactive judge. The string has length $n$, and we do not know its contents. We can query any two suffixes $S(i)$ and $S(j)$ to learn which is lexicographically smaller.

codeforcescompetitive-programminginteractive
CF 2207H3 - Bowser's Castle (Hard Version)

We are given a black-box function of $n$ variables. The function is not arbitrary: it is built by taking the variables $x1, x2, ldots, xn$ in order and combining them using only min and max, with the restriction that each variable appears exactly once and in that fixed…

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquerinteractivetreestwo-pointers
CF 2207H2 - Bowser's Castle (Medium Version)

We are asked to reverse-engineer a hidden function chosen by Bowser. The function takes n integer inputs and is constructed entirely from nested min and max operations, each input appearing exactly once in order from x1 to xn.

codeforcescompetitive-programmingconstructive-algorithmsdivide-and-conquerinteractivetreestwo-pointers
CF 2207G - Toothless

We are given an n × m grid representing sand, initially all white. Some cells are marked as needy () and must be painted black. Other cells are either special (x) or normal (.), and each non-needy cell has a value: special cells are worth b and normal cells are worth a.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsu
CF 2207H1 - Bowser's Castle (Easy Version)

We are given an unknown function that takes a list of n values and returns a single number. The function is not arbitrary: it is built by combining the inputs using only min and max, and every input variable appears exactly once, in order.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdivide-and-conquergreedyinteractivetrees
CF 2207F - Hanabi

The problem gives us a Hanabi-like card game where Zuko holds all cards in a single row, one for each combination of rank and color. Iroh can see the cards, but Zuko cannot.

codeforcescompetitive-programmingbinary-searchdata-structuresdpdsuflowsgraph-matchingsgraphsgreedy
CF 2207E2 - N-MEX (Counting Version)

We are asked to count arrays of nonnegative integers that satisfy a sequence of nested MEX conditions. Concretely, we are given an array a of length n. For each position i in the array, we must ensure that the (n-i+1)-th MEX of the prefix [b1, ..., bi] equals a[i].

codeforcescompetitive-programmingcombinatoricsconstructive-algorithmsmath
CF 2207E1 - N-MEX (Constructive Version)

We are asked to construct an array b from a given array a such that, for each prefix of b, a generalized MEX condition holds. Specifically, the (n-i+1)-th MEX of the first i elements of b must equal a[i].

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2207D - Boxed Like a Fish

We are given a tree where a token starts at a fixed non-leaf vertex. The goal is to determine whether this token can be guaranteed to reach any leaf vertex if two players act in turns. One player controls the token.

codeforcescompetitive-programmingdfs-and-similardpgamesshortest-pathstrees
CF 2207C - Where's My Water?

The grid can be understood more simply if we ignore the 2D picture and focus on each column independently. In column i, there are ai dirt tiles at the bottom, and all tiles above them up to height h are water. So the number of water tiles in column i is h - ai.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdpmath
CF 2207A - 1-1

We are given a binary string and a single operation that can be applied repeatedly. The operation only affects positions that are strictly inside the string, and only when that position is surrounded by ones on both sides.

codeforcescompetitive-programminggreedystrings
CF 2207B - One Night At Freddy's

We are asked to simulate a night at Freddy Fazbear’s Pizzeria in terms of danger management. Each animatronic accumulates danger every second, and the night lasts for a fixed number of seconds.

codeforcescompetitive-programminggamesgreedysortings
CF 2208D1 - Tree Orientation (Easy Version)

We are given a binary reachability matrix for a directed graph on $n$ nodes. The matrix tells us, for every ordered pair $(i, j)$, whether node $i$ can reach node $j$ through directed edges.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardsugraphsgreedymatricestrees
CF 2208E - Counting Cute Arrays

We are given an array of length $n$ with integers ranging from $-1$ to $n$. The $-1$ values are placeholders that can take any non-negative integer.

codeforcescompetitive-programmingcombinatoricsdp
CF 2208D2 - Tree Orientation (Hard Version)

We are given a directed reachability matrix of a tree after all its edges have been assigned directions, and we need to reconstruct a tree and its edge directions that produce exactly the same reachability information.

codeforcescompetitive-programmingdfs-and-similardsugraphsgreedysortingstrees
CF 2208B - Cyclists

We are given a deck of n cards, each with an energy cost. Bob wants to play a special "win-condition" card as many times as possible without exceeding a total energy budget m. On each turn, Bob can select a card from only the first k positions in the current deck.

codeforcescompetitive-programmingbrute-forcegamesgreedyimplementationmathsortings
CF 2208C - Stamina and Tasks

We are given a sequence of tasks, each with a point value and a difficulty percentage. You start with a stamina of 1. For each task, you can either skip it or complete it.

codeforcescompetitive-programmingdpgreedymath
CF 2208A - Bingo Candies

We are given a square grid of size $n times n$ representing a board where each cell contains a candy of a certain color. The color of a candy is denoted by an integer, and different integers represent different colors.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2209F - Dynamic Values And Maximum Sum

We are given a tree of n vertices, where each vertex has an integer value. We can perform k operations, and in each operation, we choose a vertex to root the tree at. Once a vertex is chosen as the root, its value is added directly to the total and then set to zero.

codeforcescompetitive-programmingdata-structuresgreedyimplementationtrees
CF 2209E - A Trivial String Problem

We are given a string and a set of queries. For each query, we take a substring defined by its endpoints, and for every prefix of this substring, we compute the maximum number of pieces it can be split into such that each piece is itself a prefix of the substring.

codeforcescompetitive-programmingbrute-forcedphashingstring-suffix-structuresstrings
CF 2209D - Ghostfires

The problem asks us to construct a sequence of ghostfires in three colors: red, green, and blue. OtterZ has a limited number of each color, denoted by $r$, $g$, and $b$. The goal is to place as many ghostfires as possible in a row while avoiding two constraints.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 2209A - Flip Flops

We are given a sequence of monsters, each with a strength value. We also start with an initial combat power. At any point, we can either defeat a monster if our current power is at least its strength, or we can spend a limited number of special items to increase a monster’s…

codeforcescompetitive-programminggreedy
CF 2209C - Find the Zero

We are asked to find a position of a zero in a hidden array of length $2n$, where each integer from $1$ to $n$ occurs exactly once and all remaining positions are zeros.

codeforcescompetitive-programmingconstructive-algorithmsinteractive
CF 2209B - Array

We are given an array of integers, and for each element, we need to determine how many elements to its right can be “dominated” by it, in a specific sense.

codeforcescompetitive-programminggreedy
CF 2210C1 - A Simple GCD Problem (Easy Version)

We are given an array of integers where every element can potentially be changed once. However, each position has a strict constraint: any replacement value must lie in the range from 1 up to the original value at that position, and it must differ from the original value.

codeforcescompetitive-programminggreedynumber-theory
CF 2210F - A Simple Problem

We are given a permutation of integers from 1 to n and a series of queries, each asking about a contiguous subarray of this permutation.

codeforcescompetitive-programmingbinary-searchdata-structuresgreedymathtrees
CF 2210E - Binary Strings are Simple?

We are dealing with an interactive reconstruction problem where the hidden object is a binary string of length $n$. We do not observe the string directly.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractivenumber-theory
CF 2210C2 - A Simple GCD Problem (Hard Version)

We are given two arrays of equal length. Think of the first array as the current values written on a line of positions, and the second array as upper bounds that control how far each position is allowed to be changed.

codeforcescompetitive-programmingdpgreedynumber-theory
CF 2210D - A Simple RBS Problem

We are given two balanced bracket strings of equal length. Both strings are guaranteed to be regular bracket sequences, meaning every prefix has at least as many opening brackets as closing ones and the total counts match.

codeforcescompetitive-programmingconstructive-algorithmsmathstringstrees
CF 2210B - Simply Sitting on Chairs

We have a row of $n$ chairs, all initially unmarked. A permutation $p$ of length $n$ is given, meaning each number from $1$ to $n$ appears exactly once. We start from the first chair and move right. At each chair, if it is already marked, the game stops immediately.

codeforcescompetitive-programmingdata-structuresgreedy
CF 2210A - A Simple Sequence

We are asked to construct a permutation of integers from 1 to $n$ such that the sequence of consecutive remainders is non-increasing.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedynumber-theory
CF 2211H - Median Deletion

We are given a permutation of integers from 1 to $n$. The problem allows an operation where we select any consecutive three elements and delete the second smallest among them.

codeforcescompetitive-programming
CF 2211G - Rational Bubble Sort

We are given an array of integers where each element can range from 0 to 10^6. Our allowed operation is to pick any two adjacent elements, compute their average, and then set both elements to that average.

codeforcescompetitive-programmingconstructive-algorithmsgeometrygreedy
CF 2211F - Learning Binary Search

We are working with all nondecreasing arrays of length $n$ whose values lie between $1$ and $m$. Each such array can be thought of as a way to distribute $n$ positions among $m$ distinct values, where each value appears in a contiguous block or not at all.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquerdpmath
CF 2211D - AND-array

We are given a hidden array a of length n. Instead of seeing a directly, we are provided with a sequence b such that each element bk is the sum of the bitwise ANDs of all k-element subsequences of a, modulo 10^9 + 7.

codeforcescompetitive-programmingbitmaskscombinatoricsmath
CF 2211E - Minimum Path Cover

We are given a rooted tree where every node carries a large integer value. A valid “vertical path” is simply a downward chain: each node is the child of the previous one.

codeforcescompetitive-programmingbrute-forcedpgreedyinteractivemathnumber-theorytrees
CF 2211C2 - Equal Multisets (Hard Version)

We are given two arrays of length $n$, both indexed from 1 to $n$, and a window size $k$. The first array $a$ is fully fixed, while the second array $b$ is partially unknown because some positions contain $-1$.

codeforcescompetitive-programmingconstructive-algorithmsdsugreedy
CF 2211C1 - Equal Multisets (Easy Version)

We are given two arrays, a and b, of length n and a parameter k. The array a is a permutation of numbers from 1 to n, which means every number from 1 to n appears exactly once.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedytwo-pointers
CF 2211B - Mickey Mouse Constructive

We are asked to work with arrays built from only two types of elements: 1 and -1. Each test case specifies how many of each we have, x ones and y minus ones. The array can be any permutation of these elements.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedymath
CF 2211A - Antimedian Deletion

We are given a permutation of size $n$, which is an array containing each integer from $1$ to $n$ exactly once in some order. The only operation allowed is to take any consecutive three elements and remove either the largest or the smallest among them.

codeforcescompetitive-programmingimplementationmath
CF 2214C - And?

In this problem, we are given three integers for each test case, which we can call a, b, and c. The task is to compute a single integer for each test case based on a bitwise operation involving these numbers.

codeforcescompetitive-programming*specialbitmasks
CF 2214I - You Are a Robot

We are given a tree rooted at node 1, where each edge connects a parent to a child and is marked as either empty (0), contains a human (1), or contains a robot (2). A trolley starts at the root and moves along the tree.

codeforcescompetitive-programming*special
CF 2214J - Special Problem

This problem presents an interactive game scenario where you have a hidden system generating some responses. The goal is to query the system in a structured way to deduce a hidden value or sequence.

codeforcescompetitive-programming*specialbrute-forcegamesinteractive
CF 2214H - Double Vision

This is a visual reasoning problem where the input describes a picture rather than a traditional numeric structure. You are given a grid-like arrangement of cells that visually encode information in two overlapping interpretations.

codeforcescompetitive-programming*special
CF 2214G - Anomaly

The problem presents a hidden string of length 11, and our task is to report the character at a given 1-based index for multiple queries. Each query consists of a single integer, and the output is simply the character at that position in the string.

codeforcescompetitive-programming*specialcommunication
CF 2214F - Numbers

Before I start, can you clarify if the problem "Codeforces 2214F - Numbers" has multiple test cases per input, or is it guaranteed to be a single instance per run? This affects the structure of the Python solution.

codeforcescompetitive-programming*special
CF 2214D - Neural Feud

The problem gives a very simple interaction: there are eight pre-defined questions, each associated with a single-word answer. You receive an integer n between 1 and 8, indicating which question is being asked, and you must output the corresponding answer.

codeforcescompetitive-programming*specialstrings
CF 2214E - Shortest Paths

We are given a weighted undirected graph with up to a hundred vertices. Each edge connects two numbered nodes and has a non-negative cost.

codeforcescompetitive-programming*specialshortest-paths
CF 2214B - Are You Smiling?

The task is phrased in an intentionally playful way, but the underlying requirement is straightforward string reconstruction under a fixed pattern constraint. We are given a single input line containing a sentence.

codeforcescompetitive-programming*specialstrings
CF 2214A - Odd One Out

In this problem, we are presented with a set of four tiles, each labeled by a combination of a letter and a digit. Three of the tiles are identical, and one differs in either the letter or the digit. Our goal is to identify this "odd one out" and print its label.

codeforcescompetitive-programming*specialgraph-matchingsimplementation
CF 2215G - Maze

We are given a maze represented by a grid of size $(n+2) times (n+2)$, where the outermost cells are automatically obstacles. Additional obstacle cells are provided, and it is guaranteed that all obstacles form a 4-connected component.

codeforcescompetitive-programmingtrees
CF 2215F - Research

We are looking at a two-player deterministic game played on a deck that is mostly identical cards except for one special card. The special card, initially green, sits at a known position from the top.

codeforcescompetitive-programminggames
CF 2215D - EXPloration, EXPloitation, and Gain Some EXPerience!

We are given a line of positions from 1 to $n$. Two tokens start at positions 1 and 2, and these two starting positions are already considered “taken” from the very beginning. Each token belongs to one player: Shiro controls position 1 and White controls position 2.

codeforcescompetitive-programmingbitmasksbrute-forcedpgreedyimplementation
CF 2215E - Star Map

We are given a set of points in the plane. A key structural guarantee is that no two points share the same x-coordinate and no two share the same y-coordinate, so every point is uniquely identifiable by its horizontal and vertical rank.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuresgeometrygreedysortings
CF 2215B - RReeppeettiittiioonn

The problem asks us to count the number of ways a given positive integer $n$ can be represented in a "repetitive" form across all numeral bases.

codeforcescompetitive-programmingbinary-searchbrute-forceimplementationmathnumber-theory
CF 2215A - Interval Mod

We are given an array of integers and two moduli, $p$ and $q$, along with a minimum interval length $k$. The allowed operation is to choose any contiguous subarray of length at least $k$ and reduce every element in that subarray modulo either $p$ or $q$.

codeforcescompetitive-programmingconstructive-algorithmsdpgreedymath
CF 2215C - Oriented Journey

We are dealing with a two-phase communication system built around a tree. First, an agent receives an undirected tree one edge at a time and must immediately orient each edge.

codeforcescompetitive-programmingbitmasksbrute-forcecommunicationconstructive-algorithmsgraphsinteractivetrees
CF 2220B - OIE Excursion

We are given a line of positions from 1 to n, each guarded by a volunteer. Hector starts at position 0 and wants to reach position n+1 by moving one step left, right, or staying still at the end of each second. Each volunteer has a timer that evolves deterministically.

codeforcescompetitive-programminggreedy
CF 2225G - Simple Problem

We are given a set of integers from 0 to n − 1, and the task is to order them into a single sequence. The sequence must satisfy a local constraint: for every pair of consecutive elements in the permutation, their absolute difference must be divisible by at least one number…

codeforcescompetitive-programmingbrute-forcegraphsgreedynumber-theory
CF 2225F - String Cutting

We are given a string and we are allowed to split it into several consecutive pieces. Every piece must have length at least l, and we are required to produce at least k pieces in total. After choosing a valid cut, all resulting pieces are sorted lexicographically.

codeforcescompetitive-programmingbinary-searchbrute-forcegreedyhashingstring-suffix-structuresstrings
CF 2225D - Exceptional Segments

We are working with the sequence of integers from 1 to n. From this sequence, we look at all contiguous subsegments that must contain a fixed position x. For every such segment, we compute the bitwise XOR of all elements inside it and check whether the result is exactly zero.

codeforcescompetitive-programmingbitmasksbrute-forcemath
CF 2225E - Covering Points with Circles

We are given a set of points on a 2D integer grid. These points are not adversarially structured; instead, they come from a random process inside a large axis-aligned square.

codeforcescompetitive-programmingconstructive-algorithmsgeometrymath
CF 2225A - A Number Between Two Others

We are given two integers x and y such that y is greater than x and is divisible by x. The task is to determine whether there exists a third integer z that sits strictly between x and y, is divisible by x, but does not divide y.

codeforcescompetitive-programminggreedymath
CF 2225C - Red-Black Pairs

We are given a grid with two rows and $n$ columns, so there are $2n$ cells in total. Each cell is colored either red or black.

codeforcescompetitive-programmingdpgreedy
CF 2225B - Alternating String

We are given a binary string consisting only of a and b. The goal is to determine whether we can transform it into a perfectly alternating string, meaning no two adjacent characters are the same. We are allowed to perform at most one operation.

codeforcescompetitive-programmingbrute-forcegreedy
CF 2222H - Counting Sort?

We are asked to count arrays with a property defined recursively. Given an array of integers, each bounded individually by a corresponding ri, we define a transformation f(b) that counts how many times each integer appears in b.

codeforcescompetitive-programmingbrute-forcecombinatoricsdp
CF 2222G - Statistics on Tree

We are working with a tree where each pair of vertices defines a path. For any pair of nodes $(u, v)$, we look at the unique simple path connecting them and then imagine removing all edges on that path from the tree.

codeforcescompetitive-programmingbinary-searchbrute-forcedfs-and-similardivide-and-conquergraphstrees
CF 2222F - Building Tree

We start with a weighted undirected graph on n vertices. The twist is that distance between two nodes is not the usual shortest path sum. Instead, if you take any path and look at the set of edge weights used on that path, the cost of the path is the mex of that set.

codeforcescompetitive-programmingdata-structuresdivide-and-conquerdsugraphsimplementation
CF 2222E - Seek the Truth

We are interacting with a hidden transformation on integers in the range from 0 to $2^n - 1$. Behind the scenes there is a fixed bitmask $c$ and a hidden operation type $k in {1,2,3}$. Every time we insert a number $x$, the judge does not insert $x$ itself.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2222D - Permutation Construction

We are given an array a of n integers, which can be positive, negative, or zero. The task is to construct a permutation p of length n - a sequence containing all integers from 1 to n exactly once - such that the "beauty" of the permutation is maximized.

codeforcescompetitive-programmingconstructive-algorithmsdata-structuressortings
CF 2222B - Artistic Balance Tree

We are given an array of integers and a sequence of operations. Each operation consists of two conceptual parts: first, you can swap elements symmetrically around any chosen center in the array, effectively letting you reorder elements in a controlled way; second, you mark a…

codeforcescompetitive-programminggreedysortings
CF 2222C - Median Partition

We are given a sequence of positive integers of odd length. The task is to divide this sequence into contiguous subarrays, each of odd length, such that all these subarrays share the same median. Our goal is to maximize the number of subarrays in such a partition.

codeforcescompetitive-programmingdpmath
CF 2222A - A Wonderful Contest

We are asked to determine whether a programming contest is “wonderful” in the sense that every possible integer total score between 0 and 100 n can be achieved. The contest has n problems, and each problem is divided into ai subtasks.

codeforcescompetitive-programmingbrute-forcedpmath
CF 2219E - Weird Chessboard

We are asked to construct a configuration of pieces on an $n times n$ chessboard such that every cell is "good." A piece placed at $(i,j)$ attacks every cell $(x,y)$ where $x ge i$ and $y ge j$, excluding the cell itself.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 2219C - Coloring a Red Black Tree

We are given a tree with n nodes, where each node is initially colored either red or black according to a binary string. Red nodes are marked 1 and black nodes 0.

codeforcescompetitive-programmingdfs-and-similardpgreedymathprobabilitiestrees
CF 2219D - MEX Replacement on Tree

We are given a tree with n vertices rooted at vertex 1. Each vertex has a unique integer weight between 0 and n-1. For any vertex v, we define Sv as the set of weights along the path from the root to v, inclusive.

codeforcescompetitive-programmingdata-structuresimplementationmathtrees
CF 2219B2 - Unique Values (Hard version)

We are given an array of length $2n+1$ containing integers from $1$ to $n$. Every integer appears exactly twice, except one integer, which appears three times. Our task is to identify the positions of the integer that appears three times.

codeforcescompetitive-programmingbinary-searchbitmasksconstructive-algorithmsinteractive
CF 2219A - Grid L

We are given two types of tiles: unit-length segments (1×1 edges) and L-shaped pieces formed by joining two segments at a right angle.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsmathnumber-theory
CF 2219B1 - Unique Values (Easy version)

We are given an array of length $2n+1$. Every number lies in the range $1$ to $n$. The structure is highly constrained: all values appear exactly twice except for one special value that appears exactly three times.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsdivide-and-conquerinteractivemath