brain

tamnd's digital brain — notes, problems, research

41650 notes

CF 1060H - Sophisticated Device

We are working in a very unusual computational model: instead of directly manipulating variables, we interact with an array of hidden memory cells. Only two of them initially contain unknown values, while all others are initialized to one.

codeforcescompetitive-programmingconstructive-algorithms
CF 1060E - Sergey and Subway

We start with a tree of subway stations. Every station is a node, and every tunnel is an edge, so there is exactly one simple path between any two stations.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1060B - Maximum Sum of Digits

We are given a single large integer $n$, and we want to split it into two non-negative integers $a$ and $b$ such that their sum stays exactly $n$.

codeforcescompetitive-programminggreedy
CF 1060D - Social Circles

We are given several guests, and each guest has a personal requirement about how they sit in a circular arrangement.

codeforcescompetitive-programminggreedymath
CF 1060C - Maximum Subrectangle

The matrix in this problem is not given explicitly. Instead, every cell is formed by multiplying an element from array a with an element from array b. This creates a grid where each row is a scaled version of b, and each column is a scaled version of a.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
CF 1060A - Phone Numbers

We are given a multiset of digit cards, each card containing a single character from 0 to 9. From these cards, we want to assemble as many valid phone numbers as possible.

codeforcescompetitive-programmingbrute-force
CF 1061F - Lost Root

We are given a tree that is known to be a perfect $k$-ary tree, meaning it has a root, every internal node has exactly $k$ children, and all leaves are at the same depth.

codeforcescompetitive-programminginteractiveprobabilities
CF 1061E - Politics

We are given two different spanning trees over the same set of cities. Each tree represents how one candidate organizes the country, with a chosen root city acting as their capital.

codeforcescompetitive-programmingflowsgraphs
CF 1061D - TV Shows

We are given a collection of time intervals, each representing a TV show that occupies a continuous range of minutes. The key constraint is that a single TV cannot be used to watch two shows whose intervals overlap in time.

codeforcescompetitive-programmingdata-structuresgreedyimplementationsortings
CF 1061B - Views Matter

We are given several vertical stacks of blocks placed side by side. Each position $i$ has a stack of height $ai$. From above, the camera only cares whether a position is occupied or empty, so every column contributes exactly one visible cell as long as it has at least one block.

codeforcescompetitive-programminggreedyimplementationsortings
CF 1061C - Multiplicity

We are asked to count how many subsequences of a given array are “valid” under a position-based divisibility rule.

codeforcescompetitive-programmingdata-structuresdpimplementationmathnumber-theory
CF 1061A - Coins

We are given a collection of coin denominations that includes every integer value from 1 up to n, and we are allowed to use any number of coins of any of these values.

codeforcescompetitive-programminggreedyimplementationmath
CF 1062F - Upgrading Cities

We are given a directed acyclic graph of cities connected by one-way roads. From the constraints, the graph has no directed cycles, so it behaves like a partial order: some cities are comparable through reachability, and others are incomparable.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 1062B - Math

We are given a single integer as a starting point, and we are allowed to transform it using two operations. One operation multiplies the current number by any positive integer we choose, effectively letting us inflate the number arbitrarily.

codeforcescompetitive-programminggreedymathnumber-theory
CF 1062E - Company

The company hierarchy forms a rooted tree where employee 1 is the root, and every other employee has exactly one direct boss. This defines a parent relationship and also induces depths from the root, where depth is the number of edges from employee 1.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similargreedytrees
CF 1062D - Fun with Integers

We are given a set of integers from the range of absolute values 2 up to n, and each number also has its negative counterpart available. Think of every integer i in this range as a node in a graph, including both i and -i.

codeforcescompetitive-programmingdfs-and-similargraphsimplementationmath
CF 1062C - Banh-mi

We are given a binary array where each position has a value of either zero or one. We repeatedly remove elements from a chosen segment, and every time we remove an element, two things happen: we gain its value immediately, and all remaining elements in that segment get…

codeforcescompetitive-programminggreedyimplementationmath
CF 1062A - A Prank

We are given a strictly increasing array of integers, all between 1 and 1000. Someone is allowed to erase exactly one contiguous block of elements, leaving a gap in the sequence. The remaining elements stay in their original positions.

codeforcescompetitive-programminggreedyimplementation
CF 1063F - String Journey

We are given a single string and we want to decompose it into a sequence of progressively shorter substrings, where each substring in the sequence must appear inside the previous one.

codeforcescompetitive-programmingdata-structuresdpstring-suffix-structures
CF 1063D - Candies for Children

We are simulating a deterministic passing process on a circular arrangement of $n$ children. A box starts at position $l$ and is passed clockwise.

codeforcescompetitive-programmingbrute-forcemath
CF 1063E - Lasers and Mirrors

The maze is an $n times n$ grid where each cell can either be empty or contain a fixed type of mirror that behaves like a 45-degree reflector. A laser starts from each column on the southern boundary and travels northward into the grid.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1063C - Dwarves, Hats and Extrasensory Abilities

We are interacting with an unknown assignment of colors to points, where the opponent can choose each point’s color after seeing where we place it. We must output a sequence of distinct integer-coordinate points.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgeometryinteractive
CF 1063A - Oh Those Palindromes

We are given a multiset of lowercase letters. We are allowed to rearrange these letters into any order we want, forming a new string of the same length. For any resulting string, we look at every contiguous substring and check whether it is a palindrome.

codeforcescompetitive-programmingconstructive-algorithmsstrings
CF 1063B - Labyrinth

The task places us on a grid maze where each cell is either open or blocked. We start from a given cell and can move in the four cardinal directions as long as we stay inside the grid and avoid obstacles.

codeforcescompetitive-programminggraphsshortest-paths
CF 1064A - Make a triangle!

We are given three positive integers representing the current lengths of three sticks. In one move, we are allowed to pick exactly one stick and increase its length by one unit.

codeforcescompetitive-programmingbrute-forcegeometrymath
CF 1064B - Equations of Mathematical Magic

The equation links a number a with a variable x using two operations: subtraction and bitwise XOR. For each given value of a, we are asked to count how many non-negative integers x satisfy the identity a - (a XOR x) - x = 0. The input consists of several independent values of a.

codeforcescompetitive-programmingmath
CF 1065F - Up and Down the Tree

We are given a rooted tree with vertex 1 as the root, and every vertex except the root has exactly one parent defined by the input. Some vertices are leaves in the usual sense of the tree structure.

codeforcescompetitive-programmingdfs-and-similardptrees
CF 1065G - Fibonacci Suffix

We are working with a family of binary strings built in the same recursive way as Fibonacci numbers, except instead of addition we concatenate strings.

codeforcescompetitive-programmingstrings
CF 1065E - Side Transmutations

We are given strings of length n over an alphabet of size Instead of tracking how a single string evolves, the real question is to understand which positions in the string are fundamentally indistinguishable under repeated application of these operations.

codeforcescompetitive-programmingcombinatoricsstrings
CF 1065D - Three Pieces

We are given an $N times N$ grid where every cell contains a unique number from $1$ to $N^2$. These numbers define a forced visiting order: we must start at the cell containing 1, then eventually reach the cell containing 2, then 3, and continue in increasing order until $N^2$.

codeforcescompetitive-programmingdfs-and-similardpshortest-paths
CF 1065B - Vasya and Isolated Vertices

We are given a simple undirected graph with a fixed number of vertices and edges. The graph has no self-loops and no duplicate edges.

codeforcescompetitive-programmingconstructive-algorithmsgraphs
CF 1065A - Vasya and Chocolate

Vasya has a fixed amount of money and wants to maximize how many chocolate bars he ends up with under a repeating promotion. Every bar has a fixed price, so his initial purchasing power is simply how many bars he can buy directly.

codeforcescompetitive-programmingimplementationmath
CF 1065C - Make It Equal

We are given a collection of vertical towers, each represented by a positive integer height. In one operation we choose a target height $H$, and then every tower that is taller than $H$ is cut down to exactly $H$, while shorter towers remain unchanged.

codeforcescompetitive-programminggreedy
CF 1066F - Yet another 2D Walking

We are given a set of points in the first quadrant of the grid, and Maksim starts at the origin. In one move he can step to any of the four neighboring lattice points, so every move costs one unit of Manhattan distance. The key restriction is not geometric but structural.

codeforcescompetitive-programmingdp
CF 1066B - Heaters

We are given a one-dimensional house represented as a binary array. Some positions contain heaters, marked with 1, while empty positions are 0. Every heater, if activated, warms a continuous interval around its position.

codeforcescompetitive-programminggreedytwo-pointers
CF 1066A - Vova and Train

The setting is a one-dimensional path from position 1 to position L, where time and position are synchronized so that at minute i, Vova is at coordinate i.

codeforcescompetitive-programmingmath
CF 1068B - LCM

We are given a single integer $b$, and we conceptually iterate over every positive integer $a$. For each $a$, we compute a value derived from the least common multiple of $a$ and $b$, specifically $frac{mathrm{lcm}(a,b)}{a}$.

codeforcescompetitive-programmingmathnumber-theory
CF 1070F - Debate

We are asked to choose a subset of people, each having a weight (influence) and one of four “support types” describing whether they support Alice, Bob, both, or neither.

codeforcescompetitive-programminggreedy
CF 1071E - Rain Protection

We are controlling a rigid but flexible “bar” formed by a rope whose endpoints are constrained to slide along two horizontal segments, one at height zero and one at height $h$.

codeforcescompetitive-programmingbinary-searchgeometry
CF 1073E - Segment Sum

We are asked to consider every integer inside a range $[l, r]$ and filter it by a digit constraint: we only keep numbers that use at most $k$ distinct decimal digits in their usual base-10 representation.

codeforcescompetitive-programmingbitmaskscombinatoricsdpmath
CF 1073C - Vasya and Robot

We are given a fixed sequence of moves for a robot on an infinite grid, starting from the origin. Each character in the sequence moves the robot one step in one of the four cardinal directions.

codeforcescompetitive-programmingbinary-searchtwo-pointers
CF 1075A - The King's Race

We are given an $n times n$ grid. One king starts at the bottom-left corner $(1,1)$ and the other starts at the top-right corner $(n,n)$. A coin is placed at $(x,y)$, and both kings try to reach it as fast as possible.

codeforcescompetitive-programmingimplementationmath
CF 1076E - Vasya and a Tree

We are given a rooted tree where vertex 1 acts as the root, and every vertex initially holds value 0. The tree is static, but we are asked to process a sequence of update operations.

codeforcescompetitive-programmingdata-structurestrees
CF 1076B - Divisor Subtraction

We are given a single large integer and we repeatedly apply a deterministic process that always reduces it. At each step, we inspect the current number, find its smallest prime factor, subtract that factor from the number, and continue until the value becomes zero.

codeforcescompetitive-programmingimplementationmathnumber-theory
CF 1076A - Minimizing the String

We are given a single string made of lowercase letters, and we are allowed to delete at most one character from it. After this optional deletion, we obtain a new string, and among all possible results (including doing nothing), we want the lexicographically smallest one.

codeforcescompetitive-programminggreedystrings
CF 1077F2 - Pictures with Kittens (hard version)

We are given a sequence of pictures arranged in a line, each with a beauty value. We need to choose exactly x of these pictures to repost, but the choice is constrained by a coverage rule: any contiguous block of length at least k must contain at least one chosen picture.

codeforcescompetitive-programmingdata-structuresdp
CF 1077F1 - Pictures with Kittens (easy version)

We are given a line of pictures, each with a value representing its beauty. The task is to select exactly a fixed number of pictures, and among all such selections we want the maximum total beauty.

codeforcescompetitive-programmingdp
CF 1077E - Thematic Contests

We are given a multiset of problems where each problem belongs to a topic. The same topic can appear many times. From this pool, we want to form several contests. Each contest must use only problems from a single topic, so it is homogeneous.

codeforcescompetitive-programminggreedysortings
CF 1077D - Cutting Out

We are given a multiset of integers, and we want to construct a pattern array of fixed length $k$. Once we choose this pattern, we repeatedly try to “extract” it from the original multiset: each extraction consumes one occurrence of every value in the pattern, and after…

codeforcescompetitive-programmingbinary-searchsortings
CF 1077C - Good Array

We are given a list of integers, and we want to identify which positions behave “special” under a deletion operation. For each index, we temporarily remove that element and look at the remaining array.

codeforcescompetitive-programming
CF 1077B - Disturbed People

We are given a row of flats, each either having its light on or off. The configuration is a binary array where 1 means lit and 0 means dark.

codeforcescompetitive-programminggreedy
CF 1077A - Frog Jumping

A frog moves along a number line starting from position zero. Its movement is strictly alternating: it first jumps to the right by a fixed distance a, then to the left by b, then right again by a, and so on.

codeforcescompetitive-programmingmath
CF 1078E - Negative Time Summation

We are given a very unusual computational model: a robot walks on an infinite grid while executing a program, and the grid itself can be rewritten and even “rewound in time”. Two binary integers are initially written on the grid.

codeforcescompetitive-programmingconstructive-algorithms
CF 1080D - Olya and magical square

We start with a square grid whose side length is a power of two, specifically $2^n times 2^n$. The only allowed operation is to take any existing square of side $a$ and split it into four equal smaller squares of side $a/2$.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1080E - Sonya and Matrix Beauty

We are given a grid of characters. From this grid we may choose any axis-aligned subrectangle, and we are allowed to reorder characters independently inside each row of that chosen subrectangle.

codeforcescompetitive-programmingstrings
CF 1080F - Katya and Segments Sets

We are given several collections of segments, where each collection corresponds to a set index from 1 to n. Inside a single set, there may be many segments, and each segment is a closed interval on the number line. The task revolves around answering queries about a range of sets.

codeforcescompetitive-programmingdata-structuresinteractivesortings
CF 1080A - Petya and Origami

Petya is preparing invitation cards for a party, and each invitation consumes a fixed amount of colored paper sheets. Every invitation requires 2 red sheets, 5 green sheets, and 8 blue sheets.

codeforcescompetitive-programmingmath
CF 1080C - Masha and two friends

We are working on a very large grid, conceptually a chessboard with $n$ rows and $m$ columns. Each cell initially has a color determined by a fixed chessboard pattern, alternating between black and white. Two paint operations are applied on top of this initial pattern.

codeforcescompetitive-programmingimplementation
CF 1080B - Margarite and the best present

We are given a very large infinite sequence where each position has a deterministic value based only on its index. The value alternates sign and grows in magnitude linearly: position 1 contributes −1, position 2 contributes +2, position 3 contributes −3, and so on.

codeforcescompetitive-programmingmath
CF 1081F - Tricky Interactor

We are given a hidden binary array of length $n$, containing only zeros and ones. We are also told how many ones it originally contains, but not their positions. The array is placed in the hands of an interactive judge that mutates it after every query in a very specific way.

codeforcescompetitive-programmingconstructive-algorithmsimplementationinteractive
CF 1081H - Palindromic Magic

We are given two long strings, and from each string we are allowed to pick a single substring that is a palindrome. From the first string we choose one palindromic substring, from the second string we choose another palindromic substring, and we concatenate them in that order.

codeforcescompetitive-programmingdata-structureshashingstrings
CF 1081E - Missing Numbers

We are given only half of a hidden sequence of positive integers, specifically every even-positioned value. The full sequence has even length $n$, and has a very rigid structure: if you look at prefix sums, every prefix sum must be a perfect square.

codeforcescompetitive-programmingbinary-searchconstructive-algorithmsgreedymathnumber-theory
CF 1081G - Mergesort Strikes Back

Stopped thinking

codeforcescompetitive-programmingmathprobabilities
CF 1081A - Definite Game

We are given a single positive integer as the starting value of a number $n$. We are allowed to repeatedly transform this number by choosing an integer $x$ that is strictly smaller than the current value of $n$, with the restriction that $x$ must not divide $n$.

codeforcescompetitive-programmingconstructive-algorithmsmath
CF 1081D - Maximum Distance

We are given a connected weighted undirected graph where edges have costs, and a subset of vertices is marked as special.

codeforcescompetitive-programmingdsugraphsshortest-pathssortings
CF 1081C - Colorful Bricks

We are painting a line of $n$ bricks, each brick choosing one of $m$ available colors. Once the painting is done, we look at the positions where the color changes compared to the previous brick.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 1081B - Farewell Party

We are given a group of n people. Each person wore exactly one hat, and every hat belongs to one of n possible types labeled from 1 to n. Multiple people may share the same hat type, and some hat types may not be used at all.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
CF 1082G - Petya and Graph

We are given a simple undirected graph where each vertex carries a cost and each edge carries a reward. We are allowed to pick any subset of vertices, and then from the edges we may only keep those whose endpoints are both selected.

codeforcescompetitive-programmingflowsgraphs
CF 1082F - Speed Dial

We are given a set of phone numbers, each associated with how frequently Polycarp dials it. Every time a number is dialed, he must physically press digits, but the phone allows up to $k$ special speed dial buttons.

codeforcescompetitive-programmingdpstringstrees
CF 1082E - Increasing Frequency

We are given an array where each position stores an integer value. We are allowed to pick exactly one continuous segment and add the same integer value to every element inside that segment. This value can be positive, negative, or zero.

codeforcescompetitive-programmingbinary-searchdpgreedy
CF 1082D - Maximum Diameter Graph

We are given a set of vertices, and for each vertex we are told how many edges it is allowed to participate in at most. Our task is to actually construct a simple undirected connected graph that respects these degree limits and, among all such graphs, maximizes the diameter.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
CF 1082A - Vasya and Book

We are given a book with pages arranged in a line from 1 to n. Vasya starts on page x and wants to reach page y. Each button press moves his current page either forward by d pages or backward by d pages, but any move that would leave the interval [1, n] is not allowed.

codeforcescompetitive-programmingimplementationmath
CF 1082B - Vova and Trophies

We are given a binary string of length $n$, where each position represents a trophy placed in a row. Each trophy is either golden or silver. The only thing that matters is the structure of contiguous golden segments.

codeforcescompetitive-programminggreedy
CF 1082C - Multi-Subject Competition

Each candidate belongs to exactly one subject and brings a numeric contribution, which may be positive or negative.

codeforcescompetitive-programminggreedysortings
CF 1083F - The Fair Nut and Amusing Xor

Two arrays evolve over time, and after each update we must determine how many operations are needed to make them identical under a very specific operation model.

codeforcescompetitive-programmingdata-structures
CF 1083E - The Fair Nut and Rectangles

Each rectangle is anchored at the origin and stretches to a point $(xi, yi)$, so geometrically every rectangle is a lower-left aligned axis-parallel rectangle.

codeforcescompetitive-programmingdata-structuresdpgeometry
CF 1083D - The Fair Nut's getting crazy

We are given an array and we want to count how many ordered pairs of subarrays behave in a very specific geometric way on the index line. Each subarray is a contiguous segment on indices. We choose two such segments. They must overlap, so their intersection is not empty.

codeforcescompetitive-programmingdata-structuresimplementation
CF 1083B - The Fair Nut and Strings

We are working with binary strings of fixed length, where each string consists only of characters a and b. The Fair Nut originally had a multiset of k such strings, each of length n, but the exact strings are lost.

codeforcescompetitive-programminggreedystrings
CF 1083C - Max Mex

We are given a rooted tree on $n$ nodes. Each node stores a distinct value from $0$ to $n-1$, so the values form a permutation. Alongside this, the tree structure is fixed, but the values can change over time through swap operations. Two operations are supported.

codeforcescompetitive-programmingdata-structurestrees
CF 1083A - The Fair Nut and the Best Path

We are given a tree where each node represents a city. Every city contains a fuel station, and each station allows us to obtain some fixed amount of fuel $wi$. Traveling between two cities connected by a road consumes fuel equal to that road’s length.

codeforcescompetitive-programmingdata-structuresdptrees
CF 1084C - The Fair Nut and String

We are given a string made of lowercase letters and we are interested only in the positions of two characters, namely 'a' and 'b'. From this string, we want to count how many strictly increasing sequences of indices we can form such that every chosen index points to an 'a'.

codeforcescompetitive-programmingcombinatoricsdpimplementation
CF 1084A - The Fair Nut and Elevator

The problem describes a single elevator in a building where each floor has a known number of residents. Each resident makes exactly two trips per day, one going down to the first floor and one returning back to their own floor.

codeforcescompetitive-programmingbrute-forceimplementation
CF 1084B - Kvass and the Fair Nut

We are given several kegs of kvass, each containing some initial amount. In one operation, we can reduce any single keg by exactly one liter, and each such operation contributes one liter toward a total amount we want to “pour out”.

codeforcescompetitive-programminggreedyimplementation
CF 1085G - Beautiful Matrix

We are given an $n times n$ matrix where every entry is an integer from $1$ to $n$. The matrix is constrained in two ways: each row contains no repeated values, and vertically adjacent cells in the same column are also distinct.

codeforcescompetitive-programmingcombinatoricsdata-structuresdp
CF 1085E - Vasya and Templates

We are given three strings over an alphabet of size $k$. Think of the letters $a, b, c, dots$ but only the first $k$ of them are used.

codeforcescompetitive-programminggreedyimplementationstrings
CF 1085B - Div Times Mod

We are given two integers, a target value built from a multiplication expression, and a fixed base parameter that controls how we split any positive integer into a quotient and a remainder.

codeforcescompetitive-programmingmath
CF 1085C - Connect Three

We are given three distinct cells on an infinite grid, each representing a square plot of land. Initially everything is blocked, and we are allowed to “clear” any cells we want.

codeforcescompetitive-programmingimplementationmath
CF 1086F - Forest Fires

We are given a set of initial fire sources placed on an infinite integer grid. Fire spreads every second in all eight directions, so each burning cell ignites every neighboring cell that shares a side or a corner.

codeforcescompetitive-programmingmath
CF 1088E - Ehab and a component choosing problem

We are given a weighted tree, where every node carries an integer value that can be positive, negative, or zero. The task is to select some nodes and partition the selected nodes into several connected components.

codeforcescompetitive-programmingdpgreedymathtrees
CF 1088D - Ehab and another another xor problem

We are trying to determine two hidden integers, a and b, each less than $2^{30}$. We cannot see them directly. Instead, we are allowed to query pairs $(c, d)$, and the judge compares the values $a oplus c$ and $b oplus d$, returning whether the first is greater, equal, or…

codeforcescompetitive-programmingbitmasksconstructive-algorithmsimplementationinteractive
CF 1088F - Ehab and a weird weight formula

We are given a set of nodes, each carrying a fixed positive weight. The task is not to compute anything on a given tree, but to design a tree structure on these nodes so that a certain cost expression becomes as small as possible. Two constraints shape the construction.

codeforcescompetitive-programmingdata-structurestrees
CF 1088A - Ehab and another construction problem

We are given a small integer $x$, and we need to construct two integers $a$ and $b$, both constrained to lie between 1 and $x$, such that a few arithmetic conditions hold simultaneously. First, $b$ must divide $a$, meaning $a$ is an exact multiple of $b$.

codeforcescompetitive-programmingbrute-forceconstructive-algorithms
CF 1088C - Ehab and a 2-operation task

We are given a sequence of integers and allowed to repeatedly apply operations that affect prefixes of the array.

codeforcescompetitive-programmingconstructive-algorithmsgreedymath
CF 1088B - Ehab and subtraction

We are repeatedly performing a global “level reduction” on an array. At each step, we look at all positive values currently present, identify the smallest among them, output that value, and then reduce every positive element by that same amount.

codeforcescompetitive-programmingimplementationsortings
CF 1104A - Splitting into digits

We are given a single integer $n$, and we want to represent it as a sum of positive integers, each between 1 and 9 inclusive.

codeforcescompetitive-programmingconstructive-algorithmsimplementationmath
CF 1104B - Game with string

We are given a single string consisting of lowercase letters. Two players alternate turns, and a move consists of picking a pair of identical characters that sit next to each other in the current string and removing both of them.

codeforcescompetitive-programmingdata-structuresimplementationmath
CF 1160A2 - Collaboration

We are given a base and a collection of job sites on a grid. Each job site describes a task located at a coordinate, with a fixed duration, a required number of workers, and a time window during which the job must finish.

codeforcescompetitive-programming*special
CF 1219G - Harvester

We are given a rectangular grid of values, where each cell represents how many bubbles can be collected from that position. Johnny can activate a harvesting operation at most four times.

codeforcescompetitive-programmingimplementation
CF 1219C - Periodic integer number

We are given two numbers. The first is a fixed block length L. The second is a very large integer A, given as a decimal string so it can have up to 100,000 digits.

codeforcescompetitive-programmingimplementationstrings
CF 1230B - Ania and Minimizing

We are given a very large decimal string representing a number with exactly n digits. We are allowed to change at most k of these digits, one position at a time, replacing a digit with any other digit from 0 to 9.

codeforcescompetitive-programminggreedyimplementation