brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 105059C - SeaTac

We are given a connected undirected graph that represents a city, where intersections are nodes and roads are edges. A car starts at node 1 and must reach node n. Every road costs exactly one unit of fuel to traverse.

codeforcescompetitive-programming
CF 105059D - Assignment Allocation

We are given a semester divided into days, and a collection of assignments. Each assignment is available only during a fixed interval of days, from its start day to its deadline day, and it can be completed on any single day inside that interval.

codeforcescompetitive-programming
CF 105058A - Степенные числа

We are given many independent queries. Each query provides two integers, a starting value n and a base k. We want to find the smallest integer x such that x ≥ n and x can be written as a sum of distinct powers of k. This means we are allowed to pick exponents a1, a2, ...

codeforcescompetitive-programming
CF 105058C - Нечестная игра

We are given an $n times m$ grid with a single token (the “piece”) starting at cell $(r, c)$. The game evolves in discrete rounds.

codeforcescompetitive-programming
CF 105056D - Tasks at Odoo

We are given a line of tasks, each with a fixed processing time, and a global deadline. Tasks must be launched in order, meaning task i cannot begin before task i-1 has been started. This creates a dependency chain on start times, not on completion order.

codeforcescompetitive-programming
CF 105056A - Potential Odoo Email

We are given a single string that is supposed to represent an email-like identifier, and we need to decide whether it matches a very specific pattern used by a fictional group of addresses. A valid string must consist of two parts separated by a single '@' character.

codeforcescompetitive-programming
IMO 1963 Problem 4

The system is a cyclic linear homogeneous system with five variables and a real parameter $y$.

imomathematicsolympiad
IMO 1963 Problem 3

The first issue is whether the hypothesis “consecutive sides satisfy $a_1 \ge a_2 \ge \cdots \ge a_n$” is purely linear or implicitly cyclic.

imomathematicsolympiad
IMO 1963 Problem 2

For a point $P$ in space, the condition that the angle with vertex at $P$ has one side passing through $A$ and the other intersecting segment $BC$ means that there exists a point $X \in BC$ such that…

imomathematicsolympiad
IMO 1963 Problem 1

The equation

imomathematicsolympiad
CF 105056C - Viruses

We are simulating objects moving on a one-dimensional line segment from position 0 to a fixed destination k. Each module starts somewhere on this line and moves to the right at a constant speed of one unit per second.

codeforcescompetitive-programming
IMO 1959 Problem 6

All invalid reasoning in the previous attempt comes from unbounded motion along a line and from treating angle limits at infinity as meaningful geometric invariants.

imomathematicsolympiad
CF 105056H - Views Testing

We are given a tree of views. Each view can move to any other view by following a unique shortest path, and moving between two views has a cost equal to the number of edges on that path. Alongside the tree, there is a cyclic array of size $k$.

codeforcescompetitive-programming
CF 105056G - Giant Community

We are given a rooted inheritance structure of applications. Each app has a unique identifier, a parent pointer, and two parameters that define a linear profit function over time: a slope and an intercept.

codeforcescompetitive-programming
IMO 1959 Problem 5

Small values of $m$ are checked to determine structural invariants.

imomathematicsolympiad
CF 105056F - Odoo Trees

We are given a company hierarchy that forms a rooted tree, where employee 1 is the root and every other employee has exactly one direct manager. Any employee’s subtree represents all people under them in the organizational chart. Each employee starts with an initial salary.

codeforcescompetitive-programming
CF 105056E - POS Kiosk

We are given an array of integers where each value describes the net change in stored records during a batch: positive values increase occupied space and negative values free space.

codeforcescompetitive-programming
CF 105056B - Make it ODOO!

We are given a string made only of the characters O and D. We are allowed to modify it using two operations, each costing one minute. One operation deletes a single character, but only if it is at the left end or the right end of the string.

codeforcescompetitive-programming
CF 105058E - Годовой отчет

We are given several independent scenarios. In each scenario, there are up to 40 candidates, each carrying a label that encodes their knowledge about a fixed number of topics as a bitmask.

codeforcescompetitive-programming
CF 105058D - Стековое кодирование

We are given a static array and for each query we must output a sequence of stack operations that reproduces exactly the subarray defined by the query, using a very specific encoding model. The model is a stack that supports three actions.

codeforcescompetitive-programming
CF 105058B - Mixing Drinks

We are given a cup made of multiple horizontal layers of coffee. Each layer has a fixed volume (height) and a fixed “strength”. The layers are stacked from bottom to top, and initially nothing is mixed.

codeforcescompetitive-programming
CF 105059B - Bus Routes

We are given a street with stops labeled from 1 to n, and we want to move from stop 1 to stop n. Movement is free only when it happens through bus routes, and otherwise it costs exactly the distance walked along the line. Each bus route is an interval [L, R].

codeforcescompetitive-programming
IMO 1959 Problem 4

The previous approach failed because it tried to manufacture several derived lengths from $c$ without a coherent straightedge-and-compass dependency chain and without a well-defined geometric configur…

imomathematicsolympiad
IMO 1959 Problem 3

Let $t=\cos x$.

imomathematicsolympiad
CF 105059F - Average of Averages

We are given an integer array and we look at every contiguous segment of it. For each segment, we compute its average value, meaning the sum of elements in that segment divided by its length. The task is to take all these segment averages and compute their overall mean.

codeforcescompetitive-programming
CF 105059E - Mole Whacking Robots

We have a line of $n$ holes labeled from 1 to $n$. Each hole contains a single mole, and every mole appears exactly once during a game that lasts $n$ seconds.

codeforcescompetitive-programming
IMO 1959 Problem 2

Let

imomathematicsolympiad
CF 105059A - Luddy Rocks

The task is essentially about checking whether a fixed target word can be constructed from the letters available in a given string. For each test case, we are given a “banner” made of uppercase letters.

codeforcescompetitive-programming
CF 105062A - Is It Rated??

We are given two integers, m and d. Think of m as a month number in a calendar year and d as a day of the month. The task is to decide whether this pair can represent a valid calendar date in the simplified world implied by the problem.

codeforcescompetitive-programming
CF 105062E - Fixing Chaos

The problem describes a sequence of special values called “chaos points,” indexed starting from 1. We are given a small index $n$, and we must output the value associated with the $n$-th position in this sequence.

codeforcescompetitive-programming
CF 105062D - Important Memories

The input describes a single integer $n$, constrained to a very small range from 1 to 6. There is no additional structure, no secondary parameters, and no hidden dataset implied by the statement. The task is to produce a single integer output based on this value.

codeforcescompetitive-programming
CF 105064A - A Highly Constrained Problem...

We are asked to construct a permutation of length $n$, meaning each integer from $1$ to $n$ appears exactly once, such that every position $i$ carries two independent constraints that describe how it participates in increasing subsequences.

codeforcescompetitive-programming
Kvant Physics Problem 36

The scan of Kvant problem F36 is missing, so the physical system, numerical data, and even the problem statement are not available.

kvantphysics
CF 105064K - ab ba count

We are given a small alphabet, at most 7 letters, and a set of allowed swaps between ordered pairs of characters. Each swap rule says that whenever we see two positions in a string whose characters match one of these directed pairs, we are allowed to swap those positions.

codeforcescompetitive-programming
CF 105064J - Non-Intersecting Arcs

We are counting how many permutations of numbers from 1 to n can be arranged so that when we connect consecutive elements with straight segments, those segments never cross in their interiors.

codeforcescompetitive-programming
CF 105064I - k-goodness

We are given an integer array. From this array we define two special quantities that depend on how we restrict subarrays. The first quantity, call it $m0$, comes from looking only at subarrays that contain no negative numbers.

codeforcescompetitive-programming
CF 105064H - Tree Scoring

We are given a sequence of values placed on the vertices of an unknown rooted tree. The root is fixed at vertex 1, and every other vertex must attach to a parent with a strictly smaller label.

codeforcescompetitive-programming
CF 105064G - Armed Soldiers 1

We are given a set of soldiers placed on a number line. Each soldier has a fixed position and a weapon with a certain power. When a monster appears at some position, every soldier shoots toward that position.

codeforcescompetitive-programming
CF 105064F - Armed Soldiers 2

Each soldier sits at an integer position on a number line and has a firing strength. A monster appears at some position and comes with a shield that weakens incoming bullets depending on how far they travel.

codeforcescompetitive-programming
CF 105064E - Color Conundrum

We are working with a rooted tree where each vertex carries a color label. The root is fixed at vertex 1. On this tree, we must support two operations over time: recoloring a single vertex, and querying how many vertices of a given color exist inside a particular subtree.

codeforcescompetitive-programming
CF 105064D - Snakes Among Us

We are dealing with a classroom of an odd number of students, each secretly holding a nonzero integer score. Exactly one student has the largest score, and that score is strictly greater than everyone else.

codeforcescompetitive-programming
CF 105064C - You and Assignments

Each course has a number of assignments, and we are allowed to repeatedly transform the value in any single course using a special operation that depends on its index. The goal is to minimize the sum of all course values after applying these operations any number of times.

codeforcescompetitive-programming
CF 105066H - Afterimages

We are given two arrays of heights, each of length $n$, representing two lines of Korosensei’s afterimages. During each song, every position $i$ forms a pair between the $i$-th element of the first line and the $i$-th element of the second line, and their interaction cost is…

codeforcescompetitive-programming
CF 105066L - Gaslighting

We are given a fixed string and then a large number of queries, each query specifying a substring interval $[l, r]$.

codeforcescompetitive-programming
CF 105066K - Another Ordering Problem

We are given a collection of sushi toppings, each topping having a cost and a single forbidden relationship. If we choose topping i, then another specific topping bi is not allowed to appear together with it.

codeforcescompetitive-programming
CF 105066J - Everyone Loves Threes Magic (Easy Version)

We are given many independent queries, and each query defines an interval $[L, R]$ with values up to one million. For each such interval, we must imagine all subintervals $[l, r]$ that lie completely inside it, meaning $L le l le r le R$.

codeforcescompetitive-programming
CF 105066I - Another Bitwise Problem

We are given an array of integers, and we repeatedly apply a transformation controlled by a nonnegative integer parameter $x$. For a fixed choice of $x$, every array element $ai$ is XORed with $x$, and all these results are summed together.

codeforcescompetitive-programming
CF 105066F - Unique Subsequences

We are given a string and a target length $k$. From this string, we consider every possible subsequence of length $k$. A subsequence is formed by choosing positions in increasing order, not necessarily contiguous, and reading the characters at those positions.

codeforcescompetitive-programming
Kvant Math Problem 1499

We seek infinitely many rational solutions of

kvantmathematicsolympiad
Kvant Math Problem 1497

A toroidal $15\times 15$ chessboard can be identified with the group $\mathbb Z_{15}\times\mathbb Z_{15}$, where coordinates are taken modulo $15$.

kvantmathematicsolympiad
Kvant Math Problem 1477

The phrase “cut off a similar one” is interpreted in the standard geometric sense used in olympiad problems: from a convex polygon one performs cuts along straight lines intersecting adjacent sides, p…

kvantmathematicsolympiad
Kvant Math Problem 1473

Let

kvantmathematicsolympiad
Kvant Math Problem 1463

Part (a): let

kvantmathematicsolympiad
Kvant Math Problem 1462

Let

kvantmathematicsolympiad
Kvant Math Problem 1459

The vessel rotates steadily about a vertical axis.

kvantmathematicsolympiad
Kvant Math Problem 1458

I cannot produce a correct solution to M1458 from the text alone, because the problem explicitly depends on the geometry of the pulley arrangement shown in the figure.

kvantmathematicsolympiad
CF 105270C - Range Contradiction

We are given an array of even length, and we are allowed to freely reorder its elements using swaps, so in effect we can permute it arbitrarily.

codeforcescompetitive-programming
CF 105271K - MnTm

We are given a grid of seats with n rows and m columns. Each cell contains a cost, and picking a seat means paying that cost. AAlikhan wants to choose exactly k + 1 seats (himself plus k friends) such that the total cost does not exceed a budget B.

codeforcescompetitive-programming
CF 105271F - Minim and his struggle

Minim has a sequence of n hours before an exam. At each hour, exactly one activity is possible: either eating or sleeping, depending on a given string. A character e means he is allowed to eat in that hour, and s means he is allowed to sleep.

codeforcescompetitive-programming
CF 105271A - ACC triangle

We are given two types of resources: one type represents single “A” pieces and the other represents “C” pieces. Using these, we want to build a triangular structure where row i contains exactly one A followed by i−1 C’s. So the structure grows row by row.

codeforcescompetitive-programming
CF 105272I - Investigating Mars

We are given a rectangular grid where each cell is either empty, a wall, or the unique starting position of a robot. The robot starts with an initial direction encoded in that starting cell, and then repeatedly applies a deterministic movement rule.

codeforcescompetitive-programming
CF 105272F - Festival of the Moon

We are observing a single festival where every participant bought exactly one ticket. There are two ticket types: a normal ticket costing v and a discounted lunar ticket costing exactly half of that, v/2, where v is guaranteed to be even.

codeforcescompetitive-programming
CF 105272B - Battle in space

Two players take turns writing a number. First, the opponent announces an integer n. After seeing it, we choose our own integer m. Whoever writes the larger number wins immediately.

codeforcescompetitive-programming
CF 105276J - Joining Two Trees

We are given two separate trees, one on the vertices of the first block and one on the vertices of the second block. We are allowed to connect exactly one vertex from the first tree to exactly one vertex from the second tree, turning the whole structure into a single tree.

codeforcescompetitive-programming
CF 105276B - Binary Bracket

We are given a fixed single-elimination tournament with $2^K$ players. The bracket structure is completely predetermined: players are placed in order, first round pairs adjacent indices, then winners of adjacent matches face each other in the next round, and so on until one…

codeforcescompetitive-programming
CF 105278H - Emblems

A Codeforces user is tracked through their rating history, and their “status tier” changes as their rating crosses fixed thresholds such as pupil, specialist, expert, and so on.

codeforcescompetitive-programming
CF 105278C - s-parkour

We are given a sequence of building heights, all distinct. For any interval from index $i$ to $j$, we imagine walking along the buildings in order. Each step compares two consecutive heights: if we move to a higher building it is an ascent, otherwise it is a descent.

codeforcescompetitive-programming
CF 105283H - Digit Removal

We are given a very large integer a and another integer b, both written as decimal strings. The number a has exactly four more digits than b.

codeforcescompetitive-programming
CF 105283A - P!=NP

We are asked to count how many ordered pairs of integers $(n, p)$ satisfy a small set of constraints involving a product relationship between the two values. The value $p$ is chosen first and is restricted to the range $0 le p le P$.

codeforcescompetitive-programming
CF 105284H - Thomas Sometimes Hides His Feelings in C++

We are given an even number of indices, each representing a character trope. Between every ordered pair of tropes we have a directed value, which may be negative one meaning the relationship is forbidden, or a nonzero modular value otherwise.

codeforcescompetitive-programming
CF 105284A - P!=NP

We are asked to count integer pairs $(n, p)$ where $p$ is constrained to lie between $0$ and $P$, and two arithmetic conditions involving multiplication and factorial-like behavior must both hold.

codeforcescompetitive-programming
CF 105292E - Employees Selection

We are given a company hierarchy that forms a rooted tree, with employee 1 as the root and every other employee having exactly one direct supervisor.

codeforcescompetitive-programming
CF 105293A - Mr. Wow and Lucky Array

We are given a binary array where each prefix is tightly constrained: every element is either 0 or 1, and at any prefix position, the number of ones cannot exceed half of the prefix length (rounded down).

codeforcescompetitive-programming
CF 105297K - Grabbing plush

We are given a row of N stuffed animals, each with an integer value that can be positive or negative. We are allowed to perform at most M operations.

codeforcescompetitive-programming
CF 105297F - Carbon Neutral

We are given a directed graph where each edge represents a financial transaction between two companies. For every transaction, we must assign a value from the set {-1, 0, 1}.

codeforcescompetitive-programming
CF 105297A - Nauryz

There is a single music device that plays songs one after another. Each guest arrives at a specific time, selects a song with a fixed duration, and that song is normally appended to the end of the playback queue.

codeforcescompetitive-programming
CF 105307H - Final Quiz

We are asked to count how many length-n sequences we can build using k symbols, where each position is a quiz answer choice. The constraint forbids any run of four identical consecutive values.

codeforcescompetitive-programming
CF 105307A - Card Dealer Game

We are given a sequence of decks, each deck containing only two types of cards: red and blue. In each round, the current dealer chooses one unused deck, the deck is shuffled, and the other player picks one card uniformly at random.

codeforcescompetitive-programming
CF 105309H - Easy palindrome question

We are given a sequence of length $n$, where each position represents how many problems a friend solved on that day. Some values are already known, some are unknown and marked as $-1$, meaning they can be freely chosen. We are also given two types of constraints.

codeforcescompetitive-programming
CF 105309A - World's Hardest Math Problem II

We are asked to construct any number of a given length $n$, where $2 le n le 6$, such that two conditions hold simultaneously. First, the number must be rotationally symmetric under a 180-degree rotation.

codeforcescompetitive-programming
CF 105310H - Cereal Trees IV

We are given a rooted tree where node 1 is the root and every node carries a value that can be positive or negative. The tree does not change structurally, but the values at nodes change over time through updates.

codeforcescompetitive-programming
CF 105310C - Red Pandacakes

We are given a circular arrangement of stores, each store containing some number of pancakes. Two players, Lura and Oscar, will each end up visiting a contiguous segment of stores along the circle, but their segments are constrained by a key rule: neither of them is allowed to…

codeforcescompetitive-programming
CF 105314I - Ahmad and Gifting Syndrome

We are given several independent test cases. In each test case, there are $n$ intervals. From each interval $[li, ri]$, we must choose exactly one integer $xi$. After making all choices, we compute the sum of all selected values.

codeforcescompetitive-programming
CF 105314F - Ahmad and Swapping Syndrome

We are given several independent test cases. In each test case, there is a sequence of words arranged in a line. The task is to count how many pairs of positions $(i, j)$ with $i < j$ satisfy a simple visual condition: the two words at these positions “fascinate Ahmad” if…

codeforcescompetitive-programming
CF 105314A - Rama and Cats Syndrome

We are given several test cases. In each test case, there is an array of positive integers representing values of food bags. Rama must choose exactly $n-1$ of these bags and her “satisfaction” is defined as the bitwise OR of the chosen values.

codeforcescompetitive-programming
CF 105315J - Hamza's Birthday

Each test case describes a collection of dishes, where every dish belongs to a specific restaurant and has a numeric taste value. The key constraint is that you cannot mix restaurants. You must pick exactly one restaurant and take all dishes belonging to it.

codeforcescompetitive-programming
CF 105315F - Osama's Birthday

We are given several collections of flower types, where each collection (called a bouquet) is essentially a set of allowed flower labels drawn from a universe of size at most 60. For each test case, Osama chooses exactly one bouquet and then builds a garden of length $m$.

codeforcescompetitive-programming
CF 105315B - Noorhan's Birthday

We are given a number of independent queries. Each query provides an integer n, and we must output a single integer a, where a is the prime number closest to n. If two primes are equally close, the smaller one must be chosen.

codeforcescompetitive-programming
CF 105316K - Marks

Each test case describes a classroom snapshot. For every test case, we are given several students, and for each student we receive exactly eight integers representing their scores in eight different subjects.

codeforcescompetitive-programming
CF 105316G - Intersection Not Allowed

We are given multiple independent test cases. In each test case there are $n$ lockers and $q$ rental requests. Each request fixes one locker $x$ and a time interval $[l, r]$, meaning that locker $x$ is occupied throughout that entire interval.

codeforcescompetitive-programming
CF 105316B - Omar's Magic Trick

We are given a deterministic process that starts with exactly three single-digit cards. Each card holds a value from 1 to 9. The process repeatedly transforms the whole collection: every card value is multiplied by 3, and then the result is split back into its decimal digits.

codeforcescompetitive-programming
CF 105317F - Maze Runner

We are given a very small grid, at most 10 by 10, where every cell contains a lowercase letter. From any cell we are allowed to move to any of its 8 neighbors, including diagonals, and we are allowed to revisit cells arbitrarily many times.

codeforcescompetitive-programming
CF 105317B - Paulo's Plan

We are given a very small set of distinct characters in a string $T$, and a much larger string $S$ that contains exactly the same multiset of characters as $T$, just in repeated quantities. We are allowed to permute both strings freely.

codeforcescompetitive-programming
CF 105336C - 种树

We are given a tree with $n$ nodes representing neighborhoods connected by roads. Some of these neighborhoods are already completed, while the rest still need work. Each day, a team of three workers chooses exactly three neighborhoods that form a connected subgraph in the tree.

codeforcescompetitive-programming
CF 105345J - Phantom Poker

We are given an array of $n$ cards laid out in a line, where each card carries a value from 1 to 13. Over time, the values change through updates, and we are also asked to answer range queries. A query of the first type changes a single position in the array to a new value.

codeforcescompetitive-programming
CF 105345D - Nightmare on 24th

We are given a line of buildings, each containing some number of students. Freddy always starts from the first building and moves strictly to the right. As he visits buildings in order, he accumulates the number of students he has seen so far.

codeforcescompetitive-programming
CF 105346H - Speedway Evacuation

We are given a line segment of integer positions from 0 to n. Several students stand on integer points between 1 and n−1, and multiple students may share the same position.

codeforcescompetitive-programming
CF 105346C - Spooky Hallway

We are given a binary string representing a line of lanterns, where each position is either lit or unlit. In one move, we are allowed to pick any contiguous segment and flip every bit inside it, turning zeros into ones and ones into zeros.

codeforcescompetitive-programming
CF 105348A - Try and Cry

We are given a round-robin tournament with $N$ teams where every pair plays exactly one match and every match produces a winner. A win gives 1 point, a loss gives 0 points. After all matches, teams are ranked by total points, and ties are resolved using run rate.

codeforcescompetitive-programming
CF 105350B - A Cool Pair Problem

We are given an upper bound $n$. From all pairs of integers $(a, b)$ such that both lie between 1 and $n$ and $a < b$, we are only allowed to consider those pairs where the bitwise AND of the two numbers is zero.

codeforcescompetitive-programming