<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://limyunkai.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://limyunkai.com/" rel="alternate" type="text/html" /><updated>2022-05-08T13:49:32+08:00</updated><id>https://limyunkai.com/feed.xml</id><title type="html">Binaries and Binomials</title><subtitle>Blog about what I had learnt.</subtitle><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><entry><title type="html">Shopee Code League 2022 Solution Writeup</title><link href="https://limyunkai.com/shopee-code-league-2022-solution-writeup/" rel="alternate" type="text/html" title="Shopee Code League 2022 Solution Writeup" /><published>2022-05-08T00:30:00+08:00</published><updated>2022-05-08T00:30:00+08:00</updated><id>https://limyunkai.com/shopee-code-league-2022-solution-writeup</id><content type="html" xml:base="https://limyunkai.com/shopee-code-league-2022-solution-writeup/">&lt;p&gt;Shopee Code League is a 2-week coding league consisting of two rounds of coding competitions and several workshops. I participated in Shopee Code League 2022 with two of my friends, who are also my colleagues (Joshua and Ren Xian). The coding league consists of the Qualification Round and Final Round. Only the top 100 teams from the Qualification Round can qualify for the Final Round.&lt;/p&gt;

&lt;p&gt;Unlike the past year, this year’s Shopee Code League only has algorithmic competition, making it a pure competitive programming competition like Google Code Jam and Facebook Hacker Cup. Coupled with the super attractive prizes, I guess that successfully attracted many competitive programming experts like IOI medalists and ACM ICPC world finalists to the competition, which makes everything super competitive.&lt;/p&gt;

&lt;p&gt;The Qualification round is held on the 19th of March 2022 and consists of 5 problems to be solved in 3 hours. Our team solved all problems in the qualification round and qualified for the finals with 44th place. The final round is held on the 26th of March 2022 and consists of 9 problems to be solved in 5 hours. Our team managed to solve 8 of the 9 problems in the final rounds and ranked in 62nd place.&lt;/p&gt;

&lt;p&gt;It was a fun and challenging competition. However, several significant flaws in the competition affected the overall experience. The two of the most severe issues were the inferior competition platform and the clarity of the problem statement.&lt;/p&gt;

&lt;p&gt;Shopee decided to use HackerEarth as the competition platform. To be honest, this is the worst ever platform I have ever encountered in my competitive programming career. It was believed to have over three thousand teams participated in the qualifications round. When the qualification round started, the HackerEarth server couldn’t handle the load of over 3000+ clients DDOS it simultaneously. As a result, I had experienced a more 10 minutes delay before I could successfully load the first problems.&lt;/p&gt;

&lt;p&gt;Besides the delay at the beginning of the competition, the whole platform constantly lagged, and it took some time to load every page. Moreover, the scoreboard was not working, and some submissions took more than 5 minutes to judge. If I am not mistaken, the scoreboard took more than 60 hours to be fully updated and finalized 😆. In short, the platform is disastrous.&lt;/p&gt;

&lt;p&gt;Also, this is a team competition, but they only allowed one account per team and one session per account to access the platform. Hence, we have to use some ways to share the problem statement and code. Our team decided to use a private GitHub repository to share the problem statement and our code.&lt;/p&gt;

&lt;p&gt;Furthermore, most of the problem statements are poorly written, lack of clarity, lack of rigor, and some even come without an input constraint. That is unprofessional and gives out a lot of bad impressions to me 😕.&lt;/p&gt;

&lt;p&gt;Overall, I still feel that it was a fun experience, and I like solving those problems. It reminds me of the competitive and nervous atmosphere of participating in an actual competitive programming competition. Just that it attracts too many competitive programming masters to the competition that makes it next to impossible for my team to win any prizes despite being able to solve almost all of the problems, we lost a lot in the time penalty.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;qualification-p0---shopee-xpress-delivery&quot;&gt;Qualification P0 - Shopee Xpress Delivery&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/a-delivery.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem was the first problem I read, and I immediately jumped into solving it as I recognized it as a very straightforward BFS problem. However, due to some bugs in the implementation, I could not pass all the test cases on the first try. After debugging for quite some time, I decided to put this problem aside and look at other problems first.&lt;/p&gt;

&lt;p&gt;Later on, I came back to this problem and realized that there might be a portal on the starting first cell, and my code will not consider that portal. After realizing that, I immediately made some minor modifications to my BFS code and successfully passed all the test cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; BFS (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/a-delivery.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Easy-Medium&lt;/p&gt;

&lt;p&gt;The solution is a very straightforward BFS on the grid. We just need to be careful with the implementation and edge cases.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;qualification-p1---installation-of-a-shopee-billboard&quot;&gt;Qualification P1 - Installation of a Shopee Billboard&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/b-billboard.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem was solved by my teammate, but I do know the solution. At first, I noticed that this problem had missing input constraints. After I had thought of the problem for a while, I could not find any polynomial-time solution for this problem and hence skipped it and continued to other problems.&lt;/p&gt;

&lt;p&gt;After that, my teammate just submitted his implementation, and his code was able to pass all test cases. It turns out that the intended solution is indeed exponential. It is just recursive backtracking with pruning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Complete Search, Recursive Backtracking with Pruning (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/b-billboard.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Easy-Medium&lt;/p&gt;

&lt;p&gt;The solution is a very straightforward complete search, recursive backtracking with pruning. The version without proper pruning will not pass the time limit.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;qualification-p2---fireworks-festival&quot;&gt;Qualification P2 - Fireworks Festival&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/c-fireworks.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, when I was reading the problem statement, I had a hard time understanding the problem as the problem statement was extremely confusing to me. It took me quite some time to fully understand the problem.&lt;/p&gt;

&lt;p&gt;After understanding the problem, I was sure that the solution was &lt;em&gt;dp&lt;/em&gt; (&lt;em&gt;dynamic programming&lt;/em&gt;). Just that if we did the &lt;em&gt;dp&lt;/em&gt; without any optimization, the time complexity would be \(O(n^2m)\). I tried to use a &lt;em&gt;priority queue&lt;/em&gt; to optimize the &lt;em&gt;dp&lt;/em&gt; to become \(O(nm\log{n})\), but it still won’t pass the time limit. Finally, I modified my code to use the &lt;em&gt;monotonic queue optimization&lt;/em&gt;, which reduced the time complexity to \(O(nm)\) and passed the time limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; DP with Monotonic Queue Optimization (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/c-fireworks.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Medium-Hard&lt;/p&gt;

&lt;p&gt;Before we start going into the solution, since the original problem statement is extremely confusing, let’s modify the problem statement and solve my version of the problem instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Modified Problem Statement:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;

  &lt;p&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;
    Shopee will be hosting a fireworks festival in Singapore. There are a total of \(n\) cities in a straight line, and the distance between adjacent cities is \(1\).
  &lt;/span&gt; &lt;br /&gt;
  &lt;br /&gt;
  &lt;span style=&quot;font-style: normal;&quot;&gt;
    There are \(m\) fireworks to be set off. The \(i\)-th firework will be set off at time \(t_i\) minutes in \(x_i\)-th city and rewarding \(c_i\) Shopee coins for each firework. If during the \(i\)-th firework set off and you are at \(y\)-th city, you will receive \(c_i - \lvert x_i-y \rvert\) amount of Shopee coins for watching that firework.
  &lt;/span&gt; &lt;br /&gt;
  &lt;br /&gt;
  &lt;span style=&quot;font-style: normal;&quot;&gt;
    You cannot skip watching any fireworks, and it is possible to receive a negative amount of Shopee coins. It is also possible that two or more fireworks can be set off at the same time, and you will be watching both fireworks at the same time in some city.
  &lt;/span&gt; &lt;br /&gt;
  &lt;br /&gt;
  &lt;span style=&quot;font-style: normal;&quot;&gt;
    What is the largest amount of Shopee coin you can obtain?
  &lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First of all, define the following function. Let&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\text{cost}(i, j)\) be the number of coin you will receive if you watch the \(i\)-th fireworks at \(j\)-th city. So \(\text{cost}(i, j) = c_i - \lvert x_i - j \rvert\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then, let&lt;/p&gt;

\[\begin{align*}
\text{dp}(i, j) = &amp;amp; \text{ maximum amount of coins you can receive for fireworks } 1 \text{ to } i \text{ }\\
                  &amp;amp; \text{ where you were at } j\text{-th } city \text{ during the } i\text{-th } firework \text{ set off}
\end{align*}\]

&lt;p&gt;So the answer that the probem requires is \(\text{max}(\text{dp}(m, 1),\, \text{dp}(m, 2),\, \ldots,\, \text{dp}(m, n))\).&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;em&gt;base case&lt;/em&gt;&lt;/strong&gt; for the dp is&lt;/p&gt;

\[\text{dp}(1, i) = c_1\]

&lt;p&gt;that is the maximum amount of coins rewards for the \(1\)-st firework since you can choose to start at any city to maximize your rewards.&lt;/p&gt;

&lt;p&gt;Next is to determine how to compute \(\text{dp}(i, j)\) for the &lt;strong&gt;&lt;em&gt;recurrence case&lt;/em&gt;&lt;/strong&gt;. The naive and straightforward way is as follows&lt;/p&gt;

\[\text{dp}(i, j) = \text{cost}(i, j) + \text{max}(\text{dp}(i-1, y_1),\, \text{dp}(i-1, y_2),\, \ldots,\, \text{dp}(i-1, y_k))\]

&lt;p&gt;where \(y_1,\, y_2,\, \ldots,\, y_k\) are the cities that are reachable from city \(j\) with the speed and time between fireworks \(i\) and \(i-1\), this can be computed with&lt;/p&gt;

\[\begin{gather*}
\text{maxWalkDist} = (t_i - t_{i-1}) \times \text{speed} \\
\lvert j - y_1 \rvert,\, \lvert j - y_2 \rvert,\, \ldots,\, \lvert j - y_k \rvert \le \text{maxWalkDist}
\end{gather*}\]

&lt;p&gt;With this, the time complexity to compute a dp state is \(O(n)\), and there is \(n \times m\) number of dp states, so we now have a \(O(n^2m)\) solution.&lt;/p&gt;

&lt;p&gt;Obviously, a \(O(n^2m)\) solution will not pass the time complexity. Hence we need to optimize the dp. To optimize the dp, we need the following observation.&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(y_1,\, y_2,\, \ldots,\, y_k\) are contiguous cities&lt;/li&gt;
  &lt;li&gt;when computing \(\text{dp}(i, j)\) and \(\text{dp}(i, j+1)\) they share a lot of similarity in terms of their reachable cities since the \(\text{maxWalkDist}\) will be the same&lt;/li&gt;
  &lt;li&gt;to be exact, there will be at most one additional reachable city and at most one fewer reachable city&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Without_loss_of_generality&quot;&gt;WLOG&lt;/a&gt;, let \(y_1 &amp;lt; y_2 &amp;lt; \ldots &amp;lt; y_k\)&lt;/li&gt;
  &lt;li&gt;when comparing city \(j+1\) with city \(j\), the additional reachable city (if exist) will be \(y_k + 1\)&lt;/li&gt;
  &lt;li&gt;the unreachable city (if applicable) will be \(y_1\) (note that it depends on the situation, sometimes \(y_1\) will be reachable from both city \(j\) and \(j+1\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More particulary, when computing \(\text{dp}(i, 1),\, \text{dp}(i, 2),\, \ldots,\, \text{dp}(i, n)\), we are actually finding the &lt;strong&gt;sliding window maximum&lt;/strong&gt;. It is known that &lt;strong&gt;sliding window maximum&lt;/strong&gt; can be solved in linear time with monotonic queue, so we can use monotonic queue to optimize the dp state computation. With &lt;em&gt;monotonic queue optimization&lt;/em&gt;, \(\text{dp}(i, 1),\, \text{dp}(i, 2),\, \ldots,\, \text{dp}(i, n)\) can be computed in \(O(n)\) time and hence, the final time complexity is \(O(nm)\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;qualification-p3---connecting-the-numbers&quot;&gt;Qualification P3 - Connecting the Numbers&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/d-connect.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem is one of the hardest problems in the competition. Fortunately, I was able to get some insight into solving this problem very fast. I was very confident that my approach was correct, and hence I jumped into implementing it. After like 20 to 30 minutes of implementation and debugging, I was able to pass all the test cases.&lt;/p&gt;

&lt;p&gt;Now here comes the interesting part, after the competition, there was a &lt;a href=&quot;https://www.hackerearth.com/challenges/competitive/shopee-code-league-2022-qualification-round/discussion/is-connecting-the-nu-354823c6/&quot;&gt;discussion thread on hackerearth&lt;/a&gt; about this problem, saying that the model solution was wrong. If the model solution was wrong, that means my approach was wrong too. After running my code on the counterexample in the discussion thread, I confirmed that my solution was wrong. It really hurts me because I was sooooo confident that my original approach was brilliant and correct. I was so happy after my solution got accepted, but now it turns out that it is the wrong approach.&lt;/p&gt;

&lt;p&gt;Luckily, the model solution of the problem setter was as wrong as mine, and hence our team got the points for this problem. So I guess we should feel happy about that too.&lt;/p&gt;

&lt;p&gt;I will describe my “&lt;em&gt;incorrect&lt;/em&gt;” solution that passed all the test cases below. Regarding the “&lt;em&gt;correct&lt;/em&gt;” solution, I just know that this problem can be reduced to a 2-SAT problem where the boolean variables are whether each edge should be placed inside or outside the circle, and the clauses are each pair of intersecting edges. As for the implementation, although I know that 2-SAT is solvable in linear time in terms of the number of clauses, I don’t really know the exact algorithm and implementation for this problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Ad-Hod, Observation (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/d-connect.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Hard&lt;/p&gt;

&lt;p&gt;The idea to solve this problem is that we need to find a valid drawing for the circle. If we found one valid drawing, we output &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;yes&lt;/code&gt;, otherwise, we output &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;no&lt;/code&gt;. So the hard part is to figure out how to get the valid drawing if it exists.&lt;/p&gt;

&lt;p&gt;These are all the key observations that will help in deriving the solution.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;There are only two ways to draw each connecting line, either draw them &lt;em&gt;inside&lt;/em&gt; or &lt;em&gt;outside&lt;/em&gt; of the circle.&lt;/li&gt;
  &lt;li&gt;If there exists a valid drawing without intersection, then flipping all the lines from &lt;em&gt;inside&lt;/em&gt; to &lt;em&gt;outside&lt;/em&gt; and &lt;em&gt;outside&lt;/em&gt; to &lt;em&gt;inside&lt;/em&gt; is another valid drawing.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Inside&lt;/em&gt; and &lt;em&gt;outside&lt;/em&gt; drawings are independent of each other, so we can draw all the &lt;em&gt;outside&lt;/em&gt; lines first and then draw the &lt;em&gt;inside&lt;/em&gt; lines.&lt;/li&gt;
  &lt;li&gt;When you draw a line on one side, you split the circle into two parts. If there is another line required to cross the two parts, it has to be on a different side.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for observation 1, 2, 3, and 4 here&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;So now, because of &lt;em&gt;3&lt;/em&gt;, we can focus on drawing the lines &lt;em&gt;outside&lt;/em&gt; first and then draw the remaining lines &lt;em&gt;inside&lt;/em&gt;. Then, because of &lt;em&gt;2&lt;/em&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Without_loss_of_generality&quot;&gt;WLOG&lt;/a&gt;, we can draw the first lines &lt;em&gt;outside&lt;/em&gt;. And because of &lt;em&gt;4&lt;/em&gt;, the circle is now split into two parts after drawing the first line. Then, we can repeat the process recursively for each part, find the next line that is within the same part, and then connect them to the same side again until there are no more lines that can be connected within the same part.&lt;/p&gt;

&lt;p&gt;Because of &lt;em&gt;3&lt;/em&gt;, we can draw the line on the &lt;em&gt;outside&lt;/em&gt; using the process described above first, then repeat the same process on the &lt;em&gt;inside&lt;/em&gt;. If there are still lines that are not connected after the two processes, then there is no valid drawing.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the process&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The incorrect part&lt;/strong&gt; &lt;br /&gt;
The key reason that I am so confident that my approach is correct is that I thought, “&lt;em&gt;this seems to be the only way to draw the lines, there is no other way&lt;/em&gt;” because everything seems to be deterministic and follows the observation. So if everything is deterministic, there is only one single way to draw the lines, my approach has considered every possible situation, and hence it must be correct. But that is not the case, and there is actually a degree of freedom hidden somewhere.&lt;/p&gt;

&lt;p&gt;Notice the process below.&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Then, we can repeat the process recursively for each part, &lt;strong&gt;find the next line that is within the same part&lt;/strong&gt;, and then &lt;strong&gt;connect them to the same side again&lt;/strong&gt; until there are no more lines that can be connected within the same part.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the process above, we find the next line that is within the part and draw it on the same side. If this is the first-ever line, then it had no problem. That is completely fine. But if that is the second line, then it had the degree of freedom to draw it on the other side of the circle. So my approach is actually a &lt;strong&gt;greedy&lt;/strong&gt; approach which &lt;em&gt;greedily&lt;/em&gt; group the next line to be on the same side as the first line, but that is not necessarily needed to be on the same side in the final valid drawing.&lt;/p&gt;

&lt;p&gt;Because of that, my approach is incorrect as I did not explore all possible ways of drawing. Below is a counterexample that will cause my approach to fail.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the counterexample&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;qualification-p4---money-transfer&quot;&gt;Qualification P4 - Money Transfer&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/e-money.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This problem is the easiest problem in the competition. However, I did not solve it first because I thought I could solve P0 and P3 first. It was a mistake not to solve this problem first because it will significantly increase our team’s time penalty.&lt;/p&gt;

&lt;p&gt;After getting stuck in P0 and P3 with some bugs, I took 5 minutes to quickly solve this and submit it to prevent further increasing the time penalty.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Simulation, Hashmap (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Qualification/e-money.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Trivial&lt;/p&gt;

&lt;p&gt;The solution is just to simulate the problem scenario.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p0---stringing-strings&quot;&gt;Final P0 - Stringing Strings&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/a-strings.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My teammate solved this problem during the competition, but I do know the solution. Straightforward recursive backtracking will work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Complete Search with Recursive Backtracking (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/a-strings.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Easy-Medium&lt;/p&gt;

&lt;p&gt;We just need to make sure that during the backtracking or DFS, we prioritize the lower indexed potential pieces first so that our final answer has the smallest lexicographic order.&lt;/p&gt;

&lt;p&gt;We can also use rolling hash to optimize the string comparison, but it is not needed to pass the time limit.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p1---can-you-bounce&quot;&gt;Final P1 - Can You Bounce?&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/b-bounce.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, I had no idea how to solve this problem, but my teammate mentioned that this seemed to be solvable with the &lt;em&gt;binary lifting technique&lt;/em&gt;. After I understand the problem, it is indeed solvable with the &lt;em&gt;binary lifting technique&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;My teammate proposed to try on the solution implementation first, but he had bugs in his code. Later on, while he was having a hard time debugging his implementation, I also tried to implement a working solution. Luckily, my code worked and passed all the test cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Binary Lifting (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/b-bounce.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Hard&lt;/p&gt;

&lt;p&gt;First of all, we noticed that the grid is small (\(\text{row}, \text{col} \le 8\)), so there is at most \(64\) cells.&lt;/p&gt;

&lt;p&gt;Let&lt;/p&gt;

\[\begin{align*}
\text{ways}(c_{pq},\, c_{xy},\, k) = &amp;amp; \text{ number of ways for the pawn piece to travel } \\
                                     &amp;amp; \text{ from cell}(p, q) \text{ to cell}(x, y) \text{ in } k \text{ moves }
\end{align*}\]

&lt;p&gt;Now here is the core idea, notice that we can have the following equations.&lt;/p&gt;

\[\begin{align*}
\text{ways}(c_{pq},\, c_{xy},\, a+b)
&amp;amp;= \text{ways}(c_{pq},\, c_{11},\, a) \times \text{ways}(c_{11},\, c_{xy},\, b) \\
&amp;amp;+ \text{ways}(c_{pq},\, c_{12},\, a) \times \text{ways}(c_{12},\, c_{xy},\, b) \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \text{ways}(c_{pq},\, c_{1n},\, a) \times \text{ways}(c_{1n},\, c_{xy},\, b) \\
&amp;amp;+ \text{ways}(c_{pq},\, c_{21},\, a) \times \text{ways}(c_{21},\, c_{xy},\, b) \\
&amp;amp;+ \text{ways}(c_{pq},\, c_{22},\, a) \times \text{ways}(c_{22},\, c_{xy},\, b) \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \text{ways}(c_{pq},\, c_{nn},\, a) \times \text{ways}(c_{nn},\, c_{xy},\, b) \\
\text{ways}(c_{pq},\, c_{xy},\, a+b)
&amp;amp;= \sum_{i, j\ \in\ \text{all cells}}{\text{ways}(c_{pq},\, c_{ij},\, a) \times \text{ways}(c_{ij},\, c_{xy},\, b)}
\end{align*}\]

&lt;p&gt;The above equations can be interpreted as&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;the number of ways to travel from \(c_{pq}\) to \(c_{xy}\) can be computed from the number of ways to travel from \(c_{pq}\) &lt;strong&gt;via a middle cell&lt;/strong&gt; then to \(c_{xy}\)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;that means that if we know the value of \(\text{ways}(c_{pq},\, c_{xy},\, a)\) and \(\text{ways}(c_{pq},\, c_{xy},\, b)\) for all \(p, q, x, y\), we can compute \(\text{ways}(c_{pq},\, c_{xy},\, a+b)\) too, using the equation above.&lt;/p&gt;

&lt;p&gt;So now, the binary lifting technique comes into play. Traditionally, the binary lifting technique is used in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Lowest_common_ancestor&quot;&gt;LCA&lt;/a&gt; algorithm to find the \(n\)-th parent of any node in \(O(\log{n})\) time.&lt;/p&gt;

&lt;p&gt;The idea of the binary lifting technique is that we store the solution for 1, 2, 4, 8, 16, and until the maximum power of 2 available. Then, to get the solution for arbitrary number \(n\), we just need to get the binary representation of \(n\) and “add” up all the 1-bits.&lt;/p&gt;

&lt;p&gt;In this problem, we store all the values for \(\text{ways}(c_{pq},\, c_{xy},\, 2^a)\) for all \(p, q, x, y,\) and \(a \le 60\) (\(60\) is enough since input constraint is \(10^{18} &amp;lt; 2^{60}\)). That is possible as there will be at most \(8^4 \times 60 \approx 250\text{k}\) values to compute and store which is within the time and memory limits.&lt;/p&gt;

&lt;p&gt;The base case is \(\text{ways}(c_{pq},\, c_{xy},\, 1)\) where we just need to simulate the process. For other power of 2, we can use the equation above to compute,&lt;/p&gt;

\[\begin{align*}
\text{ways}(c_{pq},\, c_{xy},\, 2^{a+1}) &amp;amp;= \text{ways}(c_{pq},\, c_{xy},\, 2^a + 2^a) \\
                                         &amp;amp;= \sum_{i, j}{\text{ways}(c_{pq},\, c_{ij},\, 2^a) \times \text{ways}(c_{ij},\, c_{xy},\, 2^a)}
\end{align*}\]

&lt;p&gt;The time complexity to compute the value for \(\text{ways}(c_{pq},\, c_{xy},\, 2^a)\) for all \(p, q, x, y,\) and \(a \le \log{k}\) is \(O(n^4 \cdot n^2 \cdot \log{k}) = O(n^6 \log{k})\). We then store all these values in an array as part of the precomputation process and prepare them for answering each query later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note:&lt;/em&gt;&lt;/strong&gt; To better demonstrate the process of computing the solution for each query, we use color coding to determine which value is &lt;span style=&quot;color: violet;&quot;&gt;precomputed&lt;/span&gt; and which is not. Note that all the &lt;span style=&quot;color: violet;&quot;&gt;precomputed&lt;/span&gt; value are in the form of \(\textcolor{violet}{\text{ways}(c_{pq},\, c_{xy},\, 2^a)}\).&lt;/p&gt;

&lt;p&gt;To answer the query, note that the starting cell and ending cell is fixed, let the starting cell be \(c_u\) and ending cell be \(c_v\). Then, to compute \(\text{ways}(c_u,\, c_v,\, k)\), we can use the binary lifting technique for that. For example, to compute the solution when \(k = 22 \ (10110_2)\). We first need to compute \(\text{ways}(c_u,\, c_{xy},\, 110_2)\) for all \(x, y\).&lt;/p&gt;

\[\textcolor{lightseagreen}{\text{ways}(c_u,\, c_{xy},\, 110_2)} = \sum_{i, j}{\textcolor{violet}{\text{ways}(c_u,\, c_{ij},\, 10_2)} \times \textcolor{violet}{\text{ways}(c_{ij},\, c_{xy},\, 100_2)}}\]

&lt;p&gt;then&lt;/p&gt;

\[\text{ways}(c_u,\, c_{xy},\, 10110_2) = \sum_{i, j}{\textcolor{lightseagreen}{\text{ways}(c_u,\, c_{ij},\, 110_2)} \times \textcolor{violet}{\text{ways}(c_{ij},\, c_{xy},\, 10000_2)}}\]

&lt;p&gt;after we have \(\text{ways}(c_u,\, c_{xy},\, 10110_2)\) we just output the solution for the cell that \(c_{xy} = c_v\).&lt;/p&gt;

&lt;p&gt;For the time complexity, there is \(O(n^2)\) possible value of \(x, y\) and we need to repeat the “addition” process at most \(\log{k}\) time, so the time complexity per query is \(O(n^2 \cdot n^2 \cdot \log{k}) = O(n^4 \log{k})\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p2---reviewing-reviews&quot;&gt;Final P2 - Reviewing Reviews&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/c-reviews.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I immediately noticed that I could use &lt;a href=&quot;https://en.wikipedia.org/wiki/Rolling_hash&quot;&gt;rolling hash&lt;/a&gt; to solve this problem as it is almost similar to one problem I solved recently, &lt;a href=&quot;/solving-ieeextreme-15-0-hard-problems/#image-convolution&quot;&gt;Image Convolution of IEEEXtreme 15.0&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Despite knowing the solution, it still took me some time to implement the rolling hash algorithm (yes, my coding speed is slow), but it got accepted after 20 minutes of coding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Rolling Hash (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/c-reviews.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Medium&lt;/p&gt;

&lt;p&gt;The variable in the original problem statement is a little confusing, so let’s declare our own variables. Let&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(m \times n\) be the size of the original image where \(m\) is the number of rows and \(n\) is the number of columns&lt;/li&gt;
  &lt;li&gt;\(x \times y\) be the size of the search image where \(x\) is the number of rows and \(y\) is the number of columns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since &lt;a href=&quot;https://en.wikipedia.org/wiki/Rolling_hash&quot;&gt;rolling hash&lt;/a&gt; works in a single dimension, we need to repeat the rolling hash in both directions to get the hash of an image.&lt;/p&gt;

&lt;p&gt;In the first dimension, for each row of the original image, we perform the rolling hash &lt;em&gt;horizontally&lt;/em&gt; with a window size of \(y\) and store all the hash of all valid windows in another array. The resulting hash array should have a size of \((m) \times (n - y + 1)\).&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the resulting hash here&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Then, we repeat the rolling hash process &lt;em&gt;vertically&lt;/em&gt; in the other dimension. For each column of the hash array that we obtained from the previous hashing process, we perform the rolling hash with a window size of \(x\) and store all the hash of all valid windows in another array. The resulting hash array should have a size of \((m - x + 1) \times (n - y + 1)\).&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the resulting hash here&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;We repeat the 2-dimensions rolling hash process on the search image, and we should get a single hash value. Then, we just compare the hash value with each hash in the \((m - x + 1) \times (n - y + 1)\) array and output the number of matching hash.&lt;/p&gt;

&lt;p&gt;The total time complexity and space complexity are linear to the size of input, \(O(nm)\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p3---ice-cream-shop&quot;&gt;Final P3 - Ice Cream Shop&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/d-icecream.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Not yet solved but probably maths. &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Very Hard&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p4---magic-cables&quot;&gt;Final P4 - Magic Cables&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/e-magic.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an interesting problem. During the contest, I saw many teams solve this problem through the scoreboard. So I thought the solution should be not so hard and thought a naive MST should be able to solve the problem, despite knowing that the naive MST complexity is \(O(n^2 \log{n})\). Unfortunately, it turns out that a naive MST algorithm will not pass the time limit, and I had actually wasted some time coding Prim’s algorithm for this.&lt;/p&gt;

&lt;p&gt;After I realized that the naive MST algorithm would not works, I went back to the beginning and started to draw observation. With this in mind, I managed to come up with a solution quite fast and coded it out in 5 min. The solution is actually not that hard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Math, Ad-Hoc (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/e-magic.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Medium&lt;/p&gt;

&lt;p&gt;By making several key observations, the solution will automatically appear.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;All the even numbers can connect to number 1 with 0 costs.&lt;/li&gt;
  &lt;li&gt;For all the odd numbers, if you invert all the bits of that number, you will get a smaller even number. Then that odd number can be connected to that even number with a cost of 0.&lt;/li&gt;
  &lt;li&gt;For &lt;em&gt;2.&lt;/em&gt;, there is only a single exception: the number with all bits is 1, &lt;em&gt;i.e.&lt;/em&gt;, the number in the form of \(2^k - 1\). This is because the server with ID 0 does not exist, and we cannot use the strategy above. Instead, we can connect to the &lt;em&gt;next number&lt;/em&gt; with a cost of 0.&lt;/li&gt;
  &lt;li&gt;So, if the &lt;em&gt;next number&lt;/em&gt; doesn’t exist, we are forced to connect this number with number 1, which will have the minimum possible cost, 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So now, the solution is obvious, if the total number of servers is &lt;strong&gt;NOT&lt;/strong&gt; in the form of \(2^k - 1\), output 0, or else, output 1.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p5---rewards&quot;&gt;Final P5 - Rewards&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/f-rewards.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I immediately noticed that this problem could be solved with &lt;em&gt;greedy algorithm&lt;/em&gt; after reading the problem. However, when I was done reading the problem statement, one of my teammates was already trying on this problem. So during the competition, I told her the idea to solve, and she managed to submit a working solution during the competition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Greedy (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/f-rewards.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Easy-Medium&lt;/p&gt;

&lt;p&gt;The key idea to solve this problem is to &lt;em&gt;work backward&lt;/em&gt;, year by year. Instead of start considering the project with the earliest deadline, we start considering the project with the latest deadline.&lt;/p&gt;

&lt;p&gt;When working backward year by year, let’s consider only the years before the deadline of the last project since there will not be any more projects that can be chosen after that.&lt;/p&gt;

&lt;p&gt;The advantage of working backward is that we can store the projects that are after the current year in a list, and when considering which project to work on this year, we can pick the project that has the highest reward in the list. This is the optimal choice to make because when working backward, all possible projects that we can work on are inside the list, and among all the possible projects, we want to work on the project that returns the highest rewards.&lt;/p&gt;

&lt;p&gt;Of course, since we are looking for the highest value in a list, we don’t want to use any simple list. Instead, we should use a priority queue to optimize that process. Also, do note that there might be some years when we have no projects to work on, and remember to use &lt;em&gt;64-bit&lt;/em&gt; integer for this problem.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p6---seamoney-network-security&quot;&gt;Final P6 - SeaMoney Network Security&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/g-security.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The original problem statement for this problem is buggy, extremely confusing, and hard to understand. It took me some time to fully understand the problem statement, and because the statement is buggy, I had to ask for clarification and wait for a reply.&lt;/p&gt;

&lt;p&gt;After understanding the problem, it is actually a very simple connected component in a grid problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Graph Traversal, DFS (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/g-security.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Medium&lt;/p&gt;

&lt;p&gt;Observe the following.&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;If a connected component has &lt;em&gt;one&lt;/em&gt; initially infected node, the whole component will be infected.&lt;/li&gt;
  &lt;li&gt;Since only &lt;em&gt;one&lt;/em&gt; initially infected node can be removed, if a connected component has more than &lt;em&gt;one&lt;/em&gt; initially infected node, the whole component will be infected no matter what.&lt;/li&gt;
  &lt;li&gt;If a connected component has &lt;em&gt;one&lt;/em&gt; initially infected node, removing that initially infected node will prevent the whole component from being infected.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So now, the solution is clear, run a DFS to find the size of the connected component and the number of initially infected nodes in each of the components. Then among all the connected components that have only one initially infected node, find the largest component in size and the ID of the initially infected node in that component. If there is a tie in size, get the one with the smaller ID.&lt;/p&gt;

&lt;p&gt;If there is no connected component with only one initial infected node, output 0 (the first infected node) since you cannot reduce any infected machine when the infection ends.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p7---split-the-bill&quot;&gt;Final P7 - Split the Bill&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/h-bill.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I actually spend quite some time on this problem. At first, I wasted some time because I misunderstood the problem, I thought that the person who would pay the bill was to be determined by us dynamically.&lt;/p&gt;

&lt;p&gt;After I reread the problem statement a few more times, I realized that the person that would pay for the bills is actually fixed and pre-determined. Even after realizing that, I proceed with the wrong approach.&lt;/p&gt;

&lt;p&gt;My original idea for the problem is that for every triplet of person A, B, C, if A owes B and B owes C, then we can “redirect” the debt to become A owe C (see diagram below). We can keep performing the “redirect” until that for each person A, either A did not owe someone money, or no one owes A money. This is possible because if it is not the case, then we can perform a “redirect” using A as the pivot to reduce the total debt.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the &quot;redirect&quot; process&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;I coded that approach and kept getting the wrong answer verdict. Later on, I figured out that this approach has a major flaw and is indeed a wrong solution. For example, it will fail on the following debt graph.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the counterexample&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;After I found the counterexample, I immediately realized that the solution might be min-cost flow. So I used my min-cost flow template in &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Data%20Structure%20and%20Algorithm%20Rev%201/min_cost_flow.cpp&quot;&gt;here&lt;/a&gt; and got accepted after that.&lt;/p&gt;

&lt;p&gt;Fast forward until now, when I am writing this writeup, I thought of the problem again. Then I realize that the straightforward traditional min-cost flow implementation might not be the correct solution since the cost definition in this problem is slightly different. But since my unmodified min-cost flow implementation passes all the test cases, I will assume that the solution is correct 😆.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Min Cost Flow (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/h-bill.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Medium-Hard&lt;/p&gt;

&lt;p&gt;Let&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(\text{debt}(a, b)\) be the total amount of money that \(a\) owes \(b\)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now consider the following function,&lt;/p&gt;

\[\text{nett}(a) = \sum_{i\ \in\ \text{everyone}}{\text{debt}(a, i)} - \sum_{i\ \in\ \text{everyone}}{\text{debt}(i, a)}\]

&lt;p&gt;\(\sum{\text{debt}(a, i)}\) can be interpreted as the total money that \(a\) owes everyone else and \(\sum{\text{debt}(i, a)}\) can be interpreted as the total money that everyone else owe \(a\). So \(\text{nett}(a)\) can be interpreted as the total amount of money that \(a\) should pay to resolve \(a\)’s debt.&lt;/p&gt;

&lt;p&gt;Instead of considering who owes who, and who shall pay who, let’s assume that there is a moderator among them. So if \(\text{nett}(a)\) is positive, then \(a\) will need to pay the moderator \(\text{nett}(a)\) amount of money. And if \(\text{nett}(a)\) is negative, then \(a\) will receive \(-\text{nett}(a)\) amount of money from the moderator. Then, everyone is happy, and all debt is resolved.&lt;/p&gt;

&lt;p&gt;But in this problem, there is no moderator available, so instead, we need to find the optimal way to pay \(\text{nett}(a)\) amount to the network (or receive from the network if \(\text{nett}(a)\) is negative). This is exactly what min-cost flow can solve.&lt;/p&gt;

&lt;p&gt;We model the problem like the following flow graph.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;center&gt;&lt;code&gt;&amp;lt;TODO: insert image for the flow graph here, in the meantime, read the code to understand how the flow graph looks&amp;gt;&lt;/code&gt;&lt;/center&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Then the answer is just the &lt;em&gt;min-cost flow&lt;strong&gt;*&lt;/strong&gt;&lt;/em&gt; of the above flow graph.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;*&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;note&lt;/em&gt;&lt;/strong&gt;: to avoid confusing people, the cost required in this problem is not the same as the cost in the traditional min-cost flow algorithm, hence I need to modify this part in my solution to fit the cost definition in this problem to solve this problem, see the difference in &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/1dd60737f78b6c946ca3c84dff0dd88ea48bb280/Data%20Structure%20and%20Algorithm%20Rev%201/min_cost_flow.cpp#L92&quot;&gt;min-cost flow template&lt;/a&gt; and &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/1dd60737f78b6c946ca3c84dff0dd88ea48bb280/Competition/Shopee%20Code%20League%202022%20-%20Final/h-bill.cpp#L83&quot;&gt;my solution&lt;/a&gt; for this problem. And remember that this might not be the correct solution, but it somehow works.&lt;/p&gt;

&lt;p&gt;I kind of have the actual correct solution in my mind when I am writing this, but it will be even more confusing to explain that. So let’s just keep it this way.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;final-p8---shopee-event&quot;&gt;Final P8 - Shopee Event&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/i-event.pdf&quot; target=&quot;_blank&quot;&gt;pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I figured out the solution 5 min after I understood the problem. At first glance, we just need to find the size of each connected component, and we can do some simple DFS graph traversal for that.&lt;/p&gt;

&lt;p&gt;But that will not work because it is a graph with multiple &lt;em&gt;cliques&lt;/em&gt; and extremely many edges. The number of edges in the graph is \(O(n^2)\). So if we naive-ly modeled the graph and tried to run some graph traversal algorithm to find the connected component, it will surely get a time limit exceeded verdict.&lt;/p&gt;

&lt;p&gt;But since we only want to find the connected component size, we can use a disjoint set for that and skip the graph traversal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Disjoint Set (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/Shopee%20Code%20League%202022%20-%20Final/i-event.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Difficulty:&lt;/em&gt;&lt;/strong&gt; Easy-Medium&lt;/p&gt;

&lt;p&gt;For each interest group, we select the first person to be the representative. Then for the remaining person, just perform a union operation with the representative using a disjoint set.&lt;/p&gt;

&lt;p&gt;In the end, we just query the component size from the disjoint set and output them.&lt;/p&gt;

&lt;p&gt;Since all disjoint set operations are amortized constant&lt;strong&gt;*&lt;/strong&gt;, the total time complexity is linear to the input size and the total number of person \(O(n + k)\).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;*&lt;/strong&gt; well, in the context of competitive programming, we usually just pretend that the &lt;a href=&quot;https://en.wikipedia.org/wiki/Ackermann_function#Inverse&quot;&gt;inverse Ackermann function&lt;/a&gt; is constant 😆&lt;/p&gt;

&lt;hr /&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="competitive-programming" /><category term="blog" /><category term="shopee-code-league" /><summary type="html">Shopee Code League is a 2-week coding league consisting of two rounds of coding competitions and several workshops. I participated in Shopee Code League 2022 with two of my friends, who are also my colleagues (Joshua and Ren Xian). The coding league consists of the Qualification Round and Final Round. Only the top 100 teams from the Qualification Round can qualify for the Final Round.</summary></entry><entry><title type="html">Solving IEEEXtreme 15.0 Hard Problems</title><link href="https://limyunkai.com/solving-ieeextreme-15-0-hard-problems/" rel="alternate" type="text/html" title="Solving IEEEXtreme 15.0 Hard Problems" /><published>2021-10-31T00:30:00+08:00</published><updated>2021-10-31T00:30:00+08:00</updated><id>https://limyunkai.com/solving-ieeextreme-15-0-hard-problems</id><content type="html" xml:base="https://limyunkai.com/solving-ieeextreme-15-0-hard-problems/">&lt;p&gt;This post will be updated if I have more time to fill in the details or I solved more problem.&lt;/p&gt;

&lt;p&gt;Problem are sorted from least solves to most solves with the exception of &lt;a href=&quot;#beautiful-summation&quot;&gt;Beautiful Summation&lt;/a&gt;, because it is beautiful, the problem the caught my eye, the first problem I solved and I like this problem the most.&lt;/p&gt;

&lt;p&gt;It is worth noticing that number of solves doesn’t correlates with the difficulty that based on my judgement. A very good example is a &lt;a href=&quot;#beautiful-summation&quot;&gt;hard math derivation problem&lt;/a&gt;, can have more solves than a &lt;a href=&quot;#image-convolution&quot;&gt;straightforward bitwise optimization problem&lt;/a&gt; and a &lt;a href=&quot;#word-search&quot;&gt;straightforward Rabin-Karp string matching problem&lt;/a&gt;. Another example is a &lt;a href=&quot;#bridge-construction&quot;&gt;DFS problem&lt;/a&gt; is having less solves than a &lt;a href=&quot;#bus-company&quot;&gt;HLD problem&lt;/a&gt; and a &lt;a href=&quot;#xtreme-teams&quot;&gt;non-trivial meet in the middle optimization problem&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The collection of problems are available at &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task&quot;&gt;here&lt;/a&gt; and the collection of my solutions are available at &lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/tree/master/Competition/IEEEXtreme%2015.0%202021&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;beautiful-summation&quot;&gt;Beautiful Summation&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/summation/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (18 solves as of 1 Nov 21)&lt;/p&gt;

&lt;p&gt;This is the first problem that caught my eye and I am very interested in solving it because of the math nature and how straight forward the problem is.&lt;/p&gt;

&lt;p&gt;The first thing that I noticed was \(N\) is very huge, so I know that I need some solution that have at most \(\log(N)\) time complexity. So it is either an \(O(1)\) formula solution or \(O(\log(n))\) divide and conquer solution. I searched through the internet and tried many idea like FFT, \(O(\log(n))\) fast matrix exponentiation, &lt;a href=&quot;https://en.wikipedia.org/wiki/Arithmetic_progression#Derivation&quot;&gt;arithmetic progression like formula derivation&lt;/a&gt;, and setting up recurrence relation but all leads to dead end.&lt;/p&gt;

&lt;p&gt;When I almost gave up and searching the internet for one last time, I used the search term &lt;em&gt;“algorithm for computing power sum”&lt;/em&gt; and found &lt;a href=&quot;https://www.ijser.org/researchpaper/Some-algorithmic-methods-for-computing-the-sum-of-powers.pdf&quot;&gt;this paper&lt;/a&gt; that shed some light on the potential solution. The &lt;em&gt;method 2&lt;/em&gt; of the paper seem to suggest a recurrence relation that halving the \(N\) is possible, and if that is possible, there is a high chance that I will have my solution.&lt;/p&gt;

&lt;p&gt;I did the math on paper and finally I got my recurrence relation.&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;strong&gt;&lt;em&gt;Side Note:&lt;/em&gt;&lt;/strong&gt; When working on the math, I found out that the recurrence ralation in method 2 given by the paper is &lt;strong&gt;WRONG&lt;/strong&gt; #faceplam&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Math + Divide and Conquer + DP (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/beautiful_summation.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Let \(P\) be constant and \(S(N, Q)\) be our desired sum to obtain.&lt;/p&gt;

\[S(n, q) = \sum_{k=1}^{n}{P^k k^q} = P^1 1^q + P^2 2^q + \cdots + P^n n^q \tag{1}\]

\[\begin{aligned}
S(2n, q)
&amp;amp;= P^1 1^q + P^2 2^q + \cdots + P^{2n} (2n)^q \\
&amp;amp;= S(n, q) + P^{n+1} (n+1)^q + \cdots + P^{n+n} (n+n)^q \\
&amp;amp;= S(n, q) + P^n \left( P^1 (n+1)^q + \cdots + P^n (n+n)^q \right) \\
\end{aligned}\]

&lt;p&gt;Lets take a closer look on the following sum&lt;/p&gt;

\[x = P^1 (n+1)^q + P^2 (n+2)^q + \cdots + P^n (n+n)^q\]

&lt;p&gt;do a &lt;a href=&quot;https://en.wikipedia.org/wiki/Binomial_theorem&quot;&gt;binomial expansion&lt;/a&gt; and then factorize&lt;/p&gt;

\[\begin{aligned}
x
&amp;amp;= \textcolor{lightseagreen}{P^1} \left[ \textcolor{violet}{ {q \choose 0} n^q}\textcolor{lightseagreen}{1^0} + \textcolor{violet}{ { q \choose 1} n^{q-1}}\textcolor{lightseagreen}{1^1} + \cdots + \textcolor{violet}{ {q \choose q} n^0}\textcolor{lightseagreen}{1^q} \right] \\
&amp;amp;+ \textcolor{lightseagreen}{P^2} \left[ \textcolor{violet}{ {q \choose 0} n^q}\textcolor{lightseagreen}{2^0} + \textcolor{violet}{ { q \choose 1} n^{q-1}}\textcolor{lightseagreen}{2^1} + \cdots + \textcolor{violet}{ {q \choose q} n^0}\textcolor{lightseagreen}{2^q} \right] \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \textcolor{lightseagreen}{P^n} \left[ \textcolor{violet}{ {q \choose 0} n^q}\textcolor{lightseagreen}{n^0} + \textcolor{violet}{ { q \choose 1} n^{q-1}}\textcolor{lightseagreen}{n^1} + \cdots + \textcolor{violet}{ {q \choose q} n^0}\textcolor{lightseagreen}{n^q} \right] \\[10px]
x
&amp;amp;= \textcolor{violet}{ {q \choose 0} n^q} \left( \textcolor{lightseagreen}{P^1 1^0} + \textcolor{lightseagreen}{P^2 2^0} + \cdots + \textcolor{lightseagreen}{P^n n^0} \right) \\
&amp;amp;+ \textcolor{violet}{ {q \choose 1} n^{q-1}} \left( \textcolor{lightseagreen}{P^1 1^1} + \textcolor{lightseagreen}{P^2 2^1} + \cdots + \textcolor{lightseagreen}{P^n n^1} \right) \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \textcolor{violet}{ {q \choose q} n^0} \left( \textcolor{lightseagreen}{P^1 1^q} + \textcolor{lightseagreen}{P^2 2^q} + \cdots + \textcolor{lightseagreen}{P^n n^q} \right) \\[10px]
x
&amp;amp;= \textcolor{lightseagreen}{S(n, 0)}\textcolor{violet}{ {q \choose 0} n^q} + \textcolor{lightseagreen}{S(n, 1)}\textcolor{violet}{ {q \choose 1} n^{q-1}} + \cdots + \textcolor{lightseagreen}{S(n, q)}\textcolor{violet}{ {q \choose q} n^0}
\end{aligned}\]

&lt;p&gt;finally, a recurrence ralation that halves \(n\)&lt;/p&gt;

\[S(2n, q) = S(n, q) + P^n \sum_{i = 0}^{q} \textcolor{lightseagreen}{S(n, i)}\textcolor{violet}{ {q \choose i} n^{q-i}}\]

&lt;p&gt;for completeness of the recurrence relation, we also have&lt;/p&gt;

\[\begin{align*}
S(0, q) &amp;amp;= 0 \\
S(1, q) &amp;amp;= P \\
S(2n+1, q) &amp;amp;= S(2n, q) + P^{2n+1}(2n+1)^q \\
\end{align*}\]

&lt;p&gt;That is almost but still not the end of the story, we still have some minor details like the final time and space complexity to fill in, lets analyse that.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;\(P^n\) can be computed in \(O(\log(n))\) time with &lt;a href=&quot;https://en.wikipedia.org/wiki/Exponentiation_by_squaring&quot;&gt;fast exponentiation technique&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;The binomial coefficient \(\textcolor{violet}{q \choose i}\) can be precomputed with pascal triangle technique with \(O(Q^2)\) time and space. Once the pascal triangle is precomputed we can obtain the binomial coefficient in \(O(1)\) time.&lt;/li&gt;
  &lt;li&gt;The summation \(\sum_{i = 0}^{q} \textcolor{lightseagreen}{S(n, i)}\textcolor{violet}{ {q \choose i} n^q}\) can be computed in \(O(q\log(q))\) time.&lt;/li&gt;
  &lt;li&gt;Assuming that \(S(n, 0), S(n, 1), \ldots, S(n, q)\) is computed, \(S(2n, q)\) can be compute in \(O(q\log(q) + \log(n))\) time.&lt;/li&gt;
  &lt;li&gt;We need to use DP to store the value of computed \(S(n, q)\) because there are overlapping subproblems.&lt;/li&gt;
  &lt;li&gt;There is total of \(O(2\log(N) \times Q) = O(Q\log(N))\) possible values of \(n\) and \(q\) for which we need to computed the value of \(S(n, q)\).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hence, the total time complexity will be&lt;/p&gt;

\[\begin{align*}
&amp;amp; O(Q\log(N) \times (Q\log(Q) + \log(N)) + Q^2) \\
&amp;amp;= O(Q^2\log(Q)\log(N) + Q\log^2(N) + Q^2) \\
&amp;amp;= O(Q^2\log(Q)\log(N)) \qquad \because Q \ll N \\
\end{align*}\]

&lt;p&gt;and total space complexity will be&lt;/p&gt;

\[O(Q^2 + Q\log(N))\]

&lt;p&gt;Given \(Q \leq 1000\) and \(N \leq 10^9\), the time complexity should be just enough to solve the problem. My implementation runs in 1989ms on the largest test case which barely passed the time limit of 2000ms.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;image-convolution&quot;&gt;Image Convolution&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/image-convolution/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (8 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Optimization - Bitwise Operation (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/image_convolution.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;word-search&quot;&gt;Word Search&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/wordsearch&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (13 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Rabin-Karp String Matching (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/word_search.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bridge-construction&quot;&gt;Bridge Construction&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/bridge/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (16 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Graph - DFS (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/bridge_construction.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;bus-company&quot;&gt;Bus Company&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/buscompany/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (20 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Heavy-Light Decomposition&lt;/p&gt;

&lt;p&gt;Haven’t implement yet but quite certain that it is HLD.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;xtreme-teams&quot;&gt;Xtreme Teams&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/xtreme-teams/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (84 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Meet in the Middle - Bitwise Operation (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/xtreme_teams.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;language-learning&quot;&gt;Language Learning&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/language-learning/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (96 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Dynamic Programming (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/language_learning.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;expression-evaluation&quot;&gt;Expression Evaluation&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/expression/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (102 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Recursion - Implementation  (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/expression_evaluation.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;maximum-exploitation&quot;&gt;Maximum Exploitation&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/exploitation/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (127 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Dynamic Programming (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/maximum_exploitation.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;spies-of-red-and-blue&quot;&gt;Spies of Red and Blue&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/spies/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (171 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Graph - Simulation (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/spies_of_red_and_blue.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;doctors-appointments&quot;&gt;Doctor’s Appointments&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Problem Statement:&lt;/em&gt;&lt;/strong&gt; &lt;a href=&quot;https://csacademy.com/ieeextreme-practice/task/appointment/&quot; target=&quot;_blank&quot;&gt;CS Academy&lt;/a&gt; (193 solves as of 1 Nov 21) &lt;br /&gt;
&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Greedy Algorithm (&lt;a href=&quot;https://github.com/limyunkai19/competitive-programming-codes/blob/master/Competition/IEEEXtreme%2015.0%202021/doctors_appointments.cpp&quot; target=&quot;_blank&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;To be updated with more details. In the meantime, I believe the code is pretty much self-explanatory.&lt;/p&gt;

&lt;hr /&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="competitive-programming" /><category term="blog" /><category term="ieeextreme" /><summary type="html">This post will be updated if I have more time to fill in the details or I solved more problem.</summary></entry><entry><title type="html">Malaysia ACM ICPC 2018 Solution Writeup</title><link href="https://limyunkai.com/malaysia-acm-icpc-2018-solution-writeup/" rel="alternate" type="text/html" title="Malaysia ACM ICPC 2018 Solution Writeup" /><published>2018-07-19T00:30:00+08:00</published><updated>2018-07-19T00:30:00+08:00</updated><id>https://limyunkai.com/malaysia-acm-icpc-2018-solution-writeup</id><content type="html" xml:base="https://limyunkai.com/malaysia-acm-icpc-2018-solution-writeup/">&lt;p&gt;I participated in this contest as my final national ACM-ICPC contest. With a certain amount of luck, my teammates (Jenn Pang and Wing Khang) and I won the contest.&lt;/p&gt;

&lt;p&gt;The contest is held on 11th &amp;amp; 12th May 2018 at International Islamic University Malaysia (IIUM), Kuala Lumpur. It consists of 10 problems to be solved in 5 hours.&lt;/p&gt;

&lt;p&gt;Before the contest, we have developed a few &lt;em&gt;strategies&lt;/em&gt; including separate the task of reading and understanding problem statement equally to all 3 members in our team. Also, not to forgot that the rule of thumb of doing the contest is that we should &lt;em&gt;always&lt;/em&gt; solve the problems in the sequence of difficulty, easy to hard (or I should say, in the sequence of confidence level, from high to low). Lastly, we know that we should always observe the scoreboard and solve the problem that many people had solved.&lt;/p&gt;

&lt;p&gt;Following are my post-contest solution write-up of the competition together with some in-contest thought and situation. All the AC codes are available at &lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/tree/master/2018/solution&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; All the variables below are referring to the &lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/2018_Problem_Set.pdf&quot;&gt;problem statement&lt;/a&gt;, if not defined explicitly.&lt;/p&gt;

&lt;h3 id=&quot;some-opinion-on-the-contest&quot;&gt;Some Opinion on the Contest&lt;/h3&gt;
&lt;p&gt;This year, the problems have generally higher quality than every previous year contest, thanks to the problem setters this year. There are still room to improve but at least, weird problem, confusing statement, and super low quality test data do not exist.&lt;/p&gt;

&lt;p&gt;It is great to see such improvements in my national ACM-ICPC contest. Hope that the contest quality can continue to improve in following years.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;a---aku-negaraku&quot;&gt;A - Aku Negaraku&lt;/h1&gt;
&lt;p&gt;This is the second problem our team solved. Jenn Pang has understood the problem and decide to implement it. I helped a bit in the debugging of the indexing problem and we get AC after that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Ad-Hoc - Simulation (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/a.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;This is a simulation problem. After doing complexity analysis, naive simulation of the process is \(O(n^2m)\) which is feasible. The naive implementation is described as below:&lt;/p&gt;

&lt;p&gt;Use a &lt;em&gt;boolean&lt;/em&gt; array to keep track of whether person \(i\) has been kicked or not. Loop \(n-1\) times where each iteration will kick \(1\) person. For each iteration, to find the next person to kick we simply iterate through the array, one by one, skip those who has been kicked in the previous iterations. The following shows 2 methods of implementing this simulation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Implementation 1&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// use a index to keep track of current position&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// outer loop, n-1 times, each time kick 1 person&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// inner loop, to skip m times&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// n -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; ...&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// this person had been kicked, we should not advance the j counter&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// after skipped m times, cur is the next person to kick&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// kick this person&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// output idx where selected[idx] == false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Implementation 2&lt;/em&gt;&lt;/p&gt;
&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// use a index to keep track of current position&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// outer loop, n-1 times, each time kick 1 person&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// inner loop, to skip m times&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// n-1 -&amp;gt; 0 -&amp;gt; 1 -&amp;gt; ...&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// after skipped m times, cur is the next person to kick&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cur&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// kick this person&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// output idx+1 where selected[idx] == false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The second implementation uses \(0\)-based indexing to enable the use of modulus, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cur = (cur+1)%n;&lt;/code&gt; and use while loop to find the next available person.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;b---cheap-deliveries&quot;&gt;B - Cheap Deliveries&lt;/h1&gt;
&lt;p&gt;Immediately after I understand this problem, I notice that it is a TSP (Travelling Salesman Problem) with DP problem. However, because of the implementation difficulties and uncertainty, we actually left this problem behind and solve other problem first.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Graph - TSP with DP (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/b.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Variable declaration&lt;/em&gt;. Let&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(k\) be the number of item to be delivered, given \(k \le 18\)&lt;/li&gt;
  &lt;li&gt;\(u_i\) be the pickup location of the \(i\)-th item&lt;/li&gt;
  &lt;li&gt;\(v_i\) be the dropoff location of the \(i\)-th item&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key to identifies this as a TSP are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Abu &lt;strong&gt;must&lt;/strong&gt; deliver &lt;strong&gt;all&lt;/strong&gt; \(k\) items&lt;/li&gt;
  &lt;li&gt;Abu can choose &lt;strong&gt;any&lt;/strong&gt; other items as his next items to deliver&lt;/li&gt;
  &lt;li&gt;It seeks for &lt;em&gt;minimum&lt;/em&gt; total travel distance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, after identifying this as a TSP, we still need a few observations and pre-processing to solve this problem. We need to observe that:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Since all \(k\) items must be delivered, our answer is &lt;em&gt;at least&lt;/em&gt; the sum of shortest distance from \(u_1\) to \(v_1\), \(u_2\) to \(v_2\) and so on until \(u_k\) to \(v_k\). This can be found by running \(k\) times of Dijkstra’s algorithm.&lt;/li&gt;
  &lt;li&gt;After finish delivered one item, Abu must use the shortest path to the next item pickup location in the optimum delivery path. Hence, we can construct a &lt;em&gt;reduced complete graph&lt;/em&gt; with \(k\) node and let &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dist[i][j]&lt;/code&gt; represent the adjacency matrix of the reduced graph. We then fill in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dist[i][j]&lt;/code&gt; with&lt;/li&gt;
&lt;/ul&gt;

\[\text{dist}(i, j) = \text{shortest path from } v_i \text{ to } u_j\]

&lt;ul&gt;
  &lt;li&gt;Case of \(-1\). We are required to output \(-1\) if it is impossible to deliver all item. The trivial one are, if there is no path from \(u_i\) to \(v_i\) then output \(-1\). The less trivial one are, if \(\text{dist}(i, j) = -1\) for any \((i, j)\) then output \(-1\). To see this, let \(\text{dist}(a, b) = -1\), this means that there is no path from \(v_a\) to \(u_b\). This also means that you have &lt;em&gt;no way&lt;/em&gt; to go pickup item \(b\) after delivering item \(a\) (and the opposite situation too, \(a\) after \(b\)) which implies that Abu is unable to deliver &lt;em&gt;all&lt;/em&gt; items.&lt;/li&gt;
  &lt;li&gt;Memory limit and &lt;em&gt;long long&lt;/em&gt;. First, we need to use &lt;em&gt;long long&lt;/em&gt;, at &lt;em&gt;worst case&lt;/em&gt; there are \(10^4\) cities with all roads are \(10^6\) in length, which lead to \(10^{10}\) shortest path distance if the graph is a &lt;em&gt;straight line graph&lt;/em&gt;. Using &lt;em&gt;int&lt;/em&gt; might lead to a Wrong Answer verdict. With our &lt;em&gt;dp&lt;/em&gt; table of size \(2^{18} \cdot 18\) and memory to store the original graph you can notice that there is not much left from the memory limit of 64 MB. Hence, we have to be careful not to exceed the memory limit when implementing the solution.&lt;/li&gt;
  &lt;li&gt;This TSP is a variant of the original TSP as in this problem, Abu no need to go back to the beginning after delivering his last item.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We now have a complete graph of \(k\) node, and we want to run TSP algorithm on it to find our solution. Naive TSP algorithm would get a &lt;em&gt;time limit exceeded&lt;/em&gt; verdict as it is \(O(k!)\) and \(1 \le k \le 18\). We need a faster TSP algorithm with the help of &lt;em&gt;dynamic programming&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;The naive TSP algorithm explore all \(k!\) permutation search space, but there is certainly overlapping subtask. For example, \(A{-}B{-}C{-}[\text{other } k-3 \text{ items}]\) and \(B{-}A{-}C{-}[\text{other } k-3 \text{ items}]\) has overlapping subtask, and the minimum for \(C{-}[\text{other } k-3 \text{ items}]\) will always be the same. Hence, we can avoid this recomputation with &lt;em&gt;dp memorization&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let&lt;/p&gt;

\[\begin{align*}
bitmask =&amp;amp; \text{ base } 2 \text{ integer with } k \text{ digits } (\therefore 0 \le bitmask &amp;lt; 2^k) \\
\text{remaining}(bitmask) =&amp;amp; \text{ }\{\text{item } i: i\text{-th digit of }bitmask\text{ is } 0 \} \\
\text{dp}(bitmask, last) =&amp;amp; \text{ minimum distance to deliver all item in remaining}(bitmask) \\
&amp;amp;\text{  and Abu is currently at position }v_{last}
\end{align*}\]

&lt;p&gt;The above definition can be understood as, the variable \(bitmask\) is used to represent a set and if \(i\)-th bit is \(1\) represent that the \(i\)-th item had been delivered and \(\text{dp}(bitmask, last)\) is the minimum distance for Abu to further travel to deliver the remaining items given that Abu had just finish delivered the \(last\)-th item.&lt;/p&gt;

&lt;p&gt;Then we need to have the recurrence relation and base case.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Base case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The base case is when Abu has no more item to deliver, and thus the minimum distance to deliver the remaining item is \(0\).&lt;/p&gt;

\[\text{dp}(111\cdots1_2, last) = \text{dp}(2^k-1, last) = 0 \quad \text{for} \quad last = 0, 1, \ldots, k-1\]

&lt;p&gt;&lt;strong&gt;Recurrence:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After Abu had delivered his last item, Abu is at position \(v_{last}\). Abu need to choose his next destination, \(u_i\) such that \(i \in \text{remaining}(bitmask)\). Among all destination Abu can choose, he must choose the one that requires minimum travel distance. And after Abu had chosen the next item \(i\) and delivered, Abu will be at position \(v_i\) and \(i\)-th item is delivered, so we need to include \(i\)-th bit in our \(bitmask\).&lt;/p&gt;

\[\displaylines{ \text{dp}(bitmask, last) = \text{min}(\ \ \text{dist}(v_{last}, u_i) + \text{dp}(bitmask + 2^i, i)\ \ ) \\ \forall i \in \text{remaining}(bitmask) }\]

&lt;p&gt;&lt;strong&gt;The answer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After the &lt;em&gt;dp&lt;/em&gt; table is computed, we can obtain our answer at&lt;/p&gt;

\[\displaylines{ \text{minimum distance} = \text{min}(\ \ \text{dp}(2^i, i)\ \ ) + \sum{\text{min_dist}(u_i, v_i)} \\ \text{for } 0 \le i &amp;lt; k }\]

&lt;p&gt;It is \(\text{min}(\ \ \text{dp}(2^i, i)\ \ )\) because there is no cost on choosing which item to start deliver.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;c---elis-curious-mind&quot;&gt;C - Eli’s Curious Mind&lt;/h1&gt;
&lt;p&gt;I would say this problem is actually quite &lt;em&gt;hard&lt;/em&gt; because it takes time to understand the problem. At the moment I understand the problem, it seems &lt;em&gt;dp&lt;/em&gt;-ish. So, I started to &lt;em&gt;get my hands dirty&lt;/em&gt; on small cases and try to figure out the recurrence relation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;get your hands dirty&lt;/em&gt; is a problem solving tactic that I learned from the book &lt;em&gt;The Art and Craft of Problem Solving&lt;/em&gt; by &lt;em&gt;Paul Zeitz&lt;/em&gt;. It means that try out some cases on a paper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Dynamic Programming (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/c.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;The problem may seem unclear at first. But it gets better when you &lt;em&gt;gets your hand dirty&lt;/em&gt;. Try to list out the answer for a given small \(N\) with pen and paper and repeat on more different \(N\).&lt;/p&gt;

&lt;p&gt;Let \(T_n\) be the number of different mixtures that can be made with \(N\) chemical.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;\(N\)&lt;/th&gt;
      &lt;th&gt;mixture&lt;/th&gt;
      &lt;th&gt;\(T_n\)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;1 and 2&lt;/td&gt;
      &lt;td&gt;none&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;3&lt;/td&gt;
      &lt;td&gt;\(\{1, 3\}\)&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;4&lt;/td&gt;
      &lt;td&gt;\(\{1, 3\}, \{1, 4\}, \{2, 4\}\)&lt;/td&gt;
      &lt;td&gt;3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;5&lt;/td&gt;
      &lt;td&gt;\(\{1, 3, 5\}, \{1, 4\}, \{2, 4\}, \{2, 5\}\)&lt;/td&gt;
      &lt;td&gt;4&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;6&lt;/td&gt;
      &lt;td&gt;\(\{1, 3, 5\}, \{1, 3, 6\}, \{1, 4, 6\}, \{2, 4, 6\}, \{2, 5\}\)&lt;/td&gt;
      &lt;td&gt;5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;7&lt;/td&gt;
      &lt;td&gt;\(\{1, 3, 5, 7\}, \{1, 3, 6\}, \{1, 4, 6\}, \{1, 4, 7\},\) &lt;br /&gt; \(\{2, 4, 6\}, \{2, 4, 7\}, \{2, 5, 7\}\)&lt;/td&gt;
      &lt;td&gt;7&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;During the process, you may have observed the following:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;for a valid combination set, the gap cannot be larger or equal to \(3\). If there is such case, according to rule 2, you must include the chemical in between.&lt;/li&gt;
  &lt;li&gt;if there is total \(N\) chemical, the last chemical in a valid mixture could only be \(N\) or \(N-1\). If the last chemical is \(N-2\) or smaller, you can &lt;em&gt;always&lt;/em&gt; include \(N\) to make a new mixture, hence, according to rule 2, it is invalid.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Until now, for those who have some experience in competitive programming, this problem may seem &lt;em&gt;dp&lt;/em&gt;-ish. Hence, now we should focus on finding the &lt;em&gt;recurrence relation&lt;/em&gt;. If you can find the &lt;em&gt;recurrence relation&lt;/em&gt; you solve the &lt;em&gt;dp&lt;/em&gt; problem. A common strategy when dealing with such problems is to find out whether the solution for \(N\) can be built from smaller \(N\).&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;key&lt;/strong&gt; to solve this problem is actually defining \(S_n =\) number of mixture that has last chemical as \(N\) and we find \(S_n\) instead of \(T_n\). \(T_n\) can be found using \(T_n = S_n + S_{n-1}\) (because of observation 2). Now, \(S_n\) can be obtain using &lt;em&gt;dp&lt;/em&gt;.&lt;/p&gt;

\[\displaylines{ S_n = S_{n-2} + S_{n-3} \quad \text{for} \quad n &amp;gt; 5 \\ S_1 = S_2 = 0 \\ S_3 = 1 \quad S_4 = 2 \quad S_5 = 2 }\]

&lt;p&gt;&lt;em&gt;Why?&lt;/em&gt; Because, for a mixture that end with chemical \(n\), the previous chemical must be either \(n-2\) &lt;em&gt;or&lt;/em&gt; \(n-3\). It cannot be \(n-1\) because of rule 1 and it cannot be less than \(n-3\) because of observation 1.  So to make a new mixture that ends with chemical \(n\), we take the mixtures that ends with chemical \(n-2\) and \(n-3\) then add chemical \(n\) to them. Hence, we have \(S_n = S_{n-2} + S_{n-3}\).&lt;/p&gt;

&lt;p&gt;Our base case is \(n = 1, 2, 3, 4, 5\) because, up to \(n=5\) we are able to select chemical 1 and 2 as the next-to-last chemical. This will cause problems as \(S_1 = S_2 = 0\).&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;d---explorace&quot;&gt;D - Explorace&lt;/h1&gt;
&lt;p&gt;At some point of time during the contest, my teammates identified it as a MST problem and come to me. My reaction was like “hmm MST. Okayyy. no trick? no catch?”. After double confirming that there is no other trick in this problem, I asked my teammates to &lt;em&gt;“copy and paste”&lt;/em&gt; the MST code from our cheatsheet and get AC (should be “read and type” but whatever).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Graph - Direct MST (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/d.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;This is a straightforward MST (Minimum Spanning Tree) problem. Implement a MST algorithm with either Prim’s or Kruskal’s to get AC.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;e---matrix-multiplication-calculator&quot;&gt;E - Matrix Multiplication Calculator&lt;/h1&gt;
&lt;p&gt;I found this problem when my teammate was implementing his solution for G. This is a straightforward and easy implementation problem. Immediately after he finished coded G and get AC. I took over the PC and coded it in 10 minutes and get a speedy AC.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Ad-Hoc - Implementation (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/e.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;This is an Ad-Hoc implementation problem. One method to helps in implementing the solution is by defining a function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multiply(int r, int c)&lt;/code&gt; such that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;multiply(r, c)&lt;/code&gt; returns the r-th row, c-th column of the answer matrix.&lt;/p&gt;

&lt;div class=&quot;language-c++ highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;multiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ans&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ans&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After you have the function, the rest is just the problem on input and output format.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;f---sum-of-sub-rectangle-areas&quot;&gt;F - Sum of Sub Rectangle Areas&lt;/h1&gt;
&lt;p&gt;This is the hardest problem in the competition. I found this problem and immediately knows that the direction to solve it is to &lt;em&gt;derive an&lt;/em&gt; \(O(1)\) &lt;em&gt;closed-form equation aka formula&lt;/em&gt;. After some preliminary math session, I manage to obtain a \(O(N)\) solution but it is not fast enough.&lt;/p&gt;

&lt;p&gt;Eventually I stuck at a part that are relatively simple, that is, find a \(O(1)\) &lt;em&gt;equation&lt;/em&gt; for the sum \(1\cdot2 + 2\cdot3 + \cdots + (n-1)\cdot n\) and I am quite frustrated at it. My mathematics skill has been deteriorate since I stopped doing olympiad math actively (which is the time when I got to my university). It gets even more frustrating when I saw another team had solved the problem while I am still helpless at the sum. I was like, “noooooo, my math has lost to another team” (yes, I am proud of my mathematics). This almost cost us losing the contest.&lt;/p&gt;

&lt;p&gt;I had tried almost all sort of way to find the \(O(1)\) equation, including trying to fit a polynomial to the function by try-and-error-ing its coefficient but none of them leads to something useful.&lt;/p&gt;

&lt;p&gt;After we had cleared almost all the easy and medium problems, all members of our team involved in deriving the equation. And eventually one of my teammates mentions something about “it seems to has something to do with &lt;em&gt;sum of squares&lt;/em&gt;”. Anything happens after this, is &lt;strong&gt;pure luck&lt;/strong&gt; and &lt;strong&gt;magic&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;“&lt;em&gt;Sum of squares&lt;/em&gt;” is what helps us in this problem. I then tell him, “hmm okay, sum of squares, I remember that the formula for sum of square is \(\frac{(n)(n+1)(n+2)}{6}\)”. Then I started to play around with the equation and try plugging in \(n\) and see the correlation with the answer and &lt;strong&gt;“holy crap !!! this is the answer !!!”“&lt;/strong&gt;. If this is not luck, I don’t know what is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the &lt;em&gt;correct&lt;/em&gt; formular for sum of squares is \(\frac{(n)(n+1)(2n+1)}{6}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt; Math - Combinatorics (to obtain the equation) + Algebra (to simplify the equation) (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/f.py&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There is a reason why this is the hardest problem. Because it is not easy to obtain the \(O(N)\) equation either. It might be harder than simplifying the equation from \(O(N)\) to \(O(1)\).&lt;/p&gt;

&lt;p&gt;During the contest, I had drawn a very helpful diagram that helps in obtaining the equation. Let’s use some diagrams to help in deriving the equation.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://limyunkai.com/assets/images/ICPC2018-F-1.png&quot; alt=&quot;f diagram 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The above diagram shows that all possible subrectangles of a square of side length \(n\) can be list down in a table of size \(n \times n\). We will be using the table similar to the diagram above for the following explanation.&lt;/p&gt;

&lt;p&gt;It is important to understand that the table cell of \(r\)-th row and \(c\)-th column represent the subrectangles of size \(r \times c\).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://limyunkai.com/assets/images/ICPC2018-F-2.png&quot; alt=&quot;f diagram 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The diagram above is pretty straightforward, each table cell represent the area of the rectangle of a given size.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://limyunkai.com/assets/images/ICPC2018-F-3.png&quot; alt=&quot;f diagram 3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The above diagram computes the number of different subrectangles for every given size. We use \(n\) for the sake of generalization.&lt;/p&gt;

&lt;p&gt;To understand the diagram, you should answer the following combinatorics problem yourself:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Given a \(n \times n\) square, how many different \(2 \times 2\) subrectangles are in the square. What about \(2 \times 3\) ?? What about \(3 \times 2\) ??&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt; There are \((n-1)\times(n-1)\) different \(2 \times 2\) subrectangles, \((n-1)\times(n-2)\) different \(2 \times 3\) subrectangles and \((n-2)\times(n-1)\) different \(3 \times 2\) subrectangles as correspond to the diagram above.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://limyunkai.com/assets/images/ICPC2018-F-4.png&quot; alt=&quot;f diagram 4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, if we have the number of different rectangles of a given size and multiply that amount with their area, we will get sum of subrectangle areas of given size. The total sum is just the sum across all subrectangle of different sizes.&lt;/p&gt;

&lt;p&gt;For example, let’s focus on subrectangle of size \(3 \times 2\). There are \((n-2)\times(n-1)\) different subrectangle of such size, and their area is \(3 \times 2\). Thus, the sum of subrectangle area of size \(3 \times 2\) is \(\left[ (n-2) \times (n-1) \right] \times \left[ 3 \times 2 \right]\). This is correspond to row \(3\) column \(2\) of the table above.&lt;/p&gt;

&lt;p&gt;Now it is not hard to see that the answer to the problem is the sum of all terms in the table above. So, let’s add them up.&lt;/p&gt;

&lt;p&gt;Let \(S_n\) be the sum of subrectangle area of square of side length \(n\).&lt;/p&gt;

\[\begin{align*}S_n
&amp;amp;= \textcolor{violet}{\left[ 1 \times n \right] } \times \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{violet}{\left[ 1 \times n \right] } \times \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{violet}{\left[ 1 \times n \right] } \times \textcolor{lightseagreen}{\left[ n \times 1 \right]} \\
&amp;amp;+ \textcolor{violet}{\left[ 2 \times (n-1) \right] } \times \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{violet}{\left[ 2 \times (n-1) \right] } \times \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{violet}{\left[ 2 \times (n-1) \right] } \times \textcolor{lightseagreen}{\left[ n \times 1 \right]} \\
&amp;amp;+ \textcolor{violet}{\left[ 3 \times (n-2) \right] } \times \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{violet}{\left[ 3 \times (n-2) \right] } \times \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{violet}{\left[ 3 \times (n-2) \right] } \times \textcolor{lightseagreen}{\left[ n \times 1 \right]} \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \textcolor{violet}{\left[ n \times 1 \right] } \times \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{violet}{\left[ n \times 1 \right] } \times \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{violet}{\left[ n \times 1 \right] } \times \textcolor{lightseagreen}{\left[ n \times 1 \right]} \\[10px]
S_n
&amp;amp;= \textcolor{violet}{\left[ 1 \times n \right] } \ \bigl( \ \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{lightseagreen}{\left[ n \times 1 \right]} \ \bigr) \\
&amp;amp;+ \textcolor{violet}{\left[ 2 \times (n-1) \right] } \ \bigl( \ \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{lightseagreen}{\left[ n \times 1 \right]} \ \bigr) \\
&amp;amp;+ \textcolor{violet}{\left[ 3 \times (n-2) \right] } \ \bigl( \ \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{lightseagreen}{\left[ n \times 1 \right]} \ \bigr) \\
&amp;amp;\ \ \vdots \\
&amp;amp;+ \textcolor{violet}{\left[ n \times 1 \right] } \ \bigl( \ \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{lightseagreen}{\left[ n \times 1 \right]} \ \bigr) \\[10px]
S_n
&amp;amp;= \bigl( \ \textcolor{lightseagreen}{\left[ 1 \times n \right] } + \textcolor{lightseagreen}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{lightseagreen}{\left[ n \times 1 \right]} \ \bigr) \bigl( \ \textcolor{violet}{\left[ 1 \times n \right] } + \textcolor{violet}{\left[ 2 \times (n-1) \right]} + \cdots + \textcolor{violet}{\left[ n \times 1 \right]} \ \bigr) \\
&amp;amp;= \bigl( 1 \times n + 2 \times (n-1) + \cdots + n \times 1 \bigr)^2 \\
\end{align*}\]

&lt;p&gt;Now we got our \(O(n)\) equation. To simplify it to \(O(1)\) we need some algebra trick and formulas.&lt;/p&gt;

\[\begin{align*}
S_n
&amp;amp;= \bigl( 1 \times n + 2 \times (n-1) + \cdots + n \times 1 \bigr)^2 \\
&amp;amp;= \bigl( \left[ 1 \cdot n \right] + \left[ 2 \cdot (n-1) \right] + \cdots + \left[ n \cdot (n-(n-1)) \right] \bigr)^2  \\
&amp;amp;= \bigl( \left[ n \right] + \left[ 2n - 2(1) \right] + \left[ 3n - 3(2) \right] + \cdots + \left[ n^2 - n(n-1) \right] \bigr)^2 \\
&amp;amp;= \bigl( n + 2n + 3n + \cdots + n^2 - \left[ 1(2) + 2(3) + 3(4) + \cdots + (n-1)(n) \right] \bigr)^2 \\
&amp;amp;= \bigl( n\left( 1 + 2 + 3 + \cdots + n \right) - \left[ 1(2) + 2(3) + 3(4) + \cdots + (n-1)(n) \right] \bigr)^2 \\
&amp;amp;= \left( n \cdot \frac{n(n+1)}{2} - \bigl[ \ 1(2) + 2(3) + 3(4) + \cdots + (n-1)(n) \ \bigr] \right)^2 \\
\end{align*}\]

&lt;p&gt;Now the only problem left is to find an \(O(1)\) equation for the expression&lt;/p&gt;

\[\begin{equation} 1(2) + 2(3) + 3(4) + \cdots + (n-1)(n) \label{eq1} \tag{1} \end{equation}\]

&lt;p&gt;With some observation, we can see that&lt;/p&gt;

\[\begin{align*}
\eqref{eq1}
&amp;amp;= 1(1+1) + 2(2+1) + 3(3+1) + \cdots + (n-1)((n-1) + 1) \\
&amp;amp;= 1^2 + 1 + 2^2 + 2 + 3^2 + 3 + \cdots + (n-1)^2 + (n-1) \\
&amp;amp;= 1^2 + 2^2 + 3^2 + \cdots + (n-1)^2 + 1 + 2 + 3 + \cdots + (n-1) \\
&amp;amp;= \frac{(n-1)(n)(2(n-1)+1)}{6} + \frac{(n-1)(n)}{2} \\
&amp;amp;= \frac{(n-1)(n)(2n-1)}{6} + \frac{(n-1)(n)}{2} \\
&amp;amp;= \frac{(n-1)(n)}{2} \left( \frac{2n-1}{3} + 1 \right) \\
&amp;amp;= \frac{(n-1)(n)}{2} \left( \frac{2n-1 + 3}{3} \right) \\
&amp;amp;= \frac{(n-1)(n)(2n+2)}{6} \\
&amp;amp;= \frac{(n-1)(n)(n+1)}{3} \\[10px]
S_n
&amp;amp;= \left( \frac{n^2(n+1)}{2} - \frac{(n-1)(n)(n+1)}{3} \right)^2 \\
&amp;amp;= \left( n(n+1) \cdot \left(\frac{n}{2} - \frac{n-1}{3} \right) \right)^2 \\
&amp;amp;= \left( n(n+1) \cdot \left(\frac{3n - 2n + 2}{6} \right) \right)^2 \\
&amp;amp;= \left(\frac{n(n+1)(n+2)}{6}\right)^2 \quad (Q.E.D.) \\
\end{align*}\]

&lt;hr /&gt;

&lt;h1 id=&quot;g---wak-sani-satay&quot;&gt;G - Wak Sani Satay&lt;/h1&gt;
&lt;p&gt;I actually never understand the problem during the contest. My teammate says he knows how to do this, and I was like “okay, then thank you very much, I go read other problem”. Hence, I have nothing much to say about this problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt;    Ad-Hoc - Understanding Problem (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/g.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;This problem can be solved by a careful reading of the problem, understanding it correctly and implementing it correctly. One trick to solve such understanding problems is to translate the problem from &lt;em&gt;English&lt;/em&gt; to &lt;em&gt;Mathematics&lt;/em&gt;. The translations are:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;\(1\)kg meat \(= 85\) satay&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;retail price&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;nasi impit \(= 0.8\) per packet&lt;/li&gt;
      &lt;li&gt;chicken satay \(= 0.8\) per stick&lt;/li&gt;
      &lt;li&gt;beef satay \(= 1.0\) per stick&lt;/li&gt;
      &lt;li&gt;lamb satay \(= 1.2\) per stick&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;cost&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;chicken meat \(= 7.5\) per kg&lt;/li&gt;
      &lt;li&gt;beef meat \(= 24.0\) per kg&lt;/li&gt;
      &lt;li&gt;lamb meat \(= 32.0\) per kg&lt;/li&gt;
      &lt;li&gt;marinate meat for satay \(= 8.0\) per kg&lt;/li&gt;
      &lt;li&gt;nasi impit \(= 0.2\) per packet&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;with the information above, the net profit is trivial:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;cost per satay&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;chicken \(= 7.5\;/\;85 + 8.0\;/\;85\)&lt;/li&gt;
      &lt;li&gt;beef \(= 24.0\;/\;85 + 8.0\;/\;85\)&lt;/li&gt;
      &lt;li&gt;lamb \(= 32.0\;/\;85 + 8.0\;/\;85\)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;net profit&lt;/strong&gt; \(=\) retail price \(-\) cost
    &lt;ul&gt;
      &lt;li&gt;chicken = \(0.8 - (7.5\;/\;85 + 8.0\;/\;85)\) per satay&lt;/li&gt;
      &lt;li&gt;beef = \(1.0 - (24.0\;/\;85 + 8.0\;/\;85)\) per satay&lt;/li&gt;
      &lt;li&gt;lamb = \(1.2 - (32.0\;/\;85 + 8.0\;/\;85)\) per satay&lt;/li&gt;
      &lt;li&gt;nasi impit \(= 0.8 - 0.2 = 0.6\) per packet&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally, with all the information above we can just take amount \(\times\) net profit to get the total net profit.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;h---stroop-effect&quot;&gt;H - Stroop Effect&lt;/h1&gt;
&lt;p&gt;Another problem that I actually did not understand during the contest. My teammates solved this problem together. I think I was busy deriving F at that time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt;    Ad-Hoc - Understanding Problem (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/h.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Another understanding problem like G but more complicated and longer problem statement. This problem require a stronger &lt;em&gt;English&lt;/em&gt; basics and sense of logic to understand it. Same as above, we translate &lt;em&gt;English&lt;/em&gt; to &lt;em&gt;Mathematics&lt;/em&gt;. We get:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;You are given a sequence of 2 letter string consist of character ‘1’, ‘2’, ‘3’, ‘4’&lt;/li&gt;
  &lt;li&gt;The sequence is a &lt;em&gt;Stroop&lt;/em&gt; sequence &lt;em&gt;if and only if&lt;/em&gt; &lt;strong&gt;all&lt;/strong&gt; of the following condition are true:
    &lt;ol&gt;
      &lt;li&gt;number of “\(xx\)” must be equal to number of “\(xy\)” where \(x \ne y\) and \(x, y \in \{1, 2, 3, 4\}\)&lt;/li&gt;
      &lt;li&gt;for set of “\(xx\)”, number of ‘1’ = number of ‘2’ = … = number of ‘4’&lt;/li&gt;
      &lt;li&gt;for set of “\(xy\)”, number of ‘1’ = number of ‘2’ = … = number of ‘4’&lt;/li&gt;
      &lt;li&gt;for each “\(xy\)”, number of “\(x_1y_1\)” = number of “\(x_2y_2\)” = … = number of “\(x_4y_4\)”&lt;/li&gt;
      &lt;li&gt;for sequence “\(a_1b_1\)”,  ”\(a_2b_2\)”,  ”\(a_3b_3\)”,  \(\ldots\),  ”\(a_nb_n\)”,  \(a_i = a_{i+1} = a_{i+2}\)   &lt;em&gt;or&lt;/em&gt;   \(b_i = b_{i+1} = b_{i+2}\)   &lt;strong&gt;IS NOT ALLOWED&lt;/strong&gt;&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, note that we can simplify the 5 conditions above to the 4 conditions below for the ease of implementation:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;let &lt;em&gt;congruent&lt;/em&gt; = number of “\(x_1x_1\)” = number of “\(x_2x_2\)” = …&lt;/li&gt;
  &lt;li&gt;let &lt;em&gt;incongruent&lt;/em&gt; = number of “\(x_1y_1\)” = number of “\(x_1y_2\)” = …&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;congruent&lt;/em&gt; \(\times 4\)   ==   &lt;em&gt;incongruent&lt;/em&gt; \(\times 12\)&lt;/li&gt;
  &lt;li&gt;for sequence “\(a_1b_1\)”,  ”\(a_2b_2\)”,  ”\(a_3b_3\)”,  \(\ldots\),  ”\(a_nb_n\)”,  \(a_i = a_{i+1} = a_{i+2}\)   &lt;em&gt;or&lt;/em&gt;   \(b_i = b_{i+1} = b_{i+2}\)   &lt;strong&gt;IS NOT ALLOWED&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Checking all 4 conditions above will give you an AC.&lt;/p&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;i---super-ball&quot;&gt;I - Super Ball&lt;/h1&gt;
&lt;p&gt;This problem was a total failure. We did not solve it during the contest. At first glance, the problem seems &lt;em&gt;min cost flow&lt;/em&gt; to me. I have such thought because there is one &lt;em&gt;min cost flow&lt;/em&gt; problem in previous ICPC too. Then, I started to model the graph on a paper and analyze the complexity. The graph that I modeled is super messy and contain too many nodes. We end up giving up this problem because the time is running out and it is impossible to code a bug-free solution in that time limit.&lt;/p&gt;

&lt;p&gt;After the contest, I think about the problem again and &lt;em&gt;dp&lt;/em&gt; seem to be able to solve the problem because it looks like a &lt;em&gt;directed acyclic graph&lt;/em&gt;. My &lt;em&gt;dp&lt;/em&gt; assumption was further confirmed by the problem setter.&lt;/p&gt;

&lt;p&gt;Back to home, I coded the &lt;em&gt;dp&lt;/em&gt; solution and pass the test data in 30 minutes and I was speechless at that moment. I failed because I “think too much”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt;    Dynamic Programming (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/i.cpp&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;It is not so trivial that it is a DAG (&lt;em&gt;directed acyclic graph&lt;/em&gt;) but once you &lt;em&gt;assume&lt;/em&gt; it is a DAG, you can start to see the properties of DAG in the problems.&lt;/p&gt;

&lt;p&gt;First of all, let’s make some observation:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;the process of &lt;em&gt;producing&lt;/em&gt; and &lt;em&gt;recycling&lt;/em&gt; are independent to each other. Hence, they can be counted separately.&lt;/li&gt;
  &lt;li&gt;the process of &lt;em&gt;producing&lt;/em&gt; and &lt;em&gt;recycling&lt;/em&gt; is exactly the same. Hence, they can be computed using the exact same algorithm. (From now on, we will only be focus on the algorithm to find the cost for &lt;em&gt;producing&lt;/em&gt;, &lt;em&gt;recycling&lt;/em&gt; is just &lt;em&gt;producing&lt;/em&gt; in reverse direction)&lt;/li&gt;
  &lt;li&gt;you &lt;strong&gt;must&lt;/strong&gt; go through \(N\) factory to produce \(N\) layer. (I know you can produce \(2\) layer at the same factory but for the sake of generalization, let’s assume that this process is &lt;em&gt;produce&lt;/em&gt; layer \(1\) &lt;strong&gt;then&lt;/strong&gt; transfer to &lt;em&gt;same&lt;/em&gt; factory with &lt;em&gt;cost of&lt;/em&gt; \(0\) &lt;strong&gt;then&lt;/strong&gt; produce layer \(2\))&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following flow graph represents our problem. The capacity of the edge in the following flow graph is all \(1\). The &lt;em&gt;min cost flow&lt;/em&gt; of the following graph will be our answer to this problem.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://limyunkai.com/assets/images/ICPC2018-I-Annotated.svg&quot; alt=&quot;flow-graph&quot; /&gt;&lt;/p&gt;

&lt;p&gt;However, you do not need a &lt;em&gt;min cost flow&lt;/em&gt; algorithm to solve the problem. Since the graph above is a DAG, you can use &lt;em&gt;dynamic programming&lt;/em&gt; to solve the problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the following solution use \(0\)-based indexing to be consistent with my code solution&lt;/p&gt;

&lt;p&gt;Let&lt;/p&gt;

\[\begin{align*}\text{dp}(l, f) =&amp;amp; \ \text{cost to produce layer } 0 \text{ to layer } l \textbf{ and } \\
&amp;amp; \ \text{the ball is currently at factory } f \\
\text{cost}(l, f) =&amp;amp; \ \text{cost to produce layer $l$ at factory $f$} \\
\text{cost}(l, f) =&amp;amp; \ \infty, \quad \text{if factory $f$ is unable to produce layer $l$} \\
\text{dist}(f_1, f_2) =&amp;amp; \ \text{cost to transfer the ball from factory $f_1$ to $f_2$}
\end{align*}\]

&lt;p&gt;&lt;strong&gt;Base case:&lt;/strong&gt;&lt;/p&gt;

\[\text{dp}(0, f) = \text{cost}(0, f) \quad \text{for} \quad 0 \le f &amp;lt; F\]

&lt;p&gt;&lt;strong&gt;Recurrence:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A bit similar to B, after the ball is at factory \(f\), the ball has to choose its next destination to produce its next layer. The ball can choose any of the factories as long as the factory is able to produce its next layer.&lt;/p&gt;

\[\displaylines{ \text{dp}(l, f) = \text{min}(\ \ \text{dist}(i, f) + \text{cost}(l, f)+ \text{dp}(l-1, i)\ \ ) \\ \text{for} \quad 0 \le i, f &amp;lt; F, \ \  1 \le l &amp;lt; N }\]

&lt;p&gt;&lt;strong&gt;The answer:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After the &lt;em&gt;dp&lt;/em&gt; table is computed, we can obtain our answer at&lt;/p&gt;

\[\text{minimum cost} = \text{min}(\ \ \text{dp}(N-1, f)\ \ ) \quad \text{for} \quad 0 \le f &amp;lt; F\]

&lt;hr /&gt;

&lt;h1 id=&quot;j---virus-outbreak&quot;&gt;J - Virus Outbreak&lt;/h1&gt;
&lt;p&gt;Before the contest start, I was tasked to read and understand the last 3 problems (H, I, J). When the contest starts, I started with H, and I was like “hmm, lengthy statement, I probably should try with the next one”. Then, I continue to I and it was the same !! I continue to skip until J and finally found a shorter statement. After understands the problem ask us to identify the sequence, I list down the sequence into a table with their known corresponding value. \(1\), \(3\) and \(8\) immediately caught my attention and “It is Fibonacci !!!”. Also, I noticed that you probably need some big integer. Hence, I quickly grab the PC, coded a python solution and get the first AC in the contest at \(6\)-th minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Solution:&lt;/em&gt;&lt;/strong&gt;    Identify the Pattern - Fibonacci (&lt;a href=&quot;https://github.com/limyunkai19/Malaysia-National-ACM-ICPC/blob/master/2018/solution/j.py&quot;&gt;Code&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For those who are familiar with Fibonacci sequence, the number \(3\) and \(8\), should probably give you an alert that it is a Fibonacci. For those who are not familiar with the Fibonacci sequence, this problem might be hard.&lt;/p&gt;

&lt;hr /&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="competitive-programming" /><category term="blog" /><category term="acm-icpc" /><summary type="html">I participated in this contest as my final national ACM-ICPC contest. With a certain amount of luck, my teammates (Jenn Pang and Wing Khang) and I won the contest.</summary></entry><entry><title type="html">Why Jekyll, Minimal Mistakes and GitHub Pages</title><link href="https://limyunkai.com/why-jekyll-minimal-mistakes-and-github-pages/" rel="alternate" type="text/html" title="Why Jekyll, Minimal Mistakes and GitHub Pages" /><published>2018-01-13T00:30:00+08:00</published><updated>2018-01-13T00:30:00+08:00</updated><id>https://limyunkai.com/why-jekyll-minimal-mistakes-and-github-pages</id><content type="html" xml:base="https://limyunkai.com/why-jekyll-minimal-mistakes-and-github-pages/">&lt;p&gt;To begin this blog post, let’s be aware that currently there is a lot of blogging platforms available on the Internet. &lt;a href=&quot;https://startbloggingonline.com/blog-platform-comparison-chart/&quot;&gt;This page&lt;/a&gt; and &lt;a href=&quot;http://www.wpbeginner.com/beginners-guide/how-to-choose-the-best-blogging-platform/&quot;&gt;this page&lt;/a&gt; provide a comparison on the major platforms available. Wordpress seems to be the one that is recommended in both pages.&lt;/p&gt;

&lt;p&gt;However, I myself have my own concern about my site. These are what I concern about my site:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Customizable on HTML/CSS level (I am a geek)&lt;/li&gt;
  &lt;li&gt;Free hosting (who doesn’t want free stuff?)&lt;/li&gt;
  &lt;li&gt;Custom domain (yeah, I want limyunkai.com)&lt;/li&gt;
  &lt;li&gt;User experience (must be easy to use, of course)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short, I want to have a &lt;strong&gt;simple&lt;/strong&gt; and &lt;strong&gt;highly customizable&lt;/strong&gt; site using &lt;strong&gt;custom domain name&lt;/strong&gt; and hosted for &lt;strong&gt;free&lt;/strong&gt;. &lt;em&gt;Fulfilling all&lt;/em&gt; my requirements seem too good to be true, and don’t forget that free stuff usually comes with some catches (either they are stealing your personal information, hidden charges or other catches that I couldn’t know). Luckily, I know that GitHub Pages host your static site for free (yes, free and there is no catch).&lt;/p&gt;

&lt;p&gt;Keeping in mind that GitHub Pages host static site for free, a quick Google shows that Jekyll works well with GitHub Pages. Instantly, I knew that Jekyll-GitHub combo is what I am looking for. Here’s why:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It is serving static site — why would you need database and server-side language for a blog :laughing:&lt;/li&gt;
  &lt;li&gt;Completely free&lt;/li&gt;
  &lt;li&gt;Highly customizable — I have full control on the codes of my site&lt;/li&gt;
  &lt;li&gt;Easy to use once the setup is done&lt;/li&gt;
  &lt;li&gt;I write my content in a simple way (with Markdown) yet highly customizable (with HTML)&lt;/li&gt;
  &lt;li&gt;LaTeX support — I need to write math equations&lt;/li&gt;
  &lt;li&gt;Hey, it is GitHub
    &lt;ul&gt;
      &lt;li&gt;I already have a GitHub account&lt;/li&gt;
      &lt;li&gt;I am comfortable with git and GitHub&lt;/li&gt;
      &lt;li&gt;They handle the security problem (as oppose to private cloud, you have to concern about the security)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;I always prefer the geek way of doing things&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, it is time to look for a Jekyll theme. I am looking for something clean and simple. Jekyll default theme is &lt;em&gt;too&lt;/em&gt; clean and &lt;em&gt;too&lt;/em&gt; simple, like it is nothing. After that, I found out that &lt;a href=&quot;https://github.com/mmistakes/minimal-mistakes&quot;&gt;Minimal Mistakes&lt;/a&gt; looks nice for me and I decided to use it as my theme.&lt;/p&gt;

&lt;p&gt;I need to setup the Jekyll, Minimal Mistakes and GitHub Pages combo to work on my local environment as well as GitHub Pages. The method documented on Minimal Mistakes &lt;a href=&quot;https://mmistakes.github.io/minimal-mistakes/docs/quick-start-guide/#github-pages-method&quot;&gt;quick-start guide&lt;/a&gt; seems to be not working (or I am missing out something).&lt;/p&gt;

&lt;p&gt;What motivates me to create the &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll&quot;&gt;minimal-mistakes-jekyll&lt;/a&gt; repository is that I wish to figure out an easy way to setup this combo, so that I can tell my non-technical friends who wish to start a blog or a site, “Hey, you want to have your own website? Just register a GitHub account and follow my guide. It’s free !!”. After trying and error several methods in the documentation, I found out that copying the theme files seems to works the best and suit my needs.&lt;/p&gt;

&lt;p&gt;Jekyll becomes intuitive to me once I figure out the file structure and &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll#file-structure&quot;&gt;documented it in README&lt;/a&gt; of my repository. I also wrote an &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll&quot;&gt;instruction&lt;/a&gt; that non-technical person can follow and make some &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll#customization&quot;&gt;changes&lt;/a&gt; on the theme to further suit my needs.&lt;/p&gt;

&lt;p&gt;Wish to start your own blog or website? Just fork &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll&quot;&gt;minimal-mistakes-jekyll&lt;/a&gt; to get started :smile:&lt;/p&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="blog" /><category term="web-dev" /><category term="jekyll" /><category term="minimal-mistakes" /><category term="github" /><category term="thought" /><summary type="html">To begin this blog post, let’s be aware that currently there is a lot of blogging platforms available on the Internet. This page and this page provide a comparison on the major platforms available. Wordpress seems to be the one that is recommended in both pages.</summary></entry><entry><title type="html">Why and How I Switch from Sublime Text to Atom</title><link href="https://limyunkai.com/why-and-how-i-switch-from-sublime-text-to-atom/" rel="alternate" type="text/html" title="Why and How I Switch from Sublime Text to Atom" /><published>2018-01-08T00:30:00+08:00</published><updated>2018-01-08T00:30:00+08:00</updated><id>https://limyunkai.com/why-and-how-i-switch-from-sublime-text-to-atom</id><content type="html" xml:base="https://limyunkai.com/why-and-how-i-switch-from-sublime-text-to-atom/">&lt;p&gt;I have been a huge fan of Sublime Text. It is my second text editor (the first is notepad++). Since a long time ago, I am aware of the existent of Atom text editor but I thought it is almost the same as Sublime Text, hence I am going to stick to Sublime Text since I am more familiar with it and I &lt;em&gt;thought&lt;/em&gt; Sublime and Atom are almost the same in terms of code editing experience.&lt;/p&gt;

&lt;p&gt;I am fine with Sublime Text for a long period of time as I mainly use Sublime Text to code C++ or Python program and I am having an awesome coding experience in Sublime Text. However, as I am dealing with more variety of stuff recently I started to notice the shortage and limitation of Sublime Text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; From now on, all the features I am discussing are out-of-the-box features. (Seriously, I don’t like to install too many third-party plugins)&lt;/p&gt;

&lt;p&gt;The first time I notice the limitation of Sublime Text is when I am dealing with files with Chinese character with GBK encoding. As usual, I used Sublime Text to view and edit the file, but, surprisingly, Sublime Text did not provide support for GBK encoding out-of-the-box. A quick Google shows that there are 2 ways for me to deal with GBK encoding, install GBK plugins on Sublime or use Atom. I chosen the former, tried to install the plugins and realize it is kind of inconvenient to use those plugins (I had forgotten the exact detail but I remember I did not use Sublime Text for GBK, it must involve some tedious setup or poor user experience for me to ditch Sublime Text on GBK). Out of frustration, I installed Atom and yes, Atom does well with the GBK encoding. However, due to my support toward Sublime Text, I still stick to Sublime Text on general text editing and coding.&lt;/p&gt;

&lt;p&gt;After that, Sublime Text still serves me quite well in text editing. The breaking point when I finally decided to switch from Sublime to Atom is when I need to do Markdown editing. Same as the case above, a quick google shows that there are 2 ways for me to deal with Markdown, install plugins or use Atom. As usual, I choose the former. Installing the plugins was easy, but the user experience is not good (if compared to Atom, I can safely use the word &lt;em&gt;sucks&lt;/em&gt;). You need to manually generate the preview every time you wish to view the preview and it usually takes a few seconds to generate it. Then, you need to switch the window to a browser to view your Markdown and then switch back to Sublime Text to continue you Markdown editing. Then, I tried to use Atom, guess what Atom does? &lt;strong&gt;out-of-the-box&lt;/strong&gt; Markdown preview and syntax highlighting, &lt;strong&gt;side-by-side&lt;/strong&gt; preview and &lt;strong&gt;live update&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At this moment, I know that I have to make the switch. The only reason I stay in Sublime was my love toward it but there is a ton of reason to make the switch. I am sorry Sublime, I have to ditch you now :cry:.&lt;/p&gt;

&lt;p&gt;Here are the reasons that make me &lt;strong&gt;make&lt;/strong&gt; the switch.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Atom is practically the superset of Sublime Text (I can safely say that 85% of what Sublime Text can do, Atom can do better)&lt;/li&gt;
  &lt;li&gt;The GBK encoding support (as described above)&lt;/li&gt;
  &lt;li&gt;The Markdown editing user experience (as described above)&lt;/li&gt;
  &lt;li&gt;Other cool features that Atom ships
    &lt;ul&gt;
      &lt;li&gt;Project-wide search function&lt;/li&gt;
      &lt;li&gt;Git integration &lt;br /&gt; (This is actually super cool, files status on git are color indicated, gitignored files are light gray, staged file are green, unstaged modifies are orange)&lt;/li&gt;
      &lt;li&gt;Spell checker&lt;/li&gt;
      &lt;li&gt;Live, side-by-side HTML/CSS preview&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;It is free and open source (I know Sublime Text is &lt;em&gt;free&lt;/em&gt; too, but if you need a &lt;em&gt;license&lt;/em&gt;, you need to pay right?)&lt;/li&gt;
  &lt;li&gt;Atom icon looks nicer than Sublime Text most recent icon :laughing: (I like the preview Sublime Text icon but not that latest one)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of course, there are reasons that somewhat make me &lt;strong&gt;refuse&lt;/strong&gt; to the switch too.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Sublime Text is blazing fast (&amp;lt; 1 sec), Atom is somewhat fast (~ 3 sec) to open a file or directory&lt;/li&gt;
  &lt;li&gt;There is no out-of-the-box hex editor on Atom&lt;/li&gt;
  &lt;li&gt;There are definitely some features in Sublime Text I gonna miss but currently, I am still not sure, haven’t code too much on Atom yet (more Atom plugins? :fearful:)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, I am only discussing features that I know and might use, certainly there are awesome features in Sublime Text and Atom I had missed and unaware of but currently, I focus on those features I am aware of.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How&lt;/strong&gt; do I make the switch?&lt;/p&gt;

&lt;p&gt;The feels of both editors at first glance are almost same, below are the differences that I am aware of.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Atom doesn’t have a minimap (I don’t really use the minimap, so I am okay with this)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/atom/atom/issues/13318&quot;&gt;This&lt;/a&gt; issue. Sadly, as I am aware of, there is still no fix&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, configure my &lt;strong&gt;setting&lt;/strong&gt; for my text editor&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;always reopen previous state after closing the editor &lt;br /&gt; (Preferences -&amp;gt; Core -&amp;gt; Restore Previous Windows On Start)&lt;/li&gt;
  &lt;li&gt;trim whitespace on save &lt;br /&gt; (Preferences -&amp;gt; Packages -&amp;gt; whitespace -&amp;gt; Ensure Single Trailing New Line, Keep Markdown Line Break, Remove Trailing Whitespace)&lt;/li&gt;
  &lt;li&gt;scroll past end &lt;br /&gt; (Preferences -&amp;gt; Editor -&amp;gt; Scroll Past End)&lt;/li&gt;
  &lt;li&gt;shows current file line ending (unix/dos) and encoding &lt;br /&gt; (default is shown on bottom right corner)&lt;/li&gt;
  &lt;li&gt;replace tab with whitespace. Yes, I &lt;em&gt;hate&lt;/em&gt; tab &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\t&lt;/code&gt; character in my code, unless I am coding with &lt;em&gt;whitespace&lt;/em&gt; language? &lt;br /&gt; (default is good)&lt;/li&gt;
  &lt;li&gt;tab length = 4 &lt;br /&gt; (Preferences -&amp;gt; Editor -&amp;gt; Tab Length -&amp;gt; 4)&lt;/li&gt;
  &lt;li&gt;show whitespace (line ending, tab, space) on highlight. This is a feature I like and use a lot in Sublime Text &lt;br /&gt; (Preferences -&amp;gt; Editor -&amp;gt; Check Show Invisibles -&amp;gt; Paste the following at stylesheet file, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;styles.less&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;atom-text-editor {
    .leading-whitespace, .invisible-character {
        color: #222;
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;key binding &lt;br /&gt; (Paste the following at keymap file, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keymap.cson&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;'atom-workspace atom-text-editor:not([mini])':
    'cmd-shift-up': 'editor:add-selection-above'
    'cmd-shift-down': 'editor:add-selection-below'
    'ctrl-shift-up': 'editor:move-line-up'
    'ctrl-shift-down': 'editor:move-line-down'

'.platform-darwin atom-text-editor':
    'cmd-d': 'find-and-replace:select-all'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Up&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Down&lt;/code&gt; — Swap lines up or down&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cmd&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shift&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Up&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Down&lt;/code&gt; — Multi-select line above or below&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cmd&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt; — Select all&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;As I am still (relatively) new to Atom, I think I will miss out quite a lot of differences, I will edit this post if I found out other stuff that is different in Atom.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updates:&lt;/strong&gt; I actually switch back to Sublime Text 3 after trying to do extensive coding (Python, C++ and etc) on Atom. Now, I am using Sublime Text as my main text editing and use Atom for Markdown editing.&lt;/p&gt;

&lt;p&gt;A few reasons that make me return to Sublime Text:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Atom is slow, like super slow (compared to Sublime Text) and this is the main reason I ditch atom for general text editing.
&lt;img src=&quot;https://limyunkai.com/assets/images/atom-slow.gif&quot; alt=&quot;atom-slow&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;Atom cache of unsaved files is problematic and might cause data loss. Unlike Notepad++ or Sublime Text, when you have unsaved files, you close the application you will know your data is safe.&lt;/li&gt;
  &lt;li&gt;I am more used to the shortcut and environment of Sublime Text, I feel much more comfortable to do coding in Sublime Text compare to Atom.&lt;/li&gt;
&lt;/ul&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="blog" /><category term="how" /><category term="sublime-text" /><category term="atom" /><category term="text-editor" /><category term="setup" /><summary type="html">I have been a huge fan of Sublime Text. It is my second text editor (the first is notepad++). Since a long time ago, I am aware of the existent of Atom text editor but I thought it is almost the same as Sublime Text, hence I am going to stick to Sublime Text since I am more familiar with it and I thought Sublime and Atom are almost the same in terms of code editing experience.</summary></entry><entry><title type="html">My First Blog Post</title><link href="https://limyunkai.com/my-first-blog-post/" rel="alternate" type="text/html" title="My First Blog Post" /><published>2017-12-22T00:30:00+08:00</published><updated>2017-12-22T00:30:00+08:00</updated><id>https://limyunkai.com/my-first-blog-post</id><content type="html" xml:base="https://limyunkai.com/my-first-blog-post/">&lt;p&gt;I enjoy doing stuff that is cool, challenging and fun. Particularly, I am interested in problem solving, mathematics (especially, mathematics olympiad), informatics olympiad (competitive programming), Artificial Intelligent (AI), algorithm, robotic, Internet of Things (IoT), Capture the Flag (CTF) and development related topics.&lt;/p&gt;

&lt;p&gt;I learnt a lot while I am exploring these topics. However, I tend to forget something that I had learnt and had to browse through the Internet to relearn something that I had learnt before. This is super unproductive. For example, I learnt how to setup a &lt;em&gt;nginx&lt;/em&gt; server and I found out several tips and tricks when setting it up, but several months later when I need to setup another &lt;em&gt;nginx&lt;/em&gt; server, I know the general steps but I had forgotten some important tips and tricks.&lt;/p&gt;

&lt;p&gt;Hence, I decided to blog about stuff that I had learnt to act as a reminder for myself and also helping others to pick something up fast. I will also blog about other things that I feel interesting (usually technical). This blog will act as a medium to express my thought and to polish my English writing too.&lt;/p&gt;

&lt;p&gt;When I decided to write a blog, there are several things to consider, including the blogging engine, where to host, the theme and style of the site and etc. After a short research on several options, I decided to use Jekyll, GitHub Pages, and Minimal Mistakes theme. Why this combo? This is answered in a separated &lt;a href=&quot;/why-jekyll-minimal-mistakes-and-github-pages/&quot;&gt;blog post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After deciding the Jekyll, GitHub Pages, and Minimal Mistakes combo, I need to actually set them up which is kind of non-trivial for me as there are many ways to setup this combo, but the trivial way does not allow customization of the theme. Hence, I spend some time browsing the Internet, try to understand how Jekyll works and find the best way to make the combo works.&lt;/p&gt;

&lt;p&gt;I then conclude my &lt;a href=&quot;/why-jekyll-minimal-mistakes-and-github-pages/&quot;&gt;findings&lt;/a&gt; in this repository &lt;a href=&quot;https://github.com/limyunkai19/minimal-mistakes-jekyll&quot;&gt;minimal-mistakes-jekyll&lt;/a&gt; as a simple yet customizable way to setup Jekyll on Github Pages.&lt;/p&gt;

&lt;p&gt;After setup all the technical stuff and get everything to works, I had to decide the configuration and plan the content. I had an idea of how should my site looks like, what my content should be and almost all the configuration, except one, the site title. I have a few options, either my name, omit it or other creative site titles. I tried using my name or omit it but it looks awkward and unsatisfactory to me.&lt;/p&gt;

&lt;p&gt;Hence, I decided to use a custom creative name as my site title. But now, the problem that makes me headaches comes to me (again), naming something. I am bad in giving name, all names I had ever used is either lame or stupid, like &lt;em&gt;KitKat&lt;/em&gt; as my programming competition group, &lt;em&gt;sudo rm -rf&lt;/em&gt; as my security competition group or &lt;em&gt;The Potatoes&lt;/em&gt; as my robotics hackathon group name, they are not really &lt;em&gt;creative&lt;/em&gt; (I think). After brainstorming for awhile, I fail to comes up with a good name.&lt;/p&gt;

&lt;p&gt;I asked around, telling my friend what I will be writing in my site and asking them for some suggestions. Some of their suggestion are either too &lt;em&gt;creative&lt;/em&gt; or &lt;em&gt;abstract&lt;/em&gt; and it does not fit as a technical site. The suggestions remain unsatisfactory until one of my friends suggested, “Binaries and Binomials”, and I was like, “Yes, that’s it! Thank you very much” (yes, I mean it, thanks for such fantastic name). It is technical, creative (I like the double &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bi&lt;/code&gt; syllable), and it suit my content perfectly (see &lt;a href=&quot;/about/#about-this-site&quot;&gt;About This Site&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;After everything is decided and configured, now I can focus on writing the contents of this site, and make some changes to the theme when I feel there is a need.&lt;/p&gt;

&lt;p&gt;Lastly, I would like to thank all my friends (including Google) that helped me in proofreading, suggestions in name, grammar and sentence structure.&lt;/p&gt;</content><author><name>Lim Yun Kai</name><email>yunkai96@hotmail.com</email></author><category term="blog" /><summary type="html">I enjoy doing stuff that is cool, challenging and fun. Particularly, I am interested in problem solving, mathematics (especially, mathematics olympiad), informatics olympiad (competitive programming), Artificial Intelligent (AI), algorithm, robotic, Internet of Things (IoT), Capture the Flag (CTF) and development related topics.</summary></entry></feed>