brain

tamnd's digital brain — notes, problems, research

41641 notes

CF 105487K - Xiao Kai's Dream of Provincial Scholarship

Each student in the class has two separate sets of attributes: one for each semester. For each semester, we care about three scores: intelligence, morality, and sports. The sum of these three defines that semester’s “comprehensive score”.

codeforcescompetitive-programming
CF 105487J - Sum of Squares of GCDs

We are given two permutations of the integers from 1 to n, but they are stored as arrays indexed by positions. Each query selects a contiguous segment of indices in the first permutation and another contiguous segment in the second permutation.

codeforcescompetitive-programming
CF 105487I - String Duplication

We are given a base string s and we construct a much longer string T by concatenating m copies of s back to back. So T = s + s + ... + s. The task is to compute how many distinct substrings appear anywhere inside T.

codeforcescompetitive-programming
CF 105487H - Square Root

We are given a binary string, and we interpret it as a sequence where only the 1 characters matter. Every maximal contiguous block of 1s forms a segment, while 0s act as separators that break the string into independent segments.

codeforcescompetitive-programming
CF 105487G - Increasing Sequence

We are given an array of non-negative integers. We are allowed to choose a single integer x in the range from 0 to k, and we apply XOR with x to every element of the array. After this transformation, we require the resulting array to be non-decreasing.

codeforcescompetitive-programming
CF 105487E - Centroid Tree

We are given a rooted tree on $n$ labeled nodes where every node except the root has exactly one parent, and parents always have smaller indices than children.

codeforcescompetitive-programming
CF 105487B - Aho-Corasick Automaton

We are asked to count how many different Aho-Corasick automata could have produced a certain final shape, under very limited structural information. An Aho-Corasick automaton in this setting is built from two intertwined objects.

codeforcescompetitive-programming
CF 105487D - Excellent Splitting

We are given a permutation, and we are allowed to split its elements into two subsequences while preserving original order inside each subsequence. One subsequence is called A, the other is B.

codeforcescompetitive-programming
CF 105486G - Expanding Array

We start with a list of integers, and we are allowed to repeatedly expand it by taking any neighboring pair and inserting a value derived from them using bitwise operations: AND, OR, or XOR.

codeforcescompetitive-programming
CF 105477D - Girona Flower Time

The city can be modeled as a directed complete graph where every location is a node and every ordered pair of nodes has a travel time. Each node also has a non-negative value representing how many tourists stand there.

codeforcescompetitive-programming
IMO 1974 Problem 2

In triangle $ABC$, we seek a point $D$ on the side $AB$ such that

imomathematicsolympiad
IMO 1974 Problem 1

The corrected argument begins by rechecking the structure of the process itself rather than inheriting any assumption from the flawed solution.

imomathematicsolympiad
IMO 1970 Problem 6

A direct “vertex–angle ≥ 60°” charging argument cannot be repaired by any local bound of the form “at most a fixed fraction of pairs at a point subtend angle ≥ 60°”, since configurations can be made e…

imomathematicsolympiad
CF 105486L - Recover Statistics

We are given three target order statistics extracted from an unknown multiset of integers: a value that is supposed to act as the median position at 50 percent, another that corresponds to the 95 percent cutoff, and a final one for the 99 percent cutoff.

codeforcescompetitive-programming
CF 105486K - Magical Set

We are given a collection of distinct integers. You can repeatedly perform an operation where you pick a number larger than 1 from the current collection, remove it, and replace it with one of its proper divisors.

codeforcescompetitive-programming
CF 105486J - Grand Prix of Ballance

The system is simulating a live competition that produces a stream of server logs while a contest is running. There are several levels, and at any moment only one level is “active”, determined by the most recent log of type 1.

codeforcescompetitive-programming
CF 105486I - Good Partitions

We are given a sequence and we want to understand, for each possible block size $k$, whether a very specific partitioning of the array behaves nicely. The array is cut into consecutive segments of length $k$, except possibly the last segment which may be shorter.

codeforcescompetitive-programming
CF 105486H - Friendship is Magic

We are given a large integer written in decimal form. For each such number, we consider all ways to cut its decimal representation into two non-empty parts. Each cut produces two strings, which we interpret again as integers by reading them in base 10.

codeforcescompetitive-programming
CF 105486E - Disrupting Communications

We are given a tree, so every pair of nodes is connected by exactly one simple path. Alongside this structure, we consider many possible connected subgraphs, meaning we choose some set of nodes and edges from the tree such that everything stays connected.

codeforcescompetitive-programming
CF 105486A - Arrow a Row

We are given a binary string consisting of two symbols, and -. We start from a blank canvas of the same length filled with , and we are allowed to perform painting operations.

codeforcescompetitive-programming
CF 105486C - Chinese Chess

We are given a 10×9 chessboard and a hidden piece that belongs to one of six movement types inspired by Chinese chess. We do not know its type or its position.

codeforcescompetitive-programming
CF 105486D - Closest Derangement

We are given a permutation p of size n. The task is to construct another permutation q of the same numbers such that no position keeps its original value, meaning for every index i, the value q[i] must differ from p[i].

codeforcescompetitive-programming
CF 105485M - 猜猜看

We are interacting with a hidden number $x0$, but we never see it directly. Instead, there is a second evolving value $x$ that starts equal to $x0$. We can issue three kinds of interactive commands. One asks whether the current $x$ is divisible by a chosen number $a$.

codeforcescompetitive-programming
CF 105485K - 冰红茶

We are given a rectangular grid with n rows and m columns, and a collection of k bottles of iced tea, each with a fixed price. The task is to place some or all of these bottles into distinct grid cells, with at most one bottle per cell.

codeforcescompetitive-programming
CF 105485J - 星穹列车

The train moves along a fixed horizontal ray that starts at a given point and continues infinitely to the right. Every danger zone is a circle on the plane, and whenever the train’s path passes through a circle, we count only the portion of the train’s path that lies inside…

codeforcescompetitive-programming
CF 105485G - 奥运会

We are asked to count how many Olympic events happen inside a year interval. The key detail is that there are two independent sequences of events: Summer Olympics and Winter Olympics. Each follows a strict periodic pattern.

codeforcescompetitive-programming
CF 105485H - 文神的比赛

We are given a group of contestants in a programming contest. Each contestant has solved a set of problems, and this set is encoded as a string of distinct uppercase letters from A to Z. The length of the string is the number of solved problems.

codeforcescompetitive-programming
CF 105485C - 文神的序列

We are given a sequence of positive integers. In one operation, we pick two different positions i and j, and replace the value at i with the bitwise AND of the two values, ai becomes ai & aj.

codeforcescompetitive-programming
CF 105485D - 低谷(easy)

We are given a sequence of integers representing heights. In one move, we choose any position and decrease that single value by one. We may repeat this operation up to k times.

codeforcescompetitive-programming
CF 105485A - 数组

The task describes an array purely as a way to motivate indexing from zero. If an array has length $n$, its valid indices run from $0$ up to $n - 1$. The problem then asks us to output the index of the last element of such an array when only the length $n$ is given.

codeforcescompetitive-programming
CF 105481M - 盲盒谜题

We are simulating a fairly involved single-player process on a fixed 3×3 grid where items are placed one by one from a given sequence. Each grid cell either holds a “turtle” of some color or is empty.

codeforcescompetitive-programming
CF 105481L - 龙之研习

We are looking at a modified calendar where each year is classified as either a training year or a rest year. Starting from the year 2024, the character gains exactly one unit of progress in every training year, while rest years contribute nothing.

codeforcescompetitive-programming
CF 105481J - 结课风云

Each student has two components in their grade: a fixed exam score and a controllable continuous assessment score. For student $i$, the current total is $xi + yi$, where $xi$ is the coursework score capped at $a$, and $yi$ is the exam score capped at $b$.

codeforcescompetitive-programming
CF 105481H - 划分数字

We are given a large integer $x$ (up to $10^{18}$). For each such number, we may split its decimal representation into two non-empty parts by choosing a cut position in its digit string.

codeforcescompetitive-programming
CF 105481G - 顾影自怜

We are given one or more arrays. For each array, we look at every contiguous subarray and assign it a value based on a simple rule: take the maximum element inside the subarray, count how many times this maximum appears, and if that count is at least k, the subarray…

codeforcescompetitive-programming
CF 105481D - 都市叠高

We are given a set of $n$ distinct points in the plane, revealed one by one in order. At the moment a point appears, it becomes “active”.

codeforcescompetitive-programming
CF 105481A - 爱上字典

We are given a long piece of text that represents a story. The text contains words mixed with spaces and punctuation marks such as commas, periods, exclamation marks, and question marks.

codeforcescompetitive-programming
IMO 1970 Problem 5

The configuration places strong orthogonality constraints: the projection of $D$ onto the plane $ABC$ is the orthocenter of $\triangle ABC$, and at the same time $\angle BDC$ is a right angle.

imomathematicsolympiad
CF 105477A - Coins

We are given several independent scenarios. In each scenario, Baq owns a collection of coins, each coin having a positive integer value. Using any number of these coins, he can form sums by choosing a subset and adding their values.

codeforcescompetitive-programming
CF 105476D - Witch Hunt

We are given a set of people connected by two kinds of relationships. Each person must be assigned one of two roles, which we can think of as either being a witch or not being a witch. The relationships impose constraints on these assignments.

codeforcescompetitive-programming
CF 105476C - Of Streetlights and Thieves

We are given several independent scenarios along a street. In each scenario, there are fixed positions where people stand, and a set of streetlights, each placed at some coordinate and each able to illuminate a symmetric interval around itself determined by its radius.

codeforcescompetitive-programming
CF 105475D - Rooms

We can model the situation as a directed graph on $N$ nodes, one node per person. Each person $i$ keeps one key for their own room and deposits a second key into the room of person $ci$.

codeforcescompetitive-programming
CF 105475E - Coloring Trees

We are given a tree where each vertex is colored either 0 or 1. In one move, we are allowed to choose a set of vertices that forms a connected subgraph in the tree and such that all chosen vertices currently share the same color.

codeforcescompetitive-programming
CF 105475B - Chickens

We are given a set of points on a number line, each point initially holding one chicken. Two chickens are considered connected if we can move from one position to the other using a sequence of jumps, where each jump must be strictly shorter than a chosen value $k$.

codeforcescompetitive-programming
CF 105472J - Jealous Youngsters

Something went wrong while generating the response. If this issue persists please contact us through our help center at [help.openai.com](https://help.openai.com/).

codeforcescompetitive-programming
IMO 1970 Problem 4

The flawed solution failed because it tried to force a “singleton prime contribution” without proving it, and it confused “a prime factor appears once” with “its valuation contributes an unavoidable o…

imomathematicsolympiad
CF 105472H - Hot Hike

We are given a sequence of daily temperatures covering a vacation of length $n$. We must choose a continuous block of exactly three consecutive days: the first day is hiking up to a lake, the second day is rest (ignored for heat considerations), and the third day is hiking back.

codeforcescompetitive-programming
CF 105472D - Dungeon Dawdler

We are inside an unknown rectangular dungeon made of grid cells. Each cell is either a wall or a walkable space, and the walkable space has a special twist: there can be up to two trapdoors that behave like hidden teleporters.

codeforcescompetitive-programming
CF 105472A - Alphabet Animals

We are given the last animal name spoken by the previous player and a pool of unused animal names. A valid move for us must satisfy a chaining rule: the new name must begin with the last character of the previous name, and it must not have been used before.

codeforcescompetitive-programming
CF 105472G - Game of Gnomes

We are given a set of identical units called gnomes, and we must split them into at most a fixed number of groups before the process starts.

codeforcescompetitive-programming
CF 105471G - An Easy Math Problem

We are given a positive integer $n$. We look at all ways to pick two positive integers $p$ and $q$ such that their product divides $n$, and additionally $p le q$. For each valid pair, we compute a value $r = frac{p}{q}$.

codeforcescompetitive-programming
CF 105471C - Counting Strings

We are given a string indexed from 1 to n. We look at pairs of indices $(l, r)$ with $l le r$. Each such pair defines a substring $s[l..r]$, but we only accept it if the endpoints are coprime, meaning $gcd(l, r) = 1$.

codeforcescompetitive-programming
CF 105465M - Max Minus Min

We start with an array of integers. In one move, we are allowed to pick a contiguous segment and add the same value to every element in that segment. We may also choose not to perform any move at all.

codeforcescompetitive-programming
CF 105465K - $K$ Subsequences

We are given an array consisting only of 1 and -1. We must split the indices of this array into k groups. Each group is treated as a subsequence in the original order, meaning we keep relative order but do not require contiguity.

codeforcescompetitive-programming
CF 105465J - Jackpot

We are given an array of length 2n. We repeatedly pick two adjacent elements in the current array, remove them, and gain a score equal to the absolute difference of those two values. After doing this exactly n times, the array becomes empty.

codeforcescompetitive-programming
CF 105465G - Graph Race

We are working with a connected, unweighted, undirected graph. Every vertex has two values attached to it, $au$ and $bu$. The task only cares about vertices that are directly connected to vertex $1$.

codeforcescompetitive-programming
CF 105465I - Impossible Numbers

We are given a collection of $n$ cubes, each cube having six visible digits. Each cube can be oriented so that any one of its six faces becomes the top face, which means that for every cube we can choose any one of its six digits as the digit it contributes.

codeforcescompetitive-programming
CF 105465F - Fast XORting

We are given a permutation of all integers from 0 to n − 1, where n is a power of two. The goal is to transform this permutation into sorted order using two types of operations.

codeforcescompetitive-programming
CF 105465D - Distinct Game

We are given two sequences, each acting like a stack where only the last element is accessible. Every value from 1 to k appears exactly twice across both sequences, so each number forms exactly one pair of occurrences scattered between the two stacks. Two players alternate moves.

codeforcescompetitive-programming
CF 105465B - Build Permutation

We are given an array of integers and asked to construct a permutation π of indices from 1 to n such that pairing each position i with π[i] makes all sums ai + aπ[i] identical across every index i.

codeforcescompetitive-programming
CF 105465C - Christmas Sky

We are given two finite point sets in the plane. One set represents the stars in a new photograph, the other represents stars in an old photograph. We are allowed to translate the new photo by a vector $(tx, ty)$, without rotating or scaling it.

codeforcescompetitive-programming
CF 105461K - Cheater Detector

We are given a set of students where some pairs are known to have exchanged homework. Each report is an undirected edge between two students, meaning those two are connected in a “cheating interaction” graph.

codeforcescompetitive-programming
CF 105461H - Zürich Trams

The network of Zurich stations forms a tree, so between any two stations there is exactly one simple path. On top of this static structure, there are several trams.

codeforcescompetitive-programming
CF 105461J - Gibberish

We are dealing with a hidden permutation of positions from 1 to n. Whenever we send a word of length n, the system rearranges the letters according to this fixed permutation and returns the result.

codeforcescompetitive-programming
CF 105461G - Contrived Intelligence

We are dealing with a hidden integer-coefficient polynomial $P(x)$, but we never evaluate it directly. Instead, we interactively query an index $k$, and the judge tells us how many values among $P(1), P(2), dots, P(k)$ are divisible by $k$.

codeforcescompetitive-programming
CF 105461E - Lighting the Street

We are given a straight street represented as a continuous segment from 0 to L. There are n fixed lamp posts placed at integer coordinates along this segment. We are not allowed to choose their positions, only the type of bulb installed in each lamp post.

codeforcescompetitive-programming
CF 105461B - Digital Products

We are given a number $n$, and we consider every integer $x$ from 1 up to $n$. For each number $x$, we compute a value formed by multiplying all its decimal digits. If a number contains a zero digit, its digit product becomes zero.

codeforcescompetitive-programming
CF 105461D - LSB

We are given a system that allows us to construct new bitsets from an initial bitset $B0$. Each bitset has length $n$, and we can generate new ones using only a small set of operations: shifting left or right, XOR, and OR between previously constructed bitsets.

codeforcescompetitive-programming
CF 105459L - A Game On Tree

We are given a tree with $n$ nodes. A “move” in this problem is not about edges or nodes directly, but about choosing a simple path between any two nodes in the tree.

codeforcescompetitive-programming
CF 105459K - Farm Management

We are deciding how to distribute a fixed working day of length $m$ across $n$ crop types. Each crop $i$ gives a linear profit: every unit of time spent on it contributes $wi$ profit.

codeforcescompetitive-programming
CF 105459J - New Energy Vehicle

We are given a vehicle that can consume energy from multiple batteries while moving forward on a number line. Each battery starts fully charged and contributes a fixed amount of usable distance, one unit of charge equals one kilometer.

codeforcescompetitive-programming
CF 105459H - Subsequence Counting

We are given a long sequence that is not stored explicitly as an array, but described as runs of equal values. Each run contributes a block of identical elements, so the original sequence can be seen as a compressed array of length $L$, where $L$ can be extremely large.

codeforcescompetitive-programming
IMO 1970 Problem 3

The expression for $b_n$ involves weighted increments of the nondecreasing sequence $(a_k)$, with each term having the structure

imomathematicsolympiad
CF 105459G - Welcome to Join the Online Meeting!

We are given an undirected graph where vertices represent participants and edges represent mutual acquaintance. The goal is to “activate” all participants in an online meeting that starts with exactly one creator and then grows by invitations along acquaintance edges.

codeforcescompetitive-programming
CF 105459F - 1D Galaxy

We are given a set of particles on a line. Each particle starts at a coordinate and has a fixed weight, which can be positive or negative.

codeforcescompetitive-programming
CF 105459D - A Simple String Problem

We are working with a very thin grid, only two rows and many columns. From any cell, movement is constrained: you can always move to the cell immediately to the right in the same row, and from a cell in the top row you may also drop vertically into the cell directly below it…

codeforcescompetitive-programming
CF 105459B - Concave Hull

We are given a set of points in the plane, with the promise that no three lie on a straight line. From these points we may choose any subset and arrange the chosen points in some cyclic order to form a simple polygon.

codeforcescompetitive-programming
CF 105459C - Giving Directions in Harbin

We are given a sequence of movement instructions on an infinite grid. Each instruction tells us to move in one of the four absolute directions, north, south, west, or east, and to go a certain number of intersections in that direction.

codeforcescompetitive-programming
CF 105458D - Professor Oak Strikes Back

We are given several independent typing sessions. In each session, Professor Oak produces a long text using a very specific two-finger typing model on a fixed keyboard.

codeforcescompetitive-programming
CF 105458B - The Fortune of Francis

We are given a collection of license plates belonging to cars purchased over time by a single owner. Each plate is a fixed-format string: four digits followed by three uppercase letters.

codeforcescompetitive-programming
CF 105458A - Juan's Flight

Each test case describes Juan’s attempt to choose a single store from which he will buy three required components for a flying car: an engine, a steering wheel, and a spare tire. Every store offers all three items, but each store has different prices for them.

codeforcescompetitive-programming
CF 105457D - Pickle Rick

We are working on an infinite grid where each cell is a unit square. A 1×1×2 cuboid starts in a fixed initial configuration at the origin, and it moves by rolling over one of its edges, like a domino flipping from one face to another. Each such roll counts as one move.

codeforcescompetitive-programming
CF 105457B - Islands and Mountains

We are given a line of land split into $n$ consecutive segments, each with a fixed height. Over time, the sea level rises in steps, and after each rise we must determine how many connected groups of dry land remain.

codeforcescompetitive-programming
CF 105457C - Schedules

We are given a list of class schedules, each represented by a start time and an end time on a single circular day that has m discrete hours.

codeforcescompetitive-programming
CF 105456D - Multidimensional Excursions

We are working in a k-dimensional integer lattice. A state is a point with k integer coordinates, and each move changes exactly one coordinate by either +1 or −1. After 2n moves, we want to count how many different sequences of moves bring us back to the origin.

codeforcescompetitive-programming
CF 105456A - Palindrome ABC

We are given counts of three characters, namely how many times we must use the letters A, B, and C. For each test case, the task is to construct a string using exactly those characters such that the string reads the same forwards and backwards, and among all valid such strings…

codeforcescompetitive-programming
IMO 1970 Problem 2

Let the common digit string be interpreted in two positional systems with bases $a$ and $b$.

imomathematicsolympiad
CF 105455D - La Pachanga

We are given a set of players and a list of pairwise “hate relations”, each with a numerical strength. We need to split all players into two teams. A pair of players placed in the same team is only acceptable if their mutual hate is not “too large”.

codeforcescompetitive-programming
CF 105455C - Spam Mail

We are given a number of points on a line representing mailboxes that must all be “visited” and cleaned, and another set of points representing people who can move along the same line. Each person starts at a fixed coordinate and can move one unit per second left or right.

codeforcescompetitive-programming
CF 105454L - Конфет много не бывает

Two players alternate taking turns from a pile of $N$ candies. The first player starts, and on each move a player removes some number of candies, but only amounts that are powers of two, meaning the move set is $1, 2, 4, 8, 16, dots$.

codeforcescompetitive-programming
CF 105454J - Диета для учёных

We are given a set of dishes, each with four nutritional values: proteins, fats, carbohydrates, and calories. Separately, we are given acceptable ranges for each of these four quantities.

codeforcescompetitive-programming
CF 105454I - Грибы против зомби

We are given a sorted set of objects on a number line: some positions contain zombies moving left, and some contain mushrooms that can reverse a zombie’s direction. A zombie starts in a normal state moving toward decreasing coordinates at speed 1.

codeforcescompetitive-programming
CF 105454F - Новое слово

We are given an alphabet that is cyclic, numbered from 1 to $C$. A word is just a sequence of these numbers, and we are interested in finding occurrences of a pattern word $W$ inside multiple texts.

codeforcescompetitive-programming
CF 105454D - Музыкальные стулья

The game can be viewed as a directed graph on $n$ vertices, where each vertex $i$ has exactly one outgoing edge to $ai$. Every participant initially sits on a distinct vertex (chair), and during a round they all try to move along the outgoing edge of their current vertex.

codeforcescompetitive-programming
CF 105454B - Красивый угол

We are working in a plane with a vertex that defines an angle and two rays forming its sides. One ray is determined by the vertex and a second point, and the other ray is determined similarly.

codeforcescompetitive-programming
CF 105454E - Команды на ПРОШП

We are given a group of $n$ people and want to form teams of exactly three distinct members. However, not every triple is allowed because there are $m$ forbidden pairs of people who cannot appear together in the same team.

codeforcescompetitive-programming
CF 105453H - The magical forest of Seih Sou

We are given a forest represented as an undirected graph with up to one million nodes and edges. Some nodes are initially marked as special, and these special nodes define what it means for a node to be “magical”.

codeforcescompetitive-programming
CF 105453G - Airport Departures' Optimization

We are given a sequence of flights sorted by their scheduled departure times. Each flight has a time when it ideally wants to use the runway, a payment it offers if it is allowed to depart exactly at that time, and a penalty it imposes if it is not.

codeforcescompetitive-programming
IMO 1970 Problem 1

The earlier algebraic model failed because it used incorrect expressions for $\frac{r_1}{q_1}$ and $\frac{r_2}{q_2}$ and then attempted to repair the resulting identity through polynomial manipulation…

imomathematicsolympiad
CF 105453E - Generation and transmission network

We are given a fully specified network of islands where every island can either be powered by building a generator on it or by being connected through transmission lines to some other island that eventually has a generator.

codeforcescompetitive-programming