brain

tamnd's digital brain — notes, problems, research

43815 notes

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
IMO 1996 Problem 3

The functional equation is

imomathematicsolympiad
IMO 1996 Problem 2

A direct continuation of the previous angle-sum manipulation is unsafe because relations involving three rays at a point were previously used without controlling whether the point lies inside the rele…

imomathematicsolympiad
CF 105236B - Найди отрицательное

We are given two points on the integer grid, each acting as the center of a circular influence. Around each center, every lattice point within a given Euclidean radius has its value flipped by multiplying it by −1.

codeforcescompetitive-programming
IMO 1996 Problem 1

The correction must repair three independent failures: a missing invariant for even $r$, a non-existent construction for $r=73$, and a spurious modular obstruction for $r=97$.

imomathematicsolympiad
IMO 1995 Problem 6

For small primes the structure can be tested directly.

imomathematicsolympiad
IMO 1995 Problem 5

The failure in the previous argument comes from a structural mismatch: the target inequality cannot be reached by first producing an expression for $CF$ and then attempting to “discard” remaining boun…

imomathematicsolympiad
CF 105236E - Гробовая геометрия

We are given a set of points on a 2D integer grid. Among them, there exists a hidden point $(a, b)$. For every given point $(xi, yi)$, we are also given the squared Euclidean distance from that point to $(a, b)$, but the list of these distances is shuffled, so we do not know…

codeforcescompetitive-programming
CF 105236D - Посчитай-ка пути

We are given a weighted tree with up to one hundred thousand vertices. Each edge has an integer weight. For every query, we pick two vertices and look at the unique simple path between them. This path gives us a sequence of edge weights in order.

codeforcescompetitive-programming
CF 105236C - Футбол в Берляндии

We have $n$ football players. Initially, each player $i$ has a shirt numbered $i$, so the labels form the sequence $1,2,dots,n$. After a change, shirt number $1$ is replaced by $n+1$, so the available set of shirt numbers becomes $2,3,dots,n+1$.

codeforcescompetitive-programming
CF 105239D - Da Hong Pao

We are given a sequence of cups arranged in a line. Each cup has a value that represents how relaxing it is to drink. Evgeny repeatedly removes cups until none remain, but each time he is only allowed to take either the leftmost or the rightmost remaining cup.

codeforcescompetitive-programming
IMO 1995 Problem 4

The recurrence is first rewritten correctly by clearing denominators:

imomathematicsolympiad
CF 105239I - Path And k Vertices

We are given a rooted tree where every edge is directed from a child up to its parent, so from any node you can follow a unique chain of parents until you reach the root. Each vertex has a distinct integer value attached to it.

codeforcescompetitive-programming
CF 105239H - These Piles of Stones Again!

We are given a small combinatorial game played on three independent piles of stones. Each move consists of selecting exactly one pile and removing a number of stones from it. The number of stones removed must belong to a fixed allowed set given in the input.

codeforcescompetitive-programming
CF 105239G - Butterball on a Diet

Each store trip gives Butterball two independent supplies: some rice and some chicken breast. Across all trips, he wants to assemble meals of fixed size $k$ grams, but the rules restrict how ingredients can be combined.

codeforcescompetitive-programming
CF 105239F - Large Tiling With Dominoes

We are asked to count how many ways we can completely cover a rectangular grid of height m and extremely large width n using 1×2 dominoes. Each domino covers exactly two adjacent cells either horizontally or vertically, and every cell of the grid must be covered exactly once.

codeforcescompetitive-programming
CF 105239E - Rain

We are given a rectangular grid representing flooded terrain, where each cell has a water depth value. A traveler starts in the top-left cell and wants to reach the bottom-right cell.

codeforcescompetitive-programming
CF 105239B - Let Us Assemble a Portfolio Together

We are given a collection of projects, and for each project there are several mutually exclusive ways to execute it. Each way has a cost and a revenue. For every project we must either pick exactly one of its available ways or skip the project entirely.

codeforcescompetitive-programming
CF 105242C - Powerful String

We are given several independent test cases. Each test case describes a tree, meaning a connected acyclic graph. The task is to decide whether there exists a walk on this tree that visits every node at least once and never more than twice.

codeforcescompetitive-programming
IMO 1995 Problem 3

Testing the condition for small values of $n$ starts with rewriting the requirement as a linear system in the unknowns $r_i$.

imomathematicsolympiad
IMO 1994 Problem 6

For any infinite set $S$ of primes, the objects under consideration are integers of the form $p_1p_2\cdots p_k$, where $p_i\in S$ are distinct primes and $k\ge 2$.

imomathematicsolympiad
CF 105242L - Median of the Array

We are given several test cases, and in each one we start with a list of integers. The task is to split this list into two non-empty groups so that every element belongs to exactly one of the groups.

codeforcescompetitive-programming
CF 105242K - 2.. 3.. 4.. Colorful! Colorful! Colorful!

We are given multiple test cases. Each test case consists of a set of points on a 2D plane. Every point has integer coordinates and also a color label.

codeforcescompetitive-programming
CF 105242J - The Square Game

We are given a single odd integer n that represents the number of chess games played between two players, both named Ahmad. Every game produces a decisive result, so there are no draws, and each game contributes exactly one win to one of the two players.

codeforcescompetitive-programming
IMO 1994 Problem 5

Testing small structures suggests that the expression $x+f(y)+xf(y)$ behaves like a deformed product since it equals $(1+x)(1+f(y))-1$.

imomathematicsolympiad
CF 105242I - Minimum XOR

We are given an array of integers and then asked many independent queries. Each query provides a value x, and we must consider all pairs of distinct indices (i, j) such that the bitwise OR of the two array values is “compatible” with x, in the sense that every bit that…

codeforcescompetitive-programming
CF 105242H - Banis Hotel

We are given a hotel with floors numbered from bottom to top. Each floor has a structural limit that restricts how many guests can be on that floor or any floors above it.

codeforcescompetitive-programming