Codeforces celebrates 10 years! We are pleased to announce the crowdfunding-campaign. Congratulate us by the link https://codeforces.com/10years. ×

### Nickolas's blog

By Nickolas, 4 years ago, ,

I'm happy to see that this year there were 3 people who managed to solve all 7 problems! Unfortunately, only 1097 participants solved at least one problem, which is less than in 2014.

#### 656A - Da Vinci Powers

This problem asked to figure out an integer sequence from two samples and problem title. It turned out to be surprisingly hard, a lot harder than I anticipated. A quick search through OEIS shows that while there are a lot of sequences which have these two numbers in them, only one is related to Leonardo da Vinci (and if you're looking for da Vinci, there are only two sequences overall). http://oeis.org/A221180 is an erroneous series of powers of 2, written down by da Vinci in his diaries and available as part of "Codex Madrid I".

#### 656B - Scrambled

Just one word: typoglycemia. The urban legend (unsupported by any known research) claims that people can easily read text even if letters in each word are scrambled, as long as the first and the last letters stay in place. Looked like a fun thing to verify on a small (and strongly biased) sample of competitive programmers. Judging from the results, it's really not much of an obstacle :-)

When un-scrambled, the lengthy statement becomes a story about two roommates who are trying to figure out a fair way to split dishes washing duty. (Fun fact: this problem idea is actually inspired not by any real-life events but by a theater play.) "You agree on two arrays of integers M and R, number upcoming days (including the current one) with successive integers (the current day is zero), and you wash the dishes on day N if and only if there exists an index i such that N % M[i] = R[i], otherwise your roommate does it... Calculate the percentage of days on which you end up doing the washing."

To find the answer, you can find least common multiple of numbers in array M. The infinite number of days ahead can be split into identical blocks of M days, so the percentage of all days on which you end up with the chore will be the same as the percentage of the first LCM days. Iterate over days 0..LCM-1 and for each day check who gets to do the chore on it (since each element is at most 16, LCM will be at most 720720, and iteration will be sufficiently fast).

A much simpler approach would be just to iterate over a lot of days regardless of LCM and calculate the answer based on them — the absolute error will be small enough for this solution to pass.

#### 656C - Without Text

One more statement-less problem (and one more problem which turned out to be harder than I thought), but at least this one has a picture! By this time anyone with a history of participation in my contests should recognize a program regardless of the language in which it is written. In this case it is Sanscript, a visual dataflow language. The image doesn't represent the whole program, just the body of the main loop, but it contains most of the logic.

Individual elements of the program (functions) are fairly well annotated, so it shouldn't be too hard to figure out the overall purpose of the "code". The whole mess of the blocks and arrows calculates sum of indices of uppercase letters in English alphabet (A is 1, B is 2 etc.) minus sum of indices of lowercase letters in alphabet. Non-letter characters are ignored.

#### 656D - Rosetta Problem

I love so many unusual programming languages that one language per problem just can't cover all of them. The solution is simple: have several languages per problem! Unfortunately, most people on Codeforces don't share my passion for languages, and this problem, while being trivial to implement, turned out to be the hardest in the whole contest.

Each paragraph of the statement is a short program in one of esoteric languages. If you recognize each one, find an interpreter for it and execute the program, you'll get a piece of statement. Put them together to find out what is it that you need to do to solve the actual problem:

#### 656E - Out of Controls

This problem was the first and the last one to tell you clearly and without doubt what you have to do: write a solution to a simple graph problem (likely using a Floyd-Warshall algorithm) without any traditional reserved words for loops and conditional statements.

There is a number of workarounds possible, which strongly depend on the language you use. Three main approaches were:

• Honestly rewrite the solution in a recursive way.
• Add some other characters in the middle of each forbidden keyword (/*..*/ in C++ or @ in Python with eval)
• Use built-in functions like map, each etc.
• I suspect the few Haskell users were not inconvenienced at all :-)

#### 656F - Ace It!

This problem was contributed by kit1980.

One of the most common tricks in April Fool's day contests is OEIS lookup. Most statement-less problems can be solved by thoroughly searching the website. In this problem, you were given OEIS sequence numbers, and if you checked them on the website, you could notice that the answer is the first element of the given sequence. Now it's just a matter of encoding this lookup process, given that Codeforces doesn't allow solutions to visit external websites...

Ok, it's about time to shout "April Fool!" and burst into laughter. Forget about OEIS. This problem was carefully forged to look very much like what I've described (and I hope it did!), but the actual solution is much, much simpler. The input represents a hand of cards in a game of blackjack, and you have to calculate the sum of points for it. A stands for Ace, worth 1 point (the minimal sum of the 6 digits part of the hand is 12, so if Ace is counted as 11, you're guaranteed to go bust), digits 2..9 correspond to matching cards, and pair of digits 10 represents, well, a ten. The reference to "validity" in the statement meant that 1 or 0 will never appear alone, but will always form a valid card.

#### 656G - You're a Professional

This problem was a kind of tribute to a story called "The Expert" (https://www.youtube.com/watch?v=BKorP55Aqvg). You are given a simple task, but the checker, a.k.a. the customer, keeps throwing new requirements at you. First, you have to rewrite your solution in any other language (that's when you don't want C++ to be the only programming language you know!) regardless of what was your original language. Next, the solution turns out to be too long (again, regardless of its original length). Finally, you have to add a kitten to it (just put a word "kitten" anywhere in the code). Turned out to be much easier than decoding weird programming languages!

• +121

 » 4 years ago, # |   +5 Oh, I was sure, that in D second language was Befunge, but tested interpreters freezed.
 » 4 years ago, # | ← Rev. 2 →   +29 A is probably the most frustrating problem I ever seen on Codeforces.
•  » » 4 years ago, # ^ |   0 I totally agree with you.
•  » » 4 years ago, # ^ |   0 After reading the previous contest's problem statement and tutorial I figured out that only OEIS can save us :D
•  » » » 4 years ago, # ^ |   +8 Except for Problem F.
 » 4 years ago, # |   0 E is the best problem i have ever seen.... :D
 » 4 years ago, # |   0 Wait, does G consider C++ and C++11 to be different languages? What about MS C++ and GNU C++?
 » 4 years ago, # |   0 Please help me. I dont understand an editorial of A.
•  » » 3 years ago, # ^ |   0 It relates to this sequence (http://oeis.org/) which is 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8092, 16184, 32368 .... Which has a mistake in the 14th term which should be 8192.
 » 4 years ago, # |   0 This is what I did for E: Problem E
 » 4 years ago, # |   +39 I think our sense of humor are compatible!Nice contest!
•  » » 4 years ago, # ^ |   0 WOW
 » 4 years ago, # |   +21 Really nice problems, I got fooled by F :)Was it intentional that the first page in google search for "malbolge interpreter online" gives segmentation fault for the provided code? Only the second result (the one you point to) returns answer. BTW I didn't know what is the last language but this part of statement was unnecessary.
•  » » 4 years ago, # ^ |   0 Without the last piece I interruptted "Print number of ones in BASE 8" as print oct(raw_input().count('1'))[1:]There are indeed only two possibilities, though.
•  » » 4 years ago, # ^ |   0 No.The order of search results depends on the person, I think the one I link to from the editorial was the first one for me. I guess Malbolge is not standardized enough to be portable cross-implementations :-)
 » 4 years ago, # |   +11 Some c++ functional-style solution of E: 17101307
•  » » 4 years ago, # ^ |   +16 You invented for_each(start, end, function), does you?
•  » » » 4 years ago, # ^ |   0 I was not sure it's not banned :) Also it's not that trivial to generate start and end (they should be iterators, not numbers).
 » 4 years ago, # |   +7 the most boring problem is A!!!
 » 4 years ago, # | ← Rev. 3 →   +2 EAdd some other characters in the middle of each forbidden keyword (/*..*/ in C++ or @ in Python with eval)Do you mean sth like this: f/*..*/or (int i = 0; i < n; i++);But I got CE from my compiler...
•  » » 4 years ago, # ^ |   +11
 » 4 years ago, # |   +8 For D I actually went to google image search to search for that image-language. No luck
 » 4 years ago, # |   +5 E written in C++ with a little bit ASM 17107204
 » 4 years ago, # |   +39 In D, I tried two Malbolge interpreters: this and this, and none of them can execute the second program. Is it really correct?
•  » » 4 years ago, # ^ |   +21 I know it's a terrible thing for a software developer to say, but it worked for me with http://www.malbolge.doleczek.pl/, and it was the first interpreter in my search results. Next time I'll have to pick a more standardized language — or a different kind of joke altogether :-)
•  » » » 4 years ago, # ^ |   0 could you please tell me why should we use the word "kitten" in problem G ??
•  » » 4 years ago, # ^ |   +13 http://www.matthias-ernst.eu/malbolge/malbolge.c works for me. (under x86_64 gcc version 5.3.1 20160307 (Debian 5.3.1-11))
 » 4 years ago, # |   +18 F is such troll.. How did you even find such sequences starting with 21, 22, 23?
•  » » 4 years ago, # ^ |   +13 In the announcement thread someone wrote that OEIS provides an archive with all sequences. From there — probably a script on local files.
•  » » 4 years ago, # ^ |   +4 Search for the given string on OEIS. That's how I got fooled.
 » 4 years ago, # |   +4 Given small constraint in E, my first thought was to write 1000 if statements (with C++ conditional operator), similar to this: 17104757. Luckily I gave up midway and found the recursive solution :)
•  » » 4 years ago, # ^ |   +8 I didn't try this problem, but why we can't simply write Floyd-Warshall by goto loops in C++ ?
•  » » » 4 years ago, # ^ |   +8 Without if statement it's a bit tricky to implement goto loops
•  » » 4 years ago, # ^ |   +1 that's what I did E-code just a recursion functions instead of 2 loops for input ,3 for Floyd-Warshall and 2 to find the answer
•  » » 4 years ago, # ^ |   0 I figure out that he just needs to write some code to print it, but that guy is really a new phenomena.
 » 4 years ago, # |   +16 For me error message in G was misleading. I decided that more modern language is some really modern, and start learning D. But it appears that any other language is appropriate.In all other respects it was a merry contest!
•  » » 4 years ago, # ^ |   0 Next time you can look at Status and see what others are doing.
 » 4 years ago, # |   0 My first time attempting such a contest, I really enjoyed it :-). Too bad it only comes once a year...
 » 4 years ago, # |   0 in problem G , why should we add the word 'kitten' !!
•  » » 4 years ago, # ^ | ← Rev. 2 →   +36 And, the checker didn't take my -=^o^=- for one. So sad.
 » 4 years ago, # | ← Rev. 2 →   0 In problem D, I used online Malbolge compiler, but I got RE and i gave up this problem. So sad..
•  » » 4 years ago, # ^ |   +5 Actually, once I've got the other three parts, "Prnt number ??? base 8 notation of a", I was tempted to check whether it's the number of 0s, 1s, or 2s by just submitting such three solutions.
 » 4 years ago, # |   0 E was fun using iota(v.begin(), v.end(), 0) and for_each(v.begin(), v.end(), [](){}).17115093
 » 4 years ago, # |   +39 @ in Python with eval What is relation of "@" and eval?PS: I did it with simple exec: 17101778
 » 4 years ago, # |   +9 Problem F was a good one! I spent half an hour trying to fit the necessary info into 64 KBytes... Feeling foolish :P .Thank you for the contest! Also, I'm amazed by the flexibility shown by the Codeforces platform in problems E and G.
 » 4 years ago, # |   0 Can anybody plz tell me why in problem G the word kitten is added in solution How come you get to know to add this word only as this is not mentioned in the problem statement.
•  » » 4 years ago, # ^ |   0 You will be given the instruction in the verdict if you click on the "Wrong Answer on Test 1". For this task you are not penalized for these incorrect submissions so you can try as many times as you want.
 » 4 years ago, # |   0 how pow(2,35)not same as the what it is to be
•  » » 4 years ago, # ^ |   +8 The sequence is not actually powers of 2, it's what da Vinci believed to be powers of 2, but he made an error during calculations.
 » 4 years ago, # |   0 How to solve problem G? I have submit it with C++,C,Pascal,JavaScript,JAVA8,but I always get a Wrong answer on test 1
•  » » 4 years ago, # ^ |   +3 In the list of your submissions, the "Wrong answer on test 1" outcome should be clickable. Click and read what you are expected to do next.
 » 3 years ago, # | ← Rev. 2 →   -26 .