brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 105222H - GG and YY's Stone Game

We are given a pile of stones and two players who alternate turns, with GG moving first. On each move, a player removes either one or two stones from the pile. The player who cannot make a move loses.

codeforcescompetitive-programming
CF 105222G - Function Query

We are given a static array of integers. For each query, we are also given two numbers $a$ and $b$, which define a function on any value $x$: $$f(x) = (a oplus x) - b$$ where $oplus$ is bitwise XOR.

codeforcescompetitive-programming
CF 105222E - L-Covering Checker

We are given a grid where each cell contains a symbol describing how it participates in a tiling made of L-shaped triominoes. Each L-shape consists of a center cell marked C and three adjacent arms extending in the four cardinal directions, labeled U, D, L, and R.

codeforcescompetitive-programming
CF 105222B - Link Summon

We are given five types of spirits, indexed from 1 to 5, and we have a certain number of copies of each type. Each spirit of type i has a fixed intrinsic value i. A single operation, called a “summon”, chooses some subset of available spirits.

codeforcescompetitive-programming
CF 105222C - Black-White Cubic Lattice

We are given a 3D grid of cells with coordinates $(i, j, k)$. Each cell initially has a color, either black or white, and we are allowed to flip its color at a given cost.

codeforcescompetitive-programming
CF 105222A - Reverse Pairs Coloring

We are given a permutation of size $n$, and we look at every inversion pair in it. An inversion is a pair of positions $i < j$ where the value at $i$ is larger than the value at $j$.

codeforcescompetitive-programming
CF 105223N - Larger but smaller!

Codeforces 105223N: Larger but smaller!

codeforcescompetitive-programming
CF 105223M - Minimize Sum

Codeforces 105223M: Minimize Sum

codeforcescompetitive-programming
CF 105223L - Geoland

We are asked to decide whether we can place $n$ distinct lattice points in the plane and connect them in a cycle so that all edges have equal Euclidean length, the polygon is simple (no self-intersections), and no three consecutive vertices lie on a single straight line.

codeforcescompetitive-programming
IMO 1999 Problem 6

Substituting special values is the first constraint.

imomathematicsolympiad
CF 105223F - Fire Kings

Codeforces 105223F: Fire Kings

codeforcescompetitive-programming
CF 105223E - Lazy Fouad

Codeforces 105223E: Lazy Fouad

codeforcescompetitive-programming
CF 105223K - Water Filling

We are given a rooted tree where each node represents a one-liter tank. Water can be poured into any chosen tank, but the filling does not stay local.

codeforcescompetitive-programming
CF 105223J - Only Two

We are given an axis-aligned square and inside it several straight segments, each of which is either horizontal or vertical. The segments are strictly inside the square, but they may overlap or even coincide.

codeforcescompetitive-programming
CF 105223I - Fofo Loves Bitset

We are given several independent strings, and for each one we must decide whether it contains a specific pattern, the word “bitset”, as a contiguous block inside it.

codeforcescompetitive-programming
CF 105223H - Game with wife

We are given several independent test cases. Each test case describes a game state consisting of several piles of stones.

codeforcescompetitive-programming
CF 105223G - Subsubsequence

We are given an array that changes over time. After each update, we are asked to compute a global quantity built in two layers. First, take any non-empty subsequence of the current array.

codeforcescompetitive-programming
CF 105223D - Coconuting

We are given several test cases. In each test case, we receive an array of integers. Our task is to count how many pairs of positions $(i, j)$ with $i < j$ satisfy a very specific algebraic relationship between the values $ai$ and $aj$.

codeforcescompetitive-programming
CF 105223B - A Problem You Will Hate More Than Yourself

We start with an existing tree on $n$ vertices. We are allowed to add new vertices and connect them with edges, but we are not allowed to create cycles, so the final structure must still be a tree. After these additions, the resulting tree must satisfy two structural conditions.

codeforcescompetitive-programming
CF 105223C - Bit And Segment

We are given an array and for every position $i$, we want to count how many segments $[l, r]$ that include $i$ have a special property tied to bitwise AND.

codeforcescompetitive-programming
CF 105223A - Levi Is Sad

We are given a line of students, each with a fixed initial height. The school is unhappy with any student who is strictly shorter than both of their immediate neighbors. The first and last students are exempt because they only have one neighbor.

codeforcescompetitive-programming
CF 105224C - Leaf Partition

We are given a tree, and only some nodes matter as “items to distribute”: the leaves. Every leaf must be assigned to exactly one of K groups.

codeforcescompetitive-programming
CF 105224A - Trampolines

We are given a one-dimensional board of positions from 1 to n. Each position i contains a jump length t[i]. If a ball is dropped at position i, it repeatedly performs deterministic jumps: from i it moves to i + t[i], then from that new position j it moves to j + t[j], and so…

codeforcescompetitive-programming
CF 105224B - Yet Another Maximization Problem

We are maintaining an array that changes over time, and after each change we may be asked to compute an optimal score based on splitting the array into contiguous parts.

codeforcescompetitive-programming
CF 105227C - Card Constructions

We are given a number of cards and asked to repeatedly construct the tallest possible “card pyramid”, remove the cards used, and continue until no further pyramid can be built. The final answer is how many pyramids were constructed across all iterations.

codeforcescompetitive-programming
CF 105227A - LLPS

We are given a single string made of lowercase letters. From this string we may delete characters while preserving order, producing any subsequence.

codeforcescompetitive-programming
CF 105227F - k-Amazing Numbers

We are given an array and we want to understand how “stable” each value is across fixed-length windows. For a chosen window size $k$, we slide a segment of length $k$ across the array. A number is considered good for this $k$ if it appears in every single such segment.

codeforcescompetitive-programming
IMO 1999 Problem 5

A direct Euclidean angle chase in the original configuration quickly becomes entangled because four different circles interact in a non-symmetric way: the circumcircle $G$, two internally tangent circ…

imomathematicsolympiad
CF 105227E - Recursive Queries

Each query gives a segment of integers and asks how many numbers in that segment share a specific value under a transformation function g. The function g takes a number and repeatedly replaces it with the product of its digits until the value becomes a single digit.

codeforcescompetitive-programming
CF 105227D - Chat Order

We are simulating a dynamic chat sidebar that always shows recent conversations first. Every time Polycarp sends a message to a friend, that friend’s chat becomes the most recently active and is moved to the very top of the list.

codeforcescompetitive-programming
CF 105227B - Let's Watch Football

We are given a video of length c seconds. Each second of watching requires consuming a units of data, while the internet connection can download b units of data per second continuously.

codeforcescompetitive-programming
CF 105228G - The Mystery of the Sacred Triangle

We are given multiple independent queries. Each query describes a triangle in the plane using three points. A vertical light source shines from above, and every point of the triangle casts a vertical projection downwards onto the ground.

codeforcescompetitive-programming
CF 105228F - The Game Club

We are looking at a sequential game played by people sitting in a circle. Each player has a fixed “favorite number”. A single die with faces from 1 to m is rolled repeatedly, but the rolls are not globally shared.

codeforcescompetitive-programming
CF 105228C - Suffixes

We are given a fixed set of dictionary words, each very short, and then a large number of queries. Each query provides a word and a rank. For a query word, we compare it against every dictionary word using suffix matching.

codeforcescompetitive-programming
CF 105228B - Randy Ranges

We are given an array where each element is a large integer up to 10^18, and we need to support two operations. One operation updates a single position in the array.

codeforcescompetitive-programming
CF 105228E - Building Pigeon Houses

We are given a collection of pigeon species, where each species has a limited supply of pigeons available for purchase. The goal is to build as many identical pigeon houses as possible.

codeforcescompetitive-programming
CF 105228D - Frogo

We are given several independent scenarios. In each scenario there are $n$ steps, each with a height value, and a frog that moves from the leftmost step to the rightmost step. The frog can rearrange the steps in any order before starting its journey.

codeforcescompetitive-programming
CF 105228A - The Game

Two players stand on a tree, initially anchored at node 1. They take turns moving a token along edges, always stepping to a neighbor of the current node. Once a node has been visited, it is removed from consideration, so the token can never return to it.

codeforcescompetitive-programming
IMO 1999 Problem 4

The condition states that $n^{p-1}$ divides $(p-1)^n+1$, with $p$ prime and $n \le 2p$.

imomathematicsolympiad
CF 105229I - 六元组计数

Codeforces 105229I: 六元组计数

codeforcescompetitive-programming
CF 105229K - 时光

We are given a set of missions, each mission i has a cost of time Ai and a value Bi. A person has a total time budget M and can choose a subset of missions to complete, each at most once, in any order, as long as the total time spent does not exceed M.

codeforcescompetitive-programming
CF 105229M - 不共戴天

We are given a line of $n$ water lilies labeled from left to right. We need to design two independent directed systems of connections on these positions. The first system belongs to a frog.

codeforcescompetitive-programming
CF 105229L - 扩散模型

We are given a rooted tree where each node represents a state in a diffusion process. Starting from the root, a token moves downward until it reaches a leaf.

codeforcescompetitive-programming
CF 105229J - 极简合数序列

We are given several independent test cases. Each test case provides an array of positive integers. From this array we consider every contiguous segment and compute its sum.

codeforcescompetitive-programming
CF 105229H - 出金记录

We are observing a gacha system that produces a sequence of “gold intervals”. Each interval is the number of draws between two consecutive gold pulls, and that interval is a random variable whose distribution depends on a counter that evolves during the same interval.

codeforcescompetitive-programming
CF 105229G - 象棋大师

We are asked to count how many monotone paths exist on an $n times n$ grid from the bottom-left corner $(0,0)$ to the top-right corner $(n,n)$, where each move increases either the x-coordinate or the y-coordinate by exactly one.

codeforcescompetitive-programming
CF 105229F - 羁绊大师

Each hero comes with two labels, think of them as two “bond types”. Every bond type appears on at most two heroes in total. A bond becomes active only when both heroes that contain it are selected.

codeforcescompetitive-programming
CF 105229D - 咸鱼跑酷

We are given a line of positions, and at every position there are two possible “actions” available. Each action is either an addition of a fixed value or a multiplication by a fixed value.

codeforcescompetitive-programming
CF 105229E - 无线软件日

We are given a long sequence of letters, and we are allowed to freely rearrange any of them after “cutting” them out of the original text.

codeforcescompetitive-programming
CF 105229C - 无线基站最佳选址

We are given a set of points on the plane, and we must cover every point using exactly two geometric covering devices. One device is a circle and the other is a square.

codeforcescompetitive-programming
CF 105229A - 无线网络整点栅格统计

We are working on a grid of integer lattice points inside a rectangle from (0, 0) to (n, m). For every lattice point (a, b), we must count how many distinct geometric squares can be formed such that (a, b) is one of the four vertices and all four vertices lie inside the…

codeforcescompetitive-programming
CF 105229B - 异或和之和

We are given a tree where each node stores an integer weight. For any two nodes, we can look at the unique path between them and compute the bitwise XOR of all node weights along that path.

codeforcescompetitive-programming
CF 105230K - Treasures

We are given a rectangular grid where each cell represents either a wall, an empty passage, a trap, the starting position, or a cell containing a numeric amount of treasure. From the starting cell, movement is allowed in four directions.

codeforcescompetitive-programming
IMO 1999 Problem 3

The condition requires a set of marked squares such that every square of an $n\times n$ board is either marked or shares a side with a marked square.

imomathematicsolympiad
CF 105230J - Super Bishop

We are given a rectangular grid with $n$ rows and $m$ columns. A piece starts at the top-left cell and moves like a bishop, meaning it always travels diagonally.

codeforcescompetitive-programming
CF 105230I - Pizzas

We are given a set of ingredients, and some pairs of ingredients are known to taste the same. That relation is not just pairwise, it extends transitively, so if ingredient A matches B and B matches C, then A, B, and C all belong to the same flavor group.

codeforcescompetitive-programming
CF 105230F - Franklin is Back

Codeforces 105230F: Franklin is Back

codeforcescompetitive-programming
CF 105230G - Great Factors

We are maintaining an array where each element is a small positive integer, and we are interested only in its prime factor structure.

codeforcescompetitive-programming
CF 105230H - Mountains

We are given a one-dimensional path encoded as a string of + and -. We start at an implicit height of zero before processing the string. Each character moves the current height by exactly one unit: + increases height by one, - decreases it by one.

codeforcescompetitive-programming
CF 105230E - Great Product

We are given a single integer $n$, and we want to express it as a product of integers greater than 1. The twist is that among all possible factorizations, we are not optimizing for simplicity or minimal number of terms, but for the opposite: we want to maximize how many…

codeforcescompetitive-programming
CF 105230D - Divisor Sequence

We are given a list of integers, and for each one we repeatedly apply a transformation: replace the number with the sum of its proper divisors, meaning all divisors strictly smaller than the number itself.

codeforcescompetitive-programming
CF 105230A - Areas

Codeforces 105230A: Areas

codeforcescompetitive-programming
CF 105230C - Little Birthday Party

We are given a classroom with $n$ students, each independently assigned a birthday uniformly over 365 days. We are asked for the probability of a very specific configuration.

codeforcescompetitive-programming
CF 105230B - Card Game

Each of the 60 cards corresponds to a fixed pattern over the positive integers. A number appears on a card exactly when it satisfies a certain binary condition derived from that card’s index.

codeforcescompetitive-programming
IMO 1999 Problem 2

Let $S=\sum_{1\le i<j\le n} x_i x_j (x_i^2+x_j^2)$ and $T=\sum_{i=1}^n x_i$.

imomathematicsolympiad
IMO 1999 Problem 1

The condition says that for every pair of distinct points $A,B \in S$, the perpendicular bisector of segment $AB$ is a symmetry axis of the entire finite set $S$.

imomathematicsolympiad
CF 105231A - Maliang Learning Painting

Codeforces 105231A: Maliang Learning Painting

codeforcescompetitive-programming
IMO 1998 Problem 6

Substituting small values reveals structural rigidity.

imomathematicsolympiad
IMO 1998 Problem 5

The configuration centers on the intouch triangle of $ABC$.

imomathematicsolympiad
IMO 1998 Problem 4

The divisibility condition is $ab^{2}+b+7 \mid a^{2}b+a+b$.

imomathematicsolympiad
CF 105231B - Magic Leeks

We are given a one-dimensional field of leeks represented by an array. A worker starts at a fixed position and moves along this line for a fixed number of time steps. At every step, all leeks grow uniformly by the same amount.

codeforcescompetitive-programming
IMO 1998 Problem 3

For each prime exponent $a$ in $n=\prod p_i^{a_i}$ the ratio contributes a factor

imomathematicsolympiad
IMO 1998 Problem 2

For each contestant, the pattern of ratings by the $b$ judges can be encoded by a binary vector of length $b$, where $1$ represents a pass and $0$ represents a fail.

imomathematicsolympiad
IMO 1998 Problem 1

Placing $P$ at the origin is safe because the perpendicular bisector conditions $PA=PB$ and $PC=PD$ become $|a|=|b|$ and $|c|=|d|$.

imomathematicsolympiad
CF 105231L - Campus

We are given a weighted undirected graph representing a campus. Each node contains a number of tourists, and certain nodes are designated as gates. Each gate is only active during a specific time interval. Over time from 1 to T, the set of active gates changes.

codeforcescompetitive-programming
CF 105231K - Magic Tree

We are given a graph that is extremely simple in structure: a grid with 2 rows and $m$ columns. Each cell $(i, j)$ is a vertex, and edges exist only between orthogonally adjacent cells.

codeforcescompetitive-programming
CF 105231J - Magic Mahjong

We are given multiple independent hands of Mahjong, each consisting of 14 tiles encoded as a 28-character string. Each tile is written as a value plus a suit or honor marker, so every tile occupies exactly two characters in the input.

codeforcescompetitive-programming
CF 105231I - Neuvillette Circling

We are given a set of points in the plane, and we should think of every pair of points as being connected by a segment. Each such segment corresponds to one “enemy” that can appear at any position along that segment, but its exact location is not fixed in advance.

codeforcescompetitive-programming
CF 105231H - Convolution

We are given a large numeric grid, think of it as a matrix of values. We also fix the size of a smaller rectangular “filter” of size $k times l$.

codeforcescompetitive-programming
CF 105231G - Multiples of 5

We are given a very large integer written in base 11, but we never see it as a continuous string. Instead, the number is encoded as a sequence of blocks. Each block says “repeat digit d exactly k times”, and concatenating all blocks gives the full base-11 representation.

codeforcescompetitive-programming
CF 105231F - The Ropeways

We are given a tree of up to two hundred thousand nodes. Each edge is marked with a value 0 or 1, and over time these edge values can flip between broken and working. The structure of the tree itself never changes, only whether an edge is currently usable.

codeforcescompetitive-programming
CF 105231E - Magic Subsequence

We are given a sequence of positive integers and asked to construct two different subsets of indices such that the sum of values chosen by the first subset equals the sum of values chosen by the second subset.

codeforcescompetitive-programming
CF 105231D - Magic LCM

We are given a sequence of positive integers. We are allowed to repeatedly pick any two positions in the sequence and replace the pair using a deterministic transformation: one position becomes the gcd of the pair, the other becomes the lcm of the pair.

codeforcescompetitive-programming
CF 105231C - Liar

We are given a set of players, each of whom claims to own a certain integer value. However, these claims may or may not be true. The actual values assigned to all players must sum up to a fixed total $s$.

codeforcescompetitive-programming
IMO 1997 Problem 6

Testing the structure of partitions of $2^n$ into powers of $2$ for small $n$ shows that multiplicities alone do not determine any canonical pairing process.

imomathematicsolympiad
IMO 1997 Problem 5

The equation is

imomathematicsolympiad
CF 105242D - You Have Been Grid Squared

We are given a square grid of size $n times n$. The first row is fixed: it contains the numbers from 1 to $n$ in order. Every cell below is generated deterministically: each entry is the square of the number directly above it in the same column.

codeforcescompetitive-programming
IMO 1997 Problem 4

The condition states that for every index $i$, every symbol in $S={1,2,\dots,2n-1}$ must appear at least once in the union of row $i$ and column $i$.

imomathematicsolympiad
IMO 1997 Problem 3

The previous argument fails because it attempts to control prefix sums via a greedy choice that is not guaranteed to be feasible at every step, and it incorrectly infers global bounds from stepwise bo…

imomathematicsolympiad
CF 105242E - Replace with MEX

We are given a sequence of integers, and we are allowed to remove exactly one element from it. After removing that element, the remaining elements keep their original order, forming a shorter sequence. On this modified sequence, we look at all prefixes.

codeforcescompetitive-programming
IMO 1997 Problem 2

Substituting small configurations clarifies the failure of any approach relying on a relation between $\angle BAU$ and $\angle CAU$.

imomathematicsolympiad
IMO 1997 Problem 1

A black–white checkerboard coloring on $\mathbb{Z}^2$ can be encoded by the function $c(x,y)=(-1)^{x+y}$, where one color corresponds to $+1$ and the other to $-1$.

imomathematicsolympiad
IMO 1996 Problem 6

The sequence $(x_i)_{i=0}^n$ evolves by steps of fixed sizes $p$ or $-q$, with $p,q>0$, and starts and ends at $0$.

imomathematicsolympiad
CF 105242M - Taim and Zingers

We are given a number of candies, called Zingers, initially held by Kaito. Before any distribution happens, a character named Taim is allowed to secretly take up to k Zingers for himself.

codeforcescompetitive-programming
CF 105242A - Prefix GCD

We are given an array and allowed to perform a single operation at most once. The operation selects a contiguous segment, computes the mex of that segment, and then overwrites every element inside the segment with that mex value.

codeforcescompetitive-programming
CF 105239A - 1-Stable Sequence by Number

We are asked to enumerate sequences of length n where every element is a positive integer and neighboring elements differ by at most one.

codeforcescompetitive-programming
IMO 1996 Problem 5

The configuration consists of a convex hexagon $ABCDEF$ with three pairs of parallel sides: $AB \parallel DE$, $BD \parallel EF$, and $CD \parallel FA$.

imomathematicsolympiad
IMO 1996 Problem 4

Let

imomathematicsolympiad
CF 105239C - Colored Tree

We are given a tree where each node carries two attributes: a weight and a color. From this tree we want to select a subset of vertices with two simultaneous restrictions. First, no two chosen vertices may be adjacent in the tree, so the chosen set must be an independent set.

codeforcescompetitive-programming
CF 105236A - Самое короткое условие

We are given three integers $R$, $x$, and $y$. We consider all integer segments $[l, r]$ such that both endpoints lie between 1 and $R$. For each such segment, we look at how many numbers inside it are divisible by $y$.

codeforcescompetitive-programming