<almost-copy-pasted-part>

Hello! Codeforces Round 579 (Div. 3) will start at Aug/13/2019 17:35 (Moscow time). You will be offered 6 or 7 problems (or 8) with expected difficulties to compose an interesting competition for participants with ratings up to 1600. However, all of you who wish to take part and have rating 1600 or higher, can register for the round unofficially.

The round will be hosted by rules of educational rounds (extended ACM-ICPC). Thus, during the round, solutions will be judged on preliminary tests, and after the round it will be a 12-hour phase of open hacks. I tried to make strong tests — just like you will be upset if many solutions fail after the contest is over.

You will be given 6 or 7 (or 8) problems and 2 hours to solve them.

Note that **the penalty** for the wrong submission in this round (and the following Div. 3 rounds) is **10 minutes**.

Remember that only the *trusted participants of the third division* will be included in the official standings table. As it is written by link, this is a compulsory measure for combating unsporting behavior. To qualify as a *trusted participants of the third division*, you must:

- take part in at least two rated rounds (and solve at least one problem in each of them),
- do not have a point of 1900 or higher in the rating.

**Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.**

Thanks to MikeMirzayanov for the platform, help with ideas for problems and for coordination of my work. Thanks to my good friends Mikhail awoo Piklyaev, Maksim Neon Mescheryakov and Ivan BledDest Androsov for help in round preparation and testing the round.

Good luck!

I also would like to say that participants who will submit wrong solutions on purpose and hack them afterwards (example) will not be shown in the hacking leaders table.

</almost-copy-pasted-part>

**UPD**: Editorial is published!

Auto comment: topic has been translated by vovuh (original revision, translated revision, compare)I hope it will be a good contest!

I hope this round will rebuild our shattered hope on easy rounds.

This is QUALITY comment how could anyone dislike it?

Teacher: What is most available free stuff in the world?

Student: CF downvote, Sir!

Vovuh's rounds are always good!

How do you know??. You've never participated in any of his rounds.

we all know, not only him.

I wrote his problems on Vjudge.

After this contest my final exam will be started....But I will keep doing contest

Best ways to increase your contribution :)

That means It's also a tricky part...

You guys makes me disappinted..The comment is hidden because of too negative feedback, click here to view it

and make a memes for contribution guys XD

Thanks MikeMirzayanov for adding Diagnostics Hint feature on RE.

Sorry to disappoint you but the diagnostic hint is disabled in contests.

This is participants attending this contest at night 24:00.

I think I will become one of the cods :(

Will the downtime of polygon affect us? Will there be testing in the contest?

don't worry, it is fixed.

I didn't do much with my youtube channel recently because I was busy with summer schools and stuff, and this is bad for publicity :)

So I guess I will do screencast with English commentary for this round and I'll try to go more in depth about solutions. That is, if Mike and team will fix Polygon. Hope to see you on the channel!

deleted

After the contest, of course. This round is rated for many people.

it seems that Polygon is fixed, at least temporarily.

Is there any negative point for the unsuccessful hacking attempt during the 12 hours of hacking period?

No. And no positive point for successful hacking attempt either.

Unfortunately there is an issue with CF-Predictor and it will not be available during coding phase of this contest. CF-Predictor is going to be back after 22:00 UTC today.

I'm very sorry for the inconvenience.

Any update ?

It's working again!

Me before Contest : second thing don't tell what you think I will be I'm the one at the sail I'm the master of my seeeeooh oooh

After Contest : Paaaaaain you made a you made a believer

No stress Happy round

Long queue times anyone? Sorry posted previous comment in russian :C

Oh my god! Queueueueueueforces

Please, do not be Codeforces Round 536 (Div. 2)

The system is not allowing me to submit even a single solution. It is always showing "You have submitted exactly the same code before". please help!!

It means that the the solution has been submitted. You don't have to submit again.

It was showing that for different code. I only was able to submit on m2 then.

Thanks for the round. It sucks. Can u fix your servers pls, the submission was in queue for about 7 minutes. Make it unrated or increase the time. Thanks

Please be patient, they said they are fixing it, besides it's happening with all of us.

To solve problems or for learning from this platform, we don't need to pay anything. It's totally opensource. This community help us with many things. Imagine the number of submissions per moment. It's pretty obvious that there will be problems sometime. Just be patient.

contest should be unrated i submited my solution 12 mins ago

Queueforces Div3

I use gmail for codeforces. How can i enter in codeforces2?

Yes I also need to know something about this ; If anyone can help...?

use "Forgot your password?" option in login window to create a password on codeforces.com. You could then use this to login to m2.codeforces.

thanks, man

Thanks...!

MY CUR PING : 600000 ms and it keeps on increasing :/MY CUR PING : 600000 ms and it keeps on increasing :/UPDUPD: Ping is the reason of my same two commentspls make it unrated!!!

Contest extended by 20 minutes, but the situation that has already happened cannot be reversed. It's not good for successful contest. :(

make this round unrated

Wondering what happens if you hack a solution, and it gets compilation error.

Me waiting for the verdicts.

deleted

Is there a solution in python that runs in time for D2? If not, then why support it at all!

frustrated^^ The problem was very nice to think about, thank you — I am curious what I did wrong...there is. check mine https://codeforces.com/contest/1203/submission/58739316

thank you for your reply, I see; at least my idea was the same.

Hm, that's not a python solution, it's a C solution written in python :-) I tried using str.index() etc, but this seems less performant, strange, I thougt builtins should be better than loops...

I also would guess that str.index() is would be faster than a loop. Just checked your solution at https://codeforces.com/contest/1203/submission/58751526 The runtime is |s| * |t| so it is not optimal. It's not because of python. :)

I also solved it in Python, so yes, there is.

What is TC 37 in F1 ?

not offical

2 301 10 -1 300 -300

in my case ，，if you solve it greedily，，it will WA

Thank you fengjk Can you give me a hint to solve F1 ?

Sorry for slow website and judge queue. I think it was the first major queue during the last months. Actually, I do not understand the reason for now: is it because of too heavy tests + easy problems or there is another reason. I'll investigate it. I'm doubly upset because I was thinking about ideas for these problems for several days (it seems that all ideas belong to me). I hope you enjoyed the problems!

Even though it queued a bit in between, it turned out to be a good contest. At least for me, I enjoyed it.

Really enjoyed the problems, Thanks a lot

Hello... I login into codeforces using the gmail account ; but it was not there on the alternate version of the website ( The light version ) ...

Is there someway of login on that light version for people who login there accounts using gmail...? Please suggest ; thanks in advance...!

Edit : Got it...! Thanks...!

Are you feeding the hamster properly?

Upd:now I got what is the problem with C. Can you tell me what is wrong with other ones?Can someone please tell me why I got WA on all of my submissions in this contest? (except A)

https://codeforces.com/contest/1203/submission/58755675

https://codeforces.com/contest/1203/submission/58763681

https://codeforces.com/contest/1203/submission/58744361

https://codeforces.com/contest/1203/submission/58770060

In C elements up to $$$10^{12}$$$ you must use long long

Thanks, but in line 29 I have #define int long long

Maybe t = gcd(tmp, t)

What is testcase 33 in D2?

Failed to solve a QUEUE question in interview this morning, and now CF is showing me QUEUEEEEEEEEE. God's pun game is strong :(

Could have made WA to AC if it wasn't QUEUEEEE, this is frustrating..

I think the order should have been C-A-E-B-D-F, but I suppose it doesn't really matter in Div 3 contests.

how to solve F2? I spent 2 hours thinking :( . Is there some standard algorithm?

First do the ones with positive reward, then most possible ones with negative reward by knapsack.

in queue:)

R.I.P QUEUEFORCES

36 hours hacking phase?

F2 is similar to Problem I in NWERC2017.

why is the open hacking phase of 36 hrs??

It is a mistake, it will 12 hours. I'll fix it ASAP.

this contest —

queue= PERFECT!!Why the duration of open hack is 36 hours, not 12?

Why does the timer for open hacking (https://codeforces.com/contest/1203/standings) say that the open hacking phase lasts over 35 hours?

still 36 hours open hacking?

see it fixed. we should be patients

Contest was nice.

This contest should get unrated. I had to wait for a long time to see the whether the test cases passed or not. This wasted a lot of time of mine.

Fully agree with you

I think, you should solve further tasks instead of waiting verdicts

Next time you should work on other problems while it is testing, so you are not wasting any time.

it seems Dsiv.3 always have a huge number of participations this round have a 13216 participations, which I think is one of the most participations in contests. maybe it should increase the number of Div.3?

Increasing the number may cause the quality goes a little bad. Plus, there is once-a-week Educational rounds.

Screencast with commentary

How to use m2.codeforce?

I only use the auto?(one click?) login of Gmail.

You need to set new password with "Recover password" link.

Please help with the solution of F2

I'm getting WA on test case 18 in problem D2. Could someone help me to figure out what is going wrong. This is my submission 58778018. Thanks in advance.

Replace else in last for with

`if (i < n - 1)`

, because there is a case, where removing substring is between $$$pre[0]$$$ and $$$suff[1]$$$.how to solve f1 ??

Does the hacking in hacking phase gives points?

no

How to sort the input in optimal order in F2 ?

In question C I got TLE in this submission 58730683 and pretest passed in this 58757237 can anyone explain why ??????

Maybe it's because of the time it takes your gcd function to go from one step to the other

I also got TLE in test 5 during the constest. I used faster input methods and got AC. As you can see your solution ran in 850 ms, which is just a bit below TLE.

I think the problems are really great, if it not were for the technical issues it might be an excellent contest.

Best ways to get downvotes in a div.3 post:

Lv.1 wish a good contest!

Lv.2 No broken div.3 again!

Lv.5 WTF, this is a div.2 or even div 1.5!

Lv.10 See this is good examples of div 3...........

Lv.100 This comment is hidden because of too negative feedback, click here to view it

Lv.999 Please give me upvotes.

The common divisor of 2 integers $$$a, b$$$ is the divisor of $$$gcd(a,b)$$$. I tried to prove in the way.

Every integer $$$x$$$ can be rewrite under the form of multiple of prime factors:

$. &

We construct $$$gcd(a, b)$$$ by choosing all common prime factors p with the lowest exponent each factor.

And, we construct a arbitrary common divisor by choosing some common prime factors with the exponent each factor always less or equal to the lowest (i choosed in gcd).

Following this manner, the common divisor of $$$a, b$$$ is always divisor of $$$gcd(a, b)$$$.

I think this Codeforces round is a bit easy, but it's still very good, too. A good writer with a good round.

thank to the extend 20 minutes, I can solve the D2 in the last minute. however, waiting for 3 problems' judge is not a good feeling. hope nobody hack me so that i can be an expert this time.

How to solve D2 Remove the Substring (hard version)(https://codeforces.com/contest/1203/problem/D2) ?

There are 2 cases: 1)Answer — prefix or suffix of string s 2)Consider 2 subsequences: leftmost and rightmost.Assume that we take first i letters from leftmost subs. and the rest we take from rightmost.So you have to check all values such as : rightmost[i + 1] — leftmost[i], and maximize it.

is this contest rated??

Yes.

Can F1/F2 be solved by some Greedy approach? Many solved it by Dynamic Programming. I tried Greedy during the contest but it failed.

if bi is bigger than 0 then use greedy, add them all if ai is smaller than r. and for left bi which is smaller than 0 use dynamic programming

Can someone explain the idea behind problem D?

find the rightmost place and the leftmost place in s for each letter in t, then (leftmost[i] — rightmost[i + 1]) for every letter in t, get the max one, that is the answer

Problem F is a cleverly disguised "regular bracket sequence" problem. See 1745 on timus.

Editorial by me incase anyone still needs it:

A. Circle of Students

explanationRotate the array so that 1 is first. Now we have to check whether (eg. n=5) it is equal to 1,2,3,4,5 or 1,5,4,3,2

solnB. Equal Rectangles

explanationConsider the rectangle with the largest side X. Wolog it must be paired with the shortest side Y — otherwise we have X >= A >= Y >= B and so rectangle areas AB = XY >= AB. In particular there are 2 copies of X and Y. We can repeatedly form rectangles in this way.

solnC. Common Divisors

explanationConsider the greatest common divisor g of a_1, a_2, ..., a_n. We want the number of divisors this has, which is (e_1 + 1) * (e_2 + 2) * ... * (e_k + 1) if g has prime factorization g = (p_1 ^ e_1) * (p_2 ^ e_2) * ... * (p_k ^ e_k).

solnD. Remove the Substring

explanationSuppose we write T = L + R. If i is the least integer such that L is a subseq of S[:i+1], and j is the greatest integer such that R is a subseq of S[j:] then the candidate answer for that split is j-i-1.

For every possible split of T, we can find out these i's and j's with a greedy method.

solnE. Boxers

explanationThe set of boxers that could be weight 2 is a superset of the ones that could be weight 1. This means that wolog, we should try to make weight 1 boxers first (as it will give potentially free space for boxers with weight 3).

Continuing this logic, we can see that we should try to make boxers in order of weight. Also, when trying to make a boxer with some demanded weight D, we should choose in order from lowest to highest weight, since a boxer with weight D-1 can only become weight D, a boxer with weight D could become D or D+1, and a boxer with weight D+1 could become D, D+1 or D+2, so their options are strictly dominated too.

solnF. Complete the Projects

explanationSeparate the projects (a, b) into 'positive' ones that give rating [b >= 0], or 'negative' ones [b < 0]. We clearly try all the positive ones first, in order from lowest a to highest a.

Now, negative projects can dominate each other: for negative projects (a1, b1) and (a2, b2) with a1 > a2 and b1 > b2, we always prefer attempting (a1, b1) first. So we can prove that wolog we should consider the projects in that order. So, sort the negative projects from highest a+b to lowest a+b, and do DP: dp[i][r] is how many projects we can take from neg[i:] with rating r.

solnHow can we prove that projects should be considered in decreasing order of a+b?

By exchange argument (Um_nik's video has pretty good explanation)

You actually watched this... I don't understand why, but ok, looks like it worth doing :)

I came up with knapsack idea but then could not figure out sorting order (I still don't get intuition behind it) and I wrote some really strange thing with bitmasks which worked somehow but I was sure there is simpler solution and there was no editorials so I checked the video. I did enjoy parts I have seen tho, if you're seeking for some feedback :)

Intuitive intuition: Let's look on the process from the end, working backwards in time. We have to have at least $$$a_{i} + b_{i}$$$ rating, and now these projects are good (we are going back in time so our rating will increase), and it is obvious that we should do the projects in order of increasing necessary rating (which is $$$a_{i} + b_{i}$$$ now).

Professional intuition: I'm sure that I should sort the projects according to some rule, so I will write inequalities for exchange argument and see what I get. You can see in screencast that at first I guessed wrong, and even with correct comparator I was unsure until I wrote the inequalities and everything worked out.

Lets say you have at the moment rating r. And you have (a1, b1), (a2, b2)... (an, bn). Assume we already have ordered set of problems we take (No matter what this order is). Then for each taken project: ai >= r + b1 + b2 + ... + b(i — 1). So you can add to both parts bi and get (ai + bi) >= r + b1 + b2 + ... + bi. So for each i you need ai + bi just not less than some const. That gives us right to assume that if we have correct order then you can take problems in decreasing order of (ai + bi).

P.S. There are some flaws I think, but common logic is the same.

Your inequality is wrong: instead of ai >= r + ... , it should be ai <= r + ... Since we require the current rating to be >= the project requirement.

Oh thanks. So final inequality is ai + bi <= const. And there is more logic to sort in decrease order.

Let say we have 2 "negative" projects (a1, -b1), (a2,-b2) with b1, b2 > 0 and a1-b1<=a2-b2 and we can successfully complete project (a1, -b1) first follow by project (a2,-b2). Then we can always change the order and successfully do (a2, -b2) first follow by (a1, -b1): + complete (a1, -b1) equivalent to r>=a1 and r-b1>=0. Then do (a2,-b2) equivalent to r-b1>=a2 and r-b1-b2>=0. + complete (a2,-b2) first equivalent to r>=a2 and r-b2>=0. Then do (a1, -b1) equivalent to r-b2>=a1 and r-b1-b2>=0. All these conditions can be followed from above (where r-b2>=a1 because we have r-b1>=a2 and a1-b1<=a2-b2)

Can anyone please help me to understand the problem E? I dont understand the problem for a while. It would be really helpfull. Thanks in advance. :)