You can use several words in query to find by all of them at the same time. In addition, if you are lucky search understands word forms and some synonyms. It supports search by title and author. Examples:

  • 305 — search for 305, most probably it will find blogs about the Round 305
  • andrew stankevich contests — search for words "andrew", "stankevich" and "contests" at the same time
  • user:mikemirzayanov title:testlib — search containing "testlib" in title by MikeMirzayanov
  • "vk cup" — use quotes to find phrase as is
  • title:educational — search in title

Results

1.
By Um_nik, history, 5 years ago, In English
Things I don't know I'm just in a mood to shitpost. Don't take it too seriously. Things that I have heard of, but don't know (imagine how many things I haven't even heard of): - Li-Chao Segment Tree - Segment Tree Beats - RMQ in $O(n)$/$O(1)$ - Any self-balancing tree except treap - Link-cut tree - Wavelet tree - Mergesort tree - Binomial heap - Fibonacci heap - Leftist heap - Dominator tree - 3-connected components in $O(n)$ - $k$-th shortest path - Matching in general graph - Weighted matching in general graph - Preflow-push - MCMF in $O(poly(V, E))$ - Minimum arborescence (directed MST) in $O(E \log V)$ - Suffix tree - Online convex hull in 2D - Convex hull in 3D - Halfplane intersection - Voronoi diagram / Delaunay triangulation - Operation on formal power series (exp, log, sqrt, ...) (I know the general idea of Newton method) - How to actually use generating functions to solve problems - Lagrange Inversion formula - [...
- Operation on formal power series (exp, log, sqrt, ...) (I know the general idea of Newtonmethod, diagram / Delaunay triangulation - Operation on formal power series (exp, log, sqrt, ...) (I

Full text and comments »

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

2.
By parveen1981, history, 6 years ago, In English
I compiled a list of almost all useful blogs ever published on Codeforces [update: till 09.06.2021] <h3 style="color:red">If there are any blogs that I have missed, please tell in the comment section. Thank you.</h3> # Mathematics Stuff - [Number Theory in Competitive Programming [Tutorial]](https://codeforces.me/blog/entry/46620) - [Number of points on Convex hull with lattice points](https://codeforces.me/blog/entry/62183) - [FFT, big modulos, precision errors.](https://codeforces.me/blog/entry/48465) - [Number of ways between two vertices](https://codeforces.me/blog/entry/19078) - [Mathematics For Competitive Programming](https://codeforces.me/blog/entry/76938) - [FFT and NTT](https://codeforces.me/blog/entry/19862) - [Burnside Lemma](https://codeforces.me/blog/entry/51272) - [Number of positive integral solutions of equation 1/x+1/y=1/n!](https://codeforces.me/blog/entry/76836) - [On burnside (again)](https://codeforces.me/blog/entry/64860) - [Simple but often unknown theorems/lemmas/formula? Do you know?](https://codeforces.me/blog/entry/55912) - [Probabili...
Monovariants](https://codeforces.me/blog/entry/57216) - [Operations on Formal Power Series](https

Full text and comments »

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

3.
By EvenImage, history, 7 years ago, In English
A problem collection of ODE and differential technique ##A problem collection of ODE and differential technique *This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them.* For those who are interested in well-known problems in China. Thank [user:Elegia,2020-04-23] and [user:djq_cpp,2020-04-23] for developing this technique. Thank [user:tEMMIE.w.,2020-04-23] for reviewing this article. ####[Chain Reaction](http://uoj.ac/problem/50) in UOJ Round 3 By [user:vfleaking,2020-04-23] **Statement** ​ You are given a set $A$, you need to compute $g_{i} = \frac{1}{2} \sum_{j,k}{i-1 \choose j}{i-1-j \choose k} g_jg_k$ where $i-1-j-k \in A$. **Solution** ​ Let the EGF of $g$ be $x(t)$ and EGF of $A$ be $a(t)$. Thus $x'(t)=\frac{1}{2} a(t) x^2(t)+1$. We can solve this equation by D&C and FFT in $O(n\log^2 n)$. But there is a <s>slower</s> solution in $O(n\log n)$. ​ For a polynomial equation $f(x(t))=0$, we can use the Newton's method to solve it. If we find ...
)$. For a polynomial equation $f(x(t))=0$, we can use the Newton's method to solve it. If we find

Full text and comments »

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

4.
By MikeMirzayanov, history, 11 years ago, translation, In English
New: Educational Rounds on Codeforces! Hi everybody! First, I invite you to take part in an official [contest:597]. The fact is, the Codeforces team has made numerous changes to the platform (details are below), and we want to be sure that the basic functionality remained unchanged. This round will have a shortened duration of 1.5 hours, consist of 3 (maybe 4) problems that you might have already seen before. Its purpose is to test the system on the one hand, and on the other hand &mdash; to brighten up a Wednesday evening. Of course, the round will be unrated. Now the main thing. This coming Friday (yes, the 13th of November) Codeforces starts another line of rounds. We called them Educational Rounds. Using my students at the Saratov State University Programmings Competitions Training Center as an example, I regularly notice that even those who have a considerable progress in the results on the rounds often have narrow purview in terms of standard topics and ideas, they are not familiar with many well-known problems ...
to a wide range of participants; * Often the formal text of the statements; * Unrated (perhaps for

Full text and comments »

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

5.
By adamant, history, 4 years ago, In English
CDQ convolution (online FFT) generalization with Newton method Hi everyone! This is yet another blog that I had drafted for quite some time, but was reluctant to publish. I decided to dig it up and complete to a more or less comprehensive state for the [$300 contest](https://codeforces.me/blog/entry/110840). Essentially, the blog tells how to combine CDQ technique for relaxed polynomial multiplication ("online FFT") with linearization technique from Newton method (similar approach is used in the first example of the [ODE blog post](https://codeforces.me/blog/entry/76447) by [user:amiya,2023-01-14]), so that the functions that typically require Newton's method can be computed online as well. I will try to briefly cover the general idea of "online FFT" too and provide some examples, in case you're not well familiar with it. That being said... [cut] <hr> Consider the following setting: There is a differentiable function $F(x)$ such that $F(0)=0$ and a polynomial $f(x)$. You want to compute first $n$ coefficients of a formal power...
CDQ convolution (online FFT) generalization with Newton method, Newton method (similar approach is used in the first example of the [ODE blog post](https, Those are the functions that are quite typical in formal power series (for their interpretation, You want to compute first $n$ coefficients of a formal power series $g(x)$ such that $g(x) = F(f(x

Full text and comments »

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

6.
By purplesyringa, history, 5 years ago, In English
Analysis of polynomial hashing Unfortunately, most derivations of the chance of polynomial hashing collision are invalid, wrong, or misleading, and finding reliable public sources with proofs is incredibly difficult. This article is a formal analysis of the method. The goal of this article is to complement well-known empirical facts with theory, provide boundaries on the probability of collision, justify common choices, and advise against certain popular parameters. There is no code in this article, and it's mostly theoretical. It's more of a summa of everything we know about polynomial hashing in integers rather than a guide for beginners. You'll probably find something of interest still. I do, however, describe some methods of cracking hashes, which I can provide code and additional explanation for if someone asks in the comments and some general guidelines in the last section of the present article. ## Table of contents - The concept of polynomial hashing - Classical justification of the coprimality r...
is a formal analysis of the method. The goal of this article is to complement well-known empirical

Full text and comments »

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

7.
By MikeMirzayanov, history, 11 years ago, translation, In English
How to come up with the solutions: techniques As I work with students I often face the situation when if a problem doesn't seem clear to a student at the first sight, it makes them unable to solve it. Indeed, you always hear about specific methods and techniques. But you don't hear about how to think in order to apply them. In this note I'll try to sum up my experience of solving programming contest problems. However, some pieces of advice will also be applicable for olympiads in mathematics and your first steps in academic research. So you've read a problem and you don't know how to solve it. Try the following techniques, some of them can often come handy. ##### Technique 1: "Total Recall" Try to remember some similar problems that you had to solve. Quite many problems do not have a brand new idea. So probably, you can use your experience of solving a similar problem to solve this one. ##### Technique 2: "From Specific to General" Let's say that you've found the solution for the problem (hurray!). Let's consider ...
through the problem. ##### Technique 6: "Pick a Method" Try coming through popular algorithms or

Full text and comments »

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

8.
By zscoder, history, 7 years ago, In English
[Tutorial] Generating Functions in Competitive Programming (Part 1) Hi everyone! Inspired by the recent [Codeforces Round 641](https://codeforces.me/contest/1349), I decided to write an introductory tutorial on generating functions here. I am by no means an expert in generating functions so I will write about what I currently know about them. [user:MiFaFaOvO,2020-05-15] has written a really interesting [blog](https://codeforces.me/blog/entry/76447) here on Codeforces about more advanced applications of generating functions, but I think there is no English tutorial on the basics of this topic yet (or at least on CP sites). Thus, I would like to share about this topic here. I plan to split this tutorial into two parts. The first part (this post) will be an introduction to generating functions for those who have never learned about them at all, and some standard examples and showcases of generating functions. The second part will be a collection of several applications of generating functions in CP-style problems. If you are already familiar with ge...
$|x|<1$? Well, it depends on what you want to do with your series. We will work on [formal power

Full text and comments »

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

9.
By hyforces, history, 3 years ago, In English
Teamscode Summer 2023 Editorial This is the editorial for the recent Teamscode Summer 2023 contest, and the problems are open for upsolving on this [gym](https://codeforces.me/gym/104520). Problems were prepared by [user:oursaco,2023-08-22], [user:dutin,2023-08-22], [user:thehunterjames,2023-08-22], [user:Bossologist,2023-08-22], [user:Esomer,2023-08-22], [user:danx,2023-08-22], [user:codicon,2023-08-22], [user:willy108,2023-08-22], and [user:hyforces,2023-08-22]. The problems were tested by [user:omeganot,2023-08-22], [user:codicon,2023-08-22], [user:cry,2023-08-22], [user:skye_,2023-08-22], [user:Litusiano_,2023-08-22], and [user:apple_method,2023-08-22]. ### [A. Who is cooking?](https://codeforces.me/gym/104520/problem/A) <spoiler summary="Solution"> danx </spoiler> <spoiler summary="Code"> ~~~~~ print("Esomer") ~~~~~ </spoiler> ### [B. Restaurant Sorting](https://codeforces.me/gym/104520/problem/B) <spoiler summary="Solution"> The answer is $n - $ the longest prefix of the array where a...
to directly use method $2$ with them. We can't discard two numbers of this form at once, because, /noe35.pdf). Secondly, note that for a formal power series $f$, we have $s^n=e^{\ln s^n}=e^{n\ln s

Full text and comments »

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

10.
By maspy, history, 3 years ago, In English
FPS Composition and Compositional Inverse Hello. I am Japanese and have been publishing some articles within the Japanese-speaking community for some time now. This is my first attempt at translating one of my Japanese explanatory articles into English. (This is also the first CodeForces blog for me). The theme is the computation of formal power series composition and compositional inverse. - FPS Composition and Compositional Inverse - [(PART 1) Compositional Inverse and Power Projection](https://maspypy.com/fps-composition-and-compositional-inverse-part-1-compositional-inverse-and-power-projection) - [(PART 2) Composition Algorithm via Transposition Principle](https://maspypy.com/fps-composition-and-compositional-inverse-part-2) A method to improve the known computational complexity for this theme was introduced by [user:noshi91,2024-04-24] in March 2024. - https://noshi91.hatenablog.com/entry/2024/03/16/224034 - https://arxiv.org/abs/2404.05177 ([user:noshi91,2024-04-24] and [user:Elegia,2024-04-2...
formal power series composition and compositional inverse. - FPS Composition and Compositional

Full text and comments »

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

11.
By sigma__1, history, 8 months ago, In English
Editorial for CodeRed Prelims 2026 On behalf of the organizing team, we extend our deepest gratitude to everyone who participated in CodeRed Prelims 2026. Witnessing your dedication and fierce competitive spirit on the leaderboard validated the immense effort our team invested behind the scenes. Our problem-setters spent countless hours crafting and balancing these challenges. We sincerely hope the problemset provided a rewarding and engaging experience for the IIIT Allahabad community and our global participants. Below, you will find the official hints, detailed editorials, and author solutions. Happy upsolving! A: Ashutosh's Triad ---------------------- Author: [user:sigma__1,2026-04-16] <spoiler summary="Hint 1"> The phrase "minimize the maximum salary" is a classic indicator that we should use Binary Search on the answer. </spoiler> <spoiler summary="Hint 2"> Since $X$ is square-free, the maximum number of distinct prime factors $m$ is very small ($m \le 15$). Think about representing each wizard's ...
logarithmic series. To find the coefficients up to $N$, use Newton's Method for Formal Power Series (FPS, $, use Newton's Method for Formal Power Series (FPS). You'll need the Number Theoretic Transform (NTT, **4. Implementation Details and Newton's Method** To find the polynomial $A(x)$ such that $G(A

Full text and comments »

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

12.
By -is-this-fft-, history, 5 years ago, In English
[Math note] On the relationship between gf and me Today, I want to talk a bit about the relationship between two well-known methods for calculating the $n$-th term of a linear recurrence: **g**enerating **f**unctions and **m**atrix **e**xponentiation. More specifically, I want to explore how these two things are related to one another or how they can be thought of as variants of one another. This blog shouldn't be treated as a tutorial. If you know these algorithms, I doubt that I can teach you to solve some new problem in this blog. Rather, I'm kind of thinking out loud. I think it is a good idea to try to reflect and find connections between different things we have learned. This kind of thinking tends to strengthen the understanding of both methods and makes it easier to improve upon them to solve problems. And I'm sure that what I'm about to present is already quite well-known to some people ;). But when I realized this it was cool to me, so I want to share it. **Problem.** You have two sequences $b_1, b_2, \l...
$. [cut] $~$ #### Matrix exponentiation method **Fibonacci case.** Notice that for any $i \ge 2

Full text and comments »

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

13.
By EKGMA, 18 months ago, In English
Multiple PhD Positions Singapore Management University Hello Codeforces Community! ‌ Multiple PhD Positions in Formal Methods and Safe AI at the School of Computing and Information Systems, Singapore Management University. We have multiple fully funded PhD positions for motivated students who wish to push the boundaries of theory and automation of formal methods for guaranteed AI safety, under the supervision of Assistant Prof. Djordje Zikelic (https://djordjezikelic.github.io/). Possible PhD topics include: - Formal methods for learning-enabled control systems - Safe reinforcement learning - Verification and planning in Markov models - Probabilistic programming A strong candidate is expected to have solid mathematical background (demonstrated through courses such as algorithms, computability, automata theory, probability theory) and good coding skills. Master degree or prior publications are not necessary. Singapore is a vibrant and cosmopolitan place with a thriving academic landscape. It is also a perfect place for f...
excellent research environment with strong groups in formal methods, software engineering and AI. It is, of theory and automation of formal methods for guaranteed AI safety, under the supervision of, - Formal methods for learning-enabled control systems - Safe reinforcement learning, Hello Codeforces Community! ‌ Multiple PhD Positions in Formal Methods and Safe AI at the School, Multiple PhD Positions in Formal Methods and Safe AI at the School of Computing and Information

Full text and comments »

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

14.
By hly1204, history, 5 years ago, In English
A simple way to understand the transposed algo of multi-eval # A simple way to understand the transposed algo of multi-eval A simple way to understand the transposed algorithm of multi-point evaluation of polynomials in [Tellegen’s Principle into Practice](https://specfun.inria.fr/bostan/publications/BoLeSc03.pdf). I learned this from Bernstein's paper [Scaled Remainder Trees](http://cr.yp.to/arith/scaledmod-20040820.pdf). If there are any mistakes, please tell me, thanks! (Sorry for my poor English) Let $\mathbb{R}((x))$ denote the ring of formal Laurent series, $\mathbb{R}\lbrack x\rbrack$ denote the ring of polynomial. $f(x)\bmod 1:=f_{-1}x^{-1}+f_{-2}x^{-2}+\cdots$. Bernstein showed that division in $\mathbb{R}\lbrack x\rbrack$ is division in $\mathbb{R}((x^{-1}))$. Here is a concrete example. Let $A(x):=1+x+4x^2+5x^3+x^4+4x^5\in\mathbb{R}\lbrack x\rbrack$ and $B(x):=1+9x+8x^2+x^3\in\mathbb{R}\lbrack x\rbrack$, we want to compute $Q(x),R(x)\in\mathbb{R}\lbrack x\rbrack$ such that $A(x)=B(x)Q(x)+R(x)$ and $\deg R(x)\lt \deg B(x)$ ...
formal Laurent series, $\mathbb{R}\lbrack x\rbrack$ denote the ring of polynomial. $f(x)\bmod 1:=f_{-1}x, method that we compute the multiplicative inverse of formal power series $x^{\deg(p_1\cdots p_n)}p_1(x

Full text and comments »

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

15.
By Al.Cash, 12 years ago, In English
Efficient and easy segment trees This is my first attempt at writing something useful, so your suggestions are welcome. Most participants of programming contests are familiar with segment trees to some degree, especially having read this articles http://codeforces.me/blog/entry/15890, http://e-maxx.ru/algo/segment_tree (Russian only). If you're not &mdash; don't go there yet. I advise to read them after this article for the sake of examples, and to compare implementations and choose the one you like more (will be kinda obvious). Segment tree with single element modifications ================== Let's start with a brief explanation of segment trees. They are used when we have an array, perform some changes and queries on continuous segments. In the first example we'll consider 2 operations: 1. modify one element in the array; 2. find the sum of elements on some segment. [cut] . ### Perfect binary tree I like to visualize a segment tree in the following way: [image link](http://i.imgur.com/GGBmcEP....
operations we perform, and this is why we get correct results. I won't bother withformal proof here

Full text and comments »

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

16.
By adamant, history, 4 years ago, In English
Arrow product: How to enumerate directed graphs Hi everyone! In this blog, I would like to present a somewhat novel concept in competitive programming, which is, while being relatively simple, allows us to enumerate directed graphs with specific type of strongly connected components. This allows us to easily and uniformly compute generating functions e.g. for acyclic digraphs or strongly connected digraphs. The formalism introduced here is also very intuitive at that. I initially wanted to make a problem based on the content of this blog to appear in today's round, but after some discussions we decided to exclude it, as the contest already had a sufficient amount of difficult problems. You may try the original problem **[problem:441297A]** via the [invitation link](https://codeforces.me/contestInvitation/4d42a205a747b194397bbabd35ab2e81f9793447). #### Prerequisites You are expected to be familiar with exponential generating functions, and the [exponential formula](https://en.wikipedia.org/wiki/Exponential_formula) for c...
acyclic digraphs, and $L(\cdot)$ is a function defined on formal power series, which divides the $k$-th

Full text and comments »

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

17.
By adamant, history, 5 years ago, In English
Fast polynomial composition Hi everyone! Today I want to describe an efficient solution of the following problem: <hr> **[Composition of Formal Power Series](https://judge.yosupo.jp/problem/composition_of_formal_power_series)**. Given $A(x)$ and $B(x)$ of degree $n-1$ such that $B(0) = 0$, compute $A(B(x)) \pmod{x^n}$. <hr> The condition $B(0)=0$ doesn't decrease the generality of the problem, as $A(B(x)) = P(Q(x))$, where $P(x) = A(x+B(0))$ and $Q(x) = B(x) - B(0)$. Hence you could replace $A(x)$ and $B(x)$ with $P(x)$ and $Q(x)$ when the condition is not satisfied. Solutions that I'm going to describe were published in Joris van der Hoeven's [article](https://www.sciencedirect.com/science/article/pii/S0747717102905626) about operations on formal power series. The article also describes a lot of other common algorithms on polynomials. It is worth noting that Joris van der Hoeven and David Harvey are the inventors of the breakthrough $O(n \log n)$ [integer multiplication algorithm](https://hal.archi...
> **[Composition of Formal Power Series](https://judge.yosupo.jp/problem

Full text and comments »

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

18.
By maomao90, 3 years ago, In English
Editorial for Hello 2024 ### [problem:1919a] Author: [user:maomao90,2024-01-02] <spoiler summary="Hint 1"> When does the game end? </spoiler> <spoiler summary="Solution"> Depending on whether the player chooses to exchange wallets with their opponent on step $1$, $1$ coins will be removed from either the opponent's wallet or the player's wallet. This means that if either of the players still has remaining coins, the game will not end as at least one of the choices will still be valid. The only way that the game ends is when both players have $0$ coins. Since each operation decreases the total amount of coins by exactly $1$, the only way for Alice to win the game is if $a + b$ is odd. </spoiler> <spoiler summary="Code"> ~~~~~ #include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int a, b; cin >> a >> b; if ((a + b) % 2 == 0) { cout << "Bob\n"; } else { cout << "Alice\n"; } } ...
formal proof is given below. Let us define an alternative penalty function $p2(l, r) = |a_l + a_{l+1

Full text and comments »

Tutorial of Hello 2024
  • Vote: I like it
  • +760
  • Vote: I do not like it

19.
By aliasadiiii, 3 years ago, In English
Internship Positions at ISTA Dear Codeforces Community, The Chatterjee group at Institute of Science and Technology Austria (ISTA) is hiring scientific interns for summer 2024. The group’s research focuses on (stochastic) game theory, formal methods, and program verification. The target group is mainly the 3rd and 4th year undergraduate students with strong mathematical and algorithmic background. Having prior research experience is a plus. Internship positions at ISTA are fully-funded and the desired time frame is from July to September 2024 (flexible). Unfortunately, a remote internship is not possible at the moment. In case you are interested, send your CV and transcript to [email protected] by December 31st.
interns for summer 2024. The group’s research focuses on (stochastic) game theory,formal methods, and, ) game theory, formal methods, and program verification. The target group is mainly the 3rd and

Full text and comments »

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

20.
By adamant, history, 4 years ago, In English
Combinatorial species: An intuition behind generating functions Hi everyone! The usage of generating functions is quite common in competitive programming these days. But it seems to happen so, that they're mostly presented as a way to simplify formal manipulation with polynomial coefficients, rather than something meaningful. But there actually is a meaning to all of this, and today I'm going to shed a light on it. Alongside the blog post we'll uncover the combinatorial meaning of - The addition $F(x)+G(x)$, - The multiplication $F(x)G(x)$, - The exponent $\exp F(x)$, - The logarithm $\log F(x)$, - The sum of the infinite geometric progression $\frac{1}{1-F(x)}=1+F(x)+F^2(x)+\dots$, - The general composition $F(G(x))$ for the generating functions $F(x)$ and $G(x)$ and the underlying structures they represent. ### Prerequisites - Basic notion of set theory (cardinality of sets, mappings, bijections, cartesian product, disjoint union, etc); - Polynomials and formal power series (representation, convolution formula, power seri...
days. But it seems to happen so, that they're mostly presented as a way to simplifyformal

Full text and comments »

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

21.
By sahaun, history, 3 years ago, In English
Ellipse matching algorithm [HELP] This is not a problem from any online judge, but for a project I am working on. There is an ellipse and a list of points. The task is to score the list with a number between $0$ and $1$. A score of $1$ means that the list of points forms a perfect ellipse. A list forms a perfect ellipse when: 1. All the points in the list lie on the circumference of the ellipse. 2. The points are evenly spaced (distributed evenly) across the circumference. <spoiler summary="Formal-ish statement"> You are given the center $(C_x, C_y)$ and the radii $(R_x, R_y)$ of an ellipse. You are also given a list $L$ of points, $(x_i, y_i)$ where $1\leq i\leq |L|$. You need to output the score of the list $L$ as described above. </spoiler> The expected time complexity is less than $O(N^3)$, not strictly necessary. $N$ being the number of points in the list. If you want some inspiration, I have attempted the same problem but checked matching with circles and polygons. I am explaining how I did it...
spaced (distributed evenly) across the circumference.

Full text and comments »

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

22.
By LorentzianExpanders, history, 23 months ago, In English
Convolution, In the Perspective of 3-Dimensional Tensors Hello everyone! Convolution is perhaps the first class of algorithms that one encounters in competitive programming requiring algebraic knowledge. There are many types of convolutions that we are interested in, including: - **Sequential convolution** (i.e., polynomial multiplication), - **XOR convolution**, - **AND/OR convolution**, - **GCD/LCM convolution**, - **Subset convolution**, and others. One of the most well-known ways to understand fast algorithms for these convolutions is through their associated algebraic structures. These algebraic structures can often be decomposed using the Chinese Remainder Theorem (CRT) into simpler components, i.e., direct products. For instance, in the case of XOR convolution, the algebraic structure arises from the computation rules of the group algebra: $$ R[\mathbb Z_2^n]\colon \left(\sum_{g\in \mathbb Z_2^n} a_g g\right) \left(\sum_{g\in \mathbb Z_2^n} b_g g\right) = \left(\sum_{g,h\in \mathbb Z_2^n} a_g b_h (g+h) \right), $$...
$, the time complexity is $O(n \cdot a^n)$; if $r > a$, the complexity is $O(r^n)$. Thismethod is

Full text and comments »

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

23.
By adamant, history, 5 years ago, In English
On linear recurrences and the math behind them Hi everyone! There are already dozens of blogs on linear recurrences, why not make another one? In this article, my main goal is to highlight the possible approaches to solving linear recurrence relations, their applications and implications. I will try to derive the results with different approaches independently from each other, but will also highlight similarities between them after they're derived. ### Definitions **Def. 1**. An order $d$ **homogeneous linear recurrence with constant coefficients** (or _linear recurrence_) is an equation of the form $$ F_n = \sum\limits_{k=1}^d a_k F_{n-k}. $$ **Def. 2**. In the equation above, the coefficients $a_1, \dots, a_d \in R$ are called the **recurrence parameters**, **Def. 3**. and a sequence $F_0, F_1, \dots \in R$ is called an order $d$ **linear recurrence sequence**. <hr> The most common task with linear recurrences is, given initial coefficients $F_0, F_1, \dots, F_{d-1}$, to find the value of $F_n$. <hr> **Example...
same result as in the matrix approach. #### Graeffe's method _This approach was described by

Full text and comments »

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

24.
By rulerofcakes, history, 21 month(s) ago, In English
My honest journey to Master in 4 years Hi all, this is my first blog on codeforces. I've just reached Master(+2100) after spending about 4 years on codeforces, and I'd like to talk about what I like and regret about my past decisions regarding practicing for this milestone. I know plenty of GM+s have written such blogs, but I think many of you(like my past self) may find these unrelatable simply because of how good they were from the beginning / how much time they have spent / etc, so I decided to write one of my own humble version. Hopefully some of you may find this helpful for your own journey. I honestly think it's possible to reach Master level proficiency in around 2 years, even if you're starting from scratch, assuming you practice hard enough with the right materials. This is based on my own experience. I say proficiency and not reaching the rating itself because I think having high codeforces rating may become even more meaningless in the near future with LLMs. ### The Beginning Like many of you all, I'm j...
proper formal education regarding this subject, so I could say I studied mostly on my own for the past

Full text and comments »

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

25.
By Fefer_Ivan, 13 years ago, translation, In English
New feature of Polygon: tests for checkers and validators Good afternoon, Codeforces! Today I'll tell you about a new feature of [Polygon](http://codecenter.sgu.ru/polygon/) system, which is used to prepare all Codeforces rounds. Of course the system is open to any user – many contests for other competitions and training camps are prepared there. Two key elements of a problem, besides the author's solution, tests and statements, are two programs: the validator and the checker. The validator is the program that reads the test and reports whether it corresponds to the condition of a problem or not. Validators must be absolutely formal – a validator validates a test if and only if it meets the conditions of the problem and can be safely added to the test set. You can easily write validators using the <a href="http://code.google.com/p/testlib">testlib.h</a> library. Sometimes authors neglect validators (which never happens during the Codeforces contests) and it threatens the validity of tests. Since the Codeforces contests contain hacks,...
whether it corresponds to the condition of a problem or not. Validators must be absolutelyformal – a

Full text and comments »

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

26.
By aniervs, 8 months ago, In English
[Tutorial] Derandomization via Conditional Expectations Hello everyone! In this blogpost, I want to talk about the probabilistic method in mathematics, how it can be used to obtain good randomized approximation algorithms for hard problems, and how we can use some **derandomization** techniques to turn these into deterministic algorithms that maintain the exact same guarantees. Thanks to [user:peltorator,2026-04-11] for proofreading this article and giving very useful feedback. <spoiler summary="Prerequisites"> To get the most out of this post, you should be familiar with a few foundational concepts from discrete probability: * **Discrete Probability Spaces:** A probability space consists of a sample space $\Omega$ (the set of all possible outcomes) and a probability measure $\mathbb{P}$. For every outcome $\omega \in \Omega$, the probability satisfies $\mathbb{P}(\omega) \ge 0$, and the sum over all outcomes is exactly $\sum_{\omega \in \Omega} \mathbb{P}(\omega) = 1$. * **Events:** An event $A$ is a subset of the sample spac...
Hello everyone! In this blogpost, I want to talk about the probabilistic method in mathematics

Full text and comments »

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

27.
By zscoder, history, 7 years ago, In English
[Tutorial] Generating Functions in Competitive Programming (Part 2) Welcome to Part 2 of my tutorial on generating functions. The [first part](https://codeforces.me/blog/entry/77468) focused on introducing generating functions to those without any background in generating functions. In this post, I will demonstrate a few applications of generating functions in CP problems. Let us start with some relatively straightforward examples. Note: Unless stated otherwise, all computations are done modulo a convenient prime (usually $998244353$). Also, $[n]$ denotes the set $\\{1,2,...,n\\}$. ### Blatant Applications in Counting Problems **Problem.** [AGC 005 Problem F](https://atcoder.jp/contests/agc005/tasks/agc005_f) You have a tree $T$ with $n$ vertices. For a subset $S$ of vertices, let $f(S)$ denote the minimum number of vertices in a subtree of $T$ which contains all vertices in $S$. For all $1 \le k \le n$, find the sum of $f(S)$ over all subsets $S$ with $|S| = k$. Constraints: $n \le 2 \cdot 10^{5}$. <spoiler summary="Solution"> First, ...
method [here](https://codeforces.me/blog/entry/77284?#comment-620981)). Let's look at a different

Full text and comments »

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

28.
By greateric, history, 6 months ago, In English
Useless Math Information #4.5: Designing the Perfect Rating System part 2 part 2 to farm contribution ahahahahahahaha Mathematical definition of Elo ------------------ Elo is intended to measure skill. Formally, skill is how likely you are to win a game (we're still focusing on two-player for now). If a player with a high rating plays against a player with a low rating, we would expect the higher rated player to win more, on average. Now let's define what rating is. If player A has rating $a$ and player B has rating $b$, then player A should have a $\sigma(\frac{a-b}{\beta})$, where $\beta = \frac{400}{\ln 10} = 173.7178$, and $\sigma()$ is the sigmoid function $\sigma(z) = \frac{1}{1+e^{-z}}$. This formula looks scary, but it's just a formal way of writing the one you might be familiar with. This formula expands/simplifies to: $$\frac{1}{1 + e^{-\frac{a-b}{400 / \ln 10}}}$$ $$= \frac{1}{1 + 10^{\frac{b-a}{400}}}.$$ You're probably more familiar with the last equation above. If you are 400 points weaker, you'd have a 1 to 10 ($\frac{1}{11...
function $\sigma(z) = \frac{1}{1+e^{-z}}$. This formula looks scary, but it's just aformal way of

Full text and comments »

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

29.
By Pancake, 13 years ago, In English
a question about the DivideAndConquer solution for the closest pair problem I have recently learnt the $O(N log N)$ solution which solves the closest pair problem based on a divide-and-conquer approach. However , I still have a question about it . I assume all N points are unique. In the case where the closest pair in the current sub-problem consists of one point to the left of the middle line , and another to the right of the middle line , we have to : - list the points that satisfy $ abs(x - x_mid) < D $ : D is the shortest distance so far. - sort these points with respect to their y-coordinates (in non-decreasing order) - Loop on those points in order , for each point there is a constant number of points that exist within the $ 2D * D $ rectangle and any point outside of this rectangle can't improve the answer. I know that within a $ 2D * D $ rectangles there can exist at most $ 6 $ points such that any pair of them is at least $ D $ units of distance apart. Hence , in the previous method , I think we should examine at most 5 neighbor points with...
distance apart. Hence , in the previous method , I think we should examine at most 5 neighbor points, of them is at least $ D $ units of distance apart. Hence , in the previous method , I think we

Full text and comments »

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

30.
By Frankenstein123, history, 7 years ago, In English
A simple Math Problem Let's suppose I need to calculate $a^{b^{c}}$ modulo $10^9 + 7$, with the constraints $1 \leq a, b, c \leq 10^{18}$. I can calculate $ans = b^c$ in $\mathcal{O}(log(c))$, with modulo $10^9 + 6$, (probably everyone knows how) and then calculate $a^{ans}$ with modulo $10^9 + 7$. But how does first taking $10^9 + 6$ and then $10^9 + 7$ work? Can anyone present a formal proof for this? Also are there any other methods to do this?
first taking $10^9 + 6$ and then $10^9 + 7$ work? Can anyone present a formal proof for this? Also are, But how does first taking $10^9 + 6$ and then $10^9 + 7$ work? Can anyone present aformal proof

Full text and comments »

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

31.
By MikeMirzayanov, 12 years ago, translation, In English
10 Reasons to Prepare Problems in Polygon <img src="http://assets.codeforces.com/images/poly21.jpg" style="float:right;margin:0 0.5em 1em 1em;"/> Hello Codeforces. Just a reminder about something most of you know. Polygon is a service to prepares programming problems and contests. It is usually used to prepare problems for olympiads/programming contests but it is also often used to prepare educational content. It is located at https://polygon.codeforces.com/ and is open to everybody. I have recently found out that it's been more than five years since the creation of Polygon. It's high time to summarize the experience we've accumulated. I first publicly spoke about Polygon in a narrow circle of Russian teams' coaches on ACM-ICPC World Finals in 2009. I cannot say that everybody was enthusiastic about the innovation. Some people were openly skeptical about such system's viability and relevance. After 5 years on the ACM-ICPC finals in Ekaterinburg Oleg Hhristenko ([user:snarknews,2014-11-03]) said that in his o...
. SVN) everything was structured by some half-formal unspoken naming rules. I am going to give you

Full text and comments »

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

32.
By Spheniscine, history, 7 years ago, In English
Tutorial for Advent of Code 2019 day 22 part 2 [Advent of Code](https://adventofcode.com/) is a website that releases programming puzzles every December from the 1st to the 25th. The puzzles have two parts, and the second part isn't revealed until you solve the first part. This year, there have been many questions regarding part 2 of [day 22](https://adventofcode.com/2019/day/22), as it involves modular arithmetic in a way that hasn't been seen in previous puzzles there. I have been asked for a tutorial for it on Reddit, but I'm posting it here due to better support for mathematical notation. <spoiler summary="Part 2 summary"> You are basically asked to do the same thing as in part 1, but with $119315717514047$ cards, and repeating the steps in your input $101741582076661$ times. Also you're asked for the card in *position* $2020$. </spoiler> First off, if you are unfamiliar with modular arithmetic, I encourage you to read my other blog post, [Modular Arithmetic for Beginners](https://codeforces.me/blog/entry/72527). Th...
$F$ into itself naively. There are two approaches to solving this problem: ** Method 1

Full text and comments »

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

33.
By adamant, history, 5 years ago, In English
Associativity and general identity testing Hi everyone! Five days have passed since my [previous post](https://codeforces.me/blog/entry/91610) which was generally well received, so I'll continue doing posts like this for time being. Abstract algebra is among my favorite subjects. One particular thing I find impressive is the associativity of binary operations. One of [harder problems](https://codeforces.me/gym/102129/problem/B) from my contests revolves around this property as you need to construct an operation with a given number of non-associative triples. This time I want to talk about how one can check this property for both groups and arbitrary magmas. First part of my post is about Light's associativity test and how it can be used to deterministically check whether an operation defines a group in $O(n^2 \log n)$. Second part of the post is about Rajagopalan and Schulman probabilistic identity testing which allows to test associativity in $O(n^2 \log n \log \delta^{-1})$ where $\delta$ is error tolerance. Finall...
. Finally, the third part of my post is dedicated to the proof of Rajagopalan–Schulmanmethod and bears

Full text and comments »

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

34.
By arvindf232, history, 12 months ago, In English
Quadratic binary energy function minimisations by Flow ## Motivations I tried to read [https://codeforces.me/blog/entry/148438](https://codeforces.me/blog/entry/148438) and failed. It contains a lot of extra explanations and intuition that I either already knew or could reconstruct immediately. That is not inherently bad, but for me personally it made the key ideas harder to see. (I think most contestants would not struggle with visualising binary logical relations...) As I asked around (and with help from LLMs), it became clear that the underlying structure is the Kolmogorov–Zabih characterization of which quadratic binary energies are solvable via a single max-flow. This blog is essentially a reweighting of that material: shorter, more “algebraic”, and aimed at people who are already comfortable with max-flow / min-cut and with abstracting away implementation details. This blog is also just essentially an extremely long comment that is too long to fit in comment section. ## Declarations While writing this, I did **not**...
-rated programmers or anyone already familiar with the general method. In particular, none of the

Full text and comments »

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

35.
By aryanc403, 5 years ago, In English
Power series on sets? (Added one example) Update 2 &mdash; Thanks ~adamant,2021-06-25 for his [Subset convolution interpretation](https://codeforces.me/blog/entry/92153) blog. It does simplifies a lot of things. Update 1 - Let's consider this problem - We have a function `subset_convolution(A,B)` it gives us [Subset Sum Convolution](https://codeforces.me/blog/entry/72488) of two sets $A, B$. Let's say we array $A$ with $A[0]=1$ and we want to find `A^K` defined as $A$ convoluted with itself $K$ times. `A^2 = subset_convolution(A,A)` `A^3 = subset_convolution(A^2,A)` ... `A^k = subset_convolution(A^{k-1},A)` The best I can think right now is using something on lines of fast exponential to achieve $O(log K*N^2*2^N)$ time where $2^N$ is the size of A. Also, there exist some solutions $O(N^3*2^N)$ using the fact that the majority of the multiplications will be with A[0] and permutations & combinations. But it can be done in $O(N^2*2^N)$ using tricks well known at some pla...
seniors doing MATH major — where can I read formal definitions of "set power series" since

Full text and comments »

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

36.
By AlexLuchianov, 5 years ago, In English
[Tutorial, Flows] Project Selection Problem One advanced topic in competitive programming are flows. The main challenge in flow problems lays often not in the algorithm itself, but in modelling the graph. To solve the project selection problem, we will model it as an instance of the minimum cut problem: _"You are given a directed graph with weighted edges. One node is designated as a source and another as a sink. Erase a set of edges of minimal total weight such that the source and the sink become disconnected. The source and the sink are considered to be disconnected if there no longer exists a directed path between them"_ The minimum cut problem is equivalent to the [maximum flow problem](https://cp-algorithms.com/graph/edmonds_karp.html). Note that we can consider the maximum flow problem as a black-box that solves our instances of minimum cut. Thus, once we manage to reduce our problems to minimum cut, we can consider them solved. ###The project selection problem This problems is most often stated as: _"You a...
)$, $(l_i + 1, x_i)$ $\dots$ $(r_i, x_i)$. In less formal terms, this means that we can regain our

Full text and comments »

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

37.
By adamant, history, 4 years ago, In English
Unlabeling combinatorial species (cycle index series) Hi everyone! In my [previous blog](https://codeforces.me/blog/entry/103979), I wrote about how generating functions can be used to enumerated labeled species. In this blog, I want to continue the topic by writing about how one can account for different kinds of symmetries when counting different combinatorial structures. Ultimately, we will end up deriving and hopefully understanding the analogue of [Pólya enumeration theorem](https://en.wikipedia.org/wiki/Pólya_enumeration_theorem) in species. Difficulty: ★★★★☆ Prerequisites: - Familiarity with combinatorial species (see my [prev. blog](https://codeforces.me/blog/entry/103979)), OR - Very good intuition with enumerative combinatorics, genfuncs and recap below. I will try to use plain language rather than formulas as much as possible, as it seems to be the preferred format for readers. ## Recap Below is a very brief recap of the most important things from the previous article. I tried to keep it as informal as p...
above, we may define a multivariate formal power series $$ Z_F(t_1, t_2, t_3, \dots) = \sum

Full text and comments »

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

38.
By errorgorn, 5 years ago, In English
Catalan Numbers and Generating Uniform Balanced Bracket Sequences Hi everyone! Today [user:nor,2022-05-27] sir and I would like to talk about generating uniform bracket sequences. Over the past few years when preparing test cases, I have had to generate a uniform bracket sequence a few times. Unfortunately I could not figure out how, so I would like to write a blog about this now. Hopefully this blog would be useful to future problem setters :) Scroll down to the end of the blog to copy our generators. First, let's define some things. A bracket sequence is a string with $n$ $\texttt{(}$ s and $n$ $\texttt{)}$ s. A **balanced** brackets sequence is a bracket sequence with the additional constraint that it becomes a valid arithmetic expression when we add some $\texttt{1}$ s and $\texttt{+}$ s. Let $p$ be the prefix sum array of a bracket sequence (we assign $1$ to $\texttt{(}$ and $-1$ to $\texttt{)}$ and take the prefix sum). For example, if our bracket sequence is $\texttt{())()((())}$, then $p=[1,0,-1,0,-1,0,1,2,1,0]$. An alternate way to thi...
=1$ for $n=0$. After some manipulation with formal power series $[1,2 \text{ example } 2.3.3]$, you

Full text and comments »

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

39.
By Misuki, 4 years ago, In English
[tutorial] Bostan-Mori, an elegant algorithm to compute k-th term of linear recurrence in O(dlgdlgk) Recently I am learning generating function and some application about it, and found out this algorithm is very elegant but seems to only be well-known in Japan, also I have nothing to do during lunar new year, so I decide to write a blog to share this algorithm with CF community! edit: Actually this algorithm have been discussed before, you can also see the other explanation in the link of this [comment](https://codeforces.me/blog/entry/111862?#comment-996663). If there have some mistake or question, please comment below to let me know :) ## Prerequistes - FFT/NTT - basic understanding of generating function - basic understanding of linear recurrence - knowing how to compute [inv of sparse formal power series](https://judge.yosupo.jp/problem/inv_of_formal_power_series_sparse) in $O(nk)$ ## the connection between $\frac{P(x)}{Q(x)}$ and linear recurrence In this section, I will show the relation between $\frac{P(x)}{Q(x)}$ and linear recurrence, by proving the foll...
[inv of sparse formal power series](https://judge.yosupo.jp/problem

Full text and comments »

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

40.
By adamant, history, 21 month(s) ago, In English
Geometric meaning of LP duality Hi everyone! Recently, linear programming (LP) duality was brought up in a Discord server, and it made me think again about how, whenever it is introduced, it's most often _very_ poorly motivated. Some examples that I've seen include: - Directly deriving it from general Lagrange duality (which I did myself in the past, and I like this method, but it's not best for LP); - Giving some vague economics-based explanation in terms of goods quantities and costs; - Making a very handwavy argument about approximating the target function with constraints; - Simply proving it symbolically without giving a good explanation to what and why we're doing. After some thinking, I would like to share a geometric interpretation to LP duality, that I think should very intuitively and directly explain what's the meaning of our actions, and why does it actually deliver the same result (and not just an upper bound) as the primal problem. **Tl;dr**. Both primal and dual LP problems find the **su...
(which I did myself in the past, and I like this method, but it's not best for LP); - Giving some vague

Full text and comments »

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

41.
By adamant, history, 4 years ago, In English
Partitions and pentagonal number theorem Hi everyone! In today's blog I'd like to write about the theorem that allows to efficiently solve the following problems: - What is the number of partitions of a non-negative number $n$ for $n \leq 10^5$? - What is the number of partitions of a non-negative number $n$ for $n \leq 10^5$, so that no summand repeats $d$ or more times? - What is the number of partitions of a non-negative number $n$ for $n \leq 10^5$, so that no summand is divisible by $d$? - **[HackerEarth &mdash; Perfect Permutations](https://www.hackerearth.com/de/problem/algorithm/perfect-permutations-september-clash/)**: What is the number of permutations of length $n$ with $k$ inversions for $k \leq n \leq 10^5$? - **[problem:102354E]**: Let $\phi = \frac{9}{10} \cdot \frac{99}{100} \cdot \frac{999}{1000} \cdot \dots$, what is the $k$-th digit of $\phi$ for $k \leq 10^{18}$? - **[SNSS-2018 Round 5 &mdash; Investment Portfolio](https://contest.yandex.ru/contest/8703/problems/C/)**: You have $2n$ dollars and ...
}}\right)} $$ ## Prerequisites - Familiarity with generating functions, formal power series

Full text and comments »

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

42.
By galen_colin, 3 years ago, In English
THE OPTIMAL PRACTICE STRATEGY (**NOT CLICKBAIT**) Spoiler: it's clickbait. Sorry. Titles like those are fun. ...but, it's the same style of clickbait as my [roadmap](https://www.youtube.com/watch?v=bSdp2WeyuJY) [spoiler 2: if you haven't seen that, it markets itself as a standard roadmap (y'know, soulless and devoid of purpose), but then a few minutes in, says "ok but roadmaps are stupid and here's the advice that you really need" and completely changes the direction of the video]. That's my style of clickbait, and that's the vibe this blog goes for. [cut] <br><br> So... hear me out, please. The start ------------------ First, a couple meta-notes. I will likely exaggerate my tone a bit here for dramatic effect. Don't take it personally, please. Also, **this applies to almost all ratings**. At the very least, I recommend you process the main point of this blog and see whether or not you already do something similar (for most people... probably not?) The problem ------------------ I'm sure if you've looked at the...
anecdotal than formal in illustrating this, but it's still a very important idea I've rarely seen

Full text and comments »

Tags hi
  • Vote: I like it
  • +207
  • Vote: I do not like it

43.
By mrinmoy66sadhukhan, 14 months ago, In English
I have idea to stop AI submissions Not full proof but i think this will help.. #### Method 1: More interactive problems. I think interactive problems are more difficult for AI to solve. ![ ](/predownloaded/48/b7/48b7b3e0db509c5821b2ab5df765d52feb3295ec.jpg) #### Method 2: Only one submission allowed per question.. Very harsh but this will stop cheaters from giving repeated prompts.. This will also make contest more tough.. less correct submissions. #### Method 3: Well, not really a method.. but I think if problems are described in more verbose manner.. in more informal way.. rather than formal way.. and we are forced to interpret input/output on our own.. then question will be more difficult for AI.. _Thank you for reading._
#### Method 3: Well, not really a method.. but I think if problems are described in more verbose, Not full proof but i think this will help.. #### Method 1: More interactive problems. I think

Full text and comments »

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

44.
By hirayuu_cf, 2 years ago, In English
Introduce the best problem I made Hello, CodeForces! I am [user:hirayuu_cf,2024-06-14]. I often create problems on [yukicoder](https://yukicoder.me/). By the way, GPT-4o is a hot topic right now. It has a significant impact on competitive programming, such as making it possible to solve typical problems by just copy-pasting, but that's another story. I am a Japanese speaker and cannot speak English very well, but thanks to ChatGPT, I am able to express my thoughts in English like this. Most of this blog, including this text, has been translated by ChatGPT, sorry for any mistakes. Let's get back to the topic. In the past, I co-hosted the [yukicoder contest 424](https://yukicoder.me/contests/486) with [user:Magentor,2024-06-14]. (At the time of writing, I am a Candidate Master, and [user:Magentor,2024-06-14] is a Newbie, but both [Magentor](https://atcoder.jp/users/Magentor) and [I](https://atcoder.jp/users/hirayuu_At) have good results on AtCoder.) Since this is a good opportunity, I would like to share some...
greedy method, it becomes $((1000, 1), (999999, 1000), (998998, 999), \dots, (3003, 4), (2002, 3

Full text and comments »

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

45.
By Elegia, history, 23 months ago, In English
More on D-Finite Functions II: Problems After finishing this part, I found out some of them are not that related to D-Finite functions (especially for the last section), but in these problems, we still need some insight to deal with differential operators. So I'll keep them here. ## Sums involving powers Let's consider the following problem of summation $$ \sum_{0\leq n \leq M} f(n) \cdot n^k, $$ where $M$ can be finite or infinite. We want to separate a large class of $f$ such that such summation can be solved in $O(k)$. You may already know some examples: - For the constant function $f(n) = 1$, known as [662F](https://codeforces.me/problemset/problem/622/F), can be solved in linear time through Lagrange interpolation on consecutive sampling points. - For the geometric series $f(n) = r^n$, you can find the [finite case](https://judge.yosupo.jp/problem/sum_of_exponential_times_polynomial) and [infinite case](https://judge.yosupo.jp/problem/sum_of_exponential_times_polynomial_limit) (assume $|r| < 1$) in Libra...
$. Clearly, these things can all be done in $O(k\log k)$ by elementary operations onformal power

Full text and comments »

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

46.
By JaySharma1048576, 5 years ago, In English
Codeforces Round #730 (Div. 2) Editorial #### [A: Exciting Bets](https://codeforces.me/contest/1543/problem/A) <spoiler summary="Hint 1"> $GCD(a,b)=GCD(a-b,b)$ if $a>b$ </spoiler> <spoiler summary="Hint 2"> $a-b$ does not change by applying any operation. However, $b$ can be changed arbitrarily. </spoiler> <spoiler summary="Tutorial"> If $a=b$, the fans can get an infinite amount of excitement, and we can achieve this by applying the first operation infinite times. Otherwise, the maximum excitement the fans can get is $g=\lvert a-b\rvert$ and the minimum number of moves required to achieve it is $min(a\bmod g,g-a\bmod g)$. <spoiler summary="Proof"> Without loss of generality, assume $a>b$ otherwise we can swap $a$ and $b$. We know that $GCD(a,b) = GCD(a-b,b)$. Notice that no matter how many times we apply any operation, the value of $a-b$ does not change. We can arbitrarily change the value of $b$ to a multiple of $a-b$ by applying the operations. In this way, we can achieve a $GCD$ equal to $a-b$. Now, ...
describe two of them. Let $q_i$ denote the $i$-th query. Then

Full text and comments »

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

47.
By Qwerty1232, 19 months ago, In English
Making NTT convolution 10x faster with avx2 > Text is also available on [github pages](https://piskareviv.github.io/blog_aux_ntt_1/) (formatting may look a bit cleaner there) > Thanks [user:alexxela12345,2025-05-05] for reviewing this blog Hello everyone! I want to share some of my thoughts and experiments on vectorizing NTT. I prefer NTT to real-valued FFT because of the imprecision of the latter. I use `avx2` because it is the most advanced vector extension supported by the majority of modern online judges (including Codeforces), as of 2024. And I have no idea how many bugs (already found two) and how much UB my code contains, at least it passes some kind of tests. ### Benchmark info All the benchmarks are performed on my `Ubuntu 22` `Intel i5-1135g7` laptop. I execute `cpupower frequency-set -d 3.0ghz -u 3.0ghz` before benchmarks to (attempt to) fix CPU frequency for better accuracy. Code is available at [github](https://github.com/piskareviv/blog_aux_ntt_1). You can try running all the benchmarks o...
as formal variables, permutation doesn't change their values, only their order in the array. We

Full text and comments »

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

48.
By Spheniscine, history, 6 years ago, In English
Unofficial ACL Beginner Contest Editorial ### [A &ndash; Repeat ACL](https://atcoder.jp/contests/abl/tasks/abl_a) <spoiler> Easy programming-language-knowledge check typical of the first task of AtCoder beginner contests. The following is a passing Kotlin submission: ``` fun main() { val k = readLine()!!.toInt() val ans = "ACL".repeat(k) println(ans) } ``` </spoiler> ### [B &ndash; Integer Preference](https://atcoder.jp/contests/abl/tasks/abl_b) <spoiler> Assume there is an integer in both ranges and call it $x$. Note that both $x \ge \max(A, C)$ and $x \le \min(B, D)$ must therefore be true. Thus $x$ exists if and only if $\max(A, C) \le \min(B, D)$ is true. This is the standard formula for finding the overlap of two ranges. </spoiler> ### [C &ndash; Connect Cities](https://atcoder.jp/contests/abl/tasks/abl_c) <spoiler> Note that the initial network of cities can be divided into one or more *components*, where any city of a component can reach any other city in that component follow...
. [One can visualize this by treating $x^k$ as a formal symbol meaning "ways to make $k$ bad pairs

Full text and comments »

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

49.
By mohammedehab2002, history, 9 years ago, In English
Codeforces round #473 editorial #### [problem:959A] It's easy to see that if $n=0$, the next player loses. If $n$ is even, Mahmoud will choose $a=n$ and win. Otherwise, Mahmoud will have to choose $a<n$. $n$ is odd and $a$ is even, so $n-a$ is odd. Ehab will then subtract it all and win. Therefore, if $n$ is even Mahmoud wins. Otherwise, Ehab wins. $n=1$ doesn't follow our proof, yet Ehab still wins at it because Mahmoud won't be even able to choose $a$. Code link (me) : https://pastebin.com/X3D08tg9 Code link ([user:mahmoudbadawy,2018-04-02]) : https://pastebin.com/4u3RHE7n Time complexity : $O(1)$. **Bonus task :** If there were multiple integers, and each player can choose which integer to subtract from, who will win? <spoiler summary="Solution"> Ehab can follow a good greedy strategy : make some number odd and leave it till the end of the game. Mahmoud won't be able to make it 0 so Ehab will win. If there's already an odd integer, or there are at least 2 even integers, Ehab can do that. Theref...
$ (node $u$ is connected to node $u$ without that bit). Let's take

Full text and comments »

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

50.
By MikeMirzayanov, 15 years ago, translation, In English
Codeforces Contest Rules This document provides a detailed and formal version of the Codeforces contest rules. If you're simply looking to understand the basics, we recommend starting with the post [Codeforces Contests](/blog/entry/456). Please note that organizers may make minor modifications to the rules for specific rounds; any such changes will be included in the official announcement of the respective round. Unless otherwise stated, the following rules should be considered the default for all contests. By participating in a Codeforces contest and/or submitting any materials, you automatically agree to abide by these [terms and conditions](/terms). ### General information about a round 1. You need to register to participate in a round. The registration opens six hours before the start of the contest and closes 5 minutes before it, unless the information about the round states otherwise. 1. The system of conducting contests has two interface languages available: Russian and English. The cont...
This document provides a detailed and formal version of the Codeforces contest rules. If you're

Full text and comments »

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

51.
By Ceilings, 21 month(s) ago, In English
Editorial for IIT Hyderabad Code Clash 2025 We hope you enjoyed solving the problems, and thank you for participating! We are very sorry about the error in constraints for D. [Problem A &mdash; Denial](https://codeforces.me/gym/590383/problem/A) <spoiler summary="Intuition"> The traveler’s position after any number of moves is constrained on a fixed circle which is the circle that passes through the three points: $P$, position after first move, position after second move. For the traveler to come back to $P$, he will have to head in the same direction as the initial direction and if he is heading in the same direction as the initial direction then, he must be at $P$(else his subsequent positions wont lie on the same circle). Thus, $n\cdot a$ must be a multiple of $360$. The first time this happens is when he turns a total angle of $lcm(a,360)$, i.e, the number of moves is $\frac{lcm(a,360)}{a}$. Thus the total distance is $d \cdot \frac{lcm(a,360)}{a}$. </spoiler> <spoiler summary= "Formal proof"> Let the directi...
is $d \cdot \frac{lcm(a,360)}{a}$. Let the

Full text and comments »

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

52.
By EbTech, history, 7 years ago, In English
Generalizing Segment Trees with Rust This blog post outlines the design of a very general data structure for associative range queries, in the Rust programming language. In the "real world", self-balancing binary search trees can be augmented to handle a variety of range queries. However, for contest problems, statically allocated variants are much easier to code and usually suffice. The contest community has come to know these data structures as _segment trees_. Here, I will generalize most of the segment trees that you can find in the wild into one polymorphic data structure, that can easily be copy-pasted during online competitions. I will call it an _ARQ tree_. ARQ is pronounced "arc", which has a similar meaning to "segment", but also stands for "Associative Range Query". It supports highly customizable range queries, the main requirement being that the aggregation operation must be _associative_. ### Associativity and Semigroups We begin with an array $a_0, a_1, a_2, \ldots, a_{n-1}$. Each $a_i$ belongs to...
formal notation: **Associative Law:** $+: S \times S \rightarrow S$ satisfies $a + (b + c) = (a

Full text and comments »

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

53.
By CristianoPenaldo, history, 4 years ago, In English
Atcoder 279G-At most 2 colors: Generating functions [Second-hand, Newbie Oriented]. **Part1: Introduction** [Atcoder Beginner Contest 279](https://atcoder.jp/contests/abc279) is good for learning [generating functions (GFs)](https://en.wikipedia.org/wiki/Generating_function). GFs could solve two of them (G and Ex). The English version tutorial of [279Ex](https://atcoder.jp/contests/abc279/tasks/abc279_h) has already been posted on the [MathStackExchange](https://math.stackexchange.com/questions/4586327/sum-of-product-of-min-which-is-related-to-the-pentagonal-number-theorem) by a kind person. Unfortunately, the English tutorial on [279G](https://atcoder.jp/contests/abc279/tasks/abc279_g) is not available. Now I would like to make a second-hand tutorial on [279G](https://atcoder.jp/contests/abc279/tasks/abc279_g) based on [PCTprobability's idea](https://atcoder.jp/contests/abc279/editorial/5293). I spend a huge amount of time understanding this idea. For contestants at about my level, it is quite difficult to understand [the idea](https://atcoder.jp/contests/abc27...
/NTT in $O(NlogN)$ time. Here is a useful summation: [Operations on Formal Power Series](https

Full text and comments »

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

54.
By Dominater069, 3 years ago, In English
Codeforces Round #934 (Div1, Div2) Editorial Sorry for the delay in publishing the editorial. If anything is unclear or missing, please let me know in the comments. In all the problems, reading the hints is a must as the solution continues from there. [problem:1944A] Idea: [user:Dominater069,2024-03-17] Preparation: [user:Dominater069,2024-03-17] Editorial: [user:Dominater069,2024-03-17] <spoiler summary="Hint 1"> What is the minimum number of bridges to burn if we want to make exactly $i$ islands visitable from $1$? </spoiler> <spoiler summary="O(n) Solution"> Atleast $i \cdot (n - i)$ bridges need to burnt (the bridges connecting the $i$ reachable islands and the $n - i$ non-reachable islands). A simple $O(n)$ solution is for every $i$ from $1$ to $n$, check if $i \cdot (n - i) \le k$, in which case print $i$ and break. </spoiler> <spoiler summary="Hint 2"> What is the answer when $k \ge n - 1$. </spoiler> <spoiler summary="Hint 3"> When $k < n - 1$, is it possible to make any island non-...
$. Hence the minimum number of bridges to burn always exceeds $n - 1$.

Full text and comments »

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

55.
By dacin21, history, 8 years ago, In English
On the mathematics behind rolling hashes and anti-hash tests This blog assumes the reader is familiar with the basic concept of rolling hashes. There are some math-heavy parts, but one can get most of the ideas without understanding every detail. The main focus of this blog is on how to choose the rolling-hash parameters to avoid getting hacked and on how to hack codes with poorly chosen parameters. # Designing hard-to-hack rolling hashes ## Recap on rolling hashes and collisions Recall that a rolling hash has two parameters $(p, a)$ where $p$ is the modulo and $0 \leq a < p$ the base. (We'll see that $p$ should be a big prime and $a$ larger than the size $\left|\Sigma\right|$ of the alphabet.) The hash value of a string $S = s_0 \dots s_{n-1}$ is given by $$ h(S) := \left(\sum\limits_{i=0}^{n-1} a^{n-1-i} s_i\right) \mod p $$ For now, lets consider the simple problem of: given two strings $S, T$ of equal length, decide whether they're equal by comparing their hash values $h(S), h(T)$. Our algorithm declares $S$ and $T$ t...
= 2 ^ {\sqrt{2 \lg p} + 1}$ in $\Theta\left(n\right)$ time. (A more formal analysis can be found

Full text and comments »

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

56.
By chinesedfan, history, 2 years ago, In English
Understanding Segment Tree by Divide and Conquer > As is well-known, segment tree allows answering range queries over an array efficiently, while still being flexible enough to allow quick modification of the array. -- https://cp-algorithms.com/ **This blog is about how to solve segment tree problems generally**, including not only the classic range sum/minimum/maximum, but also some other complex cases. If are already confident enough of your skills, you can skip reading most of the content and go to practice the last problem directly. ## Basic Example Almost everyone learns segment tree from calculating range sums with single element updates. The formal definition is: > Given an array $A$, for each query range $[L,R]$, returns its sum $\sum_{i=L}^R A[i]$. And also handle assignments of the form $A[i] = x$. The main idea is to divide the whole range $[1,N]$ into 2 parts. Obviously, if we know sums of each part, the whole range sum can be calculated in $O(1)$ by a simple add operation. ``` sum[1,N] = sum[1, N/2] ...
element updates. The formal definition is: > Given an array $A$, for each query range $[L,R

Full text and comments »

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

57.
By eugenechka.boyko.2_0-0, 19 months ago, translation, In English
Codeforces Round 1022 Editorial #### [problem:2108A] Author: [user: eugenechka.boyko.2_0-0,2025-04-30] <spoiler summary="Solution"> Let’s start with $p = [1, 2, 3, …, n]$. For this $p$, $f(p) = 0$. Let’s move $n$ to the beginning one position at a time. It’s easy to see that we increase the answer by $2$ at each step. Now, let’s move $n - 1$ to position $2$, then $n - 2$ to position $3$, and so on, until we reach $p = [n, n - 1, …, 2, 1]$. For this $p$, $f(p) = \lfloor \frac{n^2}{2} \rfloor$. While doing this, we obtained every even value from $0$ to $\lfloor \frac{n^2}{2} \rfloor$, since we were adding $+2$ at each step. Let’s prove that we can’t get any other values. First of all, it’s easy to see that we can’t obtain a value less than $0$ or greater than $\lfloor \frac{n^2}{2} \rfloor$. Second, we can only obtain even values, because each swap changes the answer by an even number. So the answer is $\lfloor \frac{n^2}{4} \rfloor + 1$ Time complexity : $\text{O}(1)$. </s...
this method, no group will have two vertices of the same color), which has complexity $O(n)$. Thus

Full text and comments »

58.
By 2471CoconutMilk, 14 months ago, In English
plz help me in my last blog a guy told me this: ``` The list of topics that you should learn for solving 800 rated problems : Li-Chao Segment Tree Segment Tree Beats RMQ in O(n)/O(1) Any self-balancing tree except treap Link-cut tree Wavelet tree Mergesort tree Binomial heap Fibonacci heap Leftist heap Dominator tree 3-connected components in O(n) k-th shortest path Matching in general graph Weighted matching in general graph Preflow-push MCMF in O(poly(V,E)) Minimum arborescence (directed MST) in O(ElogV) Suffix tree Online convex hull in 2D Convex hull in 3D Halfplane intersection Voronoi diagram / Delaunay triangulation Operation on formal power series (exp, log, sqrt, ...) (I know the general idea of Newton method) How to actually use generating functions to solve problems Lagrange Inversion formula ``` can it be as hard as this to solve 800 rated problems?is he joking? plz help me!!!!!
intersection Voronoi diagram / Delaunay triangulation Operation on formal power series (exp, log, sqrt, triangulation Operation on formal power series (exp, log, sqrt, ...) (I know the general idea of Newton

Full text and comments »

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

59.
By blackscreen1, history, 6 months ago, In English
SEATST 2026 Experience + Day 1 editorial Introduction ------------------ This last weekend, I took part in SEATST (Southeast Asia Team Selection Test) 2026. A few people (namely [user:YSH2020,2026-05-26] and [user:Tyx2019,2026-05-26]) have posted blogs on the contest. About SEATST ------------------ SEATST is a IOI format (2 days, 3 problems in 5 hours on each day) contest made in 2025 that "replaced APIO as a crucial component of IOI selection in Singapore." (this statement is directly quoted from the SEATST website found [here](https://seatst.github.io)). Looking at my APIO scores for these 2 years and my SEATST scores, I believe I am one of the largest beneficiaries for the shift away from APIO towards SEATST. Here are my scores: - APIO 2025: 87/300, 10th in SG - SEATST 2025: 380/600, 3rd in SG - APIO 2026: 13.5/300, 21st in SG (I know my strategy was kinda screwed but whatever) - SEATST 2026: 419/600, 4th in SG My experience this year ------------------ I had _quite_ an interesting experience i...
]$ that we had would not make the result any worse. More formal writing is left as an exercise to the

Full text and comments »

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

60.
By NotSharwan, history, 7 years ago, In English
Dyanamic Programming # Dynamic Programming There were huge number of sources on the internet on this topic but still we (me and my friend) couldn't understand any of it for a very long time until we fiddled with code and tracked the output for every change in the input. So this repository is exactly created for people like us to make the transition from [greedy](https://en.wikipedia.org/wiki/Greedy_algorithm) to dynamic programming easier. This will just be an introduction to dynamic programming, so that one can pick it up from there. I have added additional sources for practice and other online tutorials that I found a little helpful at the end and will continue to do so as I find something new. It is for programmers who are comfortable with brute-force and might not the serve the purpose for absolute beginners. Contributions or suggestions are welcome. ## Definition So what's dynamic programming? Let's first look at a more formal definition. Dynamic programming (also known as dynamic optimiz...
? Let's first look at a more formal definition. Dynamic programming (also known as dynamic

Full text and comments »

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

61.
By Bring, history, 4 years ago, In English
Solution to ARC154F Dice Game -- Generating functions and polynomials [For a better experience please click here.](https://www.cnblogs.com/BrianPeng/p/17103976.html) Link to the question: [Luogu](https://www.luogu.com.cn/problem/AT_arc154_f), [AtCoder](https://atcoder.jp/contests/arc154/tasks/arc154_f) ## Preface The very first generating function and polynomial problem solved in my life! *This blog is a detailed explanation and extension of the [official editorial](https://atcoder.jp/contests/arc154/editorial/5602). I will try my best to explain the mathematical expressions and their deeper meanings so that you may understand if you are also new to generating functions and polynomials* --- ## Our Goal Let $X$ be our random variable, which is the number of rolls after which all $N$-sides have shown up once for the first time. Its probability mass function $p_i=\mathbb P(X=i)$ is just the probability that all $N$-sides have shown up at exactly $i$-th roll. Then, what we are looking for is $\mathbb E(X)=\sum_{i=0}^\infty ip_i=0p_...
sequence $\{a_i\}_{i=0}^\infty,$ there are two formal power series associated with it: * Its

Full text and comments »

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

62.
By Leftist_G, 9 months ago, In English
Codeforces Round 1083 (Div. 2) Editorial Thank you for participating and accompanying Simons! We hope you enjoyed the problems. <spoiler summary="Rate the contest!"> - Horrible contest - Bad contest - Average contest - Good contest - Epic contest </spoiler> <spoiler summary="Rate the difficulty!"> - Impossible contest - Hard contest - Average contest - Simple contest - Trivial contest </spoiler> <spoiler summary="Rating Predictions"> | | A | B | C | D | E | F | G | |-----| ----- | -----| -----| -----| -----| -----| -----| | [user:Leftist_G,2026-02-25] | 800 | 800 | 1400 | 2000 | 2400 | 2600 | 2900 | | [user:cool_milo,2026-02-25] | 800 | 800 | 1400 | 1800 | 2400 | 2700 | 3300 | | [user:StayAlone,2026-02-25] | 800 | 900 | 1500 | 1900 | 2300 | 2200 | 2800 | | [user:liuhangxin,2026-02-25] | 800 | 900 | 1000 | 1300 | | 2500 |...
not written with full formal tightness. We actually want to compute $$ \sum\limits_{i=0}^m

Full text and comments »

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

63.
By Moody_Nabil, history, 5 years ago, In English
A problem collection of ODE and differential technique A problem collection of ODE and differential technique ====================================================== This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them. For those who are interested in well-known problems in China. Thank [user:Elegia,2021-10-21] and [uset:djq_cpp] for developing this technique. Thank [user:Miracle03,2021-10-21] for reviewing this article. [Chain Reaction](https://uoj.ac/problem/50) in UOJ Round 3 By [user:vfleaking,2021-10-21] **Statement** ​ You are given a set A, you need to compute gi=12∑j,k(i−1j)(i−1−jk)gjgk where i−1−j−k∈A. **Solution** ​ Let the EGF of g be x(t) and EGF of A be a(t). Thus x′(t)=12a(t)x2(t)+1. We can solve this equation by D&C and FFT in O(nlog2n). But there is a slower solution in O(nlogn). ​ For a polynomial equation f(x(t))=0, we can use the Newton's method to solve it. If we find a polynomial xn that x≡xn(modtn). We can derive the ...
use the Newton's method to solve it. If we find a polynomial xn that x≡xn(modtn). We can derive the

Full text and comments »

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

64.
By lior5654, 5 years ago, In English
[Tutorial] Solving a 3300 | Codeforces Round #773 (Div. 1) Problem E — Special Positions Hello Codeforces! (Long Post!) Introduction ------------------ As I've recently solved my first ever $\ge$ 3000 rated problem (3300) on Codeforces &mdash; [Codeforces Round #773 (Div. 1) Problem E &mdash; Special Positions](https://codeforces.me/problemset/problem/1641/E) and the solution that I came up with is different than the one presented in the official editorial, I thought that it will be valuable to the community if I share my approach. ![ ](https://i.imgur.com/toIoJG4.jpeg) Note that problem solving is a complicated & creative process. In the editorial, I show clean steps to reach the final solution, but the jump between each step is not always trivial (and sometimes hard!). Reaching this solution involved a large amount of drawings, observations, calculations & mistakes. There's no magic trick (at least to my knowledge :) ). Alright, enough introduction, let's get started! (click "The Editorial" below this line in order to be able to view the editorial) ...
expectation. Note: I'm being extra formal, I suggest you simply take a pen & some paper, and draw to

Full text and comments »

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