brain
tamnd's digital brain — notes, problems, research
41650 notes
The problem can be restated as follows. Mr. Black has a house with two sets of doors, each leading to a separate exit: left and right. Each door is initially closed, and we know the exact sequence in which Mr. Black opens them.
We are given a sequence of integers arranged in a line. In one move, we pick two neighboring positions and use the difference between their values to either increase or decrease one of them by exactly that difference.
We are given a single sequence, and we are told that it was originally formed by taking two hidden sequences and interleaving them.
We are given a connected undirected graph with n vertices and m edges. Our task is to assign a direction to every edge so that the resulting directed graph does not contain any path of length two or more.
We are asked to find the median string between two given strings of the same length, s and t, using lexicographical ordering. Both strings consist only of lowercase Latin letters, and s is guaranteed to be strictly smaller than t.
We are given a multiset of integers that was created by taking two sequences, one strictly increasing and one strictly decreasing, merging all their elements together, and then shuffling the result. The original order inside the merged array is lost.
We are given a sequence of integers, and we are allowed to remove elements one by one under a parity constraint that depends on the previous deletion. The first removed element can be anything.
We are given several short strings, and for each one we need to decide whether it forms a single continuous block of the alphabet without any gaps or repetition. Think of the lowercase alphabet as a line from ‘a’ to ‘z’.
We are given a single string of uppercase letters with length between 1 and 10. The task is to determine whether this string is "neat." A neat word, in this context, is defined as one where no letter appears more than once at even positions or more than once at odd positions.
This is an interactive game against a fixed but unknown opponent program. The opponent chooses one deterministic strategy at the beginning of the test and sticks to it for all 20 rounds.
We are given a small array of integers, each between 1 and 32, and we are asked to find a certain integer that represents the maximum number of consecutive elements that satisfy a bitwise property.
We are given a small supervised learning task disguised as a programming problem. There are 50 grayscale images indexed from 1 to 50. For the first 20 images, we are given binary labels indicating whether each image is considered a “Fourier doodle” or not.
We are given a single integer a between 0 and 15. This integer represents a configuration of a simple 4-bit circuit, where each bit can be either 0 or 1. The task is to compute an output integer based on a mysterious internal rule of the circuit.
We are asked to determine whether a given number can be represented as the sum of any number of integers equal to 4 or 7. The input is a single integer $a$ between 1 and 99, and the output is either "YES" if such a representation exists, or "NO" otherwise.
We start with an array whose length is a power of two. The allowed operation is very unusual: whenever the current array is not sorted in non-decreasing order, we may delete either its left half or its right half. After that, we repeat the same process on the remaining half.
We are given a set of $n$ points on a 2D plane, with the guarantee that no three points are collinear. From these points, we want to count the number of 5-point subsets that can form a pentagram-a star-shaped configuration where the points are connected in a specific…
We are given a rooted tree with n nodes, where node 1 is the root. Each node other than the root has a parent specified. A leaf is any node without children.
We are asked to assign heights to houses along a street in order to maximize total profit. The street has n available positions, each of which can host a house with an integer height between 0 and h. The profit from a house of height a is a^2. There are m city restrictions.
A frog starts at position 0 on a number line. From any position, it can move forward by adding a or move backward by subtracting b. However, during the process of exploring what is reachable, we only allow it to stay within the segment [0, x] when computing f(x).
We are given an array of integers and a series of queries. Each query instructs us to flip the sign of numbers in the array that satisfy a comparison: either all numbers greater than a threshold or all numbers less than a threshold.
We are asked to determine the diameter of an unknown weighted tree. The tree has n nodes connected by n-1 edges, each with a positive integer weight at most 100. We do not have direct access to the edges.
The game is played on a complete bipartite graph with two equal groups of vertices. Every vertex on the left side connects to every vertex on the right side, and each such edge has a unique weight.
We are given a hidden assignment of colors to numbered coins, where each coin is exactly one of three colors. The goal is to partition the coins into three groups so that each group contains coins of a single color, but we do not know the colors directly.
We are given a binary string pattern s consisting of '1', '0', and '?', with the guarantee that the first character is '1'.
We are working on a line of $n$ cells where a token starts somewhere and may move over time. Bob asks a sequence of queries, each query naming a cell, and Alice must always answer “NO” to every query.
We are asked to analyze a two-player game played on an array of piles, each containing some number of stones. There are $n$ piles, and $n$ is guaranteed to be even.
The problem gives a rectangular grid of characters representing a pattern on a metal plate, where each cell contains either a . (empty) or a (filled). The task is to find the smallest rectangle that contains all the characters.
We are asked to maintain an array that grows dynamically. On each operation, we append a new element to the array and immediately count the number of contiguous subarrays (segments) within a given range [l, r] whose mex equals a given number k.
We are given an array of integers placed on vertices of a complete set of labels. Between any two vertices we implicitly define an undirected edge if the two associated values share a nontrivial common divisor, meaning their gcd is greater than one.
We are given a permutation of the numbers from 1 to $n$, where $n$ is guaranteed to be even. A permutation means each number appears exactly once in the array. The task is to sort this permutation in ascending order.
We are given a collection of objects, each contributing a signed value and a binary mask. We must choose a positive integer s. Once s is fixed, each object is either kept as-is or flipped in sign depending on a parity condition computed from s and its mask.
We are given two multisets of integer positions on a number line. One multiset describes where stones start, the other describes where we want them to end.
We are given three pools of building blocks. There are a pieces of the letter string "a", b pieces of "b", and c pieces of "ab". We are allowed to select any subset of these blocks and concatenate them in any order we want.
We are given a collection of $n$ disjoint pairs of integers. Every integer from $1$ to $2n$ appears exactly once across all pairs, so each number belongs to exactly one pair and there is no overlap.
We are given two sorted timelines of flights forming a mandatory two-leg journey. A passenger first chooses a flight from A to B, spending a fixed travel time, and then immediately connects to a flight from B to C, again with a fixed travel time.
We are given a small island country with n settlements and m bidirectional roads connecting them. Each road has a travel time which is either a or b seconds. The roads are initially connected in such a way that every settlement is reachable from every other settlement.
Working
We are given a string of parentheses that encodes a rooted tree via an Euler tour traversal. Every opening bracket corresponds to walking down an edge in the rooted tree, and every closing bracket corresponds to walking back up that same edge.
We are given a fixed base string, which we can think of as a long “universe sequence” of characters. Alongside it, there are three evolving strings, one per group.
We are given a bag of tiles, each labeled with either a 1 or a 2. Our task is to arrange all the tiles into a sequence so that when we calculate the prefix sums - that is, the sum of the first element, the sum of the first two elements, and so on - the number of sums that are…
We are given an $n times n$ square board, where some cells are occupied and others are free. The goal is to completely tile the free cells using identical pentomino pieces shaped like a cross: a center square with four adjacent squares, one in each cardinal direction.
We are given a very simple two-phase trading scenario. In the morning, there are several sellers offering unlimited quantities of the same stock at different buy prices. You can pick any one of these prices and buy as many shares as you want at that price.
We have a queue of students, each with two personal characteristics: $ai$, which measures how much they dislike people in front of them, and $bi$, which measures how much they dislike people behind them.
We are given a tree of n vertices arranged in a simple line, where each vertex has a value ai. Conceptually, this is just an array of numbers connected consecutively by edges.
We are asked to determine the probability that an array consisting of zeros and ones becomes sorted in non-decreasing order after performing a fixed number of random swaps. Each swap selects two distinct positions in the array uniformly at random and exchanges their values.
The process generates a single infinite sequence by repeatedly appending blocks of numbers, where each block alternates between odd and even numbers and doubles in size each time.
We are given a grid of integers where each row represents a set of choices, and from every row we must pick exactly one number. After picking one number per row, we compute the bitwise XOR of all chosen numbers.
We are given a string of uppercase Latin letters of length at least 4, and we want to transform some of its letters so that the substring "ACTG" appears somewhere.
We are asked to count sequences of planet visits with strong structural constraints. A path starts at any planet from 1 to n, and then performs exactly k − 1 moves.
We are asked to count ordered sequences of distinct planets visited by a character who starts on any planet and then makes exactly $k-1$ moves.
We are given two starting integers. From both numbers, we are allowed to shift them upward by the same non-negative amount $k$, producing the pair $a+k$ and $b+k$. For each such shift, we can compute the least common multiple of the two resulting numbers.
The problem describes a full trie built from all correct bracket sequences of length $2n$. Every node in this trie corresponds to a prefix of some valid sequence, and edges correspond to appending either an opening or closing bracket while maintaining validity.
The task is to reconstruct an array of positive integers, a, given two arrays b' and c'. These arrays were generated from a through two stages: first, by taking all consecutive pairs in a to form b and c, where each bi is the minimum and each ci is the maximum of the pair (ai…
We are given a positive integer x representing the "number" of a cat. Our goal is to transform x into a number of the form 2^m - 1 for some non-negative integer m. These numbers in binary consist entirely of 1s, such as 0 (empty longcat), 1, 3, 7, 15, and so on.
We are given a collection of treasure chests and a collection of keys. Each chest has a number written on it and each key also has a number written on it. A key can open a chest only when the sum of their numbers is odd.
We are asked to consider a line segment of length $l$. We randomly choose $n$ subsegments on this line. Each subsegment is determined by picking two points uniformly at random on the segment, so their endpoints may be non-integer.
We are given a hidden simple path drawn on an $n times n$ grid. The path represents a snake: it visits distinct cells, each consecutive pair shares a side, and the two ends of the path are special cells called the head and the tail. We cannot see the path directly.
We are given a rooted tree where every node either behaves like a minimum aggregator or a maximum aggregator. The leaves do not compute anything; they simply hold values.
We are given a 3-dimensional arrangement of unit bricks arranged in an $n times m$ grid. The height of bricks at position $(i,j)$ is unknown, but we are provided with three partial views: the front, the left, and the top.
We are given a string consisting of three types of characters: open parenthesis "(", close parenthesis ")", and question marks "?". Our goal is to replace each "?
Serval is going to the bus station at a specific time t. There are n bus routes, each with a first bus arriving at si minutes and subsequent buses every di minutes. Serval will take the first bus that comes after or exactly at time t.
We are given a row of n students, each with a distinct programming skill ranging from 1 to n. Two coaches take turns picking students to form their teams. On a coach's turn, they select the student with the highest skill remaining in the row.
We are given an array of integers and asked to find a pair of indices (i, j) such that the least common multiple (LCM) of the two numbers at these indices is as small as possible. The array can contain up to one million elements, and each number can be as large as ten million.
We have a shop with n shovels, each with a specific price. Misha wants to buy exactly k shovels, possibly in multiple purchases. The twist is that the shop offers special deals: if you buy exactly xj shovels in a single purchase, the yj cheapest among those shovels are free.
We control a robot that starts at position 0 on a one-dimensional axis and must try to walk up to position n. The robot has two power sources: a battery with capacity b and an accumulator (charged by a solar panel) with capacity a.
We are given four numbers that represent three pairwise sums of unknown positive integers $a$, $b$, $c$ and the sum of all three numbers. These four numbers are in no particular order. Our task is to reconstruct the original three integers $a$, $b$, $c$ from these sums.
Polycarp has a cat with a strict weekly eating schedule. The cat consumes fish food on Mondays, Thursdays, and Sundays; rabbit stew on Tuesdays and Saturdays; and chicken stakes on Wednesdays and Fridays.
We are given an array of integers. We must choose a single non-negative value D and then, independently for each element, either add D, subtract D, or leave it unchanged. The goal is to make every element become the same value after these operations.
We are given a simple undirected graph that is already 2-edge-connected. By Menger's theorem, this means every pair of vertices has two edge-disjoint paths between them, which is exactly the condition required by the two delivery companies.
We are given a single string made of lowercase English letters. We are allowed to choose one contiguous segment inside this string and reverse that segment exactly once. After performing this single reversal, we obtain a new string.
The problem gives us a hidden polynomial of degree at most 10 with integer coefficients, each strictly less than $10^6 + 3$. The task is to find an integer $x0$ such that the polynomial evaluates to zero modulo $10^6 + 3$.
We are given a sequence of integers and allowed to optionally pick exactly one contiguous segment and multiply every element inside it by a fixed value x.
We are given several event times, already sorted in increasing order. Ivan wants to configure an alarm clock that rings periodically. Once the first ring happens at minute y, the clock continues ringing at times: y, y + p, y + 2p, y + 3p, ...
We are given a digit string of odd length, and two players alternately delete single characters from it. The process continues until only 11 characters remain.
We are given a program written in a strange language where each variable has a short name of up to four alphanumeric characters, with the first character not being a digit.
We are repeatedly drawing cards from a multiset of values, without replacement. The only thing that matters is the sequence of drawn values, and how each value compares to the previous drawn value. The game behaves like this: the first drawn card just sets a baseline value.
We are given a permutation of the numbers from 1 to n. For every subarray [l, r], we look at its maximum value. The subarray is called special when the sum of the two endpoint values equals that maximum: $$pl + pr = max(pl,dots,pr)$$ The task is to count how many subarrays…
We are given a tree with n vertices, where each edge is labeled either 0 or 1. We need to count all ordered pairs of distinct vertices (x, y) such that, when walking along the unique path from x to y, we never traverse a 0-edge after we have already traversed a 1-edge.
We are given a short string of lowercase letters and we are allowed to reorder its characters arbitrarily. The goal is to produce an arrangement where no two adjacent characters differ by exactly one position in the alphabet.
We are given a sequence of geometric figures. Each number represents one of three shapes: - 1 = circle - 2 = isosceles triangle whose height equals its base length - 3 = square Every figure is inscribed into the previous one and is chosen with the largest possible size.
We are given a collection of points placed on a number line, and the goal is to form as many disjoint pairs as possible.
We are given an $n times m$ matrix containing only zeros and ones. We may flip any row and any column any number of times. Flipping means replacing every value in that row or column by its opposite. After all chosen flips are applied, the matrix is read in row-major order.
We are given a multiset of integers representing heights of people standing in a line. From these people, we must choose a subset and then reorder the chosen elements into a circular arrangement.
We are given a sequence of integers and must construct the longest possible strictly increasing sequence by repeatedly taking either the leftmost or the rightmost element. Each time we take a number, it is appended to our growing sequence and removed from the original sequence.
We need to distribute exactly n solved problems across k consecutive days. Let a[i] be the number of problems solved on day i. Every day must contain at least one problem.
We are given two arrays a and b, each of length n, containing integers from 0 to n-1. We can reorder b arbitrarily. After choosing an order for b, we construct a new array c where each element is (ai + bi) % n.
We are asked to explore numbers generated by repeatedly applying a particular transformation function. For a number $x$, we first add one to it. If the resulting number has trailing zeros, we remove them all until none remain. This defines the function $f(x)$.
We are given a number as a string of digits from 1 to 9 and a mapping f from each digit to another digit in the same range. The task is to maximize the resulting number by selecting at most one contiguous segment of digits and replacing each digit x in that segment with f(x).
We are given a permutation of size $n$. Think of it as a row of cards where every value from 1 to $n$ appears exactly once. At each move, we are only allowed to remove a card from either the far left or far right end of the current row, and we record the removed value.
We are given an array of positive integers, each bounded by a number $c$. The task is to examine all subsequences of this array and classify them by a number called their density.
We are asked to reconstruct an unknown tree with $n$ vertices by interacting with a device that allows a single type of query. Each vertex of the tree has a lamp, and the device lets us propose a set of distances $d1, d2, dots, dn$.
We are asked to reconstruct a permutation of numbers from 1 to n given a partially known array called next. Each element next[i] represents the smallest index j greater than i such that p[j] p[i]. If no such j exists, next[i] is set to n+1. If next[i] is unreadable, it is -1.
We are given a set of $n$ distinct points on the plane, with the guarantee that no three points are collinear. We need to order these points into a polygonal line such that two conditions hold: it never intersects itself, and at each internal vertex, the turn direction matches…
We have a party with $n$ boys and $m$ girls. Each boy gives some number of sweets to every girl, forming an $n times m$ matrix of integers. For each boy, the minimum number of sweets he gives to any girl is specified as $bi$.
We are asked to construct a binary string of length n such that the shortest substring appearing exactly once has length k. A substring is a consecutive segment of the string, and it is unique if it occurs in exactly one position.
We are given an array of non-negative integers. We define a property called a $k$-extension: an array is a $k$-extension if for every pair of elements $ai$ and $aj$, the inequality $k cdot The input consists of the length $n$ of the array, up to 300,000, and the array elements…
We have a street with n building positions. Every position can contain a house whose height is an integer between 0 and h. The profit from a house of height a is a², so taller houses are always better. The city imposes m zoning rules.
We are given a string c which represents a partially unreadable code. Some positions in c are readable lowercase letters, and others are asterisks representing unknown characters.
We are given a set of points on a plane, each representing a power pole. Every pair of poles defines a straight infinite line, and that line is considered a “wire”.
We are given a sequence of colors arriving over time, one per day. Each day contributes one occurrence of a color.