You are not logged in. Please login at to post your questions!


Invitation to CodeChef July Long Challenge 2018!

Hello CodeChef Community! We’re excited to invite you for the July Long Challenge 2018 sponsored by ShareChat. Join us for ten intense days of coding challenges! Joining me on the problem setting panel are:

I hope you will enjoy solving them. Please give your feedback on the problem set in the comments below, after the contest.

Contest Details:

Time: 6th July 2018 (1500 hrs) to 16th July 2018 (1500 hrs). (Indian Standard Time — +5:30 GMT) — Check your timezone.

Contest link:

Registration: You just need to have a CodeChef handle to participate. For all those, who are interested and do not have a CodeChef handle, are requested to register in order to participate.

Prizes: Top 10 performers in Global and Indian category will get CodeChef laddus, with which the winners can claim cool CodeChef goodies. Know more here:
(For those who have not yet got their previous winning, please send an email to

Good Luck!
Hope to see you participating!!

This question is marked "community wiki".

asked 06 Jul '18, 03:55

mgch's gravatar image

accept rate: 20%

edited 06 Jul '18, 12:54

l_returns's gravatar image


hoping my name in list of authors someday :(
Haven't got reply on my request of joining problem setting (before one month)..

(06 Jul '18, 12:46) l_returns4★

"Top 10 performers get laddus". Did Codechef update their rules? I hope it's just a typo :/

(06 Jul '18, 14:05) abdullah7686★

yeah I also think so because contest page shows different prizes according to division..

(06 Jul '18, 14:57) l_returns4★

Enough of waiting now !!!!
Unluckily editorialist gave all editorials of questions I already solved.... And editorials for questions I don't know are not out yet !!!
Contest Lasts for 10 days and editorialist gets solutions from starting of contest... they why this much delay ? If you don't have time then why to apply as editorialist ???
Please look into this
Aren't 13 days enough for 10 questions...

(19 Jul '18, 00:44) l_returns4★

@l_returns: here is author's brief sketches for the rest of problems.

@melfice had some problems and he promised to finish the rest of editorials in 2 days

(19 Jul '18, 02:59) mgch6★

This link will do... :D Thank you for sharing this @mgch...

(19 Jul '18, 14:09) l_returns4★
showing 5 of 6 show all

Can someone from Problem setting panel explain the sample test case of Reach Equilibrium as it seems a little unclear...
Please provide P and Q instead of the final answer for better understanding if possible...


answered 07 Jul '18, 19:25

l_returns's gravatar image

accept rate: 23%

edited 07 Jul '18, 19:29

PS: I commented on question 17 hours ago but haven't got a reply still... Many other people also commented about it....

(07 Jul '18, 19:28) l_returns4★

also maybe I think @mention is not working in comments on problem page....

(07 Jul '18, 22:53) l_returns4★

Do the magnitudes need to be integers in this problem, or they can be any real numbers. (According to the question it seems that they can be any real values but I doubt that.)

(08 Jul '18, 07:21) pshishod26454★

I am not having any faith in codechef anymore. Like no reply in 48 hours? No explanation of sample test case...And forget that even @admin is not worried to look at the announcement post once in a day. Seriously why??

(08 Jul '18, 15:04) pshishod26454★

explaining or disclosing P Q will be a spoiler maybe... and hence codechef is not replying... though I feel they should reply that "we can't do that now" ...

(08 Jul '18, 19:04) l_returns4★

We(teja349 and me) decided to don't add explanation for this problem, I'll explain why after the contest. Anyways, we added P and Q now.

(08 Jul '18, 20:49) mgch6★

@pshishod2645 sorry for the delay, I'm a bit busy with my university. Yes, magnitudes can be any real numbers(it's written in the statement)

(08 Jul '18, 20:50) mgch6★

Thanks @mgch atleast you replied with "You can't provide explanation, as it may be a spoiler",. Btw I myself found the value of P and Q by just running a loop of i, and j and checking i/j mod (10^9 + 7), :P

(08 Jul '18, 23:13) pshishod26454★
showing 5 of 8 show all

How many problems?


answered 06 Jul '18, 14:56

asadullo's gravatar image

accept rate: 0%

Can someone tell about notification "You are not allowed to check this content." in July long 2018 contest... Thanks.....

This answer is marked "community wiki".

answered 08 Jul '18, 15:28

hardik_95's gravatar image

accept rate: 0%

Please share Screenshot.

(08 Jul '18, 18:17) aryanc4035★

Commented on Magic Set problem but no reply in 10 hours.

This answer is marked "community wiki".

answered 08 Jul '18, 16:04

tendibee's gravatar image

accept rate: 0%

wikified 08 Jul '18, 16:05

Commented on Magic Set problem no reply from day contest started plz setter look to it.


answered 09 Jul '18, 14:07

code_man's gravatar image

accept rate: 8%

hehe I remember your name... "code_man" XD
reminds me of MMASS question we discussed..
I remember due to username :) and our long discussions..

(10 Jul '18, 13:24) l_returns4★

Haahaa hu pan nai bhulu MMASS and ur help for that:)

(10 Jul '18, 23:31) code_man3★

Hey how u know Gujarati bro ??

(11 Jul '18, 07:08) l_returns4★

Ala bhai hu gujrati chu ....:)_/_

(11 Jul '18, 23:38) code_man3★

nice man :D

(12 Jul '18, 02:27) l_returns4★

I commented on the Magic Set problem but still no reply.


answered 10 Jul '18, 05:31

spafindoople's gravatar image

accept rate: 0%

Is there anyone who got reply from problem setting panel for MGCSET ?? Can anyone (from problem setting panel) add better explanation for test cases of MGCSET?? I'm waiting for reply from 2 days.

And a suggestion for problem setting panel - Make some comments public.


answered 10 Jul '18, 11:13

aryanc403's gravatar image

accept rate: 10%

edited 10 Jul '18, 14:49

@vijju123 @mgch I strongly feel problem statement of MGCSET has been altered in past 2 days. And why is no announcement made after this change?

(10 Jul '18, 19:56) aryanc4035★

Commented on Gears but I am not getting any reply. I am waiting for more than two days.


answered 10 Jul '18, 12:02

vipin1407's gravatar image

accept rate: 10%

Can anyone tell me how to flush the output after every line in Chef and war question.

What I have been using is cout.flush() but it doesn't seen to work.


answered 10 Jul '18, 17:48

hrishabh15's gravatar image

accept rate: 33%


C++ use the fflush(stdout) function
Java — call System.out.flush()
Python — sys.stdout.flush()
Pascal — flush(output)

(10 Jul '18, 19:48) brijesh_19984★

cout << endl;
works for c++... use it whenever u wanna flush..

(14 Jul '18, 12:51) l_returns4★

Sorry guys! It was my fault, Didn't read the question properly.

(17 Jul '18, 23:56) hrishabh155★

@mgch the sequences d's in Pizza delivery is constrained to be already sorted or theey can be in any arbitrary order.


answered 11 Jul '18, 09:47

pshishod2645's gravatar image

accept rate: 13%


Arbitrary order

(12 Jul '18, 02:26) mgch6★

Magic set problem needs to be more detailed, I would appreciate if someone can help me with problem .


answered 11 Jul '18, 12:17

arjun1459's gravatar image

accept rate: 0%

bound by rules of codechef :(

(11 Jul '18, 20:04) l_returns4★

ha ha i dont want answer , i just want some one to explain me question a little more , i am little dumb so it will be a fovour

(11 Jul '18, 21:33) arjun14592★

its not allowed acc to discuss rules..

(12 Jul '18, 02:28) l_returns4★

@admin : Couldn't understand sample test for Reach Equilibrium.Please provide some explanation!!


answered 11 Jul '18, 22:00

nishantaryakum's gravatar image

accept rate: 0%

Full explanation will be spoiler to the solution :(

(12 Jul '18, 02:26) mgch6★

remove your duplicate answers now.. as u got attention and reply...

(15 Jul '18, 00:59) l_returns4★

@admin: In the problem Reach Equilibrium, magnitudes of the vectors can be any positive real number including zero.(please confirm this)


answered 12 Jul '18, 17:39

anishray042's gravatar image

accept rate: 0%

Real numbers. Refer to @mgch comment above.

(12 Jul '18, 17:51) vijju123 ♦♦5★

Including zero?(that's my main concern)

(12 Jul '18, 17:56) anishray0423★

Non-negative includes 0 by default rules.

(12 Jul '18, 18:31) vijju123 ♦♦5★

My first challenge here and NMNMX already became my most hated problem ever. First day I quickly tried brute force on it and got 20 points. Last 5 days have been working on it day and night and improved a lot but still getting 20 points. Is it possible to solve that problem with Python (in normal ways, I got a way to solve it but it's kinda cheating :P)?


answered 14 Jul '18, 13:19

tieros's gravatar image

accept rate: 11%

Finally passed all test cases! Weird thing one of the first thing I tried days ago helped me. At that I didn't use it because it was taking forever in my local pc, but here codechef dealed with quickly:)

(14 Jul '18, 16:10) tieros4★


(15 Jul '18, 00:58) l_returns4★

yes it is possible to solve in python, I passed mine in just 0.24 seconds. You can have a look at it from searching my name on the leaderboard

(16 Jul '18, 16:55) panik4★


so regarding the MAGIC_SET problem, does the order matter.

because for {1 2 1}, both {1 2} and {2 1} are sub-sequences but the elements are same. So is the order meant to be maintained?


answered 16 Jul '18, 11:54

migos's gravatar image

accept rate: 0%

edited 16 Jul '18, 11:54

When will editorials be posted? Can someone please explain their approach for Gears !!


answered 16 Jul '18, 15:30

vishesh345's gravatar image

accept rate: 0%

edited 16 Jul '18, 15:31

Didn't have time to implement it, but I guess you can model it it as a graph. If a odd-length cycle exists in a component, then the whole component is "blocked". Otherwise, for any two gears X and Y, you can find the speed of Y given X... the intermediate gears are quite irrelevant.

(16 Jul '18, 15:35) xrisk3★
(16 Jul '18, 15:58) vijju123 ♦♦5★

Thanks a lot ! I never solved many problems with DSU...just basic ones, i was not aware of it, will have a look at it.

(16 Jul '18, 16:03) vishesh3453★

HERE is my code..
Its neat..
DSU (without path compression (u ll understand why if u go with my logic of bool invert))
Hint: assign 0 or 1 sign to each node (for detecting cycle and for detecting sign of rotating).....

(16 Jul '18, 16:08) l_returns4★

Thank you!! will refer it :)

(16 Jul '18, 16:26) vishesh3453★

Editorial links for PDELIV and SUBWAY july18 are not working. @admin


answered 17 Jul '18, 16:15

dushyant7917's gravatar image

accept rate: 0%

Thats coz they arent uploaded yet. Editorialist is still writing them.

(17 Jul '18, 16:46) vijju123 ♦♦5★

long challenge lasts for 10 days... do codechef hide solutions from editorialist till contest gets ended ? If no , why not still editorialist was able to complete them !!!

(17 Jul '18, 21:18) l_returns4★

Ask that from editorialist himself @l_returns xD. No, he gets all solutions and setter's explanation.

(17 Jul '18, 23:40) vijju123 ♦♦5★

It's been two days since contest ended and we still don't have editorials for all problems...please add them


answered 18 Jul '18, 18:05

venturer's gravatar image

accept rate: 14%

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 06 Jul '18, 03:55

question was seen: 3,251 times

last updated: 19 Jul '18, 14:09