Hi!

I'm honored to invite you to Codeforces Round #432, it will be held on 4th September 14:35 UTC. There will be 5 problems for each division, as usual, you have 2:30 to solve the problems. The contest was prepared by Lewin Lewin Gan, Artsem Arterm Zhuk and me.

The IndiaHacks Final Round will be held on 3rd September 12:30. Finalist must not discuss the problems after their contest.

The stories of my problems will be about Arpa, although in one problem you'll see Mojtaba Moji FayazBakhsh, my great teacher.

I'd like to thank Lewin, Artsem and myself (:P) at first, then Konstantin zemen Semenov and white2302 for testing the problems, Nikolay KAN Kalinin for helping us in moving the contest to codeforces and Mike MikeMirzayanov Mirzayanov for the great Codeforces and Polygon platforms.

The scoring distribution will be announced later.

Obviously, if you are interested in if the round is rated or not, ask in comments and get a lot of down votes.

**UPD**. There will be 5 problems for div.2 and **6** problems for div.1.

**UPD2**. Scoring Distribution: div.1: 500-1000-1250-1750-2000-2500, div.2: 500-1000-1500-2000-2500.

**UPD3**. Editorial is partially ready. I'll complete it soon.

Congratulations to winners:

Div.1:

1 . AngryBacon

2 . dreamoon

3 . sd0061

4 . W4yneb0t

5 . Um_nik

Div.2:

1 . miaom

2 . fzzzq2002

3 . igoodvegetableb

4 . _Lucas97 and Szymanski_w (WoW !!)

`Obviously, if you are interested in if the round is rated or not, ask in comments and get a lot of down votes.`

is it rated ? :))))))

wtf ? Just about 60 down votes ? :|

I want to ~100 or ~200 :D

`4nd September 14:35`

`3nd September 12:30`

Didn't know September had an extra "thirnd" and "fournd" days :)Thanks. Fixed.

and now we have 3th September ??

Thanks. Fixed.

WTF? Just say that the contest is rated. It's not a place for your stupid jokes. There are new users don't know if it is F**king rated or not!!! Hope statements are not s**t like your announcement.

Hah all those glass-hearted suckers downvoting me.

So unusual time for contest

Sorry, didn't notice UTC, thought it is Moscow time

If its rated than Cool and if not also Cool . But you should have said if its rated or not in ur blog post.Yes I though it was unrated because it was based on a contest that happened before which could cause a leak of problems.

I missed the round (HE India Hacks Finals) :( It seems that the time in codeforces calendar is wrong.

Oh no, I'm very sorry about that, I forgot to update it :(

Darn, forgot to check it was 12.30 UTC time. Should have got a notification at the beginning of the round :(

I also missed the round on Hackerearth and didn't registered for it too. So can i participate in cf round?

Yes, this is fine. We have a list of people who opened the contest, so you should be able to compete as long as you didn't open the problems.

Thanks for the contest. Indiahacks final sounds pretty tough. Will the difficulty be of a normal round?

A bit harder than a normal round.

just a bit harder?

Of course, the high rated orange gets upvotes for sarcastic comment while everyone else gets downvoted to hell.

Amazing community we have here.

Is it rated?

I hope to be specialist in the 50th contest for me :) Good Luck for everyone :)

dude, you don't know whether or not, it's gonna be rated!

Pretty sure it's just like a normal contest, other than difficulty.

good luck newbiex

Great contest with a great rank for me, I hope. It's true that I never solve more than 3 problems in a contest. Bring good luck to me and all of you, too!

I think, Arpa means "Artem", not "Artsem".

Still no one answered if the contest is rated officialy? What kind of joke is this? How can CF admins allow this

If you really didn't get,

Yes, it's rated.I asked same but I got many down votes :| why ?

you asked,but in bad place. and also in that place you should mention that it wasn't mentioned in the blog.-some people have algerie to "Is it rated?"-

Because you have done it for a joke.

Please include that in the post. I take CF round very seriously and you are making fun out of it

how could you say that ! this is your second contest

but if you are really active , why you still don't know that the round is unrated only when they say it in the announcement

Spoiler Alert!In fact,it is rated as usual.

So,don't ask the same questions unless you want to get a lot of down votes. :)

like you, and like me (because i know this comment will get lots of down votes) :)

I've advanced to the finals, but I'm in other country on bubblecup, so I had no time or posibility to take part in the finals, also I've not visited hackerearth website last days, in one word: I have no idea about competition, I only know who won it (from friend). Can I write this round?

Yes, this is fine. We have a list of people who opened the contest, so you should be able to compete as long as you didn't open the problems.

you are pasting your line again and again :D

So are Codeforce rating contest or this unrate codeforec.com contest on internet. Plz I now need now!

Thanks to CF calendar, I don't need to ask whether the round is rated or not. For those who don't know about this:

I don't even need the calendar to know this fact, this contest's name is "Codeforces Round #432" so since it booked a number (432) it means it's rated, also if it wasn't rated then there wouldn't be two divisions

I didn't know that. Thanks for telling us.

What a late time for Chinese players. I'm glad to take part in it ,but out of the curriculum...you know

An additional hour later for Korea, Japan and parts of Indonesia...

I'm a Japanese, and the contest starts at 23:35 and ends at 01:35. Also, system test will ends after 2 o'clock am. It is so late time for 9-th grader student.

But this is

earlier one I think. Some of past codeforces contests start at 00:05, 00:35, 01:35, ... In the worst case contest starts at 02:35 and ends at 04:35. What time do you think the ending of systemtest and rating update?????????I am so sorry to hear that,it is an earlier one indeed. But what makes me embarrassed is that I made a mistake.I regarded this contest will start at 23:35,I am so sorry. Wish us would have an interesting contest and have a high rating!

`There will be 5 problems for each division, as usual, you have 2:30 to solve the problems.`

Is 2:30 a usual time duration for Codeforces contests?

No, the usual time is 2:00 to solve the problems.

I think they mean usual for an IndiaHacks round.

is the contest rated ? :P

Are you moron?

You are already 9th that gives that question

It was 2.5 hours or more surprising when I first saw the game. As a Chinese player, I needed to go to bed after one o'clock in the morning, and I hope that tomorrow morning classes will not fall asleep. In addition, I wish codeforces would be getting better and better, and this competition can be rated normally. I wish you all good results in the competition.

WoW,I think it's an excellent contest. Although the contest will start at 22:35 in China. I will take part in it! :P

So is it like there are 4 shared problems in both divisions?

No. 3.

so right now there is two condition:

1.Div 1 is simpler2.Div 2 is harderso which one is correct??In fact, Div 2 is simpler than Div 1.

I know that,but from the place that 3 question are shared,question c,d,e div 2 is shared,so if C or D are harder than usual ,div 2 is harder,and if not both div are as usual as they were.(actully i'm not sure about what i'm saying:) )

Neither :)

can anyone say's what is the difference of CUP,and contest that based on CUP?

Maybe this article should just tell us if it's rated rather than warn us that question about rated or not will be down-voted.

i dont care it is rated or not. give me down votes

Hope to be rated.

yes, it is as you wish

After the contest you will hope it was unrated.

(Off topic question: is the previous sentence grammatically correct? If not, how should I say it correctly?)

FIX: After the contest you would wish the contest was unrated

But anyway, we are programmers, we code, we encrypt and decrypt. Grammatical mistakes are nothing.

"Grammatical mistakes are nothing."My compiler doesn't think so.

Didn't able to register IndiaHacks Final Round 2017 Div 2. On clicking the register button says page not working codeforces.com didn’t send any data. ERR_EMPTY_RESPONSE

Now working

I feel confused why there are many people who want to know if it's rated?

Hope clear problem description this time.

Love you Arpa

Hello I am your new competitor.

and how about me ? :DDD

shit veryyyyyyyyyyyy funny :|

I usually don't understand Indian accents. Will it affect my performance?

Dude i understand that you want downvotes, but being racist is just blatantly wrong and i think that your account should be temporarily suspended.

Nice joke with rate/unrate...

Good luck everyone! :3

Does Minimum Spanning Tree appears in any codeforces Div-2 contest? As of now, I haven't seen any :/

Why do you care if it appears or not?

Because he only knows minimum spanning tree hahahah

xD Thats one funny explanation

Arpa you and your teacher have almost the same rating. That's cool :)

Is it rated OR not? Yes!

in today's round ,will div1A==div2C or div1A==div2D ?

Less than 2 minutes until contest, and still no score distribution. Later means, after contest?

3rd contest with geom, I think I will lost my rating(

too weak pretests for problem D div2

Is it a thing that you can say during the contest? If your saying is true, many people that knows your comment use the different strategy.

is this mathforces??

codeforces is not taking submissions. Is there any issue with portal ?

wtf how much geometry ? 2 problems out of 5 ?? that cruel

Unable to see other's code for hacking :|

Why Unrated is higher than Rated?

I think Arpa and his teacher wanna to make more down rating users like them!

I think sum of all users rating changes in contest equal to 0.

Congratulations! I got many down votes because of baby who is you ;) Heyyy don't jump at me ;\

You were wrong and I won! First fact you got -50 Ha ha ha ha ha ha!

In Div2B, i have try to hack three different solution on same test case ,two of them giving "Yes" and one is giving "NO" as output still all goes unsuccessful. and try to hack a code in which he is dividing by 0 but still i got unsuccessful.

there is something problem in hacking ...please check

You didn't have three equal hacks by the time of posting, and all outputs were "No".

We need more geometry problems, why two only?you need more not me. you solved both problems?:)

WTF was this contest? I'll give you all diplomas.

Keep calm and just hate Arabs

I want Medal :(

upvote if you go to the CF to read the memes

Someone probably shared problems.

Probably my rating will go up, but I didn't like problems...

well the goal of the contest was to make it painful for div2 first : 2 geometry problems second : only 5 problems while div1 has 6 maybe an extra non geomtric problem would make it less frustrating

Hardest B-Div2 in the History!

Not that hard if you google it!

I don't understand why some people submit obvious wrong bruteforce for d(it's painful to hack them).

what's the solution?

I had solution where I generated primes up to 10^6 and done something with them + optimization. Is that bruteforce you are talking about or?

ideas on div2 C ?

I think this works.

First of all, dismiss the cases

n= 1,n= 2 as trivial (I failed to do this correctly on many instances).Now, note that if

n> 11, there cannot be any good points. (verify this with the 2 dimensional case, where a similar conclusion holds whenn> 5, and extrapolate). Nown≤ 11 and it suffices to simply brute force every triplet of points, which works in time.how did you up come with that observation ?

Intuitively, it gets increasingly difficult for a point to form an obtuse angle with every pair of points as the number of points get very big. My first observation was that there can only be one good point when

n≥ 3, since ifPis a good point, and soThen I realized it's difficult for even one good point to exist, which led me to the bound I found in the previous post (I think I have a proof, but it is quite messy).

could you explain in details about

`n > 11`

, please?It's nothing close to a formal proof, but the proof I have in mind is quite tedious, so I'll just give a heuristic argument.

Consider the 2 dimensional case of this problem. The maximum number of points there can be in order for there to be a good point is 5. (consider the zero vector and the unit vectors in each direction (+x,-x,+y,-y)). In the 3 dimensional case, it's also pretty clear that the best we can do is 7, with the same construction (except we add +z and -z). Extrapolating this way, I got my bound of 11 (although in retrospect I should have been more lenient, just in case).

Yup, i failed that n=1 n=2 this time...tried for an hour but that didnt cross my mind...well atleast this wont be happening again!

Wow,how did you think of this,I mean,as an amateur I thought that it's hard for a collection of a lot of points to exist such that some points are good among them,but to make SUCH A BOLD statement that, ans = 0 for n > 11..

I want to learn how did you think of this,and also how you convinced yourself.. I mean not intuitively but what solid reasoning made you confident on your statement?!

Thanks!!

I'm an amateur myself, but I think the intuition for this came from doing math contests (which I'm not that much of an amateur in), where I encountered similar problems. Starting with the 2D case was a natural step (I can actually draw the points!), where I noticed that 5 points was maximal. I didn't arbitrarily choose the number 11 and try to prove that it was maximal, but I think the extrapolation method is enough motivation.

I did come up with somewhat of a proof before I submitted, but I was fairly certain in my intuition. I generally wouldn't submit without at least a sketch of a proof.

pretty impressive,my background in math isn't that solid,for most of it I have studied only calculus and almost no geometry, Your statement was no less than MAGIC to me,seriously, I will try to keep this in mind,also if you can link some article or some proof,please do,I can't find one..

By the way,In the end when I was not able to think of a solution for Div2 C, I submitted a brute force solution which was O(n^3),someone told me 10^9 operations run fine on codeforces server,lets test that today :P

EDIT:I was unaware of the situation that for n > 11 the solution would be zero,so in order to make my N^3 solution run,I made a little pruning effort by breaking the loop in case acute angle occured,so my algo reduced to O(11^3) for n > 11,pretty lucky haha :DThat's good to hear. I think v_Enhance's post here serves as a nice proof (I forgot about this until now, oops.)

My code outputted "0" if N >= 100 and was a brute force otherwise. Does this work?

3 points form a triangle. At most, only one of those points can be good by definition of a triangle. Make a queue, pop 3 elements, append at most one. Brute force the points remaining (at most 2).

i would agree if we talk about 2D/3D. but in 5D i can't even imagine plane, so taking about properties of triangle in 5D sounds a little bit unreasonable

It is reasonable because when 3 5D points are chosen, they form a plane.

I think the same, but I implemented a thing like a sieve.

how to solve div2 B ?

fu**ing geometry

Assume a point of rotation exists, call it

X. Then clearlyXA=XB=XCand so It follows that it is necessary to haveAB=BC, and moreover to have thatA,B,Care not collinear. It is easy to see that these conditions are also sufficient, and we're done.You can construct a circle from 3 points (sorry for my horrible English)

The requirements are that the distance between A & B and B & C is the same and the points makes a right angle. Play with rotating triangles on Desmos.

How did you pass the pretests after getting WA #8 on C, those who did?

I had a silly mistake not taking into account values with only one prime factor(a typo), and that turned my wa8 into pretests passed.

Give me counter example for (ax-bx)*(by-cy)-(cx-bx)*(by-ay) != 0 (preset 6(

Use

`long long`

That was exactly what I did: http://codeforces.com/contest/851/submission/30078835

I see. You only test that points are colinear, but that is not enough. You should also check that segments ab and bc are equal in length.

What's up with tc 8 div2E?

This is what I did, let's calculate the grundy number G for each prime separately.

For a prime, if the powers of this prime in the array in the sorted order are P1,P2,P3...Pn.

Then, grundy no. for this prime would be P1^(P2-P1)^(P3-P2)..^(Pn-Pn-1).

So Arpa wins only if the xor of G for all primes is 0. Can anyone tell why this is wrong?

p1 = 1, p2 = 3 should be a losing state

your grundy number is wrong, I counted grundy by dp on bitmasks and it passed.

Yeah I get it. Thanks

What with states for 2?

I can't prove it, but there is small number of states even for 2. At least I tried on 2

^{29}- 1 and some numbers like that and it worked fine with map.fml seriously? I spent more than 1 hour thinking about that but I thought there would be too many states :(

I think that number of states is less than number of compositions of log(1e9) because when we divide by p^k than we subtract k from max{k1,...,ks}. Am I right?

Can div1 C be solved using grundy numbers, where each prime is equivalent to a nim stack? I couldn't figure out how to compute it though since there are too many states.

I like geometry problems. Only if i had read B and C today :(

Geometry everywhere

This submission for Div 2. D was TLE on pretest 10, does anyone see why? Should be O(10**8)

There are about 8e4 primes below 1e6. So, total number of operations is about 8e4 * 5e5 = 4e10. TLE thus.

Oh I see, I only tried primes under 1000

Im happy to see someone had this idea haha. I solved it same way except for one optimization but it didnt help (i thought its good optimization but looks like not really that much)

same here!! my solution doesn't pass, where m = 1e6.

When in the last five minutes you get hacked on Problem B after spending an hour figuring out that you need to use long numbers and when three points are in a straight line it doesn't work :(

getting hacked is better than failing in the system testing .

In problem B, i thought that only when AB = BC you can achieve thing described in problem. I coded but it failed on test 3. Why does it not wok?

If the three points are collinear it doesn't work

Why it does not work?

If you draw a circle that passes through the three points then you can rotate the page on the center of the circle. You can make that circle for all angles that the points might be in, unless they're collinear

The angles of BAC and BCA should be the same as well (but should not be collinear).

that'll be true if AB=AC

You should check if the 3 points are on a straight line.If that is the case ans will be no even if AB=AC.

Problem F in Div. 1 reminded me of this problem from Stanford Math Tournament a few years ago (scroll down to page 7).

Can a similar solution be used here?

Yes, it can be solved this way, but instead of just finding

f(1), one needs to addf(a_{i}) for alli.I still wonder how people solve this problem in 30 minutes, though :) It took me more than 90 minutes yesterday.

It's well-known in China. WJMZBMR created exactly the same problem back in 2012.

Meh, out of 13 people that have solved it, 11 are Chinese, so it seems you are right. That makes me even more sad that I made an error in my calculations which stopped me from getting AC on this.

Are the results published anywhere online?

The first contest in wich i solved D and not C. I didn't study n-D vectors in highschool lol

what was pretest 10 of DIV1C I calculated grundy number of each prime separately using DP.

Cf rules are stupid, it wasn't "enter the dragon" as I expected. XD

Tfw you find D and E easier than B and C. :/

:(

I like geometry and math problems much more than data structures ;d

The Best I Could Make Before my rating drops to Newwwwbie

What is wrong in this code ? Please help ...

dist1+dist2!=dist3 What is that? Why?

To check if they're not collinear

Might be double inaccuracy (e.g. abs(dist1 — dist2) = 1e-8 or some other very small number when they should equal). I kept it as long long (didn't sqrt) and compared the square of the distance so I could compare integers

dist1+dist2!=dist3 does not guarantee that the 3 points are not collinear

How ? Tell me any example .

for your code: (0, 0) (1000, 1000), (1, 1) in this order. they are collinear, but your code states otherwise

this case is taken care by the condition "dist1==dist2" if they are different then for sure the answer is NO but is they are same then only one condition can make the answer NO i.e when points are collinear and if dist1 is equal to dist 2 then the points are collinear only if dist1+dist2==dist3!!!

Floating point error due to the sqrt() function is the reason it fails

Man, I tried hacking a solution that did it, but I was wrong ;_;

Thing is...we have already checked if d1==d2 or not, if their sum is equal to d3 then they are co linear. So...you can just check if B is the midpoint of AC or not

Now I know mistake. Order of points may not be A-B-C. Maybe A,B,C are on the line but their order is C-A-B or something so dist1+ dist2 != dist3 but they are collinear.

There's nothing wrong in this code.

I have done the exact same thing and my solution passed system tests :)

I used long double instead of double for the distances and used sqrtl() instead of sqrt(), it got AC (after the contest).

good for you

How to solve Div2 B ??? I am Helpless in geometry ???

just check that if point B lies on the perpendicular bisector of line AC. and also these three points must not be collinear. if(B lies on perpendicular bisector of line AC than) print yes else no

Seeing all this I really beleive that becoming purple is really a far dream . :(

same as saying check if the triangle is isosceles!

For problem D, I had this approach (time limit on pretest 10). Generate primes up to 10^6. Idea is to find for every prime (not really EVERY, there is optimization) what is minimum that we can achieve to get all numbers divisible by that prime.It is easy to see that we will either delete some number or increase it prime — ( number%prime) times, so there is simple calculation for every number. Now comes optimization: If number of a[i] that are divisible by some prime > 2 is less than or equal to number of a[i] divisible by 2, skip that prime (because it will obviously make worse or same score as with 2). So, after we visit every prime, we will now best answer. I know this is overkill but I thought it would maybe pass because this optimization eliminates a lot of primes (or does it).

rating predictor

WHY problem C div2 solve with N^3 :(( :((

It cannot be solved by pure N^3, only with the fact that if the pair giving acute angle is already found, break the loop, which significantly reduces runtime.

I know this trick, I use it in D but I dont have reason use it in C... Why n > 100 -> write 0 :(( :((

First of all, my bad for having a wrong idea and not looking at test samples carefully but I think these kind of things shouldn't happen during the contest....

but they did not mention about the point C!

Hey no! Or else everyone's B will fail!

I'm really sorry. Excuse me. I remember that I was to press "No"... I don't know what happened, it seems I accidentally pressed "Yes" (in the drop down menu). Anyway, I'm happy that you get the correct answer only after 3 minutes. Sorry again.

If it only happened to me, it's fine. Thank you for an interesting problem set. :)

Yes, only to you. Thanks for your kindness, and sorry again :)

First Answer was right.... :)

So many people have solved div2 D , but I got TLE. What is the algorithm

You can enumerate the final gcd, and devide [1,1e6] to several parts like [1,gcd],[gcd+1,2*gcd],[2*gcd+1,3*gcd],and for every part the last x/y values should perform operation 2 for several times , and the rest should perform operation 1.And you can put the array in some bullets, and calculate the suffix sum of the bucket , and another special type of suffix sum which can be calculate like this: s[i]=s[i-1]+bucket[i]*i. And for every part you can calculate the ans under 'this gcd' in O(1) time,and for emutating gcd in and the parts in O(n/1+n/2+....+n/n)=O(nlogn) to solve the problem.

Sorry for my poor English.

P.S.: You can check the code by miaom 30061008

thx. 432 people passed pretest, and now 81 left. miaom code let me realize my algorithm is wrong(TLE)

(:з」∠)Wait — you need to check all possibilities for final gcd or what?

Yes, you should check from 1 to the maximum number of the array.

I think the point decrease speed was not adjusted for a 2:30 long contest.

NOT

ADJUSTED

DRAIN

NEEDS

TO

STOP

!!!!!

How to solve C? Don't tell me that the intended way to calculate the Grundy number is DP on bitmask...

PS: Btw, RIP yellow color T_T

I think the answer is "Yes". The number of states is pretty small.

How I can understand it, if maximum degree is 30 as log2(1e9)?

I also didn't solve the problem because of this, but now I think I understand why it works. Let's look at states by their maximum set bit. For states where this bit ≤ 20, we obviously have < 2

^{20}states that we can reach.Now for bits > 20, for example 23, the number of states is bounded by the number of ways we can reach 23 from 30 by performing subtractions each step, which is basically < 2

^{7}.In simpler words the number of states with the maximum bit

kis <min(2^{k}, 2^{30 - k}).I don't really get your idea there. Could you elaborate it more specifically?

Yeah, let me try explain it in a better way. The problem is when

p= 2 (pis the prime factor).Basically we'll have at most 1 state where the maximum nonzero bit is 30, at most 2 states where it's 29, at most 4 states where it's 28, etc. Thus we need to look at how many states that initial state spawns.

I think I get your idea. So, the maximum number of state is not 2

^{30}, but 2^{15}, right?Yes.

So it turned out that the solution actually involve an elegant observation, not just a "brute force and pray that it'll pass" problem.

Thanks for your explanation!

I think it is. For numbers bigger then 2 is easy but I can't show that for 2 number of states is small.

If we calculate only DP values that we really need, there could be much less values to calculate. But I can't even make an upper estimate for the count for these values...

If by "DP on bitmask" you mean "backtrack with memoization" then yes, I believe it's intended.

Wrong answer on test 3 (Div 2. C). What's test 3 ??? Why wrong ?

did you check the trivial cases

n= 1 andn= 2?I see a lot of submission for Div 2 C checking all i,j,k. And there I was thinking of some fancy algorithm to cut down the runtime :((

Not fancy algorithm, but you could use pigeon hole principle to return 0 immediately if n >= 244, and then brute force from there... Think that might be intended solution

Why 244? Is it actually possible to have 243 vectors from a single point whose respective angles are all not acute? I really hope not

EDIT: Okay, I outputted 0 for N >= 100 and passed.

Similar to editorial answer, but I instead considered components of each vector and whether they were positive, negative, or zero (three possibilities). 3

^{5}= 243Where do you get 244 from?

32 is optimal, never mind

http://codeforces.com/blog/entry/54265?#comment-384074

Are you sure about 244?

~~I can't imagine the example with answer >= 0 for more, than 32 points.~~Can't imagine it too.32 is optimal, never mind

http://codeforces.com/blog/entry/54265?#comment-384074

Where did you get 244 from ?

32 is optimal, never mind

http://codeforces.com/blog/entry/54265?#comment-384074

That's what I thought as well. After thinking for half an hour I came up with this: Consider three points. Draw lines between the three points and then you see that only one of them can be good. From there we can deduce there is at most 1 good point. You can now compare the first three points to find one that might be the good point. If the triangle created by the first three points is acute, then just choose one of them to be your candidate even though you know it is not actually a good point. Then do the same thing with your current candidate and some other two points you want to test. After less than n tests you will have a single point that may or may not be good. From there, just use an N^2 algorithm to see if it is actually good or not. I'm not sure if this works yet since system testing is not over but I'm just putting my thought out there.

EDIT: it just passed system tests

Oh that's a nice little optimization.

GeoForces!!!

Geometry Geometry everywhere :||||||||||||||

For Div2B : the two cases that can produce a "yes" are:

1- the triangle has 3 equal sides.

2- the triangle has a right angle centered in point b and distance(a,b) = distance(b,c).

what am i missing here ?

any isosceles triangle with ab=bc will do the job

No. The triangle must have a positive area and have a right angle at point b

No. Right angle does nothing. Center of rotation will be circumcenter of triangle ABC and only thing you need is AB = BC and A,B,C are not collinear. I dont know why you think right angle is important.

Yup, for me I checked that:

1- slope(AB) != slope(BC) AKA They are not collinear

2- |AB| = |AC|

If both above conditions are satisfied the answer is Yes. The gotcha for me was when computing the slope when ax == bx or bx == cx (since I ended up with a division by zero). So I added an extra condition to check for this. in the beginning

you can check the slope by multiplication:

(x1-x2)*(y1-y3)==(y1-y2)*(x1-x3)

There will be no zero division

Awesome! Thanks

anyone know how to solve 1B in a non-hacky way? I am no good at math

You can see my submission, it runs in O(10^6log(10^6)).

Can you please explain what's happening? I'm still confused.

My submission just got wa on 61. :(

I think it should be some edge case I missed (EDIT: yep, a very stupid one). What I did is fix some final gcd. Every number has to be a multiple of this gcd. We have two options, either delete the number or make it a multiple of this gcd. First find which of the options is suitable. Let's say you increment some number k times to make it a multiple of the gcd, then for it to be optimal, k*y must less than or equal to x i.e k <= floor(y/x) otherwise we could just delete the number instead of increasing it. Now fix two consecutive multiples of this gcd, call them z1 and z2 and z1 < z2. You need to change the numbers between them. So increase the numbers which are in the range [z2-k, z2] and delete the remaining ones i.e [z1, z2-k-1]. To efficiently calculate this, use some prefix sums.

My AC code: http://codeforces.com/contest/851/submission/30081999

Let me know if something is still unclear.

I thought I saw RoadToMaster's coding style and templates of problem D and E div.2 are different. Am I wrong ?

P/s. He/She is now at rank 8.

Ignore

In both cases, the answer is to delete all, isn't it?

What's the bug causes wrong answers here?

I think not considering x*n

Why the hell would anyone put 100+ test cases on div2A? It's just gonna take a really long time to test, and I doubt it will be more efficient than having like 30

I have a feeling that system test is going to destroy many people (including me) :v

many

O(n^{3})s passed on div1A. Why not maken≤ 3000?Because answer is 0 for

n> 64 and one will eventually end up with 64n^{2}operations??

so upper limit on n has no meaning, it can be even 10

^{18}But input would TLE on their side with 1e18 =)

Could you elaborate your proof for

n> 64?n > 64 is very high upper bound. Answer will be zero if n > 11. AC solution http://codeforces.com/contest/850/submission/30076671

I can give you an intuitive proof. First of all for n >= 3, answer could not be greater than 1, thus we only need to find this point. So lets think about the upper bound in 2D, then we will extend our solution to 5D. Without loss of generality, assume the point which we want to find to be the origin. You could only place 4 points(two on each axis, one on positive side and other on negative side of the axis) such that point at origin is a good point. Now think about 3D. In going from 2D to 3D we can only place 2 more points(on the 3rd axis) such that origin is a good point. Hence in 5D, there can be atmost 10 points excluding the origin. Thus for n > 11 answer will be 0.

My solution's complexity was

O(n+ 11^{3}), which is a pure brute-force solution after considering the above observation.Div.2 C:

`is acute (i.e. strictly less than 90°)`

but it was not said that acute is strictly more than 0 degrees.Let's continue your thought.

What if - 1, - 2, - 3, ... are also acute? What would it mean to be obtuse?

In div2D, isnt this conditions enough?

If initially gcd > 1, then answer = 0

Else

ans = min(cost(2) , min(cost(x)) for all x, where x is an odd number present in an array, and cost(x) is the cost to make gcd equal to x.

PS — got it, its wrong.

Consider such circumstance that you have an array teemed with odd numbers along with a single 1, where you will proceed cost(x) for N times.

No.

Let's say you have 9 14 15 21 the best answer would be cost(3).

Got it thanks!

3 1000000 1 9 9 2

'odd number present in an array' and 'GCD = x' may not satisfy at the same time

Okay, how about this case: 2 9 21 let modification cost to be A, removal cost to be exorbitant then cost(2) = 2a, cost(9) = 7a+6a, cost(21) = 19a+12a however,cost(3) = a

In this case the condition you have proposed seems to be insufficient.

The fact is it depend on prime make it :) :)

In problem A shouldn't an acute angle be strictly greater than 0°? https://en.wikipedia.org/wiki/Angle

When it takes you 5mins to read,solve & submit problem D(got WA but still impressed) :D

A similar problem was once on a Quera contest and here the pretests were too weak so you just had to copy your code from the other problem.

F seems cool. I have a pretty unproven guess at the solution. Maybe somebody could verify?

Let E(something) be the expected time taken for something to happen, and | inside meaning conditionality.

Let's ignore mod P, because we can.

ans = sum over colours of P(colour i dominates eventually) * E(1 colour let| colour i dominates).

So all we need is to evaluate E(1 colour let| colour i dominates). Clearly easy.

coughAll we need to care about is how many balls of i there are at a given moment. Define F(k) to be E(dominates starting from k balls of colour i | colour i eventually dominates).

We handwave and pretend that we can treat it as if transitions happen every step, but scale the duration of the step accordingly. (You are feeling extreeeemely sleeeepy...)

Then since we know that for an unbiased random walk starting from 0, the probability of hitting -a before b is a/(a+b), the transitions must be (conditionally) weighted in ratio k+1:k-1.

Now we form a linear equation for F(k): F(k) = T + (k-1)/2k * F(k-1) + (k+1)/2k * F(k+1), where T, the expected time is (kC2 + (n-k)C2)/nC2.

Solving this takes O(N^2) time and we are done.

Anyone knows if this is correct and if so, is there any way to justify the handwaving step?

"Then since we know that for an unbiased random walk starting from 0, the probability of hitting -a before b is a/(a+b)" — but here our random walk is not unbiased. I also don't get "the transitions must be (conditionally) weighted in ratio k+1:k-1."

Moreover I don't think that "handwaving step" is correct, I do not know how to exchange between problems with transition every step and not in every step, because avergae waiting time is different for different number of balls in our color.

Moreover I don't know where did you get O(n^2).

However I believe that we can reach conclusion using your logic. We just need to work out a lot of formulas and hope that we will get something that will be possible to evaluate in time.

Thanks for the reply.

The random walk is unbiased -- the probability of converting colour A to notA is the same as converting colour notA to A. (since the probabilities of exchanging orders of draw is the same).

For the weightage of the ratios, we have:

P(transition to k-1 balls | a transition happens and colour i eventually dominates) = P(k-1 balls eventually dominate)/2 / P(k-1 balls eventually dominate)/2 + P(k+1 balls eventually dominate)/2, where /2 is the probability of the transitions happening.

The linear equations are of form aF(i-1)+bF(i)+cF(i+1) = d. So the matrix looks like:

XXOOO|? XXXOO|? OXXXO|? OOXXX|? OOOXX|?

whereby gaussian elimination actually can take O(N) time.

Handwaving is handwaving. I can't defend that.

Screencast

LOL. Many O(N^3) solutions passed Div2 C. And all of them using C++. Why not decrease input to pass time limit not only using C++ ?