brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 105314B - Ahmad and Pairs Syndrome

We are given an array of integers. From this array, we conceptually form all pairwise differences between every ordered pair of distinct indices.

codeforcescompetitive-programming
CF 105310J - Cereal Grids III (Hard Version)

We are given a square grid of size $n times n$ and a multiset of exactly $k$ ones and $n^2 - k$ zeros. The task is to place all values into the grid. Once the grid is built, we read every row as a binary string and every column as a binary string.

codeforcescompetitive-programming
CF 105310I - Vines

We are maintaining a vertical structure of layers indexed from 0 at the top down to n at the bottom. Some layers may contain a “vine”, and each vine has a current integer length.

codeforcescompetitive-programming
CF 105310G - Cereal City

We are given a set of points inside an $n times n$ grid, and we need to connect all of them using a very unusual construction process that produces axis-aligned roads. Every road starts from the outer boundary of the grid and is drawn straight inward along a grid line.

codeforcescompetitive-programming
CF 105310F - Red Pandatrees

We are given an undirected tree and a target permutation of its nodes. The goal is to transform the tree, through a special repeated “shuffle” operation, into a final rooted tree that is a simple path and whose depth-first traversal from the root visits nodes exactly in…

codeforcescompetitive-programming
CF 105310E - math problem

We are given an array $a$ of length $n$, but it is not independent. There is another hidden array $b$ of the same length, and every value of $a$ is defined as a sum over certain multiples in $b$.

codeforcescompetitive-programming
IMO 1966 Problem 5

Let

imomathematicsolympiad
CF 105310A - Cereal Grids III (Easy Version)

We are asked to construct an $n times n$ binary grid containing exactly $k$ ones and the remaining cells zeros. The grid is judged by a quantity called Super Rank, which counts how many distinct row strings and column strings appear in the final matrix when you read rows left…

codeforcescompetitive-programming
CF 105310D - Range Flips

We are given two strings of equal length, and we want to transform the first string into the second using range operations.

codeforcescompetitive-programming
CF 105310B - Red Pandaships

We are given a circle of n red pandas, numbered in clockwise order. Some pairs of pandas are already connected by non-crossing chords.

codeforcescompetitive-programming
CF 105309I - Range Flips

We are given two strings of equal length, and we are allowed to modify the first string using operations that act on contiguous segments. Each operation chooses a segment and applies one of two fixed transformations to every character in that segment.

codeforcescompetitive-programming
CF 105309J - Red Pandatrees

We are given an unrooted tree on $n$ nodes and a target permutation of its nodes. The final goal is to transform the tree, through a sequence of global “re-rooting shuffles”, into a rooted line-shaped tree such that a DFS starting from the root visits nodes exactly in the…

codeforcescompetitive-programming
CF 105309G - Red Pandacakes

We are given a circle of pancake stores. Each store holds some number of pancakes, and all stores are arranged in a cycle so that moving past the last store wraps back to the first. Two players interact with this circle.

codeforcescompetitive-programming
CF 105309E - Red Pandaships

We are given several test cases. In each test case, there are $n$ red pandas arranged in a circle and $k$ initial pairs of pandas already connected by non-intersecting chords.

codeforcescompetitive-programming
CF 105309F - Yet Another Count the Pairs Satisfying a Condition Problem

We are given a permutation of length $n$, meaning every value from $1$ to $n$ appears exactly once in the array. Each index $i$ has a value $ai$, and we can think of the permutation as defining a one-to-one mapping between positions and values.

codeforcescompetitive-programming
CF 105309B - Simple Arrays

We are given an array where every element is either 0, 1, or 2. We are allowed to independently flip the sign of any elements. After choosing signs, we want to know whether it is possible to make the total sum of the array equal to zero.

codeforcescompetitive-programming
CF 105309C - Shiori Novella's 3D Showcase

The grid can be seen as a board of binary tiles. Each cell contains either a 0 or a 1, and we are allowed to flip a cell, turning 0 into 1 or 1 into 0. The goal is to modify the grid so that no two neighboring cells, horizontally or vertically, share the same value.

codeforcescompetitive-programming
CF 105309D - Cereal Grids III (Easy Version)

We are asked to construct an $n times n$ binary grid using exactly $k$ ones and $n^2 - k$ zeros. The only requirement on the grid is structural: when we look at all rows as binary strings and all columns as binary strings, the number of distinct rows plus the number of…

codeforcescompetitive-programming
CF 105307K - A Potion Shopping On This Wonderful World!

Each potion in this problem can be viewed as a subset of stat types among at most 14 possible stats. Buying a potion gives you all of its covered stats, and because the protagonist is “lucky”, every potion is guaranteed to succeed, so each chosen potion deterministically…

codeforcescompetitive-programming
CF 105307J - Rook Placement

We are maintaining a dynamic set of pawns on a very large chessboard. The board itself is too large to store explicitly, so the only meaningful information is which cells currently contain pawns.

codeforcescompetitive-programming
IMO 1966 Problem 4

The identity resembles a telescoping sum.

imomathematicsolympiad
CF 105307I - Lulu And The Magical Array

We are given an array of hidden integers. We cannot directly read the values, but we are allowed to query any pair of indices and receive the bitwise XOR of those two elements.

codeforcescompetitive-programming
CF 105307G - Ki Chang Jab Takkataen

We are given a sequence of grasshoppers positioned along a straight path. Each grasshopper appears at a specific distance from the start, and when the elephant reaches that position, the grasshopper is at some vertical height.

codeforcescompetitive-programming
CF 105307F - Portal Maintenance

We are given a connected system of planets linked by a tree of portals. Every portal connects two planets and has a cost that is paid whenever Isaac travels through it while his jammer is active.

codeforcescompetitive-programming
CF 105307E - Hidden Project

We are given a sequence of days from 1 to N. On each day, you normally earn a fixed income of a baht value a. However, you are allowed to optionally run special projects, and each project replaces your normal income during its active days.

codeforcescompetitive-programming
CF 105307D - Animal Circus

We are given several animal types, each type having a certain number of animals. On each day, one type is updated by adding or subtracting animals.

codeforcescompetitive-programming
CF 105307B - Emma and the Pixie dust

We are given a large set of distinct positive integers representing “cuteness levels”. From these numbers, Emma first selects exactly $N$ elements.

codeforcescompetitive-programming
CF 105307C - Chopsticks

We are given a collection of identical “pairs” of chopsticks, where each pair is characterized by a single integer length. From each pair we can treat the two chopsticks as two equal sides of a rectangle.

codeforcescompetitive-programming
CF 105297L - Night at Hazrat Sultan

We are maintaining a dynamic set of points on the plane. Initially we are given a collection of stars, each represented by integer coordinates. After that, we repeatedly add or remove stars.

codeforcescompetitive-programming
CF 105297J - Acarajé

We are given a list of potential customers, where each customer has a maximum price they are willing to pay for a product. If we set a price $P$, then exactly those customers with $pi ge P$ will buy the product, and each of them contributes $P$ to the revenue.

codeforcescompetitive-programming
CF 105297I - From Baikonur to Mars

We are given an array of non-negative integers, where each value represents the height of a mountain. The goal is to reduce every value to zero using as few operations as possible. Two operations are available, and both can be applied to any chosen subset of indices.

codeforcescompetitive-programming
IMO 1966 Problem 3

The problem concerns a regular tetrahedron with vertices $A,B,C,D$ and circumcenter $O$.

imomathematicsolympiad
CF 105297H - Traffic light

The task is to compute the earliest possible arrival time at a destination node in a graph where each edge behaves like a traffic-controlled corridor.

codeforcescompetitive-programming
CF 105297E - Energy crisis

We are given a connected undirected graph where nodes represent power plants and edges represent possible transmission routes. Each route has a cost that changes over time according to a quadratic function in time $t$, specifically $a t^2 + b t + c$.

codeforcescompetitive-programming
CF 105297G - Teleporting through Kazakhstan

We are given a sequence of points on a number line that must be visited in a fixed order. We start at position 0. At each step we move to the next required position in the list, but we are allowed to choose between two movement modes.

codeforcescompetitive-programming
CF 105297B - Chopping Down Trees

We are choosing a set of $M$ distinct integer positions from the range $[1, N]$. Each chosen position contains a tree of fixed height $H$.

codeforcescompetitive-programming
CF 105297D - A is for Apple

We are given a rectangular 3D box aligned with the coordinate axes, stretching from the origin to $(x, y, z)$. Inside this box, there is already one spherical apple placed somewhere in space. Its center is given as $(tx, ty, tz)$, and it has radius $r$.

codeforcescompetitive-programming
CF 105297C - Road Cycling

We are given a circular route with $n$ cycling stations. Each station has two values: the amount of energy you gain when stopping there, and the amount of energy required to travel from it to the next station in the cycle. A cyclist starts at a chosen station with zero energy.

codeforcescompetitive-programming
CF 105293E - Mr.Wow and Hidden Permutation

We are given a hidden permutation $p$ of length $n$, where $n equiv 2 pmod 4$. We never see the permutation directly. Instead, we can query any set of exactly $n/2$ distinct indices, and the judge returns the median value among the corresponding $p$-values.

codeforcescompetitive-programming
CF 105293F - Mr.Wow and Decoding

We are given a circular array of constraints, and we want to construct another array of nonnegative integers that satisfies them while minimizing the total sum.

codeforcescompetitive-programming
CF 105293C - Mr. Wow and Spells

We are given a row of monsters, each with a positive health value. A spell is an operation where we choose a number x, then scan monsters from left to right. The first monster whose current health is at least x gets reduced by x, and the spell stops immediately.

codeforcescompetitive-programming
CF 105293B - Mr. Wow and Dislikes

We are given an array of integers. The goal is to repeatedly apply an operation so that, at the end, every element in the array is non-positive. One operation works like this. We pick an index $i$.

codeforcescompetitive-programming
CF 105293D - Mr.Wow and Multiset

We start with a multiset containing the numbers from 1 to n. Each operation picks two currently present values x and y, removes both, and inserts their difference x − y. After exactly n − 1 such operations, only one number remains.

codeforcescompetitive-programming
IMO 1966 Problem 2

The condition mixes side lengths and tangents of angles.

imomathematicsolympiad
CF 105284J - Grid Product

We are given a grid of upper bounds, and we consider all integer grids of the same size where each cell is chosen independently within its allowed range. For each such choice of grid values, we compute a score formed from row sums and column sums.

codeforcescompetitive-programming
CF 105284K - The Astral Express

We are given a one-dimensional universe made of segments arranged in a line. Each segment has a value, initially either +1 or -1 depending on whether it lies in the left half or the right half of the array.

codeforcescompetitive-programming
CF 105284I - Flappy Deer

We are simulating a character that moves strictly from left to right on an infinite grid. Time advances in discrete steps, and at every step the x-coordinate increases by one, while the y-coordinate can change by at most one unit up or down.

codeforcescompetitive-programming
IMO 1966 Problem 1

Let

imomathematicsolympiad
CF 105284G - Ifrit Tile

We are given a tree with $n$ nodes. Each of $m$ colors corresponds to a fixed simple path in this tree, defined by two endpoints $si$ and $ti$. Think of each color as a group of tokens that would occupy every node on that path when active.

codeforcescompetitive-programming
CF 105284F - Stage 4

We start with a single integer value and process a sequence of operations. Each element in the permutation gives us a binary choice: either we add that number to the current value, or we flip a single bit of the current value using XOR with a power of two determined by the…

codeforcescompetitive-programming
CF 105284E - Waymo orzorzorz

Jason starts from an empty text and wants to end up with a text consisting of the string "orz" repeated at least $N$ times.

codeforcescompetitive-programming
CF 105284D - Kawaii the Rinbot

We are given a fixed external database that can be thought of as a long ordered list of anime titles, each sitting on a specific line number starting from 1.

codeforcescompetitive-programming
CF 105284B - Monkey Arrays

We are given an array and three distinguished values, $X$, $Y$, and $K$, with the ordering $Y < K < X$. For each test case, we need to count subarrays where two extremal conditions hold simultaneously: within the subarray, the maximum value must be exactly $X$, the minimum…

codeforcescompetitive-programming
CF 105284C - Monkey Math Tree

We are given a path graph with nodes numbered from 1 to n, where each node is connected to its immediate neighbors. Then each node i is independently kept with probability 1/i and removed with probability 1 − 1/i.

codeforcescompetitive-programming
CF 105283K - Waymo orzorzorz

We are building a text consisting of repeated copies of the string “orz”. The goal is to produce at least $N$ copies of this string in minimum time. At any moment, Jason has a current amount of text, and he can perform three actions.

codeforcescompetitive-programming
CF 105283J - Kawaii the Rinbot

We are given a fixed external text file that lists anime titles, one per line. Each title is unique and appears exactly once in that file.

codeforcescompetitive-programming
CF 105283I - Monkey Math Tree

We are given a path graph with nodes numbered from 1 to n, where each node i is independently kept with probability 1/i and removed otherwise.

codeforcescompetitive-programming
CF 105283G - Monkey Arrays

We are given an array and three special values, with a strict ordering $Y < K < X$. For each test case, the task is to count how many contiguous subarrays satisfy three simultaneous conditions: the maximum element in the subarray is exactly $X$, the minimum element is exactly…

codeforcescompetitive-programming
CF 105283F - XOR Game

We are given a binary grid and we want to travel from the top-left cell to the bottom-right cell, only moving right or down. The restriction is that every visited cell must contain a 1.

codeforcescompetitive-programming
CF 105283E - Minimize Sum

We are given an array of integers. One operation is allowed: pick any two elements, remove both, compute their bitwise XOR, and insert that result back into the array. This changes the array size by exactly minus one, since two elements are replaced by one.

codeforcescompetitive-programming
CF 105283C - Phonier

We are given an array, and each query asks about all ordered pairs of indices inside a segment. For a query segment $[l, r]$, we take every pair $(i, j)$ in that range, compute $ai + aj$, and then XOR all of those results together.

codeforcescompetitive-programming
CF 105283D - Parallel Arrays

We are given the numbers from 1 to 2n, and we must split them into two ordered lists a and b, each of length n, using every number exactly once.

codeforcescompetitive-programming
CF 105283B - Ifrit Tile 2

We are given a rectangular grid where each cell is one of three types. Some cells are valid high ground positions where we can place a unit, some are low ground cells where enemies stand, and some cells are blocked and irrelevant for placement.

codeforcescompetitive-programming
IMO 1965 Problem 6

The problem asks for an upper bound on the number of segments of maximal length among $n$ points in the plane.

imomathematicsolympiad
CF 105278M - grinch

We are given a tree with up to one million nodes. A token starts on some node, and two players alternately move it.

codeforcescompetitive-programming
CF 105278L - Strobogrammatic

We are given a single number written in hexadecimal, using digits 0 to 9 and letters A, b, C, d, E, F. The task is to modify this string into a strobogrammatic number, meaning that if we rotate the representation by 180 degrees, it should look identical again.

codeforcescompetitive-programming
CF 105278K - Baby Chaves

We are given a line of integers. In one move we pick two neighboring positions and transfer any amount of value between them: we add some integer $k$ to one side and subtract the same $k$ from the other side.

codeforcescompetitive-programming
CF 105278J - Gerrymandering

We are given a circular arrangement of voters, each voting for either J or L. We must cut this circle into exactly K consecutive segments, where the last segment wraps around to the beginning.

codeforcescompetitive-programming
CF 105278I - d-parkour

We are given a sequence of buildings, each with a distinct height. For any interval of buildings from index i to j, we consider two traversals: moving from left to right and moving from right to left.

codeforcescompetitive-programming
CF 105278G - Chocolate Volcano

We are given a polygonal “cake” whose upper boundary is defined by a polyline through $n$ points whose x-coordinates are strictly increasing.

codeforcescompetitive-programming
CF 105278F - Pacman or Shot

The grid represents a maze where two agents move over discrete time steps: Pacman and a ghost. Pacman starts at a fixed cell and then follows a predetermined sequence of moves consisting of up, down, left, and right commands.

codeforcescompetitive-programming
CF 105278E - Chaves and habibi arrays

We are given a permutation of length $N$, meaning all values are distinct. From this array we consider every contiguous subarray, and we want to count how many of those subarrays are “valid” according to a stack simulation rule.

codeforcescompetitive-programming
CF 105278D - Wise Splitting

We are given a list of money transfers between people, where each record says that one person paid on behalf of another, creating an implicit debt relationship. From these transactions we can compute how much each person ultimately owes or is owed.

codeforcescompetitive-programming
CF 105278B - Missing LDAP

We are given a person’s full name split into three or four words. The last two words are fixed surnames, while everything before them forms the given names. From this name, we must reconstruct a very specific sequence of candidate login identifiers called LDAPs.

codeforcescompetitive-programming
CF 105278A - Pacman and Russian Roulette

We are simulating a short sequence of moves on a toroidal 15 by 15 grid, where Pacman follows a fixed deterministic path while a hidden ghost moves randomly. Both start from the same uniformly random cell.

codeforcescompetitive-programming
IMO 1965 Problem 5

The previous attempt failed because it incorrectly assumed a simple affine relation between $M$ and the orthocenter $H$ of $\triangle OPQ$.

imomathematicsolympiad
CF 105276K - Keep Them Stacked

We are given three rectangular sheets, each with a fixed width and height, and we are allowed to place them on a plane without rotating them. The task is to arrange all three so that the total area of the region they occupy is as small as possible.

codeforcescompetitive-programming
CF 105276L - Lift Problem

There are $N$ lifts and $N$ special floors called waiting floors. The $i$-th waiting floor is fixed at height $10i - 5$, so these floors are evenly spaced and strictly ordered. Each lift initially sits on its own waiting floor: lift $i$ starts at floor $10i - 5$.

codeforcescompetitive-programming
CF 105276I - Ideal Cutting

We are given a convex polygon described by its vertices in counterclockwise order. The task is to cut this polygon into triangles using non-intersecting diagonals between vertices, exactly forming a triangulation.

codeforcescompetitive-programming
CF 105276H - Handful of Balls

We are given a triangular board of side length $N$. The board is not a rectangle but a triangle where row $k$ contains $k$ cells, aligned to the left, forming the familiar triangular grid structure.

codeforcescompetitive-programming
CF 105276F - Far-reaching Citations

Each published paper is constructed incrementally. Some papers are independent strings, while others are formed by taking an earlier paper and appending an extra string to its end.

codeforcescompetitive-programming
CF 105276G - GPT Intrusion

We are given a program as plain text, split into several lines. The task is to determine whether this program is “suspected to be written by GPT and exceeds its output limit.

codeforcescompetitive-programming
CF 105276E - Enthusiast of Algorithms

We are given several categories of algorithms, where each category contains a certain number of distinct algorithms. Over the next $K$ days, Bob will study exactly one category per day, and on that day he must learn exactly $M$ algorithms from that chosen category.

codeforcescompetitive-programming
CF 105276C - Cross Across the Grid

The grid can be thought of as a set of concentric square rings around the center cell. Because the size is odd, there is a single center and every other cell belongs to exactly one ring.

codeforcescompetitive-programming
CF 105276D - Decisive Duels

We are given a binary string where each character represents the outcome of a point in a badminton match simulation. A substring corresponds to a single match, and we scan it from left to right, updating a running score: 1 adds a point to David, 0 adds a point to the opponent.

codeforcescompetitive-programming
CF 105276A - Always Right

We are working on a grid maze where each cell is either a wall or a free space, and exactly one cell is marked as a start and one as an exit. The movement rules are not the usual four-directional steps.

codeforcescompetitive-programming
CF 105272A - Arc surveillance

We are given positions of occupied cells arranged around a circular prison with labels from 1 to 360. Because the structure is circular, cell 360 is adjacent to cell 1, so any contiguous surveillance interval may wrap around this boundary.

codeforcescompetitive-programming
IMO 1965 Problem 4

Let

imomathematicsolympiad
CF 105272J - Jupiter's Dinner

We are given a sequence of requests arranged in a line, where each position corresponds to a person who ordered a specific type of dish.

codeforcescompetitive-programming
CF 105272H - Honor to Saturn

We are given a linear sequence of asteroids, each colored either a or b. We are allowed to choose any contiguous segment of this sequence, remove it, and then glue its ends together to form a cycle.

codeforcescompetitive-programming
CF 105272G - Genealogy of aliens

We are looking at a population that evolves in perfectly rigid generations. The first generation starts with some number of individuals, call it $a$.

codeforcescompetitive-programming
CF 105272E - Excavating Mercury

The horizon of Mercury is described as a line of mountains, each position having a given height. We are allowed to perform only one type of operation: reduce the height of any mountain by removing material.

codeforcescompetitive-programming
IMO 1965 Problem 3

The plane $\varepsilon$ is parallel to both skew edges $AB$ and $CD$.

imomathematicsolympiad
CF 105272C - Cosmic candidates

We are given a group of $n$ people, where $n$ is divisible by 3, and these people are already partitioned into teams of exactly 3 members each. Each team will only agree to participate in a competition if at least two of its three members are convinced to go.

codeforcescompetitive-programming
CF 105272D - Dividing the solar pizzas

We are given an even number of friends, say 2n, and each friend has a single integer value representing a pizza flavor preference. The group wants to order exactly n pizzas, and each pizza must be made from two different friends’ preferences.

codeforcescompetitive-programming
CF 105271C - Trains 2

We are given a tree with vertices labeled from 1 to n. Each vertex acts like a train station, and moving along any edge between two stations costs exactly one ticket. The twist is that tickets are not globally fixed in price.

codeforcescompetitive-programming
IMO 1965 Problem 2

The coefficient matrix has positive diagonal entries and negative off-diagonal entries.

imomathematicsolympiad
IMO 1965 Problem 1

The expression involves $\sin 2x$ inside two square roots of complementary forms, suggesting the standard algebraic identity

imomathematicsolympiad
IMO 1964 Problem 6

The configuration is affine, involving a tetrahedron and three lines through the vertices of one face parallel to a fixed direction $DD_0$, where $D_0$ lies in the plane $ABC$.

imomathematicsolympiad
IMO 1964 Problem 5

Five given points determine ten straight lines joining them.

imomathematicsolympiad