Shayan's blog

By Shayan, 9 days ago, In English

Note: This is what I did. This is what I always tell my students. This is what I’m sharing because I believe it is very helpful for people here.

1. Are the tips I’m sharing the only way to reach Expert? No.

2. Is it the best way to reach Expert? Not necessarily, but I think so.

3. Can I leave hateful comments below? Do something more valuable lol. Write another blog explaining how you did it, or even a comment works.

4. Are you actually helping or just promoting your video? First, regardless of any benefit to me, this is valuable information for people. Second, I genuinely don’t need the promotion. 32,000 people have already watched it in a week, and this blog might add like 1,000 more, doesn’t make any noticeable difference for me.


Two types of advice

I believe advice generally falls into two types. Some advice is not controversial, so everyone agrees on it. By definition, it is ‘useless’ because it doesn’t add new knowledge. For example, telling someone to “practice” or “train hard” isn’t helpful since everyone already knows and agrees on that. It can serve as a reminder or motivation, but it doesn’t add knowledge.

On the other hand, some advice isn’t something you hear everywhere. Not everyone may agree with it. So, what I did here was share those kinds of opinions. And of course, anyone is free to agree or disagree in the comments. This is an open discussion.


Is there really a correct and incorrect way to learn competitive programming? Definitely. I’ve seen many people do it incorrectly. At the end of this blog, I’ll share experiences I’ve had with my previous students in different schools.

I’ll attach the video I've made at the end, but I’ll also summarize some of the key points for those who prefer reading.

Why am I so confident about this style? I've did it myself. As you can see in my rating graph, I went from newbie to expert in two months (March–May 2015), and after three months, I ranked 4th in a div 2 contest (still my best CP day ever). So, I confidently say that it works.

 My chart in early days


Okay, so what is it?

For example, I tell people to solve problems around their own rating. If your rating is 1200, solve many 1200-rated problems. It’s not a waste of time. Don’t jump to harder problems too soon. Many people do this, but they end up spending too much time thinking and not enough time implementing. Therefore, they become good at problem-solving but suck at implementation.

Also, don’t think too much. If you’re stuck, feel free to look at hints or solutions, that’s fine! You’re a beginner and you are building intuition. (Some people strongly disagree and think you should never check a solution, even if a gun is pointed at your head. I completely disagree, remember, you have just started.) I recommend choosing problem that on average you spend about 30 minutes per problem. (average! so you might solve some in 10 mins, and some in more than an hour) Some say, “Think on a hard problem for 5 hours and enjoy!” No. trust me, Accepting 10 different problems helps more at this stage. I also recommend reviewing other people’s code. Early on, this helps you write more efficient solutions.

And seriously, don’t start by learning algorithms. Just solve problems. Learning complex algorithms too early is mostly a waste of time. To reach expert, you only need to solve problems with tags like implementation, brute force, math, greedy, and DP. (DP is the only one that requires serious practice.)

Here you can see the full video:

Video — Going from Newbie to Expert in 2-3 months

This is a recurrent pattern, happened over and over again in my teaching experience. I start teaching in a school, and I see that after a year the students are still newbie/pupil at most. I work with them and in several months they get to expert. Why? The previous teacher was teaching them AVL tree (or similar things), solving very hard problems, etc. If you ask the students to explain some complex algorithm in a paragraph, they can do that. But if you give them a simple problem to accept, they can't.

Trust me, this is not the correct way to learn CP. And, yes, there is a correct way and an incorrect way.

Feel free to agree/disagree in the comments. It’s welcome and helps everyone to know opposite point of views.

Full text and comments »

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

By Shayan, 9 days ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2070A — FizzBuzz Remixed

Video

2070B — Robot Program

Video

2070C — Limited Repainting

Video

2070D — Tree Jumps

Video

2070E — Game with Binary String

Video

Full text and comments »

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

By Shayan, 3 weeks ago, In English

Hi Codeforces,

Our last topic stream was on Combinatorics. We talked about exponentiation, combination (+ why does it have that formula), what is a combinatorial proof (the most interesting part), and proved Pascal's equality and a bunch of other problems using that. Then, we talked about how to calculate combination with O(N) preprocess time and O(1) query time, and finally, solved 559C — Gerald and Giant Chess.

The Full Course

Exponentiation ($$$a^b$$$) in $$$O(lgb)$$$

Video

Combination $$$n\choose k$$$ and why is it $$$\frac{n!}{k!(n-k)!}$$$

Video

Algebraic proofs suck, what is a Combinatorial Proof

(+ Proving a bunch of equalities like Pascal's, using combinatorial proof)

Video

ChatGPT trolling me

Video

Calculating combination in code

simplest: $$$O(n^2+q)$$$

better: $$$O(n+qlgn)$$$

even better: $$$O(nlgn+q)$$$

not that much different: $$$O(n + q)$$$

Video

Solving 559C — Gerald and Giant Chess

(Combination + DP)

Video

This is the link to choose the topic for the next topic stream:

Full text and comments »

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

By Shayan, 4 weeks ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2065A — Skibidus and Amog'u

Video

2065B — Skibidus and Ohio

Video

2065C — Skibidus and Fanum Tax

Video

2065D — Skibidus and Sigma

Video

2065E — Skibidus and Rizz

Video

2065F — Skibidus and Slay

Video

2065G — Skibidus and Capping

Video

2065H — Bro Thinks He's Him

Video

Full text and comments »

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

By Shayan, 5 weeks ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

During today’s contest solution discussion, we tested ChatGPT o3-mini-high on our contest problems. And get this: it solved problems C and D! It claimed that it did it without internet access.

We asked about its capability, and it said that if it made a Codeforces account, its rating would be 3500–4000! I don’t know if AI has learned to solve very hard problems or if it’s getting overconfident.

All I can say is, things are getting pretty SCARY. I have no idea what’s going to happen with CP contests and competitive programmers soon.

2059A — Milya and Two Arrays

Video

2059B — Cost of the Array

Video

2059C — Customer Service

Video

GPT o3-mini-high Solved C

Video

2059D — Graph and Graph

Video

GPT o3-mini-high Solved D

Video

Asking ChatGPT if it is Cheating (Has Internet Access)

Video

o3 claiming that it has rating 3500 on Codeforces!

Video

Trying to Solve E2 with o2 — Not Successful

Video

P.S. Seems like rank 4000+ should be called GPT soon.

Full text and comments »

  • Vote: I like it
  • -87
  • Vote: I do not like it

By Shayan, history, 7 weeks ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2060A — Fibonacciness

Video

2060B — Farmer John's Card Game

Video

2060C — Game of Mathletes

Video

2060D — Subtract Min Sort

Video

2060E — Graph Composition

Video

2060F — Multiplicative Arrays

Video

2060G — Bugged Sort

Video

Full text and comments »

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

By Shayan, 3 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2050A — Line Breaks

Video

2050B — Transfusion

Video

2050C — Uninteresting Number

Video

2050D — Digital string maximization

Video

2050E — Three Strings

Video

2050F — Maximum modulo equality

Video

2050G — Tree Destruction

Video

Full text and comments »

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

By Shayan, history, 3 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2042A — Greedy Monocarp

Video

2042B — Game with Colored Marbles

Video

2042C — Competitive Fishing

Video

2042D — Recommendations

Video

2042E — Vertex Pairs (not complete)

Video

2042F — Two Subarrays

Video

Full text and comments »

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

By Shayan, 3 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2034A — King Keykhosrow's Mystery

Video

2034B — Rakhsh's Revival

Video

2034C — Trapped in the Witch's Labyrinth

Video

2034D — Darius' Wisdom

Video

2034E — Permutations Harmony

Video

Full text and comments »

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

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2037A — Twice

Video

2037B — Intercepted Inputs

Video

2037C — Superultra's Favorite Permutation

Video

2037D — Sharky Surfing

Video

2037E — Kachina's Favorite Binary String

Video

2037F — Ardent Flames

Video

2037G — Natlan Exploring

Video

Full text and comments »

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

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2028A — Alice's Adventures in "Chess"

Video

2028B — Alice's Adventures in Permuting

Video

2028C — Alice's Adventures in Cutting Cake

Video

2028D — Alice's Adventures in Cards

Video

2028E — Alice's Adventures in the Rabbit Hole

Video

2028F — Alice's Adventures in Addition

Video

Full text and comments »

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

By Shayan, history, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2029A — Set

Video

2029B — Replacement

Video

2029C — New Rating

Video

2029D — Cool Graph

Video

Full text and comments »

  • Vote: I like it
  • -34
  • Vote: I do not like it

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2036A — Quintomania

Video

2036B — Startup

Video

2036C — Anya and 1100

Video

2036D — I Love 1543

Video

2036E — Reverse the Rivers

Video

2036F — XORificator 3000

Video

2036G — Library of Magic

Video

Full text and comments »

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

By Shayan, history, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2032A — Circuit

Video

2032B — Medians

Video

2032C — Trinity

Video

2032D — Genokraken

Video

2032E — Balanced

Video

Full text and comments »

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

By Shayan, history, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2026A — Perpendicular Segments

Video

2026B — Black Cells

Video

2026C — Action Figures

Video

2026D — Sums of Segments

Video

2026E — Best Subsequence

Video

Full text and comments »

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

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2035A — Sliding

Video

2035B — Everyone Loves Tres

Video

2035C — Alya and Permutation

Video

2035D — Yet Another Real Number Problem

Video

2035E — Monster (Observations)

Video

Full text and comments »

  • Vote: I like it
  • -43
  • Vote: I do not like it

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2027A — Rectangle Arrangement

Video

2027B — Stalin Sort

Video

2027C — Add Zeros

Video

2027D2 — The Endspeaker (Hard Version)

Video

Full text and comments »

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

By Shayan, 4 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2033A — Sakurako and Kosuke

Video

2033B — Sakurako and Water

Video

2033C — Sakurako's Field Trip

Video

2033D — Kousuke's Assignment

Video

2033E — Sakurako, Kosuke, and the Permutation

Video

2033F — Kosuke's Sloth

Video

Full text and comments »

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

By Shayan, 5 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2030A — A Gift From Orangutan

Video

2030B — Minimise Oneness

Video

2030C — A TRUE Battle

Video

2030D — QED's Favorite Permutation

Video

2030E — MEXimize the Score

Video

Full text and comments »

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

By Shayan, 5 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2022A — Bus to Pénjamo

Video

2022B — Kar Salesman

Video

2022C — Gerrymandering

Video

2022D1 — Asesino (Easy Version)

Video

2022E1 — Billetes MX (Easy Version)

Video

2022E2 — Billetes MX (Hard Version)

Video

Full text and comments »

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

By Shayan, 5 months ago, In English

Hi,

Our last topic stream was on Number Theory. I will continue discussing number theory next week, where we will cover more facts and solve more problems.

Here is the text version of this topic stream. I will briefly summarize all the topics discussed in the livestream. You can watch the full session below.

Full Video of the Number Theory Session

Definition of GCD

In this section, I introduce the concept of the Greatest Common Divisor.

Video

Proving that gcd(a, b) = gcd(a — b, b)

As the title suggests, we prove a fact about GCD. This fact is extremely useful!

Video

The Naive Algorithm to Calculate GCD

Here, we introduce the naive solution to calculate the GCD. It works in O(min(a, b)) by simply iterating through all possible candidates.

Video

Extend the Fact to gcd(a, b) = gcd(a % b, b)

Then, we extend the fact that gcd(a, b) = gcd(a — b, b) to gcd(a, b) = gcd(a % b, b).

Video

Prove that a % b < a / 2 if a >= b

In this section, we prove another very useful fact, which helps us find the GCD with improved time complexity.

Video

O(lg a) Algorithm to Calculate GCD

Here, we use the facts to improve our solution to calculate the gcd of two numbers.

Video

Solving 1458A from Codeforces

In this section, the following problem will be solved. It is really beautiful.

https://codeforces.me/problemset/problem/1458/A

Video

How to Find All the Prime Numbers between 1 and N in O(N)

Another classic problem in number theory.

Video

Improving the Algorithm to O(N sqrt(N))

We use a simple fact to reduce one N to sqrt(N).

Video

Sieve of Eratosthenes — Improving the Algorithm to O(N.lgN)

Here, I introduce the Sieve of Eratosthenes. I explain the solution step by step, and at the end, I mention that this method is called the Sieve of Eratosthenes.

Video

Harmonic Series

In the middle of solving the problem with this method, we encounter with a number that we have to find out how big it is. We need this to find out the time complexity of our method. We will analyze the complexity of this number. We will analyze the complexity of this number, and we’ll see that it is actually known as the Harmonic Series.

Video

Solving 230B from Codeforces

Then, we try to use the topics we talked about to solve the following problem from Codeforces.

https://codeforces.me/problemset/problem/230/B

Video

Find the Smallest Prime Factor with Sieve

Actually, Sieve can be used to solve more challenging problems as well. Here, we discuss how to find the smallest prime factor of a number using Sieve.

Video

Full text and comments »

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

By Shayan, 5 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2020A — Find Minimum Operations

Video

2020B — Brightness Begins

Video

2020C — Bitwise Balancing

Video

2020D — Connect the Dots

Video

2020E — Expected Power

Video

Full text and comments »

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

By Shayan, 5 months ago, In English

Note: The text editorials will be provided by the authors of the round. This video tutorial acts as an additional resource for those who prefer video over text, not as a substitute for the text editorial.

2019A — Max Plus Size

Video

2019B — All Pairs Segments

Video

2019C — Cards Partition

Video

2019D — Speedbreaker

Video

2019E — Tree Pruning

Video

Full text and comments »

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

By Shayan, 6 months ago, In English

ICPC World Finals 2024 is happening right now, and I’m planning to upload a vlog every day. The internet speed here is a bit questionable, so it might take some time for the videos to go up.

By the way, the first video (day 0 and 1) is already uploaded, and day 2 will be up soon. You can also check out the pictures below!

This blog will be updated.

Day 0 & Day 1 Vlog

Full text and comments »

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

By Shayan, 6 months ago, In English

Hello Codeforces,

ICPC WF 2024 is happening next week, and we’re heading to Kazakhstan on Friday night.

As I’ve done plenty of interviews and AMAs, but I’ve never been the one answering questions, and as tomorrow will be our final training session, we’re planning to have an AUA afterward.

Sam (sam571128), Colin (galen_colin), and I (Shayan) will be there to talk about our goals for ICPC, how we’ve been preparing lately, and answer your questions. It’s going to be fun!

Here is the link: https://www.youtube.com/watch?v=UD4plaiJ4bc

(Since it’ll be late night in the US and not an appropriate time pretty much anywhere in the world, it will be recorded as well.)

Btw, the most important question of this blog post is, what’s your favorite team in ICPC this year? (UMD White, right?)

Full text and comments »

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