
Hello Codeforces!
The series of Educational Rounds continues thanks to the support of the Neapolis University Pafos.
On Mar/17/2025 17:35 (Moscow time) Educational Codeforces Round 176 (Rated for Div. 2) will start.
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 or 7 problems and 2 hours to solve them.
The problems were invented and prepared by Adilbek adedalic Dalabaev, Ivan BledDest Androsov, Maksim Neon Mescheryakov, Alex fcspartakm Frolov 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 to the Computer Science and Artificial Intelligence bachelor's program at Neapolis University Pafos is open!
The JetBrains Foundation supports this bachelor's program and offers 15 fully funded scholarships for the most talented applicants. The scholarships cover tuition, accommodation, medical insurance, visa fees, and pocket money (€300 per month).
First admission round:
- Application deadline – April 23, 2025
- Entrance test – April 27, 2025
UPD: Editorial is out








Hope that we'll find a variety of topics in this round rather than only maths or bitmasking type problems.
I wish we could have a
fair and enjoyable round! No cheating, just honest participation!
Edit : Why does it always happen when I wish for something not to?
lets see if -100+ is possible or not
score distribution?
There is no score distribution in an educational round.
meaning?
Educational rounds follow extended ICPC rules. You get 1 point for each problem solved, and there is a 10-minute penalty for each wrong submission before a correct one.
wont we get any elo?
We will.
I got 41 penalty points does that mean i loose elo?
Check out this blog : Open Codeforces Rating System [updated on October 2015]
Bro last question. I did not get my elo yet.
Hacking round is still ongoing
Oh after haking we get the elo.And what is the haking round do we have to do there?
This is a gr8 guide to understand hacking phases
Ok after hack round is over do we get elo?
You should have gotten you rating change!
The hacking phase is over. I only solved 1 problem. I didn't get any elo so far.
You'll probably get it soon. It takes some time.
It might be that you accidently participated in the contest unrated!
how do i become rated? i infact am unrated. sorry if this is a silly question
Well, in some contests, it allows you to participate unrated. You might have done that, and that's why you didn't get any rating!
1-1-1-1-1-1
Hope to enjoy this round without any technical issues. Because, the calendar has a less number of rated scheduled contests this month.
Why adamant about not keeping educational rounds on saturday sundays
Why this post has less up votes??
I really hope enjoy this round without the server acting unstable for no reason
bruh my alarm didn't ring
I literally registered for this contest seeing that one of my friend has already solved problem A in 2 minutes and started this contest like 5 minute late
your pfp was me 30 minutes ago
Yesss, finally, I will be back to CYAN today, inshaAllah! Scored 'C' just 13 minutes before the ending! It took me 3 unsuccessful submissions and a long time to realize that 'B' was that much easy!
what was the approach for 3rd bro i tried but failed
Bro, we need to choose a pair every time ensuring their "SUM" is at least 'N'. When this "AT LEAST" thing come to your mind, this is something "BINARY SEARCH". At the same time, you need to make it optimize that how many such index exists for the current index that if you form a pair their "SUM" will be at least 'N'. Then, when this "HOW MANY THING" come to your mind you need to sort the given array and use "PREFIX/ POSTFIX" sum array to optimize the counting approach using "BINARY SEARCH".
One important point, if the value of an index is 'N', then make it 'N-1' before processing. Because, we need to make 'N' by taking at least 2 indices.
Now, you can see my submission to align this approach in a better way. (I named the array preSum. It's actually postSum.)
actually i tried but can't figure out what's wrong in this
Hopefully, next time bro. Don't give up.
wtf was B
Solve for k=1 separately
Fr bro, made me cry when I realised
How to solve E
P.S. C << B
for each array , you can place at most 2 different values in each. suppose p,q in array a and l,r in array b; p>=q, l>=r; if p!=q and l!=r , you can place it (pow(2,n)-2)*pow... ways for each set of pqrl. you have to count combinations of p,q,r,l here observation is , p^q^l^r=0; i used digit dp here. there are some other combinations p==q, l==r it's easier to compute.
thx
any hint to solve b?
handle k is equal to 1 case explicitly otherwise it's just summation of maximum k+1 elements from the array
omg, I'm gonna kill myself. I thought about that, but I didn't consider k = 1, and get wa
did you try c?
yeah. Actually C was easier than B
can you tell me what is wrong in this code? i am confused
v[i] = min(v[i], n-1); do this and it will work
why cant I submit solution now that contest is over
is there any smarter way of doing 2F without some cosmic-tier binary search/sweep line jank
I think divide and conquer works.
For each $$$i$$$, we find optimal $$$j$$$. Let $$$solve(l,r,a,b)$$$ mean that we are solving $$$l...r$$$ and their optimal $$$j$$$ are in $$$[a,b]$$$. Then, find the optimal $$$x$$$ for the index $$$mid$$$ and call $$$solve(l,mid-1,a,x)$$$ and $$$solve(mid+1,r,x,b)$$$.
Actually the sweep line is not that complicated, you just have to notice that the best endpoints are $$$l,r$$$ such that $$$a[l]$$$ is the unique minimum of its prefix and $$$a[r]$$$ is the unique maximum of its suffix (in this problem it really helps visualizing the array as points in 2D).
And now the candidates for $$$l$$$ and $$$r$$$ are decreasing sequences, because of that, for each element, the endpoints that it appears in are a range of each sequence (i.e. the 2D conditions are now easier 1D conditions).
And then you do the sweep line of the biggest range intersection of the second sequence given that only pairs of ranges that contain me in the first sequence are alive.
it took me like 10 minutes to come up with that but 10x longer to implement
Not sure if this is the same as your solution (i don't understand how line sweep can be used here) but using the same ideas.
Find the possible values of l (prefix minimums). And for each element i, the range of values of l for which it can appear in the sequence, lets call this range (l_i,r_i).
Now we iterate through the possible values of r (suffix maximums) and for each value of r we find the largest subsequence. To do this we initialise an array arr to all 0s. For each element i<r and a_i<a_r we add 1 to all indices between l_i and r_i in arr, then the maximum element in arr is the answer. We can do this efficiently with a segment tree, since r is a decreasing sequence and a_r is an increasing sequence, each i will be added and removed at most once from the tree.
Panicforces.
WA multiple times, I'm cooked.
Could you please give me an explaination why problem B can be solved in $$$\mathcal O(n\log n)$$$ easily but $$$n\le 5000$$$?
two pointers on 2D prefsums
imo this is much harder than what solution I wanted to express...
ofc, but this implementation is not for div2b i think
Misdirection
is this really allowed in pB? I have just known that pA could (and should) be have smaller constraints.
there are two cases
when
k=1: you will take any element, and take max of first and last if available.Logic: As you have can only paint in one direction, you can only take max of first or last element
when
k>1: you will just have to take sum of k+1 max elements in array!Logic: Fix range to minimum and maximum index of k+1 max elements
Is "D" Bruteforce?
same question, I thought of bf but have no time to implement.
Yes, try every possible subset for $$$x$$$ and $$$y$$$ which are disjoint and reduces $$$x$$$ and $$$y$$$ to the same value.
It was dp, a normal knapsack dp
Can you explain, please?
Notice that dividing by 2^k and taking floor just means removing last k bits of the number. Making the 2 equal will mean (a<<i)==(b<<j) for some i,j. Also notice that if you apply operations using 2^i1 and 2^i2, it can be done in one operation of using 2^(i1+i2) (removing i1 bits and then i2 bits is equivalent to removing (i1+i2) bits together). Thus all you need to do for each i, either remove last i bits from a, or remove i bits from b, or just skip the current bit and mive to the next one (this is just standard knapsack).
My solution for reference
why does my D solution is wrong recursive dp + bits 311139765
Good C and D :)
The only unpleasant part is B, the too many "Announcement" are misleading and interferin :(
And hope the samples can be stronger.
why is time limit exceeding in my solution ????
vector ct(200000 + 1, 0), pfx(200000 + 1, 0);
You create two vectors, ct and pfx every time. If operations iterate over these vectors t times, the total number of operations can reach around 4e9 ((2e5 + 2e5) * 1e4), which can easily exceed the time limit.
Is there a reason why all of these submissions are the same for problem E? Either someone has several alts, or serious cheating is happening...
22R01A05B8 kushwahaarpit360123 vinay_m18
with several more (usually unrated or newbies).
Livestream on YT and link to telegram group with solutions A-E :/
sadly there exist multiple telegram groups sharing solutions to rounds, most of these cheaters just copy the code from these groups
ALL leaked solution :> (src -yt)
... ~~~~~
~~~~~
...
...
Rajkumar_24M11MC100 this cheater has same codes, nigga is so dumb didnt even think for a second before copy pasting the code lol. also look at his prev contests he has 0/1 submissions.
I saw that many of the top 200 participants are newbies, pupils, and specialists, which seems unusual to me. Then I checked some of their submissions, and guess what? Their submissions are quite similar to the ones you mentioned in this comment.
Problem B be like:
"Your first solution must be the sum of first $$$k+1$$$ maximum elements and you shall figure out the correct solution afterwards when you've already got a wrong submission"
Good contest, quite interesting problems.
Overall, not so bad of an Edu round. B was very educational lol.
How to solve B problem? IDEA please
Try to upper bound an answer, then prove that the bound is exact (except one corner case).
try to solve for k = 1 and for k >= 2 separately
311145412
my submission. But got WA
you are missing a case for k = 1, when corner values are maximum. example: {5, 1, 2, 3, 4} n = 5, k = 1.
Also you are sorting before storing first and last element.
D doesn't need any DP. I solved D with DFS, I try to guess the answer never greater than 100000. And it worked! :) :) :)
DFS is dp actually
No, I just used DFS to run out a answer map in home and submit. $$$O(T\times\log^2_2\max(x,y))$$$.
Check my code to see my strange solution :)
beautiful solution, i had only half an hour left after debugging B so couldnt spend much time on this :(
Is this based on the fact that the first 15 bits are enough since sum of first 15 nat nums is 120 = 60 * 2 ?
Edit :- Ok, that would tle
My solution(strange)
I observed the smaller answer map(formed locally) and found the law, then I formed the answer map in my program.
can you tell how you solved C
Think in terms of partitioning the fence of length n, if we have one partition of size p and another of (n-p) then we are interested in the number of ways to colour these two partitions using the ai we have, now we define X(x) = # (i: ai>=x), so basically we are interested in X(p)*X(n-p) but it overcounts some cases like (i,i) where some ai is >= n, n-p, so we have to remove such cases which would be equal to X(max(p, n-p)). You can count the frequency then form the X array, the further process is just implementing the above.
C 2 pointer trap can be avoided with binary search. I was lucky to choose BS instead of 2 pointer (for real)
there is nothing wrong with 3d dp . if you look other submissions , from msbs , why to only have equal reductions . That is underfit , u may even not be able to make things equal ofc excluding( u can make both as zeros which is not optimal alwys)
Wrongly interpreted my bad
BTW , you were very close .
I've just fixed my dp. Now it TLs lol, so I should probably think of another approach
Ohh overflow tle?
Daamn, I didn't think about precalculating. In this problem, it is a must. Also, I couldn't figure the error about properly computing cost of making both numbers 0 during the contest.
Indeed, an educational content here.
if we have to make x and y equal and they are not zero when made equal , msb1 , msb2 as to go to some common msb (reductions are msb1 — msb , msb2 — msb). but when they are zero that they do not have to be some common msb like 2^(-1) or 2^(-2) . one can have msb of 2^(-1) x is 0 , other can have 2^(-2) y is 0 .
e.g. 2 3
What I thought was If k>1 you can always choose any k+1 numbers in the answer. With this observation it was clear about the corner case. But due to a typing mistake and not caring about the overflow I got two wa but it's okay since I registered unrated.
Top 7 all from Japan :D
dumbest contest ive ever participated in. gl CM :(
Such a bullshit B
I really liked B tho
maybe I'm picking a side here because this contest is my best one yet
I tried solving problem D by finding the longest common prefix in the binary representation of x and y. This helped me determine the highest power of 2^k that divides each of them, which I called d1 and d2. Then, I used a DP approach with a state dp[d1][d2][60], where I tried to form two disjoint sets contributing to the smallest cost. However, I’m getting WA on test 2. Can anyone help me figure out the issue? Thanks!
Try:
1
17 16
And if you fixed that one and still didn't pass (as I did) try:
8 16030
CornerCaseForces
I am so dumb I should leave CP ATP
ALL leaked solution :> (src -yt)
... ~~~~~
~~~~~
...
...
Screencast with commentary
It's really really bad EDU, A is very bad, B > C and B's first test not a useful test. Make a good problem or don't make but give a useful test case LOL, B's test case always pass !!
I understand that B could be trivial, but how is A bad?
A is not like div2As, but I solved it easily :) but fr it's only implementation I think, no need to think :(
any hint for $$$D$$$?
Think in bit and optimised with dp
the closest to returning to blue, if I could realize x and y can shift same number in D and didn't write continue to avoid it
Please someone tell me how to solve c in a simple way. Please....
Look at my solution. You know that you only need to pick two colors and paint the planks such that starting few planks have same color of first type, while the rest have the same color of second type. Now, fix the number of planks having the type of first color and then check for the possible number of ways to select colors for the second type to paint rest of the planks. Now, suppose that you can color i planks with color-1 and j planks with color-2. Now, it's only possible when
a[color-1] >= ianda[color-2] >= j, which is the number of colors which can color at least i and at least j planks, respectively. Hence, total number of ways will be (number of colors having a[x] >= i) * (number of colors having a[x] >= j). But doing so, you're taking such indices for which color-1 and color-2 are same, so you need to subtract such cases. Just visualize it, the number of such cases will be the minimum of (number of colors having a[x] >= i, number of colors having a[x] >= j).nice solution too good. I also solved this problem after thinking so much. My approach is just visualise how we can get the answer if k == 2. then I created a general formuala to compute the answer for any k given. Here in my solution it does not depend upon value of n because if value of n will be greater than 1e6 then checking all could be a problem. but in my solution I will reduce the number of a[i] paints to n-1 if a[i] >= n because this is the thing which took me so much time to notice. Nice to see so much solution for a sinlge problem.
I don't seem to properly understand C. As a trivial/slow solution, I would apply the colors to the fence s.t. all of color i is on the left, and all of color j in on the right, and do this for all i and j. This only works if a[i] + a[j] >= n, and if so there should be a[i] + a[j] — n + 1 ways to do this, as seen in the sample testcases. We can express this as the following line of python:
res = sum(a + b - n + 1 for i, a in enumerate(l) for j, b in enumerate(l) if i != j and a + b >= n)But even this slow solution fails on many testcases in test 2 by printing a too high answer, for example this one:
l = [5, 6, 3, 4, 3, 7, 7, 4]gives the answer 210, but the actual answer from the judge is 182. Can someone help me understand where my error is?
Edit: n = 7 in the example
what if ai = n? is your formula correct?
Ahh, that's probably the problem, thank you
For B***
Sum of first K + 1 elements is correct but,
(what if k == 1, suppose the maximum is at any index != 0 and != n — 1 then we will always take the boundary elements of array, aka the last blue box)
:)
Are you guys able to see the standings
DPforces
Can someone please explain D, without magically defining DP.
Think like we remove i bits from the first number and j bits from the second number, now we want the minimum cost to do so which we can get by dp, dp[i][j] = minimum cost to trim i bits from 1st, j bits from 2nd
we find subproblem to solve in dp. how you found that dp[i][j] with the given definition is subproblem? also can you give me a hint to implement it?
Division by power of 2, is trimming off last i/j digits, so the question to ask would be how much should I trim from both so as to make them equal, the answer to that would be let's say we trimmed off i bits from x and j bits from y, now what is the minimum cost to do so?, hence you would be forming the dp states as dp[i][j]= minimum cost to trim i bits from 1st, j bits from 2nd
Thank you
Never felt so stupid solving B... Implemented maps, vector of pairs, custom sorts...just to be solved by k=1 explicit case.
Here is a different approach for C no problem https://codeforces.me/contest/2075/submission/311149194
I'm new here and don't know how to hack or generate test cases that can cause TLE for a given code. Can someone please explain this in detail or share any documentation where I can learn more about it?
good guide
E is very good problem although I can not solve during contest
When will the Ratings change??
System testing has finished already 4 hours ago. So, when will we get contest rating ?
very excited to get your cheating result?
Which cheating result ?
The one you got!
[REDACTED] FULLY WRONG, T.T
your greedy $$$Excess, X, Y$$$ would also fail at $$$X = 1, Y = 8$$$
bitstring in this case would be $$$1110$$$ which is impossible to split into something that would sum up to $$$1$$$ and $$$8$$$
dammit. Next time while posting some radical idea that everyone didn't think of, I'll AC everything first.
OvO — > T.T
Actually your solution was almost right, except a few edge cases. I have done it similarly. 311133606
By the way, how did you think of this test case? How do you think of such stabby cases in general?
there's no real strat for it cause it's just something you get good at
Top 7 contestants are from Japan in a row!
wow!!boom!!!
HEY adedalic, BledDest, Neon, fcspartakm, MikeMirzayanov
I HOPE YOU SEE THIS !!!
ChatGPT is now solving E like it's nothing, and most cheaters are blindly submitting AI-generated solutions.
I CAUGHT ONE: Aslaan_Khan in previous contests. His/Her ranking was between 4K-20K, but suddenly, BOOM — NEWBIE to SPECIALIST,
He/She completely SKIPPED PUPIL like some magic trick.
HOW DO I KNOW HE CHEATED?
maintoreturnjust to bypass detection.This is a serious issue. AI-generated solutions are polluting the leaderboard.
Codeforces MUST NOT FORGIVE Aslaan Khan Aslaan_Khan. هذا الرجل غش بشكل فاضح—jumping from newbie to specialist overnight, skipping pupil like it’s nothing. This is حرام against real competitors who actually work hard.
He SWITCHED LANGUAGES MID-CONTEST, had compilation errors because he NEVER ran it locally, and shoved the entire code into one line like some coward trying to dodge plagiarism checks. هل تعتقدون أننا أغبياء؟
This is a مهزلة. BAN HIM. STRIP HIS RATING. اجعلوه عبرة لغيره. If Codeforces allows this nonsense, the whole platform will turn into a playground for cheaters.
KAN, Una_Shem, geranazavr555, MikeMirzayanov Codeforces Headquarters, please listen!
This is not just about one cheater—this (Aslaan_Khan) is about the integrity of competitive programming. Watching someone like Aslaan Khan jump from newbie to specialist overnight, skipping an entire rank,
He switched languages mid-contest, had compilation errors (because he never ran the code locally), and even formatted everything in one line to dodge detection. This is blatant abuse, and it’s happening more and more with AI-generated solutions. If this continues, what’s the point of competing fairly anymore?
I urge Codeforces to take a stand. Ban him. Please don’t let cheaters like Aslaan Khan ruin what this community stands for.
@Aslaan_Khan Aslaan_Khan, your sudden leap from a 4K-20K rank to SPECIALIST raises major red flags. Your code was way too overly formatted and artificially structured, and switching languages mid-contest is sketchy. You didn’t even bother testing your code, just blindly pasted AI output. The one-line trick to bypass plagiarism checks? Unacceptable. This AI-cheating needs to end.
Very True... such students should be banned from these platform and also the placement opportunities...
I 100% CONFIRM Aslaan Khan (Aslaan_Khan) is a CHEATER! I checked his profile—his entire rating jump is FAKE (i.e in previous contest he struggle to get top 5k but now under 100), and all his solutions are AI-GENERATED GARBAGE.
Check his submissions and EXPOSE THIS FRAUD!
CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN! CF COMMUNITY EXPOSE THIS FRAUD(ASLAAN KHAN!
Found this cheaters linkedin account aswell https://www.linkedin.com/posts/aslaan001_codeforces-competitiveprogramming-specialist-activity-7307721338977234944-ESVH?utm_source=share&utm_medium=member_android&rcm=ACoAAErYq58BfLm57869foQzY0GvNKBet31_TJU Showing this as if its some kind of achievement, shameful person
This Aslaan_Khan is so sneaky! First, he deleted his linkedin post and made his linkedin profile private—what a shameful move. Then he went even further, changing his LeetCode username and LinkedIn URL to hide his tracks. But thanks to Codeforces, the truth is out!
Link of his Leetcode Account(with new username)
Link of his HackerRank Account
Link of his Linkedin Account : https://in.linkedin.com/in/aslaan-khan-1824a1272
I did some digging and found out that he runs a community called Algo Club PSIT, where he actively trains members to cheat and copy-paste solutions. He’s even the president of this organization and have a telegram group! This group is responsible for spreading solutions and ruining the integrity of coding competitions.
Link of Community
I urge Codeforces MikeMirzayanov, BledDest, KAN, adedalic, Neon, Una_Shem, geranazavr555, CF_CheaterHunter, vali, badriisurmi to ban this user and the entire community immediately. Cheaters like him are a disgrace to the competitive programming world, and strong action must be taken!
Biggest Cheater: arnabmanna
Auto comment: topic has been updated by awoo (previous revision, new revision, compare).
Fixed.
I hope it goes well.