By DmitryGrigorev, 4 days ago, translation, In English,

Hi, Codeforces! I'm glad to invite everybody to the #489 Codeforces Round, which will be held as soon as tomorrow, on Monday, June 18, 2018 at 19:35. The round will be rated for all participants from the second division (with rating below than 2100). As usually, we will be glad to see participants from the first division out of competition!

Problems for the round have been invented and prepared by us, pupils of Moscow school №2007, Dmitry DmitryGrigorev Grigorev and Fedor ushakov.fedor Ushakov. We want to give thanks to Andrew GreenGrape Raiskiy for his aid in preparing and testing of the problems, to Ildar 300iq Gainullin and to AmirReza Arpa PoorAkhavan who have tested our problems too and to the coordinator Nikolay KAN Kalinin, since our sometimes strange and undeveloped ideas have become eventually the Codeforces round. Also, we say thank you to Mike MikeMirzayanov Mirzayanov for his unbelievable Codeforces and Polygon platforms.

You will receive 5 problems and 2 hours for solving it. During the round you will be helping for an extraordinary girl Nastya, who has been living in Byteland and sometimes receives very strange gifts for her birthday :).

Score distribution will be announced, traditionally, closer to the start of the contest.

We're holding our the first and, I hope, not the last round in Codeforces, so I hope a lot you will like our problems. Please, read all the problems. Anyway, I wish luck and high rating for all the participants!

I'm looking forward your participation.

UPD Score distribution is standart — 500-1000-1500-2000-2500

UPD2 Thank you for your participation in the contest! It's very-very pleasant for me if you like the problems, and I'm sorry if you don't :) I hope the next my contest will be even better, than this. Thank you for all!

List of the winners of the contest:


  1. sminem

  2. guIRELItAr

  3. YaDon4ick

  4. q-O_O-p

  5. pajenegod

Div.1 + Div.2

  1. dotorya

  2. Benq

  3. anta

  4. sminem

  5. kevinsogo

My frank congratulations for all the winners!


Editorial is here

Read more »

  • Vote: I like it  
  • +364
  • Vote: I do not like it  

By DmitryGrigorev, history, 41 hour(s) ago, In English,

All the problems have been prepared by us, — DmitryGrigorev and ushakov.fedor.

(Idea of the problem — DmitryGrigorev)

Tutorial is loading...

Code — 39423470

(Idea of the problem — GreenGrape)

Tutorial is loading...

Code — 39423481

(Idea of the problem — ushakov.fedor)

Tutorial is loading...

Code — 39423497

(Idea of the problem — DmitryGrigorev)

Tutorial is loading...

(Idea of the problem — DmitryGrigorev)

Code — 39423501

Tutorial is loading...

Code of the solution I — 39423519

Code of the solution II — 39418926. Try to optimize :)

Thank you tfg for the idea and the code of the solution III. Very good job!

Code of the solution III — 39392321

Read more »

  • Vote: I like it  
  • +124
  • Vote: I do not like it  

By Vovuh, history, 18 hours ago, translation, In English,


Codeforces Round #490 (Div. 3) will start on June 21 (Thursday) at 14:35 (UTC). You will be offered 6 problems with expected difficulties to compose an interesting competition for participants with ratings up to 1600. Probably, participants from the first division will not be at all interested by this problems. And for 1600-1899 the problems will be too easy. 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 problems and 2 hours to solve them.

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 Maksim Ne0n25 Mescheryakov and Ivan BledDest Androsov for testing the round.

Good luck!

Read more »

  • Vote: I like it  
  • +71
  • Vote: I do not like it  

By csacademy, history, 12 hours ago, In English,

Hello, Codeforces!

We're glad to have Salitanloo as a problem setter!

We're going to host a new contest at Round #82 will take place on Wednesday, June 20th, 15:05:00 UTC. This contest will be a Div1 + Div2, with 7 tasks of varying difficulty that need to be solved in 2 hours.

Facebook event

We recently created a new Facebook event. If you choose "Interested" here, you will be notified before each round we organise from now on.

Contest format:

  • You will have to solve 7 tasks in 2 hours.
  • There will be full feedback throughout the entire contest.
  • Tasks will not have partial scoring, so you need to pass all test cases for a solution to count (ACM-ICPC-style).
  • Tasks will have dynamic scores. According to the number of users that solve a problem the score will vary between 100 and 1000.
  • Besides the score, each user will also get a penalty that is going to be used as a tie breaker.


We're going to award the following prizes:

  1. First place: 100$
  2. Second place: 50$

About the penalty system:

  • Computed using the following formula: the minute of the last accepted solution + the penalty for each solved task. The penalty for a solved task is equal to log2 (no_of_submissions) * 5.
  • Solutions that don't compile or don't pass the example test cases are ignored.
  • Once you solve a task you can still resubmit. All the following solutions will be ignored for both the score and the penalty.

If you find any bugs please email us at

Don't forget to like us on Facebook, VK and follow us on Twitter.

Read more »

  • Vote: I like it  
  • +28
  • Vote: I do not like it  

By ROIgold, history, 15 hours ago, In English,

Input is consist of 1 ≤ q ≤ 2 * 104 queries every of which are described with single positive integer n not exceeding 4 * 106.
Output is to print for each query:

x⌋ =  whole part of number, i.e. max integer which's  ≥ x
φ(x) is Euler Totient Function

OK, I can previously calculate phis of all numbers from 1 to 4 * 106 and Pi for any i, 1 ≤ i ≤ 4 * 106 in O(nlogn), but what's then? I don't know how to further optimize solution, because it is TLE with O(n) complexity per query.
Please, help me!

Read more »

  • Vote: I like it  
  • +4
  • Vote: I do not like it  

By Kudo., history, 13 hours ago, In English,

Hello Codeforces, yesterday I published a new light tool to extract CodeForces problems in PDF format, you can find the tool and the story behind it in this GitHub repository.

Have fun and if there are any comments about it, please let me know :)

Read more »

  • Vote: I like it  
  • +20
  • Vote: I do not like it  

By PraveenDhinwa, history, 15 hours ago, In English,

Competitive Programming is all about the thrill of pitting yourselves against other coders and seeing who comes out on top. And in general, there’s nothing quite as fun for our community as putting on our coding hats and flexing our fingers over our keyboards and getting down to solve an interesting problem.

But competitive programming, like every sport, also has its World Cups. And for the CP community, the International Olympiad in Informatics is one such event that we all look forward to, not only as players but also as spectators. An annual competition that began in 1989 in Bulgaria, the IOI has risen from its humble beginnings to become one of the largest worldwide competitions for secondary school students that tests their skills in programming and problem solving.

Only the very best make it to the IOI Training Camps and eventually, the finals. Many of us have always wanted to see what the competition is like but the chance is given only to a select and deserving few. Fortunately for the entire community, CodeChef is bringing the Indian IOI Training Camp experience to you on our platform.

So what is an Indian IOI Training Camp? The Training Camp is probably one of the most enriching experiences any competitive programmer can have. The camp has two aims : it narrows down the pool of participants from a country from around 30 to 4 final participants, and it also trains and tests the participants so that they are ready for the big stage.

And it is this test that CodeChef is bringing to you. We are conducting a replay of the Indian IOI Training Camp, in the same format. There will be three challenging problems and a five-hour time limit for solving them. Three Team Selection Tests were conducted in May for the selection of Indian IOI team. This contest is the first among the three replays that we plan to conduct.

We’re sure you’re as hyped about this contest as we are. How do you take part? It’s simple, just register at CodeChef if you haven’t done so already, and check out the details below! We’re looking forward to seeing you all experience the thrill of the Training Camp selection tests.

The authors of the round are: - Arjun Arul (arjunarul), Praveen Dhinwa (PraveenDhinwa), and Sidhant Bansal (sidhant)

The testers panel consists of: - Rajat De (rajat1603), Sampriti Panda (sampriti), Kushagra Juneja, Swapnil Gupta (born2rule), Sreejata Kishor Bhattacharya (AnonymousBunny), Animesh Fatehpuria (animesh_f), and Arjun P (Superty)

Duration: 5 hours
Start Date: Friday, 22nd June, 2018 at 19:00 HRS (IST)
End Date: Saturday, 23rd June, 2018 at 00:00 HRS (IST)

Contest Link:

The time in other timezones can be seen here

Good luck!

Cheers, Team CodeChef

Read more »

  • Vote: I like it  
  • +48
  • Vote: I do not like it  

By kazama460, history, 22 hours ago, In English,

i am stuck at simple problem , and the problem is that there is no Editorial available for this problem.

The problem is as follows:

Given M (Distinct) integers A1 , A2 , A3 , A4 , A5 ...... , Am , find all integers K , such that remainder of all elements with k is same I.E. A1%K = A2%K = A3%K = ..... = Am%K

and K>1.

Number of elements are 100 , and Ai <= 10^9

My solution is brute force: i am running a loop from 2 to second largest element (which can be upto 10^9) and finding all k , but its giving TLE.

This is the link to the problem

any hint or help would be appreciative. Thanks in advance and happy coding.

Read more »

  • Vote: I like it  
  • +2
  • Vote: I do not like it  

By JohnnyTest, history, 6 hours ago, In English,

I tried solving 192A, which worked on my pc but when I uploaded on codeforces, the same code gave wrong output. I tried running it on Ideone, where also it produced right result.

codeforces submission

What I'm doing wrong?

Read more »

  • Vote: I like it  
  • +3
  • Vote: I do not like it  

By sankalp_, history, 13 days ago, In English,


I think at this point we all can safely agree that there is no such thing as "talent" and even if there is such a thing,hard work beats talent any day.So I request you all to please stop arguing about this.I genuinely made this post to get all of your suggestions and get some tips/tricks which might help me along the way but this post had turned into more of an argument about why all the LGMs were born with this so called talent and are invincible and can't be reached. I believe that with enough hard work, anyone can reach LGM and if that is not happening, it is because we are not putting enough effort.I agree I'm not the right person to say this when I myself am terrible at CP but I am willing to invest a lot of my time to get better at it.


Dear all,

I am not good at competitive programming but I am willing to put in the effort to get better at it. I had a small question which I though might help me and a lot of people like me who want to get better at CP.

It is not a question asking how to solve problem X or which method to use.


I just wanted to know if, let's say you start solving a question. Can you look at the question and realize.. Oh!! this question can be solved using DP or graphs or some paradigm Y.

Or rather, how long does it usually take for the idea to click in your head?


Also, do you have a specific method to determine what to use(I know it is not possible in most cases) like looking at the constraints or the time limit or anything like that?


Is there any particular pattern you follow while solving problems? Like.. do you select a problem to solve in you free time randomly or based on a particular tag?


I found a couple of good blog entries by Morass and DarthPrince from which I practice topic specific problems and I am practicing algorithms from CLRS. Are there any resources that I am missing? If so can you please specify the names or post the links?


Also, on an average basis, how much time do you spend on CP per day?

Thank you.

Read more »

  • Vote: I like it  
  • +70
  • Vote: I do not like it