brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105242G - Lexicographically Maximum

We are given a string of lowercase English letters. We are allowed to perform an operation any number of times, where each operation picks a contiguous substring and compresses it into a single repeated letter determined by how many distinct characters were inside that substring.

codeforcescompetitive-programming
CF 105242F - Queries on Distincts

We are given a string of lowercase English letters and many queries, each query focusing on a substring defined by indices $l$ and $r$. For each such range, we first look at which distinct characters appear inside it. Suppose the substring $s[l..

codeforcescompetitive-programming
CF 105242B - Tree Tour

We are given a string made of lowercase English letters and a large number of queries, each query specifying a segment of this string. For each segment, we are allowed to choose two positions inside it and swap their characters exactly once.

codeforcescompetitive-programming
IMO 1995 Problem 2

The corrected target inequality is equivalent to proving a lower bound for a cyclic sum of fractions with denominators $a^3(b+c)$.

imomathematicsolympiad
IMO 1994 Problem 4

The condition is

imomathematicsolympiad
IMO 1995 Problem 1

Let $A,B,C,D$ be distinct collinear points in this order.

imomathematicsolympiad
IMO 1994 Problem 3

The previous argument fails because it treats binary “blocks” inside $k$ as if they evolve independently under both the inequality $k<n\le 2k$ and the structure of numbers with three ones.

imomathematicsolympiad
IMO 1994 Problem 2

Place the isosceles triangle $ABC$ with $AB=AC$ so that $A$ is symmetric above the midpoint of $BC$, and interpret $M$ as the midpoint of $BC$.

imomathematicsolympiad
IMO 1994 Problem 1

Small cases suggest that whenever two selected elements are both “far from the top”, their sum, if it stays within ${1,\dots,n}$, must also be selected, which tends to force new larger elements into t…

imomathematicsolympiad
IMO 1993 Problem 6

A configuration of lamps can be encoded as a vector $x(t) = (x_0(t), \ldots, x_{n-1}(t)) \in \mathbb{F}_2^n$, where $x_i(t)=1$ means $L_i$ is on at time $t$ and $0$ means off.

imomathematicsolympiad
IMO 1993 Problem 5

The functional equation $f(f(n)) = f(n) + n$ forces a strong coupling between values at $n$ and at $f(n)$.

imomathematicsolympiad
IMO 1993 Problem 4

The expression $m(PQR)$ is a geometric quantity defined as the minimum of the three altitudes of triangle $PQR$.

imomathematicsolympiad
IMO 1993 Problem 3

A move replaces two adjacent orthogonally neighboring pieces and one piece two steps away in the same row or column by removing the middle piece and relocating the jumping piece.

imomathematicsolympiad
IMO 1993 Problem 2

The two conditions suggest a strong metric and angle rigidity.

imomathematicsolympiad
IMO 1993 Problem 1

The polynomial $f(x)=x^n+5x^{n-1}+3$ has integer coefficients and leading coefficient $1$.

imomathematicsolympiad
IMO 1992 Problem 6

The quantity $S(n)$ measures how far one can guarantee representations of $n^2$ as sums of positive squares once representations exist up to some length.

imomathematicsolympiad
IMO 1992 Problem 5

Let $S \subset \mathbb{R}^3$ be finite, and write each point as $(x,y,z)$.

imomathematicsolympiad
IMO 1992 Problem 4

The circle $C$ is tangent to a fixed line $l$ at $M$, so the radius $OM$ is perpendicular to $l$, where $O$ denotes the center of $C$.

imomathematicsolympiad
IMO 1992 Problem 3

A direct search for the maximum number of colored edges reduces the problem to maximizing $e(R)+e(B)$ over two edge-disjoint triangle-free graphs $R$ and $B$ on $K_9$.

imomathematicsolympiad
IMO 1992 Problem 2

Substituting $y=0$ transforms the equation into $f(x^2+f(0)) = (f(x))^2$.

imomathematicsolympiad
IMO 1992 Problem 1

The original reduction to

imomathematicsolympiad
IMO 1991 Problem 6

The condition requires a uniform lower bound on pairwise differences after rescaling by a polynomial factor in the index gap.

imomathematicsolympiad
IMO 1991 Problem 5

Let $ABC$ be a triangle with an interior point $P$.

imomathematicsolympiad
IMO 1991 Problem 4

The earlier attempt failed because it tried to control gcd conditions via prime avoidance without a stable invariant.

imomathematicsolympiad
IMO 1991 Problem 3

The problem asks for the smallest integer $n$ such that every $n$-element subset of $S={1,2,\dots,280}$ contains five integers that are pairwise coprime.

imomathematicsolympiad
IMO 1991 Problem 2

Let $a_1<a_2<\cdots<a_k$ be all positive integers less than $n$ that are coprime to $n$.

imomathematicsolympiad
IMO 1991 Problem 1

The earlier failure comes from an incorrect algebraic detour: introducing a complicated symmetric rational function that is not actually the natural simplification of the geometric ratio.

imomathematicsolympiad
IMO 1990 Problem 6

The earlier approach fails because cyclicity was incorrectly used as a substitute for equal angles.

imomathematicsolympiad
IMO 1990 Problem 5

The game is defined on positive integers with two alternating moves.

imomathematicsolympiad
IMO 1990 Problem 4

The functional equation is

imomathematicsolympiad
IMO 1990 Problem 3

Checking small values gives $n=2,3,4,5$ producing $\frac{5}{4},1,\frac{17}{16},\frac{33}{25}$, so only $n=3$ works in this range.

imomathematicsolympiad
IMO 1990 Problem 2

The structure is circular and symmetric, so the key parameter is the number of points on each arc between chosen black points.

imomathematicsolympiad
CF 105244C - Space Expedition

A space explorer visits a fixed sequence of celestial objects. Each object offers some scientific value if studied, but also consumes two limited resources: energy and time.

codeforcescompetitive-programming
IMO 1990 Problem 1

The configuration contains two independent cyclic structures sharing the point $E$.

imomathematicsolympiad
IMO 1989 Problem 6

Write $A_i={i,i+n}$ for $1\le i\le n$.

imomathematicsolympiad
IMO 1989 Problem 4

Direct substitutions collapse the problem to a single relation:

imomathematicsolympiad
CF 105244I - Sum of Path Lengths

The input describes a tree with vertices numbered from 1 to n. Every vertex except the first has exactly one parent given, which implicitly defines an undirected edge between each node i and its parent pi.

codeforcescompetitive-programming
IMO 1989 Problem 3

The condition imposes a strong local symmetry constraint: every point $P$ in a finite planar set $S$ has at least $k$ other points at the same distance from it.

imomathematicsolympiad
CF 105244H - Subsequence With Specified Differences

We are given a sequence of distinct integers, and we want to extract a subsequence that is strictly increasing. On top of the usual increasing constraint, there is an additional rule that restricts how consecutive elements in the subsequence can differ: if two consecutive…

codeforcescompetitive-programming
CF 105244G - Evolutionary Tree Weights

We are given several small evolutionary scenarios, each describing a rooted tree of species and a partial mapping between some leaves and known genome strings. Every genome string has the same length and consists of four possible nucleotides.

codeforcescompetitive-programming
CF 105244F - Lottery

We are given a starting lottery ticket of length $n$. Every position initially contains the number 1. For each position $i$, there is a required target value $bi$. If we manage to make the $i$-th position equal to $bi$, we earn $ci$ coins.

codeforcescompetitive-programming
CF 105244E - Petya and Dice

We start with a row of n dice, each die showing a single lowercase letter. So at any moment the whole configuration is just a string of length n. The goal is to transform an initial string into a fixed target string using exactly m moves.

codeforcescompetitive-programming
CF 105244D - A Giraffe Travels and Munches

We are given an $m times n$ grid, where each cell contains a non-negative number representing how many trees grow there. A giraffe starts at the top-left cell $(1,1)$ and wants to reach the bottom-right cell $(m,n)$. The movement rules are constrained and unusual.

codeforcescompetitive-programming
CF 105244B - Choosing a Vertex To Remove

We are given a tree with n vertices, and every vertex carries a numeric value. If we take any connected component of this tree, its cost is defined in a slightly unusual way: we multiply the number of vertices in that component by the sum of values stored on those vertices.

codeforcescompetitive-programming
CF 105244A - New Adventures of the Wolf of Wall Street

We are asked to fill an $N times m$ grid with two types of pieces. One is a $1 times 1$ coin tile, and the other is a $1 times 2$ dollar bill that can be placed either horizontally or vertically.

codeforcescompetitive-programming
IMO 1989 Problem 2

The configuration is governed by three recurring geometric objects: the points $A_1,B_1,C_1$ on the circumcircle determined by internal angle bisectors, the external angle bisectors meeting at the thr…

imomathematicsolympiad
IMO 1989 Problem 1

The previous construction failed because it broke the fixed requirement that exactly 17 column permutations must be defined on the same index set ${0,\dots,16}$.

imomathematicsolympiad
CF 105245C - Super Pair

We are given a tree with $n$ nodes. The task is to consider every unordered pair of distinct nodes $(u, v)$ that is not already connected by an edge in the input tree, and decide whether adding a direct edge between them preserves a very strong structural property: after…

codeforcescompetitive-programming
IMO 1988 Problem 6

Testing small cases gives $k=1$ for $(a,b)=(1,1)$.

imomathematicsolympiad
IMO 1988 Problem 5

Coordinates are placed with the right angle at $A$, taking $A=(0,0)$, $B=(b,0)$, $C=(0,c)$ with $b,c>0$.

imomathematicsolympiad
CF 105245G - Multiple Game

Two players play on a pair of positive integers, and each move consists of choosing one number and reducing the other by any positive multiple of it, as long as the result stays non-negative.

codeforcescompetitive-programming
CF 105245F - Count via Construct

We are asked to count how many binary matrices of size $n times n$ satisfy two global constraints that are imposed in a very asymmetric way across rows and columns. Each row has a condition on the AND of all its entries.

codeforcescompetitive-programming
CF 105245E - XOR Priority

We are given an array and every adjacent pair can be connected either by addition or XOR. Each choice produces one expression, so there are $2^{n-1}$ expressions. However, the value of an expression is not computed in the usual left-to-right manner.

codeforcescompetitive-programming
CF 105245D - Permutational Mex

We are given a desired value of a function computed from a permutation of numbers from 0 to n-1. For any permutation, we look at every prefix and compute the MEX of that prefix, then sum all those MEX values.

codeforcescompetitive-programming
IMO 1988 Problem 4

The expression

imomathematicsolympiad
CF 105245A - King Supremacy

We are given an $n times m$ grid where each cell behaves like a chessboard square colored by parity: a cell is white when the sum of its coordinates is even and black otherwise.

codeforcescompetitive-programming
CF 105245B - Circular Cone

We are given a circular arrangement of $n$ sectors, and initially each sector contains exactly one cone. The goal is to move all cones so that they end up stacked in a single chosen sector.

codeforcescompetitive-programming
IMO 1988 Problem 3

Testing the recursion directly shows that fixed points are sparse but structured.

imomathematicsolympiad
IMO 1988 Problem 2

The structure describes $n+1$ finite sets, each of size $n$, with the property that any two sets intersect in exactly one element, and every element lies in at least two sets.

imomathematicsolympiad
CF 105255B - Schedule

We are scheduling activities over a fixed number of weeks, and each team contributes exactly one representative per week. So every week is represented by a binary string of length n, where the i-th character tells whether member 1 or member 2 of team i is present.

codeforcescompetitive-programming
IMO 1988 Problem 1

Something went wrong.

imomathematicsolympiad
IMO 1987 Problem 6

Let $f(k)=k^2+k+n$ and assume there exists a smallest integer $k_0\in[0,n-2]$ such that $f(k_0)$ is composite.

imomathematicsolympiad
CF 105255K - Alea Iacta Est

We are given up to six dice, each die showing one symbol on its top face after a roll, but internally each die has six possible symbols it can show, all equally likely.

codeforcescompetitive-programming
CF 105255J - Bridging the Gap

A group of people needs to cross a bridge at night, but only a limited number of them can be on the bridge at once. Each person has a fixed crossing time, and when multiple people cross together, the group moves at the speed of the slowest member.

codeforcescompetitive-programming
CF 105255H - Jet Lag

We are given a timeline starting at minute zero and a set of disjoint activity intervals, sorted in increasing order and not overlapping. During each activity interval, we must remain fully awake. Outside these intervals, we are free to choose when to sleep.

codeforcescompetitive-programming
CF 105255I - Waterworld

The problem describes a planet whose surface is observed in a very structured way. Instead of looking at the whole sphere at once, the measurement process slices the planet in two directions. First, the planet is split vertically into n horizontal bands from pole to pole.

codeforcescompetitive-programming
CF 105255G - Turning Red

We are given a set of lights, each initially colored red, green, or blue, and a set of buttons. Each button is connected to a subset of lights.

codeforcescompetitive-programming
CF 105255F - Tilting Tiles

We are given two configurations of a rectangular board filled with obstacles and colored tiles. Empty cells exist, and tiles occupy some of them. Tiles are indistinguishable except for their color, and multiple tiles of the same color cannot be told apart individually.

codeforcescompetitive-programming
CF 105255D - Carl's Vacation

We are given two identical geometric objects: right square pyramids standing on the same horizontal ground plane. Each pyramid is described by one directed edge of its square base and a height.

codeforcescompetitive-programming
CF 105255E - A Recurring Problem

We are asked to enumerate a very large collection of integer sequences, where each sequence is generated by a positive linear recurrence.

codeforcescompetitive-programming
CF 105255C - Three Kinds of Dice

We are given two dice, each described by a multiset of face values. When two dice are rolled against each other, we pick one face uniformly from each die and compare the numbers. The higher number wins the round, and ties are split evenly.

codeforcescompetitive-programming
CF 105255A - Riddle of the Sphinx

We are trying to recover three hidden integers, each representing the number of legs of a mythical creature. We cannot observe them directly.

codeforcescompetitive-programming
IMO 1987 Problem 5

A configuration with rational areas for every triangle suggests that all coordinates should lie in a lattice with a controlled determinant structure, since triangle area is given by a determinant expr…

imomathematicsolympiad
IMO 1987 Problem 4

Assume there exists a function $f : \mathbb{Z}_{\ge 0} \to \mathbb{Z}_{\ge 0}$ satisfying

imomathematicsolympiad
IMO 1987 Problem 3

Consider the family of all integer vectors $a=(a_1,\dots,a_n)$ with each $a_i$ in ${0,1,\dots,k-1}$.

imomathematicsolympiad
IMO 1987 Problem 2

A direct decomposition of the quadrilateral into triangles along a guessed diagonal is unreliable because the cyclic order of the constructed points is not controlled a priori.

imomathematicsolympiad
CF 105257C - Seats

We are given $n$ people and a fixed initial seating arrangement where person $i$ starts at seat $i$. Each seat is unique and every person occupies exactly one seat. Each person also has a preferred seat $ai$, which lies somewhere in a larger pool of seats $1 ldots 2n$.

codeforcescompetitive-programming
IMO 1987 Problem 1

For each permutation of ${1,\ldots,n}$, a fixed point is an index $i$ with $f(i)=i$.

imomathematicsolympiad
IMO 1986 Problem 6

A first attempt to force balance by treating each vertical or horizontal line independently fails because every point influences two constraints simultaneously, one vertical and one horizontal.

imomathematicsolympiad
IMO 1986 Problem 5

Substituting $y=2$ into the functional equation yields

imomathematicsolympiad
IMO 1986 Problem 4

A quick sanity check is to look at what the statement is really forcing on $X$.

imomathematicsolympiad
CF 105257M - Window Decoration

We are given up to ten thousand identical decorations placed inside a 100 by 100 square window. Each decoration is centered at an integer coordinate strictly inside the boundary, and each one is a rotated square whose diagonals align with the coordinate axes and have total…

codeforcescompetitive-programming
CF 105257L - Chess

We are given a game that depends on a chosen base $k$. For each test, there are $x$ coins on the table. Before the game starts, the first player selects an integer base $k ge 2$. After that, two players alternate moves.

codeforcescompetitive-programming
CF 105257K - Lethal Company

We are standing at a junction that connects multiple independent corridors. Each corridor is an infinite line extending away from us, and threats appear over time on these corridors.

codeforcescompetitive-programming
CF 105257J - Prime Guess II

We are given an array of integers $a1, a2, ldots, an$. For each query, we are also given a value $u$ and a starting position $l$.

codeforcescompetitive-programming
CF 105257I - Prime Guess I

We are interacting with a hidden prime power value. In each test case, the judge fixes an unknown prime $p$ and an exponent $k$, forming $q = p^k$. We are allowed to query powers of this hidden number: for any exponent $a$ we choose, we receive a transformed value $g(q^a)$.

codeforcescompetitive-programming
CF 105257H - Maximum Flow

We are given a directed acyclic graph where every edge can carry at most one unit of flow. From the source node 1, we are interested in every other node i and want to know how many edge-disjoint paths exist from 1 to i.

codeforcescompetitive-programming
CF 105257G - Disappearing Number

We are working with the natural numbers in increasing order, but one digit has been completely erased from existence. Any number that contains this forbidden digit is removed from the sequence.

codeforcescompetitive-programming
CF 105257F - Try a try, AC is OK

We are given several independent test cases. In each one, there is a list of integers representing scores of different code submissions. The player must submit code twice, and the final score is not a sum or maximum, but a bitwise AND of the two chosen submissions’ scores.

codeforcescompetitive-programming
CF 105257D - Double Subsequence

We are given a long string S and two short patterns s1 and s2. For every substring T of S, we look at how many times s1 appears in T as a subsequence and how many times s2 appears in T as a subsequence.

codeforcescompetitive-programming
CF 105257E - Trade Road

We are given a circle split into $K$ equally spaced positions, and a subset of $n$ of these positions contain markets. Each market sits at a fixed point on the circle, so we can think of the input as an increasing sequence of indices on a circular array.

codeforcescompetitive-programming
CF 105257A - chmod

Each input line describes a Unix-like permission configuration encoded in a compact numeric form. Instead of directly giving permissions for a file, the system uses a three-digit number, where each digit independently describes the access rights for one of three user classes…

codeforcescompetitive-programming
CF 105257B - Expression Matrix

We are asked to construct an $n times m$ grid filled with only three symbols: 1, +, and . The grid is not just a static object, it defines expressions in two directions. Every row, read left to right, becomes a valid arithmetic expression.

codeforcescompetitive-programming
IMO 1986 Problem 3

A direct attempt to repair the previous quadratic potential must first survive explicit consistency checks.

imomathematicsolympiad
IMO 1986 Problem 2

The construction applies successive $120^\circ$ clockwise rotations about the vertices $A_1,A_2,A_3$ in a periodic pattern.

imomathematicsolympiad
IMO 1986 Problem 1

Assume, for contradiction, that all six expressions

imomathematicsolympiad
CF 105259B - Mazes

The task asks us to construct a grid-based maze where movement is restricted to only going right or down, starting from the top-left cell and ending at the bottom-right cell. Some cells are empty and usable, while others contain hedges that block passage.

codeforcescompetitive-programming
IMO 1985 Problem 6

Testing small initial values clarifies the mechanism.

imomathematicsolympiad
IMO 1985 Problem 5

The configuration involves two circumcircles sharing the point $B$: the circumcircle of $ABC$ and the circumcircle of $KBN$.

imomathematicsolympiad
IMO 1985 Problem 4

The original approach fails because it tries to force a 4-term zero sum inside a single parity class, where no additive structure is guaranteed.

imomathematicsolympiad