Arpa's blog

By Arpa, history, 5 weeks ago, In English
Problem Name Submission
A Flip Flops 367720299
B Array 367720294
C Find the Zero 367720318
D Ghostfires 367720275
E A Trivial String Problem 367720261

Full text and comments »

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

By Arpa, history, 2 months ago, In English
Problem Name Submission
A Sieve of Erato67henes 363202953
B Heapify 1 363202937
C Dice Roll Sequence 363202928
D Absolute Cinema 363202918
E Idiot First Search 363202902
F Parabola Independence 363202876
G Idiot First Search and Queries 363202867

Full text and comments »

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

By Arpa, 3 months ago, In English

I just returned from another camp, the longest ever. I've been in Saudi Arabia 🇸🇦 for 12 days, teaching around 20 students. The goal of the camp was to prepare students to shape their team for IOI.

After teaching in camps in Syria, Uzbekistan, Azerbaijan, Croatia, and India, this was yet another incredible experience of helping students push closer to their competitive programming goals.

I really enjoyed working with students, as usual; or maybe even more. There were three levels of students, and working with each of them was interesting. Again, I learned new things by teaching them to students, as usual.

The camp was hosted by KAUST, which is a very beautiful place.



I covered the following topics in our classes: Sack, DP, Games, Trie, Segment Tree, Arpa's trick, NSJ, and Backtrack. None of them were taught by me; they discovered it themselves, because my style of teaching is to never teach, but let students teach themselves.

I would like to thank the organizers for the invitation and the students for making it such a joyful experience.

Full text and comments »

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

By Arpa, history, 3 months ago, In English

We are conducting a comparative study on the structure, governance, and impact of student Olympiad systems in various countries.

Our aim is to gather open and comparable information about participation rules, student age and grade levels, selection processes, and the privileges granted to Olympiad medalists.

Please provide answers for your country based on your knowledge — even partial information is valuable and appreciated.

Full text and comments »

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

By Arpa, history, 3 months ago, In English

Watch the video describing solutions: Video Link

Watch the video of live participation: Video Link

Problem Name Submission
A DBMB and the Array 359896698
B Reverse a Permutation 359896674
C Replace and Sum 359896662
D Monster Game 359896642
E Product Queries 359896546
F Pizza Delivery 359896454
G Paths in a Tree 359896762
H Remove the Grail Tree 359896790

Full text and comments »

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

By Arpa, history, 3 months ago, In English

Watch the video describing solutions: Video Link

Watch the video of live participation: Video Link

Check out my submissions:

Problem Name Submission
A Perfect Root 358641451
B Prefix Max 358641429
C Shifted MEX 358641415
D OutOfMemoryError 358641372
E The Robotic Rush 358641342
F BattleCows 358641328
G Mixing MEXes 358641306
H BattleCows 2 359040200

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By Arpa, history, 3 months ago, In English

Watch the full video: Video Link

Check out my submissions

Problem Name Submission
A Social Experiment 357647486
B Hourglass 357647497
C Huge Pile 357647510
D Unfair Game 357647518
E Exquisite Array 357647523
F Cherry Tree 357647539
G Nastiness of Segments 357647548

Full text and comments »

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

By Arpa, history, 4 months ago, In English

Watch the full video: Video Link

Check out my submission: A (354851291), B (354851311), C (354851326), D (354851404), E (354851429), F (354852547), G (354851486), H (354851523).

Please let me know which style of problem-solving video you prefer.

  • Full virtual contest experience: Record everything from the start — reading the problem, thinking aloud, solving, and coding (example).
    → Gives the complete journey of solving a problem, but tends to be quite long.

  • Live reasoning after solving on paper: Record the thinking and coding after having a rough solution idea (example).
    → Might include some mistakes or wrong attempts before getting AC.

  • Post-solve explanation: First solve and get AC, then record a short and clear video explaining the solution idea and implementation (like in this video).
    → Concise and focused on insights.

Full text and comments »

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

By Arpa, history, 4 months ago, In English

Invitation to the Go for Gold December Long Challenge!

Competitive programmers, get ready! The Go for Gold Long Challenge is back, bringing another thrilling opportunity to test your problem-solving skills and climb the leaderboard on Codeforces!

We are excited to present yet another round of engaging and challenging problems for the community. Whether you're a seasoned competitor or just starting out, this contest is designed to offer a balanced mix of difficulty levels to help everyone push their limits.

The format of the Long Challenge is IOI-style, which includes subtasks in problems, so that everyone can try all of them.

Contest Details

Please join the codeforces group and register for the contest.

Why Should You Join?

  • Enhance Your Competitive Programming Skills
  • Gain Exposure to Unique Problems
  • Engage with an Active Community of Programmers

Contributors

All problems are prepared and tested by DeadlyCritic, ili, amiraskarieh2003, Hooded_Hood, MTSS.

You can join our Discord server for any questions.

We invite you to propose problem ideas for the next rounds. Give back to the community.

The countdown has begun! Mark your calendars and prepare to GoForGold once again. We can’t wait to see your amazing submissions.

Stay tuned for more updates and happy coding!

Full text and comments »

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

By Arpa, history, 5 months ago, In English

Watch the full video: Video Link

Check out my submission: A (352117104), B (352117084), C (352117125), D (352117146), E (352117168), F (352117257).

Please let me know which style of problem-solving video you prefer.

  • Full virtual contest experience: Record everything from the start — reading the problem, thinking aloud, solving, and coding (example).
    → Gives the complete journey of solving a problem, but tends to be quite long.

  • Live reasoning after solving on paper: Record the thinking and coding after having a rough solution idea (example).
    → Might include some mistakes or wrong attempts before getting AC.

  • Post-solve explanation: First solve and get AC, then record a short and clear video explaining the solution idea and implementation (like in this video).
    → Concise and focused on insights.

Full text and comments »

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

By Arpa, history, 5 months ago, In English

Hello Codeforces!

I’m going to introduce you to a C++ struct that helps you easily forget MOD, instead of always being nervous about it.


Using this struct, you can easily add, subtract, multiply, divide, and raise to a power without thinking about overflow or missing MOD. Everything is considered in it. This is very easy to use; copy, paste, and use. Let’s see a few examples.

Operation Before After
Addition
(a + b) % MOD
a + b
Subtraction
(a — b + MOD) % MOD
a — b
Multiplication
a * b % MOD
a * b
Division Maybe a * raising b to power MOD — 2?
a / b
Power Implementing the binary pow function
a.pow(b)

Let's look at a real problem, 296B - Ярослав и две строки. The following is the old solution (20869331) without using Mint:

int sbet = 1, pbet = 1, mos = 1;
for(int i = 0; i < n; i++)
    sbet = (ll) sbet * bet(s[i], p[i]) % mod,
        pbet = (ll) pbet * bet(p[i], s[i]) % mod,
        mos = (ll) mos * eq(p[i], s[i]) % mod;
int ans = 1;
int b = count(s.begin(), s.end(), '?') + count(p.begin(), p.end(), '?');
for(int a = 10; b; b >>= 1, a = (ll) a * a % mod)
    if(b & 1)
        ans = (ll) ans * a % mod;
(ans += mos) %= mod;
(ans -= sbet — mod) %= mod;
(ans -= pbet — mod)  %= mod;
cout << ans << '\n';

But now, see how clean the new version (351365035) is:

Mint sbet = 1, pbet = 1, mos = 1;
for (int i = 0; i < n; i++) {
    sbet *= bet(s[i], p[i]);
    pbet *= bet(p[i], s[i]);
    mos *= eq(p[i], s[i]);
}
Mint ans = Mint(10).pow(count(s.begin(), s.end(), '?') + count(p.begin(), p.end(), '?'));
cout << ans + mos - sbet - pbet << '\n';

More examples:

Benefits of the Mint struct:

  • You never need to use MOD in your code.
  • Operations with int and Mint are handled safely. Like 2 + x, x + 2, x / 2, all of them work.
  • Takes modulo only once, in its constructor.
  • Short, easy to implement if you want to type it (like in ICPC) or remember it.

Also, there is an appendix to the Mint struct which makes the factorials and comb function, which are useful in a lot of cases.

I've been using this for several years, and you can be sure it works fine.


Code here

If you want to copy/paste, use this.

Full text and comments »

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

By Arpa, history, 5 months ago, In English

Invitation to the Go for Gold November Long Challenge!

Competitive programmers, get ready! The Go for Gold Long Challenge is back, bringing another thrilling opportunity to test your problem-solving skills and climb the leaderboard on Codeforces!

We are excited to present yet another round of engaging and challenging problems for the community. Whether you're a seasoned competitor or just starting out, this contest is designed to offer a balanced mix of difficulty levels to help everyone push their limits.

The format of the Long Challenge is IOI-style, which includes subtasks in problems, so that everyone can try all of them.

Contest Details

Please join the codeforces group and register for the contest.

Why Should You Join?

  • Enhance Your Competitive Programming Skills
  • Gain Exposure to Unique Problems
  • Engage with an Active Community of Programmers

Contributors

All problems are prepared and tested by DeadlyCritic, ili, amiraskarieh2003, Hooded_Hood, MTSS.

You can join our Discord server for any questions.

We invite you to propose problem ideas for the next rounds. Give back to the community.

The countdown has begun! Mark your calendars and prepare to GoForGold once again. We can’t wait to see your amazing submissions.

Stay tuned for more updates and happy coding!

Full text and comments »

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

By Arpa, history, 5 months ago, In English

Watch the full video: Video Link

Check out my submission: A (349982917), B (349982921), C1 (349982923), C2 (349982926), D (349982929), E (349982933), F (349982935), G (349982912).

Please let me know which style of problem-solving video you prefer.

  • Full virtual contest experience: Record everything from the start — reading the problem, thinking aloud, solving, and coding (example).
    → Gives the complete journey of solving a problem, but tends to be quite long.

  • Live reasoning after solving on paper: Record the thinking and coding after having a rough solution idea (example).
    → Might include some mistakes or wrong attempts before getting AC.

  • Post-solve explanation: First solve and get AC, then record a short and clear video explaining the solution idea and implementation (like in this video).
    → Concise and focused on insights.

Full text and comments »

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

By Arpa, history, 6 months ago, In English

Note 1: This is not the official editorial. I prepared these solutions while testing the problems as a tester before the contest.

Note 2: The video tutorial is for those who prefer learning from videos and want to see implementation tips alongside the problem explanations.

Watch the full video: Video Link

Check out my submission: A (346358188), B (346358219), C (346358246), D (346358285), E (346358316), F (346358353), G (346358382).

Based on your feedback, I changed the video type from premiere to regular.

Please let me know how you prefer this kind of problem-solving video.

Please let me know which style of problem-solving video you prefer.

  • Full virtual contest experience: Record everything from the start — reading the problem, thinking aloud, solving, and coding (example).
    → Gives the complete journey of solving a problem, but tends to be quite long.

  • Live reasoning after solving on paper: Record the thinking and coding after having a rough solution idea.
    → Might include some mistakes or wrong attempts before getting AC.

  • Post-solve explanation: First solve and get AC, then record a short and clear video explaining the solution idea and implementation (like in this video).
    → Concise and focused on insights.

Full text and comments »

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

By Arpa, history, 6 months ago, In English

Hello Codeforces!

We're excited to announce GTOI: Graph Theory for Olympiad in Informatics, a free, community-driven book designed specifically for competitive programming.

Why it's important and different:

  • Completely Free & Open Source: High-quality knowledge, accessible to everyone.

  • Massive Coverage: It covers from the fundamentals like DFS, BFS to advanced topics like Heavy-Light Decomposition and Min-Cost Max-Flow.

  • Contest-Ready Code: Short, fast C++ snippets ready for you to use in a contest.


This is a community project, and we need your help!

The book is on GitHub, and we invite you to help us make it better. You can:

  • Contribute: Fix issues, add new topics, add images, or provide alternative code implementations.

  • Translate: Help us bring GTOI to your native language.




Let's work together to build the ultimate graph theory resource for competitive programmers.

Read the book online!
Contribute on GitHub

Project Creator and Coordinator dorostmishe

Authors dorostmishe, Shayan.P, Matin.Asp, AliTavassoly, Amoo_Safar, _MGH_, ArshiaDadras, AliShahali1382, Kalam, KMAASZRAA, _Seyed37_

English Translators dorostmishe, AliTavassoly, Arpa

Full text and comments »

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

By Arpa, history, 6 months ago, In English

Note 1: This is not the official editorial. I prepared these solutions while testing the problems as a tester before the contest.

Note 2: The video tutorial is for those who prefer learning from videos and want to see implementation tips alongside the problem explanations.

Watch the full video: Video Link

Check out my submission: A (344369578), B (344369585), C (344369588), D (344369598), E (344369602), F (344369606), G (344369610), H (344369616).

Based on your feedback, I changed the video type from premiere to regular.

Please let me know how you prefer this kind of problem-solving video.

Please let me know which style of problem-solving video you prefer.

  • Full virtual contest experience: Record everything from the start — reading the problem, thinking aloud, solving, and coding (example).
    → Gives the complete journey of solving a problem, but tends to be quite long.

  • Live reasoning after solving on paper: Record the thinking and coding after having a rough solution idea (like in this video).
    → Might include some mistakes or wrong attempts before getting AC.

  • Post-solve explanation: First solve and get AC, then record a short and clear video explaining the solution idea and implementation.
    → Concise and focused on insights.

Full text and comments »

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

By Arpa, history, 6 months ago, In English

Invitation to the Go for Gold October Long Challenge!

Competitive programmers, get ready! The Go for Gold Long Challenge is back, bringing another thrilling opportunity to test your problem-solving skills and climb the leaderboard on Codeforces!

We are excited to present yet another round of engaging and challenging problems for the community. Whether you're a seasoned competitor or just starting out, this contest is designed to offer a balanced mix of difficulty levels to help everyone push their limits.

The format of the Long Challenge is IOI-style, which includes subtasks in problems, so that everyone can try all of them.

Contest Details

Please join the codeforces group and register for the contest.

Why Should You Join?

  • Enhance Your Competitive Programming Skills
  • Gain Exposure to Unique Problems
  • Engage with an Active Community of Programmers

Contributors

All problems are prepared and tested by DeadlyCritic, ili, amiraskarieh2003, Hooded_Hood, MTSS.

You can join our Discord server for any questions.

We invite you to propose problem ideas for the next rounds. Give back to the community.

The countdown has begun! Mark your calendars and prepare to GoForGold once again. We can’t wait to see your amazing submissions.

Stay tuned for more updates and happy coding!

Full text and comments »

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

By Arpa, history, 7 months ago, In English

Hey, Codeforces!

I’m AmirReza PourAkhavan, the former Codeforces Contest Coordinator. I let the story become complete, and I’m sharing it now.

The story is about a 16-year-old competitive programmer who left his family and migrated to another city alone to follow competitive programming. After seven years, he advanced to the International Collegiate Programming Contest World Finals twice.

Read the previous parts: 1, 2, 3, 4.

Read the Persian version here.

This part covers from December 2016 to November 2017.

The Codeforces Contest

Our contest was held on Codeforces, and it broke several records.

  • The record for the highest number of upvotes on an editorial.
  • The record for the most comments under a contest announcement.
  • And probably, the record for the longest delay for a contest!

Famous people like Errichto even called its editorial the best they had ever read.

Full text and comments »

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

By Arpa, history, 7 months ago, In English

You might wonder: what kind of popular or controversial topic gets 175 comments?

The answer:


You are right! Codeforces edu section — Community Course! Most of the comments are "Still empty" :) But the good news is, this is not the case anymore!

I've just added the first set of tutorials on the RMQ Problem, which covers these three topics:

  • Sparse Table
  • SQRT Decomposition
  • Disjoint Sparse Table

It's just a starting point, but hopefully, it will encourage others to contribute. Let's work together to build a high-quality collection of competitive programming materials! Check out a related comment below.

Let me know if you have any comments on the tutorials, which will help future writers as well.

Full text and comments »

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

By Arpa, history, 7 months ago, In English

Note 1: This is not the official editorial. I prepared these solutions while testing the problems as a tester before the contest.

Note 2: The video tutorial is for those who prefer learning from videos and want to see implementation tips alongside the problem explanations.

Watch the full video: Video Link

Check out my submission: A (340623573), B (340623949), C (340624017), D (340623462), E (340623412), F (340623387), G (340754616).

Please let me know how you prefer this kind of problem-solving video.

  • A premier video (like this one), but you can’t jump to a specific problem until the video has ended.

  • A regular video without a chatbox.

Full text and comments »

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

By Arpa, history, 7 months ago, In English

Invitation to the Go for Gold September Long Challenge!

Competitive programmers, get ready! The Go for Gold Long Challenge is back, bringing another thrilling opportunity to test your problem-solving skills and climb the leaderboard on Codeforces!

We are excited to present yet another round of engaging and challenging problems for the community. Whether you're a seasoned competitor or just starting out, this contest is designed to offer a balanced mix of difficulty levels to help everyone push their limits.

The format of the Long Challenge is IOI-style, which includes subtasks in problems, so that everyone can try all of them.

Contest Details

Please join the codeforces group and register for the contest.

Why Should You Join?

  • Enhance Your Competitive Programming Skills
  • Gain Exposure to Unique Problems
  • Engage with an Active Community of Programmers

Contributors

All problems are prepared and tested by DeadlyCritic, ili, amiraskarieh2003, Hooded_Hood.

You can join our Discord server for any questions.

We invite you to propose problem ideas for the next rounds. Give back to the community.

The countdown has begun! Mark your calendars and prepare to GoForGold once again. We can’t wait to see your amazing submissions.

Stay tuned for more updates and happy coding!

Full text and comments »

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

By Arpa, history, 7 months ago, In English

Some small countries do very well at the IOI — is that luck, culture, money, or a training system?

Or maybe because some developed countries don't care about IOI at all, so there is no investment in it? If that's the case in your country, please leave a comment. By the way, why do you think that is?

See the first 20 countries at the IOI website (the full list is here):



The first 20 countries at the IOI


Also, this is the diagram showing the relation between a country’s IOI rank and its GDP per capita. A higher GDP per capita usually means the country is more developed and people have a good standard of living, so they can invest in areas that are not essential for survival. As you can see, there is no meaningful correlation between these two parameters!



Correlation between GDP per capita and IOI rank (click to see high quality photo)


Knowing the experience of other countries and the reasons behind their good results would help the community benefit from others’ experiences and grow CP in all countries.

Please share with us why your country is great or not great at IOI.

Let me start by telling you the story behind our success in Olympiads, including IOI. Iran is very good at Olympiads, as you may know. We took third place in five main important international Olympiads, considering overall performance. To find the root cause, we should go back in time. Iran participated in the IMO for the first time in 1985. The President at the time was a supporter of Olympiads and elites. The result was great. Shortly, a few laws were passed in favor of Olympiads:

  • National gold medal winners can enter any university without participating in the university entrance exam. The number of gold medals is twice the team size, e.g., there are eight gold medals for the Iran National Informatics Olympiads.
  • Other national medal winners (around 40 people in each Olympiad) get 20% added to their final score in the university entrance exam. This is a huge number.

Giving such big advantages to people who try for Olympiads made big communities participate in Olympiads. For example, around one hundred thousand Iranian students participated in Olympiads last year. Seven thousand of them participated in the Informatics Olympiad.

I made a YouTube Short describing the politics of our high schools regarding the IOI.

Full text and comments »

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

By Arpa, history, 8 months ago, In English

Join the codeforces group and checkout the contest.

Here, you can see the PDF version of the editorial.

Full text and comments »

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

By Arpa, history, 8 months ago, In English

Note 1: This is not the official editorial. I prepared these solutions while testing the problems as a tester before the contest.

Note 2: The video tutorial is for those who prefer learning from videos and want to see implementation tips alongside the problem explanations.

Watch the full video: Video Link

Check out my submissions: A, B, C, D, E, F, G.

Please let me know how you prefer this kind of problem-solving video.

  • A premier video (like this one), but you can’t jump to a specific problem until the video has ended.

  • A regular video without a chatbox.

Full text and comments »

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

By Arpa, 8 months ago, In English

👋 Salam, Codeforces!

We are excited to announce that the final round of the Rayan Programming Contest will be held onsite in Tehran, from November 25–29, 2025!

All participants ranked 1-1000 in the Rayan Selection Round are invited to complete the registration form by August 25, 2025 August 27, 2025. The final list of invited participants—selected based on rank and geographical diversity—will be announced shortly thereafter.

Beyond the chance to win top-tier prizes worth $40,000 USD, finalists will enjoy a unique opportunity to experience the timeless beauty and rich heritage of ancient Persia, with special highlights from the vibrant city of Tehran.

Hotel accommodation, local transportation, and meals are provided to all finalists. Moreover, a partial travel fund of 200 USD will be provided to all foreign participants (except prize winners).

🏆 World Finals Prizes:

  • 🥇 1st place: $15,000 💵
  • 🥈 2nd place: $10,000 💵
  • 🥉 3rd place: $5,000 💵
  • 🏅 4th–6th places: $2,000 each
  • 🏅 7th–10th places: $1,000 each

Furthermore, T-shirts for the top 50 participants of selection round as well as 50 more for randomly chosen participants ranked 51-1000 will be sent to those who complete the registration form. 👕

We look forward to seeing you on-site! 🎉

Register!

UPDATE (August 23): The registration summary so far is available here. The final selection process is described in this post.

UPDATE (August 26): Because of codeforces unavailability last night, the registration deadline has been extended to August 27.

UPDATE (August 29): The list of finalists for the Rayan 2025 World Finals has been announced.

Full text and comments »

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