
Hello Codeforces!
The series of Educational Rounds continues thanks to the support of the Computer Science and Artificial Intelligence (CSAI) program at Neapolis University Pafos, with scholarships provided by JetBrains.
Educational Codeforces Round 187 (Rated for Div. 2) will start on Feb/25/2026 17:35 (Moscow time).
This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest, you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.
You will be given 6-7 problems and 2 hours to solve them.
The problems were invented and prepared by Adilbek adedalic Dalabaev, Ivan BledDest Androsov, Maksim Neon Mescheryakov, Roman Roms Glazov, Maks FelixArg Novotochinov and me. Also, huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.
Good luck to all the participants!
Our friends at Neapolis University Pafos also have a message for you:
Admission is now open for the BSc in Computer Science & Artificial Intelligence. Up to 40 full scholarships from the JetBrains Foundation will be awarded this year, covering tuition, accommodation, insurance, visa fees, and a €300 monthly stipend.
JetBrains Blackbox Cup 2026 Join our new unique coding competition, happening on March 15, 2026.
- Imagine joining a project with no documentation and no backlog. Your mission: explore the system, uncover hidden logic, and start solving tasks — step by step, through experimentation and smart guesses.
- AI tools are welcome! AI assistants and modern developer tools are fully allowed — resourcefulness is part of the challenge.
- Two leagues: Junior — high school students & Senior — university students, graduates, and professionals.
Registration closes on March 13.
Winning the Blackbox Cup can also boost the chances of getting a fully-funded JetBrains Foundation scholarship for BSc CSAI at Neapolis University Pafos(extra points on the entrance test).
See you!
UPD: Editorial is out








SIX SEVEN
SIX ONE
You crazy? hahaha Borisaurus in not smile, +1 please
WoW !
SIXTY SEVENNNN
Why are there people with more than 2100 rating that have registered as an official participants?
Because when they are registering their rating was below 2100, now their rating has increased above threshold but because of some codeforces bug they still counted as official participants.
I thought its like this but AkaiLemon hasnt been less than 2100 since 2018
How do you know if AkaiLemon is registered as official participants?
Dont unrated people have a star before their name when registered?
but this round is unrated for people above 2100 ig so if you are <2100 it will be rated for u
if you keep going like this, in downvotes, then you'll likely hit a limit to 1 comment in 1 hour, but I think you can message support@codeforces.com or mikemirzayanov@codeforces.com and they might consider removing the limit
Thank you <3 Btw, how do you get that e-mail address? It should be in public somewhere.
I think I found them from ai, but I don't think they will answer such requests like "please remove my limit" but you can try
and also, how do you get neg contribution, like you didn't post anything, wasn't it -84 1 hour ago?
I need a strong reasonable excuse of why they should remove (or change) this limiter for me or for everyone with negative contribution before I can confidently contact them. I will think hard about it, hope I will come up with genius solution ;)
I'm experimenting with it, I think now I could reverse engineer the secret contribution formula. Maybe I could use this secret to negotiate with admin(?) not for now, I need much more evidence :)
i love edu rounds but the fact is it always decreases my ratings!!!
No testers???
Thanks for the round! Interesting to see the Blackbox Cup format—good luck to everyone participating!
When can I become purple
Guys, what are the differences between educational round and normal round?
In normal round, only score counts.
here it's first how many have you solved, than score
Thanks!
I wish I can solve C and become 1500 rating or above. I wish there is at least one problem in difficulty 1400 — 1600 for me to study.
cp just ruined my life, i hate cp im never coming back here
avoid watching cp then
wow so funny
thats what weak ppl would say, only losers quit
What is the point of these rounds?
Even contests like Good Bye 2023 are infinitely superior to whatever today's round was.
actually it's not very full right now
Actually, I fell educational rounds like math rounds?! Of course, it can be helpful for some people, but I think it should have a tag like "MATH-HEAVY ROUND". An educational round on a place where people practice algorithm should not have 5 out of 6 problems kinds of math =((((
Guys, I think you misunderstood my opinion. I really enjoy ICPC format, and I also like math problems too. What I am trying to say is that there should be some other kinds of algorithm in the round instead of so many math and observation-based problems in a round like this. I didn't intend to be that rude in this comment, just felt bad because of bad performance so pls don't downvote me T_T
I strongly disagree
I think what makes this round special and fun is the fact that it's in ICPC scoring it's a fresh and nice thing that you know that solving the problem is more important than not getting WA, plus it's really the format of most Olympic comp where number of sub doesn't matter
Sorry, trying to reply my own comment, but I instead I reply yours for mistake=))))
why is it so hard man:(
Nice round! Though I feel like C > D
agreed! Solve D but not C :v stuck an hour on it
Hey guys, During this contest and in the last 10 minutes, I headed towards B, I thought this would be a simple greedy algorithm, but I never really had learned any algorithm, I now have wrote this code
Its not even complete, If anyone knows what should I do next, please help me.
Well, it is a greedy=)))). We have a claim that a number is beautiful only if sum of its digits <= 9. Therefor, just continue replace the biggest digit with 0 (with 1 if it is the leading digit) until you have the sum <= 9. This is my AC submission for it 364339561
364348487 what's wrong in my soln :(
Well, your second loop for(int j = 0 ; j < int(s.length()) ; j++) choose the first index where biggest digit exist to change. But to optimize, it should be the last.
Consider 909, for example. If I understand it correctly, your code change it to something like 109 and then 100, but the best way is 900?! Try not to change the leading digit, since it is not the best choice, unless there is no digit in n which is equal to it
ohh.. ok thanx now it's accepted
already someone said but i hope it helps you understand a little bit
function F needs only one digit(zero to nine). so another number(10~ ...) is not beatiful numbers. this is the start.
and i solve this way. first enter the x as string. and do the for loop to init the vector (example, if x is 645 -> v = {5, 4, 5}, x'first can't be zero) and calculate sum of x in same for loop. and sort(v.vegin(), v.end(), greater<>()). until sum is samller than 10, subtract the v's element and count reps. that's it.
thanks
Solution of F: First put numbers from 1 to n on a binary tree, where the root is floor((1+n)/2), and the left and right child of each node represent the left and right range of the next step of binary search. For example n=12:
Then we can observe that for any two nodes u < v (proof omited):
(1) If u is ancestor of v, or the v is ancestor of u: beauty(u,v) = n-(v-u).
(2) Otherwise, beauty(u,v) = n- (2 + (size of subtree of right child of u) + (size of subtree of left child of v)).
We denote the formula above as n- (2 + RSZ(u) + LSZ(v)).
To calculate the answer, first we pretend that there's no situation (1). Then we iterate v from 1 to n, use a map to maintain for each possible size k, there are how many u < v such that RSZ(u) = k. By the structure of the binary tree, there are at most O(log(n)) different possible sizes of subtrees, so the complexity is O(n*log(n)).
Second, we need to deal with situation (1). Note that the height of the binary tree is at most O(log(n)), there are at most O(n*log(n)) pairs of nodes with ancestor relation, so we can brute force for every single pair.
Therefore, we solved the problem in O(n*log(n)).
Code example: 364371615
You can deal with both situations in one dfs: 364374549
Actually, it's possible(and not hard) to reach $$$O(n \log^t \log n)$$$(t is a number from 0,1,2, depends on how you write the code) for this problem.
For situation (1), we can enumerate the node with the smaller depth between u and v, and it becomes two range adds. There's $$$n$$$ nodes, $$$O(1)$$$ each, $$$O(n)$$$ total.
For situation (2), we can enumerate the LCA of u and v, and we only need to merge the nodes in the left subtree and the ones in the right. Since when a node has a depth $$$k$$$, there's $$$O(\log(n)-k)$$$ different values of $$$\rm{RSZ(a\ node\ in\ its\ left\ subtree)}$$$ and $$$\rm{LSZ(another\ node\ in\ its\ right\ subtree)}$$$, calculating this node costs $$$O((\log(n)-k)^2)$$$ (if you use map, there could be one or two $$$\log \log n$$$s), the total cost is $$$O(\sum\limits_{i=0}^{\log n} (\log(n)-i)^2 \times 2^i)$$$, which turns out to be $$$O(n)$$$.
Though, this optimization would give the code a great constant factor, it doesn't seem to be better than your $$$O(n \log n)$$$ one.
Man I almost got D but TLE is kicking my butt.
Though i couldn't solve problem C, i enjoyed thinking about. Any ideas on how to solve it?
hint just think in terms of bit you know that the answer will be sum of each numbers bit for example say 13 3 so you know that whatever a b c d e will be itll be just sum of bits of 3 so find greedily n using binary search or you can do this with in nlogs time
Man I have so much work to do, and I left all that in the hopes of giving this contest and solving some nice problems.
Wasted 2 hours of my time, and now I still have work to do. GGs.
In C, we were supposed to take ceil of s/m, given that the least bit of m must be less than or equal least bit of s, then answer exists. What am I missing?
try $$$m=73,\,s = 132$$$
in binary:
$$$m = \,1001001$$$
$$$s = 10000100$$$
Thanks. I found direct maxing when all bits are not on is failing and gives negative values so I think maybe a binary search approach will work for those cases. Another simple case I found is $$$ m = 10,s = 14$$$.
D is too IO-bottlenecked, it's not humane
Is there an easier way to solve E than:
It took me like an hour to implement this T_T (though my implementation skills have never been good)
Id also like to know if there is any cleaner approach. Only difference between my solution and your idea is that i used segtree for the (cnt,sum) part, then the binlifting becomes a simple find_kth in the segtree cnt field 364371413
Imagine the binary search you do in step 4 as you have a big seesaw with points that weigh down on it based on how far away it is from the center, and you are trying to find the center which balances the seesaw. You can do some math to show that the center should be the average of the currently active values so it suffices to try $$$O(1)$$$ choices for Alice near the average.
Based off this, all you need to do is maintain a set of active values, use lower_bound to find an element near the average, decrement/increment the iterator to get surrounding active values, and use your BITs to compute the best score Alice can achieve.
Does it not work if you try to locate the point in which the prefix sum is approximately equal to suffix sum of the sorted list of elements and iterate on values near there?
Yeah you can, but a lot of people died to the implementation of locating this point.
Hmm interesting. Maybe my implementation was wrong then.
My solution for E got TLE in Python, but after translating it to C++ post-contest, it got AC. Sad for Python users, it’s time to learn C++ I guess.
Otherwise, fun contest!
For C i though check all the bits in S(from MSB to LSB) where there is a one and find all distances after the postion of the one in S to the ones in M bits, if some of those distances have been found before do nothing and if not add the min distance, after that sum up all the unique distances as power of 2. I could not prove why it is incorrect yet it gave me a wrong answer on the last test case in the problem. Can someone help me?
Could any please explain solution to C?
$$$m$$$ allows us to use only certain degrees of $$$2$$$ to be used in $$$a_i$$$. The problem reduces to represent the target value $$$s$$$ as a sum $$$\sum 2^{k}s_k$$$ where $$$2^k \& m$$$, minimizing $$$\max{s_k}$$$
Notice that larger degrees of $$$2$$$ can always be exchanged into lower degrees of $$$2$$$.
Therefore the strategy is to do a binary search on $$$n$$$, for each guessed $$$n$$$ we iterate over allowed degrees of $$$2$$$ in decreasing order and subtract greedily
Understood, thanks!
but the s is not in 2^k so how we ensure that subtracting the highest value of 2^k will always give the best answer??
I saw a solution without binary search below, but in my solution we do binary search on the maximum number any of $$$2^k$$$ can occure in $$$n$$$.
Therefore my suggestion was not sutract the highest value of $$$2^k$$$, but subtract the maximal possible value not exceeding the current threshold (whihc we conduct the binary search on)
Why? My O(n log n) solution for Problem D got TLE on the 12th test case.364371872
for(int j=a[i];j<=V;j+=a[i])This can iterate V times for each i if
a[i] = 1You should sum equal elements
what the solution for d i tried to get every divs for each ele in b and check if it in a but i get tle
Hey,
can you please explain your solution for C. I tried going through your solution but didn't get it. I understood that we need to Binary search of some sort but unable to understand it. Help would be appreciated .
In C you can binary search the anwer. An element a[i] can only have some bits that m has.
To check for a value k if you can get the sum s you can assume that all k elements are equal to m at the begining meaning you have k instances of all bits in m you can use. Then you try to get all the bits in s.
You can start from the most significant bit. You greedily take bits starting from this bit to 0 and try to get it by summing the values of taken bits. If you cant get a bit you lose or else you move on to the next bit
For example: you want to get bit 3 with k = 2 and m = 3 (you have bits 0, 1) You first take all 3 bits 1 and have sum = 6 You still need 2 so you take 2 bits 0 and reach the sum
It is always optimal to take higher bits because lower bits can be used to create other lower bits and taking a bit wont mess up the sum because it is divisible by lower bits.
This kinda was my thought process
thank you so much.
I think C is definitely more difficult than D.Do you think so too?
And don't forget the magical
...
Yes, this problem really requires attention to constants. However, my code uses fast input.But it's okay, my problem has been solved.
Oh, sorry, didn't notice when first looking at the code you linked, you have by-character parser
i totally got cooked by C, reaching cm is so tough
Test Cases of D have IO Bottleneck.
My Contest Submission: TLE
Same Solution when attempted with this, worked:
Same Solution with Above Code: Accepted
Same issue here. Realized after contest that I didn't enable fast io and so did almost 10 to 12 submissions with tle
Same here. Took too long to realize... Never had problems without it here before this problem
Looks like D has very tight constraints. Can someone explain why my solution https://mirror.codeforces.com/contest/2203/submission/364365602
here gives TLE, whereas I can see similar solutions have got accepted
Maybe because of extra overhead, you are unnecessarily storing values in freq vector. Store them in simple vectors
I realized that in all my submissions, I hadn't enabled fast IO, that's why it was failing. Solved this problem pretty fast in contest but it didn't pass. Now realized it was the problem :(
It gives TLE because the nested loop that checks all multiples for every possible value up to n + m is too slow, especially when there are many test cases. Even when most values do not appear in the input, the code still iterates over them, leading to roughly (n + m) log (n + m) operations per test case. On top of that, large vectors are recreated for every test case, which adds extra overhead. Together, these factors make the program exceed the time limit.
I realized that in all my submissions, I hadn't enabled fast IO, that's why it was failing. Solved this problem pretty fast in contest but it didn't pass. Now realized it was the problem :(
B was nice
Can someone either prove or disprove my solution for C? If it's incorrect you're welcome to hack it :)
Let $$$f(k) = 2^k - 1$$$.
I claim that the answer is
where $$$k$$$ is an integer such that $$$1 \leq k \leq \lfloor \log_2(10^{18}) \rfloor$$$, and $$$\text{&}$$$ is the bitwise AND operator.
Submission: #364374403
EDIT: This has been answered here.
For D,
https://mirror.codeforces.com/contest/2203/submission/364378879 -this gives tle https://mirror.codeforces.com/contest/2203/submission/364379153 -this doesn't. why?
the only difference in both sol. is a extra set for all elements of b that isn't even used. weird
Most solve it as binary search solution, but actually there is an easier binary observation and this is the simplest approach.
Problem: 2203C - Test Generator Submission: 364327744
Since
ai & m = ai, everyaican only use bits that are already set inm. So eachaiis formed only from allowed bits ofm.First, look at the lowest set bit in
m, which is(m & -m). This is the smallest value anyaican contribute. So ifsis not divisible by this value, then it is impossible and the answer is-1. Also ifm = 0, it is impossible.To minimize
n, think in binary. Iterate over bits from 0 to 60 and keep:sum1: total value of bits ofsup to this bit.sum2: total value of bits ofmup to this bit.At any prefix, to build
sum1using numbers formed fromm, we need at leastceil(sum1 / sum2)numbers.Take the maximum of this value over all prefixes. That maximum is the minimum possible
n.So the whole idea is just binary counting, no need for binary search.
How do you prove that $$$\max \lceil \frac{\text{sum1}}{\text{sum2}} \rceil$$$ is not only necessary, but also sufficient?
Pareto frontier
The issue I have isn't that. It's not obvious how we can construct the final array since $$$\text{sum1} \mod \text{sum2}$$$ may not be a subset of bits of $$$\text{sum2}$$$. How can you guarantee that a valid construction actually exists?
The trick is that you don't just "fit" the total sum into $$$m$$$ once. You have $$$n$$$ different slots (elements in the array).Even if a bit in $$$s$$$ isn't in $$$m$$$, you can "break it down" into smaller bits that are in $$$m$$$. For example, if $$$s=8$$$ and $$$m=7$$$ (bits 4, 2, 1), you can't use an 8. But if $$$n=2$$$, you can break that 8 into two 4s (which $$$m$$$ does allow) and put one in $$$a_1$$$ and one in $$$a_2$$$.
Sufficiency: The condition $$$n \ge S_k / M_k$$$ literally means: "At this bit level $$$k$$$, do I have enough parallel slots ($$$n$$$) to carry all the value from $$$s$$$ that hasn't been placed yet?"
Makes sense, thank you.
It’s like water flowing down a series of pipes. The condition $$$\lceil S_k / M_k \rceil \le n$$$ ensures that at any level $$$k$$$, the total amount of "water" (the sum $$$s$$$) isn't more than the total "pipe capacity" ($$$n$$$ copies of $$$m$$$) available from that level downwards.
Because binary is powers of 2, if the "total volume" fits, you can always redistribute the water into the individual pipes as you go down.
Pareto frontier is better here to explain why only certain dp transition are required. Water flow analogy is more intuitional.
I have a solution for problem D but I'm pretty sure its not intended to pass.
I factorise the numbers and do some goofy caching to squeeze it under the time limit. I find the primes beforehand and then factorise and generate the factors for each number to tell if Alice can use the number or not.
An explanation of the intended solution would be interesting; or I'm not sure if my solution is intended to pass. I wasn't sure of the exact time complexity because of prime factorising and then constructing the factors for each number is difficult to bound.
E is really cool
Mostly probabilities are kind of disgusting but this one is really nice
But in comp I wrote i instead of n and forgot 1 modulo operation so no score for me :(
What's the reason to set $$$N = 5'000'000$$$ for pF? The TL/ML seems very tight under such constraint :/
Mostly to cut off FFT-based solutions because I think solving this problem with FFT is too boring. Unfortunately, it makes other $$$O(n \log n)$$$ solutions a bit difficult to squeeze, but the model solution is $$$O(n \log \log n + \log^3 n)$$$ and works in less than one third of the TL.
Can someone help explain C? I spent over half an hour on that but still can't figure out :<
ok so here is my approach for C instead of guessing n randomly i use BS we know n is between (0 to x) we pick a mid value and check is it possible to form s using mid value if Yes we try smaller n if No we need more numbers so we search higher
if you want i can share my code with you Peace:)
Assume that an array of length k can be generated, can you explain that an array of length k+1 can still be obtained?
If getting an valid array of length k is possible, then getting k+1 length array is also possible, as we can just add a zero to the k length array to get a k+1 length array, and this k+1 length array is still valid, as adding 0 doesn't change the answer at all.
omg I didn't even notice that. Thank you so much!
I sincerely hate the problem C. It made me green.
i am getting trouble while hacking the problems , the hacking page isn't loading at all :(
How can I solve the Problem C?
Problem F is so HARD, +1 please
Where is the Editorial??
I AbdGraph sincerely hate the problem C. It made me green.
Can anyone please hack my submission for problem D : 364389424
When will rating change reflect on account
Most probably within 6hrs.
till now nothing has been updated.why?
Has the rating been updated ?
still no
Can we do E better than n(logn)^2?
where do i find the solution for this contest
they will release the editorial for it shortly till then you can check your friends code!!
thanks
Apparently my yesterdays D solution would have passes with magic words : ios_base::sync_with_stdio(false), cin.tie(nullptr); Really... Before : https://mirror.codeforces.com/contest/2203/submission/364376838 After : https://mirror.codeforces.com/contest/2203/submission/364456720
dang, should have participated, cuz i solved ABD fast (3 problems)
When would the rating update, it's been quite a while after the system test ended.
when will our ratings be updated?
Can someone explain me how to do D please?
In number theory if we traverse for each 1 to n for each of their multiples in o(nlogn) this is the major hint of this problem
like for i from 1 to n -> for j from i to n/i ...
you can do the following:
how to find this triple? how to use this triple to solve the problem?
Any idea why no update to rating till now?
very nice round that i realy enjoy — nice and classics task — and one question why there is still not rating changes (i want my rating)
Hello, I would like to clarify that my submission for problem 2203D is my own original implementation of the standard editorial idea for this problem.
The solution uses a common and natural approach: counting frequencies, computing how many values from array a divide each value, and then classifying the elements of b into the same logical groups. Because this is the standard solution pattern for the problem, similar implementations from different users can naturally look alike in structure.
I did not copy my code from any leaked or public source during the contest. Any similarity is due to the standard nature of the solution, not to code copying.
I kindly ask you to review my submission again with this in mind.
Thank you.
364349636