brain

tamnd's digital brain — notes, problems, research

41230 notes

CF 104426G - GCD of Strings

We are given a long decimal string and asked to cut it into several contiguous pieces. Every character of the string must belong to exactly one piece, and each piece is interpreted as a non-negative integer (leading zeros are allowed and the number is not normalized).

codeforcescompetitive-programming
CF 104426E - Stacked Pearls

We are working with an $n times n$ grid where each cell can either be empty or contain a pearl with an integer size. The grid is updated through a sequence of operations, where each operation either places a pearl in a cell, replaces an existing one, or removes it.

codeforcescompetitive-programming
CF 104426F - The Lazy Author

We are given a binary array and a fixed window size. In one move, we choose any contiguous segment of exactly $k$ elements and flip every value inside it, turning zeros into ones and ones into zeros.

codeforcescompetitive-programming
CF 104426D - Bubble Sort !!?

We are given a permutation p of size n. From this permutation we construct a large list of permutations: we take every permutation of 1..n that is lexicographically greater than or equal to p, sort them in lexicographic order, and concatenate them into a single sequence A.

codeforcescompetitive-programming
CF 104426A - G Game

We are given an array of integers. Two players select disjoint subsets of indices from this array. Abdulrahman is allowed to pick up to $P$ indices, and Hazem is allowed to pick up to $Q$ indices.

codeforcescompetitive-programming
CF 104426B - Permutation Tree

We are given a tree with a designated root. The task is to assign a permutation of the vertices, meaning each vertex receives a unique integer from 1 to n, so that labels strictly increase along every root-to-leaf direction.

codeforcescompetitive-programming
CF 104426C - SYPUCPC Problemsetting

We are given several independent test cases. In each one, we start with an array of problem difficulties. We are allowed to delete any subset of these values, but we must leave at least one element behind.

codeforcescompetitive-programming
CF 104427K - Connect the Dots

We are given several test cases. In each test case, a sequence of points lies on a horizontal line, ordered from left to right. Each point has a color.

codeforcescompetitive-programming
CF 104427J - Cooperation Game

We are given a line of students, each student labeled by a class number. The process repeatedly removes two students of the same class, and each removal contributes the distance between their current positions in the line right before removal.

codeforcescompetitive-programming
CF 104427I - Visiting Friend

We are given a connected undirected simple graph representing a village, where intersections are nodes and roads are edges. For each query, two distinct nodes are fixed, one is the starting house A and the other is the destination house B.

codeforcescompetitive-programming
CF 104427H - Optimal Quadratic Function

We are given several independent test cases. In each test case, we observe a set of points on a plane, where each point has a fixed x-coordinate and an observed y-coordinate.

codeforcescompetitive-programming
CF 104427G - Make Everything White

We are given an $N times M$ board where each cell is either black or white. The task is to assign to every cell exactly one of three operations.

codeforcescompetitive-programming
CF 104427D - Lonely King

We are given a rooted tree where every vertex except the root has exactly one parent, so all edges naturally point away from vertex 1.

codeforcescompetitive-programming
CF 104427E - Treasure Box

We are given a string laid out on a number line, where each position contains a single uppercase letter. Turning this string into a palindrome requires changing some characters so that position i matches position N−i+1 for all i.

codeforcescompetitive-programming
CF 104427F - Beautiful Sequence

We are given an array of integers, and we are allowed to freely permute its elements. After choosing an ordering, we assign a “beauty score” to the resulting sequence by counting how many positions are locally good in a weak sense: an index contributes if its value is not…

codeforcescompetitive-programming
CF 104427A - Reversing

We are given a grid of size $N times M$ where each cell is either black or white. The grid we see is not necessarily the original configuration. Instead, the grid may have been transformed by a special operation applied multiple times.

codeforcescompetitive-programming
CF 104427C - One, Two, Three

We are given a long sequence made only of the values 1, 2, and 3. From this sequence, we want to extract as many disjoint triples of indices as possible, where each triple uses three different positions and respects the order of indices.

codeforcescompetitive-programming
CF 104427B - Lawyers

We are given a directed relationship between lawyers. Each relationship says that one lawyer trusts another, and this trust has a very specific operational meaning: if lawyer B trusts lawyer A, then A provides a defense for B.

codeforcescompetitive-programming
CF 104432F - Amir and Tree

We are given an undirected tree with $n$ vertices. We are allowed to choose a root, but with the restriction that the root cannot be a leaf. Once a root is fixed, every vertex $v$ has a value $f(v)$ defined recursively from the leaves upward.

codeforcescompetitive-programming
CF 104432E - Army Value

We are counting how many ways to choose three integers, one for each army type, such that each chosen value lies inside its own interval, and the XOR of all three chosen values has a special property. More concretely, we pick values $a1, a2, a3$, where $ai in [li, ri]$.

codeforcescompetitive-programming
CF 104432D - Max Co Matches

We are given a line of players, each sitting in a fixed seat from left to right, and each player has a rating value.

codeforcescompetitive-programming
CF 104432A - Easy Peasy

We are given several independent test cases. In each one, there is a list of positive integers. We are allowed to insert exactly one additional integer into this list.

codeforcescompetitive-programming
CF 104432C - Odd Subbarray

We are given an integer array and asked to count how many contiguous subarrays have a special property: if you multiply all elements inside the subarray, the resulting product has an odd number of divisors.

codeforcescompetitive-programming
CF 104432B - Letters Game

We are given a sequence of letters, where each letter is already assigned to a destination company. At the same time, we also have envelopes, and each envelope has a fixed company written on it, matching the same sequence structure.

codeforcescompetitive-programming
CF 104447M - Is it possible?

We start with a coin at coordinate (0, 0) on an infinite integer grid. Time progresses in discrete steps starting from 1. At each step i, we choose any integer xi, and then the coin moves in a constrained way depending on whether the step is odd or even.

codeforcescompetitive-programming
CF 104447L - Amazing Teacher

We are given a sequence of independent test cases. Each test case contains a single integer representing a student's original score on a 0 to 10 scale.

codeforcescompetitive-programming
CF 104443E - Cringemeter

We are given several independent strings, and for each string we must compute a single integer value that depends on the structure of how letters appear in sequence.

codeforcescompetitive-programming
CF 104443C - Morco-Feely Palindromes

We are given a single string consisting only of digits, with length at most 100. The task is to decide whether this string satisfies a very specific symmetry condition and output a simple yes or no verdict.

codeforcescompetitive-programming
CF 104435M - TheBuzz

We are given two complete descriptions of relationships among the same set of organizations, but the organizations are named in one description and numbered in the other.

codeforcescompetitive-programming
CF 104435L - Starquake!

We are given a one-dimensional landscape, where each position stores an integer height. From this array, we define connectivity not by adjacency alone, but by a height constraint: two neighboring positions can be traversed only if their heights differ by at most one.

codeforcescompetitive-programming
CF 104435J - Sensor Logs

We are given a building with four rooms labeled A, B, C, and D, connected by exactly three corridors. Each corridor is a physical passage between two rooms, and every time a person moves through a corridor from one room to the other, a log entry is recorded as a pair…

codeforcescompetitive-programming
CF 104435K - Star Seeker's Socks

We are given a collection of sock types, where each type contains a number of identical socks grouped in pairs. Type i contributes exactly 2·k[i] individual socks, all indistinguishable within that type.

codeforcescompetitive-programming
CF 104435I - Ominous Acids

We are working with shapes formed on an infinite grid using exactly $k$ unit squares. Each shape must be connected through edge-adjacency, meaning we can move between squares only if they share a full side.

codeforcescompetitive-programming
CF 104435H - Not Just an NP-Hard Problem

We are given several sticks, each with an integer length, and we must organize them into a geometric construction that ultimately produces a triangle-like shelter.

codeforcescompetitive-programming
CF 104435E - Euclidean Travel with Parallel Universes

The geometry starts from a fixed parallelogram described by two generating vectors. If we denote the origin as point A, then any point inside the shape can be uniquely written using two parameters along those vectors.

codeforcescompetitive-programming
CF 104435G - Irreversible Events

We are given a directed graph where vertices represent events and directed edges represent allowed time transitions. From an event A, we can reach event B if there is a directed path from A to B.

codeforcescompetitive-programming
CF 104435B - Cult of Wah!

Each test case contains two collections of lowercase words. The first collection is the Wah-List, which contains every word that must appear after the encrypted message has been decoded. The second collection is the encrypted message itself.

codeforcescompetitive-programming
CF 104435A - Alien Gordon Ramsey

We are given an undirected tree, meaning a connected graph with $n$ nodes and exactly $n-1$ edges. Each node represents a restaurant, and each restaurant must be assigned a positive integer label representing a “theme”. The assignment must satisfy two constraints.

codeforcescompetitive-programming
CF 104435D - Eliens Slurs

We are given a long array representing a tweet, where each element is an integer from 1 to 300. We are also given a shorter pattern array called the slur.

codeforcescompetitive-programming
CF 104435F - Flow Maximal

We are given an integer $b$. We consider all integer solutions $(a, c)$ such that $a^2 + b^2 = c^2$ and $0 le a le c$. Each solution corresponds to a circular necklace of $c$ beads, each bead being either “red” (Andromedal) or “blue”.

codeforcescompetitive-programming
CF 104435C - Dethrone Antares Now

We are given an undirected graph of planets connected by bidirectional teleporters. Each teleporter allows instant movement between two planets, and it is the only way to travel. Several commanders start on distinct planets.

codeforcescompetitive-programming
CF 1044394 - Задача из ЕГЭ

We are given three powers of two, determined by exponents $a$, $b$, and $c$, and we form the integer $$x = 2^a + 2^b - 2^c.$$ The value is guaranteed to be positive, and the exponents $a$ and $b$ are different.

codeforcescompetitive-programming
CF 1044395 - Бизнесмен Василий

We are given a sequence of integers that represent financial transactions recorded over time. We must split this sequence into exactly three contiguous, non-empty parts. Each part corresponds to a “month” in which we sum all values inside that segment.

codeforcescompetitive-programming
CF 1044392 - Ёлочки

The picture contains a single tree drawn on square cells. The trunk is always one cell wide and runs vertically through the whole tree. The tree has beauty n, which means there are exactly n branches on each side of the trunk.

codeforcescompetitive-programming
CF 1044391 - Пятистенок

We are given three lengths. Two of them describe the lengths of logs used in construction: one type of log has length a and another has length b, with a < b. The third number c is the total length of a single wooden beam that must be cut into pieces.

codeforcescompetitive-programming
CF 1044393 - Соревнование делимости

We are given a segment of consecutive integers from $A$ to $B$, inclusive. Two people are counting inside this segment with different rules: one counts how many numbers are divisible by $K$, the other counts how many numbers are divisible by $M$.

codeforcescompetitive-programming
CF 1044405 - Долгое вычитание

We are given a large integer written on a board. A sequence of operations is applied until the number becomes zero. Each operation depends entirely on the digits currently present in the number.

codeforcescompetitive-programming
CF 1044404 - Жребий Крижановского

We are given a sequence of numbers representing what each participant announces in a game. The goal is to identify numbers that appear exactly once in the entire sequence. Among those uniquely occurring numbers, we select the smallest value and output it as the winner.

codeforcescompetitive-programming
CF 1044402 - Прогрессия

Three numbers remain on the board, in their original order, after one element was erased from an arithmetic progression of four integers. We must restore the missing number and also report where it belongs so that the four resulting numbers form an arithmetic progression.

codeforcescompetitive-programming
CF 1044401 - Том Сойер

We are given three types of tickets: yellow, red, and blue. These tickets can be converted upward in a strict hierarchy. Ten blue tickets can be exchanged into one red ticket, and ten red tickets can be exchanged into one yellow ticket.

codeforcescompetitive-programming
CF 1044403 - Расклейка афиш

We are given a street with houses numbered from 1 to n. A character walks along the street twice, placing posters on houses according to divisibility rules. On the first pass, every house whose index is divisible by a is selected.

codeforcescompetitive-programming
CF 1044414 - Claims Processing

We are given a line of claims stacked from top to bottom, numbered by their original positions. The boss repeatedly processes the pile in fixed groups of three actions.

codeforcescompetitive-programming
CF 1044415 - Beware, Evil Numbers!

We are asked to count integers in the range from 1 to n that satisfy two conditions at the same time. First, the number must be even. Second, when we write that number in binary, the number of set bits, meaning the number of ones in its binary representation, must also be even.

codeforcescompetitive-programming
CF 1044412 - Switching TV-Channels

We are working with a linear sequence of TV channels labeled from 1 to N. Lisa starts on some channel P and wants to reach another channel U using a remote control with two buttons. Each button has two behaviors depending on how it is pressed.

codeforcescompetitive-programming
CF 1044413 - Treasure Hunter

We are given a straight horizontal road modeled as the x-axis. Timofey places a metal detector at two different positions on this line. First he stands at the origin and sets the detector range to a value r₁, then he moves to position x = a and sets the range to r₂.

codeforcescompetitive-programming
CF 1044411 - Long training

The task is to compute the total duration of a training session that is composed of repeated work blocks separated by rest periods. Each training session consists of $N$ identical sets. One set takes a fixed amount of time given in minutes and seconds.

codeforcescompetitive-programming
CF 104442K - P = NP

We are working in a machine model where all arithmetic is performed using 32-bit unsigned integers. That means every result is reduced modulo $2^{32}$ whenever it exceeds the representable range.

codeforcescompetitive-programming
CF 104442J - Aviones

The grid describes a black-and-white image where most cells are background and the remaining cells belong to an airplane. Every airplane cell is labeled with a digit from 0 to 9, and all cells sharing the same digit form a single “zone type”.

codeforcescompetitive-programming
CF 104442I - Cálculo numérico

We are given several independent scenarios on a 2D integer plane. In each scenario, a robot starts at a coordinate $I = (x1, y1)$ and must reach a target coordinate $F = (x2, y2)$.

codeforcescompetitive-programming
CF 104442G - El jardín del Edén

We are given a binary cellular automaton of fixed length. Each configuration is a row of C cells, where each cell is either 0 or 1.

codeforcescompetitive-programming
CF 104442H - El máximo de diversión

We are given several independent sequences of points in the plane, where each sequence describes a fixed route that must be followed in order. Each route is a list of coordinates $(x1, y1), (x2, y2), dots, (xn, yn)$, and we only care about movements between consecutive points.

codeforcescompetitive-programming
CF 104442E - Obras de ingeniería

We are given several independent test cases. Each test case describes a sequence of building heights along a one-way street. The city wants to transform this sequence so that as we move from left to right, the heights never decrease.

codeforcescompetitive-programming
CF 104442F - Fechas de entrenamiento

The statement you pasted is truncated, so there isn’t enough information to reconstruct the actual problem. Right now we only see the title “Fechas de entrenamiento” and empty Input/Output sections.

codeforcescompetitive-programming
CF 104442D - El abeXORro

We are given several independent test cases. In each one, there is an array of values placed on nodes, which we can think of as flowers carrying some amount of pollen.

codeforcescompetitive-programming
CF 104442C - Crimen en Villacepé

We are given a graph on $n$ people. Each input edge between two people means there was some declaration between them, but the content of the declaration has been lost.

codeforcescompetitive-programming
CF 104442B - IKERobot

We are given a robot moving on an infinite integer grid. It starts at a given coordinate and must reach a target coordinate while avoiding a set of blocked grid points that cannot be stepped on.

codeforcescompetitive-programming
CF 104442A - El bruxeador

We are given an array of weights, and we must split these values into exactly $k$ non-empty groups, where each weight belongs to exactly one group. For any group, its cost is defined as the difference between the largest and smallest value inside that group.

codeforcescompetitive-programming
CF 104443G - Qpert pg yep

The task gives a single integer $m$ and asks us to compute a derived value that depends only on this number. Although the statement text is heavily corrupted, the samples define the entire behavior: for $m = 1$ the answer is $1$, for $m = 2$ the answer is $2$, and for $m = 5$…

codeforcescompetitive-programming
CF 104443H - Random Generator

We are given a single line of input consisting of an arbitrary string. The task is to output one integer derived from this string. No further constraints, rules, or transformations are specified in the visible statement.

codeforcescompetitive-programming
CF 104443F - Rt Dg

We are given an undirected structure with $n$ nodes described by $n-1$ edges, which guarantees the structure is a tree.

codeforcescompetitive-programming
CF 104443D - Missing Characters

The input to this problem is deliberately uninformative: it is always the same fixed string, and it does not influence the answer in any meaningful way.

codeforcescompetitive-programming
CF 104443A - TheForces

The task reduces to reading a single line of text from standard input and producing a fixed response regardless of what that line contains. The input is not interpreted as data with structure or meaning, it is only present to mimic a typical interactive or textual problem format.

codeforcescompetitive-programming
CF 104443B - Smaller than 100

The task is intentionally degenerate. You are given a single fixed input string, and no matter how it is read or processed, the only requirement is to output one integer. There is no variability in the input content across test cases.

codeforcescompetitive-programming
CF 104447K - Do you believe that this is a real story?

We are given a circle of n cards labeled from 1 to n. Initially every card is black. We are allowed to perform a sequence of operations, and each operation permanently paints one black card red.

codeforcescompetitive-programming
CF 104447J - How Kifah sees Extreme?

We are given an array of integers, and we are allowed to repeatedly modify individual elements using bit-level operations. In one operation, we pick a single element and either turn off one set bit in its binary representation or turn on two bits that are currently zero.

codeforcescompetitive-programming
CF 104447I - Will you accept Basharo challenge?

We are given a tree with n vertices. Each vertex has a label called its color, and every edge connects two vertices in a unique way since the graph is a tree. For any two vertices u and v, there is a unique simple path between them.

codeforcescompetitive-programming
CF 104447H - Do you love HIAST?

We are given a polygon drawn on a grid, but unlike arbitrary polygons it has a strong structure: every edge is either perfectly horizontal or perfectly vertical, and the vertices are listed in clockwise order.

codeforcescompetitive-programming
CF 104447G - What is Kaito's delimma?

We are given multiple independent test cases. In each test case, there is a list of integers representing Kaito’s friends, and a target value x.

codeforcescompetitive-programming
CF 104447F - Isn't it a hard problem?

We are given multiple test cases. In each test case there is an array of strings, each string carrying a value. Alongside, we are allowed a limited budget of character edits, where one edit changes a single character in any string to any other character.

codeforcescompetitive-programming
CF 104447E - What Does Geo Do In His Free Time

We are simulating a process on a set of $n$ identical dice, each die independently showing a uniformly random face from $1$ to $k$ every time it is rolled. The game proceeds in rounds.

codeforcescompetitive-programming
CF 104447D - Could you help the judges?

We are given an array of integers where each value is at most 1023, so every number fits in 10 bits. The judges are interested in the strongest possible contiguous segment in terms of XOR, where “strongest” means the maximum possible XOR over any subarray.

codeforcescompetitive-programming
CF 104447C - What Happens To Bashar's Laptop?

We are given a rooted folder system that starts as a fixed tree with nodes labeled from 1 to n, where folder 1 is the root. Each folder contains a list of child folders, so the input defines a directed tree structure over these initial nodes.

codeforcescompetitive-programming
CF 104447B - How Aswad Use Telegram?

We are given a chronological log of messages in a group chat. Each message has a sender and a timestamp. One particular participant, Aswad, follows a fixed reaction rule: whenever a message appears, he starts a waiting timer of length k minutes.

codeforcescompetitive-programming
CF 104447A - Is It A Math Problem?

We are given a single integer $n$. From this number, we first consider all its positive divisors. If $n = 10$, the divisors are $1, 2, 5, 10$. The problem defines a special value built from these divisors: take their product.

codeforcescompetitive-programming
CF 104508G - Grouping Problem

We are given a set of people sitting on a number line, each with a fixed coordinate. If we decide to keep a subset of these people together in one “group”, the cost of that group depends on the spread of their positions.

codeforcescompetitive-programming
CF 104508A - Area in Convex

We are given the vertices of a convex polygon in order along its boundary, and the task is to compute its geometric area. The input describes a closed shape where every consecutive pair of points forms an edge, and the last point connects back to the first.

codeforcescompetitive-programming
CF 104451C - Строчки

I can’t write a correct full editorial for Codeforces 104451C - “Строчки” yet because the problem statement is missing from your prompt.

codeforcescompetitive-programming
CF 104451G - Разрезы

We are given an array of integers. Over time, we are allowed to place or remove “cuts” between adjacent positions. A cut splits the array into segments, and segments are never allowed to cross a cut. So at any moment, the array is partitioned into several contiguous blocks.

codeforcescompetitive-programming
CF 104451D - Красивые числа

We are given a number written as a string, and we are told it already satisfies a strict structural rule. The digits alternate between two fixed values depending on position parity: all digits in positions 1, 3, 5, and so on are identical, and all digits in positions 2, 4, 6…

codeforcescompetitive-programming
CF 104451F - Вода в лабиринте

I can’t write a correct editorial for this problem as-is because the actual statement is missing from your prompt. Right now we only have the title “Вода в лабиринте” (“Water in a maze”), but that’s not enough to reconstruct the exact mechanics.

codeforcescompetitive-programming
CF 104451E - Первый, второй...

I can’t write a correct editorial for Codeforces 104451E without the actual problem statement. Right now the prompt only includes the title and metadata, but no description of the task, input format, or output requirements.

codeforcescompetitive-programming
CF 104451A - Алхихимия

We are given three initial masses representing ingredients in a cauldron: dried nettle, frog legs, and cinnamon. After all of them are added, a single gram of a special reagent is poured in.

codeforcescompetitive-programming
CF 104451B - Обслуживание

We are given an array of distinct integers, and we are allowed to pick exactly one contiguous segment and reverse it.

codeforcescompetitive-programming
CF 104452N - Contest with bug

We are given a fixed contest duration measured in minutes and a small collection of problems, each requiring a known amount of time to solve.

codeforcescompetitive-programming
CF 104452M - Beautiful hockey

Each hockey game consists of $n$ independent periods. In every period, the scoreboard shows one of four possible outcomes: neither team scores, the first team scores once, the second team scores once, or both teams score once.

codeforcescompetitive-programming
CF 104452L - Cipher

We are given a string whose length is a power of two, say $2^n$, and it is known to be the result of repeatedly applying a very structured transformation. The transformation works in rounds. In the first round, the entire string is reversed.

codeforcescompetitive-programming
CF 104452I - Pharaoh hEx

Each test case is: - N - array a of size N - K - then K query values So the structure is strictly: There is no ambiguity, no hidden grouping, no multiple test cases.

codeforcescompetitive-programming
CF 104452J - Connect and Disconnect 1

The system we are asked to design is a small flow network made from two types of components. Each component receives some incoming flow and either splits it evenly or combines multiple incoming flows into one outgoing flow.

codeforcescompetitive-programming
CF 104452K - Divide and Connect 2

We are given a directed network of devices that manipulate a single continuous flow of items. The system is a rooted structure: a single input flow enters device 1, and the flow is then transformed and routed through a collection of intermediate components until it finally…

codeforcescompetitive-programming
CF 104452H - Chess knight on the curb stone

We are given a chessboard of size $n times m$, where the central rectangle of size $(n-4)times(m-4)$ is removed. What remains is a border strip of width 2 cells all around the outside. The knight starts at the top-left corner cell $(1,1)$.

codeforcescompetitive-programming