# DSAAcademy — The Ultimate Topic List (Full Topic Map)

> **Source / attribution:** [The Ultimate Topic List](https://youkn0wwho.academy/topic-list) by [DSA(Shahjalal Shohag)](https://codeforces.com/profile/YouKn0wWho).
> Structure extracted from the author's official open-source export [ShahjalalShohag/the-ultimate-topic-list](https://github.com/ShahjalalShohag/the-ultimate-topic-list) (MIT License, data exported from the same database as the live site; static mirror: [the-ultimate-topic-list.vercel.app](https://the-ultimate-topic-list.vercel.app)).
> Templates come from [ShahjalalShohag/code-library](https://github.com/ShahjalalShohag/code-library).
>
> This file contains **roadmap structure and official links only** — topic names, IDs, difficulty/importance ratings, prerequisites, resource links, template links, and problem links. No explanations, editorials, or problem statements are reproduced. Use the topic page links for the actual content.

**Generated:** 2026-06-05 · **Data export:** 2025-09-28 · Live site currently reports 576 topics; this export contains 570 (delta: Number Theory +2, Combinatorics +1, Math +1, Miscellaneous +2 on the live site). Re-sync from the live site for the newest additions.

## How to read this map

- **Hierarchy:** Category → Subcategory → Topic. The order is the author's recommended learning order — earlier items are the implied prerequisites of later ones. Explicit `Prerequisites` are listed only where the author defined them.
- **Topic page:** every topic links to `https://youkn0wwho.academy/topic-list/<topic_id>` (resources, starred picks, and the problem list live there).
- **Difficulty:** Very Easy · Easy · Medium · Hard · Very Hard (author's rating).
- **Importance:** ★★★ must-know · ★★☆ good-to-know · ★☆☆ rare/optional.
- **Phase:** the author's learning-path phase number (lower = earlier), where defined.
- **★ on a resource/problem:** starred (recommended) by the author.
- **Problem difficulty tag** `[VE/E/M/H/VH]`: author's per-problem rating where it parses to the 0–4 scale, `[—]` otherwise.

## Contents

1. [Basics](#1-basics) — 19 subcategories, 56 topics
2. [Data Structures (DS)](#2-data-structures-ds) — 18 subcategories, 82 topics
3. [Graph Theory](#3-graph-theory) — 21 subcategories, 103 topics
4. [Number Theory](#4-number-theory) — 9 subcategories, 57 topics
5. [Combinatorics](#5-combinatorics) — 7 subcategories, 24 topics
6. [Math](#6-math) — 10 subcategories, 79 topics
7. [Strings](#7-strings) — 7 subcategories, 31 topics
8. [Dynamic Programming (DP)](#8-dynamic-programming-dp) — 10 subcategories, 35 topics
9. [Game Theory](#9-game-theory) — 4 subcategories, 7 topics
10. [Geometry](#10-geometry) — 10 subcategories, 55 topics
11. [Miscellaneous](#11-miscellaneous) — 11 subcategories, 41 topics

---

## 1. Basics

**Category ID:** `basics` · **Subcategories:** 19 · **Topics:** 56

### 1.1 Intro to Programming

**Subcategory ID:** `intro_to_programming` · **Topics:** 1

#### 1.1.1 What is Programming?

- **ID:** `programming` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/programming
- **Resources (4):**
  - ★ [Why Programming Is Important? | Bugra Kilic](https://www.youtube.com/watch?v=Dv7gLpW91DM)
  - ★ [What is Coding? | TeXplaiNIT](https://www.youtube.com/watch?v=N7ZmPYaXoic)
  - [What is Programming? | Code Academy](https://www.codecademy.com/article/what-is-programming)
  - ★ [What is Computer Programming? | freecodecamp](https://www.freecodecamp.org/news/what-is-programming/)

### 1.2 Learn a Language

**Subcategory ID:** `learning_a_language` · **Topics:** 10

#### 1.2.1 Intro to C++ and Setting up the Environment

- **ID:** `intro_to_cpp` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/intro_to_cpp
- **Resources (10):**
  - [C++ Introduction | W3 Schools](https://www.w3schools.com/cpp/cpp_intro.asp)
  - [CodeBlocks IDE Installation on Windows 10/11 \[2023 Update\] MinGW GCC Compiler | C & C++ Programming Geeky Script](https://www.youtube.com/watch?v=zIhhO2DcW2s)
  - [How to install CodeBlocks on Mac #1 CProgramming | CSBHASHA](https://www.youtube.com/watch?v=5kgtA6vPJOs)
  - [Install and setup CodeBlocks C/C++ IDE on Linux | LinuxH2O](https://www.youtube.com/watch?v=KTrQyyVmHDc)
  - [How to Compile and Run C++ Code | Tech With Tim](https://www.youtube.com/watch?v=lPd13fsU-CQ&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=1)
  - ★ [Getting Started With C++ | Programiz](https://www.programiz.com/cpp-programming/getting-started)
  - [Your First C++ Program | Programiz](https://www.programiz.com/cpp-programming/first-program)
  - ★ [Online IDE](https://www.programiz.com/cpp-programming/online-compiler/)
  - ★ [C++ Tutorial for Beginners - Full Course | freeCodeCamp.org](https://www.youtube.com/watch?v=vLnPwxZdW4Y)
  - ★ [Virtual Judge](https://vjudge.net/)
- **Problems (1):**
  - `[E]` ★ [Hello World](https://vjudge.net/problem/Aizu-ITP1_1_A)

#### 1.2.2 Data Types, Variables and Input Output

- **ID:** `variables_and_data_types` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/variables_and_data_types
- **Resources (9):**
  - ★ [C++ Program Structure | Tech With Tim](https://www.youtube.com/watch?v=ckbfOdMhZls&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=2)
  - ★ [Data Types and Variables | Tech With Tim](https://www.youtube.com/watch?v=zgutFVxOlTY&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=3)
  - ★ [User Input and Constants | Tech With Tim](https://www.youtube.com/watch?v=OA28SYILJv8&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=4)
  - [C++ Variables, Literals and Constants | Programiz](https://www.programiz.com/cpp-programming/variables-literals)
  - [C++ Comments | Programiz](https://www.programiz.com/cpp-programming/comments)
  - [C++ Data Types | Programiz](https://www.programiz.com/cpp-programming/data-types)
  - [C++ Constants | Programiz](https://www.programiz.com/cpp-programming/constants)
  - [C++ Basic Input/Output | Programiz](https://www.programiz.com/cpp-programming/input-output)
  - ★ [Data Types | USACO Guide](https://usaco.guide/general/data-types?lang=cpp)
- **Problems (1):**
  - `[E]` ★ [Basic Data Types](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/B)

#### 1.2.3 Operators

- **ID:** `operators` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/operators
- **Resources (5):**
  - ★ [Arithmetic Operators | Tech With Tim](https://www.youtube.com/watch?v=CWtiqVQp8uk&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=5)
  - ★ [Comparison Operators | Tech With Tim](https://www.youtube.com/watch?v=taBgBbXRadc&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=6)
  - ★ [Logical Operators (And, Or and Not) | Tech With Tim](https://www.youtube.com/watch?v=F__aAx-3HOY&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=7)
  - ★ [C++ Operators | Programiz](https://www.programiz.com/cpp-programming/operators)
  - ★ [C++ Relational and Logical Operators | Programiz](https://www.programiz.com/cpp-programming/relational-logical-operators)
- **Problems (6):**
  - `[E]` ★ [Simple Calculator](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/C)
  - `[E]` ★ [Difference](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/D)
  - `[E]` ★ [Area of a Circle](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/E)
  - `[E]` ★ [Age in Days](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/R)
  - `[M]` ★ [Summation from 1 to N](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/G)
  - `[M]` ★ [The last 2 digits](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/Y)

#### 1.2.4 Conditional Statements

- **ID:** `conditional_statements` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/conditional_statements
- **Resources (2):**
  - ★ [If, Else & Else If | Tech With Tim](https://www.youtube.com/watch?v=Zkr0aAdD1Ww&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=8)
  - ★ [C++ if, if...else and Nested if...else | Programiz](https://www.programiz.com/cpp-programming/if-else)
- **Problems (11):**
  - `[E]` ★ [Welcome for you with Conditions](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/I)
  - `[E]` ★ [Multiples](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/J)
  - `[E]` ★ [Capital or Small or Digit](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/M)
  - `[E]` [Char](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/N)
  - `[E]` [Interval](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/S)
  - `[E]` [Float or int](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/U)
  - `[E]` [Comparison](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/V)
  - `[M]` ★ [Max and Min](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/K)
  - `[M]` ★ [Sort Numbers](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/T)
  - `[M]` ★ [Mathematical Expression](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/W)
  - `[H]` ★ [Coordinates of a Point](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/Q)

#### 1.2.5 Loops

- **ID:** `loops` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/loops
- **Resources (6):**
  - ★ [For Loops | Tech With Tim](https://www.youtube.com/watch?v=gVmTVsAn6EI&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=10)
  - [C++ for Loop | Programiz](https://www.programiz.com/cpp-programming/for-loop)
  - ★ [While, Do While Loops & Break/Continue | Tech With Tim](https://www.youtube.com/watch?v=aOskrzlcBRY&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=11)
  - [C++ while and do...while Loop | Programiz](https://www.programiz.com/cpp-programming/do-while-loop)
  - ★ [C++ break Statement | Programiz](https://www.programiz.com/cpp-programming/break-statement)
  - ★ [C++ continue Statement | Programiz](https://www.programiz.com/cpp-programming/continue-statement)
- **Problems (18):**
  - `[E]` ★ [1 to N](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/A)
  - `[E]` ★ [Even Numbers](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/B)
  - `[E]` ★ [Even, Odd, Positive and Negative](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/C)
  - `[E]` [Fixed Password](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/D)
  - `[E]` ★ [Multiplication table](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/F)
  - `[E]` ★ [Factorial](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/G)
  - `[E]` ★ [One Prime](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/H)
  - `[E]` ★ [Divisors](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/K)
  - `[E]` [Numbers Histogram](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/N)
  - `[E]` ★ [Pyramid](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/O)
  - `[E]` ★ [Shape1](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/P)
  - `[E]` [Max](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/E)
  - `[M]` ★ [Digits](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/Q)
  - `[M]` [Sequence of Numbers and Sum](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/R)
  - `[M]` ★ [Sum of Consecutive Odd Numbers](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/S)
  - `[M]` ★ [Shape2](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/T)
  - `[H]` ★ [Shape3](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/W)
  - `[H]` [Convert To Decimal 2](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/X)

#### 1.2.6 Functions

- **ID:** `functions` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/functions
- **Resources (6):**
  - ★ [Functions | Tech With Tim](https://www.youtube.com/watch?v=C83tPpvxIJA&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=20)
  - ★ [C++ Functions | Programiz](https://www.programiz.com/cpp-programming/function)
  - ★ [C++ User-defined Function Types | Programiz](https://www.programiz.com/cpp-programming/user-defined-function-types)
  - [C++ Programming Default Arguments (Parameters) | Programiz](https://www.programiz.com/cpp-programming/default-argument)
  - [C++ Function Overloading | Programiz](https://www.programiz.com/cpp-programming/function-overloading)
  - ★ [Top 10 Most Used Inbuilt C++ functions for Competitive Programming | Geeks for Geeks](https://www.geeksforgeeks.org/top-10-most-used-inbuilt-c-functions-for-competitive-programming/)
- **Problems (10):**
  - `[E]` [Add](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/A)
  - `[E]` ★ [Two numbers](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/H)
  - `[E]` ★ [Swap](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/E)
  - `[E]` ★ [GCD](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/L)
  - `[E]` ★ [Wonderful Number](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/C)
  - `[E]` ★ [Primes from 1 to n](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/J)
  - `[M]` ★ [Lucky Numbers](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/M)
  - `[M]` ★ [Some Sums](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/U)
  - `[M]` [Equation](https://codeforces.com/group/MWSDmqGsZm/contest/223205/problem/F)
  - `[H]` ★ [Hard Compare](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/Z)

#### 1.2.7 Arrays

- **ID:** `arrays` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/arrays
- **Resources (4):**
  - ★ [Arrays | Tech With Tim](https://www.youtube.com/watch?v=1FVBeLD_FdE&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=9)
  - ★ [C++ Arrays | Programiz](https://www.programiz.com/cpp-programming/arrays)
  - [Passing Array to a Function in C++ Programming | Programiz](https://www.programiz.com/cpp-programming/passing-arrays-function)
  - [C++ Multidimensional Arrays | Programiz](https://www.programiz.com/cpp-programming/multidimensional-arrays)
- **Problems (21):**
  - `[E]` ★ [Summation](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/A)
  - `[E]` ★ [Searching](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/B)
  - `[E]` [Replacement](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/C)
  - `[E]` [Max](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/E)
  - `[E]` ★ [Lowest Number](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/E)
  - `[E]` ★ [Easy Fibonacci](https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/Y)
  - `[M]` ★ [Reversing](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/F)
  - `[M]` ★ [Palindrome Array](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/G)
  - `[M]` ★ [Sorting](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/H)
  - `[M]` ★ [Smallest Pair](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/I)
  - `[M]` ★ [Max Subarray](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/L)
  - `[M]` ★ [Replace MinMax](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/M)
  - `[M]` ★ [Minimize Number](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/P)
  - `[M]` [Count Subarrays](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/Q)
  - `[M]` ★ [Permutation with arrays](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/R)
  - `[H]` ★ [Frequency Array](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/V)
  - `[H]` ★ [Is B a subsequence of A ?](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/U)
  - `[H]` ★ [Search In Matrix](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/S)
  - `[H]` ★ [Matrix](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/T)
  - `[H]` [Mirror Array](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/W)
  - `[H]` ★ [2D Array - DS](https://vjudge.net/problem/HackerRank-2d-array)

#### 1.2.8 Strings

- **ID:** `strings` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/strings
- **Resources (3):**
  - [Strings | Tech With Tim](https://www.youtube.com/watch?v=QtP0PdLEvFk&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=13)
  - [C++ Strings | Programiz](https://www.programiz.com/cpp-programming/strings)
  - [C++ String Class | Programiz](https://www.programiz.com/cpp-programming/string-class)
- **Problems (16):**
  - `[E]` ★ [Say Hello With C++](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/A)
  - `[E]` [Create A New String](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/A)
  - `[E]` ★ [Let's use Getline](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/B)
  - `[E]` ★ [Way Too Long Words](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/F)
  - `[E]` [First digit !](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/P)
  - `[E]` ★ [Sum Digits](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/K)
  - `[E]` [Conversion](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/G)
  - `[M]` [The Brothers](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/L)
  - `[M]` [Calculator](https://codeforces.com/group/MWSDmqGsZm/contest/219158/problem/O)
  - `[M]` ★ [Compare](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/C)
  - `[M]` ★ [Strings](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/D)
  - `[M]` ★ [Good or Bad](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/H)
  - `[M]` ★ [Palindrome](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/I)
  - `[M]` ★ [Count Letters](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/J)
  - `[M]` [I Love strings](https://codeforces.com/group/MWSDmqGsZm/contest/219856/problem/K)
  - `[H]` ★ [8 Neighbors](https://codeforces.com/group/MWSDmqGsZm/contest/219774/problem/X)

#### 1.2.9 Pointers and References

- **ID:** `pointers` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/pointers
- **Resources (7):**
  - ★ [Pointers (*) | Tech With Tim](https://www.youtube.com/watch?v=jUbOcBkdMF0&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=15)
  - ★ [References (&) | Tech With Tim](https://www.youtube.com/watch?v=RGYGiLUAQ3c&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=14)
  - ★ [Pointers in C/C++](https://www.youtube.com/playlist?list=PL2_aWCzGMAwLZp6LMUKI3cc7pgGsasm2_)
  - [C++ Pointers | Programiz](https://www.programiz.com/cpp-programming/pointers)
  - [C++ Pointers and Arrays | Programiz](https://www.programiz.com/cpp-programming/pointers-arrays)
  - [C++ References | Programiz](https://www.programiz.com/cpp-programming/references)
  - ★ [C++ Pass by Reference | Programiz](https://www.programiz.com/cpp-programming/pointers-function)
- **Problems (1):**
  - `[E]` ★ [Pointer](https://vjudge.net/problem/HackerRank-c-tutorial-pointer)

#### 1.2.10 Structures

- **ID:** `structures` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 0
- **Topic page:** https://youkn0wwho.academy/topic-list/structures
- **Resources (3):**
  - ★ [C++ Structures | Programiz](https://www.programiz.com/cpp-programming/structure)
  - [C++ Structure and Function | Programiz](https://www.programiz.com/cpp-programming/structure-function)
  - [Structure In C++ | CppNuts](https://www.youtube.com/watch?v=_vmtpsNgD7o)

### 1.3 Intro to Competitive Programming

**Subcategory ID:** `intro_to_cp` · **Topics:** 1

#### 1.3.1 What is Competitive Programming?

- **ID:** `competitive_programming` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/competitive_programming
- **Resources (11):**
  - ★ [Competitive-Programming-A-Complete-Guideline | DSAAcademy — Shahjalal Shohag](https://github.com/ShahjalalShohag/Competitive-Programming-A-Complete-Guideline)
  - ★ [What is Competitive Programming? | William Lin](https://www.youtube.com/watch?v=ueNT-w7Oluw&t=85s)
  - ★ [How to start Competitive Programming? For beginners! | Errichto Algorithms](https://www.youtube.com/watch?v=xAeiXy8-9Y8)
  - ★ [How to Practice | USACO Guide](https://usaco.guide/general/practicing?lang=cpp)
  - ★ [Contest Strategy | USACO Guide](https://usaco.guide/general/contest-strategy?lang=cpp)
  - ★ [Resources: Competitive Programming | USACO Guide](https://usaco.guide/general/resources-cp?lang=cpp)
  - ★ [Contests | USACO Guide](https://usaco.guide/general/contests?lang=cpp)
  - ★ [How to Debug | USACO Guide](https://usaco.guide/general/debugging-checklist?lang=cpp)
  - ★ [Basic Debugging | USACO Guide](https://usaco.guide/general/basic-debugging?lang=cpp)
  - [My Video Tutorials for all the practice problems below \[in Bangla\]](https://www.youtube.com/watch?v=DX3NnP16r3I)
  - ★ [Editorial, Codes and AI Help for all the practice problems below](https://youkn0wwho.academy/demo/progress_tracking)
- **Problems (18):**
  - `[E]` ★ [Multiplication 1](https://vjudge.net/problem/AtCoder-abc169_a)
  - `[E]` ★ [Again Twenty Five!](https://codeforces.com/problemset/problem/630/A)
  - `[E]` ★ [Counting](https://vjudge.net/problem/AtCoder-abc209_a)
  - `[E]` [Buttons](https://vjudge.net/problem/AtCoder-abc124_a)
  - `[E]` [Round decimals](https://vjudge.net/problem/AtCoder-abc226_a)
  - `[E]` ★ [Four Digits](https://vjudge.net/problem/AtCoder-abc222_a)
  - `[E]` [Biscuit Generator](https://vjudge.net/problem/AtCoder-abc125_a)
  - `[E]` [Find Multiple](https://vjudge.net/problem/AtCoder-abc220_a)
  - `[E]` ★ [Ebony and Ivory](https://vjudge.net/problem/CodeForces-633A)
  - `[E]` [Square Inequality](https://vjudge.net/problem/AtCoder-abc199_a)
  - `[E]` [Discount](https://vjudge.net/problem/AtCoder-abc193_a)
  - `[E]` [AC or WA](https://vjudge.net/problem/AtCoder-abc152_a)
  - `[E]` ★ [Tricky Sum](https://codeforces.com/problemset/problem/598/A)
  - `[E]` ★ [Almost Prime](https://vjudge.net/problem/CodeForces-26A)
  - `[M]` ★ [How many?](https://vjudge.net/problem/AtCoder-abc214_b)
  - `[M]` ★ [Beautiful Year](https://vjudge.net/problem/CodeForces-271A)
  - `[M]` ★ [Sum of Three Integers](https://atcoder.jp/contests/abc051/tasks/abc051_b)
  - `[H]` ★ [Sum of Digits](https://vjudge.net/problem/CodeForces-102B)

### 1.4 Bitwise Thinking

**Subcategory ID:** `bitwise_thinking` · **Topics:** 1

#### 1.4.1 Bitwise Operations and Bitmasks

- **ID:** `bitwise_operations` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/bitwise_operations
- **Templates (2):**
  - [Bitwise Operations.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Bitwise%20Operations.cpp)
  - [Bitmasks.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Bitmasks.cpp)
- **Resources (3):**
  - ★ [C++ Bitwise Operators | Programiz](https://www.programiz.com/cpp-programming/bitwise-operators)
  - ★ [Bitwise operations for beginners By Errichto](https://codeforces.com/blog/entry/73490)
  - [Learn these 10 Bitwise Tricks Or Regret Later | Competitive Programming Tricks Part 2](https://youtu.be/LGrE0siZ-ZA?si=Ohjq6KG7pHqf8st0)
- **Problems (18):**
  - `[E]` ★ [Bitwise Operators](https://vjudge.net/problem/HackerRank-bitwise-operators-in-c)
  - `[E]` ★ [Maximizing XOR](https://vjudge.net/problem/HackerRank-maximizing-xor)
  - `[E]` [Day 29: Bitwise AND](https://vjudge.net/problem/HackerRank-30-bitwise-and)
  - `[E]` ★ [Check bit](https://vjudge.net/problem/HackerRank-si-basic-check-bit)
  - `[E]` ★ [Flipping bits](https://vjudge.net/problem/HackerRank-flipping-bits)
  - `[E]` ★ [Swap Bits](https://vjudge.net/problem/HackerRank-si-swap-bits)
  - `[E]` ★ [Reverse Bits](https://vjudge.net/problem/HackerRank-si-reverse-bits)
  - `[E]` [Raising Bacteria](https://codeforces.com/problemset/problem/579/A)
  - `[E]` ★ [Bit Strings](https://cses.fi/problemset/task/1617)
  - `[M]` ★ [Petr and a Combination Lock](https://codeforces.com/problemset/problem/1097/B)
  - `[M]` ★ [Preparing Olympiad](https://codeforces.com/problemset/problem/550/B)
  - `[M]` [Bars](https://vjudge.net/problem/UVA-12455)
  - `[M]` [Little Elephant and Bits](https://vjudge.net/problem/CodeForces-258A)
  - `[M]` ★ [Lucky Numbers (easy)](https://codeforces.com/problemset/problem/96/B)
  - `[M]` [Many Formulas](https://vjudge.net/problem/AtCoder-arc061_a)
  - `[M]` ★ [Apple Division](https://cses.fi/problemset/task/1623)
  - `[M]` ★ [Factorials and Powers of Two](https://codeforces.com/contest/1646/problem/C)
  - `[H]` ★ [Knapsack](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/U)

### 1.5 Complexity Analysis

**Subcategory ID:** `complexity_analysis` · **Topics:** 2

#### 1.5.1 Big O Notation and Time and Space Complexity Analysis

- **ID:** `complexity_analysis` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/complexity_analysis
- **Resources (9):**
  - ★ [Mastering Big O Notation: Understanding Time and Space Complexity in Algorithms | Chinenye Okeke](https://medium.com/@DevChy/introduction-to-big-o-notation-time-and-space-complexity-f747ea5bca58)
  - ★ [Introduction to Big-O WilliamFiset](https://www.youtube.com/watch?v=zUUkiEllHG0)
  - [Big O Notation & Time Complexity Analysis Tutorial | Tech With Tim](https://www.youtube.com/watch?v=6aDHWSNKlVw)
  - [Big-O Notation - For Coding Interviews | NeetCode](https://www.youtube.com/watch?v=BgLTDT03QtU)
  - ★ [Time Complexity | USACO Guide](https://usaco.guide/bronze/time-comp?lang=cpp)
  - [Complete Guide On Complexity Analysis – Data Structure and Algorithms Tutorial | Geeks for Geeks](https://www.geeksforgeeks.org/complete-guide-on-complexity-analysis/)
  - [A Time Complexity Guide By UnexpectedValue](https://codeforces.com/blog/entry/104888)
  - ★ [How to determine the solution of a problem by looking at its constraints? By eanacra](https://codeforces.com/blog/entry/21344)
  - [Introduction to Big O Notation and Time Complexity | CS Dojo](https://www.youtube.com/watch?v=D6xkbGLQesk)
- **Problems (6):**
  - `[E]` ★ [Again Twenty Five!](https://codeforces.com/problemset/problem/630/A)
  - `[E]` ★ [Tricky Sum](https://codeforces.com/problemset/problem/598/A)
  - `[E]` ★ [Divisibility Problem](https://codeforces.com/problemset/problem/1328/A)
  - `[E]` ★ [Calculating Function](https://codeforces.com/problemset/problem/486/A)
  - `[M]` ★ [Sum of Three Integers](https://atcoder.jp/contests/abc051/tasks/abc051_b)
  - `[M]` [Repetitions](https://cses.fi/problemset/task/1069)

#### 1.5.2 Fast Input Output

- **ID:** `fast_input_output` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/fast_input_output
- **Resources (3):**
  - ★ [Fast Input/Output | G&G](https://www.youtube.com/watch?v=DhPMRStOU7o)
  - [Fast input output](https://youtu.be/aNF4DEluWnI?si=hzmaGxIlAl1Pb3ue)
  - ★ [Fast Input & Output | USACO Guide](https://usaco.guide/general/fast-io?lang=cpp)
- **Problems (1):**
  - `[E]` ★ [Enormous Input and Output Test](https://vjudge.net/problem/SPOJ-INOUTEST)

### 1.6 Recursion

**Subcategory ID:** `recursion` · **Topics:** 1

#### 1.6.1 Recursion

- **ID:** `recursion` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/recursion
- **Resources (7):**
  - ★ [Recursion in C | Neso Academy](https://www.youtube.com/playlist?list=PLBlnK6fEyqRjTO_UNGKuaaoxEqvSF0t5h)
  - ★ [C++ Recursion](https://www.programiz.com/cpp-programming/recursion)
  - ★ [5 Simple Steps for Solving Any Recursive Problem | Reducible](https://www.youtube.com/watch?v=ngCos392W4w)
  - ★ [Towers of Hanoi: A Complete Recursive Visualization | Reducible](https://www.youtube.com/watch?v=rf6uf3jNjbo&list=PLpXOY-RxVRTM_-Lvss2ezy1lVl6VUrzW2&index=2)
  - [Introduction to Recursion – Data Structure and Algorithm Tutorials | Geeks for Geeks](https://www.geeksforgeeks.org/introduction-to-recursion-data-structure-and-algorithm-tutorials/)
  - [\[Bangla\] An In-depth Analysis of Function and Recursion in Competitive Programming - DSAAcademy](https://www.youtube.com/watch?v=QwR1_GXnNkA)
  - [Recursion Series | take U forward](https://www.youtube.com/playlist?list=PLgUwDviBIf0rGlzIn_7rsaR2FQ5e6ZOL9)
- **Problems (14):**
  - `[E]` ★ [Print Recursion](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/A)
  - `[E]` ★ [Print from 1 to N](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/B)
  - `[E]` [Print from N to 1](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/C)
  - `[E]` ★ [Factorial](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/J)
  - `[E]` ★ [Fibonacci](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/O)
  - `[E]` [Print Even Indices](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/F)
  - `[E]` ★ [Hello Recursion](https://vjudge.net/problem/SPOJ-HRECURS)
  - `[E]` ★ [Weird Algorithm](https://cses.fi/problemset/task/1068)
  - `[E]` [Palindrome Array](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/R)
  - `[E]` ★ [Tower of Hanoi](https://vjudge.net/problem/CSES-2165)
  - `[M]` ★ [Number of Ways](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/Y)
  - `[M]` ★ [Apple Division](https://cses.fi/problemset/task/1623)
  - `[H]` ★ [Reach Value](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/W)
  - `[H]` ★ [Knapsack](https://codeforces.com/group/MWSDmqGsZm/contest/223339/problem/U)

### 1.7 Very Basic Math

**Subcategory ID:** `very_basic_math` · **Topics:** 3

#### 1.7.1 Divisors

- **ID:** `divisors` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/divisors
- **Templates (1):**
  - [Divisors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Divisors.cpp)
- **Resources (3):**
  - ★ [C++ Program to Display Factors of a Number | Programiz](https://www.programiz.com/cpp-programming/examples/factors-number)
  - ★ [L2. Print all Divisors of a Number | Maths Playlist | take U forward](https://www.youtube.com/watch?v=Ae_Ag_saG9s)
  - [Find all divisors of a natural number - Set 2 in C++ | tutorialspoint](https://www.tutorialspoint.com/find-all-divisors-of-a-natural-number-set-2-in-cplusplus)
- **Problems (5):**
  - `[E]` ★ [Divisors](https://vjudge.net/problem/Gym-405759K)
  - `[E]` [How Many Divisors?](https://vjudge.net/problem/Aizu-ITP1_3_D)
  - `[E]` ★ [k-th divisor](https://vjudge.net/problem/CodeForces-762A)
  - `[E]` ★ [Counting Divisors](https://cses.fi/problemset/task/1713)
  - `[M]` ★ [Product of Three Numbers](https://codeforces.com/problemset/problem/1294/C)

#### 1.7.2 GCD and LCM

- **ID:** `gcd_and_lcm` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/gcd_and_lcm
- **Templates (1):**
  - [GCD and LCM.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/GCD%20and%20LCM.cpp)
- **Resources (3):**
  - ★ [GCD of Two Numbers in C++ | Geeks for Geeks](https://www.geeksforgeeks.org/gcd-in-cpp/)
  - ★ [C++ Program to Find LCM | Programiz](https://www.programiz.com/cpp-programming/examples/lcm)
  - [Properties Of GCD function](https://codeforces.com/blog/entry/95694)
- **Problems (13):**
  - `[E]` ★ [Greatest Common Divisor](https://csacademy.com/contest/archive/task/gcd/)
  - `[E]` ★ [LCM and HCF](https://vjudge.net/problem/HackerRank-si-lcm-and-hcf)
  - `[E]` ★ [Common Divisors](https://vjudge.net/problem/CodeForces-1203C)
  - `[E]` [Dora and C++](https://codeforces.com/contest/2007/problem/C)
  - `[E]` [Two Divisors](https://codeforces.com/contest/1916/problem/B)
  - `[M]` [LCM Problem](https://codeforces.com/problemset/problem/1389/A)
  - `[M]` [GCDs](https://vjudge.net/problem/Kattis-gcds)
  - `[M]` [Bestie](https://codeforces.com/problemset/problem/1732/A)
  - `[M]` [Exciting Bets](https://codeforces.com/problemset/problem/1543/A)
  - `[H]` ★ [Minimum LCM](https://vjudge.net/problem/CodeForces-1765M)
  - `[H]` ★ [Fadi and LCM](https://vjudge.net/problem/CodeForces-1285C)
  - `[H]` ★ [Diluc and Kaeya](https://codeforces.com/contest/1536/problem/C)
  - `[H]` [Annoying String Problem](https://atcoder.jp/contests/arc181/tasks/arc181_b)

#### 1.7.3 Harmonic Number

- **ID:** `harmonic_series` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/harmonic_series
- **Templates (1):**
  - [Harmonic Number Example.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Harmonic%20Number%20Example.cpp)
- **Resources (4):**
  - [Harmonic number | Wiki](https://en.wikipedia.org/wiki/Harmonic_number)
  - [Proof: harmonic series diverges | Series | AP Calculus BC | Khan Academy](https://www.youtube.com/watch?v=4yyLfrsSXQQ)
  - ★ [what is the complexity of harmonic series](https://math.stackexchange.com/questions/2406498/what-is-the-complexity-of-harmonic-series)
  - [\[Slightly Hard\] Investigating harmonic numbers By Proofy](https://codeforces.com/blog/entry/118001)
- **Problems (10):**
  - `[E]` ★ [Counting Divisors](https://cses.fi/problemset/task/1713)
  - `[E]` ★ [Divisor Summation](https://www.spoj.com/problems/DIVSUM/)
  - `[E]` ★ [We Were Both Children](https://codeforces.com/problemset/problem/1850/F)
  - `[E]` [Number of common divisors](https://www.spoj.com/problems/COMDIV/)
  - `[E]` ★ [Aliquot Sum](https://codeforces.com/gym/103373/problem/B)
  - `[E]` [Removing Smallest Multiples](https://codeforces.com/contest/1734/problem/C)
  - `[E]` [Make Them Equal](https://codeforces.com/contest/1594/problem/C)
  - `[M]` [Orac and Models](https://codeforces.com/contest/1350/problem/B)
  - `[M]` [Super Hero](https://www.codechef.com/START159B/problems/SUPER_HERO)
  - `[H]` [Kevin and Competition Memories](https://codeforces.com/contest/2048/problem/D)

### 1.8 Range Queries Without Updates

**Subcategory ID:** `range_queries_without_updates` · **Topics:** 2

#### 1.8.1 Prefix Sum

- **ID:** `prefix_sum` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/prefix_sum
- **Templates (1):**
  - [Prefix Sum.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Prefix%20Sum.cpp)
- **Resources (2):**
  - ★ [Prefix Sums - Problems | Errichto Algorithms](https://www.youtube.com/watch?v=PhgtNY_-CiY)
  - ★ [Introduction to Prefix Sums | USACO Guide](https://usaco.guide/silver/prefix-sums?lang=cpp)
- **Problems (27):**
  - `[E]` ★ [Static Range Sum Queries](https://cses.fi/problemset/task/1646)
  - `[E]` [Static Range Sum](https://judge.yosupo.jp/problem/static_range_sum)
  - `[E]` [count a's](https://codeforces.com/group/c3FDl9EUi9/contest/262795/problem/H)
  - `[E]` ★ [Odd Queries](https://codeforces.com/contest/1807/problem/D)
  - `[E]` ★ [Breed Counting](https://vjudge.net/problem/USACO-572)
  - `[E]` ★ [Kuriyama Mirai's Stones](https://codeforces.com/contest/433/problem/B)
  - `[E]` [Little Chef and Sums](https://www.codechef.com/problems/CHEFSUM)
  - `[E]` [Worms](https://codeforces.com/problemset/problem/474/B)
  - `[E]` [Black and White Stripe](https://codeforces.com/contest/1690/problem/D)
  - `[E]` [Scuza](https://codeforces.com/problemset/problem/1742/E)
  - `[E]` [Vlad and a Sum of Sum of Digits](https://codeforces.com/problemset/problem/1926/C)
  - `[E]` [Binary Deque](https://codeforces.com/problemset/problem/1692/E)
  - `[E]` [Maximum Sum](https://codeforces.com/contest/1832/problem/B)
  - `[E]` [Closest Cities](https://codeforces.com/contest/1922/problem/C)
  - `[M]` [Fence](https://codeforces.com/problemset/problem/363/B)
  - `[M]` ★ [Subsequences Summing to Sevens](https://usaco.org/index.php?page=viewproblem2&cpid=595)
  - `[M]` [Prefix Sum Addicts](https://codeforces.com/problemset/problem/1738/B)
  - `[M]` ★ [Subarray Sums II](https://cses.fi/problemset/task/1661)
  - `[M]` ★ [Subarray Divisibility](https://cses.fi/problemset/task/1662)
  - `[M]` [Volcanic Eruption](https://www.codechef.com/problems/VOLCANO?tab=statement)
  - `[M]` [Left and Right Houses](https://codeforces.com/problemset/problem/1945/C)
  - `[M]` [Playing in a Casino](https://codeforces.com/problemset/problem/1808/B)
  - `[M]` [A and B](https://codeforces.com/problemset/problem/2149/D)
  - `[H]` [Maximum Subarray Sum](https://codeforces.com/contest/2107/problem/C)
  - `[H]` ★ [Romantic Glasses](https://codeforces.com/problemset/problem/1915/E)
  - `[VH]` [Sums of Segments](https://codeforces.com/contest/2026/problem/D)
  - `[VH]` [Sum of Subarrays](https://atcoder.jp/contests/abc423/tasks/abc423_e)

#### 1.8.2 Prefix XOR

- **ID:** `prefix_xor` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/prefix_xor
- **Templates (1):**
  - [Prefix Xor.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Prefix%20Xor.cpp)
- **Resources (2):**
  - [Prefix Xor Array | Geeks for Geeks](https://www.geeksforgeeks.org/prefix-xor-array/)
  - ★ [CSES - Range Xor Queries | USACO Guide](https://usaco.guide/problems/cses-1650-range-xor-queries/solution)
- **Problems (1):**
  - `[E]` ★ [Range Xor Queries](https://cses.fi/problemset/task/1650)

### 1.9 Standard Template Library (STL)

**Subcategory ID:** `stl` · **Topics:** 11

#### 1.9.1 Intro to STL, Containers and Iterators

- **ID:** `stl_intro` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/stl_intro
- **Resources (7):**
  - ★ [C++ Standard Template Library | Programiz](https://www.programiz.com/cpp-programming/standard-template-library)
  - ★ [Introduction | C++ STL (Standard Template Library) | Knowledge Center](https://www.youtube.com/watch?v=BKBXM7ypQG0&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=1)
  - ★ [Containers C++ | C++ STL (Standard Template Library) Knowledge Center](https://www.youtube.com/watch?v=1MmpefbNGeU&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=2)
  - ★ [Iterators in C++ | C++ STL (Standard Template Library) | types of Iterators Knowledge Center](https://www.youtube.com/watch?v=wjfb2kT6dtI&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=3)
  - ★ [Iterators Functions | C++ STL (Standard Template Library) | 4 important iterator functions Knowledge Center](https://www.youtube.com/watch?v=aATdPX_5T_Q&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=4)
  - [Iterator Invalidation | C++ STL (Standard Template Library) Knowledge Center](https://www.youtube.com/watch?v=MW9Cs4cCyTI&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=5)
  - ★ [C++ Iterators | Programiz](https://www.programiz.com/cpp-programming/iterators)

#### 1.9.2 Pairs and Tuples

- **ID:** `pairs_and_tuples` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/pairs_and_tuples
- **Resources (3):**
  - ★ [Pair in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/pair-in-cpp-stl/)
  - ★ [Tuples | Tech With Tim](https://www.youtube.com/watch?v=T9-agjKW4PQ)
  - ★ [Tuples in C++ | Geeks for Geeks](https://www.geeksforgeeks.org/tuples-in-c/)
- **Problems (2):**
  - `[E]` ★ [Indian Summer](https://codeforces.com/contest/44/problem/A)
  - `[E]` ★ [A1. Balanced Shuffle (Easy)](https://codeforces.com/problemset/problem/1970/A1)

#### 1.9.3 Vector

- **ID:** `vector` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/vector
- **Resources (7):**
  - ★ [Vectors | Tech With Tim](https://www.youtube.com/watch?v=RXzzE2wnnlo&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=18)
  - ★ [C++ Vectors | Programiz](https://www.programiz.com/cpp-programming/vectors)
  - [Vector | C++ STL (Standard Template Library) | std::vector Knowledge Center](https://www.youtube.com/watch?v=0DNDvuHZDiQ&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=6)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [Vector in C++ STL | TUF](https://takeuforward.org/c/vector-in-c-stl/)
  - [Vector in C++ STL | Geeks for Geeks](https://www.geeksforgeeks.org/vector-in-cpp-stl/)
  - [\[Hindi\] Vector In C++ STL | CodeWithHarry](https://www.youtube.com/watch?v=wKDvMcJiEPM)
- **Problems (7):**
  - `[E]` ★ [Vector](https://vjudge.net/problem/Aizu-ITP2_1_A)
  - `[E]` ★ [Vector-Sort](https://vjudge.net/problem/HackerRank-vector-sort)
  - `[E]` ★ [Vector-Erase](https://vjudge.net/problem/HackerRank-vector-erase)
  - `[E]` ★ [Vector II](https://vjudge.net/problem/Aizu-ITP2_1_D)
  - `[E]` [Good Sequence](https://vjudge.net/problem/AtCoder-arc087_a)
  - `[M]` ★ [Lower Bound-STL](https://vjudge.net/problem/HackerRank-cpp-lower-bound)
  - `[M]` [Thor](https://vjudge.net/problem/CodeForces-704A)

#### 1.9.4 Stack

- **ID:** `stack` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/stack
- **Resources (4):**
  - ★ [C++ Stack | Programiz](https://www.programiz.com/cpp-programming/stack)
  - [Stack | C++ STL (Standard Template Library) | std::stack Knowledge Center](https://www.youtube.com/watch?v=WK97Pj0wa7A&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=9)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [Stack in C++ STL | Geeks for Geeks](https://www.geeksforgeeks.org/stack-in-cpp-stl/)
- **Problems (7):**
  - `[E]` ★ [Simple Stack](https://vjudge.net/problem/EOlymp-6122)
  - `[E]` ★ [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)
  - `[E]` ★ [Stacks: Balanced Brackets](https://vjudge.net/problem/HackerRank-ctci-balanced-brackets)
  - `[E]` ★ [Nearest Smaller Values](https://cses.fi/problemset/task/1645)
  - `[E]` [Even Positions](https://codeforces.com/problemset/problem/1997/C)
  - `[M]` ★ [Longest Regular Bracket Sequence](https://codeforces.com/problemset/problem/5/C)
  - `[M]` [Scope](https://atcoder.jp/contests/abc283/tasks/abc283_d)

#### 1.9.5 Queue

- **ID:** `queue` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/queue
- **Resources (4):**
  - ★ [C++ Queue | Programiz](https://www.programiz.com/cpp-programming/queue)
  - [Queue | C++ STL (Standard Template Library) | std::queue Knowledge Center](https://www.youtube.com/watch?v=M73wcfBwX7Y&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=10)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [Queue in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/queue-cpp-stl/)
- **Problems (4):**
  - `[E]` ★ [Easy Queue](https://vjudge.net/problem/SPOJ-QUEUEEZ)
  - `[E]` ★ [Queue](https://vjudge.net/problem/Aizu-ALDS1_3_B)
  - `[M]` ★ [Team Queue](https://vjudge.net/problem/UVA-540)
  - `[M]` [Jzzhu and Children](https://codeforces.com/contest/450/problem/A)

#### 1.9.6 Priority Queue

- **ID:** `priority_queue` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/priority_queue
- **Resources (4):**
  - ★ [C++ Priority Queue | Programiz](https://www.programiz.com/cpp-programming/priority-queue)
  - [Priority Queue | C++ STL (Standard Template Library) | std::priority_queue Knowledge Center](https://www.youtube.com/watch?v=WhIcVlkZ19s&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=11)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [Priority Queue in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/priority-queue-in-cpp-stl/)
- **Problems (9):**
  - `[E]` ★ [Priority Queue](https://vjudge.net/problem/Aizu-ALDS1_9_C)
  - `[E]` ★ [Priority Queue 2](https://vjudge.net/problem/Aizu-ITP2_2_C)
  - `[E]` ★ [8 Use Priority Queue Please](https://vjudge.net/problem/CodeChef-CCOP8)
  - `[E]` ★ [priority queue minimum](https://vjudge.net/problem/Gym-381668C)
  - `[E]` [Hinata & Priority Queue](https://vjudge.net/problem/HackerRank-hinata-priority-queue)
  - `[E]` [Powering the Hero (hard version)](https://codeforces.com/contest/1800/problem/C2)
  - `[M]` [Room Allocation](https://cses.fi/problemset/task/1164)
  - `[M]` [Task Scheduler](https://leetcode.com/problems/task-scheduler/description/)
  - `[M]` [Potions (Hard Version)](https://codeforces.com/contest/1526/problem/C2)

#### 1.9.7 Deque

- **ID:** `deque` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/deque
- **Resources (4):**
  - ★ [C++ Deque | Programiz](https://www.programiz.com/cpp-programming/deque)
  - [Deque | C++ STL (Standard Template Library) | std::deque Knowledge Center](https://www.youtube.com/watch?v=3U_Eg9WdGr0&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=8)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [Deque in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/deque-cpp-stl/)
- **Problems (9):**
  - `[E]` ★ [Implement DeQue](https://vjudge.net/problem/HackerRank-si-implement-deque)
  - `[E]` [Simple deque](https://vjudge.net/problem/EOlymp-6128)
  - `[E]` [Deque](https://vjudge.net/problem/Aizu-ITP2_1_B)
  - `[E]` ★ [Ada and Queue](https://vjudge.net/problem/SPOJ-ADAQUEUE)
  - `[E]` ★ [Soldier and Cards](https://vjudge.net/problem/CodeForces-546C)
  - `[E]` [E1. Permutation Minimization by Deque](https://codeforces.com/problemset/problem/1579/E1)
  - `[E]` [Social Network (hard version)](https://codeforces.com/contest/1234/problem/B2)
  - `[M]` [Chimpanzini Bananini](https://codeforces.com/contest/2094/problem/G)
  - `[H]` ★ [Valeriy and Deque](https://vjudge.net/problem/CodeForces-1179A)

#### 1.9.8 Set, Unordered Set and Multiset

- **ID:** `set` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/set
- **Resources (13):**
  - ★ [Sets | Tech With Tim](https://www.youtube.com/watch?v=682xT_TcKUg&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=19)
  - [C++ Set | Programiz](https://www.programiz.com/cpp-programming/set)
  - [Set | C++ STL (Standard Template Library) | std::set 🔥 Knowledge Center](https://www.youtube.com/watch?v=2OEnAdl1eLc&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=12)
  - [Set in C++ | TUF](https://takeuforward.org/c/set-in-c-stl/)
  - [Set in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/set-in-cpp-stl/)
  - ★ [Unordered Set | C++ STL (Standard Template Library) | std::unordered_set 🔥 Knowledge Center](https://www.youtube.com/watch?v=g5RGA50LGCA&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=14)
  - [C++ Unordered Set | Programiz](https://www.programiz.com/cpp-programming/unordered-set)
  - [Unordered-set in C++ STL | TUF](https://takeuforward.org/c/unordered-set-in-c-stl/)
  - [Unordered Sets in C++ Standard Template Library | Geeks for Geeks](https://www.geeksforgeeks.org/unordered_set-in-cpp-stl/)
  - ★ [Multi Set | C++ STL (Standard Template Library) | std::multiset 🔥 Knowledge Center](https://www.youtube.com/watch?v=iJCnqHrkPq8&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=13)
  - [C++ Multiset | Programiz](https://www.programiz.com/cpp-programming/multiset)
  - [Multiset in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/multiset-in-cpp-stl/)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
- **Problems (7):**
  - `[E]` ★ [Sets-STL](https://vjudge.net/problem/HackerRank-cpp-sets)
  - `[E]` ★ [Distinct Numbers](https://cses.fi/problemset/task/1621)
  - `[E]` ★ [Double-Ended Priority Queue](https://vjudge.net/problem/Yosupo-double_ended_priority_queue)
  - `[E]` ★ [Concert Tickets](https://cses.fi/problemset/task/1091)
  - `[E]` [Unexpressed](https://atcoder.jp/contests/abc193/tasks/abc193_c)
  - `[M]` ★ [Collecting Numbers](https://cses.fi/problemset/task/2216)
  - `[M]` ★ [Towers](https://cses.fi/problemset/task/1073)

#### 1.9.9 Map and Unordered Map

- **ID:** `map` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/map
- **Resources (9):**
  - ★ [Maps | Tech With Tim](https://www.youtube.com/watch?v=7mwgA9XFIEQ&list=PLzMcBGfZo4-lmGC8VW0iu6qfMHjy7gLQ3&index=17)
  - [C++ Map | Programiz](https://www.programiz.com/cpp-programming/map)
  - [Map | C++ STL (Standard Template Library) | std::map Knowledge Center](https://www.youtube.com/watch?v=w1vDg3iBbLA&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=16)
  - [Map in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/map-associative-containers-the-c-standard-template-library-stl/)
  - ★ [C++ Unordered Map | Programiz](https://www.programiz.com/cpp-programming/unordered-map)
  - [unordered_map in C++ STL | Geeks for Geeks](https://www.geeksforgeeks.org/unordered_map-in-cpp-stl/)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - ★ [Blowing up unordered_map, and how to stop getting hacked on it By neal](https://codeforces.com/blog/entry/62393)
  - [\[Hindi\] CP Course by Luv - Maps](https://youtu.be/gUrfXZ0hqoA?feature=shared)
- **Problems (18):**
  - `[E]` ★ [Maps-STL](https://vjudge.net/problem/HackerRank-cpp-maps)
  - `[E]` ★ [FIGUREFUL](https://vjudge.net/problem/SPOJ-ACMCEG2B)
  - `[E]` ★ [Frinds and money](https://vjudge.net/problem/Gym-381668D)
  - `[E]` ★ [Hay Points](https://vjudge.net/problem/UVA-10295)
  - `[E]` ★ [Tom Riddle's Diary](https://vjudge.net/problem/CodeForces-855A)
  - `[E]` ★ [Registration System](https://vjudge.net/problem/CodeForces-4C)
  - `[E]` ★ [The Department of Redundancy Department](https://vjudge.net/problem/UVA-484)
  - `[E]` ★ [Babelfish](https://vjudge.net/problem/UVA-10282)
  - `[E]` ★ [Sum of Two Values](https://cses.fi/problemset/task/1640)
  - `[E]` ★ [Sum of Three Values](https://cses.fi/problemset/task/1641)
  - `[E]` [Boxes Packing](https://vjudge.net/problem/CodeForces-903C)
  - `[E]` ★ [Sum of Four Values](https://cses.fi/problemset/task/1642)
  - `[E]` ★ [Restaurant Customers](https://cses.fi/problemset/task/1619)
  - `[E]` [Ohana Cleans Up](https://codeforces.com/contest/554/problem/B)
  - `[M]` ★ [Subarray Sums II](https://cses.fi/problemset/task/1661)
  - `[M]` ★ [Subarray Divisibility](https://cses.fi/problemset/task/1662)
  - `[M]` ★ [Homo or Hetero](https://vjudge.net/problem/SPOJ-HOMO)
  - `[M]` [Chef of the Year](https://vjudge.net/problem/CodeChef-CVOTE)

#### 1.9.10 Bitset

- **ID:** `bitset` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/bitset
- **Resources (1):**
  - ★ [C++ bitset and its application | Geeks for Geeks](https://www.geeksforgeeks.org/cpp-bitset-and-its-application/)
- **Problems (3):**
  - `[E]` ★ [Set Operation](https://vjudge.net/problem/POJ-2443)
  - `[E]` ★ [Ada and Furrows](https://vjudge.net/problem/SPOJ-ADAFUROW)
  - `[H]` [Oddly Similar](https://atcoder.jp/contests/abc348/tasks/abc348_f)

#### 1.9.11 List / Linked List

- **ID:** `list` · **Difficulty:** Very Easy · **Importance:** ★★☆ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/list
- **Resources (4):**
  - ★ [List | C++ STL (Standard Template Library) | std::list Knowledge Center](https://www.youtube.com/watch?v=je7zlYfJf7Q&list=PL1w8k37X_6L9NXrP1D31hDTKcdAPIL0cG&index=7)
  - [C++ List | Programiz](https://www.programiz.com/cpp-programming/list)
  - [Complete C++ STL in 1 Video | Time Complexity and Notes | take U forward](https://www.youtube.com/watch?v=RRVYpIET_RU)
  - [List in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/list-cpp-stl/)
- **Problems (2):**
  - `[E]` ★ [Doubly Linked List](https://vjudge.net/problem/Aizu-ALDS1_3_C)
  - `[E]` ★ [Vector II](https://vjudge.net/problem/Aizu-ITP2_1_D)

### 1.10 Leveraging Monotonicity

**Subcategory ID:** `leveraging_monotonicity` · **Topics:** 2

#### 1.10.1 Binary Search

- **ID:** `binary_search` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/binary_search
- **Templates (1):**
  - [Binary Search.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Binary%20Search.cpp)
- **Resources (9):**
  - ★ [Binary Search tutorial | Errichto Algorithms](https://www.youtube.com/watch?v=GU7DpgHINWQ&list=PLl0KD3g-oDOHpWRyyGBUJ9jmul0lUOD80&index=3)
  - ★ [Binary Search | EDU](https://codeforces.com/edu/course/2/lesson/6)
  - ★ [Binary Search | USACO Guide](https://usaco.guide/silver/binary-search?lang=cpp)
  - ★ [Binary Search | CSAcademy](https://csacademy.com/lesson/binary_search)
  - [Binary Search | Programiz](https://www.programiz.com/dsa/binary-search)
  - [Binary Search Algorithm in 100 Seconds | Fireship](https://www.youtube.com/watch?v=MFhxShGxHWc)
  - [Binary Search In One Shot C++ \[Hindi\]](https://youtu.be/FYBuOLKKqrw?si=TSRi_J0MB071-uyT)
  - [Binary search and other "halving" methods | nor](https://nor-blog.codeberg.page/posts/2021-11-07-binary-search/)
  - [Binary Search Algorithm | Apna College | \[Hindi\]](https://www.youtube.com/watch?v=TbbSJrY5GqQ&ab_channel=ApnaCollege)
- **Problems (44):**
  - `[E]` ★ [Binary Search](https://codeforces.com/edu/course/2/lesson/6/1/practice/contest/283911/problem/A)
  - `[E]` ★ [Closest to the Left](https://codeforces.com/edu/course/2/lesson/6/1/practice/contest/283911/problem/B)
  - `[E]` [Closest to the Right](https://codeforces.com/edu/course/2/lesson/6/1/practice/contest/283911/problem/C)
  - `[E]` ★ [Fast search](https://codeforces.com/edu/course/2/lesson/6/1/practice/contest/283911/problem/D)
  - `[E]` ★ [Factory Machines](https://cses.fi/problemset/task/1620)
  - `[E]` ★ [Packing Rectangles](https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/A)
  - `[E]` ★ [Multiplication Table](https://cses.fi/problemset/task/2422)
  - `[E]` ★ [Ropes](https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/B)
  - `[E]` ★ [Very Easy Task](https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/C)
  - `[E]` ★ [Equation](https://codeforces.com/edu/course/2/lesson/6/2/practice/contest/283932/problem/E)
  - `[E]` [Robin Hood in Town](https://codeforces.com/contest/2014/problem/C)
  - `[E]` ★ [Array Division](https://cses.fi/problemset/task/1085)
  - `[E]` [Brightness Begins](https://codeforces.com/contest/2020/problem/B)
  - `[E]` [Queries about less or equal elements](https://codeforces.com/contest/600/problem/B)
  - `[E]` [Smooth Occlusion](https://atcoder.jp/contests/abc395/tasks/abc395_f)
  - `[E]` [Yet Another Problem About Pairs Satisfying an Inequality](https://codeforces.com/contest/1703/problem/F)
  - `[M]` ★ [Maximum Median](https://codeforces.com/contest/1201/problem/C)
  - `[M]` ★ [Splitting an Array](https://codeforces.com/edu/course/2/lesson/6/3/practice/contest/285083/problem/B)
  - `[M]` [Ugly Number III](https://leetcode.com/problems/ugly-number-iii/description/)
  - `[M]` ★ [Meeting on the Line](https://codeforces.com/problemset/problem/1730/B)
  - `[M]` ★ [Get together](https://codeforces.com/edu/course/2/lesson/6/3/practice/contest/285083/problem/A)
  - `[M]` ★ [Digit Queries](https://cses.fi/problemset/task/2431)
  - `[M]` [Cows in Stalls](https://codeforces.com/edu/course/2/lesson/6/3/practice/contest/285083/problem/C)
  - `[M]` [AGGRCOW - Aggressive cows](https://www.spoj.com/problems/AGGRCOW/)
  - `[M]` ★ [Maximum Average Segment](https://codeforces.com/edu/course/2/lesson/6/4/practice/contest/285069/problem/A)
  - `[M]` ★ [Pair Selection](https://codeforces.com/edu/course/2/lesson/6/4/practice/contest/285069/problem/C)
  - `[M]` [Magic Ship](https://codeforces.com/problemset/problem/1117/C)
  - `[M]` ★ [The Meeting Place Cannot Be Changed](https://codeforces.com/contest/782/problem/B)
  - `[M]` ★ [Interesting Function](https://codeforces.com/problemset/problem/1538/F)
  - `[M]` [Magic Powder - 1](https://codeforces.com/problemset/problem/670/D1)
  - `[M]` ★ [Mafia](https://codeforces.com/problemset/problem/348/A)
  - `[M]` ★ [Static Range Frequency](https://judge.yosupo.jp/problem/static_range_frequency)
  - `[M]` [Gift Set](https://codeforces.com/problemset/problem/1538/G)
  - `[M]` [Project Planning](https://atcoder.jp/contests/abc227/tasks/abc227_d)
  - `[M]` [Final Boss](https://codeforces.com/contest/1985/problem/F?locale=en)
  - `[M]` [Place of the Olympiad](https://codeforces.com/contest/2091/problem/D)
  - `[M]` [Magic Powder - 2](https://codeforces.com/contest/670/problem/D2)
  - `[M]` [Finding Routers](https://oj.uz/problem/view/IOI20_routers)
  - `[M]` [Scoring Subsequences](https://codeforces.com/problemset/problem/1794/C)
  - `[M]` [Wrong Binary Search](https://codeforces.com/problemset/problem/2146/C)
  - `[H]` ★ [K-th Sum](https://codeforces.com/edu/course/2/lesson/6/5/practice/contest/285084/problem/C)
  - `[H]` ★ [Swap Space](https://vjudge.net/problem/Gym-101242L)
  - `[H]` [Bomb](https://codeforces.com/contest/1996/problem/F)
  - `[H]` [Sensor Optimization Dilemma 2](https://atcoder.jp/contests/abc374/tasks/abc374_e)

#### 1.10.2 Two Pointers

- **ID:** `two_pointers` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/two_pointers
- **Templates (1):**
  - [Two Pointers.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Two%20Pointers.cpp)
- **Resources (5):**
  - ★ [Two Pointers Method | CF EDU](https://codeforces.com/edu/course/2/lesson/9)
  - ★ [Two Pointers | USACO Guide](https://usaco.guide/silver/two-pointers?lang=cpp)
  - [8.1 Two pointers method | CPH](https://usaco.guide/CPH.pdf#page=87)
  - [Two Pointers Technique | Geeks for Geeks](https://www.geeksforgeeks.org/two-pointers-technique/)
  - [Visual introduction Two Pointer Algorithm | Data Structure and Algorithm for Coding Interviews | Josh's DevBox](https://www.youtube.com/watch?v=On03HWe2tZM)
- **Problems (21):**
  - `[E]` ★ [Merging Arrays](https://codeforces.com/edu/course/2/lesson/9/1/practice/contest/307092/problem/A)
  - `[E]` ★ [Segment with Small Sum](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/A)
  - `[E]` ★ [Segment with Big Sum](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/B)
  - `[E]` ★ [Number of Segments with Small Sum](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/C)
  - `[E]` [Number of Segments with Big Sum](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/D)
  - `[E]` ★ [Sum of Two Values](https://cses.fi/problemset/task/1640)
  - `[E]` [Subarray Sums I](https://cses.fi/problemset/task/1660)
  - `[E]` [Books](https://codeforces.com/contest/279/problem/B)
  - `[E]` [Cellular Network](https://codeforces.com/contest/702/problem/C)
  - `[E]` [They Are Everywhere](https://codeforces.com/problemset/problem/701/C)
  - `[E]` [Eating Candies](https://codeforces.com/contest/1669/problem/F)
  - `[E]` ★ [Three Parts of the Array](https://codeforces.com/problemset/problem/1006/C)
  - `[E]` ★ [Playlist](https://cses.fi/problemset/task/1141)
  - `[E]` ★ [Sum of Three Values](https://cses.fi/problemset/task/1641)
  - `[E]` ★ [Subarray Distinct Values](https://cses.fi/problemset/task/2428)
  - `[E]` ★ [Sum of Four Values](https://cses.fi/problemset/task/1642)
  - `[M]` [Number of Pairs](https://codeforces.com/problemset/problem/1538/C)
  - `[M]` ★ [Split](https://codeforces.com/problemset/problem/2148/E)
  - `[M]` ★ [Segments with Small Set](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/E)
  - `[M]` ★ [Segments with Small Spread](https://codeforces.com/edu/course/2/lesson/9/2/practice/contest/307093/problem/F)
  - `[M]` [Quiz Master](https://codeforces.com/contest/1777/problem/C)

### 1.11 Basic Sorting Algorithms

**Subcategory ID:** `basic_sorting_algorithms` · **Topics:** 8

#### 1.11.1 Bubble Sort

- **ID:** `bubble_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/bubble_sort
- **Templates (1):**
  - [Bubble Sort.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Bubble%20Sort.cpp)
- **Resources (3):**
  - ★ [Bubble Sort | Programiz](https://www.programiz.com/dsa/bubble-sort)
  - ★ [Bubble Sort Visualization | Bubble Sort Animation Video | Log2Base2](https://www.youtube.com/watch?v=p6I7LIUqQnU)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (2):**
  - `[E]` ★ [Sorting: Bubble Sort](https://vjudge.net/problem/HackerRank-ctci-bubble-sort)
  - `[E]` [Bubble Sort](https://vjudge.net/problem/DMOJ-sort1)

#### 1.11.2 Selection Sort

- **ID:** `selection_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/selection_sort
- **Templates (1):**
  - [Selection Sort.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Selection%20Sort.cpp)
- **Resources (3):**
  - ★ [Selection Sort Algorithm | Programiz](https://www.programiz.com/dsa/selection-sort)
  - ★ [Selection Sort Animation | Ravindu Sachintha](https://www.youtube.com/watch?v=XeP1K3UZ35M)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (1):**
  - `[E]` ★ [Selection Sort](https://vjudge.net/problem/Aizu-ALDS1_2_B)

#### 1.11.3 Insertion Sort

- **ID:** `insertion_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/insertion_sort
- **Templates (1):**
  - [Insertion Sort.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Insertion%20Sort.cpp)
- **Resources (3):**
  - ★ [Insertion Sort Algorithm | Programiz](https://www.programiz.com/dsa/insertion-sort)
  - ★ [Insertion Sort Explained using Animations | bvdl․io](https://www.youtube.com/watch?v=HzteMqc4Gjg)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (1):**
  - `[E]` ★ [Insertion Sort](https://vjudge.net/problem/Aizu-ALDS1_1_A)

#### 1.11.4 Counting Sort

- **ID:** `counting_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/counting_sort
- **Templates (1):**
  - [Counting Sort.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Counting%20Sort.cpp)
- **Resources (3):**
  - ★ [Counting Sort Algorithm | Programiz](https://www.programiz.com/dsa/counting-sort)
  - ★ [Counting Sort Animation | Intuition | Algorithm | Visualization | Shreyaans Jain](https://www.youtube.com/watch?v=lKMkuZO4wlY)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (2):**
  - `[E]` ★ [Counting Sort 2](https://vjudge.net/problem/HackerRank-countingsort2)
  - `[E]` [The Full Counting Sort](https://vjudge.net/problem/HackerRank-countingsort4)

#### 1.11.5 Merge Sort

- **ID:** `merge_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/merge_sort
- **Templates (1):**
  - [Merge Sort.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Merge%20Sort.cpp)
- **Resources (5):**
  - ★ [Merge Sort Algorithm | Programiz](https://www.programiz.com/dsa/merge-sort)
  - ★ [Understanding Mergesort: Sorting Made Simple | Recursion Series | WilliamFiset](https://www.youtube.com/watch?v=-3u1C1URNZY)
  - ★ [Merge Sort | Manim Animation \[4K\] | CuriousWalk](https://www.youtube.com/watch?v=5Z9dn2WTg9o)
  - [MERGE SORT ALGORITHM | Sorting Algorithm | DSA | GeeksforGeeks](https://www.youtube.com/watch?v=JSceec-wEyw)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (4):**
  - `[E]` ★ [Merge sort](https://vjudge.net/problem/Gym-324997D)
  - `[E]` ★ [Inversion Count](https://vjudge.net/problem/SPOJ-INVCNT)
  - `[M]` [Merge Sort 2](https://vjudge.net/problem/Aizu-ALDS1_5_B)
  - `[M]` ★ [Bubble Sort?](https://vjudge.net/problem/SPOJ-BUBBLESORT)

#### 1.11.6 Quick Sort

- **ID:** `quick_sort` · **Difficulty:** Very Easy · **Importance:** ★★☆ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/quick_sort
- **Templates (1):**
  - [quick-sort](https://www.programiz.com/dsa/quick-sort)
- **Resources (4):**
  - ★ [Quicksort Algorithm | Programiz](https://www.programiz.com/dsa/quick-sort)
  - ★ [Quick Sort \[Visual Explanation\] | Manim Animation \[4K\] | CuriousWalk](https://www.youtube.com/watch?v=WprjBK0p6rw)
  - [QUICK SORT | Sorting Algorithms | DSA | GeeksforGeeks](https://www.youtube.com/watch?v=PgBzjlCcFvc)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (1):**
  - `[E]` ★ [Quick Sort](https://vjudge.net/problem/Aizu-ALDS1_6_C)

#### 1.11.7 Radix Sort

- **ID:** `radix_sort` · **Difficulty:** Very Easy · **Importance:** ★☆☆ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/radix_sort
- **Templates (1):**
  - [radix-sort](https://www.programiz.com/dsa/radix-sort)
- **Resources (3):**
  - ★ [Radix Sort Algorithm | Programiz](https://www.programiz.com/dsa/radix-sort)
  - ★ [Radix Sort | GeeksforGeeks](https://www.youtube.com/watch?v=nu4gDuFabIM)
  - ★ [Sorting Algorithm Visualizer | VisuAlgo](https://visualgo.net/en/sorting)
- **Problems (1):**
  - `[E]` ★ [Radix Sort](https://vjudge.net/problem/CodeChef-RDX)

#### 1.11.8 C++ STL Sort and Custom Comparator

- **ID:** `stl_sort` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/stl_sort
- **Resources (3):**
  - ★ [Sort in C++ Standard Template Library (STL) | Geeks for Geeks](https://www.geeksforgeeks.org/sort-algorithms-the-c-standard-template-library-stl/)
  - ★ [Custom Comparators | USACO Guide](https://usaco.guide/silver/sorting-custom?lang=cpp)
  - [All sorting algorithms at one place | Programiz](https://www.programiz.com/dsa/sorting-algorithm)
- **Problems (19):**
  - `[E]` ★ [Simple Sorting](https://vjudge.net/problem/CodeChef-TSORT)
  - `[E]` ★ [Sorting: Comparator](https://vjudge.net/problem/HackerRank-ctci-comparator-sorting)
  - `[E]` ★ [2D-SORT](https://vjudge.net/problem/SPOJ-SORT2D)
  - `[E]` ★ [Sorting Tuples](https://vjudge.net/problem/Aizu-ITP2_5_B)
  - `[E]` ★ [A problem of sorting](https://vjudge.net/problem/HDU-5427)
  - `[E]` ★ [Restaurant Customers](https://cses.fi/problemset/task/1619)
  - `[E]` [Sort the Array](https://vjudge.net/problem/CodeForces-451B)
  - `[E]` ★ [Parity Sort](https://vjudge.net/problem/CodeForces-1851B)
  - `[E]` [Bogosort](https://vjudge.net/problem/CodeForces-1312B)
  - `[E]` [Little Pony and Sort by Shift](https://vjudge.net/problem/CodeForces-454B)
  - `[E]` [Reverse Sort](https://vjudge.net/problem/CodeForces-1605B)
  - `[E]` ★ [Indian Summer](https://codeforces.com/contest/44/problem/A)
  - `[E]` [Rank List](https://codeforces.com/problemset/problem/166/A)
  - `[M]` ★ [The Smallest String Concatenation](https://codeforces.com/problemset/problem/632/C)
  - `[M]` ★ [Big Sorting](https://vjudge.net/problem/HackerRank-big-sorting)
  - `[M]` ★ [Double Sort](https://vjudge.net/problem/CodeForces-1681C)
  - `[M]` ★ [Concatenation of Arrays](https://codeforces.com/contest/2024/problem/C)
  - `[H]` [Nezzar and Symmetric Array](https://codeforces.com/problemset/problem/1478/C)
  - `[H]` [Correct Placement](https://codeforces.com/problemset/problem/1472/E)

### 1.12 Divide and Conquer

**Subcategory ID:** `divide_and_conquer` · **Topics:** 1

#### 1.12.1 Divide and Conquer

- **ID:** `divide_and_conquer` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/divide_and_conquer
- **Resources (2):**
  - ★ [Divide and Conquer: The Art of Breaking Down Problems | Recursion Series | WilliamFiset](https://www.youtube.com/watch?v=ib4BHvr5-Ao)
  - [Divide and Conquer Algorithm | Programiz](https://www.programiz.com/dsa/divide-and-conquer)
- **Problems (4):**
  - `[E]` ★ [Inversion Count](https://vjudge.net/problem/SPOJ-INVCNT)
  - `[E]` ★ [Print The Pattern](https://vjudge.net/problem/SPOJ-ABACABA)
  - `[M]` ★ [Merge Sort?](https://vjudge.net/problem/CodeForces-873D)
  - `[H]` [Ada and Species](https://www.spoj.com/problems/ADACABAA/)

### 1.13 Greedy and Constructive

**Subcategory ID:** `greedy_and_constructive` · **Topics:** 2

#### 1.13.1 Basic Greedy Algorithms

- **ID:** `greedy_algorithms` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/greedy_algorithms
- **Resources (3):**
  - ★ [Introduction to Greedy Algorithms | USACO Guide](https://usaco.guide/bronze/intro-greedy?lang=cpp)
  - ★ [Greedy Algorithms with Sorting | USACO Guide](https://usaco.guide/silver/greedy-sorting?lang=cpp)
  - [Greedy Algoritm by Abdul Bari](https://www.youtube.com/playlist?list=PL8zDQ1C22qvvwdkPj1uXLpwzcYDJtjnze)
- **Problems (25):**
  - `[E]` ★ [Studying Algorithms](https://vjudge.net/problem/Gym-102951B)
  - `[E]` ★ [Increasing Array](https://cses.fi/problemset/task/1094)
  - `[E]` ★ [Ferris Wheel](https://cses.fi/problemset/task/1090)
  - `[E]` ★ [Tasks and Deadlines](https://cses.fi/problemset/task/1630)
  - `[E]` [Reading Books](https://cses.fi/problemset/task/1631)
  - `[E]` [USB vs. PS/2](https://codeforces.com/contest/762/problem/B)
  - `[E]` ★ [Increasing Triplet Subsequence](https://leetcode.com/problems/increasing-triplet-subsequence/)
  - `[E]` [Movie Festival](https://cses.fi/problemset/task/1629/)
  - `[M]` ★ [Two Sets](https://cses.fi/problemset/task/1092)
  - `[M]` [Mad Scientist](https://vjudge.net/problem/USACO-1012)
  - `[M]` [Stick Lengths](https://cses.fi/problemset/task/1074)
  - `[M]` ★ [Towers](https://cses.fi/problemset/task/1073)
  - `[M]` ★ [Maximum Subarray Sum](https://cses.fi/problemset/task/1643)
  - `[M]` [The Party and Sweets](https://codeforces.com/problemset/problem/1158/A)
  - `[M]` ★ [Did We Get Everything Covered?](https://codeforces.com/problemset/problem/1924/A)
  - `[M]` [Grouping Increases](https://codeforces.com/problemset/problem/1919/C)
  - `[M]` ★ [Matching Arrays](https://codeforces.com/problemset/problem/1896/C)
  - `[M]` ★ [Least Prefix Sum](https://codeforces.com/problemset/problem/1779/C)
  - `[M]` [Sets and Union](https://codeforces.com/contest/1882/problem/B)
  - `[M]` [Robert Hood and Mrs Hood](https://codeforces.com/contest/2014/problem/D)
  - `[M]` [Quests](https://codeforces.com/problemset/problem/1914/C)
  - `[H]` ★ [Money Buys Less Happiness Now](https://codeforces.com/contest/1974/problem/G)
  - `[H]` ★ [Missing Coin Sum](https://cses.fi/problemset/task/2183)
  - `[H]` [Kevin and Numbers](https://codeforces.com/contest/2061/problem/D)
  - `[H]` [Apartments](https://cses.fi/problemset/task/1084)

#### 1.13.2 Basic Constructive Algorithms

- **ID:** `constructive_algorithms` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/constructive_algorithms
- **Resources (3):**
  - ★ [Constructive Algorithms | Percy Wong](https://assets.hkoi.org/training2019/cast.pdf)
  - [Tips on Constructive Algorithms By ReaLNero](https://codeforces.com/blog/entry/80317)
  - [Complete Constructive Problems Practice - Noob to Expert | Topic Stream 5 | Colin Galen](https://www.youtube.com/watch?v=3D3XKJonua0)
- **Problems (22):**
  - `[E]` ★ [Special Permutation](https://codeforces.com/problemset/problem/1454/A)
  - `[E]` ★ [EhAb AnD gCd](https://codeforces.com/problemset/problem/1325/A)
  - `[E]` ★ [Construct the String](https://codeforces.com/problemset/problem/1335/B)
  - `[E]` ★ [Permutations](https://cses.fi/problemset/task/1070)
  - `[E]` ★ [Lesha and array splitting](https://codeforces.com/problemset/problem/754/A)
  - `[E]` ★ [Palindrome Reorder](https://cses.fi/problemset/task/1755)
  - `[E]` [GCD vs LCM](https://codeforces.com/problemset/problem/1665/A)
  - `[E]` ★ [Unnatural Conditions](https://codeforces.com/contest/1028/problem/B)
  - `[E]` [K-divisible Sum](https://codeforces.com/problemset/problem/1476/A)
  - `[E]` [Shoe Shuffling](https://codeforces.com/contest/1691/problem/B)
  - `[E]` [Corrupted Array](https://codeforces.com/problemset/problem/1512/D)
  - `[E]` [Fun Permutation](https://codeforces.com/contest/2137/problem/B)
  - `[M]` [LCM Problem](https://codeforces.com/problemset/problem/1389/A)
  - `[M]` ★ [Two Sets](https://cses.fi/problemset/task/1092)
  - `[M]` ★ [A BIT of a Construction](https://codeforces.com/problemset/problem/1957/B)
  - `[M]` [k-LCM (hard version)](https://codeforces.com/problemset/problem/1497/C2)
  - `[M]` [Constructing the Array](https://codeforces.com/problemset/problem/1353/D)
  - `[M]` ★ [Ehab and Prefix MEXs](https://codeforces.com/problemset/problem/1364/C)
  - `[M]` ★ [Prefix Flip (Hard Version)](https://codeforces.com/problemset/problem/1381/A2)
  - `[M]` ★ [Multiples of Length](https://codeforces.com/problemset/problem/1396/A)
  - `[M]` [Manhattan Permutations](https://codeforces.com/contest/1978/problem/C)
  - `[H]` [Trip to the Olympiad](https://codeforces.com/contest/2057/problem/C)

### 1.14 2D Prefix Sum

**Subcategory ID:** `2d_prefix_sum` · **Topics:** 1

#### 1.14.1 2D Prefix Sum

- **ID:** `2d_prefix_sum` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_prefix_sum
- **Templates (1):**
  - [Prefix Sum 2D.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Prefix%20Sum%202D.cpp)
- **Resources (2):**
  - ★ [More on Prefix Sums | USACO Guide](https://usaco.guide/silver/more-prefix-sums?lang=cpp)
  - [Prefix Sum of Matrix (Or 2D Array) | Geeks for Geeks](https://www.geeksforgeeks.org/prefix-sum-2d-array/)
- **Problems (11):**
  - `[E]` ★ [Forest Queries](https://cses.fi/problemset/task/1652)
  - `[E]` ★ [range sum 2d](https://codeforces.com/group/c3FDl9EUi9/contest/262795/problem/G)
  - `[E]` ★ [Counting Rectangles](https://codeforces.com/contest/1722/problem/E)
  - `[E]` [Painting the Barn](https://vjudge.net/problem/USACO-919)
  - `[E]` [The Lazy Cow](https://vjudge.net/problem/USACO-416)
  - `[E]` [Matrix Block Sum](https://leetcode.com/problems/matrix-block-sum/description/)
  - `[M]` [Tic Tac Toe](https://www.codechef.com/LTIME97B/problems/TICTACTO)
  - `[M]` ★ [Beauty of the mountains](https://codeforces.com/contest/1982/problem/D)
  - `[M]` ★ [Counting Test](https://codeforces.com/gym/101532/problem/D)
  - `[H]` [Smilo and Minecraft](https://codeforces.com/contest/2113/problem/C)
  - `[VH]` [Hits Different](https://codeforces.com/contest/1829/problem/G)

### 1.15 More Techniques

**Subcategory ID:** `more_techniques` · **Topics:** 2

#### 1.15.1 Difference Array

- **ID:** `difference_array` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/difference_array
- **Resources (4):**
  - ★ [An Introduction To Difference Arrays By arujbansal](https://codeforces.com/blog/entry/78762)
  - [Understanding Difference Array: The Underrated Constant Time Range Update Algorithm (Part 1) | Ishank Katiyar](https://medium.com/@ishankkatiyar162/understanding-difference-array-the-underrated-constant-time-range-update-algorithm-part-1-e432ada7f1f5)
  - [Difference Array Technique | Tutorial | Range Updates | Competitive Programming Tricks Part 1](https://youtu.be/96RG7EBF8LI?si=oWJ5ZVhJ3u3XrzeK)
  - [Prefix Sums and Difference Array: 20 minutes of EVERYTHING you need to know by Algorithms with Shayan](https://youtu.be/DSQyjutKbfk?si=2a86zTgYKZbriv8F)
- **Problems (12):**
  - `[E]` ★ [Karen and Coffee](https://codeforces.com/contest/816/problem/B)
  - `[E]` ★ [Array Manipulation](https://www.hackerrank.com/challenges/crush/problem)
  - `[E]` ★ [Restaurant Customers](https://cses.fi/problemset/task/1619)
  - `[E]` ★ [Encrypting Messages](https://codeforces.com/contest/177/problem/D2)
  - `[E]` [Approximating a Constant Range](https://codeforces.com/contest/602/problem/B)
  - `[E]` [Substr Swap](https://atcoder.jp/contests/abc419/tasks/abc419_d)
  - `[M]` ★ [Greg and Array](https://codeforces.com/contest/296/problem/C)
  - `[M]` ★ [Little Girl and Maximum Sum](https://codeforces.com/contest/276/problem/C)
  - `[M]` [Turn Off The TV](https://codeforces.com/contest/863/problem/E)
  - `[M]` ★ [Cherry and Bits](https://www.codechef.com/CENS2020/problems/CENS20A)
  - `[M]` [Difference Array](https://vjudge.net/problem/CodeForces-1707B)
  - `[H]` [QED's Favorite Permutation](https://codeforces.com/contest/2030/problem/D)

#### 1.15.2 Sliding Window Technique

- **ID:** `sliding_window_technique` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/sliding_window_technique
- **Resources (2):**
  - ★ [Mastering Sliding Window Techniques | Ankit Singh](https://medium.com/@rishu__2701/mastering-sliding-window-techniques-48f819194fd7)
  - ★ [Sliding Window | USACO Guide](https://usaco.guide/gold/sliding-window?lang=cpp)
- **Problems (6):**
  - `[E]` ★ [Sliding Window Minimum](https://cses.fi/boi24/task/3221)
  - `[E]` [2^Sort](https://codeforces.com/problemset/problem/1692/G)
  - `[M]` ★ [Sliding Window Median](https://cses.fi/problemset/task/1076)
  - `[M]` ★ [Mex Min](https://atcoder.jp/contests/abc194/tasks/abc194_e)
  - `[H]` ★ [Deque-STL](https://vjudge.net/problem/HackerRank-deque-stl)
  - `[H]` [Tactical Removal](https://www.codechef.com/problems/P6172)

### 1.16 Bit Manipulation

**Subcategory ID:** `bit_manipulation` · **Topics:** 2

#### 1.16.1 Bit Manipulation

- **ID:** `bit_manipulation` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/bit_manipulation
- **Prerequisites:** Complete the Bitwise Operations and Bitmasks topic first.
- **Templates (1):**
  - [Bitwise Operations.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Bitwise%20Operations.cpp)
- **Resources (4):**
  - ★ [Bit manipulation | CP Algorithms](https://cp-algorithms.com/algebra/bit-manipulation.html)
  - ★ [Intro to Bitwise Operators | USACO Guide](https://usaco.guide/silver/intro-bitwise?lang=cpp)
  - [Some equations using bitwise operators! By srlabib](https://codeforces.com/blog/entry/94470)
  - [Bit Manipulation Playlist by Striver](https://www.youtube.com/playlist?list=PLgUwDviBIf0rnqh8QsJaHyIX7KUiaPUv7)
- **Problems (32):**
  - `[E]` ★ [Bits](https://codeforces.com/problemset/problem/484/A)
  - `[E]` ★ [XORwice](https://codeforces.com/problemset/problem/1421/A)
  - `[E]` ★ [Bitwise Operators](https://vjudge.net/problem/CodeChef-NXS2)
  - `[E]` ★ [And Then There Were K](https://codeforces.com/problemset/problem/1527/A)
  - `[E]` ★ [AND 0, Sum Big](https://codeforces.com/problemset/problem/1514/B)
  - `[E]` ★ [Bitwise Tuples](https://vjudge.net/problem/CodeChef-BITTUP)
  - `[E]` ★ [AND Sorting](https://vjudge.net/problem/CodeForces-1682B)
  - `[E]` ★ [Cat, Fox and the Lonely Array](https://codeforces.com/contest/1973/problem/B)
  - `[M]` ★ [XOR on Segment](https://codeforces.com/problemset/problem/242/E)
  - `[M]` ★ [Interesting Array](https://codeforces.com/contest/482/problem/B)
  - `[M]` ★ [Make It Beautiful](https://codeforces.com/contest/2118/problem/C)
  - `[M]` ★ [AND, OR and square sum](https://codeforces.com/problemset/problem/1368/D)
  - `[M]` ★ [Red Scarf](https://vjudge.net/problem/AtCoder-abc171_e)
  - `[M]` ★ [Sum vs XOR](https://vjudge.net/problem/HackerRank-sum-vs-xor)
  - `[M]` ★ [The Great XOR](https://vjudge.net/problem/HackerRank-the-great-xor)
  - `[M]` [Turtle and an Infinite Sequence](https://codeforces.com/problemset/problem/1981/B)
  - `[M]` ★ [MEXor Mixup](https://codeforces.com/problemset/problem/1567/B)
  - `[M]` ★ [Rock and Lever](https://codeforces.com/problemset/problem/1420/B)
  - `[M]` ★ [Johnny and His Hobbies](https://codeforces.com/problemset/problem/1362/B)
  - `[M]` ★ [And It's Non-Zero](https://codeforces.com/problemset/problem/1615/B)
  - `[M]` ★ [Powers Of Two](https://codeforces.com/problemset/problem/1095/C)
  - `[M]` [Make Good](https://codeforces.com/problemset/problem/1270/C)
  - `[M]` ★ [Xor Sum 4](https://vjudge.net/problem/AtCoder-abc147_d)
  - `[M]` ★ [AND Sequences](https://codeforces.com/problemset/problem/1513/B)
  - `[M]` ★ [Ehab the Xorcist](https://codeforces.com/problemset/problem/1325/D)
  - `[M]` [Dima and a Bad XOR](https://codeforces.com/problemset/problem/1151/B)
  - `[M]` ★ [The Wu](https://codeforces.com/contest/1017/problem/D)
  - `[M]` ★ [Sum of XOR Functions](https://codeforces.com/contest/1879/problem/D)
  - `[M]` [Take a Guess](https://codeforces.com/problemset/problem/1556/D)
  - `[M]` [Prime XOR Coloring](https://codeforces.com/contest/1991/problem/D)
  - `[M]` [Boneca Ambalabu](https://codeforces.com/contest/2094/problem/E)
  - `[H]` ★ [Queries](https://codeforces.com/gym/100739/problem/A)

#### 1.16.2 The XOR Trick

- **ID:** `the_xor_trick` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/the_xor_trick
- **Resources (1):**
  - ★ [That XOR Trick | florian](https://florian.github.io//xor-trick/)
- **Problems (4):**
  - `[E]` [Lonely Integer](https://vjudge.net/problem/HackerRank-ctci-lonely-integer)
  - `[E]` ★ [Missing Number](https://cses.fi/problemset/task/1083)
  - `[M]` ★ [Red Scarf](https://vjudge.net/problem/AtCoder-abc171_e)
  - `[M]` [Data Structures Fan](https://codeforces.com/contest/1872/problem/E)

### 1.17 Basic Modular Arithmetic

**Subcategory ID:** `modular_arithmetic` · **Topics:** 2

#### 1.17.1 Binary Exponentiation and Basic Modular Arithmetic

- **ID:** `binary_exponentiation` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/binary_exponentiation
- **Templates (1):**
  - [Binary Exponentiation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Binary%20Exponentiation.cpp)
- **Resources (4):**
  - ★ [Computations Modulo P in Competitive Programming | Errichto](https://www.youtube.com/watch?v=-OPohCQqi_E)
  - ★ [Modular Arithmetic for Beginners By Spheniscine](https://codeforces.com/blog/entry/72527)
  - ★ [Binary Exponentiation | CP Algorithms](https://cp-algorithms.com/algebra/binary-exp.html)
  - [Modular Arithmetic | USACO Guide](https://usaco.guide/gold/modular?lang=cpp)
- **Problems (14):**
  - `[E]` ★ [Exponentiation](https://cses.fi/problemset/task/1095)
  - `[E]` [MODEX](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3671)
  - `[E]` [Big Mod](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310)
  - `[E]` ★ [The last digit](https://www.spoj.com/problems/LASTDIG/)
  - `[E]` ★ [Count Good Numbers](https://leetcode.com/problems/count-good-numbers/description/)
  - `[E]` [Tiles](https://codeforces.com/contest/1178/problem/C)
  - `[E]` ★ [Just Add It](https://www.spoj.com/problems/ZSUM/)
  - `[E]` ★ [Modular Exponentiation](https://vjudge.net/problem/CodeForces-913A)
  - `[E]` ★ [Factorial Under Modulo](https://vjudge.net/problem/Gym-248968S)
  - `[E]` [Kaosar loves Polynomials](https://codeforces.com/gym/105767/problem/C)
  - `[M]` ★ [Leading and Trailing](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1970)
  - `[M]` ★ [Chef and Riffles](https://www.codechef.com/JAN221B/problems/RIFFLES)
  - `[M]` [Kill Demodogs](https://codeforces.com/problemset/problem/1731/B)
  - `[H]` ★ [Magic of the locker](https://www.spoj.com/problems/LOCKER/)

#### 1.17.2 Fermat's Little Theorem and Modular Inverse

- **ID:** `fermats_little_theorem` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/fermats_little_theorem
- **Resources (3):**
  - [Fermat's little theorem | Wiki](https://en.wikipedia.org/wiki/Fermat's_little_theorem)
  - ★ [Proof of Fermat's Little Theorem By Chris Caldwell](https://t5k.org/notes/proofs/FermatsLittleTheorem.html)
  - ★ [Modular Multiplicative Inverse | forthright48](https://forthright48.com/modular-multiplicative-inverse/)
- **Problems (2):**
  - `[E]` ★ [Modular division](https://vjudge.net/problem/EOlymp-9606)
  - `[E]` ★ [Exponentiation II](https://cses.fi/problemset/task/1712)

### 1.18 Basic Counting

**Subcategory ID:** `basic_counting` · **Topics:** 3

#### 1.18.1 Permutations, Combinations and Basic Counting Problems

- **ID:** `permutations_and_combinations` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/permutations_and_combinations
- **Templates (1):**
  - [Binomial Coefficients.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Basics/Binomial%20Coefficients.cpp)
- **Resources (4):**
  - ★ [14.2 Counting with Permutations and Combinations](https://flexbooks.ck12.org/cbook/ck-12-college-precalculus/section/14.2/primary/lesson/counting-with-permutations-and-combinations-c-precalc/)
  - [Discrete Math II/Combinatorics (Entire course) | Playlist by Kimberly Brehm](https://www.youtube.com/playlist?list=PLl-gb0E4MII0sGLCJeqDB3y63HZ6lM5LJ)
  - [Combinatorics | USACO Guide](https://usaco.guide/gold/combo?lang=cpp)
  - [Binomial Coefficients | CP Algorithms](https://cp-algorithms.com/combinatorics/binomial-coefficients.html)
- **Problems (20):**
  - `[E]` ★ [Bit Strings](https://cses.fi/problemset/task/1617)
  - `[E]` ★ [Binomial Coefficients](https://cses.fi/problemset/task/1079)
  - `[E]` ★ [Creating Strings II](https://cses.fi/problemset/task/1715)
  - `[E]` ★ [Distributing Apples](https://cses.fi/problemset/task/1716)
  - `[E]` ★ [Beautiful Numbers](https://codeforces.com/contest/300/problem/C)
  - `[E]` ★ [Two Knights](https://cses.fi/problemset/task/1072)
  - `[E]` [Card Game](https://www.spoj.com/problems/HC12/)
  - `[E]` [Number of Ways](https://www.codechef.com/LTIME24/problems/NWAYS/)
  - `[E]` [Hossam and Combinatorics](https://codeforces.com/problemset/problem/1771/A)
  - `[E]` ★ [Sherlock and Permutations](https://www.hackerrank.com/challenges/sherlock-and-permutations/problem)
  - `[M]` [Ada and Teams](https://www.spoj.com/problems/ADATEAMS/)
  - `[M]` [Good Predictions](https://www.spoj.com/problems/GOODB/)
  - `[M]` [How Does the Rook Move?](https://codeforces.com/problemset/problem/1957/C)
  - `[M]` ★ [Battling with Numbers](https://codeforces.com/problemset/problem/1866/B)
  - `[M]` ★ [Advertising Agency](https://codeforces.com/contest/1475/problem/E)
  - `[M]` [Merging the Sets](https://codeforces.com/problemset/problem/2146/B)
  - `[M]` [Make it Alternating](https://codeforces.com/contest/1879/problem/C)
  - `[H]` [Curious Array](https://codeforces.com/problemset/problem/407/C)
  - `[H]` [Placing Jinas](https://codeforces.com/problemset/problem/1696/E)
  - `[H]` ★ [Selection Sort Count](https://vjudge.net/problem/Gym-103860C)

#### 1.18.2 Stars and Bars

- **ID:** `stars_and_bars` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/stars_and_bars
- **Resources (2):**
  - ★ [Stars and bars | CP Algorithms](https://cp-algorithms.com/combinatorics/stars_and_bars.html)
  - [Stars and Bars (and bagels) - Numberphile](https://www.youtube.com/watch?v=UTCScjoPymA)
- **Problems (10):**
  - `[E]` ★ [Problem Makes Problem](https://lightoj.com/problem/problem-makes-problem)
  - `[E]` ★ [Array](https://codeforces.com/contest/57/problem/C)
  - `[E]` ★ [Kyoya and Colored Balls](https://codeforces.com/problemset/problem/553/A)
  - `[E]` ★ [Distributing Apples](https://cses.fi/problemset/task/1716)
  - `[M]` ★ [Greedy Walking](https://www.spoj.com/problems/UCV2013E/)
  - `[M]` ★ [Two Arrays](https://codeforces.com/problemset/problem/1288/C)
  - `[M]` [Marbles](https://www.spoj.com/problems/MARBLES/)
  - `[M]` [One-Dimensional Puzzle](https://codeforces.com/contest/1931/problem/G)
  - `[H]` ★ [Roaming](https://atcoder.jp/contests/abc156/tasks/abc156_e)
  - `[H]` ★ [Factorization](https://atcoder.jp/contests/abc110/tasks/abc110_d)

#### 1.18.3 Pigeonhole Principle

- **ID:** `pigeonhole_principle` · **Difficulty:** Very Easy · **Importance:** ★★☆ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/pigeonhole_principle
- **Resources (3):**
  - ★ [Pigeonhole Principle | Geeks for Geeks](https://www.geeksforgeeks.org/discrete-mathematics-the-pigeonhole-principle/)
  - [What Is the Pigeonhole Principle? | Spanning Tree](https://www.youtube.com/watch?v=B2A2pGrDG8I)
  - [Pigeonhole Principle | Brilliant](https://brilliant.org/wiki/pigeonhole-principle-definition/)
- **Problems (8):**
  - `[E]` ★ [Kuroni and Impossible Calculation](https://codeforces.com/problemset/problem/1305/C)
  - `[E]` ★ [Funny Game](https://codeforces.com/contest/1994/problem/D)
  - `[M]` ★ [Halloween treats](https://www.spoj.com/problems/HALLOW/)
  - `[M]` ★ [Going Home](https://codeforces.com/problemset/problem/1501/C)
  - `[M]` [Prinzessin der Verurteilung](https://codeforces.com/contest/1536/problem/B)
  - `[M]` ★ [XOR This OR That](https://codeforces.com/gym/105884/problem/I)
  - `[M]` ★ [Modulo Sum](https://codeforces.com/problemset/problem/577/B)
  - `[M]` [Palindrome](https://codeforces.com/contest/335/problem/B)

### 1.19 Very Basic Graphs

**Subcategory ID:** `very_basic_graphs` · **Topics:** 1

#### 1.19.1 Introduction to Graphs | Definitions and Representations

- **ID:** `graph_representations` · **Difficulty:** Very Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/graph_representations
- **Resources (11):**
  - ★ [A Gentle Introduction To Graph Theory | Vaidehi Joshi](https://medium.com/basecs/a-gentle-introduction-to-graph-theory-77969829ead8)
  - [Introduction to Graph Theory: A Computer Science Perspective | Reducible](https://www.youtube.com/watch?v=LFKZLXVO-Dg)
  - ★ [Graph Theory Introduction WilliamFiset](https://www.youtube.com/watch?v=eQA-m22wjTQ)
  - ★ [Chapter 11 Basics of graphs | CPH](https://usaco.guide/CPH.pdf#page=119)
  - [Introduction to graph theory | CSAcademy](https://csacademy.com/lesson/introduction_to_graphs)
  - [Graph representation | CSAcademy](https://csacademy.com/lesson/graph_representation)
  - [Graph Representation | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/graph-representation/tutorial/)
  - [গ্রাফ থিওরিতে হাতেখড়ি – ১ | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=143)
  - [গ্রাফ থিওরিতে হাতেখড়ি – ২ (ভ্যারিয়েবলে গ্রাফ স্টোর-১) | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=184)
  - [গ্রাফ থিওরিতে হাতেখড়ি – ৩ (ভ্যারিয়েবলে গ্রাফ স্টোর-২) | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=211)
  - [Introduction to Graphs | USACO Guide](https://usaco.guide/bronze/intro-graphs?lang=cpp)
- **Problems (5):**
  - `[E]` ★ [Graph](https://vjudge.net/problem/Aizu-ALDS1_11_A)
  - `[E]` ★ [Network Topology](https://codeforces.com/problemset/problem/292/B?locale=en)
  - `[E]` [Find Center of Star Graph](https://leetcode.com/problems/find-center-of-star-graph/description/)
  - `[E]` [Minimum Number of Vertices to Reach All Nodes](https://leetcode.com/problems/minimum-number-of-vertices-to-reach-all-nodes/description/)
  - `[M]` [Road Construction](https://codeforces.com/problemset/problem/330/B)

---

## 2. Data Structures (DS)

**Category ID:** `data_structures` · **Subcategories:** 18 · **Topics:** 82

### 2.1 Segment Tree

**Subcategory ID:** `segment_tree` · **Topics:** 13

#### 2.1.1 Segment Tree (Point Update Range Query)

- **ID:** `segment_tree` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/segment_tree
- **Templates (1):**
  - [Segment Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree.cpp)
- **Resources (3):**
  - ★ [Segment Tree Part 1 | CF EDU](https://codeforces.com/edu/course/2/lesson/4)
  - ★ [Segment Trees | CS Academy](https://csacademy.com/lesson/segment_trees)
  - ★ [Simplest form of a Segment Tree and some variations | CP Algorithms](https://cp-algorithms.com/data_structures/segment_tree.html)
- **Problems (38):**
  - `[E]` ★ [Segment Tree for the Sum](https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/A)
  - `[E]` ★ [Segment Tree for the Minimum](https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/B)
  - `[E]` ★ [Number of Minimums on a Segment](https://codeforces.com/edu/course/2/lesson/4/1/practice/contest/273169/problem/C)
  - `[E]` ★ [Inversions](https://codeforces.com/edu/course/2/lesson/4/3/practice/contest/274545/problem/A)
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` [Enemy is weak](https://codeforces.com/contest/61/problem/E)
  - `[E]` [Mega Inversions](https://vjudge.net/problem/Kattis-megainversions)
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[E]` [Pashmak and Parmida's problem](https://codeforces.com/contest/459/problem/D)
  - `[E]` ★ [Legacy](https://codeforces.com/contest/786/problem/B)
  - `[E]` ★ [Second Largest Query](https://atcoder.jp/contests/abc343/tasks/abc343_f)
  - `[M]` [Number of Inversions on Segment](https://codeforces.com/edu/course/2/lesson/4/4/practice/contest/274684/problem/C)
  - `[M]` ★ [Add Arithmetic Progression On Segment](https://codeforces.com/edu/course/2/lesson/5/4/practice/contest/280801/problem/B)
  - `[M]` ★ [Distinct Characters Queries](https://codeforces.com/problemset/problem/1234/D)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` [Xenia and Bit Operations](https://codeforces.com/problemset/problem/339/D)
  - `[M]` ★ [Sereja and Brackets](https://codeforces.com/contest/380/problem/C)
  - `[M]` [Points](https://codeforces.com/contest/19/problem/D)
  - `[M]` ★ [Ant colony](https://codeforces.com/contest/474/problem/F)
  - `[M]` ★ [Interesting Array](https://codeforces.com/contest/482/problem/B)
  - `[M]` [Infinite Inversions](https://codeforces.com/contest/540/problem/E)
  - `[M]` ★ [Subsequences](https://codeforces.com/contest/597/problem/C)
  - `[M]` ★ [SUM and REPLACE](https://codeforces.com/problemset/problem/920/F)
  - `[M]` [Hotel Queries](https://cses.fi/problemset/task/1143)
  - `[M]` ★ [Increasing subsequence II](https://cses.fi/problemset/task/1748)
  - `[M]` [List Removals](https://cses.fi/problemset/task/1749/)
  - `[M]` ★ [On Changing Tree](https://codeforces.com/contest/396/problem/C)
  - `[M]` ★ [Yaroslav and Divisors](https://codeforces.com/contest/301/problem/D)
  - `[M]` [Propagating tree](https://codeforces.com/contest/383/problem/C)
  - `[M]` [Bash and a Tough Math Puzzle](https://codeforces.com/problemset/problem/914/D)
  - `[M]` ★ [Alternating String](https://atcoder.jp/contests/abc341/tasks/abc341_e)
  - `[M]` [Ksyusha and the Loaded Set](https://codeforces.com/contest/2000/problem/H)
  - `[M]` ★ [Max GEQ Sum](https://codeforces.com/problemset/problem/1691/D)
  - `[H]` ★ [Can you answer these queries III](https://www.spoj.com/problems/GSS3/)
  - `[H]` ★ [REQ](https://codeforces.com/contest/594/problem/D)
  - `[H]` [Misha and Permutations Summation](https://codeforces.com/contest/501/problem/D)
  - `[H]` [Linear Kingdom Races](https://codeforces.com/contest/115/problem/E)
  - `[H]` [Incessant Rain](https://codeforces.com/contest/2117/problem/H)

#### 2.1.2 Segment Tree with Lazy Propagation

- **ID:** `segment_tree_with_lazy_propagation` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/segment_tree_with_lazy_propagation
- **Templates (1):**
  - [Segment Tree Lazy.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20Lazy.cpp)
- **Resources (2):**
  - ★ [Segment Tree Part 2 | CF EDU](https://codeforces.com/edu/course/2/lesson/5)
  - ★ [Range updates (Lazy Propagation) | CP Algorithms](https://cp-algorithms.com/data_structures/segment_tree.html#range-updates-lazy-propagation)
- **Problems (32):**
  - `[E]` ★ [Addition and Sum](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/D)
  - `[E]` ★ [Addition and Minimum](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/A)
  - `[E]` [Circular RMQ](https://codeforces.com/problemset/problem/52/C)
  - `[E]` [Multiplication and Sum](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/B)
  - `[E]` ★ [Assignment and Sum](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/F)
  - `[E]` [Prefix Sum Queries](https://cses.fi/problemset/task/2166)
  - `[E]` ★ [The Child and Sequence](https://codeforces.com/contest/438/problem/D)
  - `[E]` ★ [Two Sequence Queries](https://atcoder.jp/contests/abc357/tasks/abc357_f)
  - `[E]` [Range Update Point Query](https://codeforces.com/contest/1791/problem/F)
  - `[M]` ★ [Range Updates and Sums](https://cses.fi/problemset/task/1735)
  - `[M]` ★ [Range Affine Range Sum](https://judge.yosupo.jp/problem/range_affine_range_sum)
  - `[M]` ★ [Bitwise OR and AND](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/C)
  - `[M]` ★ [Inverse and K-th one](https://codeforces.com/edu/course/2/lesson/5/3/practice/contest/280799/problem/B)
  - `[M]` [Addition and First element at least X](https://codeforces.com/edu/course/2/lesson/5/3/practice/contest/280799/problem/C)
  - `[M]` [Assignment and Maximal Segment](https://codeforces.com/edu/course/2/lesson/5/3/practice/contest/280799/problem/A)
  - `[M]` [Kefa and Watch](https://codeforces.com/problemset/problem/580/E)
  - `[M]` ★ [A Simple Task](https://codeforces.com/problemset/problem/558/E)
  - `[M]` ★ [XOR on Segment](https://codeforces.com/problemset/problem/242/E)
  - `[M]` ★ [Polynomial Queries](https://cses.fi/problemset/task/1736)
  - `[M]` [Lucky Queries](https://codeforces.com/contest/145/problem/E)
  - `[M]` [Boring Segments](https://codeforces.com/contest/1555/problem/E)
  - `[M]` [Random Update Query](https://atcoder.jp/contests/abc332/tasks/abc332_f)
  - `[M]` [MEX Queries](https://codeforces.com/problemset/problem/817/F)
  - `[M]` [Diverging Directions](https://codeforces.com/contest/838/problem/B)
  - `[H]` [DZY Loves Fibonacci Numbers](https://codeforces.com/contest/446/problem/C)
  - `[H]` ★ [Please, another Queries on Array?](https://codeforces.com/problemset/problem/1114/F)
  - `[H]` [Linear Kingdom Races](https://codeforces.com/contest/115/problem/E)
  - `[H]` ★ [Queries](https://codeforces.com/gym/100739/problem/A)
  - `[H]` [Greedy Subsequences](https://codeforces.com/contest/1132/problem/G)
  - `[H]` [Addition Robot](https://codeforces.com/problemset/problem/1252/K)
  - `[H]` [Wine Factory (Easy Version)](https://codeforces.com/problemset/problem/1919/F1)
  - `[H]` [Serge and Dining Room](https://codeforces.com/contest/1179/problem/C)

#### 2.1.3 Persistent Segment Tree

- **ID:** `persistent_segment_tree` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_segment_tree
- **Templates (1):**
  - [Segment Tree Persistent.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20Persistent.cpp)
- **Resources (3):**
  - ★ [Persistent Segment Tree by Oliver-Matis Lill](https://drive.google.com/file/d/0BwGLW04WRv0ITEZjRWlMSFc2bk0/view?resourcekey=0-1Zvsu-oMrdNsCuCIU3xGNA)
  - ★ [Persistent Segment Tree | CP Algorithms](https://cp-algorithms.com/data_structures/segment_tree.html#preserving-the-history-of-its-values-persistent-segment-tree)
  - [Persistence Made Simple by hikarico](https://discuss.codechef.com/t/persistence-made-simple-tutorial/14915/5)
- **Problems (24):**
  - `[E]` ★ [Range Queries and Copies](https://cses.fi/problemset/task/1737)
  - `[E]` ★ [K-Query Online](https://www.spoj.com/problems/KQUERYO/)
  - `[E]` ★ [K-th Number](https://www.spoj.com/problems/MKTHNUM/)
  - `[E]` [Kth Number](https://www.hackerrank.com/contests/morgan-stanley-2015/challenges/wet-shark-and-kth-largest-number)
  - `[E]` ★ [To the moon](https://www.spoj.com/problems/TTM/)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` ★ [Till I Collapse](https://codeforces.com/contest/786/problem/C)
  - `[M]` [Functions On The Segments](https://codeforces.com/problemset/problem/837/G)
  - `[M]` ★ [Sign on Fence](https://codeforces.com/contest/484/problem/E)
  - `[M]` ★ [Count on a tree](https://www.spoj.com/problems/COT/)
  - `[M]` [Forbidden Sum](https://www.codechef.com/problems/FRBSUM)
  - `[M]` [Chef and Prime Queries](https://www.codechef.com/problems/PRMQ)
  - `[M]` ★ [Hossam and Range Minimum Query](https://codeforces.com/contest/1771/problem/F)
  - `[M]` ★ [Smaller Sum](https://atcoder.jp/contests/abc339/tasks/abc339_g)
  - `[M]` [Army Creation](https://codeforces.com/contest/813/problem/E)
  - `[M]` ★ [One Occurrence](https://codeforces.com/contest/1000/problem/F)
  - `[M]` [G2. Big Wins! (hard version)](https://codeforces.com/contest/2126/problem/G2)
  - `[H]` ★ [Boring Queries](https://codeforces.com/contest/1422/problem/F)
  - `[H]` ★ [Function! Not Again!!](https://lightoj.com/problem/function-not-again)
  - `[H]` ★ [Cloning](https://www.codechef.com/problems/CLONEME)
  - `[H]` ★ [The Classic Problem](https://codeforces.com/contest/464/problem/E)
  - `[H]` ★ [Frequency Mismatch (Hard Version)](https://codeforces.com/contest/1957/problem/F2)
  - `[H]` [Odd Mineral Resource](https://codeforces.com/contest/1479/problem/D)
  - `[VH]` [Noble Knight's Path](https://codeforces.com/contest/226/problem/E)

#### 2.1.4 Persistent Segment Tree with Lazy Propagation

- **ID:** `persistent_segment_tree_with_lazy_propagation` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_segment_tree_with_lazy_propagation
- **Templates (1):**
  - [Segment Tree Persistent Lazy.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20Persistent%20Lazy.cpp)
- **Resources (1):**
  - ★ [Persistence Made Simple - Persistent Lazy Propagation by hikarico](https://discuss.codechef.com/t/persistence-made-simple-tutorial/14915/11)
- **Problems (4):**
  - `[E]` ★ [To the moon](https://www.spoj.com/problems/TTM/)
  - `[M]` [Observing the Tree](https://www.codechef.com/problems/QUERY)
  - `[H]` [SubInversing](https://www.codechef.com/problems/SUBINVER)
  - `[VH]` [Fibonacci Numbers on Tree](https://www.codechef.com/problems/FIBTREE)

#### 2.1.5 2D Segment Tree

- **ID:** `2d_segment_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_segment_tree
- **Resources (3):**
  - ★ [Generalization to higher dimensions | CP Algorithms](https://cp-algorithms.com/data_structures/segment_tree.html#generalization-to-higher-dimensions)
  - [2D segment Tree by papa-ka-para](https://www.youtube.com/watch?v=kKlZ9B3cS14)
  - [2D Segment Tree | Pavel Mavrin (Pashka)](https://www.youtube.com/watch?v=_zYMsx4iOSc&list=PLrS21S1jm43igE57Ye_edwds_iL7ZOAG4&index=21)
- **Problems (9):**
  - `[E]` ★ [Forest Queries II](https://cses.fi/problemset/task/1739)
  - `[E]` ★ [Vanya and Treasure](https://codeforces.com/contest/677/problem/D)
  - `[E]` ★ [Rectangle Sum](https://judge.yosupo.jp/problem/rectangle_sum)
  - `[E]` ★ [Point Add Rectangle Sum](https://judge.yosupo.jp/problem/point_add_rectangle_sum)
  - `[M]` ★ [Map](https://codeforces.com/contest/15/problem/D)
  - `[H]` ★ [The Ultimate Bamboo Eater](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3226)
  - `[H]` ★ [The Untended Antiquity](https://codeforces.com/problemset/problem/869/E)
  - `[H]` ★ [Games](https://oj.uz/problem/view/IOI13_game)
  - `[VH]` [Pairs](https://oj.uz/problem/view/IOI07_pairs)

#### 2.1.6 Dynamic Segment Tree

- **ID:** `dynamic_segment_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_segment_tree
- **Resources (3):**
  - ★ [Dynamic Segment Tree | CP Algorithms](https://cp-algorithms.com/data_structures/segment_tree.html#dynamic-segment-tree)
  - ★ [Sparse Segment Trees | USACO Guide](https://usaco.guide/plat/sparse-segtree?lang=cpp)
  - [Dynamic Segment Trees : Online Queries for Range Sum with Point Updates | Geeks for Geeks](https://www.geeksforgeeks.org/dynamic-segment-trees-online-queries-for-range-sum-with-point-updates/)
- **Problems (5):**
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` ★ [Monkey and Apple-trees](https://oj.uz/problem/view/IZhO12_apple)
  - `[M]` [Game of Pieces](https://codeforces.com/gym/105789/problem/G)

#### 2.1.7 2D Dynamic Segment Tree

- **ID:** `2d_dynamic_segment_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_dynamic_segment_tree
- **Templates (1):**
  - [Segment Tree 2D Dynamic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%202D%20Dynamic.cpp)
- **Resources (1):**
  - [IOI 2013 - Game Solution | USACO Guide](https://usaco.guide/problems/ioi-2013game/solution)
- **Problems (1):**
  - `[H]` ★ [Games](https://oj.uz/problem/view/IOI13_game)

#### 2.1.8 Merge Sort Tree

- **ID:** `merge_sort_tree` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/merge_sort_tree
- **Templates (1):**
  - [122263](https://codeforces.com/blog/entry/122263)
- **Resources (3):**
  - ★ [Merge Sort Tree - Tutorial | arunnsit](https://discuss.codechef.com/t/merge-sort-tree-tutorial/14277/1)
  - ★ [Merge Sort Tree (and similar stuff) | By Abito](https://codeforces.com/blog/entry/122263)
  - [Point Updates in Merge Sort Trees By suvro_coder](https://codeforces.com/blog/entry/75304)
- **Problems (5):**
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[E]` ★ [Valera and Queries](https://codeforces.com/contest/369/problem/E)
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` ★ [Range Kth Smallest](https://judge.yosupo.jp/problem/range_kth_smallest)
  - `[M]` ★ [Smaller Sum](https://atcoder.jp/contests/abc339/tasks/abc339_g)

#### 2.1.9 Iterative Segment Tree

- **ID:** `iterative_segment_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/iterative_segment_tree
- **Templates (1):**
  - [Segment Tree NonRecursive.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20NonRecursive.cpp)
- **Resources (2):**
  - ★ [Efficient and easy segment trees](https://codeforces.com/blog/entry/18051)
  - [Sort before insert — A small extension to Merge sort tree By darkkcyan](https://codeforces.com/blog/entry/85513)

#### 2.1.10 Segment Tree Merging

- **ID:** `segment_tree_merging` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/segment_tree_merging
- **Templates (1):**
  - [Segment Tree Merging.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20Merging.cpp)
- **Resources (2):**
  - ★ [Segment Tree Merging | Yet Another Competitive Programming Blog](https://mzhang2021.github.io/cp-blog/segtree-merging/)
  - [using merging segment tree to solve problems about sorted list | TLE](https://codeforces.com/blog/entry/49446)
- **Problems (8):**
  - `[M]` ★ [Range Sort Query (Solve using Segment Tree Merging)](https://atcoder.jp/contests/abc237/tasks/abc237_g)
  - `[H]` [Task Tree Rotations (rot)](https://szkopul.edu.pl/problemset/problem/sUe3qzxBtasek-RAWmZaxY_p/site/?key=statement)
  - `[H]` ★ [Combat on a tree](https://www.spoj.com/problems/COT3/)
  - `[VH]` [Task Tree Rotations 2 (rod)](https://szkopul.edu.pl/problemset/problem/b0BM0al2crQBt6zovEtJfOc6/site/?key=statement)
  - `[VH]` ★ [Minimax](https://loj.ac/p/2537)
  - `[VH]` ★ [Phoenix and Bits](https://codeforces.com/contest/1515/problem/H)
  - `[VH]` [violent writing](https://loj.ac/p/2553)
  - `[VH]` [destiny](https://loj.ac/p/3340)

#### 2.1.11 Segment Tree Beats

- **ID:** `segment_tree_beats` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/segment_tree_beats
- **Templates (1):**
  - [Segment Tree Beats.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Segment%20Tree%20Beats.cpp)
- **Resources (4):**
  - ★ [Segment Tree Beats: Segment Tree On Steroids. Part 1 | peltorator](https://www.youtube.com/watch?v=NwkO73jGSPA)
  - ★ [A simple introduction to "Segment tree beats" | jiry_2](https://codeforces.com/blog/entry/57319)
  - [Segment tree beats | IOI preparation #6 | Errichto](https://www.youtube.com/watch?v=wFqKgrW1IMQ)
  - [AlgorithmsThread 4: Segment Tree Beats](https://www.youtube.com/watch?v=_TGNYtkWAsQ)
- **Problems (18):**
  - `[E]` ★ [The Child and Sequence](https://codeforces.com/contest/438/problem/D)
  - `[E]` [Gorgeous Sequence](http://acm.hdu.edu.cn/showproblem.php?pid=5306)
  - `[E]` ★ [Minimize!](https://codeforces.com/group/1rv4rhCsHp/contest/327313/problem/B)
  - `[E]` ★ [Minimize, add!](https://codeforces.com/group/1rv4rhCsHp/contest/327313/problem/D)
  - `[M]` [I like Query Problem](https://atcoder.jp/contests/abc256/tasks/abc256_h)
  - `[M]` ★ [Range Chmin Chmax Add Range Sum](https://judge.yosupo.jp/problem/range_chmin_chmax_add_range_sum)
  - `[M]` ★ [And or Max](https://csacademy.com/contest/round-70/task/and-or-max)
  - `[M]` [Bear and Bad Powers of 42](https://codeforces.com/contest/679/problem/E)
  - `[M]` [Little Pony and Lord Tirek](https://codeforces.com/problemset/problem/453/E)
  - `[M]` [Julia the snail](https://codeforces.com/problemset/problem/793/F)
  - `[M]` [Nagini](https://codeforces.com/contest/855/problem/F)
  - `[M]` [Box Operations](https://www.hackerrank.com/challenges/box-operations/problem)
  - `[M]` ★ [Good Subsegments](https://codeforces.com/contest/997/problem/E)
  - `[H]` [Minimize, add, GCDize and their friends](https://codeforces.com/group/1rv4rhCsHp/contest/327313/problem/E)
  - `[H]` ★ [New Year’s Day Old Man and Sequence](https://uoj.ac/problem/169)
  - `[H]` [Stations](https://codeforces.com/contest/1572/problem/F)
  - `[H]` [Overflow](https://dmoj.ca/problem/olep1)
  - `[VH]` [Tsinghua Training Camp 2015V](https://uoj.ac/problem/164)

#### 2.1.12 XOR Segment Tree

- **ID:** `xor_segment_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/xor_segment_tree
- **Templates (1):**
  - [XOR Segment Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/XOR%20Segment%20Tree.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] XOR Segment Tree | PurpleCrayon](https://codeforces.com/blog/entry/105723)
- **Problems (5):**
  - `[E]` ★ [xor^2](https://www.acmicpc.net/problem/24271)
  - `[E]` ★ [Swap and Maximum Block](https://codeforces.com/contest/1716/problem/E)
  - `[M]` ★ [Static Xor Range Composite Query](https://yukicoder.me/problems/no/1891)
  - `[M]` [Minimal String Xoration](https://codeforces.com/contest/1654/problem/F)
  - `[M]` [Reverse and Swap](https://codeforces.com/contest/1401/problem/F)

#### 2.1.13 Historic Information on Segment Trees

- **ID:** `historic_information_on_segment_trees` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/historic_information_on_segment_trees
- **Prerequisites:** Segment Tree Beats
- **Resources (3):**
  - ★ [Historic Information on Segment Trees | mzhang2021](https://mzhang2021.github.io/cp-blog/historic-segtree/)
  - ★ [A simple introduction to "Segment tree beats" By jiry_2](https://codeforces.com/blog/entry/57319)
  - ★ [\[Tutorial\] A Bit of Math, Historic Sum, and Range Add Range Sum Binary Indexed Tree (Fenwick Tree) By FHVirus](https://codeforces.com/blog/entry/99895)
- **Problems (2):**
  - `[H]` [Paimon Segment Tree](https://codeforces.com/gym/103470/problem/E)
  - `[VH]` [Tsinghua Training Camp 2015V](https://uoj.ac/problem/164)

### 2.2 Binary Indexed Tree (BIT)

**Subcategory ID:** `binary_indexed_tree` · **Topics:** 5

#### 2.2.1 BIT / Fenwick Tree

- **ID:** `bit` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/bit
- **Templates (1):**
  - [BIT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/BIT.cpp)
- **Resources (5):**
  - ★ [Fenwick Tree | CP Algorithms](https://cp-algorithms.com/data_structures/fenwick.html)
  - [BINARY INDEXED TREES | Topcoder](https://www.topcoder.com/community/data-science/data-science-tutorials/binary-indexed-trees/)
  - [Fenwick Tree | CS Academy](https://csacademy.com/lesson/fenwick_trees)
  - [Fenwick Trees | Algorithms Live!](https://www.youtube.com/watch?v=kPaJfAUwViY)
  - [Fenwick Tree | Pavel Mavrin (Pashka)](https://www.youtube.com/watch?v=Ti_U3Q_G7yM&list=PLrS21S1jm43igE57Ye_edwds_iL7ZOAG4&index=20)
- **Problems (22):**
  - `[E]` ★ [Curious Robin Hood](https://lightoj.com/problem/curious-robin-hood)
  - `[E]` ★ [Range Update Queries](https://cses.fi/problemset/task/1651)
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` ★ [Inversions](https://codeforces.com/edu/course/2/lesson/4/3/practice/contest/274545/problem/A)
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[E]` [Mega Inversions](https://vjudge.net/problem/Kattis-megainversions)
  - `[E]` ★ [Crayon](https://www.spoj.com/problems/CRAYON/)
  - `[E]` [Pashmak and Parmida's problem](https://codeforces.com/contest/459/problem/D)
  - `[E]` [Enemy is weak](https://codeforces.com/contest/61/problem/E)
  - `[E]` [Tufurama](https://codeforces.com/contest/961/problem/E)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` [List Removals](https://cses.fi/problemset/task/1749/)
  - `[M]` [Number of Inversions on Segment](https://codeforces.com/edu/course/2/lesson/4/4/practice/contest/274684/problem/C)
  - `[M]` ★ [Distinct Characters Queries](https://codeforces.com/problemset/problem/1234/D)
  - `[M]` ★ [Ball](https://codeforces.com/contest/12/problem/D)
  - `[M]` ★ [SUM and REPLACE](https://codeforces.com/problemset/problem/920/F)
  - `[M]` ★ [Yaroslav and Divisors](https://codeforces.com/contest/301/problem/D)
  - `[M]` ★ [Increasing subsequence II](https://cses.fi/problemset/task/1748)
  - `[M]` ★ [Nested Ranges Count](https://cses.fi/problemset/task/2169)
  - `[M]` [Sum Over Zero](https://codeforces.com/contest/1788/problem/E)
  - `[H]` [Ada and Species](https://www.spoj.com/problems/ADACABAA/)
  - `[H]` ★ [REQ](https://codeforces.com/contest/594/problem/D)

#### 2.2.2 Lower bound on BIT

- **ID:** `lower_bound_on_bit` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lower_bound_on_bit
- **Templates (1):**
  - [61364#:~:text=an intuitive proof.-,Implementation,-:](https://codeforces.com/blog/entry/61364#:~:text=an%20intuitive%20proof.-,Implementation,-%3A)
- **Resources (1):**
  - ★ [\[Tutorial\] Searching Binary Indexed Tree in O(log(N)) using Binary Lifting](https://codeforces.com/blog/entry/61364)
- **Problems (5):**
  - `[E]` ★ [War Games 2.1](https://acm.timus.ru/problem.aspx?space=1&num=1896)
  - `[E]` [Multiset](https://codeforces.com/contest/1354/problem/D)
  - `[E]` [Order Statistic Set](https://www.spoj.com/problems/ORDERSET/en/)
  - `[E]` [Dynamic Collection](https://codeforces.com/gym/104375/problem/D)
  - `[M]` [Nastya and King-Shamans](https://codeforces.com/contest/992/problem/E)

#### 2.2.3 BIT with Range Update and Range Query

- **ID:** `bit_with_range_update_and_range_query` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bit_with_range_update_and_range_query
- **Templates (1):**
  - [BIT with Range Update and Range Query.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/BIT%20with%20Range%20Update%20and%20Range%20Query.cpp)
- **Resources (2):**
  - ★ [Range Updates and Range Queries | CP Algorithms](https://cp-algorithms.com/data_structures/fenwick.html#3-range-updates-and-range-queries)
  - [Fenwick tree range updates | Petr](https://blog.mitrichev.ch/2013/05/fenwick-tree-range-updates.html)
- **Problems (2):**
  - `[E]` ★ [Addition and Sum](https://codeforces.com/edu/course/2/lesson/5/2/practice/contest/279653/problem/D)
  - `[H]` ★ [Please, another Queries on Array?](https://codeforces.com/problemset/problem/1114/F)

#### 2.2.4 2D BIT

- **ID:** `2d_bit` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_bit
- **Resources (4):**
  - ★ [BINARY INDEXED TREES | Topcoder](https://www.topcoder.com/thrive/articles/Binary%20Indexed%20Trees#2d)
  - [Finding sum in two-dimensional array | CP Algorithms](https://cp-algorithms.com/data_structures/fenwick.html#finding-sum-in-two-dimensional-array)
  - ★ [Easy implementation of Compressed 2D Binary Indexed Tree for grid of binary numbers\[Tutorial\]](https://codeforces.com/blog/entry/52094)
  - ★ [2D BIT | USACO Guide](https://usaco.guide/plat/2DRQ?lang=cpp#2d-bit)
- **Problems (10):**
  - `[E]` ★ [Forest Queries II](https://cses.fi/problemset/task/1739)
  - `[E]` [Mobile phones](http://poj.org/problem?id=1195)
  - `[E]` [Points in Rectangle](https://lightoj.com/problem/points-in-rectangle)
  - `[M]` ★ [Anton and Permutation](https://codeforces.com/contest/785/problem/E)
  - `[M]` ★ [Counting In Byteland (3D)](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/practice-problems/algorithm/counting-in-byteland/)
  - `[M]` [Intersection of Permutations](https://codeforces.com/contest/1093/problem/E)
  - `[M]` [A. Boring Class](https://codeforces.com/gym/105190/problem/A)
  - `[H]` [Crowded Cities](https://dmoj.ca/problem/bfs17p6)
  - `[H]` [Goodbye Souvenir](https://codeforces.com/contest/848/problem/C)
  - `[VH]` [Pairs](https://oj.uz/problem/view/IOI07_pairs)

#### 2.2.5 2D BIT with Range Update and Range Query

- **ID:** `2d_bit_with_range_update_and_range_query` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_bit_with_range_update_and_range_query
- **Templates (1):**
  - [BIT 2D with Range Update and Range Query.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/BIT%202D%20with%20Range%20Update%20and%20Range%20Query.cpp)
- **Resources (2):**
  - ★ [A bit more of general ideas By adamant](https://codeforces.com/blog/entry/104466)
  - [A New Algorithm for Updating and Querying Sub-arrays of Multidimensional Arrays | Paper](https://arxiv.org/pdf/1311.6093v4.pdf)
- **Problems (4):**
  - `[E]` ★ [Update Sub-Matrix & Query Sub-Matrix](https://www.spoj.com/problems/USUBQSUB/)
  - `[E]` [Чипполино](https://basecamp.eolymp.com/en/problems/4500)
  - `[H]` ★ [Iahub and Xors](https://codeforces.com/problemset/problem/341/D)
  - `[H]` ★ [The Untended Antiquity](https://codeforces.com/problemset/problem/869/E)

### 2.3 Sparse Table

**Subcategory ID:** `sparse_table` · **Topics:** 3

#### 2.3.1 Sparse Table

- **ID:** `sparse_table` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/sparse_table
- **Templates (1):**
  - [Sparse Table.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Sparse%20Table.cpp)
- **Resources (5):**
  - ★ [Sparse Table | CP Algorithms](https://cp-algorithms.com/data_structures/sparse-table.html)
  - ★ [Sparse Table Data Structure | WilliamFiset](https://www.youtube.com/watch?v=uUatD9AudXo)
  - [Sparse Table & RMQ (Range Minimum Query) | Errichto](https://www.youtube.com/watch?v=0jWeUdxrGm4)
  - [Sparse Table | Aditya Biswakarma](https://medium.com/nybles/sparse-table-f3981fbb1bc8)
  - [Sparse table | Mike Koltsov](https://www.hackerearth.com/practice/notes/sparse-table/)
- **Problems (12):**
  - `[E]` ★ [Static Range Minimum Queries](https://cses.fi/problemset/task/1647)
  - `[E]` [Catapult that ball](https://www.spoj.com/problems/THRBL/)
  - `[E]` ★ [Maximum modulo equality](https://codeforces.com/contest/2050/problem/F)
  - `[M]` ★ [Ant colony](https://codeforces.com/contest/474/problem/F)
  - `[M]` [Sereja and D](https://www.codechef.com/problems/SEAD)
  - `[M]` ★ [CGCDSSQ](https://codeforces.com/contest/475/problem/D)
  - `[M]` [R2D2 and Droid Army](https://codeforces.com/problemset/problem/514/D)
  - `[M]` [Trains and Statistic](https://codeforces.com/contest/675/problem/E)
  - `[M]` ★ [Array Stabilization (GCD version)](https://codeforces.com/contest/1547/problem/F)
  - `[M]` ★ [Longest Good Segment](https://www.codechef.com/problems/LGSEG)
  - `[M]` [Old Christmas Lights](https://dmoj.ca/problem/year2016p7)
  - `[M]` [Shopping](https://dmoj.ca/problem/pacnw16j)

#### 2.3.2 Sparse Table 2D

- **ID:** `sparse_table_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sparse_table_2d
- **Templates (1):**
  - [Sparse Table 2D.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Sparse%20Table%202D.cpp)
- **Resources (2):**
  - ★ [2D Range Minimum Query in O(1) | fnf47](https://codeforces.com/blog/entry/45485)
  - [2D Range Minimum Query in O(1) | Geeks for Geeks](https://www.geeksforgeeks.org/2d-range-minimum-query-in-o1/)
- **Problems (4):**
  - `[M]` ★ [Animals and Puzzle](https://codeforces.com/contest/713/problem/D)
  - `[M]` [Cherry and Squares](https://www.codechef.com/problems/CENS20B)
  - `[M]` [Chef and Rectangle Array](https://www.codechef.com/JUNE16/problems/CHSQARR/)
  - `[M]` ★ [Map](https://codeforces.com/contest/15/problem/D)

#### 2.3.3 Disjoint Sparse Table

- **ID:** `disjoint_sparse_table` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/disjoint_sparse_table
- **Templates (1):**
  - [Disjoint Sparse Table.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Disjoint%20Sparse%20Table.cpp)
- **Resources (3):**
  - ★ [\[Tutorial\] Disjoint Sparse Table | nilesh3105](https://discuss.codechef.com/t/tutorial-disjoint-sparse-table/17404)
  - [Video about Disjoint Sparse Table or how to answer all queries in constant time | peltorator](https://codeforces.com/blog/entry/87940)
  - [Disjoint Sparse Table tutorial | ramchandra](https://codeforces.com/blog/entry/79108)
- **Problems (4):**
  - `[E]` ★ [Product on the segment by modulo](https://www.codechef.com/problems/SEGPROD)
  - `[E]` ★ [Count maxima on an interval](https://codeforces.com/group/1rv4rhCsHp/contest/102954/problem/A)
  - `[H]` ★ [Calculate MARS](https://codeforces.com/group/1rv4rhCsHp/contest/102954/problem/C)
  - `[H]` [Maximize MARS](https://codeforces.com/group/1rv4rhCsHp/contest/102954/problem/D)

### 2.4 Trie

**Subcategory ID:** `trie` · **Topics:** 2

#### 2.4.1 Trie on Strings and Bits

- **ID:** `trie` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/trie
- **Templates (1):**
  - [Trie.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Trie.cpp)
- **Resources (4):**
  - ★ [Trie series | Striver](https://www.youtube.com/playlist?list=PLgUwDviBIf0pcIDCZnxhv0LkHf5KzG9zp)
  - [Introduction to Trie – Data Structure and Algorithm Tutorials | Geeks for Geeks](https://www.geeksforgeeks.org/introduction-to-trie-data-structure-and-algorithm-tutorials/)
  - [Trie | Principles of Algorithmic Problem Solving](https://usaco.guide/PAPS.pdf#page=243)
  - ★ [Bitwise Trie | Lalit Kundu](https://threadsiiithyderabad.quora.com/Tutorial-on-Trie-and-example-problems)
- **Problems (39):**
  - `[E]` ★ [Ada and Indexing](https://www.spoj.com/problems/ADAINDEX/)
  - `[E]` ★ [Try to complete](https://www.spoj.com/problems/TRYCOMP/)
  - `[E]` [Karuta](https://atcoder.jp/contests/abc287/tasks/abc287_e)
  - `[E]` [Query On Strings](https://www.codechef.com/problems/NPLFLF)
  - `[E]` ★ [Shortest Names](https://vjudge.net/problem/UVA-12506)
  - `[E]` ★ [Order of Digits](https://toph.co/p/priority-of-digits)
  - `[E]` ★ [Vasiliy's Multiset](https://codeforces.com/contest/706/problem/D)
  - `[E]` [Hyper Prefix Sets](https://vjudge.net/problem/UVA-11488)
  - `[E]` ★ [Set Xor-Min](https://judge.yosupo.jp/problem/set_xor_min)
  - `[E]` ★ [SubXor](https://www.spoj.com/problems/SUBXOR/)
  - `[E]` ★ [Beautiful Subarrays](https://codeforces.com/problemset/problem/665/E)
  - `[E]` [XOR](https://oj.uz/problem/view/IZhO12_xor)
  - `[E]` [Sausage Maximization](https://codeforces.com/problemset/problem/282/E)
  - `[E]` [Choosing The Commander](https://codeforces.com/contest/817/problem/E)
  - `[E]` ★ [Xor Submatrix](https://csacademy.com/contest/round-42/task/xor-submatrix/statement/)
  - `[E]` [Yet Another XOR Problem](https://toph.co/p/yet-another-xor-problem)
  - `[E]` ★ [Good Substrings](https://codeforces.com/contest/271/problem/D)
  - `[E]` [Phone List](https://www.spoj.com/problems/PHONELST/)
  - `[E]` ★ [Shorten the Array](https://codeforces.com/contest/2093/problem/G)
  - `[M]` [Vitya and Strange Lesson](https://codeforces.com/contest/842/problem/D)
  - `[M]` ★ [Word Combinations](https://cses.fi/problemset/task/1731)
  - `[M]` [A Lot of Games](https://codeforces.com/contest/456/problem/D)
  - `[M]` [Vlak](https://oj.uz/problem/view/COCI20_vlak)
  - `[M]` [Type Printer](https://oj.uz/problem/view/IOI08_printer)
  - `[M]` ★ [XOR Game](https://atcoder.jp/contests/arc122/tasks/arc122_d)
  - `[M]` ★ [Short Code](https://codeforces.com/contest/965/problem/E)
  - `[M]` ★ [Another Word Game](https://vjudge.net/problem/UVA-11539)
  - `[M]` ★ [XOR Inverse](https://codeforces.com/contest/1416/problem/C)
  - `[M]` ★ [Find and Replace](https://usaco.org/index.php?page=viewproblem2&cpid=1281)
  - `[M]` ★ Chef and String — source export-এ সঠিক URL নেই; মূল topic page থেকে problem মিলিয়ে নিন।
  - `[M]` ★ [Vishon XOR](https://lightoj.com/problem/vishon-xor)
  - `[M]` ★ [Lisa and the Martians](https://codeforces.com/contest/1851/problem/F)
  - `[M]` ★ [array-value](https://codeforces.com/contest/1983/problem/F)
  - `[M]` ★ [Yasya and the Mysterious Tree](https://codeforces.com/contest/1980/problem/G)
  - `[M]` [Fixed Prefix Permutations](https://codeforces.com/contest/1792/problem/D)
  - `[M]` [Weird Sum](https://codeforces.com/gym/101801/problem/J)
  - `[H]` [Tree and XOR](https://codeforces.com/contest/1055/problem/F)
  - `[H]` ★ [Selling RNA Strands](https://oj.uz/problem/view/JOI16_selling_rna)
  - `[H]` ★ [Comfortably Numb](https://codeforces.com/problemset/problem/1777/F)

#### 2.4.2 Persistent Trie

- **ID:** `persistent_trie` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_trie
- **Templates (1):**
  - [Persistent Trie.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Persistent%20Trie.cpp)
- **Resources (2):**
  - [Persistent Trie | Geeks for Geeks](https://www.geeksforgeeks.org/persistent-trie-set-1-introduction/)
  - [Persistent Trie - Codechef - GothamPD | Gaurav Sen](https://www.youtube.com/watch?v=0FgKhpyBTcw)
- **Problems (7):**
  - `[M]` ★ [Xor Queries](https://www.codechef.com/problems/XRQRS)
  - `[M]` ★ [Know Your Statement](https://codeforces.com/gym/101628/problem/K)
  - `[M]` ★ [Yet Another XOR Tree Problem](https://toph.co/p/yet-another-xor-tree-problem)
  - `[M]` ★ [Klasika](https://oj.uz/problem/view/COCI20_klasika)
  - `[M]` ★ [Jontrona of Liakot](https://toph.co/p/jontrona-of-liakot)
  - `[H]` [Gotham PD](https://www.codechef.com/problems/GPD)
  - `[H]` ★ [XOR Is Fun](https://toph.co/p/xor-is-fun)

### 2.5 Disjoint Set Union (DSU)

**Subcategory ID:** `dsu` · **Topics:** 8

#### 2.5.1 DSU / Union Find

- **ID:** `dsu` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/dsu
- **Templates (2):**
  - [DSU.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/DSU.cpp)
  - [unionfind_ds.cpp](https://github.com/stevenhalim/cpbook-code/blob/master/ch2/ourown/unionfind_ds.cpp)
- **Resources (9):**
  - ★ [Disjoint Set Union | CP Algorithms](https://cp-algorithms.com/data_structures/disjoint_set_union.html)
  - ★ [Union Find - Union and Find Operations WilliamFiset](https://www.youtube.com/watch?v=0jNmHPfA_yE)
  - ★ [Disjoint-set Data Structures | CS Academy](https://csacademy.com/lesson/disjoint_data_sets)
  - ★ [Disjoint Sets Union | CF EDU](https://codeforces.com/edu/course/2/lesson/7)
  - [G-46. Disjoint Set | Union by Rank | Union by Size | Path Compression | striver](https://www.youtube.com/watch?v=aBxjDBC4M1U)
  - [DISJOINT-SET DATA STRUCTURES | Topcoder](https://www.topcoder.com/thrive/articles/Disjoint-set%20Data%20Structures)
  - [Introduction to Disjoint Set Data Structure | DSU by kartik8800](https://codeforces.com/blog/entry/120381)
  - [\[Tutorial\] Proving the inverse Ackermann complexity of Union-Find By -is-this-fft-](https://codeforces.com/blog/entry/98275)
  - [DSU Extensions with Auxillary Nodes : Move and Erase](https://codeforces.com/blog/entry/130521)
- **Problems (30):**
  - `[E]` ★ [Unionfind](https://judge.yosupo.jp/problem/unionfind)
  - `[E]` ★ [Road Construction](https://cses.fi/problemset/task/1676)
  - `[E]` [Parking](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/B)
  - `[E]` ★ [Cutting a graph](https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/D)
  - `[E]` [Consecutive Letters](https://www.spoj.com/problems/CONSEC/)
  - `[E]` ★ [Anansi's Cobweb](https://acm.timus.ru/problem.aspx?space=1&num=1671)
  - `[E]` ★ [Ancient Berland Roads](https://www.codechef.com/problems/ABROADS)
  - `[E]` [Bosses](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/D)
  - `[E]` [Roads not only in Berland](https://codeforces.com/contest/25/problem/D)
  - `[E]` ★ [Experience](https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/C)
  - `[E]` ★ [Quantity of Strings](https://codeforces.com/contest/150/problem/B)
  - `[E]` [Mocha and Diana (Easy Version)](https://codeforces.com/contest/1559/problem/D1)
  - `[E]` [Mahmoud and a Dictionary](https://codeforces.com/contest/766/problem/D)
  - `[E]` [Reachability Query](https://atcoder.jp/contests/abc420/tasks/abc420_e)
  - `[M]` ★ [Unbelievable Array](https://toph.co/p/unbelievable-array)
  - `[M]` ★ [Bipartite Graph](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/I)
  - `[M]` [Two Sets](https://codeforces.com/contest/468/problem/B)
  - `[M]` ★ [Wormhole Sort](https://usaco.org/index.php?page=viewproblem2&cpid=992)
  - `[M]` [Moocast](https://usaco.org/index.php?page=viewproblem2&cpid=669)
  - `[M]` [Mountain Time](https://csacademy.com/contest/archive/task/mountain-time/statement/)
  - `[M]` ★ [Restructuring Company](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/C)
  - `[M]` ★ [Path Queries](https://codeforces.com/contest/1213/problem/G)
  - `[M]` [Road Reform](https://codeforces.com/contest/1468/problem/J)
  - `[M]` ★ [MinOr Tree](https://codeforces.com/contest/1624/problem/G)
  - `[M]` [Non-Decreasing Colorful Path](https://atcoder.jp/contests/abc335/tasks/abc335_e)
  - `[M]` ★ [GCD Counting](https://codeforces.com/problemset/problem/990/G)
  - `[M]` ★ [Mocha and Diana (Hard Version)](https://codeforces.com/contest/1559/problem/D2)
  - `[M]` [Omg Graph](https://codeforces.com/contest/2117/problem/G)
  - `[H]` [Strongest Friendship Group](https://usaco.org/index.php?page=viewproblem2&cpid=1259)
  - `[H]` ★ [Imbalance Value of a Tree](https://codeforces.com/contest/915/problem/F)

#### 2.5.2 DSU with Rollbacks

- **ID:** `dsu_with_rollbacks` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dsu_with_rollbacks
- **Templates (1):**
  - [DSU with Rollbacks.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/DSU%20with%20Rollbacks.cpp)
- **Resources (2):**
  - [DSU With Rollback | Usaco Guide](https://usaco.guide/adv/offline-del?lang=cpp#dsu-with-rollback)
  - [Rollback Idea on Union Find By Vivek Gupta](https://www.youtube.com/watch?v=AW_iea9xpFw)
- **Problems (3):**
  - `[E]` ★ [DSU with rollback](https://codeforces.com/edu/course/2/lesson/7/3/practice/contest/289392/problem/A)
  - `[E]` [Inaho](https://dmoj.ca/problem/mmcc15p1)
  - `[M]` ★ [Persistent Unionfind](https://judge.yosupo.jp/problem/persistent_unionfind)

#### 2.5.3 Reachability Tree / DSU Tree / Kruskal Reconstruction Tree (KRT)

- **ID:** `reachability_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/reachability_tree
- **Templates (1):**
  - [Reachability Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Reachability%20Tree.cpp)
- **Resources (3):**
  - ★ [Kruskal Reconstruction Tree | Yet Another Competitive Programming Blog](https://mzhang2021.github.io/cp-blog/kruskal/)
  - ★ [\[Tutorial\] Reachability Tree / DSU-tree | prabowo](https://codeforces.com/blog/entry/85714)
  - [Merging Queries Trick By SlavicG](https://codeforces.com/blog/entry/100666)
- **Problems (11):**
  - `[E]` ★ [Qpwoeirut and Vertices](https://codeforces.com/contest/1706/problem/E)
  - `[M]` ★ [Graph and Queries](https://codeforces.com/contest/1416/problem/D)
  - `[M]` ★ [Pictionary](https://oj.uz/problem/view/COCI18_pictionary)
  - `[M]` [Chefina and Strange Tree](https://www.codechef.com/problems/CHEFCOMP)
  - `[M]` [Black Cats Deployment](https://atcoder.jp/contests/cf17-tournament-round3-open/tasks/asaporo2_e)
  - `[H]` ★ [Tiptoe through the tulips](https://www.codechef.com/problems/TULIPS)
  - `[H]` ★ [Groceries in Meteor Town](https://codeforces.com/contest/1628/problem/E)
  - `[H]` [Swapping Cities](https://tlx.toki.id/problems/apio-2020/B)
  - `[H]` [Ski Course Rating](https://usaco.org/index.php?page=viewproblem2&cpid=384)
  - `[H]` [Smooth Sailing (Hard Version)](https://codeforces.com/problemset/problem/1920/F2)
  - `[H]` [Digital Village (Extreme Version)](https://codeforces.com/contest/2021/problem/E3)

#### 2.5.4 Partially Persistent DSU

- **ID:** `partially_persistent_dsu` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/partially_persistent_dsu
- **Templates (1):**
  - [DSU Partially Persistent.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/DSU%20Partially%20Persistent.cpp)
- **Resources (1):**
  - [A quite interesting trick involving Disjoint Set Union by stefdasca](https://codeforces.com/blog/entry/75369)
- **Problems (5):**
  - `[E]` ★ [New Roads Queries](https://cses.fi/problemset/task/2101)
  - `[M]` [Mountaineers](https://codeforces.com/gym/102021/problem/M)
  - `[M]` [Particle Swapping](https://open.kattis.com/problems/particles)
  - `[M]` [Jet Trains](https://codeforces.com/gym/102396/problem/C)
  - `[M]` [Osama-utiful Components](https://codeforces.com/gym/104468/problem/B)

#### 2.5.5 Persistent DSU

- **ID:** `persistent_dsu` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_dsu
- **Templates (1):**
  - [Persistent UnionFind.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Persistent%20UnionFind.cpp)
- **Resources (1):**
  - [\[Tutorial\] Persistent DSU made trivial | sword060](https://codeforces.com/blog/entry/119919)
- **Problems (3):**
  - `[E]` ★ [New Roads Queries](https://cses.fi/problemset/task/2101)
  - `[M]` ★ [Persistent Unionfind](https://judge.yosupo.jp/problem/persistent_unionfind)
  - `[M]` [Osama-utiful Components](https://codeforces.com/gym/104468/problem/B)

#### 2.5.6 Augmented DSU / Weighted DSU

- **ID:** `augmented_dsu` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/augmented_dsu
- **Templates (1):**
  - [Augmented DSU.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Augmented%20DSU.cpp)
- **Resources (2):**
  - ★ [Augmented DSU | Arpit Gupta](https://medium.com/@alphawizard/augmented-dsu-f2c974926cb2)
  - [Atcoder Good Set Query Problem Editorial by en_translator](https://atcoder.jp/contests/abc328/editorial/7664)
- **Problems (6):**
  - `[E]` ★ [Good Set Query](https://atcoder.jp/contests/abc328/tasks/abc328_f)
  - `[E]` ★ [Strange Food Chain](https://www.spoj.com/problems/CHAIN/)
  - `[E]` [Parity](https://acm.timus.ru/problem.aspx?space=1&num=1003)
  - `[E]` [Mahmoud and a Dictionary](https://codeforces.com/contest/766/problem/D)
  - `[E]` [Unionfind with Potential](https://judge.yosupo.jp/problem/unionfind_with_potential)
  - `[M]` ★ [XOR, Tree, and Queries](https://codeforces.com/contest/1788/problem/F)

#### 2.5.7 DSU on Tree and Small to Large Merging

- **ID:** `dsu_on_tree` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/dsu_on_tree
- **Templates (1):**
  - [DSU on Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/DSU%20on%20Tree.cpp)
- **Resources (5):**
  - ★ [DSU on Tree | Small to Large merging | Advanced Idea | Part 4](https://www.youtube.com/watch?v=92unAh2APJ0)
  - [18.4 - Merging Data Structures | Competitive Programming Handbook](https://usaco.guide/CPH.pdf#page=180)
  - ★ [\[Explanation\] dsu on trees (small to large) | qmk](https://codeforces.com/blog/entry/67696)
  - [\[Tutorial\] Sack (dsu on tree) | Arpa](https://codeforces.com/blog/entry/44351)
  - [Small-To-Large Merging | Usaco Guide](https://usaco.guide/plat/merging?lang=cpp)
- **Problems (18):**
  - `[E]` ★ [Distinct Colors](https://cses.fi/problemset/task/1139/)
  - `[E]` ★ [Lomsat gelral](https://codeforces.com/contest/600/problem/E)
  - `[E]` ★ [Promotion Counting](https://usaco.org/index.php?page=viewproblem2&cpid=696)
  - `[E]` [Tree Requests](https://codeforces.com/contest/570/problem/D)
  - `[E]` ★ [Treediff](https://vjudge.net/problem/SGU-507)
  - `[E]` [The Grass Type](https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/practice-problems/algorithm/the-grass-type/)
  - `[E]` [Blood Cousins Return](https://codeforces.com/contest/246/problem/E)
  - `[E]` [Dominant Indices](https://codeforces.com/contest/1009/problem/F)
  - `[M]` ★ [Tree and Queries](https://codeforces.com/contest/375/problem/D)
  - `[M]` [The Cost of Speed Limits](https://open.kattis.com/problems/speedlimit2)
  - `[M]` [Making Friends on Joitter is Fun](https://oj.uz/problem/view/JOI20_joitter2)
  - `[M]` [Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths](https://codeforces.com/contest/741/problem/D)
  - `[M]` ★ [Palindromes in a Tree](https://codeforces.com/contest/914/problem/E)
  - `[M]` ★ [Tree Inversion](https://atcoder.jp/contests/abc337/tasks/abc337_g)
  - `[M]` ★ [Short Code](https://codeforces.com/contest/965/problem/E)
  - `[M]` [Beauty and The Tree](https://codeforces.com/gym/101864/problem/D)
  - `[M]` ★ [Nim Cheater](https://codeforces.com/gym/103119/problem/I)
  - `[H]` ★ [Selling RNA Strands](https://oj.uz/problem/view/JOI16_selling_rna)

#### 2.5.8 [Trick] Maintaining Log N DSU / Range Parallel DSU

- **ID:** `maintaining_log_n_dsu` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maintaining_log_n_dsu
- **Resources (2):**
  - [Editorial of Substring Restrictions Problem | CS Academy](https://csacademy.com/contest/archive/task/substring-restrictions/solution/)
  - [A comment by aryanc403](https://codeforces.com/blog/entry/128367?#comment-1140215)
- **Problems (5):**
  - `[M]` ★ [Range Parallel Unionfind](https://judge.yosupo.jp/problem/range_parallel_unionfind)
  - `[M]` ★ [Substring Restrictions](https://csacademy.com/contest/archive/task/substring-restrictions/statement/)
  - `[M]` ★ [Listing Passwords](https://codeforces.com/gym/103388/problem/L)
  - `[M]` ★ [Kuroni and the Cowsheds](https://www.codechef.com/problems/COWSHEDS)
  - `[M]` ★ [Palindrome Construction](https://atcoder.jp/contests/abc349/tasks/abc349_g)

### 2.6 Square Root Decomposition

**Subcategory ID:** `sqrt_decomposition` · **Topics:** 12

#### 2.6.1 Basic SQRT Decomposition

- **ID:** `sqrt_decomposition` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/sqrt_decomposition
- **Resources (6):**
  - ★ [Sqrt Decomposition | CP Algorithms](https://cp-algorithms.com/data_structures/sqrt_decomposition.html)
  - ★ [Square Root Decomposition | USACO Guide](https://usaco.guide/plat/sqrt?lang=cpp)
  - [27 - Square Root Algorithms | Competitive Programming Handbook](https://usaco.guide/CPH.pdf#page=261)
  - ★ [Sqrt Decomposition | Errichto](https://www.youtube.com/watch?v=BJhzd_VG61k)
  - [What is Square Root Decomposition? - Range Query Solving | Gaurav Sen](https://www.youtube.com/watch?v=gWbDocYhwDA)
  - [Square root decomposition topic summary | Competitive Programming | Vivek Gupta | Advanced](https://www.youtube.com/watch?v=Uqyn-3w7yIU)
- **Problems (18):**
  - `[E]` ★ [Curious Robin Hood](https://lightoj.com/problem/curious-robin-hood)
  - `[E]` ★ [Range Update Queries](https://cses.fi/problemset/task/1651)
  - `[E]` ★ [Point Set Range Frequency](https://judge.yosupo.jp/problem/point_set_range_frequency)
  - `[E]` [Gravity Falls](https://codeforces.com/contest/2148/problem/F)
  - `[M]` ★ [Range Updates and Sums](https://cses.fi/problemset/task/1735)
  - `[M]` [D-query](https://www.spoj.com/problems/DQUERY/)
  - `[M]` ★ [Give Away](https://www.spoj.com/problems/GIVEAWAY/)
  - `[M]` ★ [Hill Jumping](https://www.codechef.com/AUG17/problems/HILLJUMP)
  - `[M]` [Beauty and The Tree](https://codeforces.com/gym/101864/problem/D)
  - `[M]` ★ [Array Transformer](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3154)
  - `[M]` ★ [Most Frequent Value](https://www.spoj.com/problems/FREQ2/)
  - `[M]` [A. Boring Class](https://codeforces.com/gym/105190/problem/A)
  - `[H]` ★ [Dynamic Inversion](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141)
  - `[H]` ★ [Chef And Easy Xor Queries](https://www.codechef.com/problems/CHEFEXQ)
  - `[H]` [Chef and Churu](https://www.codechef.com/problems/FNCS)
  - `[H]` ★ [Welcome home, Chtholly](https://codeforces.com/contest/896/problem/E)
  - `[H]` [The Tree](https://codeforces.com/contest/1017/problem/G)
  - `[H]` ★ [Substrings in a String](https://codeforces.com/problemset/problem/914/F)

#### 2.6.2 Splitting Objects into Light and Heavy / Case Processing

- **ID:** `splitting_objects_into_light_and_heavy` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/splitting_objects_into_light_and_heavy
- **Resources (5):**
  - ★ [Combining Algorithms | USACO Guide](https://usaco.guide/plat/sqrt?lang=cpp#combining-algorithms)
  - [27.1 - Case Processing | Competitive Programming Handbook](https://usaco.guide/CPH.pdf#page=262)
  - ★ [Light and heavy | Errichto](https://www.youtube.com/watch?v=BJhzd_VG61k)
  - ★ [sqrt(S) distinct values | Errichto](https://www.youtube.com/watch?v=BJhzd_VG61k)
  - [Square root decomposition topic summary | Competitive Programming | Vivek Gupta | Advanced](https://www.youtube.com/watch?v=Uqyn-3w7yIU)
- **Problems (14):**
  - `[E]` ★ [Little Elephant and Array](https://codeforces.com/contest/220/problem/B)
  - `[E]` ★ [Just Update and Print the array](https://www.codechef.com/problems/KOL15C)
  - `[E]` ★ [Vanya and Treasure](https://codeforces.com/contest/677/problem/D)
  - `[M]` ★ [Subset Sums](https://codeforces.com/contest/348/problem/C)
  - `[M]` ★ [Holes](https://codeforces.com/contest/13/problem/E)
  - `[M]` [Permutation and Queries](https://codeforces.com/contest/1619/problem/H)
  - `[M]` ★ [Train Maintenance](https://codeforces.com/contest/1580/problem/C)
  - `[M]` [Maximum Child Sum](https://www.spoj.com/problems/MAXCHILDSUM/)
  - `[H]` ★ [Propagation](https://atcoder.jp/contests/abc219/tasks/abc219_g)
  - `[H]` [Mr. Kitayuta's Colorful Graph](https://codeforces.com/contest/506/problem/D)
  - `[H]` [Instant Messanger](https://codeforces.com/contest/398/problem/D)
  - `[H]` ★ [Modulo Queries](https://codeforces.com/gym/105009/problem/L)
  - `[H]` [Tree Queries](https://codeforces.com/contest/1254/problem/D)
  - `[H]` [Jaber and the Prediction Tree](https://codeforces.com/group/Rilx5irOux/contest/628229/problem/E)

#### 2.6.3 Batch Processing / SQRT Decomposition on Queries

- **ID:** `batch_processing` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/batch_processing
- **Resources (4):**
  - ★ [Batching | USACO Guide](https://usaco.guide/plat/sqrt?lang=cpp#batching)
  - ★ [27.1- Batch Processing | Competitive Programming Handbook](https://usaco.guide/CPH.pdf#page=263)
  - [Sqrt decomposition by queries | Errichto](https://www.youtube.com/watch?v=BJhzd_VG61k)
  - [Square root decomposition topic summary | Competitive Programming | Vivek Gupta | Advanced](https://www.youtube.com/watch?v=Uqyn-3w7yIU)
- **Problems (5):**
  - `[E]` ★ [XXXXXXXX](https://www.spoj.com/problems/XXXXXXXX/)
  - `[M]` ★ [Serega and Fun](https://codeforces.com/contest/455/problem/D)
  - `[M]` ★ [GCD 2010](https://acm.timus.ru/problem.aspx?space=1&num=1846)
  - `[M]` ★ [Queries on the Tree](https://codeforces.com/gym/100589/problem/A)
  - `[H]` [Conveyor Belts](https://codeforces.com/contest/487/problem/D)

#### 2.6.4 SQRT Decomposition Split and Build Technique

- **ID:** `sqrt_decomposition_split_and_build_technique` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sqrt_decomposition_split_and_build_technique
- **Templates (1):**
  - [Square Root Decomposition With Reverse Update.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Square%20Root%20Decomposition%20With%20Reverse%20Update.cpp)
- **Resources (1):**
  - [Square root decomposition topic summary | Competitive Programming | Vivek Gupta | Advanced](https://www.youtube.com/watch?v=Uqyn-3w7yIU)
- **Problems (2):**
  - `[M]` ★ [Serega and Fun](https://codeforces.com/contest/455/problem/D)
  - `[H]` ★ [Жесть](https://www.eolymp.com/en/problems/2961)

#### 2.6.5 SQRT Fragmented Tree / Block Tree / SQRT Decomposition on Trees

- **ID:** `sqrt_fragmented_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sqrt_fragmented_tree
- **Templates (1):**
  - [20273231](https://codeforces.com/gym/100589/submission/20273231)
- **Resources (1):**
  - ★ [Unknown Data Structure — (Sqrt Fragmented Tree) By cjtoribio](https://codeforces.com/blog/entry/46843)
- **Problems (1):**
  - `[M]` ★ [Queries on the Tree](https://codeforces.com/gym/100589/problem/A)

#### 2.6.6 Mo's Algorithm

- **ID:** `mos_algorithm` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/mos_algorithm
- **Templates (1):**
  - [MOs Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/MOs%20Algorithm.cpp)
- **Resources (6):**
  - ★ [Mo's algorithm | Mike Koltsov](https://www.hackerearth.com/practice/notes/mos-algorithm/)
  - ★ [Mo's algorithm | CP Algorithms](https://cp-algorithms.com/data_structures/sqrt_decomposition.html#mos-algorithm)
  - [\[Tutorial\] Square root decomposition and applications | box](https://codeforces.com/blog/entry/83248)
  - ★ [Mo's Algorithm | Errichto](https://www.youtube.com/watch?v=BJhzd_VG61k)
  - [Square root decomposition topic summary | Competitive Programming | Vivek Gupta | Advanced](https://www.youtube.com/watch?v=Uqyn-3w7yIU)
  - [An alternative sorting order for Mo's algorithm (Hilbert Order) | gepardo](https://codeforces.com/blog/entry/61203)
- **Problems (13):**
  - `[E]` ★ [Powerful Array](https://codeforces.com/contest/86/problem/D)
  - `[E]` ★ [XOR and Favorite Number](https://codeforces.com/contest/617/problem/E)
  - `[E]` [Robin Hood Archery](https://codeforces.com/contest/2014/problem/H)
  - `[E]` [Triple Index](https://atcoder.jp/contests/abc293/tasks/abc293_g)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` ★ [Static Range Inversions Query](https://judge.yosupo.jp/problem/static_range_inversions_query)
  - `[M]` ★ [Tree and Queries](https://codeforces.com/contest/375/problem/D)
  - `[M]` [Jeff and Removing Periods](https://codeforces.com/contest/351/problem/D)
  - `[M]` ★ [Chefina and Beautiful Pairs](https://www.codechef.com/problems/DECOPAIR)
  - `[M]` ★ [Destiny](https://codeforces.com/contest/840/problem/D)
  - `[M]` [Ann and Books](https://codeforces.com/contest/877/problem/F)
  - `[M]` [Points on Plane](https://codeforces.com/contest/577/problem/E)
  - `[H]` [Estimating progress](https://www.codechef.com/problems/STDPRGS)

#### 2.6.7 Rollback Mo and Mo's with DSU

- **ID:** `mos_with_dsu` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/mos_with_dsu
- **Templates (1):**
  - [MOs with DSU.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/MOs%20with%20DSU.cpp)
- **Resources (3):**
  - ★ [Mo's algorithm and DSU | CF Edu](https://codeforces.com/edu/course/2/lesson/7/3)
  - ★ [A comment by niklasb](https://codeforces.com/blog/entry/7383?#comment-161520)
  - [How To Solve This Magical Problem?](https://codeforces.com/blog/entry/69394)
- **Problems (4):**
  - `[E]` ★ [Chef and Graph Queries](https://www.codechef.com/MARCH14/problems/GERALD07)
  - `[M]` ★ [Chef and Problems](https://www.codechef.com/problems/QCHEF)
  - `[M]` [Zero Query](https://www.spoj.com/problems/ZQUERY/)
  - `[M]` ★ [Static Range Mode Query](https://judge.yosupo.jp/problem/static_range_mode_query)

#### 2.6.8 Mo's on Tree

- **ID:** `mos_on_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/mos_on_tree
- **Templates (1):**
  - [MOs on tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/MOs%20on%20tree.cpp)
- **Resources (1):**
  - ★ [Mo's Algorithm on Trees \[Tutorial\] by animeshf](https://codeforces.com/blog/entry/43230)
- **Problems (5):**
  - `[E]` ★ [Count on a tree II](https://www.spoj.com/problems/COT2/)
  - `[E]` ★ [Frank Sinatra](https://codeforces.com/gym/100962/problem/F)
  - `[M]` [Factor Tree](https://www.codechef.com/APRIL20A/problems/FCTRE/)
  - `[M]` [So Close Yet So Far](https://www.codechef.com/problems/CLOSEFAR)
  - `[M]` [Vasya and Little Bear](https://www.codechef.com/ALKH2016/problems/VLB)

#### 2.6.9 Sweepline Mo

- **ID:** `sweepline_mo` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sweepline_mo
- **Resources (1):**
  - ★ [\[Tutorial\] Square root decomposition and applications | box](https://codeforces.com/blog/entry/83248)
- **Problems (1):**
  - `[E]` ★ [XOR and Favorite Number](https://codeforces.com/contest/617/problem/E)

#### 2.6.10 Mo's with Update / 3D Mo (Offline)

- **ID:** `mos_with_update` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/mos_with_update
- **Templates (1):**
  - [MOs with Update.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/MOs%20with%20Update.cpp)
- **Resources (2):**
  - [Mo's Algorithm With Updates by Gaurav Sen](https://www.youtube.com/watch?v=gUpfwVRXhNY)
  - [Mo's Algorithm (with update and without update, now you can understand both) by Fype](https://codeforces.com/blog/entry/72690)
- **Problems (5):**
  - `[E]` ★ [XXXXXXXX](https://www.spoj.com/problems/XXXXXXXX/)
  - `[E]` ★ [Distinct Dishting](https://toph.co/p/distinct-dishting)
  - `[M]` ★ [Machine Learning](https://codeforces.com/problemset/problem/940/F)
  - `[M]` [Candy Park](https://uoj.ac/problem/58)
  - `[H]` [Primitive Queries](https://www.codechef.com/FEB17/problems/DISTNUM3)

#### 2.6.11 Mo's with Update / 3D Mo (Online)

- **ID:** `mos_online` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/mos_online
- **Templates (1):**
  - [MOs Online.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/MOs%20Online.cpp)
- **Resources (1):**
  - [All comments from this blog](https://codeforces.com/blog/entry/44711?)
- **Problems (2):**
  - `[E]` [Problem with Queries](https://codeforces.com/problemset/problem/2043/G)
  - `[M]` ★ [Machine Learning](https://codeforces.com/problemset/problem/940/F)

#### 2.6.12 4D Mo

- **ID:** `4d_mo` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/4d_mo
- **Templates (1):**
  - [4D MO.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/4D%20MO.cpp)
- **Problems (2):**
  - `[M]` ★ [Strange Queries](https://vjudge.net/problem/Gym-101138D)
  - `[M]` ★ [Two Subtrees](https://codeforces.com/contest/1767/problem/F)

### 2.7 Heavy Light Decomposition (HLD)

**Subcategory ID:** `hld` · **Topics:** 1

#### 2.7.1 Heavy Light Decomposition (HLD) ft Subtrees and Path Query

- **ID:** `hld` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/hld
- **Templates (1):**
  - [HLD.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/HLD.cpp)
- **Resources (5):**
  - ★ [Heavy-light decomposition | CP Algorithms](https://cp-algorithms.com/graph/hld.html)
  - ★ [Hybrid Tutorial #-1: Heavy-Light Decomposition | galen_colin](https://codeforces.com/blog/entry/81317)
  - ★ [Easiest HLD with subtree queries | adamant](https://codeforces.com/blog/entry/53170)
  - [Heavy-Light Decomposition | USACO Guide](https://usaco.guide/plat/hld?lang=cpp)
  - ★ [\[Idea\] Using HLD to reduce memory By maomao90](https://codeforces.com/blog/entry/113453)
- **Problems (24):**
  - `[E]` ★ [Path Queries](https://cses.fi/problemset/task/1138)
  - `[E]` ★ [Path Queries II](https://cses.fi/problemset/task/2134)
  - `[E]` [Query on a tree](https://www.spoj.com/problems/QTREE/)
  - `[E]` ★ [Grass Planting](https://www.spoj.com/problems/GRASSPLA/)
  - `[E]` [Cow Land](https://usaco.org/index.php?page=viewproblem2&cpid=921)
  - `[E]` [QTREE3 - Query on a tree again!](https://www.spoj.com/problems/QTREE3/)
  - `[M]` ★ [Subtrees And Paths](https://www.hackerrank.com/challenges/subtrees-and-paths/problem)
  - `[M]` ★ [Vertex Set Path Composite](https://judge.yosupo.jp/problem/vertex_set_path_composite)
  - `[M]` ★ [Can you answer these queries VII](https://www.spoj.com/problems/GSS7/)
  - `[M]` [Observing the Tree](https://www.codechef.com/problems/QUERY)
  - `[M]` [Pishty and tree](https://www.codechef.com/JULY17/problems/PSHTTR)
  - `[M]` [Ivan Pesic and His World Tour](https://www.codechef.com/problems/QRYLAND)
  - `[M]` [Black-and-White Tree](https://www.codechef.com/problems/BLWHTREE)
  - `[M]` [Milk Visits](https://usaco.org/index.php?page=viewproblem2&cpid=970)
  - `[M]` [QTREE4 - Query on a tree IV](https://www.spoj.com/problems/QTREE4/)
  - `[M]` ★ [Nim Cheater](https://codeforces.com/gym/103119/problem/I)
  - `[M]` [Best Edge Weight](https://codeforces.com/problemset/problem/827/D)
  - `[H]` [Gangsters of Treeland](https://www.codechef.com/problems/MONOPLOY)
  - `[H]` [Max Flow](https://usaco.org/current/index.php?page=viewproblem2&cpid=576)
  - `[H]` [Exercise Route](https://usaco.org/index.php?page=viewproblem2&cpid=901)
  - `[H]` ★ [Tree Game](https://tlx.toki.id/problems/troc-14/H/)
  - `[H]` [The Tree](https://codeforces.com/contest/1017/problem/G)
  - `[H]` [Gotham PD](https://www.codechef.com/problems/GPD)
  - `[VH]` [Fibonacci Numbers on Tree](https://www.codechef.com/problems/FIBTREE)

### 2.8 Centroid Decomposition

**Subcategory ID:** `centroid_decomposition` · **Topics:** 2

#### 2.8.1 Centroid Decomposition

- **ID:** `centroid_decomposition` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/centroid_decomposition
- **Templates (1):**
  - [Centroid Decomposition.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Centroid%20Decomposition.cpp)
- **Resources (8):**
  - ★ [A Visual Introduction to Centroid Decomposition | Igor Carpanese](https://medium.com/carpanese/an-illustrated-introduction-to-centroid-decomposition-8c1989d53308)
  - [Centroid Decomposition of a Tree | Tanuj Khattar](https://tanujkhattar.wordpress.com/2016/01/10/centroid-decomposition-of-a-tree/)
  - ★ [Hybrid Tutorial #-2: Centroid Decomposition | galen_colin](https://codeforces.com/blog/entry/81661)
  - [Centroid Decomposition | USACO Guide](https://usaco.guide/plat/centroid?lang=cpp)
  - [A Simple Introduction to Centroid Decomposition | A Simple Blog](https://robert1003.github.io/2020/01/16/centroid-decomposition.html)
  - [What is Centroid Decomposition? | Gaurav Sen](https://www.youtube.com/watch?v=-Lgda-6_AiY)
  - [Episode 12 - Divide and Conquer on Trees](https://youtu.be/3pk02p1-weU)
  - [Centroid Decomposition, Auxillary Trees - Kishore Kumar | Inter-College Competitive Programming Camp](https://www.youtube.com/watch?v=9lNo4PjvezA)
- **Problems (37):**
  - `[E]` ★ [Finding a Centroid](https://cses.fi/problemset/task/2079)
  - `[E]` ★ [Ciel the Commander](https://codeforces.com/contest/321/problem/C)
  - `[E]` [Fixed-Length Paths I](https://cses.fi/problemset/task/2080)
  - `[E]` ★ [Fixed-Length Paths II](https://cses.fi/problemset/task/2081)
  - `[M]` ★ [Xenia and Tree](https://codeforces.com/contest/342/problem/E)
  - `[M]` ★ [Palindromes in a Tree](https://codeforces.com/contest/914/problem/E)
  - `[M]` [Mahmoud and a xor trip](https://codeforces.com/problemset/problem/766/E)
  - `[M]` ★ [Village (Maximum)](https://codeforces.com/contest/1387/problem/B2)
  - `[M]` [Digit Tree](https://codeforces.com/contest/716/problem/E)
  - `[M]` [Race](https://oj.uz/problem/view/IOI11_race)
  - `[M]` [Sherlock's bet to Moriarty](https://codeforces.com/contest/776/problem/F)
  - `[M]` [Lampice](https://dmoj.ca/problem/coci19c3p4)
  - `[M]` ★ [Query on a tree V](https://www.spoj.com/problems/QTREE5/)
  - `[M]` [Prime Distance On Tree](https://www.codechef.com/problems/PRIMEDST)
  - `[M]` ★ [Close Vertices](https://codeforces.com/contest/293/problem/E)
  - `[M]` ★ [LWDB](https://codeforces.com/gym/100633/problem/D)
  - `[M]` ★ [Good Path on a Tree](https://lightoj.com/problem/good-path)
  - `[M]` ★ [Tree Query](https://codeforces.com/gym/100570/problem/F)
  - `[M]` [QTREE4 - Query on a tree IV](https://www.spoj.com/problems/QTREE4/)
  - `[M]` [New Barns](https://usaco.org/index.php?page=viewproblem2&cpid=817)
  - `[M]` [BST maintenance](https://www.hackerrank.com/challenges/bst-maintenance/problem)
  - `[M]` [Union on Tree](https://www.codechef.com/problems/BTREE)
  - `[M]` [Count It](https://www.codechef.com/problems/CNTIT)
  - `[M]` [Yet Another Tree Problem](https://www.codechef.com/FEB19A/problems/TRDST/)
  - `[M]` [Black and White Tree](https://www.codechef.com/problems/GERALD2)
  - `[M]` ★ [Awesome Shawarma](https://codeforces.com/gym/101991/problem/A)
  - `[M]` [Another Travelling Salesman Problem](https://www.spoj.com/problems/YOSALES/)
  - `[H]` [Double Tree](https://codeforces.com/contest/1140/problem/G)
  - `[H]` ★ [Daylight](https://codeforces.com/gym/102114/problem/D)
  - `[H]` [Factories](https://oj.uz/problem/view/JOI14_factories)
  - `[H]` [Bob Equilibrium](https://dmoj.ca/problem/dmopc19c7p6)
  - `[H]` [Synchronization](https://oj.uz/problem/view/JOI13_synchronization)
  - `[H]` [Time Traveller Imaxblue](https://dmoj.ca/problem/tc19summerh)
  - `[H]` [Freezing with Style](https://codeforces.com/contest/150/problem/E)
  - `[H]` [Red-Black Cobweb](https://codeforces.com/contest/833/problem/D)
  - `[H]` [Terminus Est](https://dmoj.ca/problem/stnbd6)
  - `[H]` [Li Hua and Path](https://codeforces.com/contest/1797/problem/F)

#### 2.8.2 Persistent Centroid Decomposition

- **ID:** `persistent_centroid_decomposition` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_centroid_decomposition
- **Templates (1):**
  - [Centroid Decomposition Persistent.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Centroid%20Decomposition%20Persistent.cpp)
- **Resources (1):**
  - [Persistent Centroid Decomposition || Indian Programming Camp 2020 - Advanced Track - Tanuj Khattar](https://www.youtube.com/watch?v=3pN_7Dha05Y)
- **Problems (1):**
  - `[H]` ★ [Can Bash Save the Day?](https://codeforces.com/contest/757/problem/G)

### 2.9 Long Path Decomposition

**Subcategory ID:** `undefined` · **Topics:** 1

#### 2.9.1 Long Path Decomposition

- **ID:** `long_path_decomposition` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/long_path_decomposition
- **Templates (1):**
  - [Long Path Decomposition.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Long%20Path%20Decomposition.cpp)
- **Problems (1):**
  - `[M]` ★ [Spiders Evil Plan](https://codeforces.com/contest/526/problem/G)

### 2.10 BST

**Subcategory ID:** `binary_search_tree` · **Topics:** 1

#### 2.10.1 Binary Search Tree (BST)

- **ID:** `bst` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/bst
- **Templates (2):**
  - [BST.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/BST.cpp)
  - [BST using STL.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/BST%20using%20STL.cpp)
- **Resources (4):**
  - ★ [Binary Search Tree(BST) | Programiz](https://www.programiz.com/dsa/binary-search-tree)
  - [Binary Search Tree | Geeks For Geeks](https://www.geeksforgeeks.org/binary-search-tree-data-structure/)
  - [Lecture 5: Binary Search Trees, BST Sort | MIT](https://www.youtube.com/watch?v=9Jry5-82I68)
  - [BST Playlist Apna College \[Hindi\]](https://youtube.com/playlist?list=PLeZDTv5F9q5ESO6FuA-tiCBM0fj370Qw7&si=sQO7J2ZIuo2-bI9h)
- **Problems (7):**
  - `[E]` ★ [Search in a Binary Search Tree](https://leetcode.com/problems/search-in-a-binary-search-tree/description/)
  - `[E]` ★ [Insert into a Binary Search Tree](https://leetcode.com/problems/insert-into-a-binary-search-tree/description/)
  - `[E]` ★ [Delete Node in a BST](https://leetcode.com/problems/delete-node-in-a-bst/description/)
  - `[M]` ★ [Number of Ways to Reorder Array to Get Same BST](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst/description/)
  - `[M]` [Broken BST](https://codeforces.com/problemset/problem/797/D)
  - `[M]` [Recover Binary Search Tree](https://leetcode.com/problems/recover-binary-search-tree/description/)
  - `[H]` [Sasha and the Wedding Binary Search Tree](https://codeforces.com/problemset/problem/1929/F)

### 2.11 Balanced Binary Search Tree (BBST)

**Subcategory ID:** `bbst` · **Topics:** 5

#### 2.11.1 Treap

- **ID:** `treap` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/treap
- **Templates (1):**
  - [Treap.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Treap.cpp)
- **Resources (5):**
  - ★ [Treap | CP Algorithms](https://cp-algorithms.com/data_structures/treap.html#toc-tgt-8)
  - ★ [AlgorithmsThread 9: Treaps | SecondThread](https://www.youtube.com/watch?v=6x0UlIBLRsc)
  - [Treap presentation | Benq](https://docs.google.com/presentation/d/14xgtdDWnIBwmJRAuIdZ8FvLZcX9uRxnNoGOGAQRDIvc/edit#slide=id.g2b8ceafba6_0_3)
  - [Treaps : One Tree to Rule ’em all | Tanuj Khattar](https://tanujkhattar.wordpress.com/2016/01/10/treaps-one-tree-to-rule-em-all-part-1/)
  - ★ ["Merging treaps" -- or how to merge sorted sets in good complexity... By bicsi](https://codeforces.com/blog/entry/108601)
- **Problems (11):**
  - `[E]` [Order Statistic Set](https://www.spoj.com/problems/ORDERSET/en/)
  - `[E]` ★ [Ada and Aphids](https://www.spoj.com/problems/ADAAPHID/)
  - `[E]` [Ghost Town](https://www.spoj.com/problems/COUNT1IT/)
  - `[E]` ★ [Mass Change Queries](https://codeforces.com/contest/911/problem/G)
  - `[E]` [Insert](https://atcoder.jp/contests/abc392/tasks/abc392_f)
  - `[M]` ★ [The Cabins in the Woods](https://codedrills.io/contests/icpc-asia-west-continent-final-contest-2023/problems/the-cabins-in-the-woods)
  - `[M]` ★ [Hitchhiking in the Baltic States](https://codeforces.com/problemset/problem/809/D)
  - `[M]` ★ [Range Reverse Range Sum](https://judge.yosupo.jp/problem/range_reverse_range_sum)
  - `[H]` [Points and distances](https://www.hackerearth.com/problem/algorithm/septembereasy-points-and-distances-d30d0e6b/)
  - `[H]` ★ [Games](https://oj.uz/problem/view/IOI13_game)
  - `[VH]` [Vaporeon](https://www.infoarena.ro/problema/vaporeon)

#### 2.11.2 Implicit Treap

- **ID:** `implicit_treap` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/implicit_treap
- **Templates (1):**
  - [Implicit Treap.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Implicit%20Treap.cpp)
- **Resources (3):**
  - ★ [Implicit Treaps | CP Algorithms](https://cp-algorithms.com/data_structures/treap.html#implicit-treaps)
  - ★ [Implicit Treaps | USACO Guide](https://usaco.guide/adv/treaps?lang=cpp#implicit-treaps)
  - ★ [AlgorithmsThread 9: Treaps | SecondThread](https://www.youtube.com/watch?v=6x0UlIBLRsc)
- **Problems (18):**
  - `[E]` ★ [Shandom Ruffle](https://codeforces.com/gym/102787/problem/A)
  - `[E]` ★ [Trick or Treap](https://codeforces.com/gym/102787/problem/Z)
  - `[E]` ★ [Substring Reversals](https://cses.fi/problemset/task/2073)
  - `[E]` ★ [Reversals and Sums](https://cses.fi/problemset/task/2074)
  - `[E]` [Yet Another Array Queries Problem](https://codeforces.com/problemset/problem/863/D)
  - `[E]` [All in One](https://www.spoj.com/problems/ALLIN1/)
  - `[E]` ★ [Cut and Paste](https://cses.fi/problemset/task/2072)
  - `[M]` ★ [Maintaining a Sequence](https://dmoj.ca/problem/noi05p2)
  - `[M]` [Airplane Boarding](https://usaco.org/index.php?page=viewproblem2&cpid=402)
  - `[M]` ★ [Strings](https://csacademy.com/contest/archive/task/strings/statement/)
  - `[M]` [Sneetches and Speeches 3](https://codeforces.com/gym/102787/problem/C)
  - `[M]` [Cup Trick](https://codeforces.com/contest/420/problem/D)
  - `[M]` [The Grim Treaper](https://codeforces.com/gym/102787/problem/D)
  - `[M]` [Can you answer these queries VI](https://www.spoj.com/problems/GSS6/)
  - `[M]` [T-Shirts](https://codeforces.com/contest/702/problem/F)
  - `[M]` [Lucy and Palindromes](https://www.codechef.com/problems/PALINDR)
  - `[M]` [Permutation and Queries](https://codeforces.com/contest/1619/problem/H)
  - `[H]` [Can you answer these queries VIII](https://www.spoj.com/problems/GSS8/)

#### 2.11.3 Persistent Treap

- **ID:** `persistent_treap` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_treap
- **Templates (1):**
  - [Treap persistent.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Treap%20persistent.cpp)
- **Resources (1):**
  - ★ [Persistent / Immutable Treaps | Ankit Sultana](https://ankitsultana.com/2021/03/29/persistent-treaps.html)
- **Problems (4):**
  - `[E]` ★ [Version Controlled IDE](https://vjudge.net/problem/UVA-12538)
  - `[E]` [Genetics](https://www.codechef.com/problems/GENETICS)
  - `[M]` [Persistent List](https://www.eolymp.com/en/problems/2957)
  - `[H]` [Sequence](https://www.acmicpc.net/problem/19068)

#### 2.11.4 Rope

- **ID:** `rope` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/rope
- **Templates (1):**
  - [10355](https://codeforces.com/blog/entry/10355)
- **Resources (3):**
  - ★ [Implicit cartesian tree in GNU C++ STL | By Perlik](https://codeforces.com/blog/entry/10355)
  - ★ [STL Ropes in C++ | Geeks For Feeks](https://www.geeksforgeeks.org/stl-ropes-in-c/)
  - ★ [Mirrored Rope Trick: Ropes with Reverse Queries | By chromate00](https://codeforces.com/blog/entry/107434)
- **Problems (3):**
  - `[E]` ★ [To the beginning of the formation!](https://informatics.msk.ru/mod/statements/view3.php?id=1974&chapterid=2791#1)
  - `[E]` ★ [Okret](https://www.acmicpc.net/problem/14131)
  - `[E]` ★ [Substring Reversals](https://cses.fi/problemset/task/2073)

#### 2.11.5 Splay Tree

- **ID:** `splay_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/splay_tree
- **Templates (1):**
  - [SplayTree.cpp](https://github.com/Bibeknam/algorithmtutorprograms/blob/master/data-structures/splay-trees/SplayTree.cpp)
- **Resources (4):**
  - ★ [\[Tutorial\] Splay Tree: One Tree to Rule Them All | by Zhtluo](https://codeforces.com/blog/entry/108457)
  - ★ [Balanced binary search tree rotations WilliamFiset](https://www.youtube.com/watch?v=q4fnJZr8ztY)
  - [Splay Tree Notes | Michel X. Goemans MIT](https://ocw.mit.edu/courses/6-854j-advanced-algorithms-fall-2008/921232cb9a69015c50002ff5ea6a9824_lec6.pdf)
  - [Splay Tree Presentation | Stanford](https://web.stanford.edu/class/archive/cs/cs166/cs166.1146/lectures/08/Slides08.pdf)
- **Problems (3):**
  - `[E]` ★ [SuperMemo](https://codeforces.com/gym/103997/problem/A)
  - `[E]` [Ada and List](https://www.spoj.com/problems/ADALIST/)
  - `[E]` [Play with Chain](http://acm.hdu.edu.cn/showproblem.php?pid=3487)

### 2.12 Link Cut Tree (LCT)

**Subcategory ID:** `lct` · **Topics:** 4

#### 2.12.1 Link Cut Tree (LCT)

- **ID:** `lct` · **Difficulty:** Hard · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/lct
- **Templates (1):**
  - [Link Cut Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Link%20Cut%20Tree.cpp)
- **Resources (5):**
  - ★ [MIT Lecture 6.851: Advanced Data Structures (Spring'21) | Prof. Erik Demaine](https://courses.csail.mit.edu/6.851/spring21/lectures/L19.html?notes=1)
  - ★ [Dynamic Graphs Scribe Notes | Prof. Erik Demaine](https://courses.csail.mit.edu/6.851/spring21/scribe/lec19.pdf)
  - ★ [Maintain subtree information using link/cut trees | ouaan](https://codeforces.com/blog/entry/67637)
  - ★ [A Basic Exploration of Dynamic Trees | Zhiao Huang and Kirito Feng](https://www.overleaf.com/project/5cd4ea03d299a86710788575)
  - [Link-cut tree tutorial by ramchandra](https://codeforces.com/blog/entry/80383)
- **Problems (20):**
  - `[E]` ★ [Dynamic Tree Connectivity](https://www.spoj.com/problems/DYNACON1/)
  - `[E]` ★ [Dynamic Tree Vertex Add Path Sum](https://judge.yosupo.jp/problem/dynamic_tree_vertex_add_path_sum)
  - `[M]` ★ [Dynamic LCA](https://www.spoj.com/problems/DYNALCA/)
  - `[M]` ★ [Dynamic Tree Test (Easy)](https://dmoj.ca/problem/ds5easy)
  - `[M]` ★ [Query on a tree VI](https://www.codechef.com/problems/QTREE6)
  - `[M]` [Squirrel Cities](https://dmoj.ca/problem/wac4p7)
  - `[M]` ★ [Balanced Tokens](https://www.hackerrank.com/contests/pwshpc-online-round/challenges/pwsh-tokens/problem)
  - `[M]` [Dynamic Tree Vertex Set Path Composite](https://judge.yosupo.jp/problem/dynamic_tree_vertex_set_path_composite)
  - `[M]` ★ [Dynamic Tree Vertex Add Subtree Sum](https://judge.yosupo.jp/problem/dynamic_tree_vertex_add_subtree_sum)
  - `[M]` [Caves and Tunnels](https://acm.timus.ru/problem.aspx?space=1&num=1553)
  - `[M]` [Clearing the Snowdrift](https://codeforces.com/contest/2097/problem/E)
  - `[H]` ★ [Nauuo and ODT](https://codeforces.com/contest/1172/problem/E)
  - `[H]` ★ [Tree or not Tree](https://codeforces.com/contest/117/problem/E)
  - `[H]` [Train Tracks](https://codeforces.com/contest/1344/problem/E)
  - `[H]` ★ [Pastoral Oddities](https://codeforces.com/contest/603/problem/E)
  - `[H]` [Gangsters of Treeland](https://www.codechef.com/problems/MONOPLOY)
  - `[H]` [Sasha and Algorithm of Silence's Sounds](https://codeforces.com/contest/1109/problem/F)
  - `[H]` [大融合](https://www.luogu.com.cn/problem/P4219)
  - `[H]` ★ [共价大爷游长沙](https://uoj.ac/problem/207)
  - `[H]` [Dancing Elephants](https://oj.uz/problem/view/IOI11_elephants)

#### 2.12.2 Euler Tour Tree (ETT)

- **ID:** `ett` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/ett
- **Resources (3):**
  - ★ [On Euler tour trees by ifsmirnov](https://codeforces.com/blog/entry/18369)
  - ★ [A Basic Exploration of Dynamic Trees | Zhiao Huang and Kirito Feng](https://www.overleaf.com/project/5cd4ea03d299a86710788575)
  - [Dynamic subtree queries revisited: the Depth First Tour Tree | Paper by Gabriele Farina and Luigi Laura](https://arxiv.org/pdf/1502.05292.pdf)
- **Problems (2):**
  - `[H]` ★ [Dynamic Tree Subtree Add Subtree Sum](https://judge.yosupo.jp/problem/dynamic_tree_subtree_add_subtree_sum)
  - `[H]` ★ [Mashmokh's Designed Problem](https://codeforces.com/contest/414/problem/E)

#### 2.12.3 Top Tree / AAA Tree

- **ID:** `top_tree` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/top_tree
- **Templates (2):**
  - [top_tree.hpp](https://github.com/ecnerwala/cp-book/blob/master/src/top_tree.hpp)
  - [top-tree.hpp](https://ei1333.github.io/library/structure/dynamic-tree/top-tree.hpp)
- **Resources (3):**
  - ★ [\[Tutorial\] Fully Dynamic Trees Supporting Path/Subtree Aggregates and Lazy Path/Subtree Updates | smax](https://codeforces.com/blog/entry/103726)
  - ★ [A Basic Exploration of Dynamic Trees | Zhiao Huang and Kirito Feng](https://www.overleaf.com/project/5cd4ea03d299a86710788575)
  - [Top-trees and dynamic graph algorithms | Thesis Paper by Jacob Holm and Kristian de Lichtenberg](https://di.ku.dk/forskning/Publikationer/tekniske_rapporter/tekniske-rapporter-1998/98-17.pdf)
- **Problems (2):**
  - `[H]` ★ [Dynamic Tree Subtree Add Subtree Sum](https://judge.yosupo.jp/problem/dynamic_tree_subtree_add_subtree_sum)
  - `[VH]` [Dynamic Tree Test](https://dmoj.ca/problem/ds5)

#### 2.12.4 Link Cut Cactus

- **ID:** `link_cut_cactus` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/link_cut_cactus
- **Templates (1):**
  - [Link-Cut-Cactus](https://github.com/Crystalrem/Link-Cut-Cactus)
- **Resources (1):**
  - [动态仙人掌 系列题解之四 - link-cut cactus | VFleaKing](https://blog.csdn.net/VFleaKing/article/details/80748052)
- **Problems (1):**
  - `[M]` ★ [Desert](https://codeforces.com/contest/1599/problem/I)

### 2.13 Policy Based Data Structures

**Subcategory ID:** `policy_based_data_structures` · **Topics:** 2

#### 2.13.1 Ordered Set

- **ID:** `ordered_set` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/ordered_set
- **Templates (2):**
  - [Ordered Set.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Ordered%20Set.cpp)
  - [PBDS.cpp](https://github.com/Priyansh19077/YouTube-links/blob/main/PBDS.cpp)
- **Resources (3):**
  - ★ [C++ STL: Policy based data structures | adamant](https://codeforces.com/blog/entry/11080)
  - [Ordered Set and GNU C++ PBDS | Geeks For Geeks](https://www.geeksforgeeks.org/ordered-set-gnu-c-pbds/)
  - [Ordered Set | Policy Based Data Structure | Priyansh Agarwal](https://youtu.be/IWyIwLFucU4?si=trmb9zekhdHr7--A)
- **Problems (19):**
  - `[E]` [Order Statistic Set](https://www.spoj.com/problems/ORDERSET/en/)
  - `[E]` ★ [Inversions](https://codeforces.com/edu/course/2/lesson/4/3/practice/contest/274545/problem/A)
  - `[E]` [Mega Inversions](https://vjudge.net/problem/Kattis-megainversions)
  - `[E]` ★ [Mean of array](https://www.spoj.com/problems/MEANARR/)
  - `[E]` ★ [Line up](https://www.spoj.com/problems/KOILINE/)
  - `[E]` [Enemy is weak](https://codeforces.com/contest/61/problem/E)
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` [Pashmak and Parmida's problem](https://codeforces.com/contest/459/problem/D)
  - `[E]` [Petya and Array](https://codeforces.com/contest/1042/problem/D)
  - `[E]` ★ [Inversion Count](https://vjudge.net/problem/SPOJ-INVCNT)
  - `[E]` ★ [Pair of Topics](https://vjudge.net/problem/CodeForces-1324D)
  - `[E]` [Greetings](https://codeforces.com/problemset/problem/1915/F)
  - `[E]` [Colorful Queries](https://codeforces.com/gym/104308/problem/I)
  - `[E]` [Dynamic Collection](https://codeforces.com/gym/104375/problem/D)
  - `[M]` ★ [Radio stations](https://codeforces.com/contest/762/problem/E)
  - `[M]` [Database Query Engine](https://codeforces.com/gym/100861/problem/D)
  - `[M]` [List Removals](https://cses.fi/problemset/task/1749/)
  - `[M]` ★ [Sliding Window Median](https://cses.fi/problemset/task/1076)
  - `[H]` [Misha and Permutations Summation](https://codeforces.com/contest/501/problem/D)

#### 2.13.2 GP Hash Table

- **ID:** `gp_hash_table` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/gp_hash_table
- **Templates (1):**
  - [GP Hash Table.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/GP%20Hash%20Table.cpp)
- **Resources (2):**
  - ★ [C++ STL: Order of magnitude faster hash tables with Policy Based Data Structures By Chilli](https://codeforces.com/blog/entry/60737)
  - ★ [Hashmaps | USACO Guide](https://usaco.guide/gold/hashmaps?lang=cpp)
- **Problems (5):**
  - `[E]` ★ [Sum of Two Values](https://cses.fi/problemset/task/1640)
  - `[E]` ★ [Sum of Four Values](https://cses.fi/problemset/task/1642)
  - `[M]` ★ [Choosing Balls](https://codeforces.com/contest/264/problem/C)
  - `[M]` [Mr. Kitayuta, the Treasure Hunter](https://codeforces.com/contest/505/problem/C)
  - `[M]` [Amer and Graphs](https://codeforces.com/gym/101808/problem/B)

### 2.14 More Tree Data Structures

**Subcategory ID:** `more_tree_data_structures` · **Topics:** 6

#### 2.14.1 Wavelet Tree

- **ID:** `wavelet_tree` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/wavelet_tree
- **Templates (1):**
  - [Wavelet Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Wavelet%20Tree.cpp)
- **Resources (3):**
  - ★ [Introduction to New Data Structure: Wavelet Trees | By rachitiitr](https://codeforces.com/blog/entry/52854)
  - ★ [Wavelet Trees for competitive programming | IOI preparation #3 | Errichto](https://www.youtube.com/watch?v=4aSv9PcecDw)
  - [Wavelet Trees for Competitive Programming | Paper](https://ioinformatics.org/journal/v10_2016_19_37.pdf)
- **Problems (2):**
  - `[E]` ★ [K-th Number](https://www.spoj.com/problems/MKTHNUM/)
  - `[E]` ★ [Range Kth Smallest](https://judge.yosupo.jp/problem/range_kth_smallest)

#### 2.14.2 Cartesian Tree

- **ID:** `cartesian_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/cartesian_tree
- **Templates (1):**
  - [Cartesian Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Cartesian%20Tree.cpp)
- **Resources (3):**
  - ★ [\[Tutorial\] Cartesian tree and some related problems By tibinyte](https://codeforces.com/blog/entry/112664)
  - ★ [\[Tutorial\] Cartesian tree on arbitrary graphs By aymanrs](https://codeforces.com/blog/entry/114607)
  - ★ [Solve RMQ (Range Minimum Query) by finding LCA (Lowest Common Ancestor) | CP Algorithms](https://cp-algorithms.com/graph/rmq_linear.html)
- **Problems (9):**
  - `[E]` ★ [Cartesian Tree](https://judge.yosupo.jp/problem/cartesian_tree)
  - `[E]` ★ [Yet Another Array Counting Problem](https://codeforces.com/contest/1748/problem/E)
  - `[M]` [Fancy Fence](https://oj.uz/problem/view/CEOI20_fancyfence)
  - `[M]` [Kevin and Math Class](https://codeforces.com/contest/2048/problem/F)
  - `[M]` [Weird Sum](https://codeforces.com/gym/101801/problem/J)
  - `[H]` ★ [Comfortably Numb](https://codeforces.com/problemset/problem/1777/F)
  - `[H]` [Subsequence](https://codeforces.com/problemset/problem/1580/D)
  - `[VH]` [Cartesian Tree](https://codeforces.com/problemset/problem/1290/E)
  - `[VH]` [Vaporeon](https://www.infoarena.ro/problema/vaporeon)

#### 2.14.3 K-Dimensional Tree (KD Tree)

- **ID:** `kd_tree` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/kd_tree
- **Templates (1):**
  - [KD Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/KD%20Tree.cpp)
- **Resources (3):**
  - ★ [kd-Trees | CMSC 420](https://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/kdtrees.pdf)
  - [A look into K-Dimensional Trees Brandon Wheeless smucs By Brandon Wheeless](https://medium.com/smucs/a-look-into-k-dimensional-trees-290ec69dffe9)
  - [Search and Insertion in K Dimensional tree | Geeks For Geeks](https://www.geeksforgeeks.org/search-and-insertion-in-k-dimensional-tree/)
- **Problems (2):**
  - `[E]` ★ [Remember the Name...](https://toph.co/p/remember-the-name)
  - `[E]` ★ [Closest distance](https://www.spoj.com/problems/GANNHAT/)

#### 2.14.4 SQRT Tree

- **ID:** `sqrt_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sqrt_tree
- **Templates (1):**
  - [SQRT Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/SQRT%20Tree.cpp)
- **Resources (3):**
  - ★ [Sqrt Tree | CP Algorithms](https://cp-algorithms.com/data_structures/sqrt-tree.html)
  - [Sqrt-tree: answering queries in O(1) with O(NloglogN) preprocessing By gepardo](https://codeforces.com/blog/entry/57046)
  - [Sqrt-tree (part 2): modifications in O(sqrtN), lazy propagation | By gepardo](https://codeforces.com/blog/entry/59092)
- **Problems (3):**
  - `[E]` ★ [Product on the segment by modulo](https://www.codechef.com/problems/SEGPROD)
  - `[E]` ★ [Count maxima on an interval](https://codeforces.com/group/1rv4rhCsHp/contest/102954/problem/A)
  - `[E]` ★ [Dynamic Range Minimum Queries](https://cses.fi/problemset/task/1649)

#### 2.14.5 Permutation Tree

- **ID:** `permutation_tree` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/permutation_tree
- **Templates (1):**
  - [Permutation Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Permutation%20Tree.cpp)
- **Resources (1):**
  - ★ [Tutorial on Permutation Tree | errorgorn](https://codeforces.com/blog/entry/78898)
- **Problems (7):**
  - `[E]` ★ [Common Interval Decomposition Tree](https://judge.yosupo.jp/problem/common_interval_decomposition_tree)
  - `[M]` ★ [Good Subsegments](https://codeforces.com/contest/997/problem/E)
  - `[M]` ★ [Intrinsic Interval](https://codeforces.com/gym/101620/problem/I)
  - `[M]` ★ [Pudding Monsters](https://codeforces.com/contest/526/problem/F)
  - `[H]` ★ [Army of Me](https://www.codechef.com/problems/ARMYOFME)
  - `[H]` [Good Subsequences](https://www.codechef.com/MARCH20A/problems/GOODSEGS)
  - `[H]` [Beauty of a Permutation](https://codeforces.com/contest/1205/problem/F)

#### 2.14.6 PQ Tree

- **ID:** `pq_tree` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pq_tree
- **Templates (1):**
  - [123723552](https://codeforces.com/contest/1552/submission/123723552)
- **Resources (1):**
  - [Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms | Paper by Kellogg S. Booth, George S. Lueker](https://www.sciencedirect.com/science/article/pii/S0022000076800451#)
- **Problems (3):**
  - `[H]` ★ [Organizing a Music Festival](https://codeforces.com/contest/1552/problem/I)
  - `[H]` [Matrix](https://codeforces.com/contest/243/problem/E)
  - `[H]` [Classroom Scheduling](https://codeforces.com/gym/101726/problem/G)

### 2.15 Dynamic Connectivity

**Subcategory ID:** `dynamic_connectivity` · **Topics:** 2

#### 2.15.1 Dynamic Connectivity Problem (Offline)

- **ID:** `dynamic_connectivity_problem` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_connectivity_problem
- **Templates (1):**
  - [Dynamic Connectivity Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Dynamic%20Connectivity%20Problem.cpp)
- **Resources (3):**
  - ★ [Deleting from a data structure in O(T(n)logn) | CP Algorithms](https://cp-algorithms.com/data_structures/deleting_in_log_n.html)
  - [Dynamic Connectivity for Competitive Programming | DSU Rollback on Segment Tree | Vivek](https://www.youtube.com/watch?v=7gqFcunrFH0)
  - [Dynamic connectivity problem | adamant](https://codeforces.com/blog/entry/15296)
- **Problems (14):**
  - `[E]` ★ [Connect and Disconnect](https://codeforces.com/gym/100551/problem/A)
  - `[E]` [Dynamic Connectivity](https://cses.fi/problemset/task/2133)
  - `[E]` [Addition on Segments](https://codeforces.com/contest/981/problem/E)
  - `[E]` ★ [Extending Set of Points](https://codeforces.com/contest/1140/problem/F)
  - `[E]` [Disconnected Graph](https://codeforces.com/gym/100551/problem/E)
  - `[E]` ★ [Dynamic Graph Vertex Add Component Sum](https://judge.yosupo.jp/problem/dynamic_graph_vertex_add_component_sum)
  - `[M]` ★ [Joker](https://codeforces.com/contest/1386/problem/C)
  - `[M]` ★ [GCD 2010](https://acm.timus.ru/problem.aspx?space=1&num=1846)
  - `[M]` [Tree Queries](https://www.codechef.com/problems/P8169)
  - `[M]` [Graph Inclusion](https://codeforces.com/contest/2069/problem/F)
  - `[M]` ★ [Modulo 3](https://codeforces.com/contest/2104/problem/G)
  - `[M]` [Bipartite Checking](https://codeforces.com/contest/813/problem/F)
  - `[H]` ★ [A Museum Robbery](https://codeforces.com/contest/601/problem/E)
  - `[H]` [Festival Signs](https://codeforces.com/gym/105789/problem/F)

#### 2.15.2 Dynamic Connectivity Problem (Online) / HDLT Algorithm

- **ID:** `online_dynamic_connectivity_problem` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/online_dynamic_connectivity_problem
- **Resources (2):**
  - ★ [Online Dynamic Connectivity | ko_osaga](https://codeforces.com/blog/entry/128556)
  - ★ [Dynamic Connectivity | MIT CSAIL](https://courses.csail.mit.edu/6.851/spring12/scribe/L20.pdf)
- **Problems (2):**
  - `[E]` ★ [Forced Online Queries Problem](https://codeforces.com/contest/1217/problem/F)
  - `[E]` ★ [Dynamic Graph Vertex Add Component Sum](https://judge.yosupo.jp/problem/dynamic_graph_vertex_add_component_sum)

### 2.16 Monotonic Data Structures

**Subcategory ID:** `monotonic_data_structures` · **Topics:** 4

#### 2.16.1 Monotonic Stack: All Nearest Smaller Values and All Subarray Maximum/Minimum

- **ID:** `all_subarray_maximum_minimum` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/all_subarray_maximum_minimum
- **Resources (6):**
  - ★ [Introduction to Monotonic Stack – Data Structure and Algorithm Tutorials | Geeks for Geeks](https://www.geeksforgeeks.org/introduction-to-monotonic-stack-2/)
  - ★ [Monotonic Stack Data Structure Explained | AlgoMonster](https://www.youtube.com/watch?v=Dq_ObZwTY_Q)
  - [All nearest smaller values | Wiki](https://en.wikipedia.org/wiki/All_nearest_smaller_values)
  - ★ [Find the nearest smaller numbers on left side in an array | Geeks for Geeks](https://www.geeksforgeeks.org/find-the-nearest-smaller-numbers-on-left-side-in-an-array/)
  - ★ [A comment by animeshf regarding sum of all subarray maximums](https://codeforces.com/blog/entry/21902?#comment-265823)
  - [Monotonic Increasing & Decreasing Stack](https://www.youtube.com/watch?v=ALJJcA1uWmU)
- **Problems (16):**
  - `[E]` ★ [Nearest Smaller Values](https://cses.fi/problemset/task/1645)
  - `[E]` ★ [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/description/)
  - `[E]` ★ [Minimum Sum](https://atcoder.jp/contests/agc005/tasks/agc005_b)
  - `[E]` ★ [Sum of Subarray Minimums](https://leetcode.com/problems/sum-of-subarray-minimums/description/)
  - `[E]` [Imbalanced Array](https://codeforces.com/problemset/problem/817/D)
  - `[E]` ★ [DIFERENCIJA](https://www.spoj.com/problems/DIFERENC/)
  - `[E]` ★ [Mike and Feet](https://codeforces.com/problemset/problem/547/B)
  - `[M]` ★ [Ivan And Mega Queries](https://vjudge.net/problem/Gym-104120I)
  - `[M]` ★ [Pudding Monsters](https://codeforces.com/contest/526/problem/F)
  - `[M]` [Lipshitz Sequence](https://codeforces.com/contest/602/problem/D)
  - `[M]` [Matrix Maximum Sum](https://www.codechef.com/FEB16/problems/MTMXSUM/)
  - `[M]` ★ [Skyline Photo](https://codeforces.com/contest/1483/problem/C)
  - `[M]` ★ [Max GEQ Sum](https://codeforces.com/problemset/problem/1691/D)
  - `[H]` ★ [Min Max Sum](https://csacademy.com/contest/round-35/task/min-max-sum/statement/)
  - `[H]` ★ [Norma](https://dmoj.ca/problem/coci14c2p6)
  - `[H]` ★ [Comfortably Numb](https://codeforces.com/problemset/problem/1777/F)

#### 2.16.2 Monotonic Queue

- **ID:** `monotonous_queue` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/monotonous_queue
- **Templates (1):**
  - [Monotonous Queue.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Monotonous%20Queue.cpp)
- **Resources (3):**
  - ★ [Monotonic Queue Explained with LeetCode Problems Li Yin Algorithms and Coding Interviews By Li Yin](https://medium.com/algorithms-and-leetcode/monotonic-queue-explained-with-leetcode-problems-7db7c530c1d6)
  - ★ [Monotonic Queue simulation using Stack data structure](https://youtu.be/Dq_ObZwTY_Q?si=eVWNr_oRlVwxdRaU)
  - [Introduction to Monotonic Queues | Geeks For Geeks](https://www.geeksforgeeks.org/introduction-to-monotonic-queues/)
- **Problems (5):**
  - `[E]` ★ [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/description/)
  - `[E]` ★ [Sliding Window Minimum](https://cses.fi/boi24/task/3221)
  - `[E]` ★ [Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/description/)
  - `[M]` [Strip](https://codeforces.com/contest/488/problem/D)
  - `[H]` [Pictures with Kittens (hard version)](https://codeforces.com/contest/1077/problem/F2)

#### 2.16.3 Monotonic Queue 2D

- **ID:** `monotonous_queue_2d` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/monotonous_queue_2d
- **Templates (1):**
  - [53810?#comment-871637](https://codeforces.com/blog/entry/53810?#comment-871637)
- **Resources (2):**
  - ★ [Monotonic Queue | Ali Ibrahim](https://ali-ibrahim137.github.io/competitive/programming/2019/12/08/Monotonic-Queue.html)
  - ★ [Minima/maxima over all fixed-size arrays (multi-dimensional) | By bicsi](https://codeforces.com/blog/entry/53810)
- **Problems (6):**
  - `[M]` [Chef and Rectangle Array](https://www.codechef.com/JUNE16/problems/CHSQARR/)
  - `[M]` ★ [Monitor](https://codeforces.com/contest/846/problem/D)
  - `[M]` ★ [Map](https://codeforces.com/contest/15/problem/D)
  - `[M]` [Pyramid](https://wcipeg.com/problem/ioi0612)
  - `[M]` [Stamp Game](https://atcoder.jp/contests/abc228/tasks/abc228_f)
  - `[M]` [OpenStreetMap](https://codeforces.com/problemset/problem/1195/E)

#### 2.16.4 Monotonic Deque

- **ID:** `monotonic_deque` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/monotonic_deque
- **Templates (1):**
  - [122003](https://codeforces.com/blog/entry/122003)
- **Resources (1):**
  - [\[Tutorial\] Minimum Deque By k1r1t0](https://codeforces.com/blog/entry/122003)
- **Problems (3):**
  - `[E]` ★ [Peru](https://qoj.ac/contest/168/problem/149)
  - `[E]` [Sliding Window Or](https://cses.fi/problemset/task/3405/)
  - `[H]` [Bermart Ice Cream](https://codeforces.com/contest/2026/problem/F)

### 2.17 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 4

#### 2.17.1 Interval Set

- **ID:** `interval_set` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/interval_set
- **Templates (1):**
  - [Interval Set.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Interval%20Set.cpp)
- **Problems (2):**
  - `[E]` ★ [Triangle Count (Hard)](https://www.codechef.com/problems/TRICOUNT2)
  - `[E]` ★ [Daunting Device](https://codeforces.com/gym/101889/problem/D)

#### 2.17.2 Persistent Array

- **ID:** `persistent_array` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_array
- **Templates (1):**
  - [Persistent Array.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Persistent%20Array.cpp)
- **Resources (1):**
  - [Persistent Array | USACO Guide](https://usaco.guide/adv/persistent?lang=cpp#persistent-array)
- **Problems (1):**
  - `[E]` ★ [Persistent Queue](https://judge.yosupo.jp/problem/persistent_queue)

#### 2.17.3 Persistent Queue

- **ID:** `persistent_queue` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_queue
- **Templates (1):**
  - [Persistent Queue.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Persistent%20Queue.cpp)
- **Problems (2):**
  - `[E]` ★ [Persistent Queue](https://judge.yosupo.jp/problem/persistent_queue)
  - `[E]` [Persistent Queue ASC 37](https://codeforces.com/gym/100431/problem/G)

#### 2.17.4 Persistent Meldable Heap / Leftist Heap

- **ID:** `persistent_heap` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_heap
- **Templates (1):**
  - [Persistent Meldable Heap.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Persistent%20Meldable%20Heap.cpp)
- **Resources (2):**
  - [Leftist tree | Wiki](https://en.wikipedia.org/wiki/Leftist_tree)
  - [Randomized Heap | CP Algorithms](https://cp-algorithms.com/data_structures/randomized_heap.html)
- **Problems (1):**
  - `[VH]` ★ [K-th Shortest Walk](https://judge.yosupo.jp/problem/k_shortest_walk)

### 2.18 Techniques

**Subcategory ID:** `techniques` · **Topics:** 7

#### 2.18.1 Venice Technique

- **ID:** `venice_technique` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/venice_technique
- **Templates (1):**
  - [Venice Technique.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Venice%20Technique.cpp)
- **Resources (1):**
  - ★ [Venice Technique By cjtoribio](https://codeforces.com/blog/entry/58316)
- **Problems (5):**
  - `[E]` ★ [Querying Multiset](https://vjudge.net/problem/AtCoder-abc212_d)
  - `[M]` [Vitya and Strange Lesson](https://codeforces.com/contest/842/problem/D)
  - `[M]` [Credit Card](https://codeforces.com/contest/893/problem/D)
  - `[M]` ★ [PELODE](https://vjudge.net/problem/Gym-105593P)
  - `[H]` [Village Fair](https://www.spoj.com/problems/BDOI16E/)

#### 2.18.2 Offline Queries

- **ID:** `offline_queries` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/offline_queries
- **Resources (3):**
  - [What are Online and Offline query-based questions in Competitive Programming | Geeks for Geeks](https://www.geeksforgeeks.org/what-are-online-and-offline-query-based-questions-in-competitive-programming/)
  - [What is an offline solution?](https://codeforces.com/blog/entry/19771)
  - ★ [Range Queries with Sweep Line | USACO Guide](https://usaco.guide/plat/range-sweep?lang=cpp)
- **Problems (18):**
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[E]` ★ [Crayon](https://www.spoj.com/problems/CRAYON/)
  - `[E]` ★ [Anansi's Cobweb](https://acm.timus.ru/problem.aspx?space=1&num=1671)
  - `[E]` ★ [Cutting a graph](https://codeforces.com/edu/course/2/lesson/7/1/practice/contest/289390/problem/D)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` [Points](https://codeforces.com/contest/19/problem/D)
  - `[M]` ★ [Yaroslav and Divisors](https://codeforces.com/contest/301/problem/D)
  - `[M]` [Closest Equals](https://codeforces.com/problemset/problem/522/D)
  - `[M]` [Pishty and tree](https://www.codechef.com/JULY17/problems/PSHTTR)
  - `[M]` ★ [Klasika](https://oj.uz/problem/view/COCI20_klasika)
  - `[M]` ★ [Graph and Queries](https://codeforces.com/contest/1416/problem/D)
  - `[M]` ★ [Mahmoud and Ehab and yet another xor task](https://codeforces.com/contest/959/problem/F)
  - `[M]` ★ [Nested Ranges Count](https://cses.fi/problemset/task/2169)
  - `[H]` ★ [Please, another Queries on Array?](https://codeforces.com/problemset/problem/1114/F)
  - `[H]` ★ [Modulo Queries](https://codeforces.com/gym/105009/problem/L)
  - `[H]` [Minimum Xor On Segment](https://www.codechef.com/LTIME109A/problems/MINXORSEG)
  - `[H]` ★ [Prime Divisor on Tree Path](https://toph.co/p/prime-divisor-on-tree-path)
  - `[H]` ★ [REQ](https://codeforces.com/contest/594/problem/D)

#### 2.18.3 Static to Dynamic Trick / Log Decomposition

- **ID:** `static_to_dynamic_trick` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/static_to_dynamic_trick
- **Templates (1):**
  - [Static to Dynamic Trick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Static%20to%20Dynamic%20Trick.cpp)
- **Resources (3):**
  - ★ [“Log Decomposition”, a technique to insert random elements into sorted data structures By ismail-but-noob](https://codeforces.com/blog/entry/124766)
  - ★ [Idea 4 of General ideas By adamant](https://codeforces.com/blog/entry/48417)
  - ★ [Blogewoosh #7](https://codeforces.com/blog/entry/67263)
- **Problems (2):**
  - `[M]` ★ [String Set Queries](https://codeforces.com/contest/710/problem/F)
  - `[M]` ★ [Monster Game II](https://cses.fi/problemset/task/2085)

#### 2.18.4 Divide and Conquer on Queries

- **ID:** `divide_and_conquer_on_queries` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/divide_and_conquer_on_queries
- **Resources (2):**
  - ★ [Divide & Conquer - SRQ | USACO guide](https://usaco.guide/plat/DC-SRQ?lang=cpp)
  - ★ [\[Tutorial\] Divide and Conquer Offline Query — A Niche Way to solve Static Range Query By steveonalex](https://codeforces.com/blog/entry/119104)
- **Problems (13):**
  - `[E]` ★ [Static Range Minimum Queries](https://cses.fi/problemset/task/1647)
  - `[E]` ★ [Product on the segment by modulo](https://www.codechef.com/problems/SEGPROD)
  - `[E]` ★ [Count maxima on an interval](https://codeforces.com/group/1rv4rhCsHp/contest/102954/problem/A)
  - `[M]` ★ [Secret](https://oj.uz/problem/view/JOI14_secret)
  - `[M]` [Toll](https://oj.uz/problem/view/BOI17_toll)
  - `[M]` ★ [Bob and Continued Fractions](https://dmoj.ca/problem/dmopc19c7p4)
  - `[M]` [Estelle’s Supper Box](https://codebreaker.xyz/problem/supperbox)
  - `[M]` ★ [Ivan and Burgers](https://codeforces.com/problemset/problem/1100/F)
  - `[M]` [XORSHIFT](https://oj.vnoi.info/problem/mofkcup_r1_e)
  - `[H]` ★ [Subsequence Sum Queries](https://codeforces.com/gym/101741/problem/J)
  - `[H]` ★ [Non-Decreasing Subsequences](https://usaco.org/index.php?page=viewproblem2&cpid=997)
  - `[H]` ★ [Greatest Chicken Dish](https://codeforces.com/gym/101991/problem/G)
  - `[H]` ★ [Quick Tortoise](https://codeforces.com/contest/232/problem/E)

#### 2.18.5 CDQ Divide and Conquer

- **ID:** `cdq_divide_and_conquer` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/cdq_divide_and_conquer
- **Resources (5):**
  - ★ [A Simple Introduction to CDQ Divide and Conquer | A Simple Blog](https://robert1003.github.io/2020/01/31/cdq-divide-and-conquer.html)
  - ★ [Applications of Divide and Conquer | mzhang2021](https://mzhang2021.github.io/cp-blog/divide-and-conquer/)
  - [More about Query Problem | HKOI Training Camp](https://assets.hkoi.org/training2018/dc.pdf)
  - [A comment by Rezwan.Arefin01](https://codeforces.com/blog/entry/68263?#comment-525816)
  - [Divide and Conquer for solving Insert-Query Problems Offline | Rezwan's CP Blog](https://cpblog.rezwanarefin.me/posts/dnc-insert-query/)
- **Problems (4):**
  - `[E]` ★ [Another Longest Increasing Subsequence Problem](https://www.spoj.com/problems/LIS2/)
  - `[M]` [三維偏序問題](https://zerojudge.tw/ShowProblem?problemid=c571)
  - `[M]` [Intersection of Permutations](https://codeforces.com/contest/1093/problem/E)
  - `[H]` ★ [Dynamic Inversion](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3141)

#### 2.18.6 Queue Undo Trick

- **ID:** `queue_undo_trick` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/queue_undo_trick
- **Templates (1):**
  - [Queue Undo Trick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Queue%20Undo%20Trick.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] Supporting Queue-like Undoing on DS | By Noam527](https://codeforces.com/blog/entry/83467)
- **Problems (3):**
  - `[M]` ★ [Joker](https://codeforces.com/contest/1386/problem/C)
  - `[M]` [Sum](https://codeforces.com/contest/1442/problem/D)
  - `[M]` ★ [Fairy](https://codeforces.com/contest/19/problem/E)

#### 2.18.7 Priority Queue Undo Trick

- **ID:** `priority_queue_undo_trick` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/priority_queue_undo_trick
- **Templates (1):**
  - [81ba61f5e1e508e5f7e1d536dfd19958](https://gist.github.com/brunomaletta/81ba61f5e1e508e5f7e1d536dfd19958)
- **Resources (1):**
  - ★ [\[Tutorial\] Supporting Priority-Queue-like Undoing on DS By Monogon](https://codeforces.com/blog/entry/111117)
- **Problems (2):**
  - `[M]` ★ [Joker](https://codeforces.com/contest/1386/problem/C)
  - `[H]` [Pastoral Oddities (Copy)](https://codeforces.com/contest/603/problem/E)

---

## 3. Graph Theory

**Category ID:** `graph_theory` · **Subcategories:** 21 · **Topics:** 103

### 3.1 Graph Traversal

**Subcategory ID:** `graph_traversal` · **Topics:** 7

#### 3.1.1 Depth First Search (DFS)

- **ID:** `dfs` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/dfs
- **Templates (1):**
  - [DFS.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/DFS.cpp)
- **Resources (10):**
  - ★ [A Gentle Introduction To Graph Theory | Vaidehi Joshi](https://medium.com/basecs/a-gentle-introduction-to-graph-theory-77969829ead8)
  - ★ [Depth First Search (DFS) Explained: Algorithm, Examples, and Code | Reducible](https://www.youtube.com/watch?v=PMMc4VsIacU)
  - ★ [Depth First Search Algorithm | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=7fujbpJ0LB4)
  - ★ [Depth First Search (DFS) | Programiz](https://www.programiz.com/dsa/graph-dfs)
  - [Depth First Search or DFS for a Graph | Geeks For Geeks](https://www.geeksforgeeks.org/depth-first-search-or-dfs-for-a-graph/)
  - ★ [Depth first search | CS Academy](https://csacademy.com/lesson/depth_first_search)
  - ★ [Depth First Search | CP Algorithms](https://cp-algorithms.com/graph/depth-first-search.html)
  - ★ [Check whether a graph is bipartite | CP Algorithms](https://cp-algorithms.com/graph/bipartite-check.html)
  - [Depth First Search | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/depth-first-search/tutorial/)
  - ★ [Introduction to Tree Algorithms | USACO Guide](https://usaco.guide/silver/intro-tree?lang=cpp)
- **Problems (39):**
  - `[E]` ★ [Building Roads](https://cses.fi/problemset/task/1666)
  - `[E]` ★ [Subordinates](https://cses.fi/problemset/task/1674)
  - `[E]` ★ [Kefa and Park](https://codeforces.com/problemset/problem/580/C)
  - `[E]` ★ [Transformation: from A to B](https://codeforces.com/contest/727/problem/A)
  - `[E]` ★ [Ring road](https://codeforces.com/contest/24/problem/A)
  - `[E]` ★ [Send the Fool Further! (easy)](https://codeforces.com/contest/802/problem/J)
  - `[E]` ★ [Fence Planning](https://usaco.org/index.php?page=viewproblem2&cpid=944)
  - `[E]` [Mail Stamps](https://codeforces.com/contest/29/problem/C)
  - `[E]` ★ [Counting Rooms](https://cses.fi/problemset/task/1192)
  - `[E]` [Closing the Farm](https://usaco.org/index.php?page=viewproblem2&cpid=644)
  - `[E]` ★ [The Tag Game](https://codeforces.com/contest/813/problem/C)
  - `[E]` ★ [Building Teams](https://cses.fi/problemset/task/1668)
  - `[E]` ★ [A Bug’s Life](https://www.spoj.com/problems/BUGLIFE/)
  - `[E]` ★ [Mahmoud and Ehab and the bipartiteness](https://codeforces.com/contest/862/problem/B)
  - `[E]` ★ [Maze](https://codeforces.com/contest/378/problem/C)
  - `[E]` [Ice Cave](https://codeforces.com/contest/540/problem/C)
  - `[E]` [PolandBall and Forest](https://codeforces.com/contest/755/problem/C)
  - `[E]` [Maximize the Largest Component (Easy Version)](https://codeforces.com/contest/1985/problem/H1)
  - `[E]` [Lunar New Year and a Wander](https://codeforces.com/problemset/problem/1106/D)
  - `[E]` [Cut 'em all!](https://codeforces.com/contest/982/problem/C)
  - `[E]` [Edgy Trees](https://codeforces.com/problemset/problem/1139/C)
  - `[E]` ★ [A Wide, Wide Graph](https://codeforces.com/contest/1805/problem/D)
  - `[E]` [Trapped in the Witch's Labyrinth](https://codeforces.com/problemset/problem/2034/C)
  - `[E]` [Kirei Attacks the Estate](https://codeforces.com/problemset/problem/2114/E)
  - `[M]` ★ [Ada and Island](https://www.spoj.com/problems/ADASEA/)
  - `[M]` ★ [Sheep](https://www.spoj.com/problems/KOZE/)
  - `[M]` ★ [Road Improvement](https://codeforces.com/contest/638/problem/C)
  - `[M]` [Garland](https://codeforces.com/contest/767/problem/C)
  - `[M]` [Labelling Cities](https://codeforces.com/contest/794/problem/D)
  - `[M]` ★ [Leha and another game about graph](https://codeforces.com/contest/841/problem/D)
  - `[M]` [Ant on the Tree](https://codeforces.com/contest/29/problem/D)
  - `[M]` [Round Dance](https://codeforces.com/contest/1833/problem/E)
  - `[M]` ★ [Graph Without Long Directed Paths](https://codeforces.com/contest/1144/problem/F)
  - `[M]` ★ [Cover it!](https://codeforces.com/problemset/problem/1176/E)
  - `[M]` ★ [Beautiful Graph](https://codeforces.com/contest/1093/problem/D)
  - `[M]` [Cyclic Components](https://codeforces.com/contest/977/problem/E)
  - `[H]` [Dasha and Puzzle](https://codeforces.com/contest/761/problem/E)
  - `[H]` [Upgrading Tree](https://codeforces.com/contest/844/problem/E)
  - `[H]` [Centroids](https://codeforces.com/contest/709/problem/E)

#### 3.1.2 Breadth First Search (BFS)

- **ID:** `bfs` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/bfs
- **Templates (1):**
  - [BFS.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/BFS.cpp)
- **Resources (9):**
  - ★ [Breadth First Search (BFS): Visualized and Explained | Reducible](https://www.youtube.com/watch?v=xlVX7dXLS64)
  - [Breadth First Search Algorithm | Shortest Path | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=oDqjPvD54Ss)
  - ★ [Breadth First Search grid shortest path | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=KiCBXu4P-2Y)
  - ★ [Breadth-first search | CP Algorithms](https://cp-algorithms.com/graph/breadth-first-search.html)
  - ★ [Breadth first search | CS Academy](https://csacademy.com/lesson/breadth_first_search)
  - ★ [Breadth First Search | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/tutorial/)
  - [Breadth first search | Programiz](https://www.programiz.com/dsa/graph-bfs)
  - [গ্রাফ থিওরিতে হাতেখড়ি-৪(ব্রেডথ ফার্স্ট সার্চ) | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=604)
  - [Multisource BFS | Devansh](https://medium.com/geekculture/multisource-bfs-for-your-faang-coding-interviews-d5177753f507)
- **Problems (32):**
  - `[E]` ★ [Message Route](https://cses.fi/problemset/task/1667)
  - `[E]` ★ [King's Path](https://codeforces.com/contest/242/problem/C)
  - `[E]` [Minimum Knight moves !!!](https://www.spoj.com/problems/NAKANJ/)
  - `[E]` ★ [Maze](https://codeforces.com/contest/378/problem/C)
  - `[E]` ★ [Labyrinth](https://cses.fi/problemset/task/1193)
  - `[E]` ★ [Cycle In Maze](https://codeforces.com/contest/769/problem/C)
  - `[E]` [Ada and Cycle](https://www.spoj.com/problems/ADACYCLE/)
  - `[E]` [Find the Treasure](https://www.spoj.com/problems/DIGOKEYS/)
  - `[E]` [A Node Too Far](https://vjudge.net/problem/UVA-336)
  - `[E]` [Word Transformation](https://vjudge.net/problem/UVA-429)
  - `[E]` [Knight Moves](https://vjudge.net/problem/UVA-439)
  - `[E]` [Ice Cave](https://codeforces.com/contest/540/problem/C)
  - `[E]` [BFS-DFS](https://csacademy.com/contest/archive/task/bfs-dfs/statement/)
  - `[E]` ★ [Getting Zero](https://codeforces.com/problemset/problem/1661/B)
  - `[E]` ★ [Rudolf and the Ball Game](https://codeforces.com/contest/1941/problem/D)
  - `[E]` [Do use hexagon grid](https://atcoder.jp/contests/abc269/tasks/abc269_d)
  - `[M]` ★ [Police Stations](https://codeforces.com/contest/796/problem/D)
  - `[M]` ★ [Valid BFS?](https://codeforces.com/contest/1037/problem/D)
  - `[M]` ★ [Nearest Excluded Points](https://codeforces.com/contest/1651/problem/D)
  - `[M]` ★ [Fire Again](https://codeforces.com/contest/35/problem/C)
  - `[M]` [Shortest Path](https://codeforces.com/problemset/problem/59/E)
  - `[M]` ★ [Monsters](https://cses.fi/problemset/task/1194)
  - `[M]` ★ [Yet Another Multiple Problem](https://www.spoj.com/problems/MULTII/)
  - `[M]` [Bombs! NO they are Mines!!](https://vjudge.net/problem/UVA-10653)
  - `[M]` ★ [Nearest Opposite Parity](https://codeforces.com/contest/1272/problem/E)
  - `[M]` ★ [Graph Girth](https://cses.fi/problemset/task/1707)
  - `[M]` [Swap Game](https://cses.fi/problemset/task/1670/)
  - `[M]` ★ [Small Multiple](https://atcoder.jp/contests/arc084/tasks/arc084_b)
  - `[M]` [Two Buttons](https://codeforces.com/problemset/problem/520/B)
  - `[M]` [Gardener and Tree](https://codeforces.com/problemset/problem/1593/E)
  - `[H]` [Egor in the Republic of Dagestan](https://codeforces.com/problemset/problem/1407/E)
  - `[H]` ★ [Construct a Palindrome](https://atcoder.jp/contests/abc197/tasks/abc197_f)

#### 3.1.3 DFS Tree

- **ID:** `dfs_tree` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/dfs_tree
- **Resources (1):**
  - [\[Tutorial\] The DFS tree and its applications: how I found out I really didn't understand bridges By -is-this-fft-](https://codeforces.com/blog/entry/68138)
- **Problems (15):**
  - `[E]` ★ [Bertown roads](https://codeforces.com/contest/118/problem/E)
  - `[E]` ★ [Cactus](https://www.spoj.com/problems/CAC/)
  - `[E]` [One-Way Streets](https://oj.uz/problem/view/CEOI17_oneway)
  - `[E]` ★ [Strongly Connected Edges](https://cses.fi/problemset/task/2177)
  - `[M]` [Wizard's Tour](https://codeforces.com/contest/861/problem/F)
  - `[M]` ★ [Cactus](https://codeforces.com/contest/231/problem/E)
  - `[M]` ★ [Pairs of Pairs](https://codeforces.com/contest/1391/problem/E)
  - `[M]` [Giving Awards](https://codeforces.com/contest/412/problem/D)
  - `[M]` [Grand Test](https://codeforces.com/gym/101612/problem/G)
  - `[M]` [Ehab's Last Corollary](https://codeforces.com/contest/1364/problem/D)
  - `[M]` [Two Fairs](https://codeforces.com/contest/1277/problem/E)
  - `[M]` ★ [Ehab's Last Theorem](https://codeforces.com/problemset/problem/1325/F)
  - `[M]` ★ [Tourist Reform](https://codeforces.com/contest/732/problem/F)
  - `[M]` ★ [Fairy](https://codeforces.com/contest/19/problem/E)
  - `[H]` ★ [Simple Cycles Edges](https://codeforces.com/contest/962/problem/F)

#### 3.1.4 Topological Sorting

- **ID:** `topological_sorting` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/topological_sorting
- **Templates (1):**
  - [Topological Sorting.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Topological%20Sorting.cpp)
- **Resources (5):**
  - ★ [Topological Sorting | CP Algorithms](https://cp-algorithms.com/graph/topological-sort.html)
  - ★ [Topological Sort Algorithm | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=eL-KzMXSXXI)
  - ★ [Topological Sort | Kahn's Algorithm | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=cIBFEhD77b4)
  - [Topological Sorting | Geeks For Geeks](https://www.geeksforgeeks.org/topological-sorting/)
  - ★ [\[Insight\] Number of Topological Orderings of a Directed Tree By Osama_Alkhodairy](https://codeforces.com/blog/entry/75627)
- **Problems (13):**
  - `[E]` ★ [Course Schedule](https://cses.fi/problemset/task/1679)
  - `[E]` ★ [Topological Sorting](https://www.spoj.com/problems/TOPOSORT/)
  - `[E]` [Ordering Tasks](https://vjudge.net/problem/UVA-10305)
  - `[E]` ★ [Max Tree](https://codeforces.com/problemset/problem/2143/C)
  - `[E]` ★ [Fox And Names](https://codeforces.com/problemset/problem/510/C)
  - `[E]` [Answer the boss!](https://www.spoj.com/problems/RPLA/)
  - `[E]` ★ [Find Permutation](https://atcoder.jp/contests/abc291/tasks/abc291_e)
  - `[E]` [Chat Screenshots](https://codeforces.com/problemset/problem/1931/F)
  - `[M]` ★ [Count Ways to Build Rooms in an Ant Colony](https://leetcode.com/problems/count-ways-to-build-rooms-in-an-ant-colony/description/)
  - `[M]` [Build Towers](https://www.codechef.com/problems/BUILDT)
  - `[M]` ★ [Permutation Counting](https://codeforces.com/gym/103741/problem/H)
  - `[M]` [Directing Edges](https://codeforces.com/contest/1385/problem/E)
  - `[H]` ★ [Topological Sort](https://codeforces.com/gym/101102/problem/K)

#### 3.1.5 Tree Diameter

- **ID:** `tree_diameter` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/tree_diameter
- **Templates (1):**
  - [Tree Diameter.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Tree%20Diameter.cpp)
- **Resources (2):**
  - ★ [\[Tutorial\] Diameter of a tree and its applications By TheScrasse](https://codeforces.com/blog/entry/101271)
  - [AlgorithmsThread 8: Tree Basics](https://www.youtube.com/watch?v=MOy4UDjN8DM)
- **Problems (19):**
  - `[E]` ★ [Tree Diameter](https://cses.fi/problemset/task/1131)
  - `[E]` ★ [Tree Distances I](https://cses.fi/problemset/task/1132)
  - `[E]` ★ [Eagle and Dogs](https://www.spoj.com/problems/EAGLE1/)
  - `[E]` [Circumference of a Tree](https://codeforces.com/gym/102694/problem/A)
  - `[E]` [Dynamic Diameter](https://codeforces.com/gym/102694/problem/B)
  - `[E]` ★ [A Wide, Wide Graph](https://codeforces.com/contest/1805/problem/D)
  - `[M]` ★ [Anton and Tree](https://codeforces.com/problemset/problem/734/E)
  - `[M]` ★ [Removing Coins](https://atcoder.jp/contests/agc033/tasks/agc033_c)
  - `[M]` [Tree Tag](https://codeforces.com/contest/1404/problem/B)
  - `[M]` [Civilization](https://codeforces.com/contest/456/problem/E)
  - `[M]` ★ [Three paths on a tree](https://codeforces.com/contest/1294/problem/F)
  - `[H]` [Sonya and Ice Cream](https://codeforces.com/contest/1004/problem/E)
  - `[H]` ★ [Tree Compass](https://codeforces.com/contest/1943/problem/C)
  - `[H]` [The Chocolate Spree](https://codeforces.com/contest/633/problem/F)
  - `[H]` ★ [Miracle Tree](https://atcoder.jp/contests/arc117/tasks/arc117_d)
  - `[H]` ★ [Paint Tree](https://atcoder.jp/contests/arc108/tasks/arc108_f)
  - `[H]` [Diameter set](https://atcoder.jp/contests/abc221/tasks/abc221_f)
  - `[VH]` ★ [Roads and Ramen](https://codeforces.com/contest/1434/problem/D)
  - `[VH]` [Tiles Placement](https://codeforces.com/contest/1214/problem/H)

#### 3.1.6 Euler Tour Technique

- **ID:** `euler_tour_technique` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/euler_tour_technique
- **Resources (6):**
  - ★ [Euler Tour Technique | USACO Guide](https://usaco.guide/gold/tree-euler?lang=cpp)
  - ★ [AlgorithmsThread 8: Tree Basics](https://youtu.be/MOy4UDjN8DM?t=1504&si=HhXhEzFVoJO9t7KV)
  - ★ [18.2 - Subtrees & Paths | CPH](https://usaco.guide/CPH.pdf#page=174)
  - [L01 : Euler Tour Technique or Tree Flattening | Queries On Tree | CodeNCode](https://www.youtube.com/watch?v=AsXUVGh6WKI)
  - [Euler Tour of Tree | Geeks For Geeks](https://www.geeksforgeeks.org/euler-tour-tree/)
  - ★ [12. Euler tour magic, General ideas | adamant](https://codeforces.com/blog/entry/48417)
- **Problems (11):**
  - `[E]` ★ [Subtree Queries](https://cses.fi/problemset/task/1137)
  - `[E]` [Filthy Rich Trees](https://codeforces.com/gym/102694/problem/E)
  - `[E]` ★ [Underground Lab](https://codeforces.com/contest/781/problem/C)
  - `[M]` [Jamie and Tree](https://codeforces.com/contest/916/problem/E)
  - `[M]` [The Lorax](https://codeforces.com/gym/102694/problem/F)
  - `[M]` [New Year Tree](https://codeforces.com/problemset/problem/620/E)
  - `[M]` ★ [Klasika](https://oj.uz/problem/view/COCI20_klasika)
  - `[M]` [Blood Cousins](https://codeforces.com/contest/208/problem/E)
  - `[M]` [Water Tree](https://codeforces.com/problemset/problem/343/D)
  - `[M]` ★ [Danil and a Part-time Job](https://codeforces.com/problemset/problem/877/E)
  - `[M]` ★ [Distance Queries on a Tree](https://atcoder.jp/contests/abc294/tasks/abc294_g)

#### 3.1.7 Inverse Graph

- **ID:** `inverse_graph` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/inverse_graph
- **Templates (1):**
  - [Inverse Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Inverse%20Graph.cpp)
- **Resources (2):**
  - ★ [BFS Trick (Pie for a Pie trick) | By tdpencil](https://codeforces.com/blog/entry/93652)
  - ★ [Traversing the complement graph in linear/near-linear time in multiple ways | By nor](https://codeforces.com/blog/entry/93801)
- **Problems (11):**
  - `[E]` ★ [Connected Components of Complement Graph](https://judge.yosupo.jp/problem/connected_components_of_complement_graph)
  - `[E]` ★ [Connected Components?](https://codeforces.com/problemset/problem/920/E)
  - `[E]` ★ [0-1 MST](https://codeforces.com/problemset/problem/1242/B)
  - `[M]` [Counter Attack](https://codeforces.com/contest/190/problem/E)
  - `[M]` ★ [A Pie for a Pie](https://usaco.org/index.php?page=viewproblem2&cpid=765)
  - `[M]` [Bear and Forgotten Tree 2](https://codeforces.com/contest/653/problem/E)
  - `[M]` [Complete the MST](https://codeforces.com/contest/1508/problem/C)
  - `[M]` ★ [Flight Plans](https://open.kattis.com/problems/flightplans)
  - `[M]` [Rust & Murderer](https://www.hackerrank.com/challenges/rust-murderer/problem)
  - `[H]` ★ [Topological Sort](https://codeforces.com/gym/101102/problem/K)
  - `[H]` [Nezzar and Hidden Permutations](https://codeforces.com/contest/1477/problem/D)

### 3.2 Lowest Common Ancestor (LCA)

**Subcategory ID:** `lca` · **Topics:** 2

#### 3.2.1 Binary Lifting and LCA

- **ID:** `binary_lifting_and_lca` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/binary_lifting_and_lca
- **Templates (1):**
  - [LCA.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/LCA.cpp)
- **Resources (7):**
  - ★ [Binary Lifting (Kth Ancestor of a Tree Node) | Errichto](https://www.youtube.com/watch?v=oib-XsjFa-M)
  - ★ [LCA – Lowest Common Ancestor | Errichto](https://www.youtube.com/watch?v=dOAxrhAUIhA)
  - ★ [Lowest Common Ancestor - Binary Lifting | CP Algorithms](https://cp-algorithms.com/graph/lca_binary_lifting.html)
  - [AlgorithmsThread 8: Tree Basics](https://youtu.be/MOy4UDjN8DM?t=1057&si=YJIZrm_NKMJzv076)
  - ★ [Binary Jumping and LCA | USACO Guide](https://usaco.guide/plat/binary-jump?lang=cpp)
  - [18.3 Lowest common ancestor | CPH](https://usaco.guide/CPH.pdf#page=177)
  - [Binary Lifting | aryansh](https://aryansh.gitbook.io/informatics-notes/binary-lifting/binary-lifting-gold-part-1)
- **Problems (47):**
  - `[E]` ★ [Company Queries I](https://cses.fi/problemset/task/1687)
  - `[E]` ★ [Company Queries II](https://cses.fi/problemset/task/1688)
  - `[E]` [Lowest Common Ancestor](https://judge.yosupo.jp/problem/lca)
  - `[E]` ★ [Distance Queries](https://cses.fi/problemset/task/1135)
  - `[E]` ★ [Jump on Tree](https://judge.yosupo.jp/problem/jump_on_tree)
  - `[E]` ★ [Distance Query](https://www.spoj.com/problems/DISQUERY/)
  - `[E]` ★ [Kth Ancestor](https://www.hackerrank.com/challenges/kth-ancestor/problem)
  - `[E]` ★ [A Secret Mission](https://lightoj.com/problem/a-secret-mission)
  - `[E]` ★ [Planets Queries I](https://cses.fi/problemset/task/1750)
  - `[E]` ★ [Sloth Naptime](https://codeforces.com/gym/102694/problem/C)
  - `[E]` ★ [Cycle Free Flow](https://codeforces.com/gym/102694/problem/D)
  - `[E]` [Min Max Roads](https://lightoj.com/problem/min-max-roads)
  - `[E]` ★ [Tree Queries](https://codeforces.com/contest/1328/problem/E)
  - `[E]` ★ [Passable Paths (hard version)](https://codeforces.com/contest/1702/problem/G2)
  - `[E]` [Misha, Grisha and Underground](https://codeforces.com/contest/832/problem/D)
  - `[E]` ★ [Query on a tree II](https://www.spoj.com/problems/QTREE2/)
  - `[E]` ★ [Lynyrd Skynyrd](https://codeforces.com/contest/1142/problem/B)
  - `[E]` ★ [Planets Queries II](https://cses.fi/problemset/task/1160)
  - `[M]` ★ [City of Atlantis](https://toph.co/p/city-of-atlantis)
  - `[M]` [Blood Cousins](https://codeforces.com/contest/208/problem/E)
  - `[M]` ★ [Longest Good Segment](https://www.codechef.com/problems/LGSEG)
  - `[M]` ★ [Cyclic Array](https://cses.fi/problemset/task/1191/)
  - `[M]` [Archaeology](https://codeforces.com/contest/176/problem/E)
  - `[M]` [Fools and Roads](https://codeforces.com/contest/191/problem/C)
  - `[M]` [Information Graph](https://codeforces.com/contest/466/problem/E)
  - `[M]` ★ [A and B and Lecture Rooms](https://codeforces.com/contest/519/problem/E)
  - `[M]` [Duff in the Army](https://codeforces.com/contest/587/problem/C)
  - `[M]` ★ [Minimum spanning tree for each edge](https://codeforces.com/contest/609/problem/E)
  - `[M]` [Optimal Connectivity](https://www.hackerearth.com/practice/algorithms/graphs/graph-representation/practice-problems/algorithm/optimal-connectivity-c6ae79ca/)
  - `[M]` ★ [Lowest Common Ancestor](https://www.codechef.com/problems/TALCA)
  - `[M]` [Famil Door and Roads](https://codeforces.com/contest/629/problem/E)
  - `[M]` ★ [Root LCA Queries](https://csacademy.com/contest/archive/task/root-lca-queries/statement/)
  - `[M]` [Drivers Dissatisfaction](https://codeforces.com/contest/733/problem/F)
  - `[M]` [Rowena Ravenclaw's Diadem](https://codeforces.com/contest/855/problem/D)
  - `[M]` [Jamie and Tree](https://codeforces.com/contest/916/problem/E)
  - `[M]` [Ada and Orange Tree](https://www.spoj.com/problems/ADAORANG/)
  - `[M]` ★ [Omsk Metro (hard version)](https://codeforces.com/contest/1843/problem/F2)
  - `[M]` ★ [SSttrriinngg in StringString](https://atcoder.jp/contests/abc346/tasks/abc346_f)
  - `[M]` ★ [Surveillance](https://vjudge.net/problem/Kattis-surveillance)
  - `[M]` ★ [Fun With Functions](https://toph.co/p/fun-with-functions)
  - `[M]` ★ [Static Tree](https://toph.co/p/static-tree)
  - `[M]` [Two-Paths](https://codeforces.com/problemset/problem/1000/G)
  - `[M]` [Minimal Segment Cover](https://codeforces.com/contest/1175/problem/E)
  - `[H]` ★ [Choosing Subtree is Fun](https://codeforces.com/contest/372/problem/D)
  - `[H]` [Prince's Problem](https://codeforces.com/contest/986/problem/E)
  - `[H]` [Functional Constraint](https://tlx.toki.id/problems/troc-12/F)
  - `[H]` [Graph and Destination](https://tlx.toki.id/problems/troc-13/G)

#### 3.2.2 LCA in O(1)

- **ID:** `lca_in_o1` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lca_in_o1
- **Templates (1):**
  - [LCA in O(1).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/LCA%20in%20O%281%29.cpp)
- **Resources (4):**
  - ★ [RANGE MINIMUM QUERY AND LOWEST COMMON ANCESTOR | Topcoder](https://www.topcoder.com/thrive/articles/Range%20Minimum%20Query%20and%20Lowest%20Common%20Ancestor)
  - ★ [Lowest Common Ancestor - $O(\\sqrt{N})$ and $O(\\log N)$ with $O(N)$ preprocessing | CP Algorithms](https://cp-algorithms.com/graph/lca.html)
  - ★ [Lowest Common Ancestor - Tarjan's off-line algorithm | CP Algorithms](https://cp-algorithms.com/graph/lca_tarjan.html)
  - [Lowest Common Ancestor (LCA) Problem | Eulerian path method | WilliamFiset](https://www.youtube.com/watch?v=sD1IoalFomA)

### 3.3 Graph Connectivity

**Subcategory ID:** `graph_connectivity` · **Topics:** 9

#### 3.3.1 Strongly Connected Components (SCC)

- **ID:** `scc` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/scc
- **Templates (1):**
  - [SCC.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/SCC.cpp)
- **Resources (6):**
  - ★ [Finding strongly connected components / Building condensation graph | CP Algorithms](https://cp-algorithms.com/graph/strongly-connected-components.html#toc-tgt-5)
  - [Tarjan's Strongly Connected Component (SCC) Algorithm (UPDATED) | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=wUgWX0nc4NY)
  - [Strongly Connected Components | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/strongly-connected-components/tutorial/)
  - [Strongly Connected Components | USACO Guide](https://usaco.guide/adv/SCC?lang=cpp)
  - [Strong connectivity and Kosaraju's Algorithm | CPH](https://usaco.guide/CPH.pdf#page=167)
  - [\[Bangla\] গ্রাফ থিওরিতে হাতেখড়ি ১৪ – স্ট্রংলি কানেক্টেড কম্পোনেন্ট](https://www.shafaetsplanet.com/?p=2531)
- **Problems (19):**
  - `[E]` ★ [Strongly Connected Components](https://judge.yosupo.jp/problem/scc)
  - `[E]` ★ [Flight Routes Check](https://cses.fi/problemset/task/1682)
  - `[E]` ★ [Planets and Kingdoms](https://cses.fi/problemset/task/1683/)
  - `[E]` [Good Travels](https://www.spoj.com/problems/GOODA/)
  - `[E]` [Lego](https://www.spoj.com/problems/LEGO/)
  - `[E]` [Chef and Round Run](https://www.codechef.com/AUG16/problems/CHEFRRUN)
  - `[E]` ★ [Capital City](https://www.spoj.com/problems/CAPCITY/)
  - `[E]` ★ [Checkposts](https://codeforces.com/contest/427/problem/C)
  - `[E]` [Bike paths](https://szkopul.edu.pl/problemset/problem/aKKSmtjWTtDOEHDqnmQ3-eAA/site/?key=statement)
  - `[M]` ★ [Coin Collector](https://cses.fi/problemset/task/1686/)
  - `[M]` [Mr. Kitayuta's Technology](https://codeforces.com/contest/505/problem/D)
  - `[M]` [True Friends](https://www.spoj.com/problems/TFRIENDS/)
  - `[M]` [Scheme](https://codeforces.com/contest/22/problem/E)
  - `[M]` ★ [Ada and Panels](https://www.spoj.com/problems/ADAPANEL/)
  - `[M]` ★ [Ralph and Mushrooms](https://codeforces.com/contest/894/problem/E)
  - `[M]` [Catowice City](https://codeforces.com/contest/1239/problem/D)
  - `[M]` [Valuable Paper](https://codeforces.com/problemset/problem/1423/B)
  - `[H]` ★ [New Flight Routes](https://cses.fi/problemset/task/1685)
  - `[VH]` [Falling Sand (Hard Version)](https://codeforces.com/contest/1534/problem/F2)

#### 3.3.2 Incremental SCC

- **ID:** `incremental_scc` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/incremental_scc
- **Resources (2):**
  - ★ [My own algorithm — offline incremental strongly connected components in O(m*log(m)) By Radewoosh](https://codeforces.com/blog/entry/91608)
  - [Incremental Topological Ordering and Strong Component Maintenance | Paper by Bernhard Haeupler, Siddhartha Sen, Robert E. Tarjan](https://arxiv.org/abs/0803.0792)
- **Problems (3):**
  - `[M]` ★ [Strongly Connected Components (Incremental)](https://judge.yosupo.jp/problem/incremental_scc)
  - `[H]` [Link Cut Digraph](https://www.acmicpc.net/problem/19028)
  - `[VH]` [Simultaneous Coloring](https://codeforces.com/contest/1989/problem/F)

#### 3.3.3 Articulation Bridges and Bridge Tree

- **ID:** `articulation_bridges_and_bridge_tree` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/articulation_bridges_and_bridge_tree
- **Templates (1):**
  - [Articulation Bridges.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Articulation%20Bridges.cpp)
- **Resources (5):**
  - ★ [Finding bridges in a graph in O(N + M) | CP Algorithms](https://cp-algorithms.com/graph/bridge-searching.html)
  - ★ [Bridge Trees \[Tutorial\] By aryan12](https://codeforces.com/blog/entry/99259)
  - [Articulation points and bridges (Tarjan's Algorithm) By searleser97](https://codeforces.com/blog/entry/71146)
  - [Articulation Points and Bridges | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/articulation-points-and-bridges/tutorial/)
  - [The "Bridge Tree" of a graph | Tanuj Khattar](https://threadsiiithyderabad.quora.com/The-Bridge-Tree-of-a-graph)
- **Problems (18):**
  - `[E]` ★ [Two-Edge-Connected Components](https://judge.yosupo.jp/problem/two_edge_connected_components)
  - `[E]` ★ [We Need More Bosses](https://codeforces.com/problemset/problem/1000/E)
  - `[E]` [Critical Edges](https://www.spoj.com/problems/EC_P/)
  - `[E]` [Critical Links](https://vjudge.net/problem/UVA-796)
  - `[E]` [Street Directions](https://vjudge.net/problem/UVA-610)
  - `[E]` [One-Way Streets](https://oj.uz/problem/view/CEOI17_oneway)
  - `[E]` ★ [Pursuit For Artifacts](https://codeforces.com/problemset/problem/652/E)
  - `[M]` ★ [Computer Network](https://codeforces.com/gym/100114/problem/J)
  - `[M]` [King Graffs Defense](https://www.spoj.com/problems/GRAFFDEF/)
  - `[M]` ★ [Tourist Reform](https://codeforces.com/contest/732/problem/F)
  - `[M]` [Break Up](https://codeforces.com/contest/700/problem/C)
  - `[M]` ★ [Capital City](https://codeforces.com/gym/100676/problem/H)
  - `[M]` [Delete and Cut Game](https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/practice-problems/algorithm/delete-and-cut-game-91969de1/)
  - `[M]` [Code Land](https://www.codechef.com/problems/PRCNSR2)
  - `[M]` ★ [Rada and the Chamomile Valley](https://codeforces.com/contest/2132/problem/F)
  - `[M]` [Rada and the Chamomile Valley](https://codeforces.com/contest/1986/problem/F)
  - `[H]` ★ [Case of Computer Network](https://codeforces.com/contest/555/problem/E)
  - `[H]` ★ [Sherlock and Queries on the Graph](https://www.hackerrank.com/contests/101hack26/challenges/sherlock-and-queries-on-the-graph/problem)

#### 3.3.4 Online Articulation Bridges

- **ID:** `online_articulation_bridges` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/online_articulation_bridges
- **Templates (1):**
  - [Online Articulation Bridges.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Online%20Articulation%20Bridges.cpp)
- **Resources (1):**
  - [Finding Bridges Online | CP Algorithms](https://cp-algorithms.com/graph/bridge-searching-online.html)
- **Problems (1):**
  - `[M]` ★ [GraphAero](https://codeforces.com/gym/100551/problem/B)

#### 3.3.5 Articulation Points and Block Cut Tree

- **ID:** `articulation_points` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/articulation_points
- **Templates (2):**
  - [Articulation Points.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Articulation%20Points.cpp)
  - [Block Cut Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Block%20Cut%20Tree.cpp)
- **Resources (4):**
  - ★ [Finding articulation points in a graph in O(N + M) | CP Algorithms](https://cp-algorithms.com/graph/cutpoints.html)
  - [Articulation Points and Bridges | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/articulation-points-and-bridges/tutorial/)
  - ★ [Biconnected Components | USACO Guide](https://usaco.guide/adv/BCC-2CC?lang=cpp#biconnected-components)
  - ★ [Block-cut tree | Wiki](https://en.wikipedia.org/wiki/Biconnected_component#Block-cut_tree)
- **Problems (14):**
  - `[E]` ★ [Network](https://vjudge.net/problem/UVA-315)
  - `[E]` ★ [Tourist Guide](https://vjudge.net/problem/UVA-10199)
  - `[E]` [Doves and bombs](https://vjudge.net/problem/UVA-10765)
  - `[E]` ★ [Biconnected Components](https://judge.yosupo.jp/problem/biconnected_components)
  - `[M]` ★ [Forbidden Cities](https://cses.fi/problemset/task/1705)
  - `[M]` ★ [Submerging Islands](https://www.spoj.com/problems/SUBMERGE/)
  - `[M]` [Blockade](https://szkopul.edu.pl/problemset/problem/eDt8w290owtatmCjad0O0ywk/site/?key=statement)
  - `[M]` [Duathlon](https://oj.uz/problem/view/APIO18_duathlon)
  - `[M]` [Amusing journeys](https://szkopul.edu.pl/problemset/problem/YY6-3ua-C1rt7q-97laWc0UP/site/?key=statement)
  - `[M]` ★ [Leakage](https://codeforces.com/gym/102512/problem/A)
  - `[M]` [Stopping-off Cities](https://www.spoj.com/problems/STOPCITY/)
  - `[H]` [Investment](https://dmoj.ca/problem/tle17c1p6)
  - `[H]` [Pipes](https://oj.uz/problem/view/CEOI15_pipes)
  - `[H]` ★ [Chef and Sad Pairs](https://www.codechef.com/problems/SADPAIRS)

#### 3.3.6 Three Edge Connectivity

- **ID:** `three_edge_connectivity` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/three_edge_connectivity
- **Templates (1):**
  - [Three Edge Connectivity.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Three%20Edge%20Connectivity.cpp)
- **Resources (1):**
  - [A simple 3-edge connected component algorithm revisited | Paper by Nima Norouzi, Yung H. Tsin](https://www.sciencedirect.com/science/article/abs/pii/S0020019013002470)
- **Problems (2):**
  - `[E]` ★ [Three-Edge-Connected Components](https://judge.yosupo.jp/problem/three_edge_connected_components)
  - `[M]` ★ [MaxFlow (II)](https://toph.co/p/maxflow-ii)

#### 3.3.7 Four Edge Connectivity

- **ID:** `four_edge_connectivity` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/four_edge_connectivity
- **Resources (1):**
  - [Determining 4-edge-connected components in linear time | Paper by Wojciech Nadara, Mateusz Radecki, Marcin Smulewicz, Marek Sokołowski](https://arxiv.org/abs/2105.01699)

#### 3.3.8 Dynamic K-Connectivity

- **ID:** `dynamic_k_connectivity` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_k_connectivity
- **Resources (1):**
  - [Vertex Sparsification for Edge Connectivity](https://arxiv.org/abs/2007.07862)

#### 3.3.9 Ear Decomposition

- **ID:** `ear_decomposition` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/ear_decomposition
- **Resources (1):**
  - ★ [Ear decomposition tutorial By ramchandra](https://codeforces.com/blog/entry/80932)
- **Problems (1):**
  - `[H]` ★ [Economic One-way Roads](https://codeforces.com/gym/102760/problem/C)

### 3.4 Orientation

**Subcategory ID:** `orientation` · **Topics:** 2

#### 3.4.1 Strong Orientation

- **ID:** `strong_orientation` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/strong_orientation
- **Resources (1):**
  - ★ [Strong Orientation | CP Algorithms](https://cp-algorithms.com/graph/strong-orientation.html)
- **Problems (2):**
  - `[E]` ★ [Strongly Connected Edges](https://cses.fi/problemset/task/2177)
  - `[E]` [Zones](https://szkopul.edu.pl/problemset/problem/nldsb4EW1YuZykBlf4lcZL1Y/site/?key=statement)

#### 3.4.2 ST-numbering / Bipolar Orientation

- **ID:** `st_numbering` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/st_numbering
- **Templates (1):**
  - [ST Numbering.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/ST%20Numbering.cpp)
- **Resources (1):**
  - [Bipolar orientation | Wiki](https://en.wikipedia.org/wiki/Bipolar_orientation)
- **Problems (3):**
  - `[E]` ★ [st-Numbering](https://judge.yosupo.jp/problem/st_numbering)
  - `[E]` ★ [Group Division](https://codeforces.com/contest/1916/problem/F)
  - `[M]` ★ [Graph Ordering](https://cses.fi/241/task/C)

### 3.5 Minimum Spanning Tree (MST)

**Subcategory ID:** `minimum_spanning_tree` · **Topics:** 9

#### 3.5.1 Minimum Spanning Tree (Prim's and Kruskal's)

- **ID:** `mst` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/mst
- **Templates (2):**
  - [Prim's MST.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Prim's%20MST.cpp)
  - [Krushkal's MST.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Krushkal's%20MST.cpp)
- **Resources (11):**
  - ★ [Minimum spanning tree - Prim's algorithm | CP Algorithms](https://cp-algorithms.com/graph/mst_prim.html)
  - ★ [Minimum spanning tree - Kruskal's algorithm | CP Algorithms](https://cp-algorithms.com/graph/mst_kruskal.html)
  - ★ [Minimum spanning tree - Kruskal with Disjoint Set Union | CP Algorithms](https://cp-algorithms.com/graph/mst_kruskal_with_dsu.html)
  - [Second Best Minimum Spanning Tree | CP Algorithms](https://cp-algorithms.com/graph/second_best_mst.html)
  - [Minimum Spanning Tree | HackerEarth](https://www.hackerearth.com/practice/algorithms/graphs/minimum-spanning-tree/tutorial/)
  - [Prim's Minimum Spanning Tree Algorithm | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=jsmMtJpPnhU)
  - [Union Find Kruskal's Algorithm | WilliamFiset](https://www.youtube.com/watch?v=JZBQLXgSGfs)
  - [15.3 Prim’s algorithm | CPH](https://usaco.guide/CPH.pdf#page=157)
  - [15.1 - Kruskal's | CPH](https://usaco.guide/CPH.pdf#page=152)
  - ★ [Kruskal Visualizer](https://alexyd88.github.io/Kruskal-Visualizer/)
  - [Minimum Spanning Trees | USACO Guide](https://usaco.guide/gold/mst?lang=cpp)
- **Problems (41):**
  - `[E]` ★ [Spanning Tree](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/E)
  - `[E]` ★ [Road Reparation](https://cses.fi/problemset/task/1675)
  - `[E]` [Dense spanning tree](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/F)
  - `[E]` ★ [Fullmetal Alchemist](https://www.codechef.com/ICL2016/problems/ICL16A)
  - `[E]` [Chefland and Electricity](https://www.codechef.com/problems/CHEFELEC)
  - `[E]` [Flea](https://codeforces.com/problemset/problem/32/C)
  - `[E]` [Igor In the Museum](https://codeforces.com/contest/598/problem/D)
  - `[E]` [Help the old King](https://www.spoj.com/problems/IITKWPCG/)
  - `[E]` [Modems](https://www.spoj.com/problems/EC_MODE/)
  - `[E]` [Heavy Cycle Edges](https://vjudge.net/problem/UVA-11747)
  - `[E]` [Design Tutorial: Inverse the Problem](https://codeforces.com/contest/472/problem/D)
  - `[E]` [Superbull](https://usaco.org/index.php?page=viewproblem2&cpid=531)
  - `[E]` [Fenced In](https://usaco.org/index.php?page=viewproblem2&cpid=623)
  - `[E]` ★ [Better Together!](https://toph.co/p/better-together)
  - `[M]` [Hongcow Builds A Nation](https://codeforces.com/problemset/problem/744/A)
  - `[M]` ★ [Path Queries](https://codeforces.com/contest/1213/problem/G)
  - `[M]` ★ [MinOr Tree](https://codeforces.com/contest/1624/problem/G)
  - `[M]` ★ [Oil business](https://codeforces.com/edu/course/2/lesson/7/2/practice/contest/289391/problem/H)
  - `[M]` ★ [Minimum spanning tree for each edge](https://codeforces.com/contest/609/problem/E)
  - `[M]` ★ [Edges in MST](https://codeforces.com/contest/160/problem/D)
  - `[M]` ★ [Envy](https://codeforces.com/contest/891/problem/C)
  - `[M]` ★ [Cost](https://www.spoj.com/problems/KOICOST/)
  - `[M]` [BMW](https://www.spoj.com/problems/MARYBMW/)
  - `[M]` [Roads in HackerLand](https://www.hackerrank.com/contests/june-world-codesprint/challenges/johnland/problem)
  - `[M]` ★ [Bring Your Own Horse](https://vjudge.net/problem/UVA-12176)
  - `[M]` ★ [GCD and MST](https://codeforces.com/problemset/problem/1513/D)
  - `[M]` ★ [Choose Two and Eat One](https://atcoder.jp/contests/abc282/tasks/abc282_e)
  - `[M]` ★ [Spanning Tree Fraction](https://www.hackerrank.com/contests/w31/challenges/spanning-tree-fraction/problem)
  - `[M]` [ACM Contest and Blackout](https://vjudge.net/problem/UVA-10600)
  - `[M]` [I Would Walk 500 Miles](https://usaco.org/index.php?page=viewproblem2&cpid=946)
  - `[M]` [Moo Network](https://usaco.org/index.php?page=viewproblem2&cpid=1211)
  - `[M]` [MST Company](https://codeforces.com/contest/125/problem/E)
  - `[M]` [Gift](https://codeforces.com/contest/76/problem/A)
  - `[M]` ★ [Counting Graphs](https://codeforces.com/problemset/problem/1857/G)
  - `[M]` ★ [AND Maximum Spanning Tree](https://toph.co/p/and-maximum-spanning-tree)
  - `[M]` ★ [Turtle and Intersected Segments](https://codeforces.com/contest/1981/problem/E)
  - `[M]` [Road Construction](https://lightoj.com/problem/road-construction)
  - `[M]` ★ [Mahmoud and Ehab and the xor-MST](https://codeforces.com/problemset/problem/959/E)
  - `[H]` [Portals](https://usaco.org/index.php?page=viewproblem2&cpid=1138)
  - `[H]` [DFS Trees](https://codeforces.com/contest/1707/problem/C)
  - `[H]` [Avoid Rainbow Cycles](https://codeforces.com/problemset/problem/1408/E)

#### 3.5.2 Steiner Tree Problem

- **ID:** `steiner_tree_problem` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/steiner_tree_problem
- **Templates (1):**
  - [Steiner Tree Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Steiner%20Tree%20Problem.cpp)
- **Resources (3):**
  - ★ [Episode 7 - Steiner Trees | Algorithms Live!](https://www.youtube.com/watch?v=BG4vAoV5kWw)
  - [Dreyfus-Wagner DP algorithm | By Arkham_Knight](https://codeforces.com/blog/entry/91601)
  - [Exact Algorithms for Steiner Tree | Ondra Such´y](https://www.imsc.res.in/~vraman/exact/suchy.pdf)
- **Problems (3):**
  - `[E]` ★ [Minimum Steiner Tree](https://judge.yosupo.jp/problem/minimum_steiner_tree)
  - `[M]` ★ [Garden](https://codeforces.com/contest/152/problem/E)
  - `[M]` [Ticket to Ride](https://www.spoj.com/problems/TICKET/)

#### 3.5.3 Boruvka's Algorithm

- **ID:** `boruvkas_algorithm` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/boruvkas_algorithm
- **Templates (1):**
  - [Boruvka's Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Boruvka's%20Algorithm.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] Boruvka's Algorithm By RockyB](https://codeforces.com/blog/entry/77760)
- **Problems (4):**
  - `[M]` ★ [Xor-MST](https://codeforces.com/contest/888/problem/G)
  - `[M]` [Spanning Tree](https://www.codechef.com/problems/SPANTREE)
  - `[H]` ★ [Kuroni and Antihype](https://codeforces.com/contest/1305/problem/G)
  - `[H]` [Air Reform](https://codeforces.com/problemset/problem/1648/E)

#### 3.5.4 Minimum Diameter Spanning Tree

- **ID:** `minimum_diameter_spanning_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_diameter_spanning_tree
- **Templates (1):**
  - [Minimum Diameter Spanning Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Minimum%20Diameter%20Spanning%20Tree.cpp)
- **Resources (1):**
  - [Explanation of Problem C The GbAaY Kingdom](https://web.archive.org/web/20160309101249/https://adn.botao.hu/adn-backup/blog/attachments/month_0705/32007531153238.pdf)
- **Problems (4):**
  - `[E]` ★ [Minimum Diameter Spanning Tree](https://judge.yosupo.jp/problem/minimum_diameter_spanning_tree)
  - `[E]` ★ [The GbAaY Kingdom](https://www.spoj.com/problems/PT07C/)
  - `[E]` [Minimum Diameter Spanning Tree](https://www.spoj.com/problems/MDST/)
  - `[E]` ★ [BerDonalds](https://codeforces.com/contest/266/problem/D)

#### 3.5.5 Manhattan MST

- **ID:** `manhattan_mst` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/manhattan_mst
- **Templates (1):**
  - [Manhattan MST.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Manhattan%20MST.cpp)
- **Resources (1):**
  - ★ [MANHATTAN MINIMUM SPANNING TREE | LINE SWEEP ALGORITHMS | Topcoder](https://www.topcoder.com/thrive/articles/Line%20Sweep%20Algorithms#:~:text=MANHATTAN%20MINIMUM%20SPANNING%20TREE)
- **Problems (4):**
  - `[E]` ★ [Manhattan MST](https://judge.yosupo.jp/problem/manhattanmst)
  - `[E]` ★ [Dragonstone](https://www.codechef.com/problems/DRAGONST)
  - `[E]` ★ [Grid MST](https://open.kattis.com/problems/gridmst)
  - `[H]` ★ [The Sprawl](https://csacademy.com/contest/archive/task/the-sprawl)

#### 3.5.6 Euclidean MST

- **ID:** `euclidean_mst` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/euclidean_mst
- **Resources (2):**
  - [\[Tutorial\] Voronoi Diagram and Delaunay Triangulation in O(n log n) with Fortune's Algorithm | Monogon](https://codeforces.com/blog/entry/85638)
  - [Euclidean minimum spanning tree | Wiki](https://en.wikipedia.org/wiki/Euclidean_minimum_spanning_tree)
- **Problems (2):**
  - `[E]` ★ [Euclidean MST](https://judge.yosupo.jp/problem/euclidean_mst)
  - `[M]` [Caravans](https://codeforces.com/problemsets/acmsguru/problem/99999/383)

#### 3.5.7 Directed MST

- **ID:** `directed_mst` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/directed_mst
- **Templates (1):**
  - [Directed MST.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Directed%20MST.cpp)
- **Resources (1):**
  - ★ [Directed Minimum Spanning Trees | Uri Zwick](https://www.cs.tau.ac.il//~zwick/grad-algo-13/directed-mst.pdf)
- **Problems (4):**
  - `[E]` ★ [Directed MST](https://judge.yosupo.jp/problem/directedmst)
  - `[M]` [FoxTheLinguist](https://vjudge.net/problem/TopCoder-12614)
  - `[M]` ★ [Teleport](https://lightoj.com/problem/teleport)
  - `[M]` ★ [Stream My Contest](https://lightoj.com/problem/stream-my-contest)

#### 3.5.8 Dynamic MST

- **ID:** `dynamic_mst` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_mst
- **Templates (2):**
  - [Dynamic MST Offline.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Dynamic%20MST%20Offline.cpp)
  - [53863533](https://atcoder.jp/contests/abc355/submissions/53863533)
- **Resources (4):**
  - ★ [Offline Dynamic MST \[Tutorial\] By jeroenodb](https://codeforces.com/blog/entry/105192)
  - [Offline Algorithms for Dynamic Minimum Spanning Tree Problems By David Eppstein](https://ics.uci.edu/~eppstein/pubs/Epp-TR-92-04.pdf)
  - ★ [Online Dynamic MST | ivan100sic](https://codeforces.com/blog/entry/59908?#comment-436081)
  - [weighted DSU - online dynamic MST without LCT | not_amir](https://codeforces.com/blog/entry/130107)
- **Problems (4):**
  - `[E]` ★ [Dynamic MST](https://dmoj.ca/problem/ccoprep4p3)
  - `[E]` ★ [It's Time to Repair the Roads](https://codeforces.com/problemsets/acmsguru/problem/99999/529)
  - `[E]` [MST Query](https://atcoder.jp/contests/abc355/tasks/abc355_f)
  - `[M]` [collapse](https://oj.uz/problem/view/JOI18_collapse)

#### 3.5.9 Kirchoffs Theorem ft Number of MSTs

- **ID:** `kirchoffs_theorem_ft_number_of_msts` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/kirchoffs_theorem_ft_number_of_msts
- **Templates (1):**
  - [Kirchoffs Theorem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Kirchoffs%20Theorem.cpp)
- **Resources (4):**
  - ★ [The Matrix-Tree Theorems](https://personalpages.manchester.ac.uk/staff/mark.muldoon/Teaching/DiscreteMaths/LectureNotes/IntroToMatrixTree.pdf)
  - ★ [Kirchhoff's theorem. Finding the number of spanning trees | CP Algorithms](https://cp-algorithms.com/graph/kirchhoff-theorem.html)
  - [Kirchhoff’s theorem | Danish Ali](https://medium.com/@da.naqvi99/kirchhoffs-theorem-67ea182c1b45)
  - ★ [An intuition and simpler proof for Kirchoff's tree theorem By Everule](https://codeforces.com/blog/entry/103329)
- **Problems (6):**
  - `[E]` ★ [Counting Spanning Trees (Undirected)](https://judge.yosupo.jp/problem/counting_spanning_tree_undirected)
  - `[E]` ★ [Trux it Up](https://lightoj.com/problem/trux-it-up)
  - `[M]` ★ [Roads in Stars](https://www.codechef.com/problems/STARROAD)
  - `[M]` [Complement Spanning Trees](https://www.codechef.com/problems/CSTREE)
  - `[M]` ★ [We Love Forest](https://atcoder.jp/contests/abc253/tasks/abc253_h)
  - `[VH]` [生成树求和 加强版](https://loj.ac/p/6271)

### 3.6 Shortest Paths

**Subcategory ID:** `shortest_paths` · **Topics:** 11

#### 3.6.1 Dijkstra's Algorithm

- **ID:** `dijkstras_algorithm` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/dijkstras_algorithm
- **Templates (1):**
  - [Dijkstra.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Dijkstra.cpp)
- **Resources (7):**
  - ★ [Dijkstra's Shortest Path Algorithm | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=pSqmAO-m7Lk)
  - ★ [Dijkstra Algorithm on dense graphs | CP Algorithms](https://cp-algorithms.com/graph/dijkstra.html)
  - ★ [Dijkstra on sparse graphs | CP Algorithms](https://cp-algorithms.com/graph/dijkstra_sparse.html)
  - [13.2 Dijkstra’s algorithm | CPH](https://usaco.guide/CPH.pdf#page=136)
  - ★ [Dijkstra Visualizer](https://alexyd88.github.io/Dijkstra-Visualizer/)
  - ★ [Dijkstra | USACO Guide](https://usaco.guide/gold/shortest-paths?lang=cpp#dijkstra)
  - [Shortest Path Modelling Tutorial By skavurskaa](https://codeforces.com/blog/entry/45897)
- **Problems (33):**
  - `[E]` ★ [Shortest Routes I](https://cses.fi/problemset/task/1671)
  - `[E]` ★ [Shortest Path](https://judge.yosupo.jp/problem/shortest_path)
  - `[E]` ★ [Dijkstra?](https://codeforces.com/problemset/problem/20/C)
  - `[E]` [Fine Dining](https://usaco.org/index.php?page=viewproblem2&cpid=861)
  - `[E]` [The Shortest Path](https://www.spoj.com/problems/SHPATH/)
  - `[E]` [Ada and Trip](https://www.spoj.com/problems/ADATRIP/)
  - `[E]` [Destination Unknown](https://codeforces.com/gym/100625/problem/D)
  - `[E]` [Rudolf and CodeVid-23](https://codeforces.com/contest/1846/problem/G)
  - `[E]` ★ [Bicycles](https://codeforces.com/contest/1915/problem/G)
  - `[E]` [Rendez-vous de Marian et Robin](https://codeforces.com/contest/2014/problem/E)
  - `[M]` ★ [Flight Discount](https://cses.fi/problemset/task/1195)
  - `[M]` ★ [Flight Routes](https://cses.fi/problemset/task/1196/)
  - `[M]` ★ [Investigation](https://cses.fi/problemset/task/1202)
  - `[M]` [Robot Turtles](https://open.kattis.com/problems/robotturtles)
  - `[M]` ★ [President and Roads](https://codeforces.com/problemset/problem/567/E)
  - `[M]` [Ivan's Car](https://acm.timus.ru/problem.aspx?space=1&num=1930)
  - `[M]` [Shortest Path](https://codeforces.com/problemset/problem/59/E)
  - `[M]` [Jzzhu and Cities](https://codeforces.com/problemset/problem/449/B)
  - `[M]` [Complete The Graph](https://codeforces.com/problemset/problem/715/B)
  - `[M]` [A Journey to Greece](https://codeforces.com/gym/100753/problem/A)
  - `[M]` ★ [Team Rocket Rises Again](https://codeforces.com/contest/757/problem/F)
  - `[M]` [Skipping](https://codeforces.com/contest/2024/problem/D)
  - `[M]` ★ [Reducing Delivery Cost](https://codeforces.com/problemset/problem/1433/G)
  - `[M]` [Monsters](https://codeforces.com/contest/1810/problem/E)
  - `[M]` [Graph and Graph](https://codeforces.com/contest/2059/problem/D)
  - `[H]` ★ [The Classic Problem](https://codeforces.com/contest/464/problem/E)
  - `[H]` [Crocodile's Underground City](https://oj.uz/problem/view/IOI11_crocodile)
  - `[H]` ★ [Robot](https://oj.uz/problem/view/JOI21_ho_t4)
  - `[H]` [Find the Path](https://dmoj.ca/problem/apio11p2)
  - `[H]` [Shortest Paths](https://www.acmicpc.net/problem/5250)
  - `[H]` [Dynamic Shortest Path](https://codeforces.com/problemset/problem/843/D)
  - `[H]` [Dirty Arkady's Kitchen](https://codeforces.com/contest/827/problem/F)
  - `[H]` [Dangerous Bull! Who Wants to Pull?](https://lightoj.com/problem/dangerous-bull-who-wants-to-p)

#### 3.6.2 [Trick] Dijkstra on Segment Tree

- **ID:** `dijkstra_on_segment_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dijkstra_on_segment_tree
- **Templates (1):**
  - [Dijkstra on Segment Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Dijkstra%20on%20Segment%20Tree.cpp)
- **Resources (3):**
  - ★ [Segment tree for graph problems By ASHWANTH_K](https://codeforces.com/blog/entry/135761)
  - [Check editorial of 786B - Legacy](https://codeforces.com/blog/entry/51163)
  - [\[Bangla\] Handling shortest path tasks on Dense Graph with Segment Tree | Nafis](https://nafis277.github.io/Notes/shortest_path_optimization_with_segtree.pdf)
- **Problems (5):**
  - `[E]` ★ [Legacy](https://codeforces.com/contest/786/problem/B)
  - `[M]` ★ [Tickets](https://usaco.org/index.php?page=viewproblem2&cpid=1164)
  - `[M]` ★ [Dense Graph](https://www.codechef.com/problems/DENSEGRP)
  - `[M]` [Beautiful Tree](https://codeforces.com/contest/1904/problem/F)
  - `[H]` ★ [Babysitting](https://codeforces.com/contest/1903/problem/F)

#### 3.6.3 Floyd Warshall

- **ID:** `floyd_warshall` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/floyd_warshall
- **Templates (1):**
  - [Floyd Warshall.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Floyd%20Warshall.cpp)
- **Resources (4):**
  - ★ [Floyd-Warshall Algorithm | CP Algorithms](https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html)
  - ★ [Floyd Warshall All Pairs Shortest Path Algorithm | Graph Theory | Dynamic Programming WilliamFiset](https://www.youtube.com/watch?v=4NQ3HnhyNfQ)
  - [13.3 Floyd–Warshall algorithm | CPH](https://usaco.guide/CPH.pdf#page=139)
  - ★ [4.5 - All-Pairs Shortest Paths | CP2](https://usaco.guide/CP2.pdf#page=112)
- **Problems (18):**
  - `[E]` ★ [Shortest Routes II](https://cses.fi/problemset/task/1672)
  - `[E]` ★ [Greg and Graph](https://codeforces.com/problemset/problem/295/B)
  - `[E]` [Roads in Berland](https://codeforces.com/contest/25/problem/C)
  - `[E]` [Possible Friends](https://www.spoj.com/problems/SOCIALNE/)
  - `[E]` [106 miles to Chicago](https://www.spoj.com/problems/CHICAGO/)
  - `[E]` ★ [Travel Company](https://lightoj.com/problem/travel-company)
  - `[E]` [String Problem](https://codeforces.com/contest/33/problem/B)
  - `[E]` [Arbitrage](https://www.spoj.com/problems/ARBITRAG/)
  - `[E]` [Frogger](https://vjudge.net/problem/UVA-534)
  - `[E]` ★ [All Pairs Shortest Path](https://open.kattis.com/problems/allpairspath)
  - `[E]` [Edge Deletion](https://atcoder.jp/contests/abc243/tasks/abc243_e)
  - `[E]` [Weekend](https://codeforces.com/gym/101020/problem/H)
  - `[M]` [Road Construction](https://vjudge.net/problem/UVA-10724)
  - `[M]` ★ [Traveling Graph](https://codeforces.com/problemset/problem/21/D)
  - `[M]` ★ [Manic Moving](https://codeforces.com/gym/101223/problem/C)
  - `[M]` ★ [Jogging Trails](https://lightoj.com/problem/jogging-trails)
  - `[M]` [Ingredients](https://www.spoj.com/problems/INGRED/)
  - `[H]` [Remainder Game](https://atcoder.jp/contests/agc022/tasks/agc022_c)

#### 3.6.4 Bellman Ford

- **ID:** `bellman_ford` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/bellman_ford
- **Templates (1):**
  - [Bellman Ford.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Bellman%20Ford.cpp)
- **Resources (3):**
  - ★ [Bellman-Ford Algorithm | CP Algorithms](https://cp-algorithms.com/graph/bellman_ford.html)
  - ★ [Bellman Ford Algorithm | Shortest path & Negative cycles | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=lyw4FaxrwHg)
  - [Bellman-Ford | USACO Guide](https://usaco.guide/adv/sp-neg?lang=cpp#shortest-paths)
- **Problems (12):**
  - `[E]` ★ [Single source shortest path, negative weights](https://open.kattis.com/problems/shortestpath3)
  - `[E]` ★ [High Score](https://cses.fi/problemset/task/1673)
  - `[E]` ★ [Cycle Finding](https://cses.fi/problemset/task/1197/)
  - `[E]` [Ford-Bellman](https://www.eolymp.com/en/problems/1453)
  - `[E]` [MPI Maelstrom](https://vjudge.net/problem/UVA-423)
  - `[E]` [The Tourist Guide](https://vjudge.net/problem/UVA-10099)
  - `[E]` [King](https://vjudge.net/problem/UVA-515)
  - `[E]` ★ [Travel Company](https://lightoj.com/problem/travel-company)
  - `[E]` [Segments](https://www.spoj.com/problems/SEGMENTS/)
  - `[M]` ★ [Sign of Matrix](https://vjudge.net/problem/UVA-11671)
  - `[M]` [Extended Traffic](https://lightoj.com/problem/extended-traffic)
  - `[H]` ★ [Specified Range Sums](https://atcoder.jp/contests/abc404/tasks/abc404_g)

#### 3.6.5 Shortest Path Faster Algorithm (SPFA)

- **ID:** `spfa` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/spfa
- **Templates (1):**
  - [SPFA.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/SPFA.cpp)
- **Resources (3):**
  - ★ [Shortest Path Faster Algorithm (SPFA) | CP Algorithms](https://cp-algorithms.com/graph/bellman_ford.html#shortest-path-faster-algorithm-spfa)
  - ★ [Using the Shortest Path Faster Algorithm to find a negative cycle | KonaeAkira's blog](https://konaeakira.github.io/posts/using-the-shortest-path-faster-algorithm-to-find-negative-cycles.html)
  - [Shortest Path Faster Algorithm | Geeks For Geeks](https://www.geeksforgeeks.org/shortest-path-faster-algorithm/)
- **Problems (3):**
  - `[E]` ★ [The Shortest Path](https://codeforces.com/gym/101498/problem/L)
  - `[E]` [The Tourist Guide](https://vjudge.net/problem/UVA-10099)
  - `[M]` ★ [Sign of Matrix](https://vjudge.net/problem/UVA-11671)

#### 3.6.6 Johnson's Alogrithm

- **ID:** `johnsons_algorithm` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/johnsons_algorithm
- **Templates (1):**
  - [Johnson's Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Johnson's%20Algorithm.cpp)
- **Resources (2):**
  - [Johnson's Algorithm | Brilliant](https://brilliant.org/wiki/johnsons-algorithm/)
  - [Tutorial] Graph Potentials, Johnson's Algorithm — Monogon; source export-এ URL-এর বদলে পড়ার নির্দেশ ছিল। মূল topic page থেকে resource মিলিয়ে নিন।
- **Problems (3):**
  - `[E]` ★ [The Shortest Path](https://codeforces.com/gym/101498/problem/L)
  - `[E]` ★ [Johnsons Algorithm](https://www.spoj.com/problems/JHNSN/)
  - `[E]` [Skiing](https://atcoder.jp/contests/abc237/tasks/abc237_e)

#### 3.6.7 0/1 BFS

- **ID:** `0_1_bfs` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/0_1_bfs
- **Resources (2):**
  - ★ [0-1 BFS | CP Algorithms](https://cp-algorithms.com/graph/01_bfs.html)
  - ★ [0-1 BFS \[Tutorial\] By himanshujaju](https://codeforces.com/blog/entry/22276)
- **Problems (15):**
  - `[E]` ★ [Labyrinth](https://codeforces.com/contest/1063/problem/B)
  - `[E]` ★ [KATHTHI](https://www.spoj.com/problems/KATHTHI/)
  - `[E]` [Okabe and City](https://codeforces.com/contest/821/problem/D)
  - `[E]` ★ [Olya and Energy Drinks](https://codeforces.com/problemset/problem/877/D)
  - `[E]` [Chamber of Secrets](https://codeforces.com/problemset/problem/173/B)
  - `[E]` [Tracks in the Snow](https://oj.uz/problem/view/BOI13_tracks)
  - `[E]` [Jailbreak](https://codeforces.com/gym/100625/problem/J)
  - `[E]` [Ocean Currents](https://vjudge.net/problem/UVA-11573)
  - `[E]` [Valentines Day](https://www.codechef.com/problems/CC004)
  - `[E]` ★ [Wizard in Maze](https://atcoder.jp/contests/abc176/tasks/abc176_d)
  - `[E]` [Stronger Takahashi](https://atcoder.jp/contests/abc213/tasks/abc213_e)
  - `[M]` ★ [Three States](https://codeforces.com/problemset/problem/590/C)
  - `[M]` [Spiral Maximum](https://codeforces.com/problemset/problem/173/C)
  - `[M]` [Nastya and Unexpected Guest](https://codeforces.com/contest/1341/problem/E)
  - `[M]` [Snuke's Subway Trip](https://atcoder.jp/contests/arc061/tasks/arc061_c)

#### 3.6.8 Dial's algorithm

- **ID:** `dials_algorithm` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dials_algorithm
- **Templates (1):**
  - [88408?#comment-790017](https://codeforces.com/blog/entry/88408?#comment-790017)
- **Resources (3):**
  - ★ [\[Tutorial\] 1-K BFS By Yukuk](https://codeforces.com/blog/entry/88408)
  - [Dial’s Algorithm (Optimized Dijkstra for small range weights) | Geeks For Geeks](https://www.geeksforgeeks.org/dials-algorithm-optimized-dijkstra-for-small-range-weights/)
  - [A-2A-BFS (1-2-BFS) By ilyakrasnovv,](https://codeforces.com/blog/entry/90917)

#### 3.6.9 Eppsteins Algorithm

- **ID:** `eppsteins_algorithm` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/eppsteins_algorithm
- **Templates (1):**
  - [Eppsteins Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Eppsteins%20Algorithm.cpp)
- **Resources (2):**
  - ★ [\[Tutorial\] k shortest paths and Eppstein's algorithm By meooow](https://codeforces.com/blog/entry/102085)
  - [K-最短路をO((V+E)logV+KlogK)で！？Eppstein's Algorithmのわかりやすい解説！！！【C++実装つき】By hotman78](https://qiita.com/hotman78/items/42534a01c4bd05ed5e1e)
- **Problems (6):**
  - `[VH]` ★ [K-th Shortest Walk](https://judge.yosupo.jp/problem/k_shortest_walk)
  - `[VH]` [Shortest Paths](https://codeforces.com/problemsets/acmsguru/problem/99999/314)
  - `[VH]` [Subset Sum](https://www.acmicpc.net/problem/19133)
  - `[VH]` [Robotic Cow Herd](https://www.acmicpc.net/problem/14166)
  - `[VH]` [Shopping Plans](https://www.acmicpc.net/problem/19616)
  - `[VH]` [Lights On The Road](https://codeforces.com/gym/102979/problem/L)

#### 3.6.10 Suurballe's Algorithm

- **ID:** `suurballes_algorithm` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/suurballes_algorithm
- **Templates (1):**
  - [suurballe.py](https://github.com/nildo/suurballe/blob/master/suurballe.py)
- **Resources (1):**
  - ★ [Suurballe's algorithm | Wiki](https://en.wikipedia.org/wiki/Suurballe%27s_algorithm)
- **Problems (3):**
  - `[E]` ★ [Admiral](https://codeforces.com/gym/101398/problem/A)
  - `[E]` [Boa viagem, Roim](https://bubblecup.org/Content/Media/Booklet2015.pdf)
  - `[H]` ★ [Interest](https://official.contest.yandex.ru/opencupXX/contest/17756/problems/I/)

#### 3.6.11 A* Algorithm

- **ID:** `a_star_algorithm` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/a_star_algorithm
- **Resources (2):**
  - [A* search algorithm | Wiki](https://en.wikipedia.org/wiki/A*_search_algorithm)
  - [A* Search Algorithm | Geeks For Geeks](https://www.geeksforgeeks.org/a-search-algorithm/)
- **Problems (4):**
  - `[M]` [Pacman A*](https://vjudge.net/problem/HackerRank-pacman-astar)
  - `[M]` [Pacman - UCS](https://vjudge.net/problem/HackerRank-pacman-ucs)
  - `[M]` ★ [A rã saltadora preguiçosa](https://br.spoj.com/problems/RAPREGUI/)
  - `[H]` [Poslozi](https://dmoj.ca/problem/coci09c2p5)

### 3.7 Cycles

**Subcategory ID:** `cycles` · **Topics:** 5

#### 3.7.1 Cycle Detection

- **ID:** `cycle_detection` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/cycle_detection
- **Templates (1):**
  - [Cycle Detection.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Cycle%20Detection.cpp)
- **Resources (4):**
  - ★ [Checking a graph for acyclicity and finding a cycle | CP Algorithms](https://cp-algorithms.com/graph/finding-cycle.html)
  - ★ [Finding a negative cycle in the graph | CP Algorithms](https://cp-algorithms.com/graph/finding-negative-cycle-in-graph.html)
  - [Shortest Cycle in Weighted Graph](https://codeforces.com/blog/entry/68073)
  - [Floyd's Linked List Cycle Finding Algorithm | CP Algorithms](https://cp-algorithms.com/others/tortoise_and_hare.html)
- **Problems (11):**
  - `[E]` ★ [Round Trip](https://cses.fi/problemset/task/1669)
  - `[E]` ★ [Round Trip II](https://cses.fi/problemset/task/1678/)
  - `[E]` ★ [Cycle Detection (Directed)](https://judge.yosupo.jp/problem/cycle_detection)
  - `[E]` ★ [Cycle Finding](https://cses.fi/problemset/task/1197/)
  - `[E]` [Alice in Amsterdam, I mean Wonderland](https://www.spoj.com/problems/UCV2013B/)
  - `[E]` ★ [Cycle Detection (Undirected)](https://judge.yosupo.jp/problem/cycle_detection_undirected)
  - `[E]` [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/description/)
  - `[M]` [Cycle in Graph](https://codeforces.com/contest/263/problem/D)
  - `[M]` ★ [Number of Simple Paths](https://codeforces.com/contest/1454/problem/E)
  - `[M]` ★ [Graph Girth](https://cses.fi/problemset/task/1707)
  - `[M]` [Medium Demon Problem (easy version)](https://codeforces.com/contest/2044/problem/G1)

#### 3.7.2 [Problem] Minimum Weight Cycle For Each Vertex

- **ID:** `minimum_weight_cycle_for_each_vertex` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_weight_cycle_for_each_vertex
- **Templates (1):**
  - [Minimum Weight Cycle For Each Vertex.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Minimum%20Weight%20Cycle%20For%20Each%20Vertex.cpp)
- **Problems (1):**
  - `[E]` ★ [Find the Length](https://codeforces.com/gym/100917/problem/F)

#### 3.7.3 [Problem] Minimum Weight Cycle For Each Edge

- **ID:** `minimum_weight_cycle_for_each_edge` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_weight_cycle_for_each_edge
- **Templates (1):**
  - [Minimum Weight Cycle For Each Edge.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Minimum%20Weight%20Cycle%20For%20Each%20Edge.cpp)
- **Problems (1):**
  - `[E]` ★ [Ride Sharing Dilemma](https://lightoj.com/problem/ride-sharing-dilemma)

#### 3.7.4 Minimum Mean Weight Cycle

- **ID:** `minimum_mean_weight_cycle` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_mean_weight_cycle
- **Templates (1):**
  - [Minimum Mean Weight Cycle.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Minimum%20Mean%20Weight%20Cycle.cpp)
- **Resources (1):**
  - [Karp’s minimum mean (or average) weight cycle algorithm | Geeks For Geeks](https://www.geeksforgeeks.org/karps-minimum-mean-average-weight-cycle-algorithm/)
- **Problems (2):**
  - `[E]` ★ [Word Rings](https://www.spoj.com/problems/WORDRING/)
  - `[E]` [Going in Cycle!!](https://vjudge.net/problem/UVA-11090)

#### 3.7.5 Number of 3 and 4 length Cycles

- **ID:** `number_of_3_and_4_length_cycles` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_3_and_4_length_cycles
- **Templates (1):**
  - [3 CYCLE and 4 CYCLE.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/3%20CYCLE%20and%204%20CYCLE.cpp)
- **Problems (2):**
  - `[E]` ★ [Enumerate Triangles](https://judge.yosupo.jp/problem/enumerate_triangles)
  - `[H]` ★ [Connected Subgraphs](https://codeforces.com/gym/102028/problem/L)

### 3.8 More Tree Stuff

**Subcategory ID:** `more_tree_stuff` · **Topics:** 7

#### 3.8.1 Virtual Tree / Auxiliary Tree

- **ID:** `virtual_tree` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/virtual_tree
- **Templates (1):**
  - [Virtual Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Virtual%20Tree.cpp)
- **Resources (3):**
  - ★ [CP Tutorial: Virtual/Auxiliary Tree | Radoslav Dimitrov](https://www.youtube.com/watch?v=czySm7bUHgY)
  - [Editorial of this problem](https://discuss.codechef.com/t/icl1705-editorial/14269)
  - [Virtual trees method By spike1236](https://codeforces.com/blog/entry/140066)
- **Problems (10):**
  - `[M]` ★ [Kingdom and its Cities](https://codeforces.com/contest/613/problem/D)
  - `[M]` ★ [World Cup City](https://www.hackerrank.com/contests/worldcupsemifinals/challenges/wccity/problem)
  - `[M]` [Chaotic V.](https://codeforces.com/contest/1292/problem/D)
  - `[M]` ★ [Kitty's Calculations on a Tree](https://www.hackerrank.com/contests/hourrank-15/challenges/kittys-calculations-on-a-tree/problem)
  - `[M]` ★ [Yet Another Tree Problem](https://www.codechef.com/DEC21A/problems/YATP)
  - `[M]` [Leaf Color](https://atcoder.jp/contests/abc340/tasks/abc340_g)
  - `[M]` [Adjacent Leaves](https://www.codechef.com/problems/ADJLEAF2)
  - `[M]` [Tree Obsession](https://www.codechef.com/problems/ICL1705)
  - `[M]` ★ [Unique Occurrences](https://codeforces.com/contest/1681/problem/F)
  - `[H]` [Treeland and Viruses](https://codeforces.com/contest/1320/problem/E)

#### 3.8.2 Rerooting Technique

- **ID:** `rerooting_technique` · **Difficulty:** Medium · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/rerooting_technique
- **Prerequisites:** DP on Trees
- **Templates (1):**
  - [all-roots?lang=cpp](https://usaco.guide/gold/all-roots?lang=cpp)
- **Resources (4):**
  - ★ [DP on Trees - Solving For All Roots | USACO Guide](https://usaco.guide/gold/all-roots?lang=cpp)
  - ★ [Online Query Based Rerooting Technique By DeadlyCritic](https://codeforces.com/blog/entry/76150)
  - [The Ultimate Reroot Template By pajenegod](https://codeforces.com/blog/entry/124286)
  - [Rerooting DP on Trees Tutorial | codemastercpp](https://www.youtube.com/watch?v=7_huTWwl5jM)
- **Problems (25):**
  - `[E]` ★ [Tree Distances I](https://cses.fi/problemset/task/1132)
  - `[E]` ★ [Tree Distances II](https://cses.fi/problemset/task/1133)
  - `[E]` ★ [Tree with Maximum Cost](https://codeforces.com/contest/1092/problem/F)
  - `[E]` [Choosing Capital for Treeland](https://codeforces.com/contest/219/problem/D)
  - `[E]` ★ [Maximum White Subtree](https://codeforces.com/contest/1324/problem/F)
  - `[M]` [Two-Paths](https://codeforces.com/problemset/problem/1000/G)
  - `[M]` ★ [Subtree](https://atcoder.jp/contests/dp/tasks/dp_v)
  - `[M]` [Tree Painting](https://codeforces.com/contest/1187/problem/E)
  - `[M]` ★ [Distance Sums 2](https://atcoder.jp/contests/abc220/tasks/abc220_f)
  - `[M]` [City Attractions](https://www.acmicpc.net/problem/14875)
  - `[M]` [Distributing Integers](https://atcoder.jp/contests/abc160/tasks/abc160_f)
  - `[M]` [Alternating Tree](https://codeforces.com/contest/960/problem/E)
  - `[M]` [Surrounded Nodes](https://atcoder.jp/contests/abc149/tasks/abc149_f)
  - `[M]` [Vertex Deletion](https://atcoder.jp/contests/abc223/tasks/abc223_g)
  - `[M]` ★ [Expensive Expense](https://atcoder.jp/contests/abc222/tasks/abc222_f)
  - `[M]` ★ [Road Improvement](https://codeforces.com/contest/543/problem/D)
  - `[M]` [Casinos and travel](https://codeforces.com/contest/852/problem/E)
  - `[M]` ★ [Tree Inversion](https://atcoder.jp/contests/abc337/tasks/abc337_g)
  - `[M]` ★ [Tree Path Composite Sum](https://judge.yosupo.jp/problem/tree_path_composite_sum)
  - `[M]` [Tree XOR](https://codeforces.com/problemset/problem/1882/D)
  - `[H]` ★ [Patrol](https://dmoj.ca/problem/apio10p2)
  - `[H]` [Hard route](https://oj.uz/problem/view/IZhO17_road)
  - `[H]` ★ [is-this-rerooting](https://codeforces.com/group/qepOKX6Mi9/contest/363472/problem/A)
  - `[H]` ★ [Tree Sum](https://www.spoj.com/problems/TREESUM/)
  - `[VH]` [Star Trek](https://codeforces.com/contest/1402/problem/C)

#### 3.8.3 Union of Two Paths on a Tree

- **ID:** `path_union` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/path_union
- **Templates (1):**
  - [Path Union.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Path%20Union.cpp)
- **Problems (2):**
  - `[M]` ★ [Max Mex](https://codeforces.com/problemset/problem/1083/C)
  - `[M]` ★ [MEX Tree](https://codeforces.com/problemset/problem/1527/D)

#### 3.8.4 Intersection of Two Paths on a Tree

- **ID:** `path_intersection` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/path_intersection
- **Templates (1):**
  - [Path Intersection.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Path%20Intersection.cpp)
- **Problems (1):**
  - `[M]` ★ [Path Intersection](https://codeforces.com/gym/102040/problem/F)

#### 3.8.5 [Problem] Number of Paths of Each Length in a Tree

- **ID:** `number_of_paths_of_each_length_in_a_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_paths_of_each_length_in_a_tree
- **Templates (1):**
  - [Number of Paths of Each Length in a Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Number%20of%20Paths%20of%20Each%20Length%20in%20a%20Tree.cpp)
- **Problems (2):**
  - `[M]` ★ [Frequency Table of Tree Distance](https://judge.yosupo.jp/problem/frequency_table_of_tree_distance)
  - `[M]` ★ [Awesome Shawarma](https://codeforces.com/gym/101991/problem/A)

#### 3.8.6 Dynamic Online Tree Diameter

- **ID:** `dynamic_diameter_online` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_diameter_online
- **Templates (1):**
  - [Dynamic Diameter Online.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Dynamic%20Diameter%20Online.cpp)
- **Resources (1):**
  - ★ [Dynamic Diameter | hocky](https://github.com/hockyy/cf/blob/main/DynamicDiameter.md)
- **Problems (1):**
  - `[M]` ★ [Dynamic Diameter](https://codeforces.com/contest/1192/problem/B)

#### 3.8.7 [Problem] Tree Orientation to Maximize Pairs of Reachable Nodes

- **ID:** `tree_orientation_to_maximize_pairs_of_reachable_nodes` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tree_orientation_to_maximize_pairs_of_reachable_nodes
- **Templates (1):**
  - [Tree Orientation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Tree%20Orientation.cpp)
- **Resources (1):**
  - ★ [A comment by Bruteforceman](https://codeforces.com/blog/entry/89228?#comment-776479)
- **Problems (1):**
  - `[M]` ★ [Polarization](https://szkopul.edu.pl/problemset/problem/3bBT-3VuSu78UsxTQSwaJzVo/site/?key=statement)

### 3.9 Satisfiability

**Subcategory ID:** `satisfiability` · **Topics:** 3

#### 3.9.1 2 SAT

- **ID:** `2_sat` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/2_sat
- **Templates (1):**
  - [2 SAT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/2%20SAT.cpp)
- **Resources (3):**
  - ★ [2-SAT | CP Algorithms](https://cp-algorithms.com/graph/2SAT.html)
  - ★ [\[Tutorial\] 2-SAT By arujbansal](https://codeforces.com/blog/entry/92977)
  - [Episode 24 - 2SAT | Algorithms Live!](https://www.youtube.com/watch?v=0nNYy3rltgA)
- **Problems (16):**
  - `[E]` ★ [2 Sat](https://judge.yosupo.jp/problem/two_sat)
  - `[E]` ★ [Giant Pizza](https://cses.fi/problemset/task/1684/)
  - `[E]` [Flipping Cards](https://www.eolymp.com/en/problems/7538)
  - `[E]` ★ [Unusual Matrix](https://codeforces.com/contest/1475/problem/F)
  - `[E]` ★ [The Door Problem](https://codeforces.com/contest/776/problem/D)
  - `[E]` [Hackerman](https://www.codechef.com/LTIME95A/problems/HKRMAN)
  - `[E]` [Illumination](https://open.kattis.com/problems/illumination)
  - `[E]` ★ [±1](https://codeforces.com/contest/1971/problem/H)
  - `[M]` ★ [Coprime Solitaire](https://atcoder.jp/contests/abc210/tasks/abc210_f)
  - `[M]` ★ [Mex on DAG](https://codeforces.com/gym/102412/problem/H)
  - `[M]` ★ [The Light Square](https://codeforces.com/problemset/problem/1218/I)
  - `[M]` [Rectangles](https://vjudge.net/problem/UVA-11930)
  - `[H]` ★ [Babysitting](https://codeforces.com/contest/1903/problem/F)
  - `[H]` [Radio Stations](https://codeforces.com/problemset/problem/1215/F)
  - `[H]` ★ [Exam Requirements](https://codedrills.io/contests/icpc-amritapuri-2022-regional-round/problems/exam-requirements)
  - `[H]` [Ants](https://codeforces.com/problemset/problem/1007/D)

#### 3.9.2 3 SAT

- **ID:** `3_sat` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/3_sat
- **Templates (1):**
  - [3 SAT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/3%20SAT.cpp)
- **Resources (2):**
  - [DPLL algorithm](https://en.wikipedia.org/wiki/DPLL_algorithm)
  - [How does DPLL Algorithm Work? A Brief Explanation of DPLL | Mert Özlütıraş](https://mertozlutiras.medium.com/brief-explanation-of-dpll-davis-putnam-logemann-loveland-algorithm-663f4a603c1)

#### 3.9.3 System Of Difference Constraints

- **ID:** `system_of_difference_constraints` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/system_of_difference_constraints
- **Templates (1):**
  - [System Of Difference Constraints.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/System%20Of%20Difference%20Constraints.cpp)
- **Resources (3):**
  - ★ [System of difference constraints](https://reponroy.wordpress.com/2016/06/27/system-of-difference-constraints/)
  - [Solving a system of difference constraints](https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf)
  - [Difference constraints and shortest paths](https://walkccc.me/CLRS/Chap24/24.4/)
- **Problems (5):**
  - `[E]` ★ [Playing On A Directed Graph](https://toph.co/p/playing-on-a-directed-graph)
  - `[E]` [Halum](https://vjudge.net/problem/UVA-11478)
  - `[M]` [Restore Array](https://oj.uz/problem/view/RMI19_restore)
  - `[M]` [01 Sequence](https://wcipeg.com/problem/noi99p1)
  - `[M]` [Intervals](https://vjudge.net/problem/POJ-1201)

### 3.10 Eulerian Path

**Subcategory ID:** `eulerian_path` · **Topics:** 1

#### 3.10.1 Eulerian Path and Cycle

- **ID:** `eulerian_path_and_cycle` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/eulerian_path_and_cycle
- **Templates (2):**
  - [Euler Path Directed.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Euler%20Path%20Directed.cpp)
  - [Euler Path Undirected.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Euler%20Path%20Undirected.cpp)
- **Resources (4):**
  - ★ [Eulerian Tours | USACO Guide](https://usaco.guide/adv/eulerian-tours?lang=cpp)
  - ★ [19.1 Eulerian paths | CPH](https://usaco.guide/CPH.pdf#page=183)
  - ★ [Eulerian Path/Circuit algorithm (Hierholzer's algorithm) | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=8MpoO2zA2l4)
  - ★ [Eulerian path | wikiwand](https://www.wikiwand.com/en/Eulerian_path#/Hierholzer.27s_algorithm)
- **Problems (18):**
  - `[E]` ★ [Eulerian Trail (Directed)](https://judge.yosupo.jp/problem/eulerian_trail_directed)
  - `[E]` ★ [Eulerian Trail (Undirected)](https://judge.yosupo.jp/problem/eulerian_trail_undirected)
  - `[E]` ★ [Teleporters Path](https://cses.fi/problemset/task/1693/)
  - `[E]` ★ [Tanya and Password](https://codeforces.com/contest/508/problem/D)
  - `[E]` ★ [Mail Delivery](https://cses.fi/problemset/task/1691/)
  - `[E]` ★ [One-Way Reform](https://codeforces.com/contest/723/problem/E)
  - `[E]` [Senior Postmen](https://oj.uz/problem/view/BOI14_postmen)
  - `[E]` [Play on Words](https://www.spoj.com/problems/WORDS1/)
  - `[E]` ★ [Melody](https://codeforces.com/contest/2110/problem/E)
  - `[M]` ★ [Traveling Graph](https://codeforces.com/problemset/problem/21/D)
  - `[M]` ★ [Matching Substrings](https://csacademy.com/contest/archive/task/matching-substrings/statement/)
  - `[M]` ★ [Johnny and Megan's Necklace](https://codeforces.com/contest/1361/problem/C)
  - `[M]` ★ [Turtle and Multiplication](https://codeforces.com/contest/1981/problem/D)
  - `[M]` [Acrobat](https://www.acmicpc.net/problem/13973)
  - `[M]` [Weird journey](https://codeforces.com/problemset/problem/788/B)
  - `[M]` ★ [Red Blue Graph](https://toph.co/p/red-blue-graph)
  - `[M]` ★ [Fair Share](https://codeforces.com/contest/1634/problem/E)
  - `[H]` [Data Center Drama](https://codeforces.com/contest/528/problem/C)

### 3.11 Hamiltonian Path

**Subcategory ID:** `hamiltonian_path` · **Topics:** 2

#### 3.11.1 Hamiltonian Path and Cycle

- **ID:** `hamiltonian_path_and_cycle` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/hamiltonian_path_and_cycle
- **Resources (5):**
  - ★ [19.2 Hamiltonian paths | CPH](https://usaco.guide/CPH.pdf#page=187)
  - ★ [A little bit of classics: dynamic programming over subsets and paths in graphs By Ripatti](https://codeforces.com/blog/entry/337)
  - [Hamiltonian Paths and Cycles | Rahul Sethi](https://medium.com/stamatics-iit-kanpur/hamiltonian-paths-and-cycles-4f233bfbc53a)
  - [Hamiltonian Cycle | Geeks For Geeks](https://www.geeksforgeeks.org/hamiltonian-cycle/)
  - [Nontrivial Hamiltonian Cycle on 2D grid By Soul_Full_Of_Thunder](https://codeforces.com/blog/entry/79788?locale=en)
- **Problems (3):**
  - `[E]` ★ [Hamiltonian Flights](https://cses.fi/problemset/task/1690)
  - `[E]` [Fetching Cooking Tools](https://www.codechef.com/problems/TOOLS)
  - `[E]` ★ [Hamiltonian Cycle](https://vjudge.net/problem/UVA-775)

#### 3.11.2 Hamiltonian Path Heuristic Algorithm

- **ID:** `hamiltonian_path_heuristic_algorithm` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/hamiltonian_path_heuristic_algorithm
- **Templates (1):**
  - [90513](https://codeforces.com/blog/entry/90513)
- **Resources (1):**
  - [Heuristic algorithm for Hamiltonian path in directed graphs By Rewinding](https://codeforces.com/blog/entry/90513)
- **Problems (2):**
  - `[M]` [Hamiltonian Cycle](https://atcoder.jp/contests/arc118/tasks/arc118_d)
  - `[H]` [Aerobatics](https://oj.uz/problem/view/JOI21_aerobatics)

### 3.12 Cliques and Independent Sets

**Subcategory ID:** `cliques_and_independent_sets` · **Topics:** 2

#### 3.12.1 Maximum Clique

- **ID:** `maximum_clique` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_clique
- **Templates (3):**
  - [Maximum Clique.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Clique.cpp)
  - [Number of Different Cliques.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Number%20of%20Different%20Cliques.cpp)
  - [Maximum Clique and Maximum Independent Set Super Fast.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Clique%20and%20Maximum%20Independent%20Set%20Super%20Fast.cpp)
- **Resources (3):**
  - [Clique (graph theory) | Wiki](https://en.wikipedia.org/wiki/Clique_%28graph_theory%29)
  - ★ [Bron–Kerbosch algorithm | Wiki](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm)
  - ★ [Editorial of Problem E](https://codeforces.com/blog/entry/64664)
- **Problems (8):**
  - `[E]` ★ [Helping Hiasat](https://codeforces.com/contest/1105/problem/E)
  - `[E]` [Clique Problem](https://codeforces.com/problemset/problem/527/D)
  - `[M]` ★ [All Friends](https://open.kattis.com/problems/friends)
  - `[M]` ★ [Clique in the Divisibility Graph](https://codeforces.com/problemset/problem/566/F)
  - `[M]` [Trees of Tranquillity](https://codeforces.com/problemset/problem/1529/E)
  - `[M]` [Clique Partition](https://codeforces.com/problemset/problem/1948/E)
  - `[M]` [Graph Subset Problem](https://codeforces.com/problemset/problem/1439/B)
  - `[VH]` ★ [Enumerate Cliques](https://judge.yosupo.jp/problem/enumerate_cliques)

#### 3.12.2 Maximum Independent Set (MIS)

- **ID:** `maximum_independent_set` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_independent_set
- **Templates (2):**
  - [Maximum Clique.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Clique.cpp)
  - [Maximum Clique and Maximum Independent Set Super Fast.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Clique%20and%20Maximum%20Independent%20Set%20Super%20Fast.cpp)
- **Resources (5):**
  - [Independent set (graph theory) | Wiki](https://en.wikipedia.org/wiki/Independent_set_%28graph_theory%29)
  - [Maximal independent set | Wiki](https://en.wikipedia.org/wiki/Maximal_independent_set)
  - ★ [Editorial of Problem E](https://codeforces.com/blog/entry/64664)
  - [Bron–Kerbosch algorithm](https://en.wikipedia.org/wiki/Bron%E2%80%93Kerbosch_algorithm)
  - ★ [Maximum Independent Set in Trees (Linear Time Algorithm) | Easy Theory](https://www.youtube.com/watch?v=-LN5-GvV-bQ)
- **Problems (5):**
  - `[E]` ★ [Maximum Independent Set](https://judge.yosupo.jp/problem/maximum_independent_set)
  - `[E]` ★ [Helping Hiasat](https://codeforces.com/contest/1105/problem/E)
  - `[M]` ★ [Maximal Independent Set](https://www.spoj.com/problems/MAXISET/)
  - `[M]` ★ [Sensor Network](https://vjudge.net/problem/Kattis-sensor)
  - `[M]` [Matching vs Independent Set](https://codeforces.com/problemset/problem/1198/C)

### 3.13 Graph Coloring

**Subcategory ID:** `graph_coloring` · **Topics:** 5

#### 3.13.1 Chromatic Number

- **ID:** `chromatic_number` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chromatic_number
- **Templates (1):**
  - [Chromatic Number.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Chromatic%20Number.cpp)
- **Resources (1):**
  - [Effective way to compute the chromatic number of a graph By KokiYmgch](https://codeforces.com/blog/entry/57496)
- **Problems (3):**
  - `[E]` ★ [Chromatic Number](https://judge.yosupo.jp/problem/chromatic_number)
  - `[E]` ★ [Coloring Graphs](https://open.kattis.com/problems/coloring)
  - `[E]` [Colorful Tree](https://codeforces.com/problemset/gymProblem/100482/A)

#### 3.13.2 Welsh-Powell Algorithm

- **ID:** `welsh_powell_algorithm` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/welsh_powell_algorithm
- **Resources (2):**
  - [Greedy coloring | Wiki](https://en.wikipedia.org/wiki/Greedy_coloring)
  - ★ [Welsh Powell Graph colouring Algorithm | Geeks for Geeks](https://www.geeksforgeeks.org/welsh-powell-graph-colouring-algorithm/)
- **Problems (2):**
  - `[E]` ★ [Coloring Graphs](https://open.kattis.com/problems/coloring)
  - `[VH]` [Vibrating Paths (Challenge)](https://www.codechef.com/problems/VBR)

#### 3.13.3 Chromatic Polynomial ft Number of DAGs

- **ID:** `chromatic_polynomial_ft_number_of_dags` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chromatic_polynomial_ft_number_of_dags
- **Templates (1):**
  - [Chromatic Polynoimial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Chromatic%20Polynoimial.cpp)
- **Resources (3):**
  - [Chromatic polynomial | Wiki](https://en.wikipedia.org/wiki/Chromatic_polynomial)
  - [THE CHROMATIC POLYNOMIAL | CODY FOUTS](https://www.whitman.edu/Documents/Academics/Mathematics/fouts.pdf)
  - [Chromatic Polynomial | Geeks for Geeks](https://www.geeksforgeeks.org/chromatic-polynomial/)
- **Problems (2):**
  - `[E]` ★ [Chromatic Polynomial](https://judge.yosupo.jp/problem/chromatic_polynomial)
  - `[H]` ★ [Amusement Park](https://codeforces.com/contest/1193/problem/A)

#### 3.13.4 Edge Coloring of Simple Graph

- **ID:** `edge_coloring_of_simple_graph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/edge_coloring_of_simple_graph
- **Templates (1):**
  - [Edge Coloring Simple Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Edge%20Coloring%20Simple%20Graph.cpp)
- **Resources (2):**
  - [Story about edge coloring of graph By ko_osaga](https://codeforces.com/blog/entry/75431)
  - [Vizing's theorem | Wiki](https://en.wikipedia.org/wiki/Vizing%27s_theorem)
- **Problems (2):**
  - `[E]` ★ [Algorist Club](https://www.acmicpc.net/problem/10446)
  - `[M]` [Game Scheduling](https://codeforces.com/gym/101933/problem/G)

#### 3.13.5 Edge Coloring of Bipartite Graph

- **ID:** `edge_coloring_of_bipartite_graph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/edge_coloring_of_bipartite_graph
- **Templates (2):**
  - [Edge Coloring Bipartite Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Edge%20Coloring%20Bipartite%20Graph.cpp)
  - [Edge Coloring Bipartite Graph Faster.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Edge%20Coloring%20Bipartite%20Graph%20Faster.cpp)
- **Resources (1):**
  - ★ [Story about edge coloring of graph By ko_osaga,](https://codeforces.com/blog/entry/75431)
- **Problems (8):**
  - `[E]` ★ [Edge coloring of bipartite graph](https://codeforces.com/contest/600/problem/F)
  - `[M]` ★ [Privatization](https://codeforces.com/contest/212/problem/A)
  - `[M]` ★ [Football](https://codeforces.com/contest/1240/problem/F)
  - `[M]` [Choreography](https://official.contest.yandex.ru/opencupXX/contest/17756/problems/G/)
  - `[M]` [Teoreticar](https://oj.uz/problem/view/COCI18_teoreticar)
  - `[M]` [Ancient decoration](https://codeforces.com/problemsets/acmsguru/problem/99999/286)
  - `[H]` ★ [Edge Coloring of Bipartite Graph](https://judge.yosupo.jp/problem/bipartite_edge_coloring)
  - `[H]` [Sorting a Grid](https://atcoder.jp/contests/agc037/tasks/agc037_d)

### 3.14 Graph Counting

**Subcategory ID:** `graph_counting` · **Topics:** 5

#### 3.14.1 Counting Labeled Graphs

- **ID:** `counting_labeled_graphs` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/counting_labeled_graphs
- **Templates (1):**
  - [Counting Labeled Graphs.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Counting%20Labeled%20Graphs.cpp)
- **Resources (1):**
  - ★ [Counting labeled graphs | CP Algorithms](https://cp-algorithms.com/combinatorics/counting_labeled_graphs.html)

#### 3.14.2 Prufer Code

- **ID:** `prufer_code` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/prufer_code
- **Templates (1):**
  - [Prufer Code.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Prufer%20Code.cpp)
- **Resources (2):**
  - ★ [Prüfer code, Cayeley's Formula and the Number of ways to make a graph connected | CP Algorithms](https://cp-algorithms.com/graph/pruefer_code.html)
  - [Counting forests with limited degrees and component sizes By -is-this-fft-](https://codeforces.com/blog/entry/123211)
- **Problems (7):**
  - `[E]` ★ [Prüfer Code](https://cses.fi/problemset/task/1134)
  - `[E]` [Prufer Code](https://acm.timus.ru/problem.aspx?space=1&num=1069)
  - `[E]` [Anne's game](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1784)
  - `[E]` ★ [Clues](https://codeforces.com/contest/156/problem/D)
  - `[M]` ★ [Curious Guardians](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4835)
  - `[M]` ★ [The Selection](https://toph.co/p/the-selection)
  - `[H]` ★ [Combinatorics Is Fun](https://www.codechef.com/problems/COMBIISFUN)

#### 3.14.3 [Problem] Number of Arborescences with n Nodes

- **ID:** `number_of_arborescences_with_n_nodes` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_arborescences_with_n_nodes
- **Templates (1):**
  - [Number of Arborescence.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Number%20of%20Arborescence.cpp)
- **Resources (1):**
  - [Arborescence (graph theory) | Wiki](https://en.wikipedia.org/wiki/Arborescence_%28graph_theory%29)

#### 3.14.4 Tuttes Theorem ft Arborescences in a Graph

- **ID:** `tuttes_theorem_ft_arborescences_in_a_graph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tuttes_theorem_ft_arborescences_in_a_graph
- **Templates (1):**
  - [Tuttes Theorem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Tuttes%20Theorem.cpp)
- **Resources (1):**
  - [The Matrix-Tree Theorems](https://personalpages.manchester.ac.uk/staff/mark.muldoon/Teaching/DiscreteMaths/LectureNotes/IntroToMatrixTree.pdf)
- **Problems (2):**
  - `[E]` ★ [Counting Spanning Trees (Directed)](https://judge.yosupo.jp/problem/counting_spanning_tree_directed)
  - `[E]` ★ [Counting Arborescence](https://www.spoj.com/problems/DAGCNT/)

#### 3.14.5 BEST Theorem

- **ID:** `best_theorem` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/best_theorem
- **Resources (2):**
  - ★ [BEST theorem | wiki](https://en.wikipedia.org/wiki/BEST_theorem)
  - ★ [Editorial of Problem G - 16 Integers](https://atcoder.jp/contests/abc336/editorial/9283)
- **Problems (2):**
  - `[E]` ★ [Counting Eulerian Circuits](https://judge.yosupo.jp/problem/counting_eulerian_circuits)
  - `[H]` ★ [16 Integers](https://atcoder.jp/contests/abc336/tasks/abc336_g)

### 3.15 Dynamic Acyclic Graphs (DAG)

**Subcategory ID:** `dynamic_acyclic_graphs` · **Topics:** 2

#### 3.15.1 DAG Reachability

- **ID:** `dag_reachability` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dag_reachability
- **Resources (2):**
  - [\[Tutorial\] Collection of little techniques By -is-this-fft-](https://codeforces.com/blog/entry/100910)
  - [A Problem About DAG By gkO_o](https://codeforces.com/blog/entry/127593)
- **Problems (6):**
  - `[E]` ★ [Reachable Nodes](https://cses.fi/problemset/task/2138)
  - `[E]` ★ [Counting in a DAG](https://www.spoj.com/problems/DAGCNT2/)
  - `[M]` ★ [Upgrading Cities](https://codeforces.com/contest/1062/problem/F)
  - `[M]` ★ [Dream and the Multiverse](https://codeforces.com/gym/103003/problem/E)
  - `[H]` [Removal Sequences](https://codeforces.com/problemset/problem/1795/G)
  - `[H]` [Balancing Network](https://atcoder.jp/contests/agc041/tasks/agc041_e)

#### 3.15.2 Incremental DAG Reachability

- **ID:** `dynamic_dag_reachability` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_dag_reachability
- **Templates (1):**
  - [DAG Reachability Dynamic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/DAG%20Reachability%20Dynamic.cpp)
- **Resources (1):**
  - [Amortized efficiency of a path retrieval data structure | Paper by G.F. Italiano](https://www.sciencedirect.com/science/article/pii/0304397586900988)
- **Problems (1):**
  - `[M]` ★ [Ghosts having fun](https://www.spoj.com/problems/GHOSTS/)

### 3.16 Dominators

**Subcategory ID:** `dominators` · **Topics:** 1

#### 3.16.1 Dominator Tree

- **ID:** `dominator_tree` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dominator_tree
- **Templates (1):**
  - [Dominator Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Dominator%20Tree.cpp)
- **Resources (2):**
  - ★ [Dominator Tree of a Directed Graph | Tanuj Khattar](https://tanujkhattar.wordpress.com/2016/01/11/dominator-tree-of-a-directed-graph/)
  - [Dominator (graph theory) | Wiki](https://en.wikipedia.org/wiki/Dominator_%28graph_theory%29)
- **Problems (6):**
  - `[E]` ★ [Dominator Tree](https://judge.yosupo.jp/problem/dominatortree)
  - `[M]` ★ [Team Rocket Rises Again](https://codeforces.com/contest/757/problem/F)
  - `[M]` ★ [Useful Roads](https://codeforces.com/gym/100513/problem/L)
  - `[M]` [Counting on a directed graph](https://www.codechef.com/problems/GRAPHCNT)
  - `[M]` ★ [Increasing Costs](https://codeforces.com/gym/101741/problem/L)
  - `[M]` [Two Paths](https://official.contest.yandex.ru/opencupXVII/contest/4227/problems/C/)

### 3.17 Special Graphs

**Subcategory ID:** `special_graphs` · **Topics:** 3

#### 3.17.1 Cactus Graph

- **ID:** `cactus_graph` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/cactus_graph
- **Resources (2):**
  - [Cactus graph | Wiki](https://en.wikipedia.org/wiki/Cactus_graph)
  - [\[Tutorial\] The DFS tree and its applications: how I found out I really didn't understand bridges By -is-this-fft-](https://codeforces.com/blog/entry/68138)
- **Problems (12):**
  - `[E]` ★ [Forest Program](https://codeforces.com/gym/102361/problem/F)
  - `[E]` ★ [Cactus](https://www.spoj.com/problems/CAC/)
  - `[M]` ★ [Cactus](https://codeforces.com/contest/231/problem/E)
  - `[M]` [Masha and Cactus](https://codeforces.com/problemset/problem/856/D)
  - `[H]` [Cactus Not Enough](https://codeforces.com/problemset/problem/1510/C)
  - `[H]` [Cactus Determinant](https://codeforces.com/gym/102201/problem/C)
  - `[H]` ★ [Sum of Distances in Cactus](https://codeforces.com/gym/102441/problem/G)
  - `[H]` [Cactus to Tree](https://codeforces.com/problemset/problem/980/F)
  - `[H]` ★ [Cactusophobia](https://codeforces.com/problemset/problem/720/B)
  - `[VH]` [New Year Cactus](https://codeforces.com/problemset/problem/379/G)
  - `[VH]` [Happy Cactus](https://codeforces.com/problemset/problem/1268/E)
  - `[VH]` [Dead Cacti Society](https://codeforces.com/gym/102391/problem/E)

#### 3.17.2 Tournament Graph

- **ID:** `tournament_graph` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tournament_graph
- **Resources (3):**
  - ★ [Tournament (graph theory) | Wiki](https://en.wikipedia.org/wiki/Tournament_%28graph_theory%29)
  - [Hamiltonian Path in Tournament Graph](https://www.iarcs.org.in/inoi/contests/apr2005/Advanced-2-solution.php)
  - [Strongly Connected Tournament](https://math.stackexchange.com/questions/1200126/strongly-connected-tournament)
- **Problems (9):**
  - `[E]` ★ [Anya's Simultaneous Exhibition](https://codeforces.com/problemset/problem/1779/E)
  - `[M]` [Tournament-graph](https://codeforces.com/contest/323/problem/B)
  - `[M]` [Rank Fraud](https://www.codechef.com/IARCSJUD/problems/RANKFRAD)
  - `[M]` ★ [Cycle](https://codeforces.com/problemset/problem/117/C)
  - `[M]` [Riding in cycles](https://www.spoj.com/problems/CYCLERUN/)
  - `[M]` ★ [Tournament](https://codeforces.com/problemset/problem/878/C)
  - `[M]` [Sum of SCC](https://atcoder.jp/contests/arc163/tasks/arc163_d)
  - `[H]` ★ [Invertation in Tournament](https://codeforces.com/problemset/problem/1268/D)
  - `[H]` [Tournament Construction](https://codeforces.com/problemset/problem/850/D)

#### 3.17.3 Chordal Graph

- **ID:** `chordal_graph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chordal_graph
- **Templates (1):**
  - [Chordal Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Chordal%20Graph.cpp)
- **Resources (2):**
  - ★ [Chordal graph | Wiki](https://en.wikipedia.org/wiki/Chordal_graph)
  - [\[Stream\] Chordal Graph Omakase By ko_osaga](https://codeforces.com/blog/entry/106755)
- **Problems (8):**
  - `[E]` ★ [Chordal Graph Recognition](https://judge.yosupo.jp/problem/chordal_graph_recognition)
  - `[M]` ★ [Egg-free DAG](https://www.codechef.com/problems/EGGFREE)
  - `[H]` [City Tour (Large)](https://www.acmicpc.net/problem/12546)
  - `[H]` [Road](https://www.acmicpc.net/problem/25076)
  - `[H]` [Sister Ports](https://www.acmicpc.net/problem/22460)
  - `[H]` [Kid's Nightmare](https://www.acmicpc.net/problem/19267)
  - `[H]` [Palindromic Equivalence](https://www.codechef.com/DEC20A/problems/PALINDEQ)
  - `[VH]` [Apollonian Network](https://vjudge.net/problem/QOJ-7410)

### 3.18 Flow and Min Cut

**Subcategory ID:** `flow_and_min_cut` · **Topics:** 13

#### 3.18.1 Maximum Flow / Minimum Cut

- **ID:** `max_flow` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/max_flow
- **Templates (2):**
  - [Dinics Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Dinics%20Algorithm.cpp)
  - [PushRelabel.h](https://github.com/kth-competitive-programming/kactl/blob/main/content/graph/PushRelabel.h)
- **Resources (14):**
  - ★ [Maximum flow - Ford-Fulkerson and Edmonds-Karp | CP Algorithms](https://cp-algorithms.com/graph/edmonds_karp.html)
  - [Max Flow Ford Fulkerson | Network Flow | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=LdOnanfc5TM)
  - ★ [Edmonds Karp Algorithm | Network Flow | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=RppuJYwlcI8)
  - ★ [Max-flow min-cut theorem | CP Algorithms](https://cp-algorithms.com/graph/edmonds_karp.html#max-flow-min-cut-theorem)
  - [Maximum flow - Push-relabel algorithm | CP Algorithms](https://cp-algorithms.com/graph/push-relabel.html)
  - [Maximum flow - Push-relabel method improved | CP Algorithms](https://cp-algorithms.com/graph/push-relabel-faster.html)
  - ★ [Maximum flow - Dinic's algorithm | CP Algorithms](https://cp-algorithms.com/graph/dinic.html)
  - ★ [Maximum Flow | USACO Guide](https://usaco.guide/adv/max-flow?lang=cpp)
  - ★ [Flows and cuts | CPH](https://usaco.guide/CPH.pdf#page=191)
  - [Dinic's Algorithm | Network Flow | Graph Theory | WilliamFiset](https://www.youtube.com/watch?v=M6cm8UeeziI)
  - ★ [\[Tutorial\] My way of understanding Dinitz's ("Dinic's") algorithm By -is-this-fft-](https://codeforces.com/blog/entry/104960)
  - [\[Tutorial\] Maximum Flow and Minimum Cost Maximum Flow (to prove greedy) By maomao90](https://codeforces.com/blog/entry/110328)
  - ★ [Menger's theorem | Wiki](https://en.wikipedia.org/wiki/Menger%27s_theorem)
  - [Unweighted Bipartite Matching | Network Flow | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=GhjwOiJ4SqU)
- **Problems (23):**
  - `[E]` ★ [Download Speed](https://cses.fi/problemset/task/1694)
  - `[E]` ★ [Police Chase](https://cses.fi/problemset/task/1695)
  - `[E]` ★ [School Dance](https://cses.fi/problemset/task/1696)
  - `[E]` ★ [Distinct Routes](https://cses.fi/problemset/task/1711)
  - `[E]` [Fast Maximum Flow](https://www.spoj.com/problems/FASTFLOW/)
  - `[E]` ★ [Fast Maximum Matching](https://www.spoj.com/problems/MATCHING/)
  - `[E]` ★ [Matching on Bipartite Graph](https://judge.yosupo.jp/problem/bipartitematching)
  - `[E]` ★ [Best Subsequence](https://codeforces.com/contest/2026/problem/E)
  - `[M]` [Array and Operations](https://codeforces.com/contest/498/problem/C)
  - `[M]` ★ [Coin Grid](https://cses.fi/problemset/task/1709)
  - `[M]` ★ [Card Game](https://codeforces.com/problemset/problem/808/F)
  - `[M]` ★ [The Problem Needs 3D Arrays](https://codeforces.com/gym/100548/problem/C)
  - `[M]` [MobiZone vs VinaGone](https://www.spoj.com/problems/MOBIVINA/)
  - `[M]` [Delivery Bears](https://codeforces.com/problemset/problem/653/D)
  - `[M]` [Cleaning the Space](https://www.codechef.com/problems/SPCLN)
  - `[M]` ★ [Double Sort II](https://codeforces.com/problemset/problem/1783/F)
  - `[M]` [Maximize Mex](https://codeforces.com/problemset/problem/1139/E)
  - `[M]` ★ [Petya and Graph](https://codeforces.com/contest/1082/problem/G)
  - `[H]` [The Wrath of Kahn](https://open.kattis.com/problems/thewrathofkahn)
  - `[H]` ★ [Bricks](https://codeforces.com/contest/1404/problem/E)
  - `[H]` [Goods transportation](https://codeforces.com/problemset/problem/724/E)
  - `[VH]` [Special Edges](https://codeforces.com/contest/1383/problem/F)
  - `[VH]` [Recover a functional graph](https://codeforces.com/contest/739/problem/D)

#### 3.18.2 Min Cost Max Flow (MCMF)

- **ID:** `min_cost_max_flow` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/min_cost_max_flow
- **Templates (1):**
  - [Min Cost Max Flow.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Min%20Cost%20Max%20Flow.cpp)
- **Resources (9):**
  - ★ [Minimum-cost flow - Successive shortest path algorithm | CP Algorithms](https://cp-algorithms.com/graph/min_cost_flow.html)
  - ★ [\[Tutorial\] Minimum cost (maximum) flow By -is-this-fft-](https://codeforces.com/blog/entry/105330)
  - ★ [\[Tutorial\] More about minimum cost flows: potentials and Dinitz By -is-this-fft-](https://codeforces.com/blog/entry/105658)
  - ★ [\[Tutorial\] Graph Potentials, Johnson's Algorithm, and Min Cost Max Flow | Monogon](https://codeforces.com/blog/entry/95823)
  - [Solving assignment problem using min-cost-flow | CP Algorithms](https://cp-algorithms.com/graph/Assignment-problem-min-flow.html)
  - [Minimum Cost Flow | USACO Guide](https://usaco.guide/adv/min-cost-flow?lang=cpp)
  - [\[Tutorial\] Maximum Flow and Minimum Cost Maximum Flow (to prove greedy) By maomao90](https://codeforces.com/blog/entry/110328)
  - [MINIMUM COST FLOW PART TWO: ALGORITHMS | Topcoder](https://www.topcoder.com/thrive/articles/Minimum%20Cost%20Flow%20Part%20Two:%20Algorithms)
  - ★ [\[Tutorial\] Simulating Cost Flow By smax](https://codeforces.com/blog/entry/118391)
- **Problems (26):**
  - `[E]` ★ [Parcel Delivery](https://cses.fi/problemset/task/2121)
  - `[E]` ★ [Minimum Cost b-flow](https://judge.yosupo.jp/problem/min_cost_b_flow)
  - `[E]` ★ [Task Assignment](https://cses.fi/problemset/task/2129)
  - `[E]` ★ [Admiral](https://codeforces.com/gym/101398/problem/A)
  - `[E]` ★ [Grid Puzzle II](https://cses.fi/problemset/task/2131)
  - `[M]` ★ [Four Melodies](https://codeforces.com/contest/818/problem/G)
  - `[M]` ★ [Distinct Routes II](https://cses.fi/problemset/task/2130)
  - `[M]` ★ [Red-Blue Graph](https://codeforces.com/contest/1288/problem/F)
  - `[M]` [Dream Team](https://atcoder.jp/contests/abc247/tasks/abc247_g)
  - `[M]` [Component Placement](https://lightoj.com/problem/component-placement)
  - `[M]` ★ [Anti-Palindromize](https://codeforces.com/contest/884/problem/F)
  - `[M]` [Space Shuttle Experiments](https://lightoj.com/problem/space-shuttle-experiments)
  - `[M]` ★ [Button Lock](https://codeforces.com/problemset/problem/1510/B)
  - `[M]` ★ [Vasya and Endless Credits](https://codeforces.com/problemset/problem/1107/F)
  - `[M]` ★ [Petya and Graph](https://codeforces.com/contest/1082/problem/G)
  - `[M]` [Build String](https://codeforces.com/contest/237/problem/E)
  - `[M]` [April Fools' Problem (medium)](https://codeforces.com/contest/802/problem/N)
  - `[M]` ★ [Catering](https://vjudge.net/problem/Kattis-catering)
  - `[M]` ★ [No Cross Matching](https://atcoder.jp/contests/abc373/tasks/abc373_g)
  - `[M]` ★ [Polynomial K Paths](https://codeforces.com/gym/105884/problem/E)
  - `[H]` ★ [Heidi and Library (hard)](https://codeforces.com/problemset/problem/802/C)
  - `[H]` [Programmers and Artists](https://cses.fi/problemset/task/2426)
  - `[H]` [k-Maximum Subsequence Sum](https://codeforces.com/contest/280/problem/D)
  - `[VH]` ★ [Cow and Exercise](https://codeforces.com/contest/1307/problem/G)
  - `[VH]` [One Billion Shades of Grey](https://codeforces.com/contest/1427/problem/G)
  - `[VH]` [April Fools' Problem (hard)](https://codeforces.com/contest/802/problem/O)

#### 3.18.3 Min Cost Max Flow with Negative Cycles

- **ID:** `min_cost_max_flow_with_negative_cycles` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_cost_max_flow_with_negative_cycles
- **Templates (1):**
  - [Min Cost Max Flow with Negative Cycles.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Min%20Cost%20Max%20Flow%20with%20Negative%20Cycles.cpp)
- **Resources (1):**
  - [A comment by dacin21](https://codeforces.com/blog/entry/57018?#comment-406848)
- **Problems (1):**
  - `[M]` [最小费用最大流](https://uoj.ac/problem/487)

#### 3.18.4 Maximum Closure Problem

- **ID:** `maximum_closure_problem` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_closure_problem
- **Templates (1):**
  - [Maximum Closure Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Closure%20Problem.cpp)
- **Resources (2):**
  - ★ [Closure problem | Wiki](https://en.wikipedia.org/wiki/Closure_problem)
  - ★ [\[Tutorial, Flows\] Project Selection Problem By AlexLuchianov](https://codeforces.com/blog/entry/101354)
- **Problems (7):**
  - `[E]` ★ [MUL](https://atcoder.jp/contests/arc085/tasks/arc085_c)
  - `[M]` ★ [Strange Set](https://codeforces.com/problemset/problem/1473/F)
  - `[M]` [Fashion](https://csacademy.com/contest/rmi-2017-day-1/task/fashion/)
  - `[M]` [Open-Pit Mining](https://open.kattis.com/problems/openpitmining)
  - `[M]` ★ [Petya and Graph](https://codeforces.com/contest/1082/problem/G)
  - `[M]` [Killable Demon](https://codeforces.com/gym/105873/problem/K)
  - `[H]` [Zoning Restrictions](https://codeforces.com/problemset/problem/1146/G)

#### 3.18.5 L-R Flow

- **ID:** `l_r_flow` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/l_r_flow
- **Templates (2):**
  - [L R Flow with Dinic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/L%20R%20Flow%20with%20Dinic.cpp)
  - [L R Flow with MCMF.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/L%20R%20Flow%20with%20MCMF.cpp)
- **Resources (3):**
  - ★ [Flows with demands | CP Algorithms](https://cp-algorithms.com/graph/flow_with_demands.html)
  - [CMSC 451: Max-Flow Extensions | Slides By: Carl Kingsford](https://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/flowext.pdf)
  - [18 Extensions of Maximum Flow](https://web.archive.org/web/20180619120145/http://web.engr.illinois.edu/~jeffe/teaching/algorithms/2009/notes/18-maxflowext.pdf)
- **Problems (6):**
  - `[E]` ★ [Reactor Cooling](https://codeforces.com/gym/100199/problem/B)
  - `[M]` ★ [Captain America](https://codeforces.com/problemset/problem/704/D)
  - `[M]` ★ [Red-Blue Graph](https://codeforces.com/contest/1288/problem/F)
  - `[M]` [Diverse Singing](https://codeforces.com/gym/102156/problem/C)
  - `[H]` [Incorrect Flow](https://codeforces.com/contest/708/problem/D)
  - `[VH]` [Showing Off](https://codeforces.com/contest/1416/problem/F)

#### 3.18.6 Gomory-Hu Tree

- **ID:** `gomory_hu_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gomory_hu_tree
- **Templates (1):**
  - [Gomory Hu Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Gomory%20Hu%20Tree.cpp)
- **Resources (1):**
  - [Gomory–Hu tree | Wiki](https://en.wikipedia.org/wiki/Gomory%E2%80%93Hu_tree)
- **Problems (2):**
  - `[M]` ★ [Pumping Stations](https://codeforces.com/problemset/problem/343/E)
  - `[M]` [Minimal Cut Matrix](https://codeforces.com/gym/100153/problem/D)

#### 3.18.7 Gomory-Hu Tree of a Planar Graph

- **ID:** `gomory_hu_tree_of_a_planar_graph` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gomory_hu_tree_of_a_planar_graph
- **Templates (1):**
  - [Gomory Hu Tree of Planar Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Gomory%20Hu%20Tree%20of%20Planar%20Graph.cpp)
- **Problems (1):**
  - `[M]` ★ [All Pair Maximum Flow](https://codeforces.com/gym/102471/problem/K)

#### 3.18.8 Stoer Wagner Algorithm

- **ID:** `stoer_wagner_algorithm` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stoer_wagner_algorithm
- **Templates (1):**
  - [Stoer Wagner Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Stoer%20Wagner%20Algorithm.cpp)
- **Resources (1):**
  - ★ [Minimum Cut - Stoer–Wagner algorithm | Coding with Thomas](https://blog.thomasjungblut.com/graph/mincut/mincut/)
- **Problems (1):**
  - `[E]` ★ [Bomb, Divide and Conquer](https://vjudge.net/problem/UVA-10989)

#### 3.18.9 Chinese Postman Problem

- **ID:** `chinese_postman_problem` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chinese_postman_problem
- **Templates (1):**
  - [Chinese Postman Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Chinese%20Postman%20Problem.cpp)
- **Resources (2):**
  - [Chinese postman problem | Wiki](https://en.wikipedia.org/wiki/Chinese_postman_problem)
  - ★ [Solving the Chinese Postman's Problem | MIT](https://web.mit.edu/urban_or_book/www/book/chapter6/6.4.4.html)
- **Problems (2):**
  - `[M]` ★ [Traveling Graph](https://codeforces.com/problemset/problem/21/D)
  - `[M]` ★ [Jogging Trails](https://vjudge.net/problem/UVA-10296)

#### 3.18.10 Uniqueness of Min Cut

- **ID:** `unique_min_cut` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/unique_min_cut
- **Templates (1):**
  - [Unique Min Cut.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Unique%20Min%20Cut.cpp)
- **Resources (1):**
  - [Determining the uniqueness of a min-cut](https://stackoverflow.com/questions/7673711/determining-the-uniqueness-of-a-min-cut)
- **Problems (1):**
  - `[E]` ★ [Unique Attack](https://codeforces.com/gym/100200/problem/A)

#### 3.18.11 Maximum Density Subgraph

- **ID:** `maximum_density_subgraph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_density_subgraph
- **Templates (1):**
  - [Maximum Density Subgraph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Maximum%20Density%20Subgraph.cpp)
- **Resources (1):**
  - ★ [Finding a Maximum Density Subgraph | Goldberg](https://www2.eecs.berkeley.edu/Pubs/TechRpts/1984/CSD-84-171.pdf)
- **Problems (1):**
  - `[E]` ★ [Hard Life](https://vjudge.net/problem/UVA-1389)

#### 3.18.12 Min Cut in a Planar Graph

- **ID:** `min_cut_in_a_planar_graph` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_cut_in_a_planar_graph
- **Templates (1):**
  - [Min Cut in a Planar Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Min%20Cut%20in%20a%20Planar%20Graph.cpp)
- **Resources (1):**
  - [Min st-Cut of a Planar Graph in O(n log log n) Time | Christian Wulff-Nilsen](https://arxiv.org/pdf/1007.3609)
- **Problems (2):**
  - `[E]` ★ [Ada and Hose](https://www.spoj.com/problems/ADAHOSE/)
  - `[E]` ★ [Animal Run](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=4122)

#### 3.18.13 Max Cut in a Planar Graph

- **ID:** `max_cut_in_a_planar_graph` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/max_cut_in_a_planar_graph
- **Problems (1):**
  - `[H]` [Planar Max Cut](https://codeforces.com/gym/102156/problem/F)

### 3.19 Matching

**Subcategory ID:** `matching` · **Topics:** 8

#### 3.19.1 Bipartite Matching (HopCroft Karp Algorithm and Kuhn's Algorithm)

- **ID:** `bipartite_matching` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/bipartite_matching
- **Templates (2):**
  - [HopCroft Karp Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/HopCroft%20Karp%20Algorithm.cpp)
  - [Kuhns Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Kuhns%20Algorithm.cpp)
- **Resources (3):**
  - [Hopcroft–Karp Algorithm | Brilliant](https://brilliant.org/wiki/hopcroft-karp/)
  - [Understanding Hopcroft-Karp Algorithm for Maximum Matching | Punem Nithin](https://medium.com/@punem_nithin/understanding-hopcroft-karp-algorithm-for-maximum-matching-9f6d5b4b0719)
  - ★ [Kuhn's Algorithm for Maximum Bipartite Matching | CP Algorithms](https://cp-algorithms.com/graph/kuhn_maximum_bipartite_matching.html)
- **Problems (16):**
  - `[E]` ★ [School Dance](https://cses.fi/problemset/task/1696)
  - `[E]` ★ [Fast Maximum Matching](https://www.spoj.com/problems/MATCHING/)
  - `[E]` ★ [Matching on Bipartite Graph](https://judge.yosupo.jp/problem/bipartitematching)
  - `[E]` [Gopher II](https://open.kattis.com/problems/gopher2)
  - `[E]` [Work Scheduling](https://acm.timus.ru/problem.aspx?space=1&num=1099)
  - `[E]` [Knights in Chessboard (II)](https://lightoj.com/problem/knights-in-chessboard-ii)
  - `[E]` [Airports](https://codeforces.com/gym/100820/problem/A)
  - `[E]` [Ada and Path](https://www.spoj.com/problems/ADAPATH/)
  - `[E]` ★ [Best Subsequence](https://codeforces.com/contest/2026/problem/E)
  - `[E]` [Horse Race](https://codeforces.com/gym/104252/problem/H)
  - `[M]` [Maximize Mex](https://codeforces.com/problemset/problem/1139/E)
  - `[M]` [Borders](https://open.kattis.com/problems/borders)
  - `[M]` [Array and Operations](https://codeforces.com/contest/498/problem/C)
  - `[M]` [Plug It In](https://codeforces.com/gym/101873/problem/F)
  - `[H]` ★ [Just Enough Bridges](https://open.kattis.com/problems/justenoughbridges)
  - `[H]` ★ [Bricks](https://codeforces.com/contest/1404/problem/E)

#### 3.19.2 Hungarian Algorithm / Bipartite Weighted Matching

- **ID:** `hungarian_algorithm` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/hungarian_algorithm
- **Templates (1):**
  - [Hungarian Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Hungarian%20Algorithm.cpp)
- **Resources (3):**
  - ★ [ASSIGNMENT PROBLEM AND HUNGARIAN ALGORITHM | TopCoder](https://www.topcoder.com/thrive/articles/Assignment%20Problem%20and%20Hungarian%20Algorithm)
  - [AlgorithmsThread 0: Hungarian for non Hungarians](https://www.youtube.com/watch?v=cVBzMXYc4ss)
  - [Hungarian Maximum Matching Algorithm | Brilliant](https://brilliant.org/wiki/hungarian-matching/)
- **Problems (6):**
  - `[E]` ★ [Task Assignment](https://cses.fi/problemset/task/2129)
  - `[E]` ★ [Grid Puzzle II](https://cses.fi/problemset/task/2131)
  - `[E]` [Convincing Customers](https://toph.co/p/convincing-customers)
  - `[M]` ★ [Vasya and Endless Credits](https://codeforces.com/problemset/problem/1107/F)
  - `[M]` [Ada and Cities](https://www.spoj.com/problems/ADACITY/)
  - `[M]` ★ [No Cross Matching](https://atcoder.jp/contests/abc373/tasks/abc373_g)

#### 3.19.3 Blossom Algorithm Unweighted / General Matching / Randomized General Matching

- **ID:** `blossom_algorithm_unweighted` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/blossom_algorithm_unweighted
- **Templates (2):**
  - [Blossom Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Blossom%20Algorithm.cpp)
  - [Randomized Matching Unweighted.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Randomized%20Matching%20Unweighted.cpp)
- **Resources (4):**
  - ★ [\[Tutorial\] Blossom Algorithm for General Matching in O(n^3) By Monogon](https://codeforces.com/blog/entry/92339)
  - [Blossom algorithm | Wiki](https://en.wikipedia.org/wiki/Blossom_algorithm)
  - [Discussion in comments about Randomized Algorithm for General Matching](https://codeforces.com/blog/entry/92339?#comment-810158)
  - ★ [Randomized general matching with Tutte matrix By adamant](https://codeforces.com/blog/entry/92400)
- **Problems (4):**
  - `[E]` ★ [Matching on General Graph](https://judge.yosupo.jp/problem/general_matching)
  - `[E]` [一般图最大匹配](https://uoj.ac/problem/79)
  - `[E]` ★ [Party At School](https://www.spoj.com/problems/VPARTY/)
  - `[M]` ★ [A game on a graph](https://www.codechef.com/problems/HAMILG)

#### 3.19.4 Blossom Algorithm Weighted / General Weighted Matching

- **ID:** `blossom_algorithm_weighted` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/blossom_algorithm_weighted
- **Templates (2):**
  - [Blossom Algorithm Weighted.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Blossom%20Algorithm%20Weighted.cpp)
  - [Randomized Matching Weighted.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Randomized%20Matching%20Weighted.cpp)
- **Problems (2):**
  - `[E]` ★ [General Weighted Matching](https://judge.yosupo.jp/problem/general_weighted_matching)
  - `[E]` [一般图最大权匹配](https://uoj.ac/problem/81)

#### 3.19.5 Stable Marriage Problem

- **ID:** `stable_marriage_problem` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stable_marriage_problem
- **Templates (1):**
  - [Stable Marriage Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Stable%20Marriage%20Problem.cpp)
- **Resources (1):**
  - [Stable marriage problem | Wiki](https://en.wikipedia.org/wiki/Stable_marriage_problem)
- **Problems (3):**
  - `[E]` ★ [Stable Marriage Problem](https://www.spoj.com/problems/STABLEMP/)
  - `[M]` [Block Game](https://www.codechef.com/problems/BLOCKING)
  - `[H]` [Restaurants](https://codeforces.com/gym/103081/problem/L)

#### 3.19.6 Konig's Theorem and Maximum Independent Set in Bipartite Graphs

- **ID:** `maximum_independent_set_in_bipartite_graphs` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_independent_set_in_bipartite_graphs
- **Resources (2):**
  - ★ [Maximum Independent Set in Bipartite Graphs | Ali Ibrahim](https://ali-ibrahim137.github.io/competitive/programming/2020/01/02/maximum-independent-set-in-bipartite-graphs.html)
  - [Kőnig's theorems through minimum cut in bipartite graphs By adamant](https://codeforces.com/blog/entry/105697)
- **Problems (4):**
  - `[E]` ★ [No Prime Sum](https://csacademy.com/contest/archive/task/no-prime-sum/)
  - `[E]` [Heavy Chain Clusterization](https://codeforces.com/gym/100269/problem/H)
  - `[E]` ★ [Best Subsequence](https://codeforces.com/contest/2026/problem/E)
  - `[M]` [Easter Eggs](https://codeforces.com/gym/101666/problem/E)

#### 3.19.7 Halls Theorem

- **ID:** `halls_theorem` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/halls_theorem
- **Resources (4):**
  - ★ [Hall's marriage theorem | Wiki](https://en.wikipedia.org/wiki/Hall%27s_marriage_theorem)
  - [Hall's theorems through minimum cut in bipartite graphs By adamant](https://codeforces.com/blog/entry/105697)
  - [TCO 2015 Round 1A DIV 1 Problem 1000 Points By awaken](https://codeforces.com/blog/entry/44061)
  - [Discussion about a problem](https://codeforces.com/blog/entry/58793?#comment-424348)
- **Problems (6):**
  - `[M]` ★ [Bear and Fair Set](https://codeforces.com/contest/628/problem/F)
  - `[M]` [Hall's Theorem](https://codeforces.com/gym/102268/problem/H)
  - `[M]` ★ [Exhausted?](https://atcoder.jp/contests/arc076/tasks/arc076_d)
  - `[M]` ★ [Teams](https://oj.uz/problem/view/IOI15_teams)
  - `[M]` ★ [Ice Skates](https://www.acmicpc.net/problem/8177)
  - `[H]` [New Year and Forgotten Tree](https://codeforces.com/contest/611/problem/H)

#### 3.19.8 Matching using Determinants

- **ID:** `matching_using_determinants` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/matching_using_determinants
- **Resources (2):**
  - ★ [A bit more of general ideas By adamant](https://codeforces.com/blog/entry/104466)
  - ★ [Editorial of Divisible Matching](https://csacademy.com/contest/round-67/task/divisible-matching/solution/)
- **Problems (2):**
  - `[H]` [Chef and Lost Story](https://www.codechef.com/SEPT18A/problems/CHEFLST)
  - `[H]` ★ [Divisible Matching](https://csacademy.com/contest/round-67/task/divisible-matching/statement/)

### 3.20 Partially Ordered Set (POSET)

**Subcategory ID:** `poset` · **Topics:** 1

#### 3.20.1 POSET ft Dilworth's and Mirsky's Theorem

- **ID:** `poset_ft_dilworths_and_mirskys_theorem` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/poset_ft_dilworths_and_mirskys_theorem
- **Resources (3):**
  - ★ [Partially Ordered Sets By paladin8](https://codeforces.com/blog/entry/3781)
  - ★ [Lecture 14 – Posets: Mirsky’s & Dilworth’s Theorems](https://sites.gatech.edu/math3012openresources/lecture-videos/lecture-14/)
  - ★ [Dilworth Theorem for Competitive Programming | Mirsky's Theorem | Bipartite Matching | Flow | Vivek Gupta](https://www.youtube.com/watch?v=7TpBLqvqeaA)
- **Problems (10):**
  - `[E]` ★ [Cow Jog](https://usaco.org/index.php?page=viewproblem2&cpid=496)
  - `[E]` [Nested Dolls](https://www.spoj.com/problems/MDOLLS/)
  - `[M]` ★ [Clique in the Divisibility Graph](https://codeforces.com/problemset/problem/566/F)
  - `[M]` [Access Levels](https://codeforces.com/contest/1765/problem/A)
  - `[M]` [Polygon Containment](https://www.codechef.com/AM19MOS/problems/POLCON)
  - `[M]` ★ [Select Strings](https://atcoder.jp/contests/abc354/tasks/abc354_g)
  - `[M]` ★ [Tensor](https://codeforces.com/contest/1977/problem/E)
  - `[M]` ★ [Divisibility Relation](https://www.spoj.com/problems/DIVREL/)
  - `[H]` [The Wrath of Kahn](https://open.kattis.com/problems/thewrathofkahn)
  - `[VH]` ★ [Birthday](https://codeforces.com/contest/590/problem/E)

### 3.21 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 5

#### 3.21.1 Functional Graphs

- **ID:** `functional_graphs` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/functional_graphs
- **Resources (3):**
  - ★ [Introduction to Functional Graphs | USACO Guide](https://usaco.guide/silver/func-graphs?lang=cpp)
  - [16.3 Successor paths | CPH](https://usaco.guide/CPH.pdf#page=164)
  - [The Tortoise and the Hare (Floyd’s Algorithm) | Tu Vo](https://medium.com/@tuvo1106/the-tortoise-and-the-hare-floyds-algorithm-87badf5f7d41)
- **Problems (18):**
  - `[E]` ★ [Planets Queries I](https://cses.fi/problemset/task/1750)
  - `[E]` ★ [Planets Queries II](https://cses.fi/problemset/task/1160)
  - `[E]` ★ [Planets Cycles](https://cses.fi/problemset/task/1751)
  - `[E]` ★ [Reachability in Functional Graph](https://atcoder.jp/contests/abc357/tasks/abc357_e)
  - `[E]` [Secret Santa](https://codeforces.com/contest/1530/problem/D)
  - `[E]` [Badge](https://codeforces.com/contest/1020/problem/B)
  - `[E]` [The Bovine Shuffle](https://usaco.org/index.php?page=viewproblem2&cpid=764)
  - `[M]` [Cooperative Game](https://codeforces.com/contest/1137/problem/D)
  - `[M]` [Visits](https://usaco.org/index.php?page=viewproblem2&cpid=1230)
  - `[M]` [Luxury River Cruise](https://usaco.org/index.php?page=viewproblem2&cpid=284)
  - `[M]` ★ [Analysis of Pathes in Functional Graph](https://codeforces.com/problemset/problem/702/E)
  - `[M]` [Medium Demon Problem (easy version)](https://codeforces.com/contest/2044/problem/G1)
  - `[M]` [Medium Demon Problem (hard version)](https://codeforces.com/contest/2044/problem/G2)
  - `[M]` [Kernel Knights](https://basecamp.eolymp.com/en/problems/7782)
  - `[H]` ★ [Infinite Tree](https://toph.co/arena?practice=65ecc1a8c0b22c15ba984e0b#!/p/65d0c60eff9ef22def4bd3b5)
  - `[H]` ★ [Hobson's Trains](https://vjudge.net/problem/Kattis-hobsonstrains)
  - `[H]` [Vending Machine](https://open.kattis.com/problems/vending)
  - `[H]` [Mafija](https://open.kattis.com/problems/mafija)

#### 3.21.2 Degree Sequences

- **ID:** `degree_sequences` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/degree_sequences
- **Resources (4):**
  - [Erdős–Gallai theorem | Wiki](https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Gallai_theorem)
  - [Havel–Hakimi algorithm | Wiki](https://en.wikipedia.org/wiki/Havel%E2%80%93Hakimi_algorithm)
  - [A simple algorithm for realizing a degree sequence as a connected graph | Szabolcs Horvát](http://szhorvat.net/pelican/hh-connected-graphs.html)
  - [Gale–Ryser theorem | Wiki](https://en.wikipedia.org/wiki/Gale%E2%80%93Ryser_theorem)
- **Problems (6):**
  - `[E]` ★ [Degree Set](https://codeforces.com/problemset/problem/976/D)
  - `[E]` ★ [Degree Sequence Tree](https://codeforces.com/problemset/gymProblem/100738/D)
  - `[E]` [Maximum Diameter Graph](https://codeforces.com/problemset/problem/1082/d)
  - `[M]` [New Year and the Acquaintance Estimation](https://codeforces.com/contest/1091/problem/E)
  - `[H]` [Removal Sequences](https://codeforces.com/problemset/problem/1795/G)
  - `[H]` ★ [Constrained Tree Degree](https://atcoder.jp/contests/abc303/tasks/abc303_h)

#### 3.21.3 Tree Isomorphism

- **ID:** `tree_isomorphism` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tree_isomorphism
- **Templates (1):**
  - [Tree Isomorphism.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Graph%20Theory/Tree%20Isomorphism.cpp)
- **Resources (4):**
  - ★ [Tree isomorphism | Slides by Alexander Smal](https://logic.pdmi.ras.ru/~smal/files/smal_jass08_slides.pdf)
  - ★ [Explanation for ‘Tree isomorphism’ talk by Alexander Smal](https://wwwmayr.in.tum.de/konferenzen/Jass08/courses/1/smal/Smal_Paper.pdf)
  - [\[Tutorial\] Tree Isomorphism CSES By Olympia](https://codeforces.com/blog/entry/101010)
  - ★ [Hashing root trees By Vladosiya](https://codeforces.com/blog/entry/113465)
- **Problems (14):**
  - `[E]` ★ [Tree Isomorphism I](https://cses.fi/problemset/task/1700)
  - `[E]` ★ [Tree Isomorphism II](https://cses.fi/problemset/task/1701)
  - `[E]` [Tree Isomorphism](https://www.spoj.com/problems/TREEISO/)
  - `[E]` ★ [Rooted Tree Isomorphism Classification](https://judge.yosupo.jp/problem/rooted_tree_isomorphism_classification)
  - `[E]` [Binary Isomorphism](https://csacademy.com/contest/round-73/task/binary-isomorphism/)
  - `[E]` ★ [Symmetree](https://codeforces.com/contest/1800/problem/G)
  - `[E]` [Vortex](https://qoj.ac/contest/1917/problem/10097)
  - `[M]` [A tale of two trees](https://www.codechef.com/problems/TWOTREES)
  - `[M]` [Regular Forestation](https://codeforces.com/contest/1252/problem/F)
  - `[M]` [Tree Automorphisms](https://codeforces.com/gym/102354/problem/J)
  - `[M]` [Two Charts Become One](https://open.kattis.com/problems/twochartsbecomeone)
  - `[M]` ★ [Isomorphic Graph](https://toph.co/p/isomorphic-graph)
  - `[H]` ★ [Timofey and a flat tree](https://codeforces.com/problemset/problem/763/D)
  - `[H]` ★ [Generator Tree](https://codeforces.com/gym/103640/problem/G)

#### 3.21.4 Binarizing a Tree

- **ID:** `binarizing_a_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/binarizing_a_tree
- **Templates (1):**
  - [Binarizing a Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Data%20Structures/Binarizing%20a%20Tree.cpp)
- **Resources (1):**
  - ★ [Editorial of 757G — Can Bash Save the Day?](https://codeforces.com/blog/entry/49743)
- **Problems (1):**
  - `[H]` ★ [Can Bash Save the Day?](https://codeforces.com/contest/757/problem/G)

#### 3.21.5 Planarity Check

- **ID:** `planarity_check` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/planarity_check
- **Resources (2):**
  - [Planarity testing | Wiki](https://en.wikipedia.org/wiki/Planarity_testing)
  - [Session 2A - Fully-dynamic Planarity Testing in Polylogarithmic Time](https://www.youtube.com/watch?v=1deOVlruc-o)

---

## 4. Number Theory

**Category ID:** `number_theory` · **Subcategories:** 9 · **Topics:** 57

### 4.1 Primes and Divisors

**Subcategory ID:** `primes_and_divisors` · **Topics:** 12

#### 4.1.1 Sieve, Prime Factorization and Divisors

- **ID:** `sieve` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/sieve
- **Templates (1):**
  - [Sieve.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sieve.cpp)
- **Resources (12):**
  - ★ [21.1 Primes and factors | CPH](https://usaco.guide/CPH.pdf#page=207)
  - ★ [Sieve of Eratosthenes | CP Algorithms](https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html)
  - [L02 : Sieve of Eretosthenes | Number Theory | CodeNCode](https://www.youtube.com/watch?v=7zYMjXqdchc)
  - [Sieve of Eratosthenes | TarifEzaz](https://toph.co/tutorials/sieve-of-eratosthenes)
  - [Introduction to Number Theory | David Altizio](https://davidaltizio.web.illinois.edu/Divisors%20and%20Divisibility%20Overview.pdf)
  - [Basic Number Theory-2 | HackerEarth](https://www.hackerearth.com/practice/math/number-theory/basic-number-theory-2/tutorial/)
  - ★ [Extensions of the Prime Sieve By Hikari9](https://codeforces.com/blog/entry/22229)
  - ★ [Divisibility | USACO Guide](https://usaco.guide/gold/divisibility?lang=cpp)
  - [Least prime factor of numbers till n | Geeks for Geeks](https://www.geeksforgeeks.org/least-prime-factor-of-numbers-till-n/)
  - ★ [Prime Factorization using Sieve O(log n) for multiple queries | Geeks for Geeks](https://www.geeksforgeeks.org/prime-factorization-using-sieve-olog-n-multiple-queries/)
  - [Bitwise Sieve | Geeks for Geeks](https://www.geeksforgeeks.org/bitwise-sieve/)
  - [বিটওয়াইজ্ সিভ(Bitwise sieve) | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=855)
- **Problems (44):**
  - `[E]` ★ [Count Primes](https://leetcode.com/problems/count-primes/description/)
  - `[E]` ★ [Almost Prime](https://vjudge.net/problem/CodeForces-26A)
  - `[E]` ★ [N-th Prime](https://toph.co/p/n-th-prime)
  - `[E]` ★ [Printing some primes](https://www.spoj.com/problems/TDPRIMES/)
  - `[E]` ★ [Primal Fear](https://www.spoj.com/problems/VECTAR8/)
  - `[E]` [A conjecture of Paul Erdős](https://www.spoj.com/problems/HS08PAUL/)
  - `[E]` [primes triangle (I)](https://www.spoj.com/problems/PTRI2/)
  - `[E]` ★ [Medium Factorization](https://www.spoj.com/problems/FACTCG2/)
  - `[E]` ★ [Integer Factorization (15 digits)](https://www.spoj.com/problems/FACT0/)
  - `[E]` ★ [Counting Divisors](https://cses.fi/problemset/task/1713)
  - `[E]` ★ [Divisor Summation](https://www.spoj.com/problems/DIVSUM/)
  - `[E]` ★ [Common Divisors](https://cses.fi/problemset/task/1081)
  - `[E]` [Sherlock and his girlfriend](https://codeforces.com/contest/776/problem/B)
  - `[E]` ★ [Div Game](https://atcoder.jp/contests/abc169/tasks/abc169_d)
  - `[E]` [Four Divisors](https://leetcode.com/problems/four-divisors/description/)
  - `[E]` ★ [Divisor Summation (Hard)](https://www.spoj.com/problems/DIVSUM2/)
  - `[E]` [Number of common divisors](https://www.spoj.com/problems/COMDIV/)
  - `[E]` ★ [Printing Divisors](https://vjudge.net/problem/LightOJ-1443)
  - `[E]` [Interesting Ratio](https://codeforces.com/contest/2091/problem/E)
  - `[M]` ★ [T-primes](https://codeforces.com/problemset/problem/230/B)
  - `[M]` ★ [N-Factorful](https://www.spoj.com/problems/NFACTOR/)
  - `[M]` ★ [Namit In Trouble](https://www.spoj.com/problems/NGIRL/)
  - `[M]` ★ [Bazinga!](https://www.spoj.com/problems/DCEPC505/)
  - `[M]` [Binary Sequence of Prime Number](https://www.spoj.com/problems/BSPRIME/)
  - `[M]` [A Different Kind of Sorting](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2338)
  - `[M]` [Noldbach problem](https://codeforces.com/problemset/problem/17/A)
  - `[M]` [Colliders](https://codeforces.com/contest/154/problem/B)
  - `[M]` ★ [Soldier and Number Game](https://codeforces.com/contest/546/problem/D)
  - `[M]` [Reducing Fractions](https://codeforces.com/contest/222/problem/C)
  - `[M]` ★ [Integral Array](https://codeforces.com/contest/1649/problem/D)
  - `[M]` [Up the Strip](https://codeforces.com/contest/1561/problem/D2)
  - `[M]` [Power Products](https://codeforces.com/contest/1225/problem/D)
  - `[M]` ★ [Orac and LCM](https://codeforces.com/contest/1349/problem/A)
  - `[M]` ★ [Minimum Possible LCM](https://codeforces.com/contest/1154/problem/G)
  - `[M]` ★ [Coprime Subsequences](https://codeforces.com/contest/803/problem/F)
  - `[M]` [Trailing Zeroes (I)](https://lightoj.com/problem/trailing-zeroes-i)
  - `[M]` [Kavi on Pairing Duty](https://codeforces.com/contest/1529/problem/D)
  - `[M]` [An interesting problem](https://atcoder.jp/contests/abc052/tasks/arc067_a)
  - `[M]` [Jzzhu and Apples](https://codeforces.com/contest/450/problem/E)
  - `[H]` ★ [The Number of Pairs](https://codeforces.com/contest/1499/problem/D)
  - `[H]` ★ [GCD or MIN](https://atcoder.jp/contests/abc191/tasks/abc191_f)
  - `[H]` ★ [GCD of an Array](https://codeforces.com/contest/1493/problem/D)
  - `[H]` [Chain Reaction](https://codeforces.com/contest/1954/problem/E)
  - `[VH]` [Chef and Sums](https://www.codechef.com/problems/CHEFSUMS)

#### 4.1.2 Linear Sieve

- **ID:** `linear_sieve` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_sieve
- **Templates (1):**
  - [Sieve Linear.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sieve%20Linear.cpp)
- **Resources (2):**
  - ★ [Linear Sieve | CP Algorithms](https://cp-algorithms.com/algebra/prime-sieve-linear.html)
  - [\[Tutorial\] Math note — linear sieve By Nisiyama_Suzune](https://codeforces.com/blog/entry/54090)
- **Problems (3):**
  - `[E]` ★ [Printing some primes](https://www.spoj.com/problems/TDPRIMES/)
  - `[E]` [The Embarrassed Cryptographer](https://vjudge.net/problem/POJ-2635)
  - `[M]` [Ingredients that may Harm You](https://codeforces.com/gym/105327/problem/I)

#### 4.1.3 Segmented Sieve

- **ID:** `segmented_sieve` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/segmented_sieve
- **Templates (2):**
  - [Segmented Sieve.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Segmented%20Sieve.cpp)
  - [sieve-of-eratosthenes.html#segmented-sieve](https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html#segmented-sieve)
- **Resources (4):**
  - ★ [Segmented Sieve | CP Algorithms](https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html#segmented-sieve)
  - [Segmented Sieve (Print Primes in a Range) | Geeks For Geeks](https://www.geeksforgeeks.org/segmented-sieve-print-primes-in-a-range/)
  - [L22 : What is Segmented Sieve and why you should learn it? | Number Theory | CodeNCode](https://www.youtube.com/watch?v=uCgCMW9CMn4)
  - [Segmented sieve of Eratosthenes | kimwalisch](https://github.com/kimwalisch/primesieve/wiki/Segmented-sieve-of-Eratosthenes)
- **Problems (6):**
  - `[E]` ★ [Prime Generator](https://www.spoj.com/problems/PRIME1/)
  - `[E]` ★ [Prime pair connection](https://www.hackerrank.com/contests/projecteuler/challenges/euler134/problem)
  - `[E]` [Prime Intervals](https://www.spoj.com/problems/PRINT/)
  - `[E]` [Next Prime](https://cses.fi/problemset/task/3396)
  - `[E]` ★ [LCM Sequence](https://atcoder.jp/contests/abc412/tasks/abc412_e)
  - `[M]` ★ [Divisors of Binomial Coefficient](https://atcoder.jp/contests/abc227/tasks/abc227_g)

#### 4.1.4 Sieve upto 1e9

- **ID:** `sieve_upto_1e9` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sieve_upto_1e9
- **Templates (1):**
  - [Sieve upto 1e9.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sieve%20upto%201e9.cpp)
- **Problems (2):**
  - `[E]` ★ [Printing some primes (Hard)](https://www.spoj.com/problems/PRIMES2/)
  - `[E]` ★ [Enumerate Primes](https://judge.yosupo.jp/problem/enumerate_primes)

#### 4.1.5 Miller-Rabin Primality Test

- **ID:** `miller_rabin_primality_test` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/miller_rabin_primality_test
- **Templates (1):**
  - [Miller Rabin.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Miller%20Rabin.cpp)
- **Resources (4):**
  - ★ [Primality tests | CP Algorithms](https://cp-algorithms.com/algebra/primality_tests.html)
  - [Miller–Rabin primality test | Wiki](https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test)
  - [About Miller Rabbin By Abel51](https://codeforces.com/blog/entry/122130)
  - [A proof of error bound of Miller-Rabin prime test By randop](https://codeforces.com/blog/entry/98102)
- **Problems (3):**
  - `[E]` ★ [Primality Test](https://judge.yosupo.jp/problem/primality_test)
  - `[E]` [Prime or Not](https://www.spoj.com/problems/PON/)
  - `[E]` [Next Prime](https://cses.fi/problemset/task/3396)

#### 4.1.6 Pollard Rho

- **ID:** `pollard_rho` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pollard_rho
- **Templates (1):**
  - [Pollard Rho.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Pollard%20Rho.cpp)
- **Resources (2):**
  - ★ [Integer factorization | CP Algorithms](https://cp-algorithms.com/algebra/factorization.html)
  - ★ [Integer Factorization | Algorithmica](https://en.algorithmica.org/hpc/algorithms/factorization/)
- **Problems (5):**
  - `[E]` ★ [Factorize](https://judge.yosupo.jp/problem/factorize)
  - `[E]` ★ [Integer Factorization (20 digits)](https://www.spoj.com/problems/FACT1/)
  - `[E]` ★ [Divisions](https://codeforces.com/gym/100753/problem/F)
  - `[E]` ★ [Story of Totient Function](https://toph.co/p/story-of-totient-function)
  - `[H]` [Integer Factorization (29 digits)](https://www.spoj.com/problems/FACT2/)

#### 4.1.7 Prime Counting Function

- **ID:** `prime_counting_function` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/prime_counting_function
- **Templates (1):**
  - [Prime Counting Function.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Prime%20Counting%20Function.cpp)
- **Resources (4):**
  - ★ [Counting primes in n^(2/3) By Maksim1744](https://codeforces.com/blog/entry/91632)
  - [Editorial of Problem F](https://codeforces.com/blog/entry/44466)
  - [COMPUTING π(x): THE MEISSEL, LEHMER, LAGARIAS, MILLER, ODLYZKO METHOD | Paper by M. DELEGLISE AND J. RIVAT](https://cr.yp.to/bib/1996/deleglise.pdf)
  - [Dirichlet convolution. Part 2: Dirichlet series and prime counting By adamant](https://codeforces.com/blog/entry/117783)
- **Problems (7):**
  - `[E]` ★ [Counting Primes](https://judge.yosupo.jp/problem/counting_primes)
  - `[E]` ★ [Nth Prime](https://www.spoj.com/problems/NTHPRIME/)
  - `[M]` ★ [Four Divisors](https://codeforces.com/problemset/problem/665/F)
  - `[M]` ★ [Perfect Points](https://toph.co/p/perfect-points)
  - `[H]` [Divisors of factorial (extreme)](https://www.spoj.com/problems/DIVFACT4/)
  - `[H]` [Amazing Prime Sequence (hard)](https://www.spoj.com/problems/APS2/)
  - `[H]` [Breaking Math](https://www.spoj.com/problems/BBAD/)

#### 4.1.8 [Problem] Counting Numbers Having Exactly K Divisors

- **ID:** `k_divisors` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/k_divisors
- **Templates (1):**
  - [K Divisors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/K%20Divisors.cpp)
- **Resources (1):**
  - [Counting primes in O(n^(2/3)) By Maksim1744](https://codeforces.com/blog/entry/91632)
- **Problems (1):**
  - `[H]` ★ [K-Divisors](https://www.spoj.com/problems/KDIV/)

#### 4.1.9 [Problem] Smallest Number Having Exactly K Divisors

- **ID:** `smallest_number_having_exactly_k_divisors` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/smallest_number_having_exactly_k_divisors
- **Templates (1):**
  - [Smallest Number Having Exactly K Divisors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Smallest%20Number%20Having%20Exactly%20K%20Divisors.cpp)
- **Problems (1):**
  - `[M]` ★ [Politeness](https://lightoj.com/problem/politeness)

#### 4.1.10 Sum of The Number of Divisors in cbrt(n)

- **ID:** `sum_of_the_number_of_divisors_in_cbrt_n` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sum_of_the_number_of_divisors_in_cbrt_n
- **Templates (1):**
  - [Sum of The Number of Divisors in cbrt(n).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sum%20of%20The%20Number%20of%20Divisors%20in%20cbrt%28n%29.cpp)

#### 4.1.11 Wilson's Theorem

- **ID:** `wilsons_theorem` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/wilsons_theorem
- **Resources (2):**
  - [Wilson's theorem | Wiki](https://en.wikipedia.org/wiki/Wilson%27s_theorem)
  - [Fool algorithm for finding prime numbers based on long arithmetic By alexvim](https://codeforces.com/blog/entry/127832)
- **Problems (5):**
  - `[E]` ★ [Boring Factorials](https://www.spoj.com/problems/DCEPC11B/)
  - `[E]` [Boring Factorials (Reloaded)](https://www.spoj.com/problems/BORING/)
  - `[H]` ★ [Coprime Again](https://www.spoj.com/problems/IITKWPCM/)
  - `[H]` [Carousel of Combinations](https://codeforces.com/contest/1957/problem/E)
  - `[H]` [Boring Factorials (Extended)](https://www.spoj.com/problems/BORING2/)

#### 4.1.12 Implicit Prime Factorization

- **ID:** `implicit_prime_factorization` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/implicit_prime_factorization
- **Templates (1):**
  - [159590539](https://codeforces.com/contest/1656/submission/159590539)
- **Resources (1):**
  - ★ [Implicit Prime Factorisation By Everule](https://codeforces.com/blog/entry/108053)
- **Problems (3):**
  - `[M]` [Sleeping in Class](https://usaco.org/index.php?page=viewproblem2&cpid=1213)
  - `[H]` ★ [Equal LCM Subsets](https://codeforces.com/contest/1656/problem/H)
  - `[H]` ★ [Increasing LCMs](https://atcoder.jp/contests/arc122/tasks/arc122_e)

### 4.2 Multiplicative Functions

**Subcategory ID:** `multiplicative_functions` · **Topics:** 7

#### 4.2.1 Number of Divisors / Sum of Divisors / Sigma Function

- **ID:** `sigma_function` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/sigma_function
- **Resources (3):**
  - ★ [Number of divisors / sum of divisors | CP Algorithms](https://cp-algorithms.com/algebra/divisors.html)
  - [Sum Of Number Of Divisors Of Divisors Of A Number By kalimm](https://codeforces.com/blog/entry/21478)
  - ★ [Counting Divisors of a Number in O(n^(1/3)) \[tutorial\] By himanshujaju](https://codeforces.com/blog/entry/22317)
- **Problems (14):**
  - `[E]` ★ [Counting Divisors](https://cses.fi/problemset/task/1713)
  - `[E]` [Number of common divisors](https://www.spoj.com/problems/COMDIV/)
  - `[E]` ★ [Divisor Summation](https://www.spoj.com/problems/DIVSUM/)
  - `[E]` ★ [Divisor Summation (Hard)](https://www.spoj.com/problems/DIVSUM2/)
  - `[E]` ★ [Common Divisors](https://cses.fi/problemset/task/1081)
  - `[E]` ★ [Divisor Analysis](https://cses.fi/problemset/task/2182)
  - `[E]` ★ [Aliquot Sum](https://codeforces.com/gym/103373/problem/B)
  - `[E]` ★ [Sum of Divisors](https://cses.fi/problemset/task/1082)
  - `[E]` ★ [Divisions](https://codeforces.com/gym/100753/problem/F)
  - `[M]` ★ [All About Divisors](https://codeforces.com/group/H10hR2t6Sj/contest/338701/problem/J)
  - `[M]` ★ [Divisors of the Divisors of An Integer](https://codeforces.com/gym/102040/problem/C)
  - `[M]` ★ [Divisors](https://vjudge.net/problem/UVA-13279)
  - `[M]` [Kaosar Loves Divisors](https://codeforces.com/gym/105805/problem/B)
  - `[H]` ★ [Smallest Inverse Sum of Divisors](https://www.spoj.com/problems/INVDIV/)

#### 4.2.2 Euler's Totient Function / Phi Function

- **ID:** `eulers_totient_function` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/eulers_totient_function
- **Templates (1):**
  - [Phi Function.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Phi%20Function.cpp)
- **Resources (2):**
  - ★ [Euler's totient function | CP Algorithms](https://cp-algorithms.com/algebra/phi-function.html)
  - [\[Tutorial\] Euler's phi function, its properties, and how to compute it By kamilszymczak1](https://codeforces.com/blog/entry/106851)
- **Problems (34):**
  - `[E]` ★ [Euler Totient Function](https://www.spoj.com/problems/ETF/)
  - `[E]` ★ [Mathematically Hard](https://lightoj.com/problem/mathematically-hard)
  - `[E]` [Best Friend](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3856)
  - `[E]` [Totient in permutation (easy)](https://www.spoj.com/problems/TIP1/)
  - `[E]` [Another New Function](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1931)
  - `[E]` [Irreducable Basic Fractions](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1120)
  - `[E]` [Farey Sequence Length](https://open.kattis.com/problems/farey)
  - `[E]` [Relatives](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1240)
  - `[E]` [Totient Extreme](https://www.spoj.com/problems/DCEPCA03/)
  - `[E]` [Playing with GCD](https://www.spoj.com/problems/NAJPWG/)
  - `[E]` ★ [Coprime Integers](https://open.kattis.com/problems/coprimeintegers)
  - `[E]` ★ [Counting Coprime Pairs](https://cses.fi/problemset/task/2417)
  - `[E]` ★ [GCD Extreme](https://www.spoj.com/problems/GCDEX/)
  - `[E]` [Admission to Exam](https://acm.timus.ru/problem.aspx?space=1&num=1673)
  - `[M]` ★ [Product 1 Modulo N](https://codeforces.com/problemset/problem/1514/C)
  - `[M]` ★ [Farey Sequence](http://poj.org/problem?id=2478)
  - `[M]` [Simple Sum](https://www.codechef.com/NOV15/problems/SMPLSUM)
  - `[M]` ★ [LCM Sum](https://www.spoj.com/problems/LCMSUM/)
  - `[M]` ★ [LCM Extreme](https://lightoj.com/problem/lcm-extreme)
  - `[M]` ★ [Farey Sequence](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4878)
  - `[M]` ★ [Golu and Sweetness](https://www.codechef.com/problems/COZIE)
  - `[M]` ★ [G Force](https://www.spoj.com/problems/DCEPC12G/)
  - `[M]` ★ [Super Pow](https://leetcode.com/problems/super-pow/description/)
  - `[M]` [The Holmes Children](https://codeforces.com/problemset/problem/776/E)
  - `[M]` ★ [Madoka and The Best University](https://codeforces.com/contest/1717/problem/E)
  - `[M]` [Relatively Prime Powers](https://codeforces.com/contest/1036/problem/F)
  - `[M]` ★ [Eulers Peculiar Dream](https://toph.co/p/eulers-peculiar-dream)
  - `[M]` [D. Same GCDs](https://codeforces.com/contest/1295/problem/D)
  - `[M]` [Graph Cost](https://codeforces.com/contest/1731/problem/E)
  - `[H]` [Cowslip Collections](https://codeforces.com/contest/645/problem/F)
  - `[H]` [Smallest Inverse Euler Totient Function](https://www.spoj.com/problems/INVPHI/)
  - `[H]` ★ [Li Hua and Array](https://codeforces.com/problemset/problem/1797/e)
  - `[H]` ★ [Please, another Queries on Array?](https://codeforces.com/problemset/problem/1114/F)
  - `[H]` ★ [REQ](https://codeforces.com/contest/594/problem/D)

#### 4.2.3 Power Tower /  Generalized Euler theorem

- **ID:** `power_tower` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/power_tower
- **Templates (1):**
  - [Power Tower.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Power%20Tower.cpp)
- **Resources (2):**
  - ★ [Euler's totient function | CP Algorithms](https://cp-algorithms.com/algebra/phi-function.html#generalization)
  - [Finding an upperbound for the minimum number of iterations on the Euler Totient Function By wakanda-forever](https://codeforces.com/blog/entry/137590)
- **Problems (6):**
  - `[E]` ★ [Simple Calculations](https://codeforces.com/gym/100975/problem/F)
  - `[E]` ★ [Exponentiation II](https://cses.fi/problemset/task/1712)
  - `[E]` [A^B^C](https://atcoder.jp/contests/arc113/tasks/arc113_b)
  - `[M]` ★ [Exponial](https://open.kattis.com/problems/exponial)
  - `[M]` ★ [Power Tower](https://codeforces.com/problemset/problem/906/D)
  - `[M]` ★ [Venkatesh is bored](https://www.codechef.com/problems/CKOJ20E)

#### 4.2.4 Mobius Function and Mobius Inversion

- **ID:** `mobius_function` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/mobius_function
- **Templates (1):**
  - [Mobius Function.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Mobius%20Function.cpp)
- **Resources (5):**
  - ★ [Möbius Function | Brilliant](https://brilliant.org/wiki/mobius-function/)
  - ★ [\[Tutorial\] Math note — Möbius inversion By Nisiyama_Suzune](https://codeforces.com/blog/entry/53925)
  - [A Dance with Mobius Function | adurysk](https://discuss.codechef.com/t/a-dance-with-mobius-function/11315)
  - ★ [Number Theoretic Functions | Nafis](https://nafis277.github.io/Notes/NTFunctions.pdf)
  - [A bit more of general ideas By adamant](https://codeforces.com/blog/entry/104466)
- **Problems (21):**
  - `[E]` ★ [GCD Extreme](https://www.spoj.com/problems/GCDEX/)
  - `[E]` ★ [Counting Coprime Pairs](https://cses.fi/problemset/task/2417)
  - `[E]` ★ [Coprime Integers](https://open.kattis.com/problems/coprimeintegers)
  - `[E]` ★ [Coprime Triples](https://www.codechef.com/LTIME13/problems/COPRIME3)
  - `[M]` ★ [Mike and Foam](https://codeforces.com/contest/547/problem/C)
  - `[M]` ★ [Coprime Subsequences](https://codeforces.com/contest/803/problem/F)
  - `[M]` ★ [Winter is here](https://codeforces.com/contest/839/problem/D)
  - `[M]` ★ [LCMs](https://atcoder.jp/contests/agc038/tasks/agc038_c)
  - `[M]` ★ [Number of Prime Strings](https://www.spoj.com/problems/PSTR/)
  - `[M]` [Devu and Birthday Celebration](https://codeforces.com/contest/439/problem/E)
  - `[M]` ★ [Coprime Arrays](https://codeforces.com/contest/915/problem/G)
  - `[M]` [Simple Sum](https://www.codechef.com/NOV15/problems/SMPLSUM)
  - `[M]` [GCD](http://acm.hdu.edu.cn/showproblem.php?pid=1695)
  - `[M]` [GCD Product](https://www.hackerrank.com/contests/w3/challenges/gcd-product)
  - `[M]` ★ [Sum Over Subsets](https://codeforces.com/contest/1436/problem/F)
  - `[M]` ★ [Sum of gcd of Tuples (Hard)](https://atcoder.jp/contests/abc162/tasks/abc162_e)
  - `[M]` ★ [List Of Integers](https://codeforces.com/contest/920/problem/G)
  - `[M]` ★ [Square-free integers](https://www.spoj.com/problems/SQFREE/)
  - `[M]` ★ [x = a^b](https://atcoder.jp/contests/abc361/tasks/abc361_f)
  - `[M]` ★ [Joker's GCD Test](https://toph.co/p/joker-s-gcd-test)
  - `[H]` ★ [Yet Another Convolution](https://codeforces.com/gym/102354/problem/B)

#### 4.2.5 Dirichlet convolution

- **ID:** `dirichlet_convolution` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dirichlet_convolution
- **Templates (1):**
  - [Dirichlet Convolution.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Dirichlet%20Convolution.cpp)
- **Resources (6):**
  - ★ [\[Tutorial\] Math note — Dirichlet convolution By Nisiyama_Suzune](https://codeforces.com/blog/entry/54150)
  - ★ [杜教筛 | OI Wiki](https://oi-wiki.org/math/number-theory/du/)
  - ★ [Dirichlet convolution. Part 1: Fast prefix sum computations By adamant](https://codeforces.com/blog/entry/117635)
  - [Summing Multiplicative Functions (Pt. 1) | griff's math blog!](https://gbroxey.github.io/blog/2023/04/30/mult-sum-1.html)
  - [Dirichlet convolution. Part 2: Dirichlet series and prime counting By adamant](https://codeforces.com/blog/entry/117783)
  - [Prefix Sums of Multiplicative Functions | USACO Guide](https://usaco.guide/adv/multiplicative?lang=cpp)
- **Problems (6):**
  - `[E]` ★ [Sum of Totient Function](https://judge.yosupo.jp/problem/sum_of_totient_function)
  - `[E]` [function](http://acm.hdu.edu.cn/showproblem.php?pid=5608)
  - `[E]` [杜教筛](https://www.luogu.com.cn/problem/P4213)
  - `[H]` [Counting Divisors (square)](https://www.spoj.com/problems/DIVCNT2/)
  - `[H]` [简单的数学题](https://www.luogu.com.cn/problem/P3768)
  - `[H]` ★ [Dirichlet 𝑘 -th root](https://codeforces.com/gym/102471/problem/C)

#### 4.2.6 Min_25 Sieve

- **ID:** `min_25_sieve` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_25_sieve
- **Templates (1):**
  - [Min_25 Sieve.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Min_25%20Sieve.cpp)
- **Resources (4):**
  - ★ [On the Min25 sieve and extensions / SPOJ ASSIEVE By box](https://codeforces.com/blog/entry/92703)
  - ★ [Min_25 sieve | OI Wiki](https://oi-wiki.org/math/number-theory/min-25/)
  - ★ [新版min25筛（O(n^(2/3))）详解 | dengtesla](https://zhuanlan.zhihu.com/p/60378354)
  - [The prefix-sum of multiplicative function: the black algorithm | baihacker](https://baihacker.github.io/main/2020/The_prefix-sum_of_multiplicative_function_the_black_algorithm.html)
- **Problems (7):**
  - `[E]` ★ [Sum of Totient Function](https://judge.yosupo.jp/problem/sum_of_totient_function)
  - `[E]` ★ [Sum of Multiplicative Function](https://judge.yosupo.jp/problem/sum_of_multiplicative_function)
  - `[E]` [杜教筛](https://www.luogu.com.cn/problem/P4213)
  - `[E]` ★ [简单的函数](https://loj.ac/problem/6053)
  - `[E]` ★ [Count Leaves](https://codeforces.com/contest/2020/problem/F)
  - `[M]` ★ [Min_25 筛](https://www.luogu.com.cn/problem/P5325)
  - `[M]` ★ [A Simple Sieve](https://www.spoj.com/problems/ASSIEVE/)

#### 4.2.7 Powerful Number Sieve / PN Sieve

- **ID:** `powerful_number_sieve` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/powerful_number_sieve
- **Templates (1):**
  - [Powerful Number Sieve.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Powerful%20Number%20Sieve.cpp)
- **Resources (1):**
  - ★ [Powerful Number Sieve | OI Wiki](https://oi-wiki.org/math/number-theory/powerful-number/)
- **Problems (3):**
  - `[E]` ★ [简单的函数](https://loj.ac/problem/6053)
  - `[M]` ★ [Jo loves counting](https://vjudge.net/problem/HDU-7186)
  - `[M]` ★ [Min_25 筛](https://www.luogu.com.cn/problem/P5325)

### 4.3 Euclidean Algorithm

**Subcategory ID:** `euclidean_algorithm` · **Topics:** 4

#### 4.3.1 Euclidean Algorithm

- **ID:** `euclidean_algorithm` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/euclidean_algorithm
- **Templates (1):**
  - [euclid-algorithm.html#implementation](https://cp-algorithms.com/algebra/euclid-algorithm.html#implementation)
- **Resources (2):**
  - ★ [Euclidean algorithm for computing the greatest common divisor | CP Algorithms](https://cp-algorithms.com/algebra/euclid-algorithm.html)
  - [Euclid's Algorithm By ebanner](https://codeforces.com/blog/entry/48481)
- **Problems (2):**
  - `[E]` ★ [Greatest Common Divisor](https://csacademy.com/contest/archive/task/gcd/)
  - `[M]` [Blackboard Fibonacci](https://codeforces.com/problemset/problem/217/B)

#### 4.3.2 Extended Euclid

- **ID:** `extended_euclid` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/extended_euclid
- **Templates (1):**
  - [Extended Euclid.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Extended%20Euclid.cpp)
- **Resources (5):**
  - ★ [Extended Euclidean Algorithm | CP Algorithms](https://cp-algorithms.com/algebra/extended-euclid-algorithm.html)
  - ★ [Extended Euclidean Algorithm | ax + by + cz = gcd(a, b, c)](https://codeforces.com/blog/entry/79167)
  - ★ [Extended Euclidean Algorithm | USACO Guide](https://usaco.guide/adv/extend-euclid?lang=cpp)
  - [Lamé's Theorem | Cut The Knot](https://www.cut-the-knot.org/blue/LamesTheorem.shtml)
  - [Modular Multiplicative Inverse | CP Algorithms](https://cp-algorithms.com/algebra/module-inverse.html)
- **Problems (8):**
  - `[E]` ★ [Euclid Problem](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1045)
  - `[E]` ★ [Once Upon A Time](https://codeforces.com/gym/100963/problem/J)
  - `[E]` [Gift Dilemma](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4628)
  - `[E]` [Marbles](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1031)
  - `[E]` [Play with Floor and Ceil](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1614)
  - `[E]` [Mod Inverse](https://vjudge.net/problem/DMOJ-ccc01j2)
  - `[M]` ★ [ConstructOR](https://codeforces.com/problemset/problem/1748/D)
  - `[M]` ★ [Euclids algorithm revisited](https://www.spoj.com/problems/MAIN74/)

#### 4.3.3 Bezout's Identity

- **ID:** `bezouts_identity` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/bezouts_identity
- **Resources (4):**
  - ★ [Bezout's Identity | Brilliant](https://brilliant.org/wiki/bezouts-identity/)
  - [Bézout's identity | Wiki](https://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity)
  - [Bazout's Identity, Codeforces Round #499 (Div. 2) — E By CazadorDivino](https://codeforces.com/blog/entry/60892)
  - [Bézout's identity || Problem D || Codeforces Round 698 || Nezzar and Board || Div 2 | Anmol Gera](https://www.youtube.com/watch?v=yYxQ9_EL69Q)
- **Problems (5):**
  - `[E]` ★ [Check If It Is a Good Array](https://leetcode.com/problems/check-if-it-is-a-good-array/description/)
  - `[E]` [Dora and C++](https://codeforces.com/contest/2007/problem/C)
  - `[M]` ★ [Border](https://codeforces.com/contest/1011/problem/E)
  - `[M]` ★ [Nezzar and Board](https://codeforces.com/contest/1477/problem/A)
  - `[M]` ★ [Beauty of the mountains](https://codeforces.com/contest/1982/problem/D)

#### 4.3.4 Chicken McNugget Theorem

- **ID:** `chicken_mcnugget_theorem` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chicken_mcnugget_theorem
- **Resources (2):**
  - ★ [Chicken McNugget Theorem explained\[Shortly\] By offline-bot](https://codeforces.com/blog/entry/118246)
  - ★ [Chicken McNugget Theorem | AoPS](https://artofproblemsolving.com/wiki/index.php/Chicken_McNugget_Theorem)
- **Problems (2):**
  - `[E]` ★ [I Hate 1111](https://codeforces.com/contest/1526/problem/B)
  - `[E]` [Good ol' Numbers Coloring](https://codeforces.com/contest/1245/problem/A)

### 4.4 Modular Arithmetic

**Subcategory ID:** `modular_arithmetic` · **Topics:** 10

#### 4.4.1 Linear Congruence Equation

- **ID:** `linear_congruence_equation` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_congruence_equation
- **Templates (1):**
  - [Linear Congruence Equation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Congruence%20Equation.cpp)
- **Resources (1):**
  - ★ [Linear Congruence Equation | CP Algorithms](https://cp-algorithms.com/algebra/linear_congruence_equation.html)

#### 4.4.2 Chinese Remainder Theorem (CRT)

- **ID:** `crt` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/crt
- **Templates (2):**
  - [CRT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/CRT.cpp)
  - [Intersection of Arithmetic Progressions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Intersection%20of%20Arithmetic%20Progressions.cpp)
- **Resources (6):**
  - ★ [Chinese Remainder Theorem Part 1 – Coprime Moduli | forthright48](https://forthright48.com/chinese-remainder-theorem-part-1-coprime-moduli/)
  - ★ [Chinese Remainder Theorem Part 2 – Non Coprime Moduli | forthright48](https://forthright48.com/chinese-remainder-theorem-part-2-non-coprime-moduli/)
  - ★ [Chinese Remainder Theorem | CP Algorithms](https://cp-algorithms.com/algebra/chinese-remainder-theorem.html)
  - [Garner's algorithm | CP Algorithms](https://cp-algorithms.com/algebra/garners-algorithm.html)
  - [\[Tutorial\] Chinese Remainder Theorem By Valiors](https://codeforces.com/blog/entry/61290)
  - ★ [Intersection of two arithmetic progressions](https://mathoverflow.net/questions/128382/intersection-of-two-arithmetic-progressions)
- **Problems (14):**
  - `[E]` ★ [Chinese Remainder](https://open.kattis.com/problems/chineseremainder)
  - `[E]` ★ [Chinese Remainder Theorem (non-relatively prime moduli)](https://open.kattis.com/problems/generalchineseremainder)
  - `[E]` ★ [Monkey Tradition](https://lightoj.com/problem/monkey-tradition)
  - `[E]` [Remainders Game](https://codeforces.com/problemset/problem/687/B)
  - `[E]` ★ [nCr](https://www.hackerrank.com/challenges/ncr/problem)
  - `[M]` ★ [Cheese and Random Toppings](https://www.hackerrank.com/contests/infinitum10/challenges/cheese-and-random-toppings/problem)
  - `[M]` ★ [Number of Sequences](https://www.hackerrank.com/contests/w22/challenges/number-of-sequences/problem)
  - `[M]` ★ [Two chandeliers](https://codeforces.com/problemset/problem/1500/B)
  - `[M]` ★ [The Ultimate Riddle](https://www.spoj.com/problems/DCEPC13D/)
  - `[M]` ★ [Long Sandwich](https://www.codechef.com/problems/SANDWICH)
  - `[M]` [Gears in Action](https://vjudge.net/problem/Kattis-gears)
  - `[M]` [Boring Card Game](https://codeforces.com/gym/101481/problem/B)
  - `[H]` ★ [GCD Table](https://codeforces.com/problemset/problem/338/D)
  - `[H]` [Arkanoid](https://szkopul.edu.pl/problemset/problem/O730xgZEVynTWBmscBinhMbD/site/?key=statement)

#### 4.4.3 Primitive Root

- **ID:** `primitive_root` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/primitive_root
- **Templates (1):**
  - [Primitive Root.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Primitive%20Root.cpp)
- **Resources (2):**
  - ★ [Primitive Root | CP Algorithms](https://cp-algorithms.com/algebra/primitive-root.html)
  - ★ [Primitive root modulo n | I, ME AND MYSELF !!!](https://zobayer.blogspot.com/2010/02/primitive-root.html)
- **Problems (6):**
  - `[E]` [Cows and Primitive Roots](https://codeforces.com/problemset/problem/284/A)
  - `[M]` [PRIMITIVEROOTS](https://www.spoj.com/problems/PROBLEM4/)
  - `[M]` ★ [Primitive Root](https://www.spoj.com/problems/PROOT/)
  - `[M]` ★ [Product of Minimums](https://www.codechef.com/problems/MINPROD)
  - `[H]` ★ [Product Modulo](https://atcoder.jp/contests/agc047/tasks/agc047_c)
  - `[H]` ★ [Cool Subsets](https://www.codechef.com/JAN21A/problems/COOLSBST)

#### 4.4.4 Multiplicative Order and Carmichael's Lambda Function

- **ID:** `multiplicative_order` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/multiplicative_order
- **Templates (1):**
  - [Multiplicative Order.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Multiplicative%20Order.cpp)
- **Resources (3):**
  - [Multiplicative order | Wiki](https://en.wikipedia.org/wiki/Multiplicative_order)
  - [Carmichael function | Wiki](https://en.wikipedia.org/wiki/Carmichael_function)
  - [JAG summer 2015 Day4 (= OpenCup GP of Japan) D Identity Function By Mi_Sawa](https://codeforces.com/blog/Mi_Sawa?locale=en)
- **Problems (5):**
  - `[E]` ★ [I Am Good](https://toph.co/p/i-am-good)
  - `[M]` [Product transformation](https://codeforces.com/problemset/problem/852/F)
  - `[M]` [Divide and Conquer](https://maps20.kattis.com/contests/maps20/problems/divideandconquer)
  - `[H]` ★ [Identity Function](https://atcoder.jp/contests/jag2015summer-day4/tasks/icpc2015summer_day4_d)
  - `[H]` ★ [Discrete Logarithm Problems](https://atcoder.jp/contests/abc335/tasks/abc335_g)

#### 4.4.5 Discrete Log / Baby Step Giant Step

- **ID:** `discrete_log` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/discrete_log
- **Templates (1):**
  - [Discrete Log.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Discrete%20Log.cpp)
- **Resources (1):**
  - ★ [Discrete Logarithm | CP Algorithms](https://cp-algorithms.com/algebra/discrete-log.html)
- **Problems (8):**
  - `[E]` ★ [Hard Equation](https://codeforces.com/gym/101853/problem/G)
  - `[E]` [Power Modulo Inverted](https://www.spoj.com/problems/MOD/)
  - `[E]` [Discrete Logarithm is a Joke](https://codeforces.com/gym/103260/problem/M)
  - `[M]` ★ [Inverse of a Function](https://www.codechef.com/problems/INVXOR/)
  - `[M]` [SplittingFoxes3](https://community.topcoder.com/stat?c=problem_statement&pm=14386&rd=16801)
  - `[H]` ★ [Chef and Modular Sequence](https://www.codechef.com/problems/CHEFMOD)
  - `[H]` ★ [Discrete Logarithm Problems](https://atcoder.jp/contests/abc335/tasks/abc335_g)
  - `[H]` [discrete logarithm problem](https://vjudge.net/problem/HDU-6632)

#### 4.4.6 Discrete Root

- **ID:** `discrete_root` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/discrete_root
- **Templates (1):**
  - [Discrete Root.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Discrete%20Root.cpp)
- **Resources (1):**
  - ★ [Discrete Root | CP Algorithms](https://cp-algorithms.com/algebra/discrete-root.html)
- **Problems (3):**
  - `[E]` ★ [Discrete Roots](https://codeforces.com/problemsets/acmsguru/problem/99999/261)
  - `[E]` ★ [Discrete Roots](https://vjudge.net/problem/SPOJ-DISCRT)
  - `[M]` ★ [Lunar New Year and a Recursive Sequence](https://codeforces.com/contest/1106/problem/F)

#### 4.4.7 Discrete Root in O(P^(1/4))

- **ID:** `discrete_root_in_o_p_1_4` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/discrete_root_in_o_p_1_4
- **Templates (1):**
  - [Discrete Root Faster.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Discrete%20Root%20Faster.cpp)
- **Resources (2):**
  - ★ [Explanation | yukicoder](https://yukicoder.me/problems/no/981/editorial)
  - [Cipolla のアルゴリズム | 37zigen](https://37zigen.com/cipolla-algorithm/)
- **Problems (1):**
  - `[E]` ★ [Kth Root (Mod)](https://judge.yosupo.jp/problem/kth_root_mod)

#### 4.4.8 Discrete Square Root, Tonelli Shanks Algorithm, Cipolla's Algorithm

- **ID:** `tonelli_shanks_algorithm` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tonelli_shanks_algorithm
- **Templates (2):**
  - [Tonelli Shanks Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Tonelli%20Shanks%20Algorithm.cpp)
  - [https://37zigen.com/cipolla-algorithm/](https://37zigen.com/cipolla-algorithm/)
- **Resources (4):**
  - ★ [\[Prime Mod\] Tonelli–Shanks algorithm | Wiki](https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm)
  - [\[Prime Mod\] Cipolla's algorithm | Wiki](https://en.wikipedia.org/wiki/Cipolla%27s_algorithm)
  - [\[Prime Mod\] Cipolla のアルゴリズム | 37zigen](https://37zigen.com/cipolla-algorithm/)
  - ★ [\[General Solution\] Discrete square root modulo By wilcot](https://codeforces.com/blog/entry/124745)
- **Problems (3):**
  - `[E]` ★ [Sqrt Mod](https://judge.yosupo.jp/problem/sqrt_mod)
  - `[E]` [二次剩余](https://www.luogu.com.cn/problem/P5491)
  - `[M]` ★ [Square Root of LCA Convolution](https://www.codechef.com/problems/LCASQRT)

#### 4.4.9 Number of Distinct Kth Powers Modulo N

- **ID:** `number_of_distinct_kth_powers_modulo_n` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_distinct_kth_powers_modulo_n
- **Templates (1):**
  - [Number of Distinct Kth Powers Modulo n.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20Distinct%20Kth%20Powers%20Modulo%20n.cpp)
- **Resources (2):**
  - ★ [Discussion in Math Stack Exchange](https://math.stackexchange.com/questions/3796985/is-there-a-known-formula-for-the-number-of-k-textth-power-residues-modulo)
  - [Counting general power residues | Samer Seraj](https://nntdm.net/papers/nntdm-28/NNTDM-28-4-730-743.pdf)

#### 4.4.10 Number of Solutions to X^2 = 1 mod M

- **ID:** `number_of_solutions_to_x_2_1_mod_m` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_solutions_to_x_2_1_mod_m
- **Templates (1):**
  - [Number of Solutions to x^2 = 1 mod m.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20Solutions%20to%20x%5E2%20=%201%20mod%20m.cpp)
- **Resources (2):**
  - [Discussion in Math Stack Exchange 1](https://math.stackexchange.com/questions/345668/solutions-of-the-congruence-x2-equiv-1-pmodm)
  - [Discussion in Math Stack Exchange 2](https://math.stackexchange.com/questions/104961/number-of-solutions-of-x2-1-in-mathbbz-n-mathbbz)
- **Problems (1):**
  - `[E]` ★ [Congruence Problem](https://toph.co/p/congruence-problem)

### 4.5 Linear Diophantine Equations

**Subcategory ID:** `linear_diophantine_equations` · **Topics:** 5

#### 4.5.1 Linear Diophantine Equation with Two Variables

- **ID:** `linear_diophantine_equation_with_two_variables` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_diophantine_equation_with_two_variables
- **Templates (1):**
  - [Linear Diophantine Equation with Two Variables.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Diophantine%20Equation%20with%20Two%20Variables.cpp)
- **Resources (3):**
  - ★ [Linear Diophantine Equation | CP Algorithms](https://cp-algorithms.com/algebra/linear-diophantine-equation.html)
  - ★ [Solving Linear Diophantine Equations and Linear Congruential Equations](https://www.diva-portal.org/smash/get/diva2:530204/FULLTEXT01.pdf)
  - [Avoid overflow in linear diophantine equation By Jakube](https://codeforces.com/blog/entry/59842)
- **Problems (11):**
  - `[E]` ★ [Solutions to an Equation](https://lightoj.com/problem/solutions-to-an-equation)
  - `[E]` [Crucial Equation](https://www.spoj.com/problems/CEQU/)
  - `[E]` [The equation](https://codeforces.com/problemsets/acmsguru/problem/99999/106)
  - `[E]` ★ [Ebony and Ivory](https://vjudge.net/problem/CodeForces-633A)
  - `[E]` [Get AC in one go](https://www.codechef.com/problems/COPR16G)
  - `[E]` [The equation](https://vjudge.net/problem/SGU-106)
  - `[M]` ★ [S = 1](https://atcoder.jp/contests/abc340/tasks/abc340_f)
  - `[M]` [Fraction and Sequence](https://vjudge.net/problem/UVA-13041)
  - `[M]` ★ [Infinite Fence](https://codeforces.com/contest/1260/problem/C)
  - `[M]` [Skyscraper Floors](https://vjudge.net/problem/UVA-718)
  - `[VH]` [Oppa Funcan Style Remastered](https://codeforces.com/contest/986/problem/F)

#### 4.5.2 Linear Diophantine Equation with N Variables

- **ID:** `linear_diophantine_equation_with_n_variables` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_diophantine_equation_with_n_variables
- **Templates (1):**
  - [Linear Diophantine Equation with N Variables.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Diophantine%20Equation%20with%20N%20Variables.cpp)
- **Problems (1):**
  - `[E]` ★ [Illegal Towers](https://codeforces.com/gym/102020/problem/I)

#### 4.5.3 Trivariable Linear Diophantine Equation with Nonnegative Solutions

- **ID:** `trivariable_linear_diophantine_equation_with_nonnegative_solutions` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/trivariable_linear_diophantine_equation_with_nonnegative_solutions
- **Templates (1):**
  - [Linear Diophantine Equation Three Variables with Nonnegative Solutions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Diophantine%20Equation%20Three%20Variables%20with%20Nonnegative%20Solutions.cpp)
- **Resources (1):**
  - [The Number of Solutions to ax + by + cz = n and its Relation to Quadratic Residues](https://cs.uwaterloo.ca/journals/JIS/VOL23/Binner/binner4.pdf)
- **Problems (1):**
  - `[M]` [Fraction and Sequence](https://vjudge.net/problem/UVA-13041)

#### 4.5.4 Multivariable Linear Diophantine Equation with Nonnegative Solutions

- **ID:** `multivariable_linear_diophantine_equation_with_nonnegative_solutions` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/multivariable_linear_diophantine_equation_with_nonnegative_solutions
- **Templates (1):**
  - [Linear Diophantine Equation with Nonnegative Solutions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Diophantine%20Equation%20with%20Nonnegative%20Solutions.cpp)
- **Resources (2):**
  - [Congruence Shortest Path Problem By Shahjalal Shohag — DSAAcademy](https://codeforces.com/blog/entry/71617)
  - [Comment by sys.](https://codeforces.com/blog/entry/71230?#comment-556761)
- **Problems (2):**
  - `[M]` ★ [Building Blocks](https://drive.google.com/file/d/1vNCHV7gCrAz1ZYmXKmmvcsmMugGRQrZa/view)
  - `[M]` ★ [Strange Keyboard](https://codedrills.io/contests/icpc-asia-west-continent-final-contest-2022/problems/strange-keyboard)

#### 4.5.5 Linear Diophantine With N Unknowns and Two Equations

- **ID:** `linear_diophantine_with_n_unknowns_and_two_equations` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_diophantine_with_n_unknowns_and_two_equations
- **Templates (1):**
  - [Linear Diophantine With N Unknowns and Two Equations.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Linear%20Diophantine%20With%20N%20Unknowns%20and%20Two%20Equations.cpp)
- **Problems (1):**
  - `[M]` ★ [Interstellar Hunter](https://codeforces.com/gym/102769/problem/I)

### 4.6 Solutions to Equations

**Subcategory ID:** `solutions_to_equations` · **Topics:** 6

#### 4.6.1 Number of Solutions to a Basic Linear Algebraic Equation

- **ID:** `number_of_solutions_to_a_basic_linear_algebraic_equation` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_solutions_to_a_basic_linear_algebraic_equation
- **Templates (1):**
  - [Number of Solutions to a Basic Linear Algebraic Equation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20Solutions%20to%20a%20Basic%20Linear%20Algebraic%20Equation.cpp)
- **Resources (1):**
  - [Number of Solutions to a Linear Algebraic Equation By J-C](https://codeforces.com/blog/entry/54111)
- **Problems (6):**
  - `[E]` ★ [Problem Makes Problem](https://lightoj.com/problem/problem-makes-problem)
  - `[E]` [Coins](https://atcoder.jp/contests/abc087/tasks/abc087_b)
  - `[M]` ★ [Cricket Ranking](https://lightoj.com/problem/cricket-ranking)
  - `[M]` [Biswa the Digital Gutibaj](https://toph.co/p/biswa-the-digital-gutibaj)
  - `[M]` [The Top Scorer](https://codeforces.com/contest/1096/problem/E)
  - `[M]` ★ [Devu and Flowers](https://codeforces.com/problemset/problem/451/E)

#### 4.6.2 Number of Solutions to a Basic Linear Algebraic Equation using Meet in the Middle

- **ID:** `number_of_solutions_to_a_basic_linear_algebraic_equation_with_variable_upper_bound_constraints` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_solutions_to_a_basic_linear_algebraic_equation_with_variable_upper_bound_constraints
- **Templates (1):**
  - [Number of Solutions to a Basic Linear Algebraic Equation with Variable Upper Bound Constraints.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20Solutions%20to%20a%20Basic%20Linear%20Algebraic%20Equation%20with%20Variable%20Upper%20Bound%20Constraints.cpp)
- **Resources (1):**
  - [Editorial of 102114F - Fireflies](https://codeforces.com/blog/entry/67734)
- **Problems (1):**
  - `[M]` ★ [Fireflies](https://codeforces.com/gym/102114/problem/F)

#### 4.6.3 Number of Nonnegative Integer Solutions to ax + by ≤ c

- **ID:** `number_of_nonnegative_integer_solutions_to_ax_by_c` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_nonnegative_integer_solutions_to_ax_by_c
- **Templates (1):**
  - [Number of Nonnegative Integer Solutions to ax+by less than or equal to c.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20Nonnegative%20Integer%20Solutions%20to%20ax+by%20less%20than%20or%20equal%20to%20c.cpp)

#### 4.6.4 Number of Integer Solutions to 1/x + 1/y = 1/k

- **ID:** `number_of_integer_solutions_to_1_x_1_y_1_k` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_integer_solutions_to_1_x_1_y_1_k
- **Resources (1):**
  - [Number of positive integral solutions of equation 1/x+1/y=1/n! By Vivek.p](https://codeforces.com/blog/entry/76836?f0a28=1&locale=en)
- **Problems (1):**
  - `[E]` ★ [Equations](https://www.hackerrank.com/challenges/equations/problem)

#### 4.6.5 Two / Three / Four Squares Theorem

- **ID:** `two_squares_theorem` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/two_squares_theorem
- **Resources (8):**
  - ★ [Integer solutions to x² + y² = z By adamant](https://codeforces.com/blog/entry/116519)
  - [Jacobi's Two Square Theorem By NeverSayNever](https://codeforces.com/blog/entry/13851)
  - [Sum of two squares theorem | Wiki](https://en.wikipedia.org/wiki/Sum_of_two_squares_theorem)
  - [Fermat's theorem on sums of two squares | Wiki](https://en.wikipedia.org/wiki/Fermat%27s_theorem_on_sums_of_two_squares)
  - [Legendre's three-square theorem | Wiki](https://en.wikipedia.org/wiki/Legendre%27s_three-square_theorem)
  - [Lagrange's four-square theorem | Wiki](https://en.wikipedia.org/wiki/Lagrange%27s_four-square_theorem)
  - [Euler's four-square identity | Wiki](https://en.wikipedia.org/wiki/Euler%27s_four-square_identity)
  - [Brahmagupta–Fibonacci identity | Wiki](https://en.wikipedia.org/wiki/Brahmagupta%E2%80%93Fibonacci_identity)
- **Problems (4):**
  - `[E]` [Pythagorean Pair](https://www.codechef.com/START62A/problems/PYTHAGORAS)
  - `[M]` ★ [Square Country. Version 2](https://acm.timus.ru/problem.aspx?space=1&num=1593)
  - `[H]` ★ [제곱수의 합 (More Huge)](https://www.acmicpc.net/problem/17633)
  - `[H]` [제곱수의 합 2 (More Huge)](https://www.acmicpc.net/problem/17646)

#### 4.6.6 Pell's Equation

- **ID:** `pells_equation` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pells_equation
- **Templates (1):**
  - [Pells Equation.py](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Pells%20Equation.py)
- **Resources (3):**
  - ★ [Pell's Equation | Brilliant](https://brilliant.org/wiki/quadratic-diophantine-equations-pells-equation/)
  - ★ [Pell's equation By LieutenantLolicon](https://codeforces.com/blog/entry/68915)
  - [Pythagorean triples and Pell's equations By adamant](https://codeforces.com/blog/entry/116313)
- **Problems (2):**
  - `[M]` ★ [Numeric Center](https://vjudge.net/problem/UVA-12909)
  - `[M]` [Semi-triangular and also Square](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=show_problem&problem=1182)

### 4.7 Floor Sum

**Subcategory ID:** `floor_sum` · **Topics:** 3

#### 4.7.1 Sum of Floors

- **ID:** `sum_of_floors` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/sum_of_floors
- **Templates (1):**
  - [Sum of Floors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sum%20of%20Floors.cpp)
- **Resources (3):**
  - ★ [Editorial of CSES - Sum of Divisors | USACO guide](https://usaco.guide/problems/cses-1082-sum-of-divisors/solution)
  - [Discussion - Sum of floor values](https://codeforces.com/blog/entry/65363?mobile=false)
  - ★ [\[Tutorial\] Investigating the Harmonic Numbers By Proofy](https://codeforces.com/blog/entry/118001)
- **Problems (7):**
  - `[E]` ★ [Enumerate Quotients](https://judge.yosupo.jp/problem/enumerate_quotients)
  - `[E]` ★ [Sum of Divisors](https://cses.fi/problemset/task/1082)
  - `[M]` ★ [Sum of Remainders](https://codeforces.com/problemset/problem/616/E)
  - `[M]` ★ [Max/Min](https://atcoder.jp/contests/abc356/tasks/abc356_e)
  - `[M]` ★ [Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/description/)
  - `[M]` ★ [Colded LCM](https://toph.co/p/colded-lcm)
  - `[M]` [Yet Another Sum Problem](https://www.hackerearth.com/problem/algorithm/yet-another-sum-problem/description/)

#### 4.7.2 Floor Sum and Mod Sum of Arithmetic Progression

- **ID:** `floor_sum_of_arithmetic_progression` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/floor_sum_of_arithmetic_progression
- **Templates (1):**
  - [Floor Sum of Arithmetic Progressions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Floor%20Sum%20of%20%20Arithmetic%20Progressions.cpp)
- **Resources (3):**
  - ★ [Floor Sum of Arithmetic Progression and Other Variants | Asif Jawad](https://asfjwd.github.io/2020-04-24-floor-sum-ap/)
  - ★ [How I understand Floor Sum By prabowo](https://codeforces.com/blog/entry/145274)
  - [类欧几里德算法 | OI Wiki](https://oi-wiki.org/math/number-theory/euclidean/)
- **Problems (4):**
  - `[E]` ★ [Floor Sum](https://atcoder.jp/contests/practice2/tasks/practice2_c)
  - `[E]` ★ [Linear Programming?](https://toph.co/p/linear-programming)
  - `[M]` ★ [Bitwise XOR of Arithmetic Progression](http://poj.org/problem?id=3495)
  - `[M]` ★ [Ax + By < C](https://atcoder.jp/contests/abc372/tasks/abc372_g)

#### 4.7.3 Generalized Floor Sum of Arithmetic Progression

- **ID:** `generalized_floor_sum_of_arithmetic_progression` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/generalized_floor_sum_of_arithmetic_progression
- **Templates (1):**
  - [Generalized Floor Sum of Arithmetic Progressions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Generalized%20Floor%20Sum%20of%20Arithmetic%20Progressions.cpp)
- **Resources (2):**
  - ★ [Floor Sum of Arithmetic Progression and Other Variants | Asif Jawad](https://asfjwd.github.io/2020-04-24-floor-sum-ap/)
  - ★ [How I understand Floor Sum By prabowo](https://codeforces.com/blog/entry/145274)
- **Problems (3):**
  - `[E]` ★ [类欧几里得算法](https://www.luogu.com.cn/problem/P5170)
  - `[E]` ★ [类欧几里得算法](https://loj.ac/p/138)
  - `[E]` [WifiPlanet](https://community.topcoder.com/stat?c=problem_statement&pm=9733&rd=12182)

### 4.8 Fibonacci Numbers

**Subcategory ID:** `fibonacci_numbers` · **Topics:** 4

#### 4.8.1 Fibonacci Numbers

- **ID:** `fibonacci_numbers` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/fibonacci_numbers
- **Resources (5):**
  - ★ [Fibonacci Numbers | CP Algorithms](https://cp-algorithms.com/algebra/fibonacci-numbers.html)
  - ★ [Fibonacci sequence | Wiki](https://en.wikipedia.org/wiki/Fibonacci_sequence)
  - [Lamé's Theorem | Cut The Knot](https://www.cut-the-knot.org/blue/LamesTheorem.shtml)
  - ★ [How to check if a given number is Fibonacci number? | Geeks for Geeks](https://www.geeksforgeeks.org/check-number-fibonacci-number/)
  - ★ [An amazing way to calculate 10^18-th fibonacci number using 25 lines of code. By kien_coi_1997](https://codeforces.com/blog/entry/14516)
- **Problems (9):**
  - `[E]` ★ [Easy Fibonacci](https://www.spoj.com/problems/FIBEZ/)
  - `[E]` ★ [Is Fibo](https://www.hackerrank.com/challenges/is-fibo/problem)
  - `[E]` [Even Fibonacci numbers](https://www.hackerrank.com/contests/projecteuler/challenges/euler002/problem)
  - `[E]` ★ [Fibonaccharsis](https://codeforces.com/contest/1853/problem/B)
  - `[M]` ★ [Fibonacci Numbers](https://cses.fi/problemset/task/1722)
  - `[M]` [Number Sequence](https://lightoj.com/problem/number-sequence)
  - `[M]` ★ [Fibonacci Sum](https://www.spoj.com/problems/FIBOSUM/)
  - `[M]` ★ [Euclids algorithm revisited](https://www.spoj.com/problems/MAIN74/)
  - `[H]` [Fibonacci Sequence (Harder)](https://dmoj.ca/problem/fibonacci2)

#### 4.8.2 [Problem] LCM of Fibonacci Numbers

- **ID:** `lcm_of_fibonacci_numbers` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lcm_of_fibonacci_numbers
- **Templates (1):**
  - [LCM of Fibonacci Numbers.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/LCM%20of%20Fibonacci%20Numbers.cpp)
- **Resources (1):**
  - ★ [Editorial of Fibonacci LCM by kevinsogo](https://www.hackerrank.com/contests/infinitum10/challenges/fibonacci-lcm/editorial)
- **Problems (1):**
  - `[E]` ★ [Fibonacci LCM](https://www.hackerrank.com/contests/infinitum10/challenges/fibonacci-lcm/problem)

#### 4.8.3 Pisano Period

- **ID:** `pisano_period` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pisano_period
- **Templates (1):**
  - [Pisano Period.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Pisano%20Period.cpp)
- **Resources (2):**
  - [Pisano period | Wiki](https://en.wikipedia.org/wiki/Pisano_period)
  - [Geeks For Geeks | Fibonacci Number modulo M and Pisano Period](https://www.geeksforgeeks.org/fibonacci-number-modulo-m-and-pisano-period/)
- **Problems (4):**
  - `[E]` ★ [Modular Fibonacci Period](https://www.spoj.com/problems/PISANO/)
  - `[M]` ★ [Kosuke's Sloth](https://codeforces.com/contest/2033/problem/F)
  - `[M]` ★ [Divisible Fibonacci Numbers](https://www.spoj.com/problems/DIVFIBS2/)
  - `[H]` [Fibonacci Number](https://codeforces.com/problemset/problem/193/E)

#### 4.8.4 Phi Field

- **ID:** `phi_field` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/phi_field
- **Templates (1):**
  - [Phi Field.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Phi%20Field.cpp)
- **Problems (6):**
  - `[M]` ★ [Fibonacci Numbers](https://cses.fi/problemset/task/1722)
  - `[M]` ★ [Fibonacci Fever](https://codeforces.com/gym/104412/problem/F)
  - `[M]` ★ [Fibonacci Sum](https://vjudge.net/problem/Gym-105170C)
  - `[M]` ★ [Sasha and Array](https://codeforces.com/problemset/problem/718/C)
  - `[H]` ★ [Panic! at the Disco](https://www.codechef.com/problems/PANIC)
  - `[H]` [Recurrence Power Sum](https://www.spoj.com/problems/RECPWSUM/)

### 4.9 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 6

#### 4.9.1 Pythagorean Triplets

- **ID:** `pythagorean_triplets` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pythagorean_triplets
- **Templates (1):**
  - [Pythagorean Triplets.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Pythagorean%20%20Triplets.cpp)
- **Resources (1):**
  - [Pythagorean triple | Wiki](https://en.wikipedia.org/wiki/Pythagorean_triple)
- **Problems (2):**
  - `[E]` [Pythagorean Triples](https://codeforces.com/problemset/problem/707/C)
  - `[M]` ★ [Hail Pythagoras](https://codeforces.com/gym/104333/problem/I)

#### 4.9.2 Min of Mod of Arithmetic Progression

- **ID:** `min_of_mod_of_arithmetic_progression` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_of_mod_of_arithmetic_progression
- **Templates (1):**
  - [190642](https://judge.yosupo.jp/submission/190642)
- **Resources (1):**
  - [\[Library Checker\] Min of Mod of Linear | maspy](https://maspypy.com/library-checker-min-of-mod-of-linear)
- **Problems (1):**
  - `[E]` ★ [Min of Mod of Linear](https://judge.yosupo.jp/problem/min_of_mod_of_linear)

#### 4.9.3 Factorial Number System

- **ID:** `factoradic_number_system` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/factoradic_number_system
- **Templates (1):**
  - [Factoradic Number System.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Factoradic%20Number%20System.cpp)
- **Resources (1):**
  - [Factorial number system | Wiki](https://en.wikipedia.org/wiki/Factorial_number_system)
- **Problems (1):**
  - `[H]` [Misha and Permutations Summation](https://codeforces.com/contest/501/problem/D)

#### 4.9.4 Stern-Brocot Tree and Rational Approximation

- **ID:** `rational_approximation_stern_brocot_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/rational_approximation_stern_brocot_tree
- **Templates (1):**
  - [Rational Approximation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Rational%20Approximation.cpp)
- **Resources (3):**
  - ★ [The Stern-Brocot tree and Farey sequences | CP Algorithm](https://cp-algorithms.com/others/stern_brocot_tree_farey_sequences.html)
  - ★ [Some discussions about Finding fraction in a range](https://codeforces.com/blog/entry/50244)
  - [Misunderstood the problem but miraculously got an AC By Sayakiss](https://codeforces.com/blog/entry/2674)
- **Problems (7):**
  - `[E]` ★ [The Stern-Brocot Number System](https://vjudge.net/problem/UVA-10077)
  - `[E]` ★ [Rational Approximation](https://judge.yosupo.jp/problem/rational_approximation)
  - `[E]` [Admission to Exam](https://acm.timus.ru/problem.aspx?space=1&num=1673)
  - `[M]` ★ [Farey Sequence](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4878)
  - `[M]` ★ [Decimal Form](https://official.contest.yandex.ru/opencupXVIII/contest/5457/problems/E?lang=en)
  - `[M]` ★ [A/B < p/q < C/D](https://atcoder.jp/contests/abc408/tasks/abc408_g)
  - `[M]` [Nearest Fraction](https://atcoder.jp/contests/abc333/tasks/abc333_g)

#### 4.9.5 [Problem] Number of a * x mod p in a Range

- **ID:** `number_of_ax_mod_p_in_a_range` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_ax_mod_p_in_a_range
- **Templates (1):**
  - [Number of ax%p in a Range.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Number%20of%20ax%25p%20in%20a%20Range.cpp)

#### 4.9.6 [Problem] Smallest Nonnegative Integer x s.t. l ≤ a * x mod p ≤ r

- **ID:** `smallest_nonnegative_integer_x_s_t_l_ax_mod_p_r` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/smallest_nonnegative_integer_x_s_t_l_ax_mod_p_r
- **Templates (1):**
  - [Smallest Nonnegative Integer x s.t. l <= ax % p <= r.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Smallest%20Nonnegative%20Integer%20x%20s.t.%20l%20%3C=%20ax%20%25%20p%20%3C=%20r.cpp)
- **Resources (2):**
  - ★ [Recovering rational number from its remainder modulo huge integer By adamant](https://codeforces.com/blog/entry/73629)
  - ★ [This is most useful CP problem I create until now By dreamoon_love_AA](https://codeforces.com/blog/entry/72537)
- **Problems (3):**
  - `[M]` [From Modular to Rational](https://codeforces.com/gym/102354/problem/I)
  - `[H]` ★ [Golf Time](https://codeforces.com/gym/102411/problem/G)
  - `[H]` [fraction](http://acm.hdu.edu.cn/showproblem.php?pid=6624)

---

## 5. Combinatorics

**Category ID:** `combinatorics` · **Subcategories:** 7 · **Topics:** 24

### 5.1 Techniques

**Subcategory ID:** `techniques` · **Topics:** 1

#### 5.1.1 Contribution Technique

- **ID:** `contribution_technique` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/contribution_technique
- **Prerequisites:** Bit Manipulation, Basic Trees
- **Resources (3):**
  - ★ [Algorithms Lecture #1 - Sums and Expected Value Errichto Algorithms](https://www.youtube.com/watch?v=U_h3IjreRek)
  - ★ [DSA Series : Contribution Technique | ryuusama](https://medium.com/@shahh8138/contribution-technique-6e60ae7f4f95)
  - [Contribution technique-I | Ashwanth K](https://medium.com/spidernitt/contribution-technique-i-c1730f195b41)
- **Problems (18):**
  - `[E]` ★ [Two Arrays and Sum of Functions](https://codeforces.com/contest/1165/problem/E)
  - `[E]` ★ [Counting Triangles](https://vjudge.net/problem/SPOJ-TRICOUNT)
  - `[E]` ★ [Easy Peasy Subset Sum](https://toph.co/p/easy-peasy-subset-sum)
  - `[E]` ★ [SUMMATION](https://www.spoj.com/problems/SUMMATION/)
  - `[E]` [Imbalanced Array](https://codeforces.com/problemset/problem/817/D)
  - `[E]` ★ [LCM Factorization](https://codeforces.com/gym/105884/problem/J)
  - `[E]` [Jumping Reaction](https://codeforces.com/gym/104375/problem/J)
  - `[M]` ★ [Xor Sum 4](https://vjudge.net/problem/AtCoder-abc147_d)
  - `[M]` [Convolution XOR SUM](https://vjudge.net/problem/Gym-104333A)
  - `[M]` ★ [Sum of XOR Functions](https://codeforces.com/contest/1879/problem/D)
  - `[M]` ★ [Math Encoder](https://vjudge.net/problem/Baekjoon-23992)
  - `[M]` [Intersection and Union](https://codeforces.com/problemset/problem/1743/F)
  - `[M]` ★ [Score of a Tree](https://codeforces.com/contest/1777/problem/D)
  - `[M]` ★ [LuoTianyi and the Floating Islands (Hard Version)](https://codeforces.com/problemset/problem/1824/B2)
  - `[M]` ★ [And Xor Tree](https://qoj.ac/contest/1111/problem/5566)
  - `[M]` [Boneca Ambalabu](https://codeforces.com/contest/2094/problem/E)
  - `[H]` ★ [Avoid Straight Line](https://atcoder.jp/contests/abc312/tasks/abc312_g)
  - `[H]` ★ [Yet Another Mex Problem](https://www.codechef.com/problems/YAMP)

### 5.2 Catalan

**Subcategory ID:** `catalan` · **Topics:** 2

#### 5.2.1 Catalan Numbers

- **ID:** `catalan_numbers` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/catalan_numbers
- **Resources (3):**
  - ★ [Catalan Numbers | CP Algorithms](https://cp-algorithms.com/combinatorics/catalan-numbers.html)
  - [22.2 Catalan numbers | CPH](https://usaco.guide/CPH.pdf#page=220)
  - ★ [Catalan number | Wiki](https://en.wikipedia.org/wiki/Catalan_number)
- **Problems (10):**
  - `[E]` ★ [Bracket Sequences I](https://cses.fi/problemset/task/2064)
  - `[E]` [Stacking Pancakes](https://www.codechef.com/APRIL12/problems/PANSTACK/)
  - `[E]` [Skyline](https://www.spoj.com/problems/SKYLINE/)
  - `[E]` ★ [Safe Salutations](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=932)
  - `[E]` [Game of Connections](http://poj.org/problem?id=2084)
  - `[E]` [White and Black Balls](https://atcoder.jp/contests/abc205/tasks/abc205_e)
  - `[M]` ★ [How many trees?](https://codeforces.com/problemset/problem/9/D)
  - `[M]` ★ [Counting Perfect BST](https://lightoj.com/problem/counting-perfect-bst)
  - `[M]` [The Soldier's Dilemma](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4752)
  - `[M]` ★ [Anton and School - 2](https://codeforces.com/contest/785/problem/D)

#### 5.2.2 Catalan Convolution

- **ID:** `catalan_convolution` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/catalan_convolution
- **Resources (1):**
  - [\[Tutorial\] Catalan Numbers and Catalan Convolution By Dardy](https://codeforces.com/blog/entry/87585)
- **Problems (2):**
  - `[E]` [White and Black Balls](https://atcoder.jp/contests/abc205/tasks/abc205_e)
  - `[M]` ★ [Bracket Sequences II](https://cses.fi/problemset/task/2187)

### 5.3 Inclusion Exclusion

**Subcategory ID:** `inclusion_exclusion` · **Topics:** 3

#### 5.3.1 Principle of Inclusion and Exclusion (PIE)

- **ID:** `principle_of_inclusion_and_exclusion` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/principle_of_inclusion_and_exclusion
- **Resources (3):**
  - ★ [The Inclusion-Exclusion Principle | CP Algorithms](https://cp-algorithms.com/combinatorics/inclusion-exclusion.html)
  - [22.3 Inclusion-exclusion | CPH](https://usaco.guide/CPH.pdf#page=223)
  - ★ [\[Tutorial\] Inclusion-Exclusion Principle By Roundgod](https://codeforces.com/blog/entry/64625)
- **Problems (28):**
  - `[E]` ★ [The Lottery](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1266)
  - `[E]` ★ [Prime Multiples](https://cses.fi/problemset/task/2185)
  - `[E]` ★ [Count Good Numbers](https://codeforces.com/contest/2125/problem/C)
  - `[E]` [Cheerleaders](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2906)
  - `[E]` [Another Game With Numbers](https://www.spoj.com/problems/NGM2/)
  - `[E]` [EASY MATH](https://www.spoj.com/problems/EASYMATH/)
  - `[E]` [FEASTOFPIGS](https://www.spoj.com/problems/MOMOS/)
  - `[E]` ★ [Co-prime](http://acm.hdu.edu.cn/showproblem.php?pid=4135)
  - `[E]` [Typewriter](https://atcoder.jp/contests/abc246/tasks/abc246_f)
  - `[M]` [Ugly Number III](https://leetcode.com/problems/ugly-number-iii/description/)
  - `[M]` [Sky Code](https://www.spoj.com/problems/MSKYCODE/)
  - `[M]` [Count Relations](https://www.codechef.com/JAN11/problems/COUNTREL/)
  - `[M]` ★ [Square-free integers](https://www.spoj.com/problems/SQFREE/)
  - `[M]` [Almost Prime Numbers Again](https://www.spoj.com/problems/KPRIMESB/)
  - `[M]` [Find Number Of Pair of Friends](https://www.spoj.com/problems/IITKWPCH/)
  - `[M]` [Balanced Cow Subsets](https://www.spoj.com/problems/SUBSET/)
  - `[M]` ★ [Grid 2](https://atcoder.jp/contests/dp/tasks/dp_y)
  - `[M]` ★ [Count GCD](https://codeforces.com/contest/1750/problem/D)
  - `[M]` ★ [Character Encoding](http://acm.hdu.edu.cn/showproblem.php?pid=6397)
  - `[M]` ★ [Tree and Constraints](https://atcoder.jp/contests/abc152/tasks/abc152_f)
  - `[M]` ★ [x = a^b](https://atcoder.jp/contests/abc361/tasks/abc361_f)
  - `[M]` [Natlan Exploring](https://codeforces.com/contest/2037/problem/G)
  - `[M]` [King of Card Games](https://codeforces.com/gym/105631/problem/K)
  - `[M]` ★ [Loud Cicada](https://atcoder.jp/contests/abc423/tasks/abc423_f)
  - `[H]` ★ [K-Inversion Permutations](https://www.hackerrank.com/contests/101hack43/challenges/k-inversion-permutations/problem)
  - `[H]` ★ [Kids Aren't Alright](https://www.acmicpc.net/problem/19313)
  - `[H]` [Cowpatibility](https://usaco.org/index.php?page=viewproblem2&cpid=862)
  - `[H]` ★ [Jzzhu and Numbers](https://codeforces.com/contest/449/problem/D)

#### 5.3.2 Derangements

- **ID:** `derangements` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/derangements
- **Templates (1):**
  - [Derangement.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Derangement.cpp)
- **Resources (5):**
  - ★ [Derangement | Wiki](https://en.wikipedia.org/wiki/Derangement)
  - [Derangements | USACO Guide](https://usaco.guide/gold/combo?lang=cpp#derangements)
  - ★ [Derangement Generation of an Array \[Tutorial\] By lazyneuron](https://codeforces.com/blog/entry/66176)
  - ★ [Rencontres numbers | Wiki](https://en.wikipedia.org/wiki/Rencontres_numbers)
  - [Help wanted for a interesting problem. By EarthMessenger](https://codeforces.com/blog/entry/114983)
- **Problems (5):**
  - `[E]` ★ [Christmas Party](https://cses.fi/problemset/task/1717)
  - `[E]` ★ [Montmort Number](https://judge.yosupo.jp/problem/montmort_number_mod)
  - `[E]` ★ [Almost Identity Permutations](https://codeforces.com/problemset/problem/888/D)
  - `[E]` ★ [Derangement](https://codeforces.com/gym/100971/problem/B)
  - `[M]` [Array Shuffling](https://codeforces.com/contest/1672/problem/F1)

#### 5.3.3 Inclusion Exclusion on Multiples

- **ID:** `inclusion_and_exclusion_on_multiples` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/inclusion_and_exclusion_on_multiples
- **Resources (1):**
  - ★ [\[Tutorial\] DP in Number Theory By stoyan_malinin](https://codeforces.com/blog/entry/83757)
- **Problems (20):**
  - `[E]` ★ [Counting Coprime Pairs](https://cses.fi/problemset/task/2417)
  - `[E]` ★ [Common Divisors](https://cses.fi/problemset/task/1081)
  - `[E]` [Playing with GCD](https://www.spoj.com/problems/NAJPWG/)
  - `[E]` [Small GCD](https://codeforces.com/contest/1900/problem/D)
  - `[E]` ★ [Coprime Integers](https://open.kattis.com/problems/coprimeintegers)
  - `[E]` ★ [Coprime Triples](https://www.codechef.com/LTIME13/problems/COPRIME3)
  - `[E]` ★ [GCD Extreme](https://www.spoj.com/problems/GCDEX/)
  - `[M]` ★ [Coprime Subsequences](https://codeforces.com/contest/803/problem/F)
  - `[M]` ★ [Winter is here](https://codeforces.com/contest/839/problem/D)
  - `[M]` ★ [Number of Prime Strings](https://www.spoj.com/problems/PSTR/)
  - `[M]` ★ [LCMs](https://atcoder.jp/contests/agc038/tasks/agc038_c)
  - `[M]` [Devu and Birthday Celebration](https://codeforces.com/contest/439/problem/E)
  - `[M]` ★ [LCM Sum](https://www.spoj.com/problems/LCMSUM/)
  - `[M]` ★ [LCM Extreme](https://lightoj.com/problem/lcm-extreme)
  - `[M]` [GCD](http://acm.hdu.edu.cn/showproblem.php?pid=1695)
  - `[M]` ★ [Sum of gcd of Tuples (Hard)](https://atcoder.jp/contests/abc162/tasks/abc162_e)
  - `[M]` [Yet Another Sum Problem](https://www.hackerearth.com/problem/algorithm/yet-another-sum-problem/description/)
  - `[M]` ★ [Make It One](https://codeforces.com/contest/1043/problem/F)
  - `[H]` [Cowslip Collections](https://codeforces.com/contest/645/problem/F)
  - `[H]` ★ [GCD cost on the tree](https://atcoder.jp/contests/abc248/tasks/abc248_g)

### 5.4 Factorials and Binomial Coefficients (nCr)

**Subcategory ID:** `binomial_coefficient` · **Topics:** 8

#### 5.4.1 Lucas Theorem

- **ID:** `lucas_theorem` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/lucas_theorem
- **Templates (1):**
  - [Lucas Theorem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Lucas%20Theorem.cpp)
- **Resources (3):**
  - ★ [Lucas Theorem – Proof and Applications | forthright48](https://forthright48.com/lucas-theorem-proof-and-applications/)
  - [Lucas's theorem | Wiki](https://en.wikipedia.org/wiki/Lucas%27s_theorem)
  - ★ [Kummer's theorem | Wiki](https://en.wikipedia.org/wiki/Kummer%27s_theorem)
- **Problems (6):**
  - `[E]` ★ [Help with selection](https://www.codechef.com/problems/CHKSEL)
  - `[E]` ★ [Topper Rama Rao](https://www.spoj.com/problems/HLP_RAMS/)
  - `[M]` ★ [The Ultimate Riddle](https://www.spoj.com/problems/DCEPC13D/)
  - `[M]` ★ [Dukkar and Pikka](https://www.spoj.com/problems/DUKKAR/)
  - `[M]` ★ [Goodbye, Banker Life](https://codeforces.com/contest/2072/problem/F)
  - `[M]` [Cheese and Random Toppings](https://www.hackerrank.com/contests/infinitum10/challenges/cheese-and-random-toppings)

#### 5.4.2 nCr Modulo Any Mod

- **ID:** `ncr_modulo_any_mod` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/ncr_modulo_any_mod
- **Templates (1):**
  - [nCr Modulo Any Mod.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/nCr%20Modulo%20Any%20Mod.cpp)
- **Resources (4):**
  - ★ [Binomial Coefficients | CP Algorithms](https://cp-algorithms.com/combinatorics/binomial-coefficients.html)
  - [Best known algos for calculating nCr % M](https://discuss.codechef.com/t/best-known-algos-for-calculating-ncr-m/896)
  - ★ [Computing n! modulo pᵏ for small p By adamant](https://codeforces.com/blog/entry/116681)
  - ★ [Binomial Modulo Prime Power | prabowo](https://blog.prabowodjonatan.id/posts/binomial-mod-pe/)
- **Problems (5):**
  - `[E]` ★ [nCr](https://www.hackerrank.com/challenges/ncr/problem)
  - `[E]` ★ [Binomial Coefficient](https://judge.yosupo.jp/problem/binomial_coefficient_prime_mod)
  - `[M]` ★ [Long Sandwich](https://www.codechef.com/problems/SANDWICH)
  - `[M]` [Strange Game](https://lightoj.com/problem/strange-game)
  - `[H]` ★ [Binomial Coefficient](https://www.acmicpc.net/problem/19124)

#### 5.4.3 Large Factorials and Binomial Coefficients

- **ID:** `large_factorials` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/large_factorials
- **Resources (3):**
  - ★ [\[Editorial\]Contest Based on SUST Intra University Programming Contest 2019 By Shahjalal Shohag — DSAAcademy](https://codeforces.com/blog/entry/72364)
  - ★ [Fastest way to get factorial modulo a prime](https://codeforces.com/blog/entry/63491)
  - ★ [Binomial coefficients of large numbers modulo prime](https://codeforces.com/blog/entry/65178)
- **Problems (4):**
  - `[E]` ★ [Factorial](https://judge.yosupo.jp/problem/factorial)
  - `[E]` ★ [Enormous Product](https://toph.co/p/enormous-product)
  - `[H]` [Many Factorials](https://judge.yosupo.jp/problem/many_factorials)
  - `[VH]` ★ [Factorial Modulo Prime](https://www.spoj.com/problems/FACTMODP/)

#### 5.4.4 Legendre's Formula

- **ID:** `legendres_formula` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/legendres_formula
- **Resources (1):**
  - ★ [Finding Power of Factorial Divisor | CP Algorithm](https://cp-algorithms.com/algebra/factorial-divisors.html)
- **Problems (2):**
  - `[E]` ★ [Trailing Zeroes (III)](https://lightoj.com/problem/trailing-zeroes-iii)
  - `[E]` ★ [Trailing Zeros](https://cses.fi/problemset/task/1618)

#### 5.4.5 Prefix Sum Queries of Binomial Coefficients

- **ID:** `prefix_sum_queries_of_nci` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/prefix_sum_queries_of_nci
- **Templates (1):**
  - [Prefix Sum Queries of nCi.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Prefix%20Sum%20Queries%20of%20nCi.cpp)
- **Resources (1):**
  - ★ [(Rolling) Range Sum Query of binomial coefficients By arvindf232](https://codeforces.com/blog/entry/138204)
- **Problems (6):**
  - `[E]` ★ [Harvest of Apples](https://vjudge.net/problem/HDU-6333)
  - `[M]` ★ [L Partition](https://atcoder.jp/contests/arc190/tasks/arc190_b)
  - `[H]` ★ [Cool Subsets](https://www.codechef.com/JAN21A/problems/COOLSBST)
  - `[H]` [Card Game for Three](https://atcoder.jp/contests/arc061/tasks/arc061_d)
  - `[H]` ★ [The Destruction of the Universe (Hard Version)](https://codeforces.com/contest/2030/problem/G2)
  - `[H]` [Multithreading (Hard Version)](https://codeforces.com/contest/1450/problem/H2)

#### 5.4.6 Prefix Sum of Binomial Coefficients for a Fixed Large N

- **ID:** `sum_of_nci_for_a_fixed_large_n` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sum_of_nci_for_a_fixed_large_n
- **Templates (1):**
  - [Sum of nCi for a Fixed Large n.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sum%20of%20nCi%20for%20a%20Fixed%20Large%20n.cpp)
- **Resources (1):**
  - ★ [min_25 explanation](https://discuss.codechef.com/t/how-to-calculate-sum-of-binomial-coefficients-efficiently/12846/4)

#### 5.4.7 Sum of nCr Over a Fixed Congruence Class

- **ID:** `sum_of_ncr_over_a_fixed_congruence_class` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sum_of_ncr_over_a_fixed_congruence_class
- **Templates (1):**
  - [Sum of nCi over a Fixed Congruence Class.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sum%20of%20nCi%20over%20a%20Fixed%20Congruence%20Class.cpp)
- **Problems (2):**
  - `[M]` ★ [You](https://toph.co/p/abcdefgh)
  - `[H]` ★ [Simple nCr](https://codeforces.com/gym/280379/problem/A)

#### 5.4.8 [Problem] Sum of nCr(a[i], K) for each K from 1 to N

- **ID:** `sum_of_ncr_a_i_k_for_each_k_from_1_to_n` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sum_of_ncr_a_i_k_for_each_k_from_1_to_n
- **Templates (1):**
  - [Sum of C(a(i), k) for each k from 1 to n.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Sum%20of%20C%28a%28i%29,%20k%29%20for%20each%20k%20from%201%20to%20n.cpp)
- **Problems (2):**
  - `[H]` ★ [Many Easy Problems](https://atcoder.jp/contests/agc005/tasks/agc005_f)
  - `[H]` ★ [Airplane Cliques](https://codeforces.com/gym/102538/problem/A)

### 5.5 Stirling Numbers

**Subcategory ID:** `stirling_numbers` · **Topics:** 5

#### 5.5.1 Stirling Numbers (Basic)

- **ID:** `stirling_numbers` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/stirling_numbers
- **Resources (4):**
  - [Stirling numbers of the second kind | Wiki](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind)
  - [Stirling numbers of the first kind | Wiki](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind)
  - [Recurrence relation for Stirling number of first kind with a minimum value](https://math.stackexchange.com/questions/4003424/recurrence-relation-for-stirling-number-of-first-kind-with-a-minimum-value)
  - [Distributing N distinct people in M identical rooms By bluemmb](https://codeforces.com/blog/entry/48603)
- **Problems (4):**
  - `[M]` ★ [Caching Combinatorics](https://toph.co/p/caching-combinatorics)
  - `[M]` [Binary Stirling Numbers](https://www.spoj.com/problems/BINSTIRL/)
  - `[VH]` [Stirling Number of the First Kind (Small p, Large n)](https://judge.yosupo.jp/problem/stirling_number_of_the_first_kind_small_p_large_n)
  - `[VH]` [Stirling Number of the Second Kind (Small p, Large n)](https://judge.yosupo.jp/problem/stirling_number_of_the_second_kind_small_p_large_n)

#### 5.5.2 Stirling Number of the First Kind for Fixed N

- **ID:** `stirling_number_of_the_first_kind_for_fixed_n` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stirling_number_of_the_first_kind_for_fixed_n
- **Templates (1):**
  - [Stirling Number of the First Kind for Fixed n.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Stirling%20Number%20of%20the%20First%20Kind%20for%20Fixed%20n.cpp)
- **Resources (2):**
  - ★ [Stirling numbers of the first kind | Wiki](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind#Definitions)
  - [Stirling numbers with fixed n and k By adamant](https://codeforces.com/blog/entry/117906)
- **Problems (3):**
  - `[E]` ★ [Stirling Number of the First Kind](https://judge.yosupo.jp/problem/stirling_number_of_the_first_kind)
  - `[M]` ★ [Sasha and the Swaps II](https://www.hackerrank.com/contests/w23/challenges/sasha-and-swaps-ii/problem)
  - `[H]` [Bandit Blues](https://codeforces.com/problemset/problem/960/G)

#### 5.5.3 Stirling Number of the First Kind for Fixed K

- **ID:** `stirling_number_of_the_first_kind_for_fixed_k` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stirling_number_of_the_first_kind_for_fixed_k
- **Templates (1):**
  - [Stirling Number of the First Kind for Fixed k.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Stirling%20Number%20of%20the%20First%20Kind%20for%20Fixed%20k.cpp)
- **Resources (3):**
  - ★ [\[Tutorial\] Generating Functions in Competitive Programming (Part 1) By zscoder](https://codeforces.com/blog/entry/77468#:~:text=several%20disjoint%20cycles.-,Problem.%20Count%20the%20number%20of%20permutations%20of%20length,cycles.,-These%20numbers%20are)
  - [Stirling numbers with fixed n and k By adamant](https://codeforces.com/blog/entry/117906)
  - [Expansions for fixed k | Wiki](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_first_kind#Expansions_for_fixed_k)
- **Problems (2):**
  - `[E]` ★ [Stirling Number of the First Kind (Fixed K)](https://judge.yosupo.jp/problem/stirling_number_of_the_first_kind_fixed_k)
  - `[H]` ★ [Baby Ehab Plays with Permutations](https://codeforces.com/contest/1516/problem/E)

#### 5.5.4 Stirling Number of the Second Kind for Fixed N

- **ID:** `stirling_number_of_the_second_kind_for_fixed_n` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stirling_number_of_the_second_kind_for_fixed_n
- **Templates (1):**
  - [Stirling Number of the Second Kind for Fixed n.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Stirling%20Number%20of%20the%20Second%20Kind%20for%20Fixed%20n.cpp)
- **Resources (1):**
  - ★ [A comment by PrinceOfPersia](https://codeforces.com/blog/entry/48603?#comment-326879)
- **Problems (1):**
  - `[E]` ★ [Stirling Number of the Second Kind](https://judge.yosupo.jp/problem/stirling_number_of_the_second_kind)

#### 5.5.5 Stirling Number of the Second Kind for Fixed K

- **ID:** `stirling_number_of_the_second_kind_for_fixed_k` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/stirling_number_of_the_second_kind_for_fixed_k
- **Templates (1):**
  - [Stirling Number of the Second Kind for Fixed k.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Stirling%20Number%20of%20the%20Second%20Kind%20for%20Fixed%20k.cpp)
- **Resources (2):**
  - [Stirling Number of the Second Kind | Wiki](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind#Generating_functions)
  - [Stirling numbers with fixed n and k By adamant](https://codeforces.com/blog/entry/117906)
- **Problems (2):**
  - `[E]` ★ [Stirling Number of the Second Kind (Fixed K)](https://judge.yosupo.jp/problem/stirling_number_of_the_second_kind_fixed_k)
  - `[M]` ★ [Partitions](https://codeforces.com/contest/961/problem/G)

### 5.6 Partitions

**Subcategory ID:** `partitions` · **Topics:** 2

#### 5.6.1 Partitions of an Integer, Partition Function and Pentagonal Number Theorem

- **ID:** `partition_function` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/partition_function
- **Templates (1):**
  - [Partition Function.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Partition%20Function.cpp)
- **Resources (6):**
  - [Partition function (number theory) | Wiki](https://en.wikipedia.org/wiki/Partition_function_%28number_theory%29)
  - ★ [Partition Function Intuitive Approach | ABalobanov](https://codeforces.com/blog/entry/55686?#comment-394330)
  - ★ [Partitions and pentagonal number theorem By adamant](https://codeforces.com/blog/entry/104312)
  - [Glaisher's theorem](https://en.wikipedia.org/wiki/Glaisher%27s_theorem)
  - [Pentagonal number theorem | Wiki](https://en.wikipedia.org/wiki/Pentagonal_number_theorem)
  - [The Pentagonal Number Theorem and All That | Dick Koch](https://pages.uoregon.edu/koch/PentagonalNumbers.pdf)
- **Problems (5):**
  - `[E]` ★ [Partition Function](https://judge.yosupo.jp/problem/partition_function)
  - `[M]` ★ [Perfect Permutations](https://www.hackerearth.com/problem/algorithm/perfect-permutations-september-clash/)
  - `[M]` [Decimal Expansion](https://codeforces.com/gym/102354/problem/E)
  - `[H]` ★ [Sum of Prod of Min](https://atcoder.jp/contests/abc279/tasks/abc279_h)
  - `[H]` ★ [Graph Counting](https://codeforces.com/gym/102268/problem/G)

#### 5.6.2 Partitions of a Set / Bell Number

- **ID:** `bell_number` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bell_number
- **Templates (1):**
  - [Bell Number.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Bell%20Number.cpp)
- **Resources (1):**
  - [Bell number | Wiki](https://en.wikipedia.org/wiki/Bell_number)
- **Problems (2):**
  - `[E]` ★ [Bell Number](https://judge.yosupo.jp/problem/bell_number)
  - `[M]` ★ [Symmetric and Transitive](https://codeforces.com/contest/568/problem/B)

### 5.7 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 3

#### 5.7.1 Burnside's Lemma / Polya Enumeration Theorem

- **ID:** `burnside_lemma` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/burnside_lemma
- **Resources (5):**
  - ★ [Burnside's lemma / Pólya enumeration theorem | CP Algorithms](https://cp-algorithms.com/combinatorics/burnside.html)
  - ★ [\[Tutorial\] Burnside's lemma (with example) By TwoFx](https://codeforces.com/blog/entry/62401)
  - [Burnside Lemma made simple. By Everule](https://codeforces.com/blog/entry/102668)
  - [\[Video Tutorial\] Burnside Lemma By acraider](https://codeforces.com/blog/entry/98703)
  - [\[Tutorial\] From Burnside to Polya: A Short Introduction to Group Theory By Zhtluo](https://codeforces.com/blog/entry/118984)
- **Problems (16):**
  - `[E]` ★ [Counting Necklaces](https://cses.fi/problemset/task/2209)
  - `[E]` ★ [Necklace](https://lightoj.com/problem/necklace)
  - `[E]` ★ [Counting Grids](https://cses.fi/problemset/task/2210)
  - `[E]` ★ [Buildings](https://codeforces.com/gym/101873/problem/B)
  - `[E]` [Count the Necklaces](https://www.hackerrank.com/contests/infinitum12/challenges/count-the-necklaces)
  - `[E]` ★ [Cube Coloring](https://csacademy.com/contest/beta-round-8/task/cube-coloring/)
  - `[M]` ★ [Side Transmutations](https://codeforces.com/contest/1065/problem/E)
  - `[M]` [Necklace of Beads](http://poj.org/problem?id=1286)
  - `[M]` ★ [Lucy and the Flowers](https://www.codechef.com/problems/DECORATE)
  - `[M]` [Magic Bracelet](http://poj.org/problem?id=2888)
  - `[M]` [Sorting Machine](https://www.spoj.com/problems/SRTMACH/)
  - `[M]` ★ [Colorful Grids](https://www.codechef.com/problems/ICPC16E)
  - `[M]` [Dodecahedron](https://acm.timus.ru/problem.aspx?space=1&num=1661)
  - `[H]` ★ [Unique Strings](https://codeforces.com/contest/1954/problem/F)
  - `[H]` [Cube](https://atcoder.jp/contests/abc198/tasks/abc198_f)
  - `[H]` [Number of Cubes](https://codeforces.com/contest/2040/problem/F)

#### 5.7.2 Bertrand's Ballot Theorem

- **ID:** `bertrands_ballot_theorem` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bertrands_ballot_theorem
- **Resources (1):**
  - [Bertrand's ballot theorem | Wiki](https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem)
- **Problems (3):**
  - `[E]` ★ [Yanu in Movie theatre](https://www.spoj.com/problems/FUNPROB/)
  - `[M]` ★ [Winning at Sports](https://codeforces.com/gym/100579/problem/C)
  - `[H]` [Vaibhav and Ministers](https://www.codechef.com/problems/VAIMIN)

#### 5.7.3 Young Tableaus and the Hook Length Formula

- **ID:** `young_tableaus` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/young_tableaus
- **Resources (1):**
  - ★ [Young Tableaus and the Hook Length Formula By mango_lassi](https://codeforces.com/blog/entry/98167)
- **Problems (3):**
  - `[H]` ★ [Disjoint LIS](https://codeforces.com/gym/102538/problem/D)
  - `[H]` [LIS Counting](https://codeforces.com/gym/103439/problem/D)
  - `[H]` [L(I+D)S](https://yukicoder.me/problems/no/2048)

---

## 6. Math

**Category ID:** `math` · **Subcategories:** 10 · **Topics:** 79

### 6.1 Convolution

**Subcategory ID:** `convolution` · **Topics:** 7

#### 6.1.1 Fast Fourier Transform (FFT)

- **ID:** `fft` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/fft
- **Templates (1):**
  - [FFT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/FFT.cpp)
- **Resources (11):**
  - ★ [Multiplying polynomials | Fast Fourier Transform (FFT)](https://www.cs.cmu.edu/afs/cs/academic/class/15451-s10/www/lectures/lect0423.txt)
  - ★ [Fast Fourier transform | CP Algorithms](https://cp-algorithms.com/algebra/fft.html)
  - ★ [Tutorial on FFT/NTT — The tough made simple. ( Part 1 ) By sidhant](https://codeforces.com/blog/entry/43499)
  - ★ [\[Tutorial\] FFT By -is-this-fft-,](https://codeforces.com/blog/entry/111371)
  - [FFT | peltorator](https://www.youtube.com/watch?v=ZiHBc4IKcMw&list=PLENCyMEWNkfj6KCElu-qv6BNrgIMnxL8q)
  - [Fast Fourier Transform and Polynomials Moscow International Workshop ACM ICPC 2017 | Oleksandr Kulkov](https://drive.google.com/file/d/1B9BIfATnI_qL6rYiE5hY9bh20SMVmHZ7/view)
  - ★ [The Remarkable Story Behind The Most Important Algorithm Of All Time | Veritasium](https://www.youtube.com/watch?v=nmgFG7PUHfo)
  - ★ [But what is the Fourier Transform? A visual introduction | 3Blue1Brown](https://www.youtube.com/watch?v=spUNpyF58BY&t=395s)
  - ★ [The Fast Fourier Transform (FFT): Most Ingenious Algorithm Ever? | Reducible](https://www.youtube.com/watch?v=h7apO7q16V0)
  - [FFT | FFT with mod | NTT | Arabic tutorial for Competitive Programming](https://www.youtube.com/watch?v=AaU52X6Krxc&list=PL06TMXRpUI1R6ZZ6UGuerJQOEuoth-zSt&index=10)
  - [Applications on FFT | Arabic tutorial for Competitive Programming](https://www.youtube.com/watch?v=U-3qZQmYQmM&t=7850s)
- **Problems (34):**
  - `[E]` ★ [Apples and Bananas](https://cses.fi/problemset/task/2111/)
  - `[E]` ★ [Polynomial Multiplication](https://www.spoj.com/problems/POLYMUL/)
  - `[E]` ★ [A+B Problem](https://open.kattis.com/problems/aplusb)
  - `[E]` ★ [Thief in a Shop](https://codeforces.com/problemset/problem/632/E)
  - `[E]` ★ [Ada and Nucleobase](https://www.spoj.com/problems/ADAMATCH/)
  - `[E]` ★ [K-Inversions](https://open.kattis.com/problems/kinversions)
  - `[E]` ★ [Maximum Self-Matching](https://www.spoj.com/problems/MAXMATCH/)
  - `[E]` ★ [Signal Processing](https://cses.fi/problemset/task/2113)
  - `[E]` [Not Divisible](https://www.codechef.com/problems/NOTD)
  - `[E]` ★ [Very Fast Multiplication](https://www.spoj.com/problems/VFMUL/)
  - `[E]` [Fine Triplets](https://atcoder.jp/contests/abc392/tasks/abc392_g)
  - `[E]` [One Bit Positions](https://cses.fi/problemset/task/2112)
  - `[E]` [Nefertiti](https://codeforces.com/group/Rilx5irOux/contest/477876/problem/N)
  - `[E]` [Jinin](https://codeforces.com/group/Rilx5irOux/contest/537870/problem/G)
  - `[E]` [Piscine today](https://codeforces.com/group/Rilx5irOux/contest/605577/problem/E)
  - `[M]` ★ [Triple Sums](https://www.spoj.com/problems/TSUM/)
  - `[M]` ★ [Nikita and Order Statistics](https://codeforces.com/problemset/problem/993/E)
  - `[M]` [Yet Another String Matching Problem](https://codeforces.com/problemset/problem/954/I)
  - `[M]` [Lightsabers (hard)](https://codeforces.com/problemset/problem/958/F3)
  - `[M]` [Running Competition](https://codeforces.com/contest/1398/problem/G)
  - `[M]` ★ [Lazy Hash Table](https://codeforces.com/gym/101821/problem/F)
  - `[M]` ★ [Fuzzy Search](https://codeforces.com/contest/528/problem/D)
  - `[M]` [Rusty String](https://codeforces.com/problemset/problem/827/E)
  - `[M]` ★ [Frequency Table of Tree Distance](https://judge.yosupo.jp/problem/frequency_table_of_tree_distance)
  - `[M]` ★ [Awesome Shawarma](https://codeforces.com/gym/101991/problem/A)
  - `[M]` [Swimmers in the Pool](https://codeforces.com/problemset/problem/1845/F)
  - `[M]` [Substring Search](https://codeforces.com/problemset/problem/1334/G)
  - `[M]` [Bit Substrings](https://cses.fi/problemset/task/2115)
  - `[M]` [Gateways of Beisan](https://codeforces.com/group/Rilx5irOux/contest/538817/problem/G)
  - `[M]` [Convolution (Mod 2^64)](https://judge.yosupo.jp/problem/convolution_mod_2_64)
  - `[H]` ★ [Product Modulo](https://atcoder.jp/contests/agc047/tasks/agc047_c)
  - `[H]` [Design Tutorial: Increase the Constraints](https://codeforces.com/problemset/problem/472/G)
  - `[H]` ★ [Tile Cutting](https://vjudge.net/problem/Kattis-tiles)
  - `[VH]` [Epic Convolution](https://codeforces.com/problemset/problem/1054/H)

#### 6.1.2 Number Theoretic Transform (NTT)

- **ID:** `ntt` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/ntt
- **Templates (2):**
  - [NTT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/NTT.cpp)
  - [NTT With Any Prime MOD.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/NTT%20With%20Any%20Prime%20MOD.cpp)
- **Resources (4):**
  - ★ [Number theoretic transform | CP Algorithms](https://cp-algorithms.com/algebra/fft.html#number-theoretic-transform)
  - [Tutorial on FFT/NTT — The tough made simple. ( Part 2 ) By sidhant](https://codeforces.com/blog/entry/43499)
  - [Fast convolution for 64-bit integers By quasisphere](https://codeforces.com/blog/entry/45298)
  - [NTT with modular arithmetic reductions | performance comparasion with FFT](https://codeforces.com/blog/entry/129600)
- **Problems (25):**
  - `[E]` ★ [Convolution](https://judge.yosupo.jp/problem/convolution_mod)
  - `[E]` ★ [Convolution (Mod 1,000,000,007)](https://judge.yosupo.jp/problem/convolution_mod_1000000007)
  - `[E]` ★ [Lucky Tickets](https://codeforces.com/contest/1096/problem/G)
  - `[E]` ★ [Product of Polynomial Sequence](https://judge.yosupo.jp/problem/product_of_polynomial_sequence)
  - `[E]` ★ [Play the Lottery](https://toph.co/p/play-the-lottery)
  - `[E]` [Jinin](https://codeforces.com/group/Rilx5irOux/contest/537870/problem/G)
  - `[E]` [K-rep Array](https://qoj.ac/contest/2071/problem/10980)
  - `[M]` ★ [XOR Sums](https://www.codechef.com/problems/SUMXOR2)
  - `[M]` ★ [A Cumulative Sum Problem](https://www.spoj.com/problems/OVICUMSUM/)
  - `[M]` ★ [Product Tuples](https://codeforces.com/problemset/problem/1218/E)
  - `[M]` ★ [Divisor Set](https://codeforces.com/problemset/problem/1257/G)
  - `[M]` ★ [Linear Diophantine Equation](https://www.spoj.com/problems/COUNTDIO/)
  - `[M]` [Lucas Theorem](https://www.codechef.com/FEB18/problems/LUCASTH)
  - `[M]` ★ [Tree Coloring](https://codeforces.com/problemset/problem/1613/F)
  - `[M]` ★ [Add By Permutation](https://www.codechef.com/JUNE221A/problems/ADDBYPERM)
  - `[M]` ★ [Binomial Fever](https://www.codechef.com/problems/BINOFEV)
  - `[M]` [Red-White Fence](https://codeforces.com/contest/1251/problem/F)
  - `[M]` [Symmetric Swap](https://codeforces.com/gym/105973/problem/D)
  - `[M]` [K for More, K for Less](https://codeforces.com/gym/104555/problem/K)
  - `[H]` ★ [Constrained Tree Degree](https://atcoder.jp/contests/abc303/tasks/abc303_h)
  - `[H]` ★ [Power Sum](https://www.codechef.com/SEPT19A/problems/PSUM)
  - `[H]` [Permutations](https://csacademy.com/contest/round-75/task/permutations/)
  - `[H]` ★ [Transforming Sequence](https://codeforces.com/problemset/problem/623/E)
  - `[H]` ★ [PolandBall and Many Other Balls](https://codeforces.com/problemset/problem/755/G)
  - `[H]` [Chef and Interval Painting](https://www.codechef.com/MARCH18A/problems/CHEFKNN)

#### 6.1.3 2D FFT / NTT

- **ID:** `2d_fft_ntt` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_fft_ntt
- **Templates (1):**
  - [NTT 2D.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/NTT%202D.cpp)
- **Problems (4):**
  - `[E]` ★ [Dasha and cyclic table](https://codeforces.com/contest/754/problem/E)
  - `[E]` ★ [Buying Land](https://www.codechef.com/problems/BUYLAND/)
  - `[M]` ★ [Matchings](https://open.kattis.com/problems/matchings)
  - `[M]` ★ [Mosaic Browsing](https://open.kattis.com/problems/mosaicbrowsing)

#### 6.1.4 Online FFT / NTT

- **ID:** `online_ntt` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/online_ntt
- **Templates (2):**
  - [NTT Online (D&C).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/NTT%20Online%20%28D%26C%29.cpp)
  - [NTT Online.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/NTT%20Online.cpp)
- **Resources (3):**
  - ★ [CDQ convolution (online FFT) generalization with Newton method By adamant,](https://codeforces.com/blog/entry/111399)
  - ★ [Online FFT Slides | Tanuj Khattar](https://tanujkhattar.wordpress.com/wp-content/uploads/2018/01/onlinefft1.pdf)
  - ★ [Relaxed Convolution | Atcoder Editorial](https://atcoder.jp/contests/abc315/editorial/6997)
- **Problems (8):**
  - `[M]` ★ [Colored Forests](https://csacademy.com/contest/round-24/task/colored-forests/)
  - `[M]` [Jetpack](https://csacademy.com/contest/round-9/task/jetpack/statement/)
  - `[M]` [Expected Number of Customers](https://www.codechef.com/COOK112A/problems/MMNN01)
  - `[M]` ★ [Graph Coloring (hard version)](https://codeforces.com/problemset/problem/1792/F2)
  - `[M]` ★ [Typical Convolution Problem](https://atcoder.jp/contests/abc315/tasks/abc315_h)
  - `[H]` [Kyoya and Train](https://codeforces.com/problemset/problem/553/E)
  - `[H]` [Bin](https://www.acmicpc.net/problem/18743)
  - `[H]` [Stroll](https://atcoder.jp/contests/abc213/tasks/abc213_h)

#### 6.1.5 Fast Walsh Hadamard Transform (FWHT) and its Variations

- **ID:** `fwht` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/fwht
- **Templates (3):**
  - [FWHT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/FWHT.cpp)
  - [FWHT in Ternary Base.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/FWHT%20in%20Ternary%20Base.cpp)
  - [FWHT in Any Base.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/FWHT%20in%20Any%20Base.cpp)
- **Resources (10):**
  - ★ [Fast Walsh-Hadamard Transform in Competitive Programming | Chengyuan Ma's Blog](https://danglingpointer.fun/2020/08/07/FWHT/)
  - ★ [Fast Walsh Hadamard Transforms and it's inner workings By upobir](https://codeforces.com/blog/entry/71899)
  - [Fast Fourier Transform and variations of it | by atatomir](https://csacademy.com/blog/fast-fourier-transform-and-variations-of-it)
  - [15. xor-, and-, or-convolutions | General ideas By adamant](https://codeforces.com/blog/entry/48417)
  - ★ [logical_convolutions.pdf | ivanzuki](https://github.com/IvanAli/logical-convolutions/blob/main/logical_convolutions.pdf)
  - ★ [OR Convolution for Common People By ko_osaga](https://codeforces.com/blog/entry/115438)
  - ★ [Intuitive Meaning of All Convolutions | Comment by pajenegod](https://codeforces.com/blog/entry/115438?#comment-1025876)
  - ★ [Generalized FWHT: How I realized I did not understand FWHT By errorgorn](https://codeforces.com/blog/entry/96003)
  - [Ternary FWHT](https://discuss.codechef.com/t/mdswin-editorial/44120)
  - [FWHT in Any Base](https://discuss.codechef.com/t/xortreeh-editorial/17019)
- **Problems (18):**
  - `[E]` ★ [Maxor](https://csacademy.com/contest/round-53/task/maxor/)
  - `[E]` ★ [And Closure](https://csacademy.com/contest/archive/task/and-closure/)
  - `[E]` ★ [XOR Path](https://vjudge.net/problem/UVA-13277)
  - `[E]` ★ [Random Nim Generator](https://csacademy.com/contest/archive/task/random_nim_generator/statement/)
  - `[M]` [Tokens on a grid](https://csacademy.com/contest/archive/task/token-grid/statement/)
  - `[M]` ★ [Xor Spanning Tree](https://codeforces.com/problemset/problem/1218/D)
  - `[M]` ★ [Sum the Fibonacci](https://codeforces.com/problemset/problem/914/G)
  - `[M]` [Flip Row or Col](https://atcoder.jp/contests/abc396/tasks/abc396_g)
  - `[H]` [Games](https://codeforces.com/gym/102978/problem/G)
  - `[H]` ★ [United in Stormwind](https://codeforces.com/gym/103202/problem/M)
  - `[H]` ★ [Deck-Building Game](https://codeforces.com/contest/1906/problem/K)
  - `[H]` [黎明前的巧克力](https://uoj.ac/problem/310)
  - `[H]` ★ [Winning Ways](https://www.codechef.com/NOV19A/problems/MDSWIN)
  - `[H]` ★ [Chef and Horcrux](https://www.codechef.com/problems/XORTREEH)
  - `[H]` ★ [Nim Counting](https://atcoder.jp/contests/abc212/tasks/abc212_h)
  - `[H]` [18. Security Camera](https://atcoder.jp/contests/abc220/tasks/abc220_h)
  - `[VH]` ★ [Beautiful XOR Problem](https://codeforces.com/gym/104479/problem/B)
  - `[VH]` ★ [Sum of (XOR^K or 0)](https://atcoder.jp/contests/abc367/tasks/abc367_g)

#### 6.1.6 GCD Convolution

- **ID:** `gcd_convolution` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gcd_convolution
- **Templates (1):**
  - [153821](https://judge.yosupo.jp/submission/153821)
- **Resources (2):**
  - ★ [\[Tutorial\] GCD Convolution By szaranczuk](https://codeforces.com/blog/entry/112346)
  - ★ [\[Tutorial\] Zeta, Mobius Transform to AND, OR, GCD Convolution By jinhan814](https://codeforces.com/blog/entry/119082)
- **Problems (3):**
  - `[E]` ★ [Gcd Convolution](https://judge.yosupo.jp/problem/gcd_convolution)
  - `[M]` ★ [Exclusive Multiplication](https://codeforces.com/gym/103688/problem/E)
  - `[M]` ★ [Yet Another GCD Problem](https://www.codechef.com/CDUN2022/problems/YETGCD)

#### 6.1.7 LCM Convolution

- **ID:** `lcm_convolution` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lcm_convolution
- **Templates (1):**
  - [153819](https://judge.yosupo.jp/submission/153819)
- **Resources (2):**
  - [\[Tutorial\] GCD Convolution By szaranczuk](https://codeforces.com/blog/entry/112346)
  - ★ [\[Tutorial\] Zeta, Mobius Transform to AND, OR, GCD Convolution By jinhan814](https://codeforces.com/blog/entry/119082)
- **Problems (1):**
  - `[E]` ★ [Lcm Convolution](https://judge.yosupo.jp/problem/lcm_convolution)

### 6.2 Polynomial

**Subcategory ID:** `polynomial` · **Topics:** 22

#### 6.2.1 Generating Functions

- **ID:** `generating_functions` · **Difficulty:** Hard · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/generating_functions
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (7):**
  - ★ [\[Tutorial\] Generating Functions in Competitive Programming (Part 1) By zscoder](https://codeforces.com/blog/entry/77468)
  - ★ [Operations on polynomials and series | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html)
  - ★ [\[Tutorial\] Generating Functions in Competitive Programming (Part 2) By zscoder](https://codeforces.com/blog/entry/77551)
  - [A problem collection of ODE and differential technique By jqdai0815](https://codeforces.com/blog/entry/76447)
  - [Exponential formula | Wiki](https://en.wikipedia.org/wiki/Exponential_formula)
  - ★ [Useful substitutions with generating functions By adamant](https://codeforces.com/blog/entry/117237)
  - [Solution to ARC154F Dice Game -- Generating functions and polynomials By Bring](https://codeforces.com/blog/entry/112550)
- **Problems (20):**
  - `[M]` [Yet Another Number Sequence](https://codeforces.com/contest/392/problem/C)
  - `[H]` ★ [K-Inversion Permutations](https://www.hackerrank.com/contests/101hack43/challenges/k-inversion-permutations/problem)
  - `[H]` ★ [Many Easy Problems](https://atcoder.jp/contests/agc005/tasks/agc005_f)
  - `[H]` ★ [Ppeerrffeecctt Ssqquuaarreess](https://www.codechef.com/PRACTICE/problems/PERFSQRS)
  - `[H]` ★ [Weird Product](https://www.codechef.com/JULY20A/problems/WEIRDMUL)
  - `[H]` ★ [Transforming Sequence](https://codeforces.com/problemset/problem/623/E)
  - `[H]` ★ [Chef and Rainbow Road](https://www.codechef.com/problems/RNBWROAD)
  - `[H]` ★ [Dice Game](https://atcoder.jp/contests/arc154/tasks/arc154_f)
  - `[H]` ★ [The Child and Binary Tree](https://codeforces.com/problemset/problem/438/E)
  - `[H]` [链式反应](https://uoj.ac/problem/50)
  - `[H]` ★ [Q 的序列](https://loj.ac/p/6703)
  - `[H]` ★ [Simple nCr](https://codeforces.com/gym/280379/problem/A)
  - `[H]` [O Andar do Trêbado](https://codeforces.com/group/YgJmumGtHD/contest/446227/problem/I)
  - `[VH]` ★ [Sum of Fibonacci Sequence](https://atcoder.jp/contests/s8pc-3/tasks/s8pc_3_g)
  - `[VH]` [Quasi-Polynomial Sum](https://www.codechef.com/DEC12/problems/QPOLYSUM)
  - `[VH]` [Slime and Sequences (Hard Version)](https://codeforces.com/contest/1349/problem/F2)
  - `[VH]` ★ [Simple Counting](https://codeforces.com/gym/280379/problem/B)
  - `[VH]` ★ [Rhyme](https://loj.ac/p/6696)
  - `[VH]` [通用测评号](https://uoj.ac/contest/51/problem/514)
  - `[VH]` [珍珠](https://loj.ac/p/3120)

#### 6.2.2 Polynomial Inverse

- **ID:** `polynomial_inverse` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_inverse
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [Inverse series | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#inverse-series)
- **Problems (4):**
  - `[E]` ★ [Inv of Formal Power Series](https://judge.yosupo.jp/problem/inv_of_formal_power_series)
  - `[H]` ★ [The Child and Binary Tree](https://codeforces.com/problemset/problem/438/E)
  - `[H]` [Chef and the Combination Lock](https://www.codechef.com/problems/CHEFSSM)
  - `[H]` [Inv of Formal Power Series (Sparse)](https://judge.yosupo.jp/problem/inv_of_formal_power_series_sparse)

#### 6.2.3 Polynomial Exp

- **ID:** `polynomial_exp` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_exp
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [Exponent | CP Algorithm](https://cp-algorithms.com/algebra/polynomial.html#exponent)
- **Problems (4):**
  - `[E]` ★ [Exp of Formal Power Series](https://judge.yosupo.jp/problem/exp_of_formal_power_series)
  - `[M]` ★ [Perfect Partitions](https://www.codechef.com/problems/PPARTS)
  - `[H]` ★ [K-Inversion Permutations](https://www.hackerrank.com/contests/101hack43/challenges/k-inversion-permutations/problem)
  - `[H]` [Exp of Formal Power Series (Sparse)](https://judge.yosupo.jp/problem/exp_of_formal_power_series_sparse)

#### 6.2.4 Polynomial Log

- **ID:** `polynomial_log` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_log
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [Logarithm | CP Algorithm](https://cp-algorithms.com/algebra/polynomial.html#logarithm)
- **Problems (4):**
  - `[E]` ★ [Log of Formal Power Series](https://judge.yosupo.jp/problem/log_of_formal_power_series)
  - `[M]` ★ [Perfect Partitions](https://www.codechef.com/problems/PPARTS)
  - `[H]` ★ [K-Inversion Permutations](https://www.hackerrank.com/contests/101hack43/challenges/k-inversion-permutations/problem)
  - `[H]` [Log of Formal Power Series (Sparse)](https://judge.yosupo.jp/problem/log_of_formal_power_series_sparse)

#### 6.2.5 Polynomial Pow

- **ID:** `polynomial_pow` · **Difficulty:** Hard · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_pow
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [k-th power | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#k-th-power)
- **Problems (3):**
  - `[E]` ★ [Pow of Formal Power Series](https://judge.yosupo.jp/problem/pow_of_formal_power_series)
  - `[E]` ★ [Lucky Tickets](https://codeforces.com/contest/1096/problem/G)
  - `[M]` [Pow of Formal Power Series (Sparse](https://judge.yosupo.jp/problem/pow_of_formal_power_series_sparse)

#### 6.2.6 Polynomial Sqrt

- **ID:** `polynomial_sqrt` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_sqrt
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Problems (4):**
  - `[E]` ★ [Sqrt of Formal Power Series](https://judge.yosupo.jp/problem/sqrt_of_formal_power_series)
  - `[M]` ★ [Perfect Strings](https://codedrills.io/contests/icpc-asia-west-continent-final-contest-2022/problems/perfect-strings)
  - `[H]` ★ [The Child and Binary Tree](https://codeforces.com/problemset/problem/438/E)
  - `[H]` [Sqrt of Formal Power Series (Sparse)](https://judge.yosupo.jp/problem/sqrt_of_formal_power_series_sparse)

#### 6.2.7 Polynomial Composition

- **ID:** `polynomial_composition` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_composition
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [Fast polynomial composition By adamant](https://codeforces.com/blog/entry/101909)
- **Problems (2):**
  - `[E]` ★ [Composition of Formal Power Series](https://judge.yosupo.jp/problem/composition_of_formal_power_series)
  - `[M]` [Compositional Inverse of Formal Power Series](https://judge.yosupo.jp/problem/compositional_inverse_of_formal_power_series)

#### 6.2.8 Multipoint Evaluation

- **ID:** `multipoint_evaluation` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/multipoint_evaluation
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (2):**
  - [Multi-point Evaluation | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#multi-point-evaluation)
  - [Evaluation and interpolation on geometric progression By adamant](https://codeforces.com/blog/entry/118018)
- **Problems (6):**
  - `[E]` ★ [Multipoint Evaluation](https://judge.yosupo.jp/problem/multipoint_evaluation)
  - `[E]` ★ [Evaluate the polynomial](https://www.codechef.com/problems/POLYEVAL)
  - `[M]` [Chef and Equations](https://www.codechef.com/NOV18A/problems/CHEFEQUA)
  - `[H]` ★ [Chef and Rainbow Road](https://www.codechef.com/problems/RNBWROAD)
  - `[H]` ★ [Weird Product](https://www.codechef.com/JULY20A/problems/WEIRDMUL)
  - `[H]` [Multipoint Evaluation (Geometric Sequence)](https://judge.yosupo.jp/problem/multipoint_evaluation_on_geometric_sequence)

#### 6.2.9 Chirp Z Transform

- **ID:** `chirp_z_transform` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/chirp_z_transform
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (2):**
  - [Chirp-z Transform | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#chirp-z-transform)
  - [\[Tutorial\] Generalized Chirp Z-Transform By box](https://codeforces.com/blog/entry/83532)
- **Problems (4):**
  - `[E]` ★ [Chirp Z-Transform (mod 998244353)](https://www.luogu.com.cn/problem/P6800)
  - `[E]` ★ [Chirp Z-Transform (mod 10^9 + 7)](https://www.luogu.com.cn/problem/P6828)
  - `[H]` [Cyclic Cipher](https://codeforces.com/contest/901/problem/E)
  - `[H]` [Heidi Learns Hashing (Hard)](https://codeforces.com/contest/1184/problem/A3)

#### 6.2.10 Polynomial Interpolation

- **ID:** `polynomial_interpolation` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_interpolation
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (3):**
  - [Interpolation | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#interpolation)
  - [Evaluation and interpolation on geometric progression By adamant](https://codeforces.com/blog/entry/118018)
  - [\[TUTORIAL\] Basic Lagrange Interpolation pt. 2 By grhkm](https://codeforces.com/blog/entry/94143)
- **Problems (3):**
  - `[E]` ★ [Polynomial Interpolation](https://judge.yosupo.jp/problem/polynomial_interpolation)
  - `[H]` [Polynomial Interpolation (Geometric Sequence)](https://judge.yosupo.jp/problem/polynomial_interpolation_on_geometric_sequence)
  - `[H]` ★ [Weird Sum](https://www.codechef.com/problems/WRDSUM)

#### 6.2.11 Polynomial Shift

- **ID:** `polynomial_shift` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_shift
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [OGFs, EGFs, differentiation and Taylor shifts By adamant](https://codeforces.com/blog/entry/99646)
- **Problems (2):**
  - `[E]` ★ [Polynomial Taylor Shift](https://judge.yosupo.jp/problem/polynomial_taylor_shift)
  - `[M]` ★ [Binomial Fever](https://www.codechef.com/problems/BINOFEV)

#### 6.2.12 Shift of Sampling Points of Polynomial

- **ID:** `polynomial_shift_sampling_points` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_shift_sampling_points
- **Resources (1):**
  - [Shift of polynomial sampling points By adamant](https://codeforces.com/blog/entry/115696)
- **Problems (1):**
  - `[E]` ★ [Shift of Sampling Points of Polynomial](https://judge.yosupo.jp/problem/shift_of_sampling_points_of_polynomial)

#### 6.2.13 Polyomial Division and Remainder

- **ID:** `polynomial_division_and_remainder` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_division_and_remainder
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (1):**
  - [Euclidean division | CP Algorithm](https://cp-algorithms.com/algebra/polynomial.html#euclidean-division)
- **Problems (2):**
  - `[M]` ★ [Division of Polynomials](https://judge.yosupo.jp/problem/division_of_polynomials)
  - `[H]` [Basis Change](https://codeforces.com/gym/102129/problem/D)

#### 6.2.14 Polynomial Roots Under a Modulo

- **ID:** `polynomial_roots_under_modulo` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_roots_under_modulo
- **Resources (2):**
  - ★ [A bit more of general ideas By adamant](https://codeforces.com/blog/entry/104466)
  - [\[問題案\] mod p equation | Discussion](https://github.com/yosupo06/library-checker-problems/issues/924)
- **Problems (2):**
  - `[M]` ★ [Polynomial Root Finding (Mod 998244353)](https://judge.yosupo.jp/problem/polynomial_root_finding)
  - `[H]` [Irrational Root](https://www.codechef.com/problems/APRPS)

#### 6.2.15 Resultant of Two Polynomials and Half-GCD Algorithm

- **ID:** `resultant_of_two_polynomials` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/resultant_of_two_polynomials
- **Templates (1):**
  - [Polynomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial.cpp)
- **Resources (2):**
  - [Resultant and Half-GCD | CP Algorithms](https://cp-algorithms.com/algebra/polynomial.html#resultant)
  - ★ [Half-GCD algorithm By adamant](https://codeforces.com/blog/entry/101850)
- **Problems (2):**
  - `[M]` ★ [Find Linear Recurrence](https://judge.yosupo.jp/problem/find_linear_recurrence)
  - `[H]` [Inv of Polynomials](https://judge.yosupo.jp/problem/inv_of_polynomials)

#### 6.2.16 Lagrange Interpolation

- **ID:** `lagrange_interpolation` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/lagrange_interpolation
- **Templates (2):**
  - [Lagrange Interpolation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Lagrange%20Interpolation.cpp)
  - [Lagrange Interpolation with Polynomial Extraction.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Lagrange%20Interpolation%20with%20Polynomial%20Extraction.cpp)
- **Resources (3):**
  - ★ [\[TUTORIAL\] Basic Lagrange Interpolation By grhkm](https://codeforces.com/blog/entry/82953)
  - [The Application of Lagrange Interpolation in Mathematics By luosw](https://codeforces.com/blog/entry/85814)
  - [Lagrange interpolation and partial fraction decomposition By adamant](https://codeforces.com/blog/entry/98386)
- **Problems (17):**
  - `[E]` ★ [The Sum of the k-th Powers](https://codeforces.com/problemset/problem/622/F)
  - `[E]` [A Summatory (HARD)](https://www.spoj.com/problems/ASUMHARD/)
  - `[M]` ★ [Count Arrays](https://www.codechef.com/problems/COUNTIT)
  - `[M]` ★ [Some Sums](https://www.spoj.com/problems/SOMESUMS/)
  - `[M]` [The Boss on Mars](http://acm.hdu.edu.cn/showproblem.php?pid=4059)
  - `[M]` [A Summatory (Extreme)](https://www.spoj.com/problems/ASUMEXTR/)
  - `[M]` [見たことのない多項式](https://atcoder.jp/contests/arc033/tasks/arc033_4)
  - `[M]` ★ [Cowmpany Cowmpensation](https://codeforces.com/contest/995/problem/F)
  - `[M]` ★ [Battle Of The Bastards - Kings Vs Rooks](https://www.spoj.com/problems/BATTLECRY/)
  - `[M]` ★ [Guess the Root](https://codeforces.com/problemset/problem/1155/E)
  - `[H]` ★ [GCD of the Submasks](https://www.codechef.com/LTIME84A/problems/GCDMASK)
  - `[H]` [Power Sum](https://www.spoj.com/problems/PWSUMC/)
  - `[H]` ★ [Euler Totient Function Extended](https://www.codechef.com/problems/XETF)
  - `[H]` [Chef and the Combination Lock](https://www.codechef.com/problems/CHEFSSM)
  - `[H]` ★ [calc](https://www.luogu.com.cn/problem/P4463)
  - `[VH]` ★ [Counting Good Arrays](https://vjudge.net/problem/HDU-7217)
  - `[VH]` ★ [A Lazy Statement](https://toph.co/p/lots-of-cubes)

#### 6.2.17 [Problem] Sum of r^i * poly(i)

- **ID:** `polynomial_sum` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_sum
- **Templates (1):**
  - [Polynomial Sum.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial%20Sum.cpp)
- **Resources (1):**
  - [Discussion on library checker](https://github.com/yosupo06/library-checker-problems/issues/98)
- **Problems (1):**
  - `[E]` ★ [Sum of exponential times polynomial](https://judge.yosupo.jp/problem/sum_of_exponential_times_polynomial)

#### 6.2.18 Polynomial with Binomial Coefficients

- **ID:** `polynomial_with_binomial_coefficients` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_with_binomial_coefficients
- **Templates (1):**
  - [Polynomial with Binomial Coefficients.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial%20with%20Binomial%20Coefficients.cpp)
- **Resources (1):**
  - [Binomial coefficients as a basis for the space of polynomials](https://en.wikipedia.org/wiki/Binomial_coefficient#Binomial_coefficients_as_a_basis_for_the_space_of_polynomials)
- **Problems (1):**
  - `[E]` ★ [The Sum of the k-th Powers](https://codeforces.com/problemset/problem/622/F)

#### 6.2.19 Subset Sum Problem using Generating Functions

- **ID:** `subset_sum_problem_using_generating_functions` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/subset_sum_problem_using_generating_functions
- **Templates (1):**
  - [Subset Sum Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Subset%20Sum%20Problem.cpp)
- **Resources (1):**
  - [PPARTS - Editorial](https://discuss.codechef.com/t/pparts-editorial/68595)
- **Problems (2):**
  - `[E]` ★ [Subset Sum](https://judge.yosupo.jp/problem/sharp_p_subset_sum)
  - `[M]` ★ [Perfect Partitions](https://www.codechef.com/problems/PPARTS)

#### 6.2.20 Polynomial Factorization of (x^n - 1) and Cyclotomic Polynomials

- **ID:** `polynomial_factorization_of_xn_minus_1` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_factorization_of_xn_minus_1
- **Templates (1):**
  - [Polynomial Factorization.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Polynomial%20Factorization.cpp)
- **Resources (1):**
  - [Cyclotomic polynomial | Wiki](https://en.wikipedia.org/wiki/Cyclotomic_polynomial)
- **Problems (1):**
  - `[M]` ★ [Call It What You Want](https://codeforces.com/gym/102114/problem/C)

#### 6.2.21 Schwartz–Zippel Lemma

- **ID:** `schwartz_zippel_lemma` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/schwartz_zippel_lemma
- **Resources (2):**
  - [Schwartz–Zippel lemma | Wiki](https://en.wikipedia.org/wiki/Schwartz%E2%80%93Zippel_lemma)
  - [Hashing and Probability of Collision | rng_58](https://rng-58.blogspot.com/2017/02/hashing-and-probability-of-collision.html)
- **Problems (1):**
  - `[H]` [Chef and Lost Story](https://www.codechef.com/SEPT18A/problems/CHEFLST)

#### 6.2.22 Lagrange Inversion Theorem

- **ID:** `lagrange_inversion_theorem` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lagrange_inversion_theorem
- **Resources (4):**
  - ★ [Lagrange inversion theorem By adamant](https://codeforces.com/blog/entry/104184)
  - ★ [Lagrange Inversion Formula | \[Tutorial\] Generating Functions in Competitive Programming (Part 2) By zscoder](https://codeforces.com/blog/entry/77551)
  - [Lagrange inversion theorem | wiki](https://en.wikipedia.org/wiki/Lagrange_inversion_theorem)
  - [Editorial of Problem H - Beautiful Binary Tree](https://atcoder.jp/contests/abc222/editorial/2765)
- **Problems (2):**
  - `[H]` [Beautiful Binary Tree](https://atcoder.jp/contests/abc222/tasks/abc222_h)
  - `[VH]` [Slime and Sequences (Hard Version)](https://codeforces.com/contest/1349/problem/F2)

### 6.3 Matrices

**Subcategory ID:** `matrices` · **Topics:** 6

#### 6.3.1 Matrix Exponentiation

- **ID:** `matrix_exponentiation` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/matrix_exponentiation
- **Templates (2):**
  - [Matrix Exponentiation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Matrix%20Exponentiation.cpp)
  - [Matrix Exponentiation With Polynomial Coefficients.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Matrix%20Exponentiation%20With%20Polynomial%20Coefficients.cpp)
- **Resources (8):**
  - ★ [Matrix Exponentiation tutorial + training contest By Errichto](https://codeforces.com/blog/entry/80195)
  - ★ [Matrix Exponentiation | I, ME AND MYSELF !!!](https://zobayer.blogspot.com/2010/11/matrix-exponentiation.html)
  - ★ [\[Tutorial\]A Complete Guide on Matrix Exponentiation By lazyneuron](https://codeforces.com/blog/entry/67776)
  - ★ [Cool tricks using Matrix Exponential By tweety](https://codeforces.com/blog/entry/43225)
  - [\[Discussion\] Recurrence using Matrix exponentiation By allrounder](https://codeforces.com/blog/entry/19046)
  - [Min-plus matrix multiplication | Wiki](https://en.wikipedia.org/wiki/Min-plus_matrix_multiplication)
  - [Matrix Exponentiation Guide By bfs.07](https://codeforces.com/blog/entry/108615)
  - [Matrix Power Applications ppt | Mostafa](https://github.com/mostafa-saad/ArabicCompetitiveProgramming/blob/master/04%20Math/Algorithms_Number_Theory_06_Matrix_Power_Applications.pptx)
- **Problems (44):**
  - `[E]` ★ [Matrix Product](https://judge.yosupo.jp/problem/matrix_product)
  - `[E]` ★ [Pow of Matrix](https://judge.yosupo.jp/problem/pow_of_matrix)
  - `[E]` [Modular Fibonacci](https://vjudge.net/problem/UVA-10229)
  - `[E]` ★ [Random Mood](https://codeforces.com/gym/102644/problem/A)
  - `[E]` ★ [Recurrences](https://vjudge.net/problem/UVA-10870)
  - `[E]` [Fantastic Sequence](https://vjudge.net/problem/UVA-10754)
  - `[E]` [Experienced Endeavour](https://vjudge.net/problem/UVA-11551)
  - `[E]` [Sum of products](https://www.spoj.com/problems/SUMMUL/)
  - `[E]` ★ [String Mood](https://codeforces.com/gym/102644/problem/B)
  - `[E]` ★ [Graph Paths I](https://cses.fi/problemset/task/1723)
  - `[E]` ★ [Graph Paths II](https://cses.fi/problemset/task/1724)
  - `[E]` ★ [Sum of Tetranacci numbers](https://www.spoj.com/problems/TETRAHRD/)
  - `[E]` [Recursive Sequence](https://www.spoj.com/problems/SEQ/)
  - `[E]` [Krypton Number System](https://vjudge.net/problem/UVA-11651)
  - `[E]` [Geometric Progression](https://atcoder.jp/contests/abc293/tasks/abc293_e)
  - `[M]` ★ [Fibonacci Numbers](https://cses.fi/problemset/task/1722)
  - `[M]` ★ [Lunar New Year and a Recursive Sequence](https://codeforces.com/contest/1106/problem/F)
  - `[M]` ★ [Fibonacci Power Sum](https://www.spoj.com/problems/FIBPWSUM/)
  - `[M]` ★ [R Numbers](https://www.spoj.com/problems/ITRIX12E/)
  - `[M]` [Decoding Genome](https://codeforces.com/gym/316783/problem/B)
  - `[M]` [Magic Gems](https://codeforces.com/gym/316783/problem/C)
  - `[M]` ★ [Wet Shark and Blocks](https://codeforces.com/gym/316783/problem/D)
  - `[M]` ★ [Product Oriented Recurrence](https://codeforces.com/gym/316783/problem/E)
  - `[M]` ★ [Help Milo!](https://www.codechef.com/problems/HLPMIL)
  - `[M]` [Okabe and El Psy Kongroo](https://codeforces.com/problemset/problem/821/E)
  - `[M]` [Blocks for kids](https://www.spoj.com/problems/PBOARD/)
  - `[M]` ★ [Nice Patterns Strike Back](https://codeforces.com/gym/100199/problem/E)
  - `[M]` ★ [Tiles](https://lightoj.com/problem/tiles)
  - `[M]` ★ [Unlucky Strings](https://lightoj.com/problem/unlucky-strings)
  - `[M]` ★ [Kings in Chessboard](https://lightoj.com/problem/kings-in-chessboard)
  - `[M]` ★ [ABCD Strings](https://www.hackerearth.com/problem/algorithm/abcd-strings/)
  - `[M]` ★ [Smile House](https://codeforces.com/contest/147/problem/B)
  - `[M]` ★ [Knight Paths](https://codeforces.com/gym/102644/problem/E)
  - `[M]` ★ [Recurrence With Square](https://codeforces.com/gym/102644/problem/G)
  - `[M]` [String Mood Updates](https://codeforces.com/gym/102644/problem/H)
  - `[M]` ★ [Count Paths Queries](https://codeforces.com/gym/102644/problem/I)
  - `[M]` [Flibonakki](https://www.spoj.com/problems/FLIB/)
  - `[M]` [Bacterial Sampling](https://codeforces.com/gym/105164/problem/B)
  - `[M]` ★ [Xor-sequences](https://codeforces.com/contest/691/problem/E)
  - `[M]` ★ [Sasha and Array](https://codeforces.com/problemset/problem/718/C)
  - `[M]` [Walk](https://atcoder.jp/contests/dp/tasks/dp_r)
  - `[M]` [Yet Another Number Sequence](https://codeforces.com/contest/392/problem/C)
  - `[H]` ★ [PolandBall and Many Other Balls](https://codeforces.com/problemset/problem/755/G)
  - `[H]` [Paimon Segment Tree](https://codeforces.com/gym/103470/problem/E)

#### 6.3.2 Permanent of a Matrix

- **ID:** `permanent_of_a_matrix` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/permanent_of_a_matrix
- **Templates (1):**
  - [Permanent of a Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Permanent%20of%20a%20Matrix.cpp)
- **Resources (2):**
  - ★ [Permanent (mathematics) | Wiki](https://en.wikipedia.org/wiki/Permanent_%28mathematics%29)
  - ★ [Ryser formula | Wiki](https://en.wikipedia.org/wiki/Computing_the_permanent#Ryser_formula)
- **Problems (1):**
  - `[VH]` ★ [Permanent](https://codeforces.com/problemset/problem/468/E)

#### 6.3.3 Freivald's Algorithm

- **ID:** `freivalds_algorithm` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/freivalds_algorithm
- **Templates (1):**
  - [Freivalds Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Freivalds%20Algorithm.cpp)
- **Resources (2):**
  - ★ [Freivalds' algorithm | Wiki](https://en.wikipedia.org/wiki/Freivalds%27_algorithm)
  - [Freivalds’ algorithm for verifying Matrix Multiplication](https://iq.opengenus.org/freivalds-algorithm/)
- **Problems (1):**
  - `[E]` ★ [Matrix God](https://codeforces.com/gym/101341/problem/I)

#### 6.3.4 Vandermonde Matrix

- **ID:** `vandermonde_matrix` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/vandermonde_matrix
- **Templates (1):**
  - [Vandermonde Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Vandermonde%20Matrix.cpp)
- **Resources (2):**
  - ★ [Vandermonde matrix | Wiki](https://en.wikipedia.org/wiki/Vandermonde_matrix)
  - [About Vandermonde Determinant By happyguy656](https://codeforces.com/blog/entry/98824)
- **Problems (1):**
  - `[M]` ★ [Lopymonials](https://www.codechef.com/problems/SATA05)

#### 6.3.5 Hafnian of a Matrix / Number of Perfect Matchings in a Graph

- **ID:** `hafnian_of_a_matrix` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/hafnian_of_a_matrix
- **Templates (1):**
  - [Hafnian of a Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Hafnian%20of%20a%20Matrix.cpp)
- **Resources (1):**
  - [Counting perfect matchings as fast as Ryser](https://dl.acm.org/doi/abs/10.5555/2095116.2095189)
- **Problems (1):**
  - `[E]` ★ [Hafnian of Matrix](https://judge.yosupo.jp/problem/hafnian_of_matrix)

#### 6.3.6 Frobenius Form of a Matrix and Fast Matrix Power

- **ID:** `frobenius_form_of_a_matrix` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/frobenius_form_of_a_matrix
- **Templates (1):**
  - [183810](https://judge.yosupo.jp/submission/183810)
- **Resources (1):**
  - [A (Somehow) Simple (Randomized) Algorithm for Frobenius Form of a Matrix By MyBotDear](https://codeforces.com/blog/entry/124815)
- **Problems (1):**
  - `[E]` ★ [Pow of Matrix](https://judge.yosupo.jp/problem/pow_of_matrix)

### 6.4 Linear Recurrence

**Subcategory ID:** `linear_recurrence` · **Topics:** 8

#### 6.4.1 Linear Recurrence Relations

- **ID:** `linear_recurrence_relations` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_recurrence_relations
- **Resources (3):**
  - ★ [Solving Linear Recurrence Relations](https://www.eecs.yorku.ca/course_archive/2008-09/S/1019/Website_files/21-linear-recurrences.pdf)
  - [Linear Recurrence Relations | Brilliant](https://brilliant.org/wiki/linear-recurrence-relations/)
  - [Linear recurrence with constant coefficients | Wiki](https://en.wikipedia.org/wiki/Linear_recurrence_with_constant_coefficients)
- **Problems (1):**
  - `[M]` ★ [Fibonacci Numbers](https://cses.fi/problemset/task/1722)

#### 6.4.2 Linear Recurrence using Cayley-Hamilton Theorem in O(N^2 log K)

- **ID:** `linear_recurrence_using_cayley_hamilton_theorem` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_recurrence_using_cayley_hamilton_theorem
- **Templates (1):**
  - [Linear Recurrence.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Linear%20Recurrence.cpp)
- **Resources (1):**
  - ★ [Linear recurrence using Cayley-Hamilton theorem | djdolls](https://discuss.codechef.com/t/linear-recurrence-using-cayley-hamilton-theorem/6776)
- **Problems (3):**
  - `[M]` [Magic Gems](https://codeforces.com/gym/316783/problem/C)
  - `[H]` [Mr. Kitayuta's Gift](https://codeforces.com/contest/506/problem/E)
  - `[H]` [Costly Strings](https://www.hackerearth.com/problem/approximate/costly-strings/)

#### 6.4.3 Linear Recurrence using Generating Functions in O(N log N log K)

- **ID:** `linear_recurrence_using_generating_functions` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_recurrence_using_generating_functions
- **Templates (1):**
  - [Linear Recurrence Fastest.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Linear%20Recurrence%20Fastest.cpp)
- **Resources (5):**
  - ★ [\[Tutorial\] Solving Linear Recurrences with various methods, Including O(N logN logK) using FFT By demoralizer](https://codeforces.com/blog/entry/97627)
  - [\[Tutorial\] Easy Introduction to Kitamasa Method By Justice_Hui](https://codeforces.com/blog/entry/88760)
  - ★ [\[tutorial\] Bostan-Mori, an elegant algorithm to compute k-th term of linear recurrence in O(dlgdlgk) By Misuki](https://codeforces.com/blog/entry/111862)
  - ★ [On linear recurrences and the math behind them By adamant](https://codeforces.com/blog/entry/100158)
  - [RNG - Editorial](https://discuss.codechef.com/t/rng-editorial/10068)
- **Problems (3):**
  - `[E]` ★ [Kth term of Linearly Recurrent Sequence](https://judge.yosupo.jp/problem/kth_term_of_linearly_recurrent_sequence)
  - `[M]` ★ [Random Number Generator](https://www.codechef.com/problems/RNG)
  - `[VH]` ★ [Tenkei90's Last Problem](https://atcoder.jp/contests/typical90/tasks/typical90_cl)

#### 6.4.4 Linear Recurrence with Polynomial Coefficients

- **ID:** `linear_recurrence_with_polynomial_coefficients` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_recurrence_with_polynomial_coefficients
- **Templates (1):**
  - [Linear Recurrence With Polynomial Coefficients.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Linear%20Recurrence%20With%20Polynomial%20Coefficients.cpp)
- **Resources (1):**
  - [Blog by min_25](https://min-25.hatenablog.com/entry/2018/05/10/212805)

#### 6.4.5 Linear Recurrence on Matrices

- **ID:** `linear_recurrence_on_matrices` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_recurrence_on_matrices
- **Resources (1):**
  - ★ [PANIC - Editorial | DSAAcademy — Shahjalal Shohag](https://discuss.codechef.com/t/panic-editorial/80145)
- **Problems (1):**
  - `[H]` ★ [Panic! at the Disco](https://www.codechef.com/problems/PANIC)

#### 6.4.6 Generating Function of a Linear Recurrence

- **ID:** `generating_function_of_a_linear_recurrence` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/generating_function_of_a_linear_recurrence
- **Templates (1):**
  - [Generating Function of a Linear Recurrence.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Generating%20Function%20of%20a%20Linear%20Recurrence.cpp)
- **Resources (2):**
  - ★ [GENERATING FUNCTIONS AND RECURRENCE RELATIONS](https://www.math.cmu.edu/~af1p/Teaching/Combinatorics/Slides/Generating-Functions.pdf)
  - [Linear Recurrences and Rational Generating Functions](https://websites.umich.edu/~speyer/LinearRecurrences.pdf)
- **Problems (2):**
  - `[M]` ★ [Perfect Strings](https://codedrills.io/contests/icpc-asia-west-continent-final-contest-2022/problems/perfect-strings)
  - `[H]` ★ [Expected Value](https://codeforces.com/gym/102268/problem/E)

#### 6.4.7 Berlekamp Massey

- **ID:** `berlekamp_messey` · **Difficulty:** Hard · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/berlekamp_messey
- **Templates (1):**
  - [BerleKamp Massey.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/BerleKamp%20Massey.cpp)
- **Resources (3):**
  - ★ [Trivialize Linear Recurrence Problems with Berlekamp-Massey! | mzhang2021](https://mzhang2021.github.io/cp-blog/berlekamp-massey/)
  - ★ [Linear Recurrence and Berlekamp-Massey Algorithm By TLE](https://codeforces.com/blog/entry/61306)
  - [Recovering a linear recurrence with the extended Euclidean algorithm By adamant](https://codeforces.com/blog/entry/101628)
- **Problems (14):**
  - `[M]` ★ [Find Linear Recurrence](https://judge.yosupo.jp/problem/find_linear_recurrence)
  - `[M]` ★ [R Numbers](https://www.spoj.com/problems/ITRIX12E/)
  - `[M]` [Yet Another Number Sequence](https://codeforces.com/contest/392/problem/C)
  - `[M]` ★ [Fibonacci Power Sum](https://www.spoj.com/problems/FIBPWSUM/)
  - `[M]` [Even Odd Partition](https://www.codechef.com/JULY21A/problems/PARTN01)
  - `[M]` [A Way Out](https://www.codechef.com/problems/REC20F)
  - `[M]` ★ [Wet Shark and Blocks](https://codeforces.com/gym/316783/problem/D)
  - `[M]` ★ [Recurrence With Square](https://codeforces.com/gym/102644/problem/G)
  - `[M]` ★ [IFibonacci Power Sum](https://codeforces.com/gym/102141/problem/I)
  - `[H]` [Cube](https://atcoder.jp/contests/abc198/tasks/abc198_f)
  - `[H]` [Mr. Kitayuta's Gift](https://codeforces.com/contest/506/problem/E)
  - `[H]` ★ [Expected Value](https://codeforces.com/gym/102268/problem/E)
  - `[H]` ★ [Panic! at the Disco](https://www.codechef.com/problems/PANIC)
  - `[H]` [完美的旅行](https://loj.ac/p/2463)

#### 6.4.8 Reeds-Sloane Algorithm

- **ID:** `reeds_sloane_algorithm` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/reeds_sloane_algorithm
- **Templates (1):**
  - [Reeds Sloane Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Reeds%20Sloane%20Algorithm.cpp)
- **Resources (2):**
  - [Comment Thread](https://codeforces.com/blog/entry/61306?#comment-452367)
  - [Shift Register Synthesis (Modulo m ) | Paper by Reeds and Sloane](https://www.researchgate.net/publication/220616688_Shift_Register_Synthesis_Modulo_m)
- **Problems (2):**
  - `[E]` ★ [Find Linear Recurrence](https://www.spoj.com/problems/FINDLR/)
  - `[H]` [Travelling Knight 2](https://www.spoj.com/problems/KN2/)

### 6.5 Linear Algebra

**Subcategory ID:** `linear_algebra` · **Topics:** 18

#### 6.5.1 Gaussian Elimination

- **ID:** `gaussian_elimination` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/gaussian_elimination
- **Templates (2):**
  - [Gaussian Elimination.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Gaussian%20Elimination.cpp)
  - [Gaussian Elimination Modular.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Gaussian%20Elimination%20Modular.cpp)
- **Resources (5):**
  - ★ [Math 2331 - 17040: Linear Algebra | Dr. Jiwen He](https://www.math.uh.edu/~jiwenhe/math2331/index.htm)
  - ★ [Gauss method for solving system of linear equations | CP Algorithms](https://cp-algorithms.com/linear_algebra/linear-system-gauss.html)
  - ★ [Finding the rank of a matrix | CP Algorithms](https://cp-algorithms.com/linear_algebra/rank-matrix.html)
  - [2 Special cases of Gaussian \[Tutorial\] By MazzForces](https://codeforces.com/blog/entry/60003)
  - [The Fear of Gaussian Elimination By godmar](https://codeforces.com/blog/entry/65787)
- **Problems (17):**
  - `[E]` ★ [System of Linear Equations](https://judge.yosupo.jp/problem/system_of_linear_equations)
  - `[E]` ★ [Graph Coloring](https://lightoj.com/problem/graph-coloring)
  - `[E]` ★ [Going to school](https://www.spoj.com/problems/GS/)
  - `[E]` [Knight Moving](https://www.codechef.com/SEP12/problems/KNGHTMOV)
  - `[E]` [Central Heating](https://acm.timus.ru/problem.aspx?space=1&num=1042)
  - `[E]` [Snakes and Ladders](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4775)
  - `[M]` [Humpty Dumpty](https://acm.timus.ru/problem.aspx?space=1&num=1766)
  - `[M]` [Kirchhoff's Law](https://acm.timus.ru/problem.aspx?space=1&num=1266)
  - `[M]` ★ [Rank of Matrix](https://judge.yosupo.jp/problem/matrix_rank)
  - `[M]` ★ [Nikifor](https://acm.timus.ru/problem.aspx?space=1&num=1041)
  - `[M]` ★ [Guess the Root](https://codeforces.com/problemset/problem/1155/E)
  - `[M]` [Boom Bot](https://toph.co/p/boom-bot)
  - `[M]` [Palindromes](https://www.spoj.com/problems/CODESPTF/)
  - `[H]` ★ [No Game No Life](https://codeforces.com/problemset/problem/1411/G)
  - `[H]` ★ [Cost of Living](https://naipc19.kattis.com/contests/naipc19/problems/costofliving)
  - `[H]` [Basis Change](https://codeforces.com/gym/102129/problem/D)
  - `[H]` [Circles of Waiting](https://codeforces.com/contest/963/problem/E)

#### 6.5.2 Gaussian Elimination Modulo 2

- **ID:** `gaussian_elimination_modulo_2` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gaussian_elimination_modulo_2
- **Templates (1):**
  - [Gaussian Elimination Modulo 2.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Gaussian%20Elimination%20Modulo%202.cpp)
- **Resources (2):**
  - ★ [Gaussian elimination over GF(2)](https://codeforces.com/blog/entry/123081)
  - ★ [Solving modular SLAE | CP Algorithms](https://cp-algorithms.com/linear_algebra/linear-system-gauss.html#solving-modular-slae)
- **Problems (3):**
  - `[M]` ★ [Subsets Forming Perfect Squares](https://lightoj.com/problem/subsets-forming-perfect-squar)
  - `[M]` ★ [Rank of Matrix (Mod 2)](https://judge.yosupo.jp/problem/matrix_rank_mod_2)
  - `[M]` ★ [Modifying SAT](https://codeforces.com/gym/101908/problem/M)

#### 6.5.3 Determinant of a Matrix

- **ID:** `determinant_under_prime_modulo` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/determinant_under_prime_modulo
- **Templates (1):**
  - [Determinant under Prime Modulo.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Determinant%20under%20Prime%20Modulo.cpp)
- **Resources (4):**
  - ★ [Determinant | Wiki](https://en.wikipedia.org/wiki/Determinant)
  - ★ [Calculating the determinant of a matrix by Gauss | CP Algorithms](https://cp-algorithms.com/linear_algebra/determinant-gauss.html)
  - [Calculating the determinant using Kraut method | CP Algorithms](https://cp-algorithms.com/linear_algebra/determinant-kraut.html)
  - ★ [Math 2331 - 17040: Linear Algebra | Dr. Jiwen He](https://www.math.uh.edu/~jiwenhe/math2331/index.htm)
- **Problems (3):**
  - `[E]` ★ [Determinant of Matrix](https://judge.yosupo.jp/problem/matrix_det)
  - `[M]` ★ [Determinant of Matrix (Mod 2)](https://judge.yosupo.jp/problem/matrix_det_mod_2)
  - `[H]` [Wizards and Bets](https://codeforces.com/contest/167/problem/E)

#### 6.5.4 Determinant under Composite Modulo

- **ID:** `determinant_under_composite_modulo` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/determinant_under_composite_modulo
- **Templates (1):**
  - [Determinant under Composite Modulo.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Determinant%20under%20Composite%20Modulo.cpp)
- **Resources (1):**
  - [Discussion on Library Checker](https://github.com/yosupo06/library-checker-problems/issues/750)
- **Problems (3):**
  - `[E]` ★ [Determinant of Matrix (Arbitrary Mod)](https://judge.yosupo.jp/problem/matrix_det_arbitrary_mod)
  - `[E]` [Find The Determinant III](https://www.spoj.com/problems/DETER3)
  - `[M]` [Integer-valued Complex Determinant](https://acm.timus.ru/problem.aspx?space=1&num=1845)

#### 6.5.5 Characteristic Polynomial and Hesserberg Matrix

- **ID:** `characteristic_polynomial` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/characteristic_polynomial
- **Templates (1):**
  - [Characteristic Polynomial Faster.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Characteristic%20Polynomial%20Faster.cpp)
- **Resources (4):**
  - ★ [Characteristic polynomial](https://en.wikipedia.org/wiki/Characteristic_polynomial)
  - ★ [Cayley–Hamilton theorem | Wiki](https://en.wikipedia.org/wiki/Cayley%E2%80%93Hamilton_theorem)
  - ★ [Hessenberg matrix | Wiki](https://en.wikipedia.org/wiki/Hessenberg_matrix)
  - [Discussion on Library Checker](https://github.com/yosupo06/library-checker-problems/issues/665)
- **Problems (2):**
  - `[M]` ★ [Determinant](https://codeforces.com/gym/102984/problem/K)
  - `[M]` ★ [Characteristic Polynomial](https://judge.yosupo.jp/problem/characteristic_polynomial)

#### 6.5.6 [Problem] Determinant of Product Matrix

- **ID:** `determinant_of_product_matrix` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/determinant_of_product_matrix
- **Templates (1):**
  - [Determinant of Product Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Determinant%20of%20Product%20Matrix.cpp)
- **Problems (1):**
  - `[E]` ★ [Determinant Strikes Back](https://official.contest.yandex.ru/opencupXXI/contest/23124/problems/D/)

#### 6.5.7 Determinant of Sparse Matrix and Black Box Linear Algebra

- **ID:** `determinant_of_sparse_matrix` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/determinant_of_sparse_matrix
- **Templates (1):**
  - [Determinant of Sparse Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Determinant%20of%20Sparse%20Matrix.cpp)
- **Resources (2):**
  - ★ [Nice trick involving sparse matrix exponentiation (kind-of) By bicsi](https://codeforces.com/blog/entry/85969)
  - ★ [Black box linear algebra | anta](https://yukicoder.me/wiki/black_box_linear_algebra)
- **Problems (3):**
  - `[E]` ★ [Determinant of Sparse Matrix](https://judge.yosupo.jp/problem/sparse_matrix_det)
  - `[H]` ★ [Panic! at the Disco](https://www.codechef.com/problems/PANIC)
  - `[H]` [Walk on Tree](https://www.codechef.com/OCT18A/problems/TREEWALK)

#### 6.5.8 [Problem] Determinant of Permutant and Circulant Matrix

- **ID:** `determinant_of_permutant_matrix` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/determinant_of_permutant_matrix
- **Templates (1):**
  - [Determinant of Permutant Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Determinant%20of%20Permutant%20Matrix.cpp)
- **Resources (3):**
  - [Editorial of Problem G. Permutant](https://codeforces.com/gym/102129/attachments/download/15399/PTZ2018%20%281%29.pdf)
  - [Circulant matrix | Wiki](https://en.wikipedia.org/wiki/Circulant_matrix)
  - [Polynomials and roots of unity By adamant](https://codeforces.com/blog/entry/101876)
- **Problems (2):**
  - `[E]` ★ [Permutant](https://codeforces.com/gym/102129/problem/G)
  - `[H]` [Cyclic Cipher](https://codeforces.com/contest/901/problem/E)

#### 6.5.9 GCD Determinant / Smith's Determinant

- **ID:** `gcd_determinant` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gcd_determinant
- **Resources (2):**
  - ★ [The Determinants of GCD Matrices | Zhongshan Li](https://core.ac.uk/download/pdf/82649337.pdf)
  - [On Smith's determinant](https://www.sciencedirect.com/science/article/pii/S0024379596001929)
- **Problems (2):**
  - `[E]` ★ [Find The Determinant II](https://www.spoj.com/problems/DETER2/)
  - `[E]` ★ [Find The Determinant](https://www.spoj.com/problems/DETER/)

#### 6.5.10 Cauchy–Binet formula

- **ID:** `cauchy_binet_formula` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/cauchy_binet_formula
- **Resources (1):**
  - [Cauchy–Binet formula | Wiki](https://en.wikipedia.org/wiki/Cauchy%E2%80%93Binet_formula)
- **Problems (1):**
  - `[M]` ★ [Cucumber Boy and Cucumber Girl](https://www.codechef.com/problems/CUCUMBER)

#### 6.5.11 Inverse of a Matrix

- **ID:** `inverse_of_a_matrix` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/inverse_of_a_matrix
- **Templates (1):**
  - [Inverse of A Matrix.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Inverse%20of%20A%20Matrix.cpp)
- **Resources (1):**
  - ★ [Math 2331 - 17040: Linear Algebra | Dr. Jiwen He](https://www.math.uh.edu/~jiwenhe/math2331/index.htm)
- **Problems (1):**
  - `[E]` ★ [Inverse Matrix](https://judge.yosupo.jp/problem/inverse_matrix)

#### 6.5.12 Inverse of a Matrix modulo 2

- **ID:** `inverse_of_a_matrix_modulo_2` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/inverse_of_a_matrix_modulo_2
- **Templates (1):**
  - [Inverse of A Matrix modulo 2.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Inverse%20of%20A%20Matrix%20modulo%202.cpp)
- **Problems (2):**
  - `[E]` ★ [Inverse Matrix (Mod 2)](https://judge.yosupo.jp/problem/inverse_matrix_mod_2)
  - `[M]` ★ [Permutations](https://codeforces.com/contest/736/problem/D)

#### 6.5.13 Thomas Algorithm

- **ID:** `thomas_algorithm` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/thomas_algorithm
- **Templates (1):**
  - [Thomas Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Thomas%20Algorithm.cpp)
- **Resources (1):**
  - [Tridiagonal matrix algorithm | Wiki](https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm)
- **Problems (1):**
  - `[M]` ★ [Slime and Biscuits](https://codeforces.com/contest/1349/problem/D)

#### 6.5.14 Vector Space and XOR Basis

- **ID:** `basis_vector` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/basis_vector
- **Templates (1):**
  - [Basis Vector.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Basis%20Vector.cpp)
- **Resources (7):**
  - ★ [Math 2331 - 17040: Linear Algebra | Dr. Jiwen He](https://www.math.uh.edu/~jiwenhe/math2331/index.htm)
  - ★ [XOR Basis Presentation | Benq](https://drive.google.com/drive/folders/1Ll8EuA3p64JLmzImfQu5qiWvc6_QTa0E)
  - ★ [A Beautiful Technique for Some XOR Related Problems By DrSwad](https://codeforces.com/blog/entry/68953)
  - ★ [Linear Basis (Xor Basis Extended) By errorgorn](https://codeforces.com/blog/entry/98376)
  - [XOR Space | Competitive Programming Winning Technique 2 | Gaussian Elimination | Vivek Gupta](https://www.youtube.com/watch?v=qIXg9vJ6hZM)
  - [XOR basis without linear algebra By Everule](https://codeforces.com/blog/entry/100066)
  - [2 Special cases of Gaussian \[Tutorial\] By MazzForces](https://codeforces.com/blog/entry/60003)
- **Problems (29):**
  - `[E]` ★ [Maximum Subset Sum](https://lightoj.com/problem/maximum-subset-sum)
  - `[E]` ★ [XOR Maximization](https://www.spoj.com/problems/XMAX/)
  - `[E]` ★ [Godzilla and Pretty XOR](https://codeforces.com/group/qcIqFPYhVr/contest/203881/problem/S)
  - `[E]` ★ [Xor Closure](https://csacademy.com/contest/archive/task/xor-closure/statement/)
  - `[M]` ★ [Subsets Forming Perfect Squares](https://lightoj.com/problem/subsets-forming-perfect-squar)
  - `[M]` ★ [Square Subsets](https://codeforces.com/contest/895/problem/C)
  - `[M]` ★ [Mahmoud and Ehab and yet another xor task](https://codeforces.com/contest/959/problem/F)
  - `[M]` ★ [Ivan and Burgers](https://codeforces.com/problemset/problem/1100/F)
  - `[M]` [Xor Battle](https://atcoder.jp/contests/agc045/tasks/agc045_a)
  - `[M]` ★ [(Zero XOR Subset)-less](https://codeforces.com/contest/1101/problem/G)
  - `[M]` ★ [Shortest Path Problem?](https://codeforces.com/contest/845/problem/G)
  - `[M]` [Magical Permutation](https://codeforces.com/contest/1163/problem/E)
  - `[M]` ★ [Bitsetbaba and Power Grid](https://www.codechef.com/COOK106A/problems/XORCMPNT)
  - `[M]` ★ [Chef & Chutneys](https://www.hackerearth.com/problem/algorithm/chef-f59c8115)
  - `[M]` ★ [Xor Query](https://atcoder.jp/contests/abc223/tasks/abc223_h)
  - `[M]` [Spices](https://atcoder.jp/contests/abc236/tasks/abc236_f)
  - `[M]` [Xor Sum 3](https://atcoder.jp/contests/abc141/tasks/abc141_f)
  - `[M]` [Gambling Nim](https://codeforces.com/problemset/problem/662/A)
  - `[M]` ★ [The Tree Has Fallen!](https://codeforces.com/contest/1778/problem/E)
  - `[M]` ★ [Even XOR](https://atcoder.jp/contests/arc146/tasks/arc146_c)
  - `[M]` ★ [Uncle Bob and XOR Sum](https://lightoj.com/problem/uncle-bob-xor-sum)
  - `[M]` [Two Faced Hobz](https://codeforces.com/gym/104147/problem/J)
  - `[H]` ★ [Maximaze XOR sum](https://codeforces.com/gym/103414/problem/G)
  - `[H]` ★ [Duff as a Queen](https://codeforces.com/contest/587/problem/E)
  - `[H]` ★ [Chiori and Doll Picking (easy version)](https://codeforces.com/contest/1336/problem/E1)
  - `[H]` [Around the World](https://codeforces.com/contest/1299/problem/D)
  - `[H]` ★ [Increasing Xor](https://codeforces.com/contest/2143/problem/F)
  - `[H]` [Gellyfish and Forget-Me-Not](https://codeforces.com/contest/2116/problem/F)
  - `[VH]` ★ [AB=C Problem](https://atcoder.jp/contests/cf16-exhibition-final/tasks/cf16_exhibition_final_h)

#### 6.5.15 [Technique] XOR Basis ft Reduced Row Echelon Form

- **ID:** `basis_vector_reduced_row_echelon_form` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/basis_vector_reduced_row_echelon_form
- **Templates (1):**
  - [Basis Vector Reduced Row Echelon Form.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Basis%20Vector%20Reduced%20Row%20Echelon%20Form.cpp)
- **Resources (1):**
  - [Reduced row echelon form | Wiki](https://en.wikipedia.org/wiki/Row_echelon_form#Reduced_row_echelon_form)
- **Problems (1):**
  - `[H]` ★ [Find the XOR](https://codeforces.com/gym/102979/problem/F)

#### 6.5.16 [Technique] XOR Basis ft Lexicographically Largest Basis

- **ID:** `basis_vector_ft_lexicographically_largest_basis` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/basis_vector_ft_lexicographically_largest_basis
- **Templates (1):**
  - [Basis Vector ft Weighted Linearly Independent Vectors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Basis%20Vector%20ft%20Weighted%20Linearly%20Independent%20Vectors.cpp)
- **Resources (1):**
  - ★ [A comment by jiangly](https://codeforces.com/blog/entry/112149?#comment-999480)
- **Problems (4):**
  - `[M]` ★ [Ivan and Burgers](https://codeforces.com/problemset/problem/1100/F)
  - `[M]` ★ [The Tree Has Fallen!](https://codeforces.com/contest/1778/problem/E)
  - `[M]` ★ [Easy Win](https://codeforces.com/gym/102331/problem/E)
  - `[M]` ★ [Trees and XOR Queries Again](https://codeforces.com/contest/1902/problem/F)

#### 6.5.17 XOR Basis with Deletions (Online)

- **ID:** `basis_vector_with_deletions` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/basis_vector_with_deletions
- **Templates (1):**
  - [7u074ngkv127l3fl0m33bf5gck](https://basecamp.eolymp.com/en/posts/7u074ngkv127l3fl0m33bf5gck)
- **Resources (1):**
  - ★ [XOR Basis with deletions by denisovkostya](https://basecamp.eolymp.com/en/posts/7u074ngkv127l3fl0m33bf5gck)
- **Problems (1):**
  - `[M]` ★ [Beauty Permutation Queries](https://basecamp.eolymp.com/en/problems/11732)

#### 6.5.18 q Binomial

- **ID:** `q_binomial` · **Difficulty:** Very Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/q_binomial
- **Templates (1):**
  - [q Binomial.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/q%20Binomial.cpp)
- **Resources (4):**
  - ★ [Combinatorics of Vector Spaces over Finite Fields | An Abstract of the Thesis of Geoffrey Critzer](https://esirc.emporia.edu/bitstream/handle/123456789/3595/Geoffrey%20Critzer.pdf)
  - [Gaussian binomial coefficient | Wiki](https://en.wikipedia.org/wiki/Gaussian_binomial_coefficient)
  - [Moment-generating functions, inversions and q-analogs By adamant](https://codeforces.com/blog/entry/99598)
  - [Note -「q-analog」组合意义灭天地](https://www.cnblogs.com/rainybunny/p/16475568.html)
- **Problems (5):**
  - `[E]` ★ [q-Binomial Coefficient (Prime Mod)](https://judge.yosupo.jp/problem/q_binomial_coefficient_prime_mod)
  - `[M]` ★ [Matrix Rank (Hard Version)](https://codeforces.com/contest/1916/problem/H2)
  - `[M]` ★ [October 18, 2017](https://codeforces.com/contest/1603/problem/F)
  - `[H]` [Many Xor Optimization Problems](https://atcoder.jp/contests/arc139/tasks/arc139_f)
  - `[H]` ★ [make 1](https://atcoder.jp/contests/abc278/tasks/abc278_h)

### 6.6 Formulas

**Subcategory ID:** `formulas` · **Topics:** 4

#### 6.6.1 Gauss's Eureka Theorem

- **ID:** `gausss_eureka_theorem` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gausss_eureka_theorem
- **Resources (1):**
  - [Integer is Sum of Three Triangular Numbers | Wiki](https://proofwiki.org/wiki/Integer_is_Sum_of_Three_Triangular_Numbers)
- **Problems (1):**
  - `[E]` ★ [Palindromicity](https://codeforces.com/gym/103150/problem/F)

#### 6.6.2 Titu's Lemma

- **ID:** `titus_lemma` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/titus_lemma
- **Resources (2):**
  - ★ [Titu's Lemma | Brilliant](https://brilliant.org/wiki/titus-lemma/)
  - ★ [A comment by Alpha_Q](https://codeforces.com/blog/entry/49741#comment-337988)
- **Problems (2):**
  - `[E]` ★ [Inventory](https://vjudge.net/problem/Gym-102821I)
  - `[E]` ★ [Betting Business](https://toph.co/p/betting-business)

#### 6.6.3 Lifting-the-exponent(LTE) Lemma

- **ID:** `lte_lemma` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lte_lemma
- **Resources (2):**
  - ★ [Lifting-the-exponent lemma | Wiki](https://en.wikipedia.org/wiki/Lifting-the-exponent_lemma)
  - [Lifting The Exponent Lemma (LTE) | Amir Hossein Parvardi](https://services.artofproblemsolving.com/download.php?id=YXR0YWNobWVudHMvMC9mL2I3NWVmM2MyZDRiYTFlN2EzMzQxMTI2ZmM3NTNjMTcxODFmNmYw&rn=TGlmdGluZyBUaGUgRXhwb25lbnQgLSBWZXJzaW9uIDUucGRm)

#### 6.6.4 Faulhaber's Formula and Bernoulli Numbers

- **ID:** `faulhabers_formula` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/faulhabers_formula
- **Templates (1):**
  - [Faulhaber Formula Fastest.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Faulhaber%20Formula%20Fastest.cpp)
- **Resources (2):**
  - ★ [Faulhaber's formula | Wiki](https://en.wikipedia.org/wiki/Faulhaber%27s_formula)
  - [Bernoulli number | Wiki](https://en.wikipedia.org/wiki/Bernoulli_number)
- **Problems (3):**
  - `[M]` [Black Hole](https://www.hackerrank.com/contests/infinitum8/challenges/demidenko-black-hole)
  - `[H]` ★ [Series Sum](https://www.codechef.com/problems/SERSUM)
  - `[H]` ★ [Coprime Power Sum](https://www.hackerrank.com/challenges/coprime-power-sum/problem)

### 6.7 Calculus

**Subcategory ID:** `calculus` · **Topics:** 2

#### 6.7.1 Differentiation and Integration

- **ID:** `integration` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/integration
- **Templates (2):**
  - [Integration (Simpsons).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Integration%20%28Simpsons%29.cpp)
  - [Integration (Romberg).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Integration%20%28Romberg%29.cpp)
- **Resources (5):**
  - ★ [Differentiation | Brilliant](https://brilliant.org/wiki/differentiation/)
  - ★ [Finding Maxima and Minima using Derivatives | Math is Fun](https://www.mathsisfun.com/calculus/maxima-minima.html)
  - ★ [Integration | Brilliant](https://brilliant.org/wiki/integration/)
  - ★ [Simpson's rule | Wiki](https://en.wikipedia.org/wiki/Simpson%27s_rule)
  - ★ [Romberg's method | Wiki](https://en.wikipedia.org/wiki/Romberg%27s_method)
- **Problems (12):**
  - `[E]` ★ [Simple Differentiation](https://vjudge.net/problem/Gym-423724B)
  - `[E]` [Differentiation](https://vjudge.net/problem/Gym-101807D)
  - `[E]` ★ [Train Station](https://vjudge.net/problem/UVA-12997)
  - `[M]` [Environment Protection](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=441&page=show_problem&problem=3973)
  - `[M]` ★ [Speed Zones](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3838)
  - `[M]` [Curvy Little Bottles](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3893)
  - `[M]` [GM-pineapple](https://acm.timus.ru/problem.aspx?space=1&num=1562)
  - `[M]` [Tough Water Level](https://www.spoj.com/problems/CERC07W/)
  - `[M]` [Sphere](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1116)
  - `[H]` ★ [The area of the union of circles](https://www.spoj.com/problems/CIRU/)
  - `[VH]` ★ [Minimize the Distance](https://vjudge.net/problem/CodeChef-MINDIST)
  - `[VH]` [Imagine Polygons](https://vjudge.net/problem/CodeChef-IMPO)

#### 6.7.2 Line Integral

- **ID:** `line_integral` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/line_integral
- **Resources (2):**
  - ★ [Arc Length | Math is Fun](https://www.mathsisfun.com/calculus/arc-length.html)
  - [Line Integral | Brilliant](https://brilliant.org/wiki/line-integral/)

### 6.8 Probabilities and Expected Values

**Subcategory ID:** `probabilities_and_expected_values` · **Topics:** 6

#### 6.8.1 Probabilities and Expected Values

- **ID:** `probabilities_and_expected_values` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/probabilities_and_expected_values
- **Resources (2):**
  - ★ [Sums and Expected Value — part 1 By Errichto](https://codeforces.com/blog/entry/62690)
  - ★ [UNDERSTANDING PROBABILITIES | supernova](https://www.topcoder.com/thrive/articles/Understanding%20Probabilities)
- **Problems (54):**
  - `[E]` ★ [Die Roll](https://codeforces.com/problemset/problem/9/A)
  - `[E]` ★ [Archer](https://codeforces.com/problemset/problem/312/B)
  - `[E]` ★ [Dreamoon and WiFi](https://codeforces.com/problemset/problem/476/B)
  - `[E]` ★ [Little Pony and Expected Maximum](https://codeforces.com/problemset/problem/453/A)
  - `[E]` ★ [Random Events](https://codeforces.com/problemset/problem/1461/C)
  - `[E]` ★ [Wet Shark and Flowers](https://codeforces.com/contest/621/problem/C)
  - `[E]` ★ [Bad Luck Island](https://codeforces.com/problemset/problem/540/D)
  - `[E]` ★ [Andrey and Problem](https://codeforces.com/problemset/problem/442/B)
  - `[E]` [What is the Probability ?](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=997)
  - `[E]` [Journey](https://codeforces.com/problemset/problem/839/C)
  - `[E]` ★ [Ilya and Escalator](https://codeforces.com/problemset/problem/518/D)
  - `[E]` ★ [Bag of mice](https://codeforces.com/problemset/problem/148/D)
  - `[E]` ★ [Airplane](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3904)
  - `[E]` ★ [Bubble Sort](https://vjudge.net/problem/UVA-12004)
  - `[E]` [Inversions After Shuffle](https://codeforces.com/problemset/problem/749/E)
  - `[E]` [Sakurako's Box](https://codeforces.com/contest/2008/problem/F)
  - `[M]` ★ [Ada and Island](https://www.spoj.com/problems/ADASEA/)
  - `[M]` [Martingale](https://www.codechef.com/AMR18ROL/problems/MARTING1)
  - `[M]` ★ [Game on Tree](https://codeforces.com/problemset/problem/280/C)
  - `[M]` [Proprietary Probabilistic Problem](https://www.codechef.com/GWR17ROL/problems/KALADIN)
  - `[M]` [Sugoroku2](https://atcoder.jp/contests/abc189/tasks/abc189_f)
  - `[M]` [Guess Game](https://codeforces.com/problemset/problem/1864/E)
  - `[M]` ★ [LuoTianyi and the Floating Islands (Hard Version)](https://codeforces.com/problemset/problem/1824/B2)
  - `[M]` ★ [Flexible String Revisit](https://codeforces.com/problemset/problem/1778/D)
  - `[M]` [Messages](https://codeforces.com/problemset/problem/1612/E)
  - `[M]` [Bubble Strike](https://codeforces.com/problemset/problem/1599/C)
  - `[M]` [Assimilation IV](https://codeforces.com/problemset/problem/1525/E)
  - `[M]` ★ [Expected Damage](https://codeforces.com/problemset/problem/1418/E)
  - `[M]` [Inversion Expectation](https://codeforces.com/problemset/problem/1096/F)
  - `[M]` [Makoto and a Blackboard](https://codeforces.com/problemset/problem/1097/D)
  - `[M]` ★ [Fish](https://codeforces.com/problemset/problem/16/E)
  - `[M]` [Tickets](https://codeforces.com/contest/26/problem/D)
  - `[M]` [Basketball Team](https://codeforces.com/problemset/problem/107/B)
  - `[M]` [Falling Anvils](https://codeforces.com/problemset/problem/77/B)
  - `[M]` [Jerry's Protest](https://codeforces.com/problemset/problem/626/D)
  - `[M]` [Jeff and Furik](https://codeforces.com/problemset/problem/351/B)
  - `[M]` [Let's Play Osu!](https://codeforces.com/problemset/problem/235/B)
  - `[M]` [Wizards and Huge Prize](https://codeforces.com/problemset/problem/167/B)
  - `[M]` [Lucky Probability](https://codeforces.com/problemset/problem/109/B)
  - `[M]` [Shooting Gallery](https://codeforces.com/problemset/problem/30/C)
  - `[M]` ★ [Birthday Paradox](https://lightoj.com/problem/birthday-paradox)
  - `[M]` [Another Sith Tournament](https://codeforces.com/contest/678/problem/E)
  - `[M]` [Sticker Album](https://codeforces.com/gym/102861/problem/A)
  - `[M]` [Bath Queue](https://codeforces.com/problemset/problem/28/C)
  - `[M]` [Expected Power](https://codeforces.com/contest/2020/problem/E)
  - `[H]` [Good Contest](https://codeforces.com/problemset/problem/1295/F)
  - `[H]` [Dstorv](https://codeforces.com/gym/102059/problem/C)
  - `[H]` [Maze](https://codeforces.com/problemset/problem/123/E)
  - `[H]` [Museum](https://codeforces.com/problemset/problem/113/D)
  - `[H]` ★ [Birthday](https://codeforces.com/problemset/problem/623/D)
  - `[H]` [ZS Shuffles Cards](https://codeforces.com/contest/1392/problem/H)
  - `[H]` [Inversion Probability](https://cses.fi/problemset/task/1728)
  - `[H]` [T-shirt](https://codeforces.com/contest/183/problem/D)
  - `[VH]` ★ [Gem Island](https://icpc.kattis.com/problems/gemisland)

#### 6.8.2 Expected Value Powers Technique

- **ID:** `expected_value_powers_technique` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/expected_value_powers_technique
- **Resources (1):**
  - ★ [Sums and Expected Value — part 2 By Errichto](https://codeforces.com/blog/entry/62792)
- **Problems (4):**
  - `[E]` ★ [Chef Cuts Tree](https://www.codechef.com/problems/CUTTREE)
  - `[M]` ★ [Cards](https://codeforces.com/problemset/problem/1278/F)
  - `[M]` [Rikka with Subsequences](https://codeforces.com/gym/102012/problem/D)
  - `[H]` ★ [Guna Guni](https://lightoj.com/problem/guna-guni)

#### 6.8.3 The Slime Trick

- **ID:** `the_slime_trick` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/the_slime_trick
- **Resources (1):**
  - [A comment by jqdai0815](https://codeforces.com/blog/entry/77284#comment-620956)
- **Problems (2):**
  - `[M]` ★ [Slime and Biscuits](https://codeforces.com/contest/1349/problem/D)
  - `[H]` ★ [Company Acquisitions](https://codeforces.com/contest/1025/problem/G)

#### 6.8.4 Expected Occurrence Time as Substring

- **ID:** `expected_occurrence_time_as_substring` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/expected_occurrence_time_as_substring
- **Resources (3):**
  - ★ [\[Tutorial\] Expected number of coin flips required to achieve a given string By gabrielwu](https://codeforces.com/blog/entry/98808)
  - ★ [Editorial of Problem R2 06: Monkey at the Keyboard (ID: 1677)](https://bubblecup.org/Content/Media/Booklet2011.pdf)
  - [Disucussion by aid](https://codeforces.com/blog/entry/49331#comment-336565)
- **Problems (3):**
  - `[M]` ★ [Monkey at the Keyboard](https://acm.timus.ru/problem.aspx?space=1&num=1677)
  - `[M]` [Flip a Coin](https://www.acmicpc.net/problem/19338)
  - `[H]` [Monkey's Keyboard](https://codeforces.com/gym/102832/problem/G)

#### 6.8.5 Gambler's Ruin

- **ID:** `gamblers_ruin` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gamblers_ruin
- **Resources (3):**
  - ★ [Gambler's ruin | Wiki](https://en.wikipedia.org/wiki/Gambler%27s_ruin)
  - [Gambler’s Ruin Problem | columbia.edu](https://www.columbia.edu/~ks20/FE-Notes/4700-07-Notes-GR.pdf)
  - [Random Walks | MIT](https://web.mit.edu/neboat/Public/6.042/randomwalks.pdf)
- **Problems (2):**
  - `[M]` [PointSystem](https://community.topcoder.com/stat?c=problem_statement&pm=1849&rd=4675)
  - `[M]` [CatsOnTheCircle](https://community.topcoder.com/stat?c=problem_statement&pm=13643&rd=16547)

#### 6.8.6 Martingale

- **ID:** `martingale` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/martingale
- **Resources (2):**
  - [Martingale (probability theory) | Wiki](https://en.wikipedia.org/wiki/Martingale_%28probability_theory%29)
  - ★ [Probability 101, the intuition behind martingales and solving problems with them By nor](https://codeforces.com/blog/entry/110801)
- **Problems (7):**
  - `[M]` ★ [Slime and Biscuits](https://codeforces.com/contest/1349/problem/D)
  - `[H]` [ZS Shuffles Cards](https://codeforces.com/contest/1392/problem/H)
  - `[H]` [Finding Expected Value](https://codeforces.com/contest/1575/problem/F)
  - `[H]` ★ [Company Acquisitions](https://codeforces.com/contest/1025/problem/G)
  - `[H]` [Balance Beam](https://usaco.org/index.php?page=viewproblem2&cpid=864)
  - `[VH]` [School Clubs](https://codeforces.com/contest/1479/problem/E)
  - `[VH]` [Rainbow Balls](https://codeforces.com/contest/850/problem/F)

### 6.9 Mathematical Optimization

**Subcategory ID:** `mathematical_optimization` · **Topics:** 3

#### 6.9.1 Lagrange Multiplier

- **ID:** `lagrange_multiplier` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lagrange_multiplier
- **Templates (1):**
  - [Lagrange Multiplier.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Lagrange%20Multiplier.cpp)
- **Resources (2):**
  - ★ [Lagrange multiplier | Wiki](https://en.wikipedia.org/wiki/Lagrange_multiplier)
  - [Lagrange Multipliers for "Core Training" (Code Jam 2017, Round 1C) By choice](https://codeforces.com/blog/entry/51783)
- **Problems (7):**
  - `[E]` ★ [Betting Business](https://toph.co/p/betting-business)
  - `[E]` [Mushroom Scientists](https://codeforces.com/contest/186/problem/D)
  - `[M]` ★ [Speed Zones](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3838)
  - `[M]` ★ [Highway Cycling](https://wcipeg.com/problem/noi12p2)
  - `[M]` [Samantha and Portfolio Management](https://www.hackerrank.com/contests/morgan-stanley-2016/challenges/samantha-and-portfolio-management)
  - `[H]` ★ [Coprime Power Sum](https://www.hackerrank.com/challenges/coprime-power-sum/problem)
  - `[H]` ★ [Random Number Generator](https://www.hackerrank.com/contests/infinitum14/challenges/random-number-generator-1)

#### 6.9.2 Linear Programming / Simplex Algorithm

- **ID:** `simplex_algorithm` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/simplex_algorithm
- **Templates (1):**
  - [Simplex Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Simplex%20Algorithm.cpp)
- **Resources (2):**
  - [Simplex algorithm | Wiki](https://en.wikipedia.org/wiki/Simplex_algorithm)
  - [Alternative Solution to 1421 D. Hexagons using Linear Programming & Total Unimodularity By eyfmharb](https://codeforces.com/blog/entry/101470)
- **Problems (3):**
  - `[M]` ★ [Freelancer's Dreams](https://codeforces.com/problemset/problem/605/C)
  - `[M]` [01 Sequence](https://www.spoj.com/problems/SEQ1/)
  - `[H]` ★ [Red and Black Tree](https://codeforces.com/problemset/problem/375/E)

#### 6.9.3 Duality in Linear Programming (LP <> Flow)

- **ID:** `duality_in_linear_programming` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/duality_in_linear_programming
- **Resources (3):**
  - ★ [Duality in linear programming. Part 1 — definition and construction By adamant](https://codeforces.com/blog/entry/105049)
  - ★ [Duality in linear programming. Part 2 — in competitive programming By adamant](https://codeforces.com/blog/entry/105789)
  - [Dual flows and algorithms | Laurent Lessard](https://laurentlessard.com/teaching/cs524/slides/7%20-%20dual%20flows%20and%20algorithms.pdf)
- **Problems (10):**
  - `[E]` ★ [Minimum Cost b-flow](https://judge.yosupo.jp/problem/min_cost_b_flow)
  - `[M]` ★ [Freelancer's Dreams](https://codeforces.com/problemset/problem/605/C)
  - `[H]` [Fishingprince Plays With Array Again](https://codeforces.com/contest/1696/problem/G)
  - `[H]` [Roads](https://codeforces.com/problemsets/acmsguru/problem/99999/206)
  - `[H]` [Utilitarianism](https://codeforces.com/gym/102059/problem/M)
  - `[H]` [Yet Another DAG Problem](https://codeforces.com/problemset/problem/1430/G)
  - `[H]` [Hiring Employees](https://wcipeg.com/problem/noi08p3)
  - `[H]` [Snack](https://atcoder.jp/contests/arc125/tasks/arc125_e)
  - `[VH]` ★ [Cow and Exercise](https://codeforces.com/contest/1307/problem/G)
  - `[VH]` [Security Camera 2](https://atcoder.jp/contests/abc224/tasks/abc224_h)

### 6.10 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 3

#### 6.10.1 Continued Fractions

- **ID:** `continued_fractions` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/continued_fractions
- **Templates (1):**
  - [Continued Fractions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Number%20Theory/Continued%20Fractions.cpp)
- **Resources (3):**
  - ★ [On continued fractions. Part 1: Introduction By adamant](https://codeforces.com/blog/entry/73655)
  - [On continued fractions. Part 2: Properties and interpretation By adamant](https://codeforces.com/blog/entry/73687)
  - [Continued Fractions | Brilliant](https://brilliant.org/wiki/continued-fractions/)
- **Problems (1):**
  - `[E]` [Continued Fractions](https://codeforces.com/problemset/problem/305/B)

#### 6.10.2 Polynomial Real Roots

- **ID:** `polynomial_root_finding` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polynomial_root_finding
- **Resources (1):**
  - ★ [Newton's method for finding roots | CP Algorithms](https://cp-algorithms.com/num_methods/roots_newton.html)
- **Problems (1):**
  - `[E]` ★ [The Roots](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1369)

#### 6.10.3 Finite Field Arithmetic Binary

- **ID:** `finite_field_arithmetic_binary` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/finite_field_arithmetic_binary
- **Templates (1):**
  - [Finite Field Arithmetic Binary.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Math/Finite%20Field%20Arithmetic%20Binary.cpp)
- **Resources (1):**
  - [Finite field arithmetic | Wiki](https://en.wikipedia.org/wiki/Finite_field_arithmetic)
- **Problems (1):**
  - `[M]` ★ [Even Coefficients](https://www.codechef.com/DEC10/problems/EVENPOLY/)

---

## 7. Strings

**Category ID:** `strings` · **Subcategories:** 7 · **Topics:** 31

### 7.1 String Matching

**Subcategory ID:** `string_matching` · **Topics:** 4

#### 7.1.1 Knuth Morris Pratt (KMP) and Prefix Automaton

- **ID:** `kmp` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/kmp
- **Templates (2):**
  - [KMP.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/KMP.cpp)
  - [Prefix Automaton.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Prefix%20Automaton.cpp)
- **Resources (6):**
  - ★ [Prefix function. Knuth–Morris–Pratt algorithm | CP Algorithms](https://cp-algorithms.com/string/prefix-function.html)
  - ★ [(Tutorial) Prefix Function + Pattern Matching (supposedly, KMP) | galencolin](https://discuss.codechef.com/t/tutorial-prefix-function-pattern-matching-supposedly-kmp/67531)
  - ★ [The Automaton Interpretation for the KMP Algorithm By arthur_9548](https://codeforces.com/blog/entry/146191)
  - [KMP Algorithm (String Matching) Demystified | Girish Budhwani](https://binary-baba.medium.com/string-matching-kmp-algorithm-27c182efa387)
  - [Video tutorial on KMP algorithm By vedhant](https://codeforces.com/blog/entry/74280?f0a28=3&locale=en)
  - [Knuth–Morris–Pratt (KMP) (Bangla | বাংলা) #CP Pattern Matching (Substring search)](https://www.youtube.com/watch?v=sMARZCTPyNI&t=161s)
- **Problems (36):**
  - `[E]` ★ [String Matching](https://cses.fi/problemset/task/1753)
  - `[E]` ★ [Finding Border](https://cses.fi/problemset/task/1732)
  - `[E]` ★ [Finding Periods](https://cses.fi/problemset/task/1733)
  - `[E]` ★ [Periodic Strings](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396)
  - `[E]` ★ [String Factoring](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963)
  - `[E]` [Dancing the Cheeky-Cheeky](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2447)
  - `[E]` [Caesar Cipher](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4282)
  - `[E]` ★ [Pattern Find](https://www.spoj.com/problems/NAJPF/)
  - `[E]` [A Needle in the Haystack](https://www.spoj.com/problems/NHAY/)
  - `[E]` [Secret Word](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3911)
  - `[E]` ★ [MUH and Cube Walls](https://codeforces.com/problemset/problem/471/D)
  - `[E]` [War of the Corporations](https://codeforces.com/contest/625/problem/B)
  - `[E]` [String Functions](https://cses.fi/problemset/task/2107)
  - `[E]` [Order-Preserving Codes](https://codeforces.com/gym/100212/problem/C)
  - `[E]` [Message Transmission Error (hard version)](https://codeforces.com/contest/2010/problem/C2)
  - `[M]` [Prefixes and Suffixes](https://codeforces.com/problemset/problem/432/D)
  - `[M]` ★ [Extend to Palindrome](https://www.spoj.com/problems/EPALIN/)
  - `[M]` ★ [Power Strings](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1239)
  - `[M]` [Period](https://www.spoj.com/problems/PERIOD/)
  - `[M]` ★ [Anthem of Berland](https://codeforces.com/contest/808/problem/G)
  - `[M]` ★ [Required Substring](https://cses.fi/problemset/task/1112)
  - `[M]` ★ [Lucky Common Subsequence](https://codeforces.com/problemset/problem/346/B)
  - `[M]` ★ [Matrix Matcher](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960)
  - `[M]` ★ [Password](https://codeforces.com/problemset/problem/126/B)
  - `[M]` [Tavas and Malekas](https://codeforces.com/problemset/problem/535/D)
  - `[M]` ★ [Obsessive String](https://codeforces.com/contest/494/problem/B)
  - `[M]` [Messenger](https://codeforces.com/problemset/problem/631/D)
  - `[M]` ★ [String Transformation](https://codeforces.com/problemset/problem/119/D)
  - `[M]` ★ [Finding Palindromes](https://www.spoj.com/problems/VPALIN/)
  - `[M]` ★ [Bracket Substring](https://codeforces.com/problemset/problem/1015/F)
  - `[M]` [Cow Patterns](https://www.spoj.com/problems/CPATTERN/)
  - `[M]` ★ [Tree-String Problem](https://codeforces.com/contest/291/problem/E)
  - `[M]` ★ [Unlucky Strings](https://lightoj.com/problem/unlucky-strings)
  - `[M]` [String Compression](https://codeforces.com/contest/825/problem/F)
  - `[M]` [Test](https://codeforces.com/problemset/problem/25/E)
  - `[H]` ★ [Pty loves string](https://vjudge.net/problem/HDU-7084)

#### 7.1.2 Z algorithm

- **ID:** `z_algorithm` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/z_algorithm
- **Templates (1):**
  - [Z Algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Z%20Algorithm.cpp)
- **Resources (2):**
  - ★ [Z-function and its calculation | CP Algorithms](https://cp-algorithms.com/string/z-function.html)
  - [Z Algorithm By paladin8](https://codeforces.com/blog/entry/3107)
- **Problems (18):**
  - `[E]` ★ [Z Algorithm](https://judge.yosupo.jp/problem/zalgorithm)
  - `[E]` ★ [String Matching](https://cses.fi/problemset/task/1753)
  - `[E]` ★ [Finding Periods](https://cses.fi/problemset/task/1733)
  - `[E]` ★ [Finding Border](https://cses.fi/problemset/task/1732)
  - `[E]` ★ [Pattern Find](https://www.spoj.com/problems/NAJPF/)
  - `[E]` [A Needle in the Haystack](https://www.spoj.com/problems/NHAY/)
  - `[E]` ★ [MUH and Cube Walls](https://codeforces.com/problemset/problem/471/D)
  - `[E]` [String Functions](https://cses.fi/problemset/task/2107)
  - `[E]` [Query Problem](https://www.spoj.com/problems/QUERYSTR/)
  - `[E]` ★ [Periodic Strings](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=396)
  - `[E]` ★ [String Factoring](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1963)
  - `[M]` ★ [Extend to Palindrome](https://www.spoj.com/problems/EPALIN/)
  - `[M]` [Tavas and Malekas](https://codeforces.com/problemset/problem/535/D)
  - `[M]` ★ [String Transformation](https://codeforces.com/problemset/problem/119/D)
  - `[M]` [Prefixes and Suffixes](https://codeforces.com/problemset/problem/432/D)
  - `[M]` ★ [Password](https://codeforces.com/problemset/problem/126/B)
  - `[M]` ★ [Division + LCP (hard version)](https://codeforces.com/problemset/problem/1968/G2)
  - `[H]` ★ [Copy and Paste](https://codeforces.com/gym/104385/problem/G)

#### 7.1.3 String Matching using Bitsets

- **ID:** `string_matching_using_bitsets` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/string_matching_using_bitsets
- **Templates (1):**
  - [String Matching using Bitsets.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/String%20Matching%20using%20Bitsets.cpp)
- **Resources (1):**
  - [String Matching using Bitset](https://iq.opengenus.org/string-matching-using-bitset/)
- **Problems (7):**
  - `[E]` ★ [Dasha and cyclic table](https://codeforces.com/contest/754/problem/E)
  - `[M]` ★ [Frequency of String](https://codeforces.com/problemset/problem/963/D)
  - `[M]` [Yet Another String Matching Problem](https://codeforces.com/problemset/problem/954/I)
  - `[M]` [Substring Search](https://codeforces.com/problemset/problem/1334/G)
  - `[M]` ★ [Fuzzy Search](https://codeforces.com/contest/528/problem/D)
  - `[H]` ★ [Substrings in a String](https://codeforces.com/problemset/problem/914/F)
  - `[H]` [Design Tutorial: Increase the Constraints](https://codeforces.com/problemset/problem/472/G)

#### 7.1.4 String Matching with FFT ft Wildcard Matching

- **ID:** `string_matching_with_fft` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/string_matching_with_fft
- **Templates (1):**
  - [String Matching With FFT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/String%20Matching%20With%20FFT.cpp)
- **Resources (3):**
  - ★ [Interesting problem involving convolutions By snacache](https://codeforces.com/blog/entry/59386)
  - ★ [Simple Deterministic Wildcard Matching Peter Clifford and Raphael Clifford](https://www.informatika.bg/resources/StringMatchingWithFFT.pdf)
  - ★ [\[Tutorial\] On Variations of String Matching By brunomont](https://codeforces.com/blog/entry/111380)
- **Problems (11):**
  - `[E]` ★ [Ada and Nucleobase](https://www.spoj.com/problems/ADAMATCH/)
  - `[E]` ★ [Maximum Self-Matching](https://www.spoj.com/problems/MAXMATCH/)
  - `[E]` ★ [K-Inversions](https://open.kattis.com/problems/kinversions)
  - `[M]` ★ [Another Repeated String Problem](https://toph.co/c/inter-university-sust-cse-carnival-2024)
  - `[M]` ★ [Fuzzy Search](https://codeforces.com/contest/528/problem/D)
  - `[M]` [Rusty String](https://codeforces.com/problemset/problem/827/E)
  - `[M]` [Substring Search](https://codeforces.com/problemset/problem/1334/G)
  - `[M]` ★ [Mosaic Browsing](https://open.kattis.com/problems/mosaicbrowsing)
  - `[M]` [Yet Another String Matching Problem](https://codeforces.com/problemset/problem/954/I)
  - `[M]` ★ [Wildcard Pattern Matching](https://judge.yosupo.jp/problem/wildcard_pattern_matching)
  - `[H]` ★ [Zimpha Fan Club](https://codeforces.com/contest/1975/problem/G)

### 7.2 Hashing

**Subcategory ID:** `hashing` · **Topics:** 4

#### 7.2.1 String Hashing

- **ID:** `string_hashing` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/string_hashing
- **Templates (1):**
  - [String Hashing.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/String%20Hashing.cpp)
- **Resources (6):**
  - ★ [String Hashing | CP Algorithms](https://cp-algorithms.com/string/string-hashing.html#toc-tgt-7)
  - [Rabin-Karp Algorithm for string matching | CP Algorithms](https://cp-algorithms.com/string/rabin-karp.html)
  - ★ [\[Tutorial\] Rolling hash and 8 interesting problems \[Editorial\] By dmkz](https://codeforces.com/blog/entry/60445)
  - [26.3 String hashing | CPH](https://usaco.guide/CPH.pdf#page=255)
  - ★ [How to blow up too weak hashing without thinking By physics0523](https://codeforces.com/blog/entry/129094)
  - [On the mathematics behind rolling hashes and anti-hash tests](https://codeforces.com/blog/entry/60442)
- **Problems (41):**
  - `[E]` ★ [String Matching](https://cses.fi/problemset/task/1753)
  - `[E]` ★ [Pattern Find](https://www.spoj.com/problems/NAJPF/)
  - `[E]` [A Needle in the Haystack](https://www.spoj.com/problems/NHAY/)
  - `[E]` ★ [MUH and Cube Walls](https://codeforces.com/problemset/problem/471/D)
  - `[E]` ★ [String Hashing](https://open.kattis.com/problems/hashing)
  - `[E]` ★ [Finding Border](https://cses.fi/problemset/task/1732)
  - `[E]` ★ [Finding Periods](https://cses.fi/problemset/task/1733)
  - `[E]` ★ [Minimal Rotation](https://cses.fi/problemset/task/1110)
  - `[E]` ★ [Longest Palindrome](https://cses.fi/problemset/task/1111)
  - `[E]` ★ [Enumerate Palindromes](https://judge.yosupo.jp/problem/enumerate_palindromes)
  - `[E]` ★ [Longest Common Substring](https://judge.yosupo.jp/problem/longest_common_substring)
  - `[E]` ★ [Good Substrings](https://codeforces.com/contest/271/problem/D)
  - `[E]` ★ [Ada and Spring Cleaning](https://www.spoj.com/problems/ADACLEAN/)
  - `[E]` ★ [Non-Palindromic Substring](https://codeforces.com/contest/1943/problem/B)
  - `[E]` ★ [Product Equality](https://atcoder.jp/contests/abc339/tasks/abc339_f)
  - `[E]` ★ [Palindromic Partitions](https://oj.uz/problem/view/CEOI17_palindromic)
  - `[M]` [Kefa and Watch](https://codeforces.com/problemset/problem/580/E)
  - `[M]` [Digit Tree](https://codeforces.com/contest/716/problem/E)
  - `[M]` ★ [Unique Substrings Query](https://toph.co/p/unique-substrings-query)
  - `[M]` ★ [Extend to Palindrome](https://www.spoj.com/problems/EPALIN/)
  - `[M]` ★ [Power Strings](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1239)
  - `[M]` ★ [Password](https://codeforces.com/problemset/problem/126/B)
  - `[M]` ★ [String Transformation](https://codeforces.com/problemset/problem/119/D)
  - `[M]` ★ [Palindrome Queries](https://cses.fi/problemset/task/2420)
  - `[M]` [Double Profiles](https://codeforces.com/problemset/problem/154/C)
  - `[M]` [The Gift Of Raksha Bandhan](https://www.codechef.com/problems/INSQ15_A)
  - `[M]` [Detection of Extraterrestrial](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3163)
  - `[M]` ★ [Games on a CD](https://codeforces.com/contest/727/problem/E)
  - `[M]` [Buzzwords](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2955)
  - `[M]` [String Compression](https://codeforces.com/contest/825/problem/F)
  - `[M]` ★ [Palindromic characteristics](https://codeforces.com/contest/835/problem/D)
  - `[M]` [Test](https://codeforces.com/problemset/problem/25/E)
  - `[M]` [Gift Boxes](https://www.hackerrank.com/contests/womens-codesprint-5/challenges/gift-boxes/problem)
  - `[M]` [Deletion of Repeats](https://codeforces.com/contest/19/problem/C)
  - `[M]` ★ [Palindrome Degree](https://codeforces.com/contest/7/problem/D)
  - `[M]` ★ [Jitu and Strings](https://www.hackerrank.com/contests/ab-yeh-kar-ke-dikhao/challenges/jitu-and-strings/problem)
  - `[M]` ★ [Strings - 3](https://acmp.ru/index.asp?main=task&id_task=829&locale=en)
  - `[M]` ★ [Searching for Strings](https://dmoj.ca/problem/ccc20s3)
  - `[M]` [Check Transcription](https://codeforces.com/problemset/problem/1056/E)
  - `[M]` ★ [Fullmetal Alchemist II](https://codeforces.com/gym/104048/problem/K)
  - `[H]` [SubInversing](https://www.codechef.com/problems/SUBINVER)

#### 7.2.2 2D String Hashing

- **ID:** `2d_string_hashing` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/2d_string_hashing
- **Templates (1):**
  - [String Hashing 2D.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/String%20Hashing%202D.cpp)
- **Resources (1):**
  - [Hashing a board](https://codeforces.com/blog/entry/63588)
- **Problems (2):**
  - `[E]` ★ [Grid search](https://codeforces.com/gym/105446/problem/G)
  - `[M]` ★ [Matrix Matcher](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1960)

#### 7.2.3 XOR Hashing

- **ID:** `xor_hashing` · **Difficulty:** Medium · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/xor_hashing
- **Resources (2):**
  - ★ [XOR Hashing \[TUTORIAL\] By humbertoyusta](https://codeforces.com/blog/entry/85900)
  - ★ [An analysis on the error rate of Zobrist Hashing (Xor Hashing) By kinoud](https://codeforces.com/blog/entry/129907)
- **Problems (16):**
  - `[E]` [Robin Hood Archery](https://codeforces.com/contest/2014/problem/H)
  - `[M]` ★ [Three Occurrences](https://codeforces.com/problemset/problem/1418/G)
  - `[M]` ★ [Square Subsets](https://codeforces.com/contest/895/problem/C)
  - `[M]` ★ [Hossam and Range Minimum Query](https://codeforces.com/contest/1771/problem/F)
  - `[M]` ★ [The Number of Subpermutations](https://codeforces.com/problemset/problem/1175/F)
  - `[M]` [EP-Palindromes](https://toph.co/p/ep-palindromes)
  - `[M]` ★ [Prefix Equality](https://atcoder.jp/contests/abc250/tasks/abc250_e)
  - `[M]` [G2. Light Bulbs (Hard Version)](https://codeforces.com/contest/1914/problem/G2)
  - `[M]` ★ [Is It A Square?](https://toph.co/p/is-it-a-square)
  - `[M]` ★ [XORificator](https://codeforces.com/contest/1977/problem/D)
  - `[H]` ★ [The Untended Antiquity](https://codeforces.com/problemset/problem/869/E)
  - `[H]` ★ [Hyperregular Bracket Strings](https://codeforces.com/problemset/problem/1830/C)
  - `[H]` ★ [Number Game on a Tree](https://www.hackerrank.com/contests/hourrank-17/challenges/number-game-on-a-tree/problem)
  - `[H]` [Quadratic Set](https://codeforces.com/contest/1622/problem/F)
  - `[H]` ★ [Kazaee](https://codeforces.com/contest/1746/problem/F)
  - `[H]` [Odd Mineral Resource](https://codeforces.com/contest/1479/problem/D)

#### 7.2.4 Multiset Hashing

- **ID:** `multiset_hashing` · **Difficulty:** Medium · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/multiset_hashing
- **Resources (1):**
  - [Hashing and Probability of Collision | rng_58](https://rng-58.blogspot.com/2017/02/hashing-and-probability-of-collision.html)
- **Problems (6):**
  - `[E]` ★ [Rearrange Query](https://atcoder.jp/contests/abc367/tasks/abc367_f)
  - `[M]` ★ [Searching for Strings](https://dmoj.ca/problem/ccc20s3)
  - `[M]` [Amer and Graphs](https://codeforces.com/gym/101808/problem/B)
  - `[M]` [Ivan Pesic and His World Tour](https://www.codechef.com/problems/QRYLAND)
  - `[H]` ★ [Cloning](https://www.codechef.com/problems/CLONEME)
  - `[H]` ★ [Frequency Mismatch (Hard Version)](https://codeforces.com/contest/1957/problem/F2)

### 7.3 Aho Corasick

**Subcategory ID:** `aho_corasick` · **Topics:** 2

#### 7.3.1 Aho Corasick

- **ID:** `aho_corasick` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/aho_corasick
- **Templates (2):**
  - [Aho Corasick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Aho%20Corasick.cpp)
  - [Aho Corasick All Pair Occurrence Relation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Aho%20Corasick%20All%20Pair%20Occurrence%20Relation.cpp)
- **Resources (3):**
  - ★ [Aho-Corasick algorithm | CP Algorithms](https://cp-algorithms.com/string/aho_corasick.html)
  - ★ [Aho-Coresick algorithm By Pavel Mavrin](https://www.youtube.com/watch?v=w9-n3jW7q3s)
  - [Aho-Corasick algorithm. Construction By adamant](https://codeforces.com/blog/entry/14854)
- **Problems (20):**
  - `[E]` ★ [Finding Patterns](https://cses.fi/problemset/task/2102)
  - `[E]` ★ [Counting Patterns](https://cses.fi/problemset/task/2103)
  - `[E]` [Substring Frequency (II)](https://lightoj.com/problem/substring-frequency-ii)
  - `[E]` ★ [String Multimatching](https://open.kattis.com/problems/stringmultimatching)
  - `[E]` [Prefix Lookup](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2637)
  - `[E]` [SMS](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2112)
  - `[E]` [I Love Strings!!](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1620)
  - `[E]` [Obscene Words Filter](https://acm.timus.ru/problem.aspx?space=1&num=1269)
  - `[E]` [Censored!](https://acm.timus.ru/problem.aspx?space=1&num=1158)
  - `[M]` ★ [e-Government](https://codeforces.com/contest/163/problem/E)
  - `[M]` ★ [Word Combinations](https://cses.fi/problemset/task/1731)
  - `[M]` ★ [ABCD Strings](https://www.hackerearth.com/problem/algorithm/abcd-strings/)
  - `[M]` [Passwords](https://codeforces.com/gym/101174/problem/E)
  - `[M]` ★ [Frequency of String](https://codeforces.com/problemset/problem/963/D)
  - `[M]` [x-prime Substrings](https://codeforces.com/problemset/problem/1400/F)
  - `[M]` [Buying a New String](https://www.codechef.com/MAY20A/problems/TWOSTRS)
  - `[M]` ★ [Bracket Groups](https://codeforces.com/contest/2144/problem/F)
  - `[H]` [A task for substrings](https://codeforces.com/contest/1801/problem/G)
  - `[H]` [Indie Album](https://codeforces.com/contest/1207/problem/G)
  - `[VH]` ★ [Birthday](https://codeforces.com/contest/590/problem/E)

#### 7.3.2 Dynamic Aho Corasick

- **ID:** `dynamic_aho_corasick` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_aho_corasick
- **Templates (1):**
  - [Aho Corasick Dynamic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Aho%20Corasick%20Dynamic.cpp)
- **Resources (2):**
  - ★ [Aho-Corasick with additions](https://codeforces.com/blog/entry/10725?#comment-160742)
  - [Idea 4 of General ideas By adamant](https://codeforces.com/blog/entry/48417)
- **Problems (1):**
  - `[M]` ★ [String Set Queries](https://codeforces.com/contest/710/problem/F)

### 7.4 Suffix Structures

**Subcategory ID:** `suffix_structures` · **Topics:** 6

#### 7.4.1 Suffix Array

- **ID:** `suffix_array` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/suffix_array
- **Templates (1):**
  - [Suffix Array.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Suffix%20Array.cpp)
- **Resources (3):**
  - ★ [Suffix Array | CP Algorithms](https://cp-algorithms.com/string/suffix-array.html)
  - ★ [Suffix Array » Step 1-5 | CF EDU](https://codeforces.com/edu/course/2/lesson/2)
  - [A tutorial on Suffix Arrays | kuruma](https://discuss.codechef.com/t/a-tutorial-on-suffix-arrays/2950)
- **Problems (47):**
  - `[E]` ★ [Suffix Array](https://judge.yosupo.jp/problem/suffixarray)
  - `[E]` ★ [Suffix Array and LCP](https://codeforces.com/edu/course/2/lesson/2/4/practice/contest/269119/problem/A)
  - `[E]` ★ [Substring Search](https://codeforces.com/edu/course/2/lesson/2/3/practice/contest/269118/problem/A)
  - `[E]` ★ [Counting Patterns](https://cses.fi/problemset/task/2103)
  - `[E]` ★ [Distinct Substrings](https://cses.fi/problemset/task/2105)
  - `[E]` ★ [Repeating Substring](https://cses.fi/problemset/task/2106)
  - `[E]` ★ [Sorting Substrings](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/C)
  - `[E]` ★ [Substring Order I](https://cses.fi/problemset/task/2108)
  - `[E]` ★ [Substring Order II](https://cses.fi/problemset/task/2109)
  - `[E]` ★ [Lexicographical Substring Search](https://www.spoj.com/problems/SUBLEX/)
  - `[E]` ★ [Substring Distribution](https://cses.fi/problemset/task/2110)
  - `[E]` [Number of Substrings](https://judge.yosupo.jp/problem/number_of_substrings)
  - `[E]` ★ [Longest Common Substring](https://judge.yosupo.jp/problem/longest_common_substring)
  - `[E]` ★ [Longest Common Substring II](https://www.spoj.com/problems/LCS2/)
  - `[E]` ★ [Ada and Spring Cleaning](https://www.spoj.com/problems/ADACLEAN/)
  - `[E]` ★ [Pattern Positions](https://cses.fi/problemset/task/2104)
  - `[E]` [Editor](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3664)
  - `[E]` ★ [Substrings and Repetitions](https://www.codechef.com/problems/ANUSAR)
  - `[E]` [Ada and Terramorphing](https://www.spoj.com/problems/ADAPHOTO/)
  - `[E]` [JARVIS and LCP](https://www.codechef.com/problems/INSQ16F)
  - `[E]` [The longest constant gene](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3668)
  - `[E]` [Martian Strings](https://codeforces.com/problemset/problem/149/E)
  - `[M]` ★ [Substring Symphony](https://codeforces.com/gym/105973/problem/H)
  - `[M]` ★ [Frequency of String](https://codeforces.com/problemset/problem/963/D)
  - `[M]` [Liar](https://codeforces.com/contest/822/problem/E)
  - `[M]` [Entangled Strings](https://www.codechef.com/problems/TANGLED)
  - `[M]` [Top 10](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3695)
  - `[M]` [File Recover](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3343)
  - `[M]` [Stammering Aliens](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3358)
  - `[M]` ★ [Forbidden Indices](https://codeforces.com/contest/873/problem/F)
  - `[M]` ★ [Fake News (hard)](https://codeforces.com/contest/802/problem/I)
  - `[M]` ★ [Borders](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/D)
  - `[M]` ★ [Refrain](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/E)
  - `[M]` ★ [Periodic Substring](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/F)
  - `[M]` [Two Prefixes](https://codeforces.com/contest/1090/problem/J)
  - `[M]` [Standing Out from the Herd](https://usaco.org/index.php?page=viewproblem2&cpid=768)
  - `[M]` [Common Prefixes](https://atcoder.jp/contests/abc213/tasks/abc213_f)
  - `[H]` ★ [Rabbit's String](https://vjudge.net/problem/HDU-5030)
  - `[H]` ★ [Paper task](https://codeforces.com/problemset/problem/653/F)
  - `[H]` ★ [Tandem](https://www.codechef.com/problems/TANDEM)
  - `[H]` [Tricky and Clever Password](https://codeforces.com/contest/30/problem/E)
  - `[H]` ★ [Little Elephant and Strings](https://codeforces.com/problemset/problem/204/E)
  - `[H]` ★ [Misha and LCP on Tree](https://codeforces.com/contest/504/problem/E)
  - `[H]` ★ [Inverse Suffix Array](https://cses.fi/problemset/task/3225)
  - `[H]` [K-th similar password](https://codeforces.com/group/Rilx5irOux/contest/479250/problem/K)
  - `[H]` [The Story of Stringland](https://toph.co/p/the-story-of-stringland)
  - `[VH]` [Divljak](https://dmoj.ca/problem/coci14c5p6)

#### 7.4.2 Isomorphic Suffix Array

- **ID:** `isomorphic_suffix_array` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/isomorphic_suffix_array
- **Templates (1):**
  - [Suffix Array Isomorphic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Suffix%20Array%20Isomorphic.cpp)
- **Problems (1):**
  - `[M]` ★ [Similar Strings](https://www.hackerrank.com/challenges/similar-strings/problem)

#### 7.4.3 Dynamic Suffix Array

- **ID:** `dynamic_suffix_array` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_suffix_array
- **Templates (2):**
  - [3SHz0M29](https://pastebin.com/3SHz0M29)
  - [2MrMBR](https://ideone.com/2MrMBR)
- **Resources (1):**
  - [\[Tutorial\] Dynamic Suffix Arrays By brunomont](https://codeforces.com/blog/entry/93042)
- **Problems (1):**
  - `[M]` ★ [May I Add a Letter?](https://codeforces.com/gym/103185/problem/M)

#### 7.4.4 Suffix Automaton

- **ID:** `suffix_automaton` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/suffix_automaton
- **Templates (1):**
  - [Suffix Automaton.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Suffix%20Automaton.cpp)
- **Resources (3):**
  - ★ [Suffix Automaton | CP Algorithms](https://cp-algorithms.com/string/suffix-automaton.html)
  - [A short guide to suffix automata By quasisphere](https://codeforces.com/blog/entry/20861)
  - [Obtaining suffix array from suffix automaton By adamant](https://codeforces.com/blog/entry/12280)
- **Problems (21):**
  - `[E]` ★ [Finding Patterns](https://cses.fi/problemset/task/2102)
  - `[E]` ★ [Counting Patterns](https://cses.fi/problemset/task/2103)
  - `[E]` ★ [Distinct Substrings](https://cses.fi/problemset/task/2105)
  - `[E]` ★ [Substring Order I](https://cses.fi/problemset/task/2108)
  - `[E]` ★ [Substring Order II](https://cses.fi/problemset/task/2109)
  - `[E]` ★ [Substring Distribution](https://cses.fi/problemset/task/2110)
  - `[E]` [Number of Substrings](https://judge.yosupo.jp/problem/number_of_substrings)
  - `[E]` ★ [Pattern Positions](https://cses.fi/problemset/task/2104)
  - `[E]` ★ [Longest Common Substring](https://judge.yosupo.jp/problem/longest_common_substring)
  - `[E]` ★ [Substrings and Repetitions](https://www.codechef.com/problems/ANUSAR)
  - `[E]` [The longest constant gene](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3668)
  - `[E]` ★ [Longest Common Substring II](https://www.spoj.com/problems/LCS2/)
  - `[E]` ★ [Lexicographical Substring Search](https://www.spoj.com/problems/SUBLEX/)
  - `[E]` ★ [Delicious Dessert](https://codeforces.com/contest/1780/problem/G)
  - `[M]` ★ [Forbidden Indices](https://codeforces.com/contest/873/problem/F)
  - `[M]` ★ [Borders](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/D)
  - `[M]` ★ [Refrain](https://codeforces.com/edu/course/2/lesson/2/5/practice/contest/269656/problem/E)
  - `[M]` ★ [Cyclical Quest](https://codeforces.com/problemset/problem/235/C)
  - `[M]` ★ [Fake News (hard)](https://codeforces.com/contest/802/problem/I)
  - `[M]` ★ [Drawing](https://www.codechef.com/problems/PRDRAW)
  - `[H]` ★ [Little Elephant and Strings](https://codeforces.com/problemset/problem/204/E)

#### 7.4.5 [Problem] Distinct Substring Queries in Range

- **ID:** `suffix_automaton_ft_distinct_substring_queries_in_range` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/suffix_automaton_ft_distinct_substring_queries_in_range
- **Templates (1):**
  - [Suffix Automaton Distinct Substring Queries in Range.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Suffix%20Automaton%20Distinct%20Substring%20Queries%20in%20Range.cpp)
- **Resources (1):**
  - [The history of some recurring problem By adamant](https://codeforces.com/blog/entry/62331)
- **Problems (4):**
  - `[M]` ★ [How Many Substrings?](https://www.hackerrank.com/challenges/how-many-substrings/problem)
  - `[M]` ★ [To Queue or not to Queue](https://www.codechef.com/problems/TMP01)
  - `[M]` [Chef and Substrings](https://www.codechef.com/problems/GERALD3)
  - `[H]` ★ [Incomparable Pairs](https://codeforces.com/gym/102129/problem/I)

#### 7.4.6 Suffix Tree

- **ID:** `suffix_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/suffix_tree
- **Templates (1):**
  - [sT8Vd1](https://ideone.com/sT8Vd1)
- **Resources (3):**
  - ★ [Suffix Tree. Ukkonen's Algorithm | CP Algorithms](https://cp-algorithms.com/string/suffix-tree-ukkonen.html)
  - [Suffix tree. Ukkonen's algorithm By adamant](https://codeforces.com/blog/entry/16780)
  - [Fast String Searching With Suffix Trees: Tutorial by Mark Nelson](https://www.cs.otago.ac.nz/cosc348/alignments/SuffixTreesTutorial.pdf)
- **Problems (2):**
  - `[M]` [Equivalent Suffix Tries](https://www.codechef.com/JULY12/problems/EST)
  - `[M]` ★ [Longest Common Substring](https://www.spoj.com/problems/LCS/)

### 7.5 Palindromes

**Subcategory ID:** `palindromes` · **Topics:** 5

#### 7.5.1 Palindromic Tree

- **ID:** `palindromic_tree` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/palindromic_tree
- **Templates (1):**
  - [Palindromic Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Palindromic%20Tree.cpp)
- **Resources (3):**
  - ★ [Palindromic tree By ADJA,](https://web.archive.org/web/20160826200104/http://adilet.org/blog/25-09-14/)
  - ★ [Palindromic tree: behind the scenes By adamant](https://codeforces.com/blog/entry/13959)
  - [Palindromic Tree Tutorial By karamkontar](https://codeforces.com/blog/entry/58129)
- **Problems (10):**
  - `[E]` ★ [Eertree](https://judge.yosupo.jp/problem/eertree)
  - `[E]` ★ [Longest Palindrome](https://cses.fi/problemset/task/1111)
  - `[E]` ★ [The Number of Palindromes](http://acm.hdu.edu.cn/showproblem.php?pid=3948)
  - `[E]` ★ [Palindromes and Super Abilities](https://vjudge.net/problem/URAL-1960)
  - `[E]` ★ [Palindromes and Super Abilities 2](https://vjudge.net/problem/URAL-2040)
  - `[E]` ★ [100500 palidnromes](https://vjudge.net/problem/URAL-2058)
  - `[M]` [Palisection](https://codeforces.com/contest/17/problem/E)
  - `[M]` ★ [Virus synthesis](https://codeforces.com/gym/100543/problem/G)
  - `[M]` ★ [The Problem to Slow Down You](https://codeforces.com/gym/100548/problem/G)
  - `[H]` ★ [Palindromadness](https://codeforces.com/gym/102141/problem/F)

#### 7.5.2 Persistent Palindromic Tree

- **ID:** `persistent_palindromic_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_palindromic_tree
- **Templates (2):**
  - [Palindromic Tree Persistent.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Palindromic%20Tree%20Persistent.cpp)
  - [213595](https://judge.yosupo.jp/submission/213595)
- **Resources (1):**
  - ★ [Double-ended eertree By adamant](https://codeforces.com/blog/entry/130276)
- **Problems (4):**
  - `[E]` ★ [Binary Palindrome](https://www.codechef.com/problems/BINPALIN)
  - `[E]` ★ [QueryreuQ](https://codeforces.com/gym/101806/problem/Q)
  - `[M]` ★ [Momoka](https://dmoj.ca/problem/mmcc15p3)
  - `[H]` ★ [Palindromes in Deque](https://judge.yosupo.jp/problem/palindromes_in_deque)

#### 7.5.3 Manachers Algorithm

- **ID:** `manachers_algorithm` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/manachers_algorithm
- **Templates (1):**
  - [Manachers.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Manachers.cpp)
- **Resources (2):**
  - ★ [Manacher's Algorithm | CP Algorithms](https://cp-algorithms.com/string/manacher.html)
  - [Manacher's algorithm and code readability By adamant](https://codeforces.com/blog/entry/12143)
- **Problems (8):**
  - `[E]` ★ [Enumerate Palindromes](https://judge.yosupo.jp/problem/enumerate_palindromes)
  - `[E]` ★ [The Number of Palindromes](http://acm.hdu.edu.cn/showproblem.php?pid=3948)
  - `[E]` ★ [Longest Palindrome](https://cses.fi/problemset/task/1111)
  - `[E]` ★ [Extend to Palindrome](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2470)
  - `[E]` [Prefix-Suffix Palindrome (Hard version)](https://codeforces.com/contest/1326/problem/D2)
  - `[E]` ★ [QueryreuQ](https://codeforces.com/gym/101806/problem/Q)
  - `[E]` ★ [Non-Palindromic Substring](https://codeforces.com/contest/1943/problem/B)
  - `[M]` ★ [Palindromes](https://open.kattis.com/problems/palindromes)

#### 7.5.4 [Problem] Minimum Palindrome Factorization

- **ID:** `minimum_palindrome_factorization` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_palindrome_factorization
- **Templates (1):**
  - [Minimum Palindrome Factorization.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Minimum%20Palindrome%20Factorization.cpp)
- **Resources (1):**
  - [A Subquadratic Algorithm for Minimum Palindromic Factorization](https://arxiv.org/abs/1403.2431)
- **Problems (2):**
  - `[E]` ★ [100500 palidnromes](https://vjudge.net/problem/URAL-2058)
  - `[M]` ★ [Reverses](https://codeforces.com/problemset/problem/906/E)

#### 7.5.5 [Problem] Number of Palindromes in Range

- **ID:** `number_of_palindromes_in_range` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_palindromes_in_range
- **Templates (1):**
  - [Number of Palindromes in Range.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Number%20of%20Palindromes%20in%20Range.cpp)
- **Resources (1):**
  - ★ [A comment by Noam527](https://codeforces.com/blog/entry/63105?#comment-470339)
- **Problems (2):**
  - `[M]` ★ [Palindromes](https://open.kattis.com/problems/palindromes)
  - `[M]` ★ [Queries for Number of Palindromes](https://codeforces.com/contest/245/problem/H)

### 7.6 Longest Common Subsequence (LCS)

**Subcategory ID:** `lcs` · **Topics:** 5

#### 7.6.1 Longest Common Subsequence (LCS)

- **ID:** `lcs` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/lcs
- **Templates (1):**
  - [124670](https://codeforces.com/blog/entry/124670)
- **Resources (6):**
  - ★ [Longest Common Subsequence | Programiz](https://www.programiz.com/dsa/longest-common-subsequence)
  - ★ [Longest Common Subsequence (LCS) | Geeks for Geeks](https://www.geeksforgeeks.org/longest-common-subsequence-dp-4/)
  - [Longest Common Subsequence (LCS) in DP Playlist By Algorithms_with_Shayan](https://codeforces.com/blog/entry/124670)
  - [Longest Common Subsequence - Dynamic Programming - Leetcode 1143](https://www.youtube.com/watch?v=Ua0GhsJSlWM)
  - ★ [how to find the LCS of two permutations per nlogn By LinkCatList](https://codeforces.com/blog/entry/99907)
  - ★ [Converting LCS to LIS | hriss95](https://codeforces.com/blog/entry/8767?#comment-144922)
- **Problems (5):**
  - `[E]` ★ [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/description/)
  - `[E]` ★ [LCS](https://atcoder.jp/contests/dp/tasks/dp_f)
  - `[E]` [Three Strings](https://codeforces.com/contest/2050/problem/E)
  - `[M]` ★ [Yet another permutation problem](https://codeforces.com/gym/104349/problem/D)
  - `[M]` ★ [Gargari and Permutations](https://codeforces.com/problemset/problem/463/D)

#### 7.6.2 All Substring Longest Common Subsequence

- **ID:** `all_substring_longest_common_subsequence` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/all_substring_longest_common_subsequence
- **Templates (1):**
  - [All Substring Longest Common Subsequence.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/All%20Substring%20Longest%20Common%20Subsequence.cpp)
- **Resources (2):**
  - ★ [An all-substrings common subsequence algorithm | Paper](https://www.sciencedirect.com/science/article/pii/S0166218X07002727)
  - ★ [\[Tutorial\] On Range LIS Queries, Part 1 By ko_osaga](https://codeforces.com/blog/entry/111625)
- **Problems (5):**
  - `[E]` ★ [Total LCS](https://codeforces.com/gym/101237/problem/G)
  - `[E]` [LCS 9](https://www.acmicpc.net/problem/25954)
  - `[E]` [Round words](https://oj.uz/problem/view/IZhO13_rowords)
  - `[M]` ★ [Prefix-Substring LCS](https://judge.yosupo.jp/problem/prefix_substring_lcs)
  - `[M]` ★ [Square Subsequences](https://codeforces.com/gym/103652/problem/F)

#### 7.6.3 Bit LCS

- **ID:** `bit_lcs` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bit_lcs
- **Templates (1):**
  - [Bit LCS.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Bit%20LCS.cpp)
- **Resources (1):**
  - [A Bit-String Longest-Common-Subsequence Algorithm](https://users.monash.edu/~lloyd/tildeStrings/Alignment/86.IPL.html)
- **Problems (1):**
  - `[E]` ★ [Longest Common Subsequence](https://www.spoj.com/problems/LCS0/)

#### 7.6.4 Cyclic LCS

- **ID:** `cyclic_lcs` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/cyclic_lcs
- **Templates (1):**
  - [Cyclic LCS.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Cyclic%20LCS.cpp)
- **Resources (1):**
  - [Solving Cyclic Longest Common Subsequence in Quadratic Time | Andy Nguyen](https://arxiv.org/abs/1208.0396)

#### 7.6.5 LCS on RLE compressed string

- **ID:** `lcs_on_rle_compressed_string` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lcs_on_rle_compressed_string
- **Resources (1):**
  - [Matching for Run-Length Encoded Strings](https://docs.lib.purdue.edu/cgi/viewcontent.cgi?article=2354&context=cstech)

### 7.7 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 5

#### 7.7.1 Balanced Brackets

- **ID:** `balanced_brackets` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/balanced_brackets
- **Resources (2):**
  - ★ [Balanced bracket sequences | CP Algorithms](https://cp-algorithms.com/combinatorics/bracket_sequences.html)
  - ★ [Check for Balanced Brackets in an expression | Geeks for Geeks](https://www.geeksforgeeks.org/check-for-balanced-parentheses-in-an-expression/)
- **Problems (20):**
  - `[E]` ★ [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/description/)
  - `[E]` ★ [Bracket Sequences I](https://cses.fi/problemset/task/2064)
  - `[E]` [Jatayu's Balanced Bracket Sequence](https://codeforces.com/problemset/problem/1726/C)
  - `[E]` ★ [Bracket Subsequence](https://codeforces.com/problemset/problem/1023/C)
  - `[E]` [Serval and Parenthesis Sequence](https://codeforces.com/contest/1153/problem/C)
  - `[E]` [Bracket Sequence](https://codeforces.com/problemset/problem/223/A)
  - `[E]` [Replace To Make Regular Bracket Sequence](https://codeforces.com/problemset/problem/612/C)
  - `[M]` ★ [Longest Regular Bracket Sequence](https://codeforces.com/problemset/problem/5/C)
  - `[M]` ★ [Bracket Sequences II](https://cses.fi/problemset/task/2187)
  - `[M]` ★ [Anton and School - 2](https://codeforces.com/contest/785/problem/D)
  - `[M]` ★ [Bracket Substring](https://codeforces.com/problemset/problem/1015/F)
  - `[M]` ★ [Pieces of Parentheses](https://open.kattis.com/problems/piecesofparentheses)
  - `[M]` ★ [Correct Bracket Sequence Editor](https://codeforces.com/problemset/problem/670/E)
  - `[M]` ★ [Streets of Working Lanterns - 2](https://codeforces.com/gym/101341/problem/A)
  - `[M]` ★ [Parenthesis Checking](https://atcoder.jp/contests/abc223/tasks/abc223_f)
  - `[M]` ★ [Sereja and Brackets](https://codeforces.com/contest/380/problem/C)
  - `[M]` [Invertible Bracket Sequences](https://codeforces.com/contest/1976/problem/D)
  - `[M]` [Most Valuable Parentheses](https://atcoder.jp/contests/abc407/tasks/abc407_e)
  - `[M]` ★ [Bracket Groups](https://codeforces.com/contest/2144/problem/F)
  - `[H]` ★ [Hyperregular Bracket Strings](https://codeforces.com/problemset/problem/1830/C)

#### 7.7.2 Expression Parsing

- **ID:** `expression_parsing` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/expression_parsing
- **Templates (1):**
  - [Expression Parsing.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Expression%20Parsing.cpp)
- **Resources (1):**
  - [Expression parsing | CP Algorithms](https://cp-algorithms.com/string/expression_parsing.html)
- **Problems (8):**
  - `[E]` ★ [Expression Parsing](https://www.codechef.com/problems/CDM01)
  - `[E]` [Equation](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=668)
  - `[E]` ★ [Transform the Expression](https://www.spoj.com/problems/ONP/)
  - `[E]` ★ [Evaluate simple RPN expression](https://www.spoj.com/problems/RPNEVAL/)
  - `[E]` [Tertiary Calculator](https://www.spoj.com/problems/SBE201A6/)
  - `[M]` ★ [Vanya and Brackets](https://codeforces.com/problemset/problem/552/E)
  - `[M]` ★ [Children's Math](https://lightoj.com/problem/children-s-math)
  - `[M]` [Equivalent Boolean Expressions](https://lightoj.com/problem/equivalent-boolean-expression)

#### 7.7.3 Lyndon Factorization / Duval Algorithm

- **ID:** `lyndon_factorization` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lyndon_factorization
- **Templates (1):**
  - [lyndon_factorization.html](https://cp-algorithms.com/string/lyndon_factorization.html)
- **Resources (3):**
  - ★ [Lyndon factorization | CP Algorithms](https://cp-algorithms.com/string/lyndon_factorization.html)
  - ★ [Random notes on Lyndon decomposition By ko_osaga](https://codeforces.com/blog/entry/106725)
  - [Simple Linear and Effectively Duval Algorithm for Lyndon Factorization By SPyofgame,](https://codeforces.com/blog/entry/89629)
- **Problems (12):**
  - `[E]` ★ [Lyndon Factorization](https://judge.yosupo.jp/problem/lyndon_factorization)
  - `[E]` ★ [Minimal Rotation](https://cses.fi/problemset/task/1110)
  - `[E]` [Glass Beads](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=660)
  - `[E]` ★ [Longest Lyndon Prefix](https://www.acmicpc.net/problem/23495)
  - `[E]` [Lyndon Words](https://codeforces.com/problemset/gymProblem/100162/G)
  - `[M]` [Repetitions](https://www.acmicpc.net/problem/25111)
  - `[H]` ★ [Run Enumerate](https://judge.yosupo.jp/problem/runenumerate)
  - `[H]` ★ [Decomposition](https://www.acmicpc.net/problem/19020)
  - `[H]` [优秀的拆分](https://uoj.ac/problem/219)
  - `[H]` [Cutting the Line](https://codeforces.com/contest/594/problem/E)
  - `[H]` ★ [Cyclic Shifts](https://www.acmicpc.net/problem/19403)
  - `[VH]` [Two Sequences](https://codeforces.com/contest/1621/problem/I)

#### 7.7.4 Finding Repetitions / Main-Lorentz Algorithm

- **ID:** `main_lorentz_algorithm` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/main_lorentz_algorithm
- **Templates (1):**
  - [main_lorentz.html](https://cp-algorithms.com/string/main_lorentz.html)
- **Resources (1):**
  - ★ [Finding repetitions | CP Algorithms](https://cp-algorithms.com/string/main_lorentz.html)
- **Problems (3):**
  - `[E]` ★ [Repeating Substring](https://cses.fi/problemset/task/2106)
  - `[M]` [Repetitions](https://www.acmicpc.net/problem/25111)
  - `[H]` ★ [Run Enumerate](https://judge.yosupo.jp/problem/runenumerate)

#### 7.7.5 De Bruijn Sequence

- **ID:** `de_bruijn_sequence` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/de_bruijn_sequence
- **Templates (1):**
  - [De Bruijn Sequence.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/De%20Bruijn%20Sequence.cpp)
- **Resources (2):**
  - ★ [de Bruijn sequence | Wiki](https://en.wikipedia.org/wiki/De_Bruijn_sequence)
  - ★ [De Bruijn Sequences | USACO Guide](https://usaco.guide/adv/eulerian-tours?lang=cpp#de-bruijn-sequences)
- **Problems (2):**
  - `[E]` ★ [De Bruijn Sequence](https://cses.fi/problemset/task/1692)
  - `[M]` ★ [Matching Substrings](https://csacademy.com/contest/archive/task/matching-substrings/statement/)

---

## 8. Dynamic Programming (DP)

**Category ID:** `dynamic_programming` · **Subcategories:** 10 · **Topics:** 35

### 8.1 Intro to DP

**Subcategory ID:** `intro_to_dp` · **Topics:** 2

#### 8.1.1 Knapsack and Basic Dynamic Programming

- **ID:** `knapsack` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/knapsack
- **Resources (14):**
  - ★ [Introduction to Dynamic Programming | CP Algorithms](https://cp-algorithms.com/dynamic_programming/intro-to-dp.html)
  - ★ [Dynamic Programming lecture #1 - Fibonacci, iteration vs recursion | Errichto Algorithms](https://www.youtube.com/watch?v=YBSt1jYwVfU)
  - ★ [Dynamic Programming lecture #2 - Coin change, double counting | Errichto Algorithms](https://www.youtube.com/watch?v=1mtvm2ubHCY)
  - ★ [Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges | freeCodeCamp.org](https://www.youtube.com/watch?v=oBt53YbR9Kk)
  - ★ [0/1 Knapsack problem | Dynamic Programming WilliamFiset](https://www.youtube.com/watch?v=cJ21moQpofY)
  - ★ [0/1 Knapsack Problem | Geeks for Geeks](https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10/)
  - [7.1 Coin problem | CPH](https://usaco.guide/CPH.pdf#page=75)
  - ★ [Removing Items in Subset Sum | Editorial](https://atcoder.jp/contests/abc321/editorial/7281)
  - ★ [A Deep Understanding of Dynamic Programming \[Intro / Overview\] | Colin Galen](https://www.youtube.com/watch?v=Clp5c7HvLqs)
  - [Introduction to DP | USACO Guide](https://usaco.guide/gold/intro-dp?lang=cpp)
  - [Knapsack DP | USACO Guide](https://usaco.guide/gold/knapsack?lang=cpp)
  - ★ [AtCoder DP Editorial | Neo Wang](https://nwatx.me/post/atcoderdp)
  - [Paths on Grids | USACO Guide](https://usaco.guide/gold/paths-grids)
  - [Dynamic Programming Series | TLE_Eliminators](https://www.youtube.com/playlist?list=PLcXpkI9A-RZI-xF76L0sZq_u-k_yHz8pd)
- **Problems (52):**
  - `[E]` ★ [Dice Combinations](https://cses.fi/problemset/task/1633)
  - `[E]` ★ [Knapsack 1](https://atcoder.jp/contests/dp/tasks/dp_d)
  - `[E]` ★ [Coin Combinations I](https://cses.fi/problemset/task/1635)
  - `[E]` ★ [Frog 1](https://atcoder.jp/contests/dp/tasks/dp_a)
  - `[E]` ★ [Frog 2](https://atcoder.jp/contests/dp/tasks/dp_b)
  - `[E]` ★ [Removing Digits](https://cses.fi/problemset/task/1637)
  - `[E]` ★ [The Values You Can Make](https://codeforces.com/contest/687/problem/C)
  - `[E]` ★ [Grid Paths](https://cses.fi/problemset/task/1638)
  - `[E]` ★ [Book Shop](https://cses.fi/problemset/task/1158)
  - `[E]` ★ [Array Description](https://cses.fi/problemset/task/1746)
  - `[E]` [Counting Towers](https://cses.fi/problemset/task/2413)
  - `[E]` ★ [Money Sums](https://cses.fi/problemset/task/1745)
  - `[E]` ★ [Removal Game](https://cses.fi/problemset/task/1097)
  - `[E]` ★ [Two Sets II](https://cses.fi/problemset/task/1093)
  - `[E]` [Fruit Feast](https://usaco.org/index.php?page=viewproblem2&cpid=574)
  - `[E]` [Vacation](https://atcoder.jp/contests/dp/tasks/dp_c)
  - `[E]` ★ [LCS](https://atcoder.jp/contests/dp/tasks/dp_f)
  - `[E]` ★ [Grid 1](https://atcoder.jp/contests/dp/tasks/dp_h)
  - `[E]` ★ [Coins](https://atcoder.jp/contests/dp/tasks/dp_i)
  - `[E]` [Talent Show](https://usaco.org/index.php?page=viewproblem2&cpid=839)
  - `[E]` [Knapsack](https://codeforces.com/contest/1446/problem/A)
  - `[E]` [Mortal Kombat Tower](https://codeforces.com/problemset/problem/1418/C)
  - `[E]` ★ [Where is the Ghost](https://toph.co/p/where-is-the-ghost)
  - `[E]` [Colored Balls](https://codeforces.com/problemset/problem/1954/D)
  - `[E]` [Minimizing the Sum](https://codeforces.com/problemset/problem/1969/C)
  - `[E]` [Smithing Skill](https://codeforces.com/contest/1989/problem/D)
  - `[E]` [The least round way](https://codeforces.com/contest/2/problem/B)
  - `[E]` [Arpa's weak amphitheater and Mehrdad's valuable Hoses](https://codeforces.com/contest/742/problem/D)
  - `[E]` [New Rating](https://codeforces.com/contest/2029/problem/C)
  - `[E]` [Pictures with Kittens (easy version)](https://codeforces.com/contest/1077/problem/F1)
  - `[M]` ★ [Minimizing Coins](https://cses.fi/problemset/task/1634)
  - `[M]` ★ [Coin Combinations II](https://cses.fi/problemset/task/1636)
  - `[M]` ★ [#(subset sum = K) with Add and Erase](https://atcoder.jp/contests/abc321/tasks/abc321_f)
  - `[M]` ★ [Round Subset](https://codeforces.com/contest/837/problem/D)
  - `[M]` [Cow Poetry](https://usaco.org/index.php?page=viewproblem2&cpid=897)
  - `[M]` [Exercise](https://usaco.org/index.php?page=viewproblem2&cpid=1043)
  - `[M]` [Maximal Orders of Permutations](https://szkopul.edu.pl/problemset/problem/lGqKS9urITMjTXhpdaHqyoEL/site/?key=statement)
  - `[M]` ★ [Knapsack 2](https://atcoder.jp/contests/dp/tasks/dp_e)
  - `[M]` ★ [Stones](https://atcoder.jp/contests/dp/tasks/dp_k)
  - `[M]` [Deque](https://atcoder.jp/contests/dp/tasks/dp_l)
  - `[M]` ★ [Candies](https://atcoder.jp/contests/dp/tasks/dp_m)
  - `[M]` ★ [Slimes](https://atcoder.jp/contests/dp/tasks/dp_n)
  - `[M]` ★ [Grid 2](https://atcoder.jp/contests/dp/tasks/dp_y)
  - `[M]` [Mr. Kitayuta, the Treasure Hunter](https://codeforces.com/problemset/problem/506/A)
  - `[M]` [Knapsack](https://codeforces.com/problemset/problem/1132/E)
  - `[M]` [The Unbearable Lightness of Weights](https://codeforces.com/contest/1078/problem/B)
  - `[M]` [Porcelain](https://codeforces.com/contest/148/problem/E)
  - `[M]` [Ski Lessons](https://www.acmicpc.net/problem/6114)
  - `[M]` ★ [Yet Another Minimization Problem](https://codeforces.com/contest/1637/problem/D)
  - `[H]` [Cloud computing](https://oj.uz/problem/view/CEOI18_clo)
  - `[H]` ★ [Colorful Subsequence](https://atcoder.jp/contests/abc345/tasks/abc345_e)
  - `[H]` [Moorio Kart](https://usaco.org/index.php?page=viewproblem2&cpid=925)

#### 8.1.2 Knapsack and Subset Sum Optimizations

- **ID:** `subset_sum_in_sqrt` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/subset_sum_in_sqrt
- **Templates (2):**
  - [Bounded Knapsack.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Bounded%20Knapsack.cpp)
  - [Subset Sum in SQRT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Subset%20Sum%20in%20SQRT.cpp)
- **Resources (10):**
  - ★ [Subset sum queries using bitset | Geeks for Geeks](https://www.geeksforgeeks.org/subset-sum-queries-using-bitset/)
  - ★ [\[Tutorial\] Subset Sum Square Root Optimisation By arujbansal](https://codeforces.com/blog/entry/97396)
  - ★ [Decide if a number equals the sum of some submultiset of positive integers By pimenta](https://codeforces.com/blog/entry/49812)
  - ★ [\[Tutorial\] Knapsack, Subset Sum and the (max,+) Convolution By errorgorn](https://codeforces.com/blog/entry/98663)
  - ★ [Unveiling the Bounded Knapsack Problem Florian June Florian June](https://medium.com/@florian_algo/unveiling-the-bounded-knapsack-problem-737d71c4146b)
  - [\[Tutorial\] Optimized solution for Knapsack problem By sdnr1](https://codeforces.com/blog/entry/59606)
  - ★ [\[Tutorial\] Collection of little techniques By -is-this-fft-](https://codeforces.com/blog/entry/100910)
  - ★ [27.2 Integer partitions | CPH](https://usaco.guide/CPH.pdf#page=264)
  - [Integral bounded knapsack problem solvable in O(knapsack_size*num_of_items) | Petr](https://blog.mitrichev.ch/2011/07/integral-bounded-knapsack-problem.html)
  - [Bitsets | Knapsack Again | USACO Guide](https://usaco.guide/plat/bitsets?lang=cpp#knapsack-again)
- **Problems (19):**
  - `[E]` ★ [Money Sums](https://cses.fi/problemset/task/1745)
  - `[E]` ★ [Two Sets II](https://cses.fi/problemset/task/1093)
  - `[E]` ★ [Decreasing Game](https://codeforces.com/problemset/problem/1839/E)
  - `[E]` [Min-Fund Country](https://www.codechef.com/problems/MINFUND)
  - `[E]` ★ [Ada and Coins](https://vjudge.net/problem/SPOJ-ADACOINS)
  - `[M]` ★ [PolandBall and Gifts](https://codeforces.com/contest/755/problem/F)
  - `[M]` ★ [PermuTree (hard version)](https://codeforces.com/contest/1856/problem/E2)
  - `[M]` ★ [Median Sum](https://atcoder.jp/contests/agc020/tasks/agc020_c)
  - `[M]` [Knapsack](https://oj.uz/problem/view/NOI18_knapsack)
  - `[M]` [Tree Upshot](https://www.codechef.com/LTIME101B/problems/TREUPS)
  - `[M]` [Lucky Country](https://codeforces.com/contest/95/problem/E)
  - `[M]` [Eavesdropper Evasion](https://ncpc21.kattis.com/problems/eavesdropperevasion)
  - `[M]` ★ [Subset Sum](https://official.contest.yandex.ru/opencupXX/contest/18290/problems/F/)
  - `[M]` ★ [Jumping sequence](https://atcoder.jp/contests/abc221/tasks/abc221_g)
  - `[M]` ★ [Keyboard](https://www.boi2021.de/wp-content/uploads/2021/04/statement-boi2021-0-keyboard-en.pdf)
  - `[M]` ★ [Count Pairs](https://vjudge.net/problem/SPOJ-ILD18ACP)
  - `[M]` [School Excursion](https://cses.fi/problemset/task/1706)
  - `[M]` [The Values You Can Make](https://codeforces.com/contest/688/problem/E)
  - `[H]` ★ [AB Tree](https://codeforces.com/problemset/problem/1481/F)

### 8.2 Digit DP

**Subcategory ID:** `digit_dp` · **Topics:** 1

#### 8.2.1 Digit DP

- **ID:** `digit_dp` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/digit_dp
- **Templates (1):**
  - [Digit DP.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Digit%20DP.cpp)
- **Resources (5):**
  - ★ [Digit DP By flash_7](https://codeforces.com/blog/entry/53960)
  - [Introduction to Digit Dynamic Programming By kartik8800](https://codeforces.com/blog/entry/84928)
  - [DIGIT DP Tutorial \[ITERATIVE\] By Jon.Snow](https://codeforces.com/blog/entry/77096)
  - ★ [Digit DP "tricks" By gnudgnaoh](https://codeforces.com/blog/entry/95488)
  - [Digit DP Tutorial | Ep - 01 | Complete Explanation | Dynamic Programming | C++ | By Aman Babu](https://www.youtube.com/watch?v=cthI6e5KGgg)
- **Problems (29):**
  - `[E]` ★ [Counting Numbers](https://cses.fi/problemset/task/2220)
  - `[E]` ★ [Investigation](https://vjudge.net/problem/LightOJ-1068)
  - `[E]` ★ [Digit Sum](https://atcoder.jp/contests/dp/tasks/dp_s)
  - `[E]` [Maximum Product](https://codeforces.com/gym/100886/problem/G)
  - `[E]` [Magic Numbers](https://codeforces.com/contest/628/problem/D)
  - `[E]` ★ [Digit Count](https://vjudge.net/problem/LightOJ-1122)
  - `[E]` ★ [Sum of Digits](https://www.spoj.com/problems/CPCRC1C/)
  - `[E]` [Ra-One Numbers](https://www.spoj.com/problems/RAONE/)
  - `[E]` [LUCIFER Number](https://www.spoj.com/problems/LUCIFER/)
  - `[E]` [369 Numbers](https://www.spoj.com/problems/NUMTSN/)
  - `[E]` [Almost Everywhere Zero](https://atcoder.jp/contests/abc154/tasks/abc154_e)
  - `[E]` [Digit Sum](https://www.spoj.com/problems/PR003004/en/)
  - `[E]` [Little Elephant and Interval](https://codeforces.com/problemset/problem/204/A)
  - `[M]` ★ [Noora Number](https://toph.co/p/noora-number)
  - `[M]` ★ [Classy Numbers](https://codeforces.com/contest/1036/problem/C)
  - `[M]` ★ [Segment Sum](https://codeforces.com/contest/1073/problem/E)
  - `[M]` ★ [LIDS](https://toph.co/p/lids)
  - `[M]` ★ [Palindromic Numbers](https://vjudge.net/problem/LightOJ-1205)
  - `[M]` [Chef and Digits](https://www.codechef.com/problems/DGTCNT)
  - `[M]` [Logan and DIGIT IMMUNE numbers](https://www.codechef.com/problems/DIGIMU)
  - `[M]` [Chef and special numbers](https://www.codechef.com/problems/WORKCHEF)
  - `[M]` ★ [The Great Ninja War](https://www.hackerearth.com/problem/algorithm/sallu-bhai-and-ias-8838ac8d/)
  - `[M]` [Balanced Numbers](https://www.spoj.com/problems/BALNUM/)
  - `[M]` ★ [Digit Sum Divisible](https://atcoder.jp/contests/abc336/tasks/abc336_e)
  - `[M]` ★ [Counting Inversion](https://codeforces.com/gym/102040/problem/B)
  - `[M]` [Sums of Digits](https://codeforces.com/problemset/problem/509/C)
  - `[M]` [Odometer](https://usaco.org/index.php?page=viewproblem2&cpid=435&lang=en)
  - `[M]` [Zebra-like Numbers](https://codeforces.com/contest/2086/problem/E)
  - `[H]` [Sanvi and Magical Numbers](https://www.spoj.com/problems/SANVI/)

### 8.3 DP Optimizations

**Subcategory ID:** `dp_optimizations` · **Topics:** 5

#### 8.3.1 Divide and Conquer Optimization

- **ID:** `divide_and_conquer_optimization` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/divide_and_conquer_optimization
- **Templates (1):**
  - [Divide and Conquer Optimization.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Divide%20and%20Conquer%20Optimization.cpp)
- **Resources (6):**
  - ★ [Divide and Conquer DP | CP Algorithms](https://cp-algorithms.com/dynamic_programming/divide-and-conquer-dp.html)
  - ★ [Divide & Conquer Dynamic Programming Optimisation, CSES Subarray Squares | Algorithms Conquered](https://www.youtube.com/watch?v=Ec3fSWk9JOw)
  - [Dynamic Programming Optimization: Divide and Conquer technique | Tozan Southerpacks Redcoder](https://www.youtube.com/watch?v=wLXEWuDWnzI)
  - ★ [Divide & Conquer - DP | USACO Guide](https://usaco.guide/plat/DC-DP?lang=cpp)
  - [\[Bangla\] Divide and Conquer optimization explained by Anik Sarkar](https://www.youtube.com/live/0BDAXKH2GyQ?si=UYPXDaVvgOxJUPTQ)
  - [What is divide and conquer optimization in dynamic programming? | Quora](https://www.quora.com/What-is-divide-and-conquer-optimization-in-dynamic-programming)
- **Problems (23):**
  - `[E]` ★ [Subarray Squares](https://cses.fi/problemset/task/2086)
  - `[E]` ★ [Ciel and Gondolas](https://codeforces.com/contest/321/problem/E)
  - `[E]` ★ [Guardians of the Lunatic](https://www.hackerrank.com/contests/ioi-2014-practice-contest-2/challenges/guardians-lunatics-ioi14/problem)
  - `[E]` ★ [The Bakery](https://codeforces.com/contest/833/problem/B)
  - `[E]` ★ [Levels and Regions](https://codeforces.com/contest/673/problem/E)
  - `[E]` [Guards](https://codeforces.com/gym/103536/problem/A)
  - `[E]` ★ [Ada and Mold](https://www.spoj.com/problems/ADAMOLD/)
  - `[E]` [Bicolored Horses](https://acm.timus.ru/problem.aspx?space=1&num=1167)
  - `[E]` [Circular Barn](https://usaco.org/index.php?page=viewproblem2&cpid=616)
  - `[E]` [Houses and Schools](https://cses.fi/problemset/task/2087/)
  - `[E]` [Leaves](https://www.spoj.com/problems/NKLEAVES/en/)
  - `[M]` ★ [Partition Game](https://codeforces.com/contest/1527/problem/E)
  - `[M]` [Yakiniku Restaurants](https://atcoder.jp/contests/arc067/tasks/arc067_d)
  - `[M]` ★ [Yet Another Minimization Problem](https://codeforces.com/contest/868/problem/F)
  - `[M]` [Chef and Bitwise OR Operation](https://www.codechef.com/problems/CHEFAOR)
  - `[M]` [Mining](https://www.hackerrank.com/contests/world-codesprint-5/challenges/mining)
  - `[M]` ★ [Money for Nothing](https://vjudge.net/problem/Kattis-money)
  - `[M]` [Lannister Army](https://www.spoj.com/problems/LARMY/)
  - `[M]` [Two Sawmills](https://szkopul.edu.pl/problemset/problem/ovRIpLFK3IhyFPjnVXeZtGxH/site/?key=statement)
  - `[M]` [Nafta](https://oj.uz/problem/view/COI15_nafta)
  - `[M]` ★ [Branch Assignment](https://vjudge.net/problem/Gym-101242B)
  - `[M]` [Trucks and Cities](https://codeforces.com/contest/1101/problem/F)
  - `[H]` [Candies and Stones](https://codeforces.com/contest/101/problem/E)

#### 8.3.2 Knuth Optimization

- **ID:** `knuth_optimization` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/knuth_optimization
- **Templates (1):**
  - [Knuth Optimization.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Knuth%20Optimization.cpp)
- **Resources (4):**
  - ★ [Knuth's Optimization | CP Algorithms](https://cp-algorithms.com/dynamic_programming/knuth-optimization.html)
  - ★ [What is Knuth's optimization in dynamic programming? | Quora](https://www.quora.com/What-is-Knuths-optimization-in-dynamic-programming)
  - [Knuth’s Optimization in Dynamic Programming | Geeks for Geeks](https://www.geeksforgeeks.org/knuths-optimization-in-dynamic-programming/)
  - [Quadrangle Inequality Properties By upobir](https://codeforces.com/blog/entry/86306)
- **Problems (7):**
  - `[E]` ★ [Breaking Strings](https://vjudge.net/problem/ZOJ-2860)
  - `[E]` ★ [Knuth Division](https://cses.fi/problemset/task/2088)
  - `[E]` ★ [Cutting Sticks](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=944)
  - `[E]` [Prefix Codes](https://vjudge.net/problem/UVA-12057)
  - `[E]` ★ [Optimal Binary Search Tree](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=1245)
  - `[E]` [Trucks and Cities](https://codeforces.com/problemset/problem/1101/F)
  - `[M]` [Gain Battle Power](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4701)

#### 8.3.3 Aliens Trick / WQS Binary Search

- **ID:** `aliens_trick` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/aliens_trick
- **Resources (6):**
  - ★ [My Take on Aliens' Trick | Mamnoon Siam](https://mamnoonsiam.github.io/posts/attack-on-aliens.html)
  - ★ [Theoretical grounds of lambda optimization By adamant](https://codeforces.com/blog/entry/98334)
  - ★ [Incredibly beautiful DP optimization from N^3 to N log^2 N By linkret](https://codeforces.com/blog/entry/49691)
  - [The Trick From Aliens | SERBANOLOGY](https://www.serbanology.com/vault/The%20Trick%20From%20Aliens)
  - [VK cup eliminations — Levels and Regions — higher limits By Radewoosh](https://codeforces.com/blog/entry/46693)
  - [Lagrangian Relaxation | USACO Guide](https://usaco.guide/adv/lagrange?lang=cpp)
- **Problems (14):**
  - `[E]` ★ [New Year and Handle Change](https://codeforces.com/contest/1279/problem/F)
  - `[E]` ★ [Levels and Regions](https://codeforces.com/contest/673/problem/E)
  - `[E]` [Two Famous Companies](https://www.spoj.com/problems/COMPANYS/)
  - `[M]` ★ [Feast](https://oj.uz/problem/view/NOI19_feast)
  - `[M]` [Building a Tall Barn](https://usaco.org/index.php?page=viewproblem2&cpid=697)
  - `[M]` ★ [Gosha is hunting](https://codeforces.com/contest/739/problem/E)
  - `[M]` ★ [Teleporters](https://codeforces.com/problemset/problem/1661/F)
  - `[M]` [Blazing New Trails](https://open.kattis.com/problems/blazingnewtrails)
  - `[M]` [Akvizna](https://dmoj.ca/problem/coci18c4p5)
  - `[H]` ★ [Aliens](https://oj.uz/problem/view/IOI16_aliens)
  - `[H]` [Popcorn](https://csacademy.com/contest/romanian-ioi-2017-selection-2/task/popcorn/)
  - `[H]` [Honorable Mention](https://codeforces.com/gym/102331/problem/H)
  - `[H]` [Timofey and Docker](https://codeforces.com/contest/2125/problem/F)
  - `[VH]` [April Fools' Problem (hard)](https://codeforces.com/contest/802/problem/O)

#### 8.3.4 1D1D DP Optimization

- **ID:** `1d1d_dp_optimization` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/1d1d_dp_optimization
- **Templates (1):**
  - [1D1D DP.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/1D1D%20DP.cpp)
- **Resources (3):**
  - ★ [1D1D-optimization By seiko.iwasawa](https://codeforces.com/blog/entry/93772)
  - ★ [1D/1D Dynamic Programming Optimization - Part I](https://sites.google.com/site/ubcprogrammingteam/news/1d1ddynamicprogrammingoptimization-parti)
  - [DP optimization | A Simple Blog](https://robert1003.github.io/2020/02/29/dp-opt-knuth.html)
- **Problems (2):**
  - `[E]` ★ [Batch Scheduling](https://vjudge.net/problem/OpenJ_Bailian-1180)
  - `[E]` ★ [Kalila and Dimna in the Logging Industry](https://codeforces.com/contest/319/problem/C)

#### 8.3.5 DP Optimization using Data Structures [Some Practice Problems]

- **ID:** `dp_optimization_using_data_structures` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/dp_optimization_using_data_structures
- **Resources (2):**
  - ★ [\[Tutorial\]Using Segment Trees to solve Dynamic Programming problems By AlexLuchianov](https://codeforces.com/blog/entry/101210)
  - ★ [Dynamic Programming Optimizations (Segment Tree, Convex Hull Trick) | Colin Galen](https://www.youtube.com/watch?v=KX_-7AqcnEU&list=PLDjGkpToBsYCaRoQ-_S5MRxYMuKgHD62w&index=6)
- **Problems (22):**
  - `[E]` ★ [Increasing Subsequence](https://cses.fi/problemset/task/1145)
  - `[E]` ★ [Projects](https://cses.fi/problemset/task/1140)
  - `[E]` ★ [Flowers](https://atcoder.jp/contests/dp/tasks/dp_q)
  - `[E]` ★ [Flat Subsequence](https://atcoder.jp/contests/abl/tasks/abl_d)
  - `[E]` [Smooth Subsequence](https://atcoder.jp/contests/abc339/tasks/abc339_e)
  - `[M]` ★ [Subsequences](https://codeforces.com/contest/597/problem/C)
  - `[M]` [Pillars](https://codeforces.com/contest/474/problem/E)
  - `[M]` [Babaei and Birthday Cake](https://codeforces.com/contest/629/problem/D)
  - `[M]` [Pathwalks](https://codeforces.com/problemset/problem/960/F)
  - `[M]` [Trains and Statistic](https://codeforces.com/contest/675/problem/E)
  - `[M]` ★ [Word Combinations](https://cses.fi/problemset/task/1731)
  - `[M]` [Intervals](https://atcoder.jp/contests/dp/tasks/dp_w)
  - `[M]` [Strip](https://codeforces.com/contest/488/problem/D)
  - `[M]` [Domino Principle](https://codeforces.com/contest/56/problem/E)
  - `[M]` ★ [K-inversions](https://acm.timus.ru/problem.aspx?space=1&num=1523)
  - `[M]` [Cutlet](https://codeforces.com/contest/939/problem/F)
  - `[M]` [Watching Fireworks is Fun](https://codeforces.com/contest/372/problem/C)
  - `[M]` [Hanoi Factory](https://codeforces.com/problemset/problem/777/E)
  - `[M]` ★ [Blocking Elements](https://codeforces.com/contest/1918/problem/D)
  - `[H]` [Linear Kingdom Races](https://codeforces.com/contest/115/problem/E)
  - `[H]` [Coins Exhibition](https://codeforces.com/problemset/problem/930/E)
  - `[H]` [Pictures with Kittens (hard version)](https://codeforces.com/contest/1077/problem/F2)

### 8.4 Convex Hull Trick (CHT)

**Subcategory ID:** `convex_hull_trick` · **Topics:** 2

#### 8.4.1 Convex Hull Trick (CHT) and Dynamic CHT

- **ID:** `cht` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/cht
- **Templates (2):**
  - [Convex Hull Trick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Convex%20Hull%20Trick.cpp)
  - [Dynamic Convex Hull Trick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Dynamic%20Convex%20Hull%20Trick.cpp)
- **Resources (5):**
  - ★ [\[Tutorial\] Convex Hull Trick — Geometry being useful By meooow,](https://codeforces.com/blog/entry/63823)
  - [Convex hull trick and Li Chao tree | CP Algorithms](https://cp-algorithms.com/geometry/convex_hull_trick.html#toc-tgt-2)
  - ★ [Episode 11 - Convex Hull Optimization | Algorithms Live!](https://www.youtube.com/watch?v=OrH2ah4ylv4)
  - [Dynamic Programming Optimizations By indy256](https://codeforces.com/blog/entry/8219)
  - [Convex Hull Trick | USACO Guide](https://usaco.guide/plat/convex-hull-trick?lang=cpp)
- **Problems (42):**
  - `[E]` ★ [Kalila and Dimna in the Logging Industry](https://codeforces.com/contest/319/problem/C)
  - `[E]` ★ [Frog 3](https://atcoder.jp/contests/dp/tasks/dp_z)
  - `[E]` ★ [Bear and Bowling 4](https://codeforces.com/problemset/problem/660/F)
  - `[E]` ★ [Product Sum](https://codeforces.com/problemset/problem/631/E)
  - `[E]` ★ [Troubles](https://codeforces.com/gym/103536/problem/B)
  - `[E]` ★ [Squared Ends](https://csacademy.com/contest/archive/task/squared-ends)
  - `[E]` [Cyclist Race](https://www.codechef.com/JAN16/problems/CYCLRACE)
  - `[E]` ★ [Covered Walkway](https://open.kattis.com/problems/coveredwalkway)
  - `[E]` [Houses and Schools](https://cses.fi/problemset/task/2087/)
  - `[E]` ★ [Levels and Regions](https://codeforces.com/contest/673/problem/E)
  - `[E]` ★ [Segment Add Get Min](https://judge.yosupo.jp/problem/segment_add_get_min)
  - `[E]` [Hit the Coconuts](https://www.codechef.com/problems/CCC)
  - `[E]` [Machine Works](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3547)
  - `[M]` ★ [The Fair Nut and Rectangles](https://codeforces.com/contest/1083/problem/E)
  - `[M]` [Commando](https://dmoj.ca/problem/apio10p1)
  - `[M]` [Two Sawmills](https://szkopul.edu.pl/problemset/problem/ovRIpLFK3IhyFPjnVXeZtGxH/site/?key=statement)
  - `[M]` [Not Escaping](https://codeforces.com/contest/1627/problem/E)
  - `[M]` [Uncle Bogdan and Projections](https://codeforces.com/contest/1388/problem/E)
  - `[M]` [Cats Transport](https://codeforces.com/contest/311/problem/B)
  - `[M]` [Avoiding Airports](https://open.kattis.com/problems/avoidingairports)
  - `[M]` [Jump mission](https://www.codechef.com/OCT15/problems/JUMP/)
  - `[M]` [Pizza Delivery](https://www.codechef.com/JULY18A/problems/PDELIV)
  - `[M]` [Land Acquisition](https://www.spoj.com/problems/ACQUIRE/)
  - `[M]` [Cow School](http://poj.org/problem?id=3266)
  - `[M]` [Good Inflation](https://www.spoj.com/problems/GOODG/)
  - `[M]` [Harbingers](https://oj.uz/problem/view/CEOI09_harbingers)
  - `[M]` [Split the sequence](https://oj.uz/problem/view/APIO14_sequence)
  - `[M]` [Lightning Conductor](https://szkopul.edu.pl/problemset/problem/iYVwsAcHHCRZzAtQh0QFKbsu/site/?key=statement)
  - `[M]` [Frogs](https://szkopul.edu.pl/problemset/problem/HH7LQVRVHom1g8YRe9423d1P/site/?key=statement)
  - `[M]` [Cookie Clicker](https://codeforces.com/problemset/problem/377/E)
  - `[M]` [Igloo Skyscraper](https://codeforces.com/contest/91/problem/E)
  - `[M]` [Cable Plan](https://codeforces.com/gym/105811/problem/E)
  - `[M]` [Board Game](https://codeforces.com/gym/104252/problem/B)
  - `[M]` [Bunnies](https://www.spoj.com/problems/BUNNIES/)
  - `[H]` ★ [Escape Through Leaf](https://codeforces.com/contest/932/problem/F)
  - `[H]` [Polynomials](https://www.codechef.com/NOV17/problems/POLY)
  - `[H]` ★ [YATP](https://open.kattis.com/problems/yatp)
  - `[H]` [Weasel finds Staircase](https://www.codechef.com/SEPT17/problems/WEASELSC)
  - `[H]` [Train Car Selection](https://codeforces.com/contest/1137/problem/E)
  - `[H]` [Lena and Queries](https://codeforces.com/contest/678/problem/F)
  - `[H]` [Cycling (Hard Version)](https://codeforces.com/contest/2107/problem/F2)
  - `[H]` [Jaber and the Prediction Tree](https://codeforces.com/group/Rilx5irOux/contest/628229/problem/E)

#### 8.4.2 Persistent CHT

- **ID:** `persistent_cht` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_cht
- **Templates (1):**
  - [Persistent CHT.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Persistent%20CHT.cpp)
- **Resources (1):**
  - ★ [Fully Persistent Convex Hull Trick By infinity](https://codeforces.com/blog/entry/51684)
- **Problems (3):**
  - `[M]` ★ [Expert Computation](https://www.hackerrank.com/contests/w36/challenges/expert-computation/problem)
  - `[M]` [Harbingers](https://oj.uz/problem/view/CEOI09_harbingers)
  - `[M]` [Giant Community](https://codeforces.com/gym/105056/problem/G)

### 8.5 Li Chao Tree

**Subcategory ID:** `li_chao_tree` · **Topics:** 3

#### 8.5.1 Li Chao Tree

- **ID:** `li_chao_tree` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/li_chao_tree
- **Templates (1):**
  - [Li Chao Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Li%20Chao%20Tree.cpp)
- **Resources (4):**
  - ★ [A Simple Introduction to Li-Chao Segment Tree | A Simple Blog](https://robert1003.github.io/2020/02/06/li-chao-segment-tree.html)
  - ★ [Convex hull trick and Li Chao tree | CP Algorithms](https://cp-algorithms.com/geometry/convex_hull_trick.html#li-chao-tree)
  - [A simpler way to understand Li-Chao tree By ngk_manh](https://codeforces.com/blog/entry/95494)
  - ★ [\[Tutorial\] Li Chao Tree Extended 2 By tibinyte](https://codeforces.com/blog/entry/130766)
- **Problems (11):**
  - `[E]` ★ [Segment Add Get Min](https://judge.yosupo.jp/problem/segment_add_get_min)
  - `[E]` ★ [Kalila and Dimna in the Logging Industry](https://codeforces.com/contest/319/problem/C)
  - `[E]` ★ [Frog 3](https://atcoder.jp/contests/dp/tasks/dp_z)
  - `[E]` ★ [Squared Ends](https://csacademy.com/contest/archive/task/squared-ends)
  - `[E]` [Lines and Queries I](https://cses.fi/problemset/task/3429)
  - `[E]` ★ [Lines and Queries II](https://cses.fi/problemset/task/3430)
  - `[E]` [Line Segments Trace I](https://cses.fi/problemset/task/3427)
  - `[E]` ★ [Line Segments Trace II](https://cses.fi/problemset/task/3428)
  - `[M]` [Avoiding Airports](https://open.kattis.com/problems/avoidingairports)
  - `[H]` [Polynomials](https://www.codechef.com/NOV17/problems/POLY)
  - `[H]` ★ [Escape Through Leaf](https://codeforces.com/contest/932/problem/F)

#### 8.5.2 Persistent Li Chao Tree

- **ID:** `persistent_li_chao_tree` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/persistent_li_chao_tree
- **Templates (1):**
  - [Persistent Li Chao Tree.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Persistent%20Li%20Chao%20Tree.cpp)
- **Problems (3):**
  - `[M]` [Harbingers](https://oj.uz/problem/view/CEOI09_harbingers)
  - `[M]` ★ [Do you order queries?](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/segment-trees/practice-problems/algorithm/do-you-order-queries-27a70fdd/)
  - `[M]` [Scrolls of Eternal Wisdom](https://codeforces.com/group/Rilx5irOux/contest/572352/problem/E)

#### 8.5.3 Extended Li Chao tree

- **ID:** `extended_li_chao_tree` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/extended_li_chao_tree
- **Templates (1):**
  - [86731](https://codeforces.com/blog/entry/86731)
- **Resources (1):**
  - ★ [\[Tutorial\] Li Chao Tree Extended By rama_pang](https://codeforces.com/blog/entry/86731)
- **Problems (7):**
  - `[M]` ★ [Progression](https://oj.uz/problem/view/NOI20_progression)
  - `[M]` ★ [I hate Shortest Path Problem](https://atcoder.jp/contests/abc177/tasks/abc177_f)
  - `[M]` [Reazione a candela](https://training.olinfo.it/#/task/oii_candele/statement)
  - `[H]` ★ [Mall and Transportation](https://tlx.toki.id/contests/troc-13-div-1/problems/D)
  - `[H]` [Train Car Selection](https://codeforces.com/contest/1137/problem/E)
  - `[H]` [Mean Sequence](https://dmoj.ca/problem/ioi05p3)
  - `[VH]` [Meetings](https://oj.uz/problem/view/IOI18_meetings)

### 8.6 Bit Related DP

**Subcategory ID:** `bit_related_dp` · **Topics:** 6

#### 8.6.1 Bitmask DP

- **ID:** `bitmask_dp` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/bitmask_dp
- **Resources (10):**
  - ★ [Bit manipulation | CP Algorithm](https://cp-algorithms.com/algebra/bit-manipulation.html)
  - [Dynamic Programming and Bit Masking | HackerEarth](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/tutorial/)
  - ★ [10.5 Dynamic programming | CPH](https://usaco.guide/CPH.pdf#page=112)
  - [A Primer on Bitmask DP | Neo Wang](https://nwatx.me/post/dpbitmasks)
  - [\[Tutorial\] Non-trivial DP Tricks and Techniques By zscoder](https://codeforces.com/blog/entry/47764)
  - [Introduction to DP with Bitmasking By kartik8800](https://codeforces.com/blog/entry/81516)
  - ★ [A little bit of classics: dynamic programming over subsets and paths in graphs By Ripatti](https://codeforces.com/blog/entry/337)
  - ★ [Bitmask DP Problems \[Slightly Harder Examples\] | Gautam](https://gautambitmaskdp.blogspot.com/?m=1)
  - ★ [Bitmask DP | USACO Guide](https://usaco.guide/gold/dp-bitmasks?lang=cpp)
  - ★ [Traveling Salesman Problem | Dynamic Programming | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=cY4HiiFHO1o)
- **Problems (38):**
  - `[E]` ★ [Matching](https://atcoder.jp/contests/dp/tasks/dp_o)
  - `[E]` ★ [Hamiltonian Flights](https://cses.fi/problemset/task/1690)
  - `[E]` ★ [Travelling Salesman Problem](https://vjudge.net/problem/SPOJ-PESADA04)
  - `[E]` ★ [A Simple Task](https://codeforces.com/contest/11/problem/D)
  - `[E]` ★ [Team Building](https://codeforces.com/contest/1316/problem/E)
  - `[E]` [Guard Mark](https://usaco.org/index.php?page=viewproblem2&cpid=494)
  - `[E]` [Moovie Mooving](https://usaco.org/index.php?page=viewproblem2&cpid=515)
  - `[E]` ★ [Looking for Order](https://codeforces.com/problemset/problem/8/C)
  - `[E]` ★ [Maximum Independent Set](https://judge.yosupo.jp/problem/maximum_independent_set)
  - `[E]` [Shuffling Songs](https://codeforces.com/contest/1950/problem/G)
  - `[E]` [Kefa and Dishes](https://codeforces.com/problemset/problem/580/D)
  - `[M]` ★ [Traveling Graph](https://codeforces.com/problemset/problem/21/D)
  - `[M]` ★ [Square Subsets](https://codeforces.com/contest/895/problem/C)
  - `[M]` ★ [Fish](https://codeforces.com/problemset/problem/16/E)
  - `[M]` ★ [Grouping](https://atcoder.jp/contests/dp/tasks/dp_u)
  - `[M]` ★ [Little Pony and Harmony Chest](https://codeforces.com/contest/453/problem/B)
  - `[M]` [Another Sith Tournament](https://codeforces.com/contest/678/problem/E)
  - `[M]` [Little Elephant and T-Shirts](https://www.codechef.com/problems/TSHIRTS)
  - `[M]` [Little Elephant and Alcohol](https://www.codechef.com/JAN13/problems/LEALCO)
  - `[M]` [Histogram](https://www.spoj.com/problems/HIST2/)
  - `[M]` ★ [Felicity's Big Secret Revealed](https://codeforces.com/problemset/problem/757/D)
  - `[M]` ★ [Sereja and GCD 2](https://www.codechef.com/problems/SEAGCD2)
  - `[M]` [Hasan and Points Pairing](https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/practice-problems/algorithm/hasan-and-points-pairing/)
  - `[M]` ★ [Sherlock and Coprime Subset](https://www.hackerearth.com/practice/algorithms/dynamic-programming/bit-masking/practice-problems/algorithm/sherlock-and-coprime-subset/)
  - `[M]` [Uddered but not Herd](https://usaco.org/index.php?page=viewproblem2&cpid=1089)
  - `[M]` [Bank](https://oj.uz/problem/view/IZhO14_bank)
  - `[M]` [Cat and Mice](https://open.kattis.com/problems/catandmice)
  - `[M]` [Nuclear Fusion](https://codeforces.com/problemset/problem/71/E)
  - `[M]` [Gym Plates](https://codeforces.com/gym/104493/problem/A)
  - `[M]` [Maximum path](https://codeforces.com/contest/762/problem/D)
  - `[M]` [2048](https://codeforces.com/problemset/problem/413/D)
  - `[M]` ★ [Partition to K Equal Sum Subsets](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/description/)
  - `[H]` ★ [Elevator Rides](https://cses.fi/problemset/task/1653)
  - `[H]` ★ [Binary Table](https://codeforces.com/contest/662/problem/C)
  - `[H]` [Baby](https://www.spoj.com/problems/BABY/)
  - `[H]` ★ [Lights Off](https://usaco.org/index.php?page=viewproblem2&cpid=1282)
  - `[VH]` [Professional layer](https://codeforces.com/contest/1103/problem/D)
  - `[VH]` ★ [Gold Experience](https://codeforces.com/contest/1148/problem/G)

#### 8.6.2 Sum Over Subsets DP (SOS DP)

- **ID:** `sos_dp` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/sos_dp
- **Templates (1):**
  - [SOS DP.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/SOS%20DP.cpp)
- **Resources (8):**
  - ★ [Submask Enumeration | CP Algorithms](https://cp-algorithms.com/algebra/all-submasks.html)
  - ★ [SOS Dynamic Programming \[Tutorial\] By usaxena95](https://codeforces.com/blog/entry/45223)
  - ★ [Some SOS DP Insights By maxwellzen](https://codeforces.com/blog/entry/105247)
  - ★ [SOS <> N Dimensional Prefix Sum | Errichto](https://www.youtube.com/watch?v=Lpvsd8WpbWc&t=311s)
  - [SOS <> N Dimensional Prefix Sum | Rezwan](https://codeforces.com/blog/entry/45223?#comment-573034)
  - [Sum over Subsets DP | USACO Guide](https://usaco.guide/adv/dp-sos?lang=cpp)
  - [The Big idea behind SOS DP ft. Editorial of 1995D : Cases Codeforces](https://www.youtube.com/watch?v=LgxHoy3Aguk&t=1782s)
  - [SOS DP | Vivek Gupta](https://www.youtube.com/watch?v=RYdueyYBQS8&list=PLqf9emQRQrnKd5xv_NXTZ8mBSOdeU1Ha5)
- **Problems (36):**
  - `[E]` ★ [Bit Problem](https://cses.fi/problemset/task/1654)
  - `[E]` ★ [Compatible Numbers](https://codeforces.com/contest/165/problem/E)
  - `[E]` ★ [Vowels](https://codeforces.com/contest/383/problem/E)
  - `[E]` ★ [And Subset Count](https://cses.fi/problemset/task/3141/)
  - `[E]` [Covering Sets](https://www.codechef.com/problems/COVERING)
  - `[E]` ★ [Ordered Pairs](https://www.hackerearth.com/problem/algorithm/find-the-number-of-ordered-pairs-1/)
  - `[E]` [Problem Setting](https://usaco.org/index.php?page=viewproblem2&cpid=1309)
  - `[E]` ★ [Maximum And Queries (hard version)](https://codeforces.com/contest/1903/problem/D2)
  - `[M]` [Pepsi Cola](https://codeforces.com/group/qcIqFPYhVr/contest/203881/problem/K)
  - `[M]` ★ [Close Group](https://atcoder.jp/contests/abc187/tasks/abc187_f)
  - `[M]` ★ [Sandy and Nuts](https://codeforces.com/problemset/problem/599/E)
  - `[M]` ★ [Vim War](https://www.hackerrank.com/contests/w16/challenges/vim-war)
  - `[M]` [Beautiful Sandwich](https://www.codechef.com/SNFL16MR/problems/BEAUTY)
  - `[M]` ★ [Strange Functions](https://www.codechef.com/IPC15P2B/problems/STR_FUNC)
  - `[M]` ★ [Good Pairs](https://www.codechef.com/LTIME50/problems/MAXOR)
  - `[M]` [Killing Monsters](https://www.codechef.com/problems/MONSTER)
  - `[M]` [Jersey Number](https://www.codechef.com/problems/AMR14F)
  - `[M]` ★ [Cake Tasting](https://codeforces.com/gym/102128/problem/B)
  - `[M]` ★ [Good Permutations](https://csacademy.com/contest/archive/task/good-permurations/statement/)
  - `[M]` [Going Dutch](https://codeforces.com/gym/101666/problem/G)
  - `[M]` ★ [Prefix And](https://www.codechef.com/COOK126A/problems/ANDPREF)
  - `[M]` [Love-Hate](https://codeforces.com/contest/1523/problem/D)
  - `[M]` ★ [Subsequences Galore](https://codeforces.com/contest/1620/problem/G)
  - `[M]` ★ [Bits And Pieces](https://codeforces.com/contest/1208/problem/F)
  - `[M]` [Sleeping in Class](https://usaco.org/index.php?page=viewproblem2&cpid=1213)
  - `[M]` ★ [Time Limit Exceeded](https://www.spoj.com/problems/TLE/)
  - `[M]` ★ [Count Pairs](https://codeforces.com/gym/105755/problem/C)
  - `[M]` [Pretests](https://codeforces.com/gym/102006/problem/F)
  - `[M]` [Cases](https://codeforces.com/contest/1995/problem/D)
  - `[H]` ★ [Jzzhu and Numbers](https://codeforces.com/contest/449/problem/D)
  - `[H]` ★ [Varying Kibibits](https://codeforces.com/contest/800/problem/D)
  - `[H]` [Danya and Numbers](https://www.codechef.com/problems/DANYANUM)
  - `[H]` ★ [Or Plus Max](https://atcoder.jp/contests/arc100/tasks/arc100_c)
  - `[H]` [Snake Escaping](https://oj.uz/problem/view/JOI18_snake_escaping)
  - `[H]` ★ [Peculiar Partitioning II](https://toph.co/p/peculiar-partitioning-ii)
  - `[VH]` [Wise Men (Hard Version)](https://codeforces.com/contest/1326/problem/F2)

#### 8.6.3 [Problem] Subset Union of Bitsets

- **ID:** `subset_union_of_bitsets` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/subset_union_of_bitsets
- **Templates (1):**
  - [Subset Union of Bitsets.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Subset%20Union%20of%20Bitsets.cpp)
- **Problems (1):**
  - `[E]` ★ [Radio Radius](https://tlx.toki.id/contests/troc-16/problems/F)

#### 8.6.4 Subset Convolution

- **ID:** `subset_convolution` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/subset_convolution
- **Templates (1):**
  - [SOS convolutions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/SOS%20convolutions.cpp)
- **Resources (5):**
  - ★ [Tutorial on Zeta Transform, Mobius Transform and Subset Sum Convolution By sidhant](https://codeforces.com/blog/entry/72488)
  - [Fourier Meets Mobius: Fast Subset Convolution | Andreas Bjorklund and Thore Husfeldt](https://people.csail.mit.edu/rrw/presentations/subset-conv.pdf)
  - [Subset convolution interpretation By adamant](https://codeforces.com/blog/entry/92153)
  - ★ [OR Convolution for Common People By ko_osaga](https://codeforces.com/blog/entry/115438)
  - [\[Tutorial\] Zeta, Mobius Transform to AND, OR, GCD Convolution By jinhan814](https://codeforces.com/blog/entry/119082)
- **Problems (2):**
  - `[M]` ★ [Sum the Fibonacci](https://codeforces.com/problemset/problem/914/G)
  - `[M]` [Friends and Pizza](https://codeforces.com/contest/2070/problem/F)

#### 8.6.5 [Trick] Dynamic Submask Count

- **ID:** `dynamic_submask_count` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_submask_count
- **Templates (1):**
  - [127469](https://codeforces.com/blog/entry/127469)
- **Resources (2):**
  - ★ [Submask range queries By adamant](https://codeforces.com/blog/entry/103799)
  - [Dynamic sum-over-subset dp with element addition and extraction in O(2^(k/2)) time By Peter-007](https://codeforces.com/blog/entry/127469)
- **Problems (3):**
  - `[E]` ★ [Subset](https://www.hackerrank.com/contests/countercode/challenges/subset)
  - `[M]` ★ [Subset Sum](https://dmoj.ca/problem/utso18p6)
  - `[H]` ★ [Longest beautiful sequence](https://oj.uz/problem/view/IZhO17_subsequence)

#### 8.6.6 [Problem] XOR Equation

- **ID:** `xor_equation` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/xor_equation
- **Templates (1):**
  - [XOR Equation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/XOR%20Equation.cpp)
- **Resources (1):**
  - ★ [Editorial of Stone Game | kevinsogo](https://www.hackerrank.com/challenges/stonegame/editorial)
- **Problems (3):**
  - `[M]` ★ [Stone Game](https://www.hackerrank.com/challenges/stonegame/problem)
  - `[M]` ★ [Math teacher's homework](http://poj.org/problem?id=3986)
  - `[H]` ★ [Innocence](https://codeforces.com/gym/102114/problem/I)

### 8.7 More Tricks

**Subcategory ID:** `more_tricks` · **Topics:** 4

#### 8.7.1 Open and Close Interval Trick

- **ID:** `open_and_close_interval_trick` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/open_and_close_interval_trick
- **Resources (1):**
  - ★ [\[Tutorial\] Non-trivial DP Tricks and Techniques By zscoder](https://codeforces.com/blog/entry/47764)
- **Problems (4):**
  - `[E]` ★ [Group Projects](https://codeforces.com/contest/626/problem/F)
  - `[E]` ★ [Coding Company](https://cses.fi/problemset/task/1665)
  - `[E]` ★ [Increase Sequence](https://codeforces.com/contest/466/problem/D)
  - `[M]` [Sereja and Intervals](https://codeforces.com/contest/367/problem/E)

#### 8.7.2 Slope Trick

- **ID:** `slope_trick` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/slope_trick
- **Resources (6):**
  - ★ [Slope trick explained By Kuroni](https://codeforces.com/blog/entry/77298)
  - ★ [Slope Trick Visualised | benritmicocode](https://www.youtube.com/watch?v=p8RxN6Y9OOA)
  - ★ [\[Tutorial\] Slope Trick By zscoder](https://codeforces.com/blog/entry/47821)
  - ★ [Slope Trick | USACO Guide](https://usaco.guide/adv/slope-trick?lang=cpp)
  - ★ [\[Tutorial\] Intuition on Slope Trick By maomao9](https://codeforces.com/blog/entry/103222)
  - ["Worse-to-best option", a different way to think about Slope Trick By gmyu.michael](https://codeforces.com/blog/entry/91725)
- **Problems (24):**
  - `[E]` ★ [Sonya and Problem Wihtout a Legend](https://codeforces.com/contest/713/problem/C)
  - `[E]` ★ [Increasing Array II](https://cses.fi/problemset/task/2132)
  - `[E]` ★ [Buy Low Sell High](https://codeforces.com/problemset/problem/865/D)
  - `[M]` ★ [Fireworks](https://oj.uz/problem/view/APIO16_fireworks)
  - `[M]` [NarrowRectangles](http://arc070.contest.atcoder.jp/tasks/arc070_c)
  - `[M]` ★ [Safety](https://oj.uz/problem/view/NOI18_safety)
  - `[M]` [Potatoes and fertilizers](https://oj.uz/problem/view/LMIO19_bulves)
  - `[M]` [Touch The Sky](https://codeforces.com/gym/101806/problem/T)
  - `[M]` [Parklife](https://codeforces.com/gym/102391/problem/J)
  - `[M]` [Farm Village](https://atcoder.jp/contests/jag2017autumn/tasks/jag2017autumn_j)
  - `[M]` [WAAAAAAAAAAAAALL](https://atcoder.jp/contests/kupc2016/tasks/kupc2016_h)
  - `[M]` [Bookface](https://codeforces.com/gym/102576/problem/C)
  - `[M]` ★ [Inc, Dec - Decomposition](https://atcoder.jp/contests/arc123/tasks/arc123_d)
  - `[M]` ★ [Social Distancing](https://nus.kattis.com/courses/CS3233/CS3233_S2_AY2122/assignments/qs926n/problems/socialdistancing)
  - `[H]` [Honorable Mention](https://codeforces.com/gym/102331/problem/H)
  - `[H]` [Landscaping](https://usaco.org/index.php?page=viewproblem2&cpid=650)
  - `[H]` [CCDSAP Exam](https://www.codechef.com/problems/CCDSAP)
  - `[H]` [Magic Tree](https://oj.uz/problem/view/CEOI19_magictree)
  - `[H]` [Farm of Monsters](https://codeforces.com/gym/102538/problem/F)
  - `[H]` [Paths](https://oj.uz/problem/view/RMI21_paths)
  - `[VH]` [Moving Walkways](https://codeforces.com/contest/1209/problem/H)
  - `[VH]` [Mateusz and Escape Room](https://codeforces.com/contest/1229/problem/F)
  - `[VH]` [Conquer The World](https://icpc.kattis.com/problems/conquertheworld)
  - `[VH]` [April Fools' Problem (hard)](https://codeforces.com/contest/802/problem/O)

#### 8.7.3 x2 +1 Trick

- **ID:** `x2_plus_1_trick` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/x2_plus_1_trick
- **Templates (1):**
  - [x2 +1 trick.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/x2%20+1%20trick.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] Non-trivial DP Tricks and Techniques By zscoder](https://codeforces.com/blog/entry/47764)
- **Problems (2):**
  - `[M]` ★ [Perfect Permutations](https://www.hackerearth.com/problem/algorithm/perfect-permutations-september-clash/)
  - `[H]` ★ [Baby Ehab Plays with Permutations](https://codeforces.com/contest/1516/problem/E)

#### 8.7.4 Combining Subtrees Technique

- **ID:** `combining_subtrees_technique` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/combining_subtrees_technique
- **Resources (5):**
  - ★ [DP on Trees - Combining Subtrees | USACO Guide](https://usaco.guide/adv/comb-sub?lang=cpp)
  - ★ [Dp On Trees By AghaTizi](https://codeforces.com/blog/entry/63257)
  - ★ [\[Tutorial\] Collection of little techniques By -is-this-fft-](https://codeforces.com/blog/entry/100910)
  - ★ [Optimization for dp on tree needed. By negativez2](https://codeforces.com/blog/entry/69888)
  - [Optimizing Round 595 Problem F from 𝑂(𝑛4) to 𝑂(𝑛) By neal](https://codeforces.com/blog/entry/70822)
- **Problems (13):**
  - `[E]` ★ [Kth Subtree](https://vjudge.net/problem/Kattis-kthsubtree)
  - `[E]` ★ [Museum](https://oj.uz/problem/view/CEOI17_museum)
  - `[M]` [Karen and Supermarket](https://codeforces.com/problemset/problem/815/C)
  - `[M]` [Džumbus](https://oj.uz/problem/view/COCI19_dzumbus)
  - `[M]` [Cereal Trees II](https://codeforces.com/gym/103886/problem/Q)
  - `[M]` ★ [Maximum Weight Subset](https://codeforces.com/contest/1249/problem/F)
  - `[M]` [Rivers](https://dmoj.ca/problem/ioi05p6)
  - `[M]` ★ [Tree Patrolling](https://atcoder.jp/contests/abc207/tasks/abc207_f)
  - `[M]` ★ [Ostap and Tree](https://codeforces.com/contest/735/problem/E)
  - `[M]` [Miss Punyverse](https://codeforces.com/contest/1280/problem/D)
  - `[M]` ★ [Attack to a Tree](https://atcoder.jp/contests/aising2019/tasks/aising2019_e)
  - `[H]` [Periodni](https://dmoj.ca/problem/coci08c4p6)
  - `[H]` ★ [Vladislav and a Great Legend](https://codeforces.com/contest/1097/problem/G)

### 8.8 Classic DP

**Subcategory ID:** `classic_dp` · **Topics:** 3

#### 8.8.1 Longest Increasing Subsequence (LIS)

- **ID:** `lis` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/lis
- **Resources (2):**
  - ★ [Longest increasing subsequence | CP Algorithms](https://cp-algorithms.com/sequences/longest_increasing_subsequence.html)
  - [LIS in O(nlogn) with printing solution | Vivek Gupta](https://www.youtube.com/watch?v=XhzQHpGcQg4)
- **Problems (28):**
  - `[E]` ★ [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/description/)
  - `[E]` ★ [Increasing Subsequence](https://cses.fi/problemset/task/1145)
  - `[E]` ★ [Flowers](https://atcoder.jp/contests/dp/tasks/dp_q)
  - `[E]` ★ [Dosa](https://www.spoj.com/problems/DOSA/)
  - `[E]` ★ [HowManyLis](https://www.spoj.com/problems/HMLIS/)
  - `[E]` ★ [One X LIS](https://www.spoj.com/problems/ONEXLIS/)
  - `[E]` [Back to Edit Distance](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=4600)
  - `[E]` [Shortest and Longest LIS](https://codeforces.com/problemset/problem/1304/D)
  - `[E]` [LIS or Reverse LIS?](https://codeforces.com/problemset/problem/1682/C)
  - `[E]` ★ [|LIS| = 3](https://atcoder.jp/contests/abc237/tasks/abc237_f)
  - `[E]` [Consecutive Subsequence](https://codeforces.com/contest/977/problem/F)
  - `[E]` ★ [Increasing numbers](https://www.spoj.com/problems/NDS/)
  - `[M]` ★ [LISDL](https://atcoder.jp/contests/arc091/tasks/arc091_c)
  - `[M]` [LCIS](https://codeforces.com/problemset/problem/10/D)
  - `[M]` [Tourist](https://codeforces.com/contest/76/problem/F)
  - `[M]` ★ [North-East](https://codeforces.com/problemsets/acmsguru/problem/99999/521)
  - `[M]` [Supernumbers in a permutation](https://www.spoj.com/problems/SUPPER/)
  - `[M]` [Happy Birthday](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3153)
  - `[M]` ★ [Two LIS Sum](https://atcoder.jp/contests/arc149/tasks/arc149_b)
  - `[M]` [Tiling Up Blocks](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3637)
  - `[M]` ★ [LIS of Sequence](https://codeforces.com/problemset/problem/486/E)
  - `[M]` ★ [LIS on Tree](https://atcoder.jp/contests/abc165/tasks/abc165_f)
  - `[M]` ★ [LIS vs. LDS](https://codeforces.com/problemset/gymProblem/101821/B)
  - `[M]` ★ [LIS on Tree 2](https://atcoder.jp/contests/arc175/tasks/arc175_d)
  - `[M]` [Alternating Sequences](https://www.spoj.com/problems/ALTSEQ/)
  - `[M]` ★ [Gather Coins](https://atcoder.jp/contests/abc369/tasks/abc369_f)
  - `[H]` ★ [Binary Sort](https://lightoj.com/problem/binary-sort)
  - `[VH]` [LIDS](https://atcoder.jp/contests/agc059/tasks/agc059_f)

#### 8.8.2 Interval DP / Range DP / Matrix Chain Multiplication (MCM)

- **ID:** `mcm` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/mcm
- **Resources (4):**
  - ★ [Range DP | USACO Guide](https://usaco.guide/gold/dp-ranges?lang=cpp)
  - [Matrix Chain Multiplication | DP-8 | Geeks for Geeks](https://www.geeksforgeeks.org/matrix-chain-multiplication-dp-8/)
  - ★ [Some Interval DP Problems and State Reduction By lelbaba](https://codeforces.com/blog/entry/108850)
  - [Matrix Chain Multiplication using Dynamic Programming Formula - Abdul Bari](https://www.youtube.com/watch?v=_WncuhSJZyA)
- **Problems (23):**
  - `[E]` ★ [Matrix-chain Multiplication](https://vjudge.net/problem/Aizu-ALDS1_10_B)
  - `[E]` ★ [Mixtures](https://www.spoj.com/problems/MIXTURES/)
  - `[E]` [The Cow Run](https://usaco.org/index.php?page=viewproblem2&cpid=265)
  - `[E]` [248](https://usaco.org/index.php?page=viewproblem2&cpid=647)
  - `[E]` [Modern Art 3](https://usaco.org/index.php?page=viewproblem2&cpid=1114)
  - `[M]` ★ [Queries for Number of Palindromes](https://codeforces.com/contest/245/problem/H)
  - `[M]` ★ [Slimes](https://atcoder.jp/contests/dp/tasks/dp_n)
  - `[M]` [Farmer John Solves 3SUM](https://usaco.org/index.php?page=viewproblem2&cpid=994)
  - `[M]` ★ [Empty String](https://cses.fi/problemset/task/1080)
  - `[M]` ★ [Zuma](https://codeforces.com/problemset/problem/607/B)
  - `[M]` [Brackets](https://www.codechef.com/INOIPRAC/problems/INOI1602)
  - `[M]` ★ [Array Shrinking](https://codeforces.com/contest/1312/problem/E)
  - `[M]` ★ [Erase Subsequences](https://codeforces.com/contest/1303/problem/E)
  - `[M]` ★ [Dreamoon and Strings](https://codeforces.com/contest/476/problem/E)
  - `[M]` ★ [Kaavi and Magic Spell](https://codeforces.com/contest/1337/problem/E)
  - `[M]` ★ [Recovering BST](https://codeforces.com/contest/1025/problem/D)
  - `[M]` [The Sports Festival](https://codeforces.com/problemset/problem/1509/C)
  - `[M]` [Paint Charges](https://codeforces.com/problemset/problem/1927/G)
  - `[M]` [Clear the String](https://codeforces.com/problemset/problem/1132/F)
  - `[M]` [Game With Triangles: Season 2](https://codeforces.com/problemset/problem/2074/G)
  - `[H]` [Greedy Pie Eaters](https://usaco.org/index.php?page=viewproblem2&cpid=972)
  - `[VH]` [Lights Out](https://usaco.org/index.php?page=viewproblem2&cpid=602)
  - `[VH]` [Paimon's Tree](https://oj.uz/problem/view/CEOI12_race)

#### 8.8.3 Edit Distance

- **ID:** `edit_distance` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/edit_distance
- **Resources (2):**
  - ★ [Edit Distance | Geeks for Geeks](https://www.geeksforgeeks.org/edit-distance-dp-5/)
  - [Printing path in Edit Distance](https://codeforces.com/blog/entry/8076)
- **Problems (5):**
  - `[E]` ★ [Edit Distance](https://cses.fi/problemset/task/1639)
  - `[E]` [Back to Edit Distance](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=4600)
  - `[E]` ★ [Edit Distance](https://codeforces.com/gym/102001/problem/A)
  - `[E]` [Levenshtein distance](https://codeforces.com/problemset/problem/530/G)
  - `[M]` [Enchanted Artifact](https://codeforces.com/problemset/problem/1282/D)

### 8.9 Dp on Different Structures

**Subcategory ID:** `dp_on_different_structures` · **Topics:** 4

#### 8.9.1 DP on Trees and DAGs

- **ID:** `dp_on_trees_and_dags` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/dp_on_trees_and_dags
- **Resources (4):**
  - ★ [DP on Trees Tutorial By darkshadows](https://codeforces.com/blog/entry/20935)
  - [DP on Trees - Introduction | USACO Guide](https://usaco.guide/gold/dp-trees?lang=cpp)
  - [Dynamic Programming on Trees By kartik8800](https://codeforces.com/blog/entry/79857)
  - ★ [Shortest/Longest path on a Directed Acyclic Graph (DAG) | Graph Theory WilliamFiset](https://www.youtube.com/watch?v=TXkDpqjDMHA)
- **Problems (45):**
  - `[E]` ★ [Distance in Tree](https://codeforces.com/contest/161/problem/D)
  - `[E]` ★ [Longest Flight Route](https://cses.fi/problemset/task/1680)
  - `[E]` ★ [Game Routes](https://cses.fi/problemset/task/1681)
  - `[E]` [Journey](https://codeforces.com/problemset/problem/839/C)
  - `[E]` ★ [Tree Diameter](https://cses.fi/problemset/task/1131)
  - `[E]` ★ [Longest Path](https://atcoder.jp/contests/dp/tasks/dp_g)
  - `[E]` ★ [Independent Set](https://atcoder.jp/contests/dp/tasks/dp_p)
  - `[E]` ★ [Appleman and Tree](https://codeforces.com/contest/461/problem/B)
  - `[E]` ★ [Tree Matching](https://cses.fi/problemset/task/1130)
  - `[E]` [Barn Painting](https://usaco.org/index.php?page=viewproblem2&cpid=766)
  - `[E]` [Choosing Capital for Treeland](https://codeforces.com/contest/219/problem/D)
  - `[E]` [The Fair Nut and the Best Path](https://codeforces.com/contest/1083/problem/A)
  - `[E]` [Eternal Victory](https://codeforces.com/contest/61/problem/D)
  - `[E]` ★ [Bakry and Partitioning](https://codeforces.com/contest/1592/problem/C)
  - `[E]` [Sheriff's Defense](https://codeforces.com/contest/2014/problem/F)
  - `[E]` [Tree Jumps](https://codeforces.com/problemset/problem/2070/D)
  - `[M]` [Non-Decreasing Colorful Path](https://atcoder.jp/contests/abc335/tasks/abc335_e)
  - `[M]` [Mahmoud and a xor trip](https://codeforces.com/problemset/problem/766/E)
  - `[M]` ★ [Anton and Tree](https://codeforces.com/problemset/problem/734/E)
  - `[M]` ★ [Coin Collector](https://cses.fi/problemset/task/1686/)
  - `[M]` ★ [Ralph and Mushrooms](https://codeforces.com/contest/894/problem/E)
  - `[M]` ★ [Subtree](https://atcoder.jp/contests/dp/tasks/dp_v)
  - `[M]` [Binary Apple Tree](https://acm.timus.ru/problem.aspx?space=1&num=1018)
  - `[M]` [Tree Pruning](https://www.hackerrank.com/challenges/tree-pruning/problem)
  - `[M]` [Anniversary Party](https://acm.timus.ru/problem.aspx?space=1&num=1039)
  - `[M]` [Berland Federalization](https://codeforces.com/contest/440/problem/D)
  - `[M]` [Village (Minimum)](https://codeforces.com/contest/1387/problem/B1)
  - `[M]` ★ [Nastia Plays with a Tree](https://codeforces.com/contest/1521/problem/D)
  - `[M]` [Parade](https://szkopul.edu.pl/problemset/problem/1QaUWE_ePAmitZjgAszOVD1U/site/?key=statement)
  - `[M]` ★ [Parsa's Humongous Tree](https://codeforces.com/problemset/problem/1528/A)
  - `[M]` ★ [Select Edges](https://atcoder.jp/contests/abc259/tasks/abc259_f)
  - `[M]` [Delegation](https://usaco.org/index.php?page=viewproblem2&cpid=1019)
  - `[M]` [Tree XOR](https://codeforces.com/problemset/problem/1882/D)
  - `[M]` [Weight the Tree](https://codeforces.com/contest/1646/problem/D)
  - `[M]` [Vasya and Maximum Matching](https://codeforces.com/contest/1078/problem/C)
  - `[M]` [Protection](https://codeforces.com/gym/105556/problem/D)
  - `[H]` [Yet Another DAG Problem](https://codeforces.com/problemset/problem/1430/G)
  - `[H]` [Spies](https://szkopul.edu.pl/problemset/problem/r6tMTfvQFPAEfQioYMCQndQe/site/?key=statement)
  - `[H]` [Mafia](https://szkopul.edu.pl/problemset/problem/w3YAoAT3ej27YeiaNWjK57_G/site/?key=statement)
  - `[H]` ★ [Boboniu and Jianghu](https://codeforces.com/contest/1394/problem/D)
  - `[H]` [Alkane](https://atcoder.jp/contests/abc394/tasks/abc394_f)
  - `[VH]` [Torrent](https://oj.uz/problem/view/COI16_torrent)
  - `[VH]` [Training](https://oj.uz/problem/view/IOI07_training)
  - `[VH]` ★ [Creating Offices](https://cses.fi/problemset/task/1752)
  - `[VH]` [Swap](https://oj.uz/problem/view/BOI16_swap)

#### 8.9.2 DP over Divisors

- **ID:** `dp_over_divisors` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/dp_over_divisors
- **Templates (1):**
  - [DP Over Divisors.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/DP%20Over%20Divisors.cpp)
- **Resources (1):**
  - [\[Tutorial\] Zeta, Mobius Transform to AND, OR, GCD Convolution By jinhan814](https://codeforces.com/blog/entry/119082)
- **Problems (3):**
  - `[E]` [Small GCD](https://codeforces.com/contest/1900/problem/D)
  - `[H]` ★ [Maximum GCD Sum Queries](https://codeforces.com/contest/1973/problem/F)
  - `[H]` ★ [Discrete Logarithm Problems](https://atcoder.jp/contests/abc335/tasks/abc335_g)

#### 8.9.3 Substring DP

- **ID:** `substring_dp` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/substring_dp
- **Templates (1):**
  - [Prefix Automaton.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Strings/Prefix%20Automaton.cpp)
- **Resources (1):**
  - [Prefix function. Knuth–Morris–Pratt algorithm | CP Algorithms](https://cp-algorithms.com/string/prefix-function.html#building-an-automaton-according-to-the-prefix-function)
- **Problems (9):**
  - `[M]` ★ [Required Substring](https://cses.fi/problemset/task/1112)
  - `[M]` ★ [Bracket Substring](https://codeforces.com/problemset/problem/1015/F)
  - `[M]` ★ [Anthem of Berland](https://codeforces.com/contest/808/problem/G)
  - `[M]` ★ [Lucky Common Subsequence](https://codeforces.com/problemset/problem/346/B)
  - `[M]` ★ [Unlucky Strings](https://lightoj.com/problem/unlucky-strings)
  - `[M]` ★ [Remove The String](https://www.spoj.com/problems/PSTRING/)
  - `[M]` [Phone Numbers](https://acm.timus.ru/problem.aspx?space=1&num=1002)
  - `[M]` ★ [Nitu and Her Lucky String](https://toph.co/p/nitu-and-her-lucky-string)
  - `[M]` [substr = S](https://atcoder.jp/contests/abc295/tasks/abc295_f)

#### 8.9.4 DP on Convex Hulls

- **ID:** `dp_on_convex_hulls` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dp_on_convex_hulls
- **Templates (1):**
  - [DP on Convex Hulls.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/DP%20on%20Convex%20Hulls.cpp)
- **Resources (2):**
  - ★ [Transition Then State | mzhang2021](https://mzhang2021.github.io/cp-blog/transition/)
  - [A bit more of general ideas By adamant](https://codeforces.com/blog/entry/104466)
- **Problems (6):**
  - `[E]` ★ [Cold Rainy Night in Stoke](https://toph.co/p/cold-rainy-night-in-stoke)
  - `[M]` ★ [Profitable Home](https://toph.co/p/profitable-home)
  - `[M]` ★ [Integer Convex Hull](https://atcoder.jp/contests/abc202/tasks/abc202_f)
  - `[M]` [Security at Museums](https://qoj.ac/contest/1096/problem/5443)
  - `[M]` [Pegs](https://open.kattis.com/problems/peggame)
  - `[M]` ★ [ConvexScore](https://atcoder.jp/contests/arc082/tasks/arc082_c)

### 8.10 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 5

#### 8.10.1 Connected Component DP

- **ID:** `connected_component_dp` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/connected_component_dp
- **Templates (1):**
  - [Connected Component DP.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Connected%20Component%20DP.cpp)
- **Resources (3):**
  - [\[Tutorial\] Dp with connected components, a simple way to understand it. By humbertoyusta](https://codeforces.com/blog/entry/92602)
  - ★ [\[Tutorial\] Non-trivial DP Tricks and Techniques By zscoder](https://codeforces.com/blog/entry/47764)
  - [Do you really understand Connected Components DP? By TheScrasse,](https://codeforces.com/blog/entry/109293)
- **Problems (12):**
  - `[E]` ★ [Permutations II](https://cses.fi/problemset/task/1075)
  - `[M]` ★ [Skyscraper](https://oj.uz/problem/view/JOI16_skyscraper)
  - `[M]` [Kangaroo](https://oj.uz/problem/view/CEOI16_kangaroo)
  - `[M]` [Ant Man](https://codeforces.com/contest/704/problem/B)
  - `[M]` [Phoenix and Computers](https://codeforces.com/contest/1515/problem/E)
  - `[M]` ★ [Network](https://lightoj.com/problem/network)
  - `[M]` [April Fools](https://dmoj.ca/problem/utso21p7)
  - `[M]` [Mentors](https://codeforces.com/gym/103081/problem/F)
  - `[M]` [Magical Teleporter (Subtask 4)](https://codeforces.com/group/R2SERIff4f/contest/213171/problem/R)
  - `[M]` [Reading Novels](https://codeforces.com/group/IO0c6wbyI8/contest/293254/problem/D)
  - `[M]` ★ [Zero-Sum Ranges 2](https://atcoder.jp/contests/arc117/tasks/arc117_e)
  - `[H]` ★ [Route Defense](https://tlx.toki.id/problems/troc-11/H)

#### 8.10.2 Broken Profile DP / Plug DP

- **ID:** `broken_profile_dp` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/broken_profile_dp
- **Resources (5):**
  - ★ [An Introduction to Plug DP By 4fecta](https://codeforces.com/blog/entry/90841)
  - [DP on broken profile by Pavel Mavrin](https://youtu.be/0bnMHlFUM_o?si=a3z-4oat2tKsPEnq)
  - ★ [DP on Broken Profile | USACO Guide](https://usaco.guide/adv/dp-more?lang=cpp#dp-on-broken-profile)
  - [插头 DP | Oi Wiki](https://oi-wiki.org/dp/plug/)
  - [Broken profile dynamic programming | EvilBuggy](https://coderevilbuggy.blogspot.com/2018/05/broken-profile-dynamic-programming.html)
- **Problems (4):**
  - `[E]` ★ [Counting Tilings](https://cses.fi/problemset/task/2181)
  - `[M]` [Guards In The Storehouse](https://codeforces.com/problemset/problem/845/F)
  - `[M]` [Connect](https://oj.uz/problem/view/CEOI06_connect)
  - `[VH]` [Compound Escape](https://usaco.org/index.php?page=viewproblem2&cpid=949)

#### 8.10.3 Hirschberg's Algorithm

- **ID:** `hirschbergs_algorithm` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/hirschbergs_algorithm
- **Templates (1):**
  - [57512](https://codeforces.com/blog/entry/57512)
- **Resources (1):**
  - [Hirschberg's Algorithm By KokiYmgch](https://codeforces.com/blog/entry/57512)
- **Problems (1):**
  - `[E]` ★ [Classic Task](https://csacademy.com/contest/archive/task/classic-task/)

#### 8.10.4 [Problem] Number of Subsequences Having Product at least K

- **ID:** `number_of_subsequences_having_product_at_least_k` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/number_of_subsequences_having_product_at_least_k
- **Templates (1):**
  - [Number of Subsequences Having Product at least K.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Dynamic%20Programming%20Optimizations/Number%20of%20Subsequences%20Having%20Product%20at%20least%20K.cpp)
- **Resources (1):**
  - [A comment by neutron-byte](https://codeforces.com/blog/entry/55054?#comment-455887)
- **Problems (1):**
  - `[E]` ★ [Подарок](https://codeforces.com/group/NOwIbqv33y/contest/307527/problem/J)

#### 8.10.5 [Problem] Range LIS Query

- **ID:** `lis_range_query` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lis_range_query
- **Resources (3):**
  - ★ [\[Tutorial\] On Range LIS Queries, Part 1 By ko_osaga](https://codeforces.com/blog/entry/111625)
  - ★ [\[Tutorial\] On Range LIS Queries, Part 2 By ko_osaga](https://codeforces.com/blog/entry/111807)
  - [Range query to find Longest Increasing Subsequence Please Help By vivace1](https://codeforces.com/blog/entry/52726)
- **Problems (5):**
  - `[E]` ★ [Sereja and Increasing subsequence](https://www.codechef.com/DEC16/problems/SEAINCR/)
  - `[E]` ★ [Static Range LIS Query](https://judge.yosupo.jp/problem/static_range_lis_query)
  - `[E]` [Product of Unit Monge Matrices](https://loj.ac/p/184)
  - `[M]` [Form the Maximal Set](https://codeforces.com/gym/101237/problem/I)
  - `[M]` [싱싱미역](https://www.acmicpc.net/problem/26164)

---

## 9. Game Theory

**Category ID:** `game_theory` · **Subcategories:** 4 · **Topics:** 7

### 9.1 Grundy Number / Nim

**Subcategory ID:** `grundy_number` · **Topics:** 2

#### 9.1.1 Grundy Number and Basic Game Theory

- **ID:** `grundy_number` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/grundy_number
- **Resources (6):**
  - ★ [Sprague-Grundy theorem. Nim | CP Algorithms](https://cp-algorithms.com/game_theory/sprague-grundy-nim.html)
  - ★ [Sprague-Grundy theorem | e-maxx](http://e-maxx.ru/algo/sprague_grundy)
  - ★ [The Intuition Behind NIM and Grundy Numbers in Combinatorial Game Theory By Shisuko](https://codeforces.com/blog/entry/66040)
  - [ALGORITHM GAMES | Topcoder](https://www.topcoder.com/community/competitive-programming/tutorials/algorithm-games/)
  - [Grundy numbers for competitive programming | Let us code](https://letuskode.blogspot.com/2014/08/grundy-numbers.html)
  - [Game Theory | Arabic tutorial](https://www.youtube.com/watch?v=ediW8zR4dEY)
- **Problems (45):**
  - `[E]` ★ [Day 1: Game of Stones](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/a-game-of-stones/problem)
  - `[E]` [Day 1: Tower Breakers](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/tower-breakers/problem)
  - `[E]` [Day 1: A Chessboard Game](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/day-1-a-chessboard-game)
  - `[E]` ★ [Stick Game](https://cses.fi/problemset/task/1729)
  - `[E]` ★ [Day 2: Nim Game](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/day-2-nim-game/problem)
  - `[E]` ★ [Nim Game I](https://cses.fi/problemset/task/1730)
  - `[E]` ★ [Day 2: Misère Nim](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/misere-nim)
  - `[E]` ★ [Nim Game II](https://cses.fi/problemset/task/1098)
  - `[E]` [S-Nim](https://open.kattis.com/problems/snim)
  - `[E]` ★ [Day 2: Nimble Game](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/nimble)
  - `[E]` [Day 2: Poker Nim](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/day-2-poker-nim)
  - `[E]` ★ [Everything Nim](https://codeforces.com/contest/1965/problem/A)
  - `[E]` ★ [Day 2: Tower Breakers, Revisited!](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/tower-breakers-2/problem)
  - `[M]` [Day 3: Tower Breakers, Again!](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/tower-breakers-3/problem)
  - `[M]` ★ [Day 3: Chessboard Game, Again!](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/a-chessboard-game/problem)
  - `[M]` ★ [Day 3: Digits Square Board](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/digits-square-board/problem)
  - `[M]` [Day 4: Fun Game](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/fun-game)
  - `[M]` ★ [Day 4: Powers Game](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/powers-of-two-game)
  - `[M]` [Day 5: Tower Breakers - The Final Battle](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/final-tower-breakers/problem)
  - `[M]` ★ [Stair Game](https://cses.fi/problemset/task/1099)
  - `[M]` ★ [Grundy's Game](https://cses.fi/problemset/task/2207)
  - `[M]` ★ [Temporal Paradox](https://codeforces.com/group/Rilx5irOux/contest/622715/problem/D)
  - `[M]` [Floor Division Game](https://www.codechef.com/problems/FDIVGAME)
  - `[M]` ★ [Another Game](https://cses.fi/problemset/task/2208)
  - `[M]` ★ [Playing With Stones](https://vjudge.net/problem/UVA-1482)
  - `[M]` ★ [Playing with String](https://codeforces.com/contest/305/problem/E)
  - `[M]` [Arbitrary Nim](https://atcoder.jp/contests/arc168/tasks/arc168_b)
  - `[M]` [Cuboid Slicing Game](https://open.kattis.com/problems/cuboidslicinggame)
  - `[M]` [Marbles](https://codeforces.com/gym/101908/problem/B)
  - `[M]` [Matrix Game](https://www.spoj.com/problems/MATGAME/)
  - `[M]` [Pawn Game](https://acm.timus.ru/problem.aspx?space=1&num=1465)
  - `[M]` ★ [IBM Chill Zone](https://codeforces.com/gym/100500/problem/E)
  - `[M]` ★ [Sagheer and Apple Tree](https://codeforces.com/contest/812/problem/E)
  - `[M]` ★ [Game of Stones](https://codeforces.com/problemset/problem/768/E)
  - `[M]` ★ [Arpa and a game with Mojtaba](https://codeforces.com/contest/850/problem/C)
  - `[M]` [Interval Game 2](https://atcoder.jp/contests/abc206/tasks/abc206_f)
  - `[M]` ★ [A String Game](https://www.codechef.com/problems/ASTRGAME)
  - `[M]` ★ [Not a Nim Problem](https://codeforces.com/contest/2004/problem/E)
  - `[M]` [Bono v3](https://www.spoj.com/problems/BLBONO/)
  - `[M]` [Hagras Game](https://codeforces.com/group/Rilx5irOux/contest/626784/problem/J)
  - `[H]` ★ [Strange Nim](https://atcoder.jp/contests/arc091/tasks/arc091_d)
  - `[H]` [Attack on Red Kingdom](https://codeforces.com/contest/1312/problem/F)
  - `[H]` [Nullify The Matrix](https://codeforces.com/contest/1451/problem/F)
  - `[H]` [Peanuts](https://codeforces.com/contest/2032/problem/F)
  - `[H]` [Nim](https://codeforces.com/contest/2043/problem/F)

#### 9.1.2 Nimber

- **ID:** `nimber` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/nimber
- **Resources (1):**
  - ★ [Nimbers and Sprague-Grundy theorem By adamant](https://codeforces.com/blog/entry/103785)
- **Problems (2):**
  - `[E]` ★ [Nim Product](https://judge.yosupo.jp/problem/nim_product_64)
  - `[H]` ★ [Bad Cryptography](https://codeforces.com/contest/1310/problem/F)

### 9.2 Hackenbush

**Subcategory ID:** `hackenbush` · **Topics:** 2

#### 9.2.1 Green Hackenbush on Trees and Graphs

- **ID:** `green_hackenbush_on_trees_and_graphs` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/green_hackenbush_on_trees_and_graphs
- **Templates (1):**
  - [Green Hackenbush.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Game%20Theory/Green%20Hackenbush.cpp)
- **Resources (3):**
  - [Hackenbush | Wiki](https://en.wikipedia.org/wiki/Hackenbush)
  - [green-hackenbush-ww.pdf](https://www.link.cs.cmu.edu/15859-s11/notes/green-hackenbush-ww.pdf)
  - [2.6 Analysis of Green Hackenbush](https://is.muni.cz/th/325040/fi_b/Combinatorial_games.pdf)
- **Problems (6):**
  - `[E]` ★ [Day 5: Deforestation](https://www.hackerrank.com/contests/5-days-of-game-theory/challenges/deforestation/problem)
  - `[E]` ★ [Game on Tree](https://atcoder.jp/contests/agc017/tasks/agc017_d)
  - `[E]` [Play with a Tree](https://www.spoj.com/PT07/problems/PT07A/)
  - `[E]` [Bob vs ATM](https://www.codechef.com/AMR16MOS/problems/AMR16J)
  - `[M]` [Game of CS](https://lightoj.com/problem/game-of-cs)
  - `[M]` [Game of CS](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3184)

#### 9.2.2 Blue Red HackenBush

- **ID:** `blue_red_hackenbush` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/blue_red_hackenbush
- **Templates (1):**
  - [Blue Red Hackenbush.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Game%20Theory/Blue%20Red%20Hackenbush.cpp)
- **Resources (3):**
  - ★ [3.1 Analysis of Blue-Red Hackenbush](https://is.muni.cz/th/325040/fi_b/Combinatorial_games.pdf)
  - ★ [GERALD08 - Editorial](https://discuss.codechef.com/t/gerald08-editorial/5137)
  - ★ [Red-Blue Hackenbush and Surreal Numbers | Tom Davis](http://www.geometer.org/mathcircles/hackenbush.pdf)
- **Problems (1):**
  - `[M]` ★ [Chef and Tree Game](https://www.codechef.com/problems/GERALD08)

### 9.3 Graph Games

**Subcategory ID:** `graph_games` · **Topics:** 2

#### 9.3.1 Games on Arbitrary Graphs

- **ID:** `games_on_arbitrary_graphs` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/games_on_arbitrary_graphs
- **Resources (1):**
  - ★ [Games on arbitrary graphs | CP Algorithms](https://cp-algorithms.com/game_theory/games_on_graphs.html)
- **Problems (1):**
  - `[M]` [Cat and Mouse](https://leetcode.com/problems/cat-and-mouse/)

#### 9.3.2 [Problem] Matching Game On A Graph

- **ID:** `matching_game_on_a_graph` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/matching_game_on_a_graph
- **Templates (1):**
  - [Matching Game On A Graph.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Game%20Theory/Matching%20Game%20On%20A%20Graph.cpp)
- **Resources (1):**
  - ★ [HAMILG - Editorial](https://discuss.codechef.com/t/hamilg-editorial/11310)
- **Problems (1):**
  - `[M]` ★ [A game on a graph](https://www.codechef.com/problems/HAMILG)

### 9.4 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 1

#### 9.4.1 Alpha Beta Pruning

- **ID:** `alpha_beta_pruning` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/alpha_beta_pruning
- **Templates (1):**
  - [Alpha Beta Pruning.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Game%20Theory/Alpha%20Beta%20Pruning.cpp)
- **Resources (2):**
  - ★ [Minimax Algorithm in Game Theory | Set 4 | Geeks for Geeks](https://www.geeksforgeeks.org/minimax-algorithm-in-game-theory-set-4-alpha-beta-pruning/)
  - [Alpha Beta Pruning Simulator](https://schaerli.org/info2/abTreePractice/)
- **Problems (1):**
  - `[M]` ★ [Some Game](https://www.scribd.com/document/637040478/RUET-IUPC-2022-Problemset)

---

## 10. Geometry

**Category ID:** `geometry` · **Subcategories:** 10 · **Topics:** 55

### 10.1 Euclidean Geometry

**Subcategory ID:** `euclidean_geometry` · **Topics:** 1

#### 10.1.1 Euclidean Geometry

- **ID:** `euclidean_geometry` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/euclidean_geometry
- **Problems (45):**
  - `[E]` ★ [Egypt](https://vjudge.net/problem/UVA-11854)
  - `[E]` [The Lazy Lumberjacks](https://vjudge.net/problem/UVA-11936)
  - `[E]` [10:6:2](https://vjudge.net/problem/UVA-12578)
  - `[E]` ★ [Circle in Square](https://vjudge.net/problem/LightOJ-1022)
  - `[E]` ★ [Behold my quadrangle](https://vjudge.net/problem/UVA-11455)
  - `[E]` [Satellites](https://vjudge.net/problem/UVA-10221)
  - `[E]` [Points in Figures: Rectangles](https://vjudge.net/problem/UVA-476)
  - `[E]` [Points in Figures: Rectangles and Circles](https://vjudge.net/problem/UVA-477)
  - `[E]` [Soya Milk](https://vjudge.net/problem/UVA-11909)
  - `[E]` ★ [Triangle Trouble](https://vjudge.net/problem/UVA-11579)
  - `[E]` ★ [Triangle Partitioning](https://vjudge.net/problem/LightOJ-1043)
  - `[E]` ★ [Crossed Ladders](https://vjudge.net/problem/LightOJ-1062)
  - `[E]` ★ [Three Circle Problem (EASY)](https://www.spoj.com/problems/CIRCLE_E/)
  - `[E]` [Graveyard](https://vjudge.net/problem/UVA-1388)
  - `[E]` [Is this the easiest problem?](https://vjudge.net/problem/UVA-11479)
  - `[E]` ★ [Medians](https://vjudge.net/problem/UVA-10347)
  - `[E]` [Trapezium](https://vjudge.net/problem/LightOJ-1178)
  - `[E]` [The Knights Of The Round Table](https://vjudge.net/problem/UVA-10195)
  - `[E]` ★ [How Cow](https://lightoj.com/problem/how-cow)
  - `[E]` [Area of a Parallelogram](https://vjudge.net/problem/LightOJ-1305)
  - `[E]` ★ [Juice in the Glass](https://lightoj.com/problem/juice-in-the-glass)
  - `[E]` ★ [Universal Radius](https://www.spoj.com/problems/UNIR/)
  - `[E]` ★ [Calm Down](https://lightoj.com/problem/calm-down)
  - `[E]` [Olympics](https://lightoj.com/problem/olympics)
  - `[E]` ★ [Circle of Polygon](https://vjudge.net/problem/Gym-102267H)
  - `[M]` ★ [Region](https://vjudge.net/problem/UVA-10991)
  - `[M]` ★ [The Kissing Circles](https://vjudge.net/problem/UVA-10283)
  - `[M]` ★ [Polygon Inside A Circle](https://vjudge.net/problem/UVA-10432)
  - `[M]` ★ [Agent J](https://vjudge.net/problem/LightOJ-1331)
  - `[M]` ★ [Minimum Arc Distance](https://vjudge.net/problem/LightOJ-1433)
  - `[M]` ★ [How Far?](https://vjudge.net/problem/UVA-10466)
  - `[M]` [Gifts in a Hexagonal Box](https://vjudge.net/problem/UVA-10287)
  - `[M]` ★ [Weird Cake](https://toph.co/p/weird-cake)
  - `[M]` ★ [I Scream, You Scream!](https://toph.co/p/i-scream-you-scream)
  - `[M]` [Hexagonal Packing](https://toph.co/p/hexagonal-packing)
  - `[M]` ★ [Parallelogram Counting](https://lightoj.com/problem/parallelogram-counting)
  - `[M]` [Expanding Rods](https://lightoj.com/problem/expanding-rods)
  - `[M]` ★ [Intersection of Cubes](https://lightoj.com/problem/intersection-of-cubes)
  - `[M]` ★ [Kingdom Division](https://lightoj.com/problem/kingdom-division)
  - `[M]` [Overtake](https://lightoj.com/problem/overtake)
  - `[M]` ★ [Counting Rectangles](https://vjudge.net/problem/UVA-10574)
  - `[M]` ★ [Pair of Touching Circles](https://lightoj.com/problem/pair-of-touching-circles)
  - `[M]` ★ [THE MAX LINES](https://www.spoj.com/problems/MAXLN)
  - `[H]` [Trapezium Drawing](https://lightoj.com/problem/trapezium-drawing)
  - `[H]` ★ [Triangle Inside Rectangle Inside Pentagon](https://codeforces.com/gym/102141/problem/H)

### 10.2 Geometry 2D

**Subcategory ID:** `geo_2d` · **Topics:** 24

#### 10.2.1 Points, Vectors, Transformations, Dot Products, Cross Products, Precision Issues and Polar Sort(2D)

- **ID:** `points_and_vectors_2d` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/points_and_vectors_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L4-L73](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L4-L73)
- **Resources (6):**
  - ★ [Chapter 1 Precision issues and epsilons, Chapter 2.1 Points and vectors, 2.2 Transformations and 2.3 Products and angles | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - [Basic Geometry | CP Algorithms](https://cp-algorithms.com/geometry/basic-geometry.html)
  - [Geometry: 2D points and lines \[Tutorial\] By Al.Cash](https://codeforces.com/blog/entry/48122)
  - [Basic Geometry for Competitive Programming | Geeks for Geeks](https://www.geeksforgeeks.org/basic-geometry-for-competitive-programming/)
  - ★ [Easy geometry using std::complex By Hikari9](https://codeforces.com/blog/entry/22175)
  - [Geometry Russian Contest Problems Translation](https://www.dropbox.com/s/7v0hvsdacw08xd4/Translated%20Geometry%20Set.pdf?e=1)
- **Problems (18):**
  - `[E]` ★ [Point Location Test](https://cses.fi/problemset/task/2189)
  - `[E]` ★ [Length of vector](https://vjudge.net/problem/Gym-100168L)
  - `[E]` [Fourth Point!](https://vjudge.net/problem/UVA-10242)
  - `[E]` ★ [Bright Lights](https://vjudge.net/problem/UVA-10927)
  - `[E]` ★ [Polar angle of point](https://vjudge.net/problem/Gym-100168A)
  - `[E]` ★ [Angle between vectors](https://vjudge.net/problem/Gym-100168B)
  - `[E]` ★ [Once Upon A Time In Child Hood](https://toph.co/p/once-upon-a-time-in-child-hood)
  - `[E]` ★ [Sort Points by Argument](https://judge.yosupo.jp/problem/sort_points_by_argument)
  - `[E]` [Sunny Mountains](https://vjudge.net/problem/UVA-920)
  - `[E]` [Simple](https://toph.co/p/simple)
  - `[M]` [A Chase In WonderLand](https://vjudge.net/problem/SPOJ-CHASE)
  - `[M]` [Underwater Snipers](https://vjudge.net/problem/LightOJ-1383)
  - `[M]` ★ [Angle Beats](https://vjudge.net/problem/Gym-102361A)
  - `[M]` ★ [Disjoint Triangles](https://vjudge.net/problem/CodeForces-1025F)
  - `[M]` ★ [Maximum Number of Colinear Points](https://open.kattis.com/problems/maxcolinear)
  - `[M]` [Sofdor Ali and Attack Optimization](https://toph.co/p/sofdor-ali-and-attack-optimization)
  - `[M]` ★ [Closest Distance](https://lightoj.com/problem/closest-distance)
  - `[H]` ★ [Count Points in Triangles](https://judge.yosupo.jp/problem/count_points_in_triangle)

#### 10.2.2 Lines, Segments, Rays, Distance and Relation Between Two Structures, Projections and Reflections(2D)

- **ID:** `lines_and_segments_2d` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/lines_and_segments_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L74-L269](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L74-L269)
- **Resources (7):**
  - ★ [Chapter 2.4 Lines and 2.5 Segments | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - [Finding the equation of a line for a segment | CP Algorithms](https://cp-algorithms.com/geometry/segment-to-line.html)
  - ★ [Intersection Point of Lines | CP Algorithms](https://cp-algorithms.com/geometry/lines-intersection.html)
  - [Check if two segments intersect | CP Algorithms](https://cp-algorithms.com/geometry/check-segments-intersection.html)
  - ★ [Finding intersection of two segments | CP Algorithms](https://cp-algorithms.com/geometry/segments-intersection.html)
  - [Geometry: 2D points and lines \[Tutorial\] By Al.Cash](https://codeforces.com/blog/entry/48122)
  - [Geometry Russian Contest Problems Translation](https://www.dropbox.com/s/7v0hvsdacw08xd4/Translated%20Geometry%20Set.pdf?e=1)
- **Problems (39):**
  - `[E]` ★ [Distance from a point to a straight line](https://vjudge.net/problem/Gym-100168F)
  - `[E]` ★ [Bisector](https://vjudge.net/problem/Gym-100168E)
  - `[E]` ★ [Distance from point to line](https://vjudge.net/problem/Gym-100168I)
  - `[E]` ★ [Distance from point to line 2](https://vjudge.net/problem/Gym-100168G)
  - `[E]` ★ [Distance from a point to a ray](https://vjudge.net/problem/Gym-100168H)
  - `[E]` ★ [The equation of the straight line I](https://vjudge.net/problem/Gym-100168M)
  - `[E]` ★ [The equation of the straight line II](https://vjudge.net/problem/Gym-100168N)
  - `[E]` ★ [Parallel line](https://vjudge.net/problem/Gym-100168O)
  - `[E]` ★ [Distance between segments](https://vjudge.net/problem/Gym-100168J)
  - `[E]` ★ [Intersection of two lines](https://vjudge.net/problem/Gym-100168K)
  - `[E]` ★ [Belonging to a point of straight line](https://vjudge.net/problem/Gym-100168P)
  - `[E]` ★ [Belonging of a point to a segment](https://vjudge.net/problem/Gym-100168R)
  - `[E]` ★ [Belonging to the point of the ray](https://vjudge.net/problem/Gym-100168Q)
  - `[E]` [The position of the points outside the line](https://vjudge.net/problem/Gym-100168S)
  - `[E]` ★ [Line Segment Intersection](https://cses.fi/problemset/task/2190)
  - `[E]` ★ [Line Segment Intersection](https://open.kattis.com/problems/segmentintersection)
  - `[E]` ★ [Line Segment Distance](https://open.kattis.com/problems/segmentdistance)
  - `[E]` [An Angular Puzzle](https://vjudge.net/problem/UVA-12301)
  - `[E]` ★ [Intersection](https://vjudge.net/problem/UVA-191)
  - `[E]` ★ [Intersecting Lines](https://vjudge.net/problem/UVA-378)
  - `[E]` ★ [Isolated Segments](https://vjudge.net/problem/UVA-11343)
  - `[E]` [Pick-up Sticks](https://vjudge.net/problem/UVA-10902)
  - `[E]` ★ [Berry Picking](https://vjudge.net/problem/UVA-858)
  - `[E]` ★ [The Ant](https://vjudge.net/problem/SPOJ-ANTTT)
  - `[E]` [Birthday Cake](https://open.kattis.com/problems/birthdaycake)
  - `[E]` ★ [LFR](https://toph.co/p/lfr)
  - `[M]` ★ [Distance between rays](https://vjudge.net/problem/Gym-100168T)
  - `[M]` [Mysterious Mountain](https://vjudge.net/problem/UVA-10122)
  - `[M]` [GX Light Pipeline Inc](https://vjudge.net/problem/SPOJ-LITEPIPE)
  - `[M]` [Boris, You Are Wrong!](https://vjudge.net/problem/URAL-1710)
  - `[M]` ★ [Overlapping Sticks](https://vjudge.net/problem/LightOJ-1432)
  - `[M]` ★ [Rectangle Division](https://toph.co/p/rectangle-division)
  - `[M]` ★ [Alien Invasion](https://toph.co/p/alien-invasion)
  - `[M]` ★ [Laser Shot](https://lightoj.com/problem/laser-shot)
  - `[M]` ★ [Parallel Lines](https://vjudge.net/problem/Gym-105170D)
  - `[H]` ★ [Race Track](https://lightoj.com/problem/race-track)
  - `[H]` ★ [Farmers' Tale](https://lightoj.com/problem/farmers-tale)
  - `[H]` ★ [Aladdin and the Rocky Mountains](https://lightoj.com/problem/aladdin-and-the-rocky-mountai)
  - `[VH]` ★ [Minimize the Distance](https://vjudge.net/problem/CodeChef-MINDIST)

#### 10.2.3 Circles, Circle Relations, Intersections, Inscribed Circles and Circumcircles(2D)

- **ID:** `circles_2d` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/circles_2d
- **Templates (2):**
  - [Geometry 2D.cpp#L270-L363](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L270-L363)
  - [Geometry 2D.cpp#L410-L419](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L410-L419)
- **Resources (3):**
  - ★ [Chapter 2.7 Circles (excluding 2.7.5 Tangent lines) | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - ★ [Circle-Line Intersection | CP Algorithms](https://cp-algorithms.com/geometry/circle-line-intersection.html)
  - [Circle-Circle Intersection | CP Algorithms](https://cp-algorithms.com/geometry/circle-circle-intersection.html)
- **Problems (17):**
  - `[E]` ★ [The Circumference of the Circle](https://vjudge.net/problem/UVA-438)
  - `[E]` ★ [Circle Through Three Points](https://vjudge.net/problem/UVA-190)
  - `[E]` ★ [Colourful Flowers](https://vjudge.net/problem/UVA-11152)
  - `[E]` ★ [A New Door](https://www.codechef.com/problems/ANDOOR)
  - `[E]` ★ [Intersecting Circles](https://www.spoj.com/problems/CIRCINT/)
  - `[E]` ★ [Incredible Molecules](https://vjudge.net/problem/LightOJ-1118)
  - `[E]` [Air Strike](https://vjudge.net/problem/SPOJ-ANARC09F)
  - `[E]` ★ [Two Circles](https://www.spoj.com/problems/SMPCIRC/)
  - `[E]` [Circle of Boltu](https://toph.co/p/circle-of-boltu)
  - `[M]` [Rings and Glue](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1242)
  - `[M]` [Runaway to a Shadow](https://codeforces.com/problemset/problem/681/E)
  - `[M]` [Get Out!](https://codeforces.com/gym/100199/problem/F)
  - `[M]` [Biscuits](https://acm.timus.ru/problem.aspx?space=1&num=1429)
  - `[M]` ★ [Pair of Touching Circles](https://lightoj.com/problem/pair-of-touching-circles)
  - `[H]` ★ [A Colourful Prospect](https://codeforces.com/problemset/problem/933/C)
  - `[H]` ★ [LL’s cake](https://vjudge.net/problem/POJ-3743)
  - `[H]` ★ [The Falling Circle](https://lightoj.com/problem/the-falling-circle)

#### 10.2.4 Tangents(2D)

- **ID:** `tangent_2d` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tangent_2d
- **Templates (2):**
  - [Geometry 2D.cpp#L420-L454](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L420-L454)
  - [Geometry 2D.cpp#L364-L391](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L364-L391)
- **Resources (2):**
  - ★ [Chapter 2.7.5 Tangent lines | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - ★ [Finding common tangents to two circles | CP Algorithms](https://cp-algorithms.com/geometry/tangents-to-two-circles.html)
- **Problems (2):**
  - `[M]` ★ [2D Geometry 110 in 1!](https://vjudge.net/problem/UVA-12304)
  - `[M]` [Chapaev](https://acm.timus.ru/problem.aspx?space=1&num=1163)

#### 10.2.5 Circles of Apollonius(2D)

- **ID:** `circles_of_apollonius_2d` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/circles_of_apollonius_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L392-L409](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L392-L409)
- **Resources (1):**
  - ★ [Circles of Apollonius | Wiki](https://en.wikipedia.org/wiki/Circles_of_Apollonius)
- **Problems (1):**
  - `[M]` ★ [Commentator problem](https://codeforces.com/problemset/problem/2/C)

#### 10.2.6 Circle Union(2D)

- **ID:** `circle_union_2d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/circle_union_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L455-L554](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L455-L554)
- **Resources (1):**
  - [Area of union of circles discussion](https://codeforces.com/blog/entry/2111)
- **Problems (3):**
  - `[E]` ★ [Area of circles](https://www.spoj.com/problems/VCIRCLES/)
  - `[H]` ★ [The area of the union of circles](https://www.spoj.com/problems/CIRU/)
  - `[H]` ★ [Cleaning the Hallway](https://codeforces.com/gym/100443/problem/J)

#### 10.2.7 Polygons(2D)

- **ID:** `polygons_2d` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/polygons_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L555-L577](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L555-L577)
- **Resources (3):**
  - ★ [Chapter 2.6.1 Polygon area and 2.6.2 Cutting-ray test | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - ★ [Oriented area of a triangle | CP Algorithms](https://cp-algorithms.com/geometry/oriented-triangle-area.html)
  - ★ [Finding area of simple polygon | CP Algorithms](https://cp-algorithms.com/geometry/area-of-simple-polygon.html)
- **Problems (9):**
  - `[E]` ★ [Polygon Area](https://cses.fi/problemset/task/2191)
  - `[E]` ★ [Polygon Area](https://open.kattis.com/problems/polygonarea)
  - `[E]` [Smallest Regular Polygon](https://vjudge.net/problem/UVA-12300)
  - `[E]` [Points in Figures: Rectangles, Circles, Triangles](https://vjudge.net/problem/UVA-478)
  - `[E]` [Determine the Shape](https://vjudge.net/problem/UVA-11800)
  - `[E]` ★ [Divorce](https://vjudge.net/problem/Gym-101845D)
  - `[E]` ★ [Drawing Simple Polygon](https://lightoj.com/problem/drawing-simple-polygon)
  - `[M]` ★ [Piece of Cake](https://vjudge.net/problem/Kattis-pieceofcake)
  - `[H]` [Chef and Polygons](https://www.codechef.com/problems/CHEFPOLY)

#### 10.2.8 Centroid of a Polygon(2D)

- **ID:** `centroid_of_a_polygon_2d` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/centroid_of_a_polygon_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L578-L592](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L578-L592)
- **Resources (1):**
  - [Centroid | Wiki](https://en.wikipedia.org/wiki/Centroid)
- **Problems (2):**
  - `[E]` [Lifting the Stone](https://www.spoj.com/problems/STONE/)
  - `[M]` ★ [Crane Balancing](https://vjudge.net/problem/Kattis-crane)

#### 10.2.9 Geometric Median(2D)

- **ID:** `geometric_median_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/geometric_median_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L600-L632](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L600-L632)
- **Resources (2):**
  - [Geometric median | Wiki](https://en.wikipedia.org/wiki/Geometric_median)
  - [On finding geometric median with ternary searches By shortHorse](https://codeforces.com/blog/entry/71906)
- **Problems (1):**
  - `[E]` ★ [A Star not a Tree?](https://vjudge.net/problem/POJ-2420)

#### 10.2.10 Convex Hull(2D)

- **ID:** `convex_hull_2d` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/convex_hull_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L633-L669](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L633-L669)
- **Resources (3):**
  - ★ [Convex Hull construction | CP Algorithms](https://cp-algorithms.com/geometry/convex-hull.html)
  - ★ [Convex Hull | USACO Guide](https://usaco.guide/plat/convex-hull?lang=cpp)
  - ★ [Number of points on Convex hull with lattice points By Anachor](https://codeforces.com/blog/entry/62183)
- **Problems (22):**
  - `[E]` ★ [Convex Hull](https://cses.fi/problemset/task/2195)
  - `[E]` [Convex Hull](https://open.kattis.com/problems/convexhull)
  - `[E]` ★ [Static Convex Hull](https://judge.yosupo.jp/problem/static_convex_hull)
  - `[E]` ★ [Guarding Bananas](https://vjudge.net/problem/LightOJ-1203)
  - `[E]` [SCUD Busters](https://vjudge.net/problem/UVA-109)
  - `[E]` [Useless Tile Packers](https://vjudge.net/problem/UVA-10065)
  - `[E]` [Palindromic Polygon](https://vjudge.net/problem/QOJ-9417)
  - `[E]` ★ [Triangle Trap](https://codeforces.com/gym/105884/problem/C)
  - `[M]` ★ [Convex Fence](https://vjudge.net/problem/LightOJ-1239)
  - `[M]` ★ [Darts](https://vjudge.net/problem/CodeChef-DARTSEGM)
  - `[M]` ★ [Kingdom Division 2](https://vjudge.net/problem/Gym-100517K)
  - `[M]` ★ [Wall](https://acm.timus.ru/problem.aspx?space=1&num=1185)
  - `[M]` [Keep the Parade Safe](https://open.kattis.com/problems/parade)
  - `[M]` ★ [U2](https://codeforces.com/problemset/problem/1143/F)
  - `[M]` [Cow Curling](https://usaco.org/index.php?page=viewproblem2&cpid=382)
  - `[M]` ★ [Triangle](https://vjudge.net/problem/POJ-2079)
  - `[M]` ★ [Water Balance](https://codeforces.com/problemset/problem/1299/C)
  - `[M]` ★ [CONSEPHULL](https://toph.co/p/consephull)
  - `[H]` ★ [Towers of Wadia](https://toph.co/p/towers-of-wadia)
  - `[H]` ★ [Chop Chop](https://toph.co/p/chop-chop)
  - `[H]` ★ [Protect the Mines](https://lightoj.com/problem/protect-the-mines)
  - `[H]` [Kingdom Of Kittens](https://vjudge.net/problem/Kattis-kingdomofkittens)

#### 10.2.11 Point in Convex Polygon in log(N)(2D)

- **ID:** `check_if_point_is_in_convex_2d` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/check_if_point_is_in_convex_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L670-L687](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L670-L687)
- **Resources (2):**
  - ★ [Check if point belongs to the convex polygon | CP Algorithms](https://cp-algorithms.com/geometry/point-in-convex-polygon.html)
  - [4.1 Triangle: O(1) and 4.2 Convex polygon: O(logN)](https://codeforces.com/blog/entry/48868)
- **Problems (5):**
  - `[E]` ★ [Polygon and Points](https://atcoder.jp/contests/abc296/tasks/abc296_g)
  - `[E]` ★ [Polygons](https://codeforces.com/contest/166/problem/B)
  - `[E]` ★ [Theodore Roosevelt](https://codeforces.com/problemsets/acmsguru/problem/99999/253)
  - `[M]` [Very simple problem](https://codeforces.com/contest/55/problem/E)
  - `[M]` ★ [Mogohu-Rea Idol](https://codeforces.com/problemset/problem/87/E)

#### 10.2.12 Winding Number and Point in Simple Polygon(2D)

- **ID:** `winding_number_2d` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/winding_number_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L688-L714](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L688-L714)
- **Resources (3):**
  - [Winding number | Wiki](https://en.wikipedia.org/wiki/Winding_number)
  - [Point in polygon | Wiki](https://en.wikipedia.org/wiki/Point_in_polygon)
  - ★ [4.3 Simple polygon: O(N)](https://codeforces.com/blog/entry/48868)
- **Problems (3):**
  - `[E]` ★ [Winding Number](https://acm.timus.ru/problem.aspx?space=1&num=1599)
  - `[E]` [Point in Polygon](https://cses.fi/problemset/task/2192)
  - `[E]` [Point in Polygon](https://open.kattis.com/problems/pointinpolygon)

#### 10.2.13 Extreme Vertex(2D)

- **ID:** `extreme_vertex_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/extreme_vertex_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L715-L740](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L715-L740)
- **Resources (1):**
  - ★ [5. Extreme points](https://codeforces.com/blog/entry/48868)

#### 10.2.14 Rotating Calipers ft Diameter and Width of a Convex Polygon and Minimum Enclosing Rectangle(2D)

- **ID:** `rotating_calipers` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/rotating_calipers
- **Templates (1):**
  - [Geometry 2D.cpp#L741-L794](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L741-L794)
- **Resources (5):**
  - [Rotating calipers| Wiki](https://en.wikipedia.org/wiki/Rotating_calipers)
  - ★ [COMPUTATIONAL GEOMETRY WITH THE ROTATING CALIPERS by Hormoz Pirzadeh](https://www.nlc-bnc.ca/obj/s4/f2/dsk1/tape7/PQDD_0027/MQ50856.pdf?oclc_number=1006918422)
  - ★ [\[Tutorial\] Rotating calipers technique and its applications By asdasdqwer](https://codeforces.com/blog/entry/133763)
  - [Solving Geometric Problems with the Rotating Calipers | Godfried Toussaint](https://web.cs.swarthmore.edu/~adanner/cs97/s08/pdf/calipers.pdf)
  - [Finding the Diameter of a Polygon using Two pointers and Monotone Chain By chromate00](https://codeforces.com/blog/entry/110739)
- **Problems (12):**
  - `[E]` ★ [Robert Hood](https://open.kattis.com/problems/roberthood)
  - `[E]` ★ [All-Pair Farthest Points](https://vjudge.net/problem/UVA-12311)
  - `[E]` ★ [Furthest Pair of Points](https://judge.yosupo.jp/problem/furthest_pair)
  - `[E]` ★ [Trash Removal](https://vjudge.net/problem/UVA-1111)
  - `[E]` ★ [Fossil in the Ice](https://www.spoj.com/problems/TFOSS/)
  - `[E]` ★ [Fence Orthogonality](https://open.kattis.com/problems/fenceortho)
  - `[E]` [Largest Triangle](https://open.kattis.com/problems/largesttriangle)
  - `[E]` ★ [Smallest Enclosing Rectangle](https://vjudge.net/problem/UVA-12307)
  - `[E]` ★ [Smallest Bounding Rectangle](https://vjudge.net/problem/UVA-10173)
  - `[E]` ★ [Blowing Candles](https://codeforces.com/gym/101635/problem/K)
  - `[M]` ★ [Triangle](https://vjudge.net/problem/POJ-2079)
  - `[M]` ★ [Bridge Across Islands](https://vjudge.net/problem/POJ-3608)

#### 10.2.15 Minimum Enclosing Circle(2D)

- **ID:** `minimum_enclosing_circle_2d` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_enclosing_circle_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L795-L818](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L795-L818)
- **Resources (6):**
  - ★ [Smallest-circle problem | Wiki](https://en.wikipedia.org/wiki/Smallest-circle_problem)
  - ★ [Minimum enclosing circle using Welzl’s algorithm | Geeks for Geeks](https://www.geeksforgeeks.org/minimum-enclosing-circle-using-welzls-algorithm/)
  - ★ [Commented out code about Welzl's Algorithm](https://codeforces.com/blog/entry/112245?#comment-1000097)
  - ★ [Smallest Enclosing Circle Slides](http://www.cs.cmu.edu/~15451-s22/lectures/lec21-SEC-beamer.pdf)
  - [How to find the minimum enclosing circle of a set of points ZeroKelvinTutorials](https://www.youtube.com/watch?v=j5t2tYsM2mM)
  - ★ [Simple approach of Smallest Circle problem: Hill Climbing Tozan Southerpacks Redcoder](https://www.youtube.com/watch?v=WGOSX6d17TU)
- **Problems (6):**
  - `[E]` ★ [Enclose All](https://atcoder.jp/contests/abc151/tasks/abc151_f)
  - `[E]` ★ [Minimum Diameter Circle](https://www.spoj.com/problems/QCJ4/)
  - `[E]` [Aliens](https://www.spoj.com/problems/ALIENS/)
  - `[E]` ★ [Rise of the Robots](https://vjudge.net/problem/Gym-102006I)
  - `[E]` [Weird Flecks, But OK](https://open.kattis.com/problems/weirdflecksbutok)
  - `[M]` [N-Ta-Gon Has a Problem](https://toph.co/p/n-ta-gon-has-a-problem)

#### 10.2.16 Polygon Line and Convex Line Intersection, and Polygon Cutting(2D)

- **ID:** `polygon_line_intersection_2d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polygon_line_intersection_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L819-L896](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L819-L896)
- **Resources (2):**
  - ★ [6. Polygon stabbing](https://codeforces.com/blog/entry/48868)
  - ★ [Intersection between a convex polygon and a line](https://tjkendev.github.io/procon-library/python/geometry/line_convex_polygon_intersection.html)
- **Problems (3):**
  - `[E]` ★ [Cut Length](https://codeforces.com/contest/598/problem/F)
  - `[M]` ★ [Airport Construction](https://vjudge.net/problem/Kattis-airport)
  - `[H]` ★ [Freestyle](https://atcoder.jp/contests/abc356/tasks/abc356_g)

#### 10.2.17 Tangents from Point to Convex and Convex to Convex(2D)

- **ID:** `tangents_from_point_to_polygon_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/tangents_from_point_to_polygon_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L897-L930](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L897-L930)
- **Resources (6):**
  - ★ [5.1 Convex polygon: O(logN)](https://codeforces.com/blog/entry/48868)
  - ★ [Upper and lower tangent line to convex hull from a point](https://cs.stackexchange.com/questions/138901/upper-and-lower-tangent-line-to-convex-hull-from-a-point)
  - [09 Convex Hulls - Common tangent from a point | peyman afshani](https://www.youtube.com/watch?v=xwpCSvvOfMI)
  - [10 Convex Hulls - Common tangent between two hulls peyman afshani](https://www.youtube.com/watch?v=ESHYt_xQ-FY&list=PLtTatrCwXHzFp1Y_c6i82waJ2b7OWyiKM&index=10)
  - [Tangents between two Convex Polygons | Geeks for Geeks](https://www.geeksforgeeks.org/tangents-two-convex-polygons/)
  - [Help for a Geometry Problem By _Ash__](https://codeforces.com/blog/entry/64003)
- **Problems (4):**
  - `[E]` ★ [Cover the Points](https://toph.co/p/cover-the-points)
  - `[H]` ★ [Circular Island](https://codeforces.com/gym/101370/problem/D)
  - `[H]` ★ [Enclosure](https://codeforces.com/gym/101201/problem/E)
  - `[H]` [Spaceship Exploration](https://codeforces.com/contest/1906/problem/D)

#### 10.2.18 Distance from Point to Convex, Convex to Line and Convex to Convex(2D)

- **ID:** `dist_from_point_to_polygon_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dist_from_point_to_polygon_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L932-L977](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L932-L977)
- **Resources (2):**
  - [COMPUTATIONAL GEOMETRY WITH THE ROTATING CALIPERS by Hormoz Pirzadeh](https://www.nlc-bnc.ca/obj/s4/f2/dsk1/tape7/PQDD_0027/MQ50856.pdf?oclc_number=1006918422)
  - [\[Tutorial\] Distance of two convex polygon By FHVirus](https://codeforces.com/blog/entry/103477)
- **Problems (1):**
  - `[M]` ★ [Bridge Across Islands](https://vjudge.net/problem/POJ-3608)

#### 10.2.19 Maximum Distance from Convex to Convex(2D)

- **ID:** `maximum_dist_from_polygon_to_polygon_2d` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_dist_from_polygon_to_polygon_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L978-L997](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L978-L997)
- **Resources (1):**
  - [COMPUTATIONAL GEOMETRY WITH THE ROTATING CALIPERS by Hormoz Pirzadeh](https://www.nlc-bnc.ca/obj/s4/f2/dsk1/tape7/PQDD_0027/MQ50856.pdf?oclc_number=1006918422)

#### 10.2.20 Polygon Union(2D)

- **ID:** `polygon_union_2d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polygon_union_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L999-L1044](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L999-L1044)
- **Problems (1):**
  - `[E]` ★ [Darts](https://codeforces.com/contest/107/problem/E)

#### 10.2.21 Polygon Triangulation(2D)

- **ID:** `triangulation_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/triangulation_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L1244-L1270](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1244-L1270)
- **Resources (3):**
  - ★ [Polygon triangulation | Wiki](https://en.wikipedia.org/wiki/Polygon_triangulation)
  - [Every Polygon can be Triangulated Into Exactly n-2 Triangles | Proof by Induction | Think Twice](https://www.youtube.com/watch?v=2x4ioToqe_c)
  - ★ [Polygon Triangulation \[1\] - Overview of Ear Clipping | Two-Bit Coding](https://www.youtube.com/watch?v=QAdfkylpYwc)
- **Problems (2):**
  - `[M]` [Back To The Polygon](https://www.spoj.com/problems/BACKTPOL/)
  - `[H]` ★ [Gears](https://codeforces.com/contest/497/problem/D)

#### 10.2.22 Maximum Circle Cover(2D)

- **ID:** `maximum_circle_cover_2d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_circle_cover_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L1178-L1218](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1178-L1218)
- **Resources (1):**
  - [What is an algorithm for enclosing the maximum number of points in a 2-D plane with a fixed-radius circle? | Quora](https://www.quora.com/What-is-an-algorithm-for-enclosing-the-maximum-number-of-points-in-a-2-D-plane-with-a-fixed-radius-circle)
- **Problems (3):**
  - `[E]` ★ [Circle and Points](http://poj.org/problem?id=1981)
  - `[M]` ★ [WiFi Expenses](https://vjudge.net/problem/CodeChef-INF16L)
  - `[M]` ★ [Chef and Circle](https://www.codechef.com/JAN17/problems/CHEFCIRC)

#### 10.2.23 Maximum Inscribed Circle in a Convex(2D)

- **ID:** `maximum_inscribed_circle_2d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_inscribed_circle_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L1219-L1243](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1219-L1243)
- **Problems (2):**
  - `[E]` [Most Distant Point from the Sea](https://vjudge.net/problem/POJ-3525)
  - `[E]` [제주도](https://www.acmicpc.net/problem/3903)

#### 10.2.24 Triangle Circle and Polygon Circle Intersection(2D)

- **ID:** `polygon_circle_intersection_2d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polygon_circle_intersection_2d
- **Templates (1):**
  - [Geometry 2D.cpp#L1130-L1177](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1130-L1177)
- **Problems (6):**
  - `[E]` ★ [Intersection between Circle and Rectangle](https://lightoj.com/problem/intersection-between-circle-a)
  - `[E]` ★ [Fukushima Nuclear Blast](https://vjudge.net/problem/LightOJ-1358)
  - `[E]` ★ [Pollution Solution](https://vjudge.net/problem/Gym-101208J)
  - `[H]` ★ [Area of an amazing figure](https://www.codechef.com/CHN17ROL/problems/AREAFIGR)
  - `[H]` ★ [Gears](https://codeforces.com/contest/497/problem/D)
  - `[H]` [Cover the Polygon with Your Disk](https://codeforces.com/gym/101158/problem/J)

### 10.3 Geometry 3D

**Subcategory ID:** `geo_3d` · **Topics:** 9

#### 10.3.1 Points, Vectors, Dot Products, Cross Products and Mixed Products(3D)

- **ID:** `points_and_vectors_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/points_and_vectors_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L1-L95](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L1-L95)
- **Resources (1):**
  - ★ [Chapter 3.1 Points, products and orientation | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (2):**
  - `[E]` ★ [Triangle](https://codeforces.com/problemset/problem/18/A)
  - `[E]` ★ [How I Wonder What You Are!](https://vjudge.net/problem/POJ-3129)

#### 10.3.2 Planes(3D)

- **ID:** `planes_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/planes_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L97-L129](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L97-L129)
- **Resources (1):**
  - ★ [Chapter 3.2 Planes (excluding 3.2.5) | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (1):**
  - `[M]` ★ [Composite Transformations](https://vjudge.net/problem/UVA-12303)

#### 10.3.3 Plane Based Coordinate System(3D)

- **ID:** `plane_based_coordinate_system_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/plane_based_coordinate_system_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L131-L161](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L131-L161)
- **Resources (1):**
  - ★ [Chapter 3.2.5 Coordinate system based on a plane | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (2):**
  - `[H]` ★ [Bikpik Colony](https://toph.co/p/bikpik-colony)
  - `[H]` ★ [Stars in a Can](https://naipc17.kattis.com/contests/naipc17/problems/starsinacan)

#### 10.3.4 Lines, Segments, and Distances, Angles and Intersections Between Lines and Planes(3D)

- **ID:** `lines_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lines_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L163-L258](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L163-L258)
- **Resources (2):**
  - ★ [Chapter 3.3 Lines | CP Geo](https://victorlecomte.com/cp-geo.pdf)
  - ★ [Chapter 3.4 Angles between planes and lines | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (4):**
  - `[E]` ★ [Ardenia](https://vjudge.net/problem/UVA-1469)
  - `[M]` [The Deadly Olympic Returns!!!](https://vjudge.net/problem/UVA-10794)
  - `[M]` ★ [Star War](https://vjudge.net/problem/UVA-11836)
  - `[H]` ★ [Entangled Circles](https://vjudge.net/problem/CodeChef-CIRCLES)

#### 10.3.5 Triangles and Distance from Triangle to Triangle(3D)

- **ID:** `distance_from_triangle_to_triangle_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/distance_from_triangle_to_triangle_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L259-L304](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L259-L304)
- **Resources (1):**
  - ★ [A comment by ko_osaga](https://codeforces.com/blog/entry/64489?#comment-485643)
- **Problems (3):**
  - `[E]` ★ [Triangles](https://codeforces.com/gym/102040/problem/I)
  - `[E]` ★ [3D Triangles](https://vjudge.net/problem/UVA-11275)
  - `[H]` [Paperweight](https://vjudge.net/problem/UVA-1100)

#### 10.3.6 Spherical Geometry and Winding Number(3D)

- **ID:** `spheres_3d` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/spheres_3d
- **Templates (2):**
  - [Geometry 3D.cpp#L548-L746](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L548-L746)
  - [Geometry 3D.cpp#L768-L776](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L768-L776)
- **Resources (1):**
  - ★ [3.6 Spherical geometry | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (3):**
  - `[M]` ★ [Der Stern](https://lightoj.com/problem/der-stern)
  - `[M]` ★ [Bermuda Polygon](https://vjudge.net/problem/UVA-13281)
  - `[M]` ★ [Cutting Cheese](https://vjudge.net/problem/Kattis-cheese)

#### 10.3.7 Minimum Enclosing Sphere(3D)

- **ID:** `minimum_enclosing_sphere_3d` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/minimum_enclosing_sphere_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L748-L766](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L748-L766)
- **Resources (2):**
  - ★ [Simple approach of Smallest Circle problem: Hill Climbing Tozan Southerpacks Redcoder](https://www.youtube.com/watch?v=WGOSX6d17TU)
  - ★ [Smallest Enclosing Circle/Sphere Problem By hongjun-7](https://codeforces.com/blog/entry/23554)
- **Problems (2):**
  - `[E]` ★ [Space Rescuers](https://codeforces.com/problemset/problem/106/E)
  - `[E]` ★ [Minimizing Sphere](https://toph.co/p/minimizing-sphere)

#### 10.3.8 Polyhedron, Pyramid, Cone and Cylinder(3D)

- **ID:** `polyhedron_3d` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/polyhedron_3d
- **Templates (2):**
  - [Geometry 3D.cpp#L307-L365](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L307-L365)
  - [Geometry 3D.cpp#L779-L825](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L779-L825)
- **Resources (1):**
  - ★ [Chapter 3.5 Polyhedrons | CP Geo](https://victorlecomte.com/cp-geo.pdf)
- **Problems (3):**
  - `[E]` [Pyramid](https://lightoj.com/problem/pyramid)
  - `[M]` [Weapon](https://vjudge.net/problem/HDU-4617)
  - `[VH]` [Tetrahedrons and Spheres](https://vjudge.net/problem/UVA-11887)

#### 10.3.9 Convex Hull(3D)

- **ID:** `convex_hull_3d` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/convex_hull_3d
- **Templates (1):**
  - [Geometry 3D.cpp#L367-L546](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L367-L546)
- **Resources (1):**
  - ★ [Efficient 3D Convex Hull Tutorial By Monogon](https://codeforces.com/blog/entry/81768)
- **Problems (5):**
  - `[E]` ★ [3D Convex Hull](https://vjudge.net/problem/HDU-3662)
  - `[E]` [Convex Hull 3D](https://www.spoj.com/problems/CH3D/)
  - `[E]` [Ultimate Weapon](https://vjudge.net/problem/POJ-3528)
  - `[M]` ★ [Asteroids](https://vjudge.net/problem/POJ-3862)
  - `[H]` ★ [Stars in a Can](https://naipc17.kattis.com/contests/naipc17/problems/starsinacan)

### 10.4 Delaunay

**Subcategory ID:** `delaunay` · **Topics:** 1

#### 10.4.1 Delaunay Triangulation and Voronoi Diagram

- **ID:** `delaunay_triangulation` · **Difficulty:** Very Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/delaunay_triangulation
- **Templates (2):**
  - [Delaunay Triangulation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Delaunay%20Triangulation.cpp)
  - [Voronoi Diagram.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Voronoi%20Diagram.cpp)
- **Resources (4):**
  - ★ [\[Tutorial\] Voronoi Diagram and Delaunay Triangulation in O(n log n) with Fortune's Algorithm By Monogon](https://codeforces.com/blog/entry/85638)
  - [Delaunay triangulation | Wiki](https://en.wikipedia.org/wiki/Delaunay_triangulation)
  - [Voronoi diagram | Wiki](https://en.wikipedia.org/wiki/Voronoi_diagram)
  - ★ [Delaunay triangulation and Voronoi diagram | CP Algorithms](https://cp-algorithms.com/geometry/delaunay.html)
- **Problems (5):**
  - `[E]` ★ [Landing](https://dmoj.ca/problem/cco08p6)
  - `[M]` [Caravans](https://codeforces.com/problemsets/acmsguru/problem/99999/383)
  - `[M]` [Good Manners](https://acm.timus.ru/problem.aspx?space=1&num=1504)
  - `[M]` [Empire Strikes Back](https://acm.timus.ru/problem.aspx?space=1&num=1520)
  - `[H]` ★ [Panda Preserve](https://icpc.kattis.com/problems/pandapreserve)

### 10.5 Half Plane

**Subcategory ID:** `half_plane` · **Topics:** 2

#### 10.5.1 Half Plane Intersection

- **ID:** `half_plane_intersection` · **Difficulty:** Hard · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/half_plane_intersection
- **Templates (1):**
  - [Half Plane Intersection.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Half%20Plane%20Intersection.cpp)
- **Resources (2):**
  - ★ [Half-plane intersection | CP Algorithms](https://cp-algorithms.com/geometry/halfplane-intersection.html)
  - ★ [Blogewoosh #5 (with images from now) By Radewoosh](https://codeforces.com/blog/entry/61710)
- **Problems (20):**
  - `[E]` ★ [Video Surveillance](https://vjudge.net/problem/POJ-1474)
  - `[E]` ★ [Polygons Intersection](https://codeforces.com/gym/100952/problem/J)
  - `[E]` ★ [Defend the Recipe](https://www.codechef.com/problems/ALLPOLY)
  - `[E]` ★ [Uyuw's Concert](https://vjudge.net/problem/POJ-2451)
  - `[E]` [Animesh decides to settle down](https://www.codechef.com/problems/CHN02)
  - `[E]` [Rotating Scoreboard](http://poj.org/problem?id=3335)
  - `[E]` [How I Mathematician Wonder What You Are!](http://poj.org/problem?id=3130)
  - `[E]` [Art Gallery](http://poj.org/problem?id=1279)
  - `[E]` [Polygons](https://vjudge.net/problem/UVA-137)
  - `[E]` [Domes](https://vjudge.net/problem/Kattis-domes)
  - `[E]` [Most Distant Point from the Sea](https://vjudge.net/problem/POJ-3525)
  - `[E]` [제주도](https://www.acmicpc.net/problem/3903)
  - `[M]` ★ [The Perfect Spider Web](https://codeforces.com/gym/105973/problem/E)
  - `[M]` [Feng Shui](http://poj.org/problem?id=3384)
  - `[M]` ★ [Ax + By < C](https://atcoder.jp/contests/abc372/tasks/abc372_g)
  - `[M]` [Health in Hazard](https://codeforces.com/gym/104736/problem/H)
  - `[H]` [Triathlon](http://poj.org/problem?id=1755)
  - `[H]` [Arrow](https://dmoj.ca/problem/ccoprep3p3)
  - `[H]` [Jungle Outpost](http://poj.org/problem?id=3968)
  - `[VH]` [(Almost) Fair Cake-Cutting](https://basecamp.eolymp.com/en/problems/11100)

#### 10.5.2 Dynamic Half Plane Intersection

- **ID:** `dynamic_half_plane_intersection` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_half_plane_intersection
- **Templates (1):**
  - [Half Plane Intersection Dynamic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Half%20Plane%20Intersection%20Dynamic.cpp)
- **Problems (1):**
  - `[E]` ★ [Defend the Recipe](https://www.codechef.com/problems/ALLPOLY)

### 10.6 Convex Polygon

**Subcategory ID:** `convex_polygon` · **Topics:** 3

#### 10.6.1 Minkowski Sum

- **ID:** `minkowski_sum` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/minkowski_sum
- **Templates (1):**
  - [Geometry 2D.cpp#L1103-L1129](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1103-L1129)
- **Resources (3):**
  - ★ [Minkowski sum of convex polygons | CP Algorithms](https://cp-algorithms.com/geometry/minkowski.html)
  - ★ [\[Tutorial\] Distance of two convex polygon By FHVirus](https://codeforces.com/blog/entry/103477)
  - [\[Solved\] A problem related to: minkowski sum of two simple polygon By steinum](https://codeforces.com/blog/entry/90738)
- **Problems (8):**
  - `[E]` [Bridge Across Islands](https://vjudge.net/problem/OpenJ_Bailian-3851)
  - `[M]` ★ [Mogohu-Rea Idol](https://codeforces.com/problemset/problem/87/E)
  - `[M]` ★ [Geometers Anonymous Club](https://codeforces.com/contest/1195/problem/F)
  - `[M]` ★ [Non-Flying Weather](https://acm.timus.ru/problem.aspx?space=1&num=1894)
  - `[M]` ★ [CONSEPHULL](https://toph.co/p/consephull)
  - `[M]` ★ [Rotation Dilemma](https://toph.co/p/rotation-dilemma)
  - `[M]` ★ [Gravitational Wave Detector](https://codeforces.com/gym/104252/problem/G)
  - `[H]` ★ [Gears](https://codeforces.com/contest/497/problem/D)

#### 10.6.2 Dynamic Convex Hull

- **ID:** `dynamic_convex_hull` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_convex_hull
- **Templates (1):**
  - [Convex Hull Dynamic.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Convex%20Hull%20Dynamic.cpp)
- **Resources (1):**
  - ★ [Tiny Dynamic Convex Hull Implementation By brunomont](https://codeforces.com/blog/entry/112458)

#### 10.6.3 Onion Decomposition

- **ID:** `onion_decomposition` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/onion_decomposition
- **Templates (1):**
  - [Onion Decomposition.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Onion%20Decomposition.cpp)
- **Resources (1):**
  - [Dynamic convex hull implementation By dragonslayerintraining](https://codeforces.com/blog/entry/75929)
- **Problems (3):**
  - `[E]` ★ [Convex Layers](https://judge.yosupo.jp/problem/convex_layers)
  - `[M]` [Winding polygonal line](https://codeforces.com/problemset/problem/1158/D)
  - `[H]` [Bubble Popping](https://codeforces.com/contest/1599/problem/D)

### 10.7 Lattice Points

**Subcategory ID:** `lattice_points` · **Topics:** 2

#### 10.7.1 Picks Theorem

- **ID:** `picks_theorem` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/picks_theorem
- **Resources (2):**
  - [Pick's Theorem | CP Algorithms](https://cp-algorithms.com/geometry/picks-theorem.html)
  - [Pick’s Theorem | Tom Davis](http://www.geometer.org/mathcircles/pick.pdf)
- **Problems (3):**
  - `[E]` ★ [Polygon Lattice Points](https://cses.fi/problemset/task/2193)
  - `[E]` ★ [Trees on My Island](https://lightoj.com/problem/trees-on-my-island)
  - `[M]` ★ [Find C](https://codeforces.com/gym/101161/problem/D)

#### 10.7.2 Lattice Points inside a Non-Lattice Polygon

- **ID:** `lattice_points_inside_a_non_lattice_polygon` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lattice_points_inside_a_non_lattice_polygon
- **Resources (1):**
  - ★ [Lattice points inside non-lattice polygon | CP Algorithms](https://cp-algorithms.com/geometry/lattice-points.html)

### 10.8 Sweep Line

**Subcategory ID:** `sweep_line` · **Topics:** 5

#### 10.8.1 Sweep Line Algorithm and Radial Sweep

- **ID:** `sweep_line_algorithm` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/sweep_line_algorithm
- **Resources (4):**
  - ★ [How to sweep like a Sir By DanAlex](https://codeforces.com/blog/entry/20377)
  - [LINE SWEEP ALGORITHMS | Topcoder](https://www.topcoder.com/thrive/articles/Line%20Sweep%20Algorithms)
  - ★ [Chapter 30 Sweep line algorithms | CPH](https://usaco.guide/CPH.pdf#page=285)
  - ★ [Sweep Line | USACO Guide](https://usaco.guide/plat/sweep-line?lang=cpp)
- **Problems (23):**
  - `[E]` ★ [Rectangles](https://vjudge.net/problem/Gym-101982F)
  - `[E]` ★ [Intersection Points](https://cses.fi/problemset/task/1740)
  - `[E]` ★ [Closest Pair](https://open.kattis.com/problems/closestpair2)
  - `[E]` [Circuits](https://vjudge.net/problem/Gym-101987A)
  - `[E]` [Square Overlap](https://usaco.org/index.php?page=viewproblem2&cpid=227)
  - `[E]` [Balloon](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=4376)
  - `[E]` ★ [Grid MST](https://open.kattis.com/problems/gridmst)
  - `[E]` [Jigsaw of Shadows](https://codeforces.com/gym/105505/problem/J)
  - `[M]` ★ [Birthday Cake](https://codeforces.com/gym/104114/problem/B)
  - `[M]` [Cow Steeplechase II](https://usaco.org/index.php?page=viewproblem2&cpid=943)
  - `[M]` [Hill Walk](https://usaco.org/index.php?page=viewproblem2&cpid=266)
  - `[M]` ★ [Seeing the Boundary](https://dmoj.ca/problem/ioi03p6)
  - `[M]` ★ [Pionek](https://szkopul.edu.pl/problemset/problem/NZSCUwz2ACePsBKuVCIVzrRt/site/?key=statement)
  - `[M]` [Hide and seek](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=4413)
  - `[M]` ★ [Oil](https://vjudge.net/problem/Gym-101242G)
  - `[M]` ★ [WiFi Expenses](https://vjudge.net/problem/CodeChef-INF16L)
  - `[M]` ★ [Chef and Circle](https://www.codechef.com/JAN17/problems/CHEFCIRC)
  - `[H]` [Plahte](https://oj.uz/problem/view/COCI17_plahte)
  - `[H]` [Walk](https://oj.uz/problem/view/CEOI06_walk)
  - `[H]` [Signaling](https://dmoj.ca/problem/apio10p3)
  - `[H]` ★ [Cleaning the Hallway](https://codeforces.com/gym/100443/problem/J)
  - `[VH]` ★ [Roads](https://codeforces.com/contest/1402/problem/B)
  - `[VH]` [Global Warming](https://codeforces.com/contest/1666/problem/G)

#### 10.8.2 Closest Pair of Points

- **ID:** `closest_pair_of_points` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/closest_pair_of_points
- **Templates (1):**
  - [Closest Pair of Points.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Closest%20Pair%20of%20Points.cpp)
- **Resources (3):**
  - ★ [Finding the nearest pair of points | CP Algorithms](https://cp-algorithms.com/geometry/nearest_points.html)
  - ★ [A (possibly simpler) algorithm for closest pair problem By bicsi](https://codeforces.com/blog/entry/58747)
  - [Closest Pair of Points using Divide and Conquer algorithm | Geeks for Geeks](https://www.geeksforgeeks.org/closest-pair-of-points-using-divide-and-conquer-algorithm/)
- **Problems (7):**
  - `[E]` ★ [Minimum Euclidean Distance](https://cses.fi/problemset/task/2194)
  - `[E]` ★ [Closest Pair of Points](https://judge.yosupo.jp/problem/closest_pair)
  - `[E]` [The Closest Pair Problem](https://vjudge.net/problem/UVA-10245)
  - `[E]` ★ [Closest Pair](https://open.kattis.com/problems/closestpair2)
  - `[M]` [Minimum Sum](https://codeforces.com/contest/120/problem/J)
  - `[M]` ★ [Closest Triplet](https://www.spoj.com/problems/CLOSEST/)
  - `[M]` [National Park](https://acm.timus.ru/problem.aspx?space=1&num=1514)

#### 10.8.3 Rectangle Union

- **ID:** `rectangle_union` · **Difficulty:** Easy · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/rectangle_union
- **Templates (1):**
  - [Rectangle Union.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Rectangle%20Union.cpp)
- **Resources (2):**
  - ★ [How to sweep like a Sir By DanAlex](https://codeforces.com/blog/entry/20377)
  - [Rectangle Union Problem By P_Nyagolov](https://codeforces.com/blog/entry/44484)
- **Problems (4):**
  - `[E]` ★ [Area of Rectangles](https://cses.fi/problemset/task/1741)
  - `[E]` ★ [Area of Union of Rectangles](https://judge.yosupo.jp/problem/area_of_union_of_rectangles)
  - `[E]` ★ [Rectangles](https://vjudge.net/problem/Gym-101982F)
  - `[E]` ★ [Kingdom of Ants](https://vjudge.net/problem/Kattis-kingdomofants)

#### 10.8.4 All Pair Segment Intersection.

- **ID:** `all_pair_segment_intersection` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/all_pair_segment_intersection
- **Templates (1):**
  - [All Pair Segment Intersection.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/All%20Pair%20Segment%20Intersection.cpp)
- **Resources (1):**
  - ★ [Search for a pair of intersecting segments | CP Algorithms](https://cp-algorithms.com/geometry/intersecting_segments.html)
- **Problems (2):**
  - `[M]` ★ [RC Kaboom Show](https://codeforces.com/contest/1359/problem/F)
  - `[M]` ★ [No Smoking!](https://acm.timus.ru/problem.aspx?space=1&num=1469)

#### 10.8.5 Vertical decomposition

- **ID:** `vertical_decomposition` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/vertical_decomposition
- **Resources (1):**
  - [Vertical decomposition | CP Algorithms](https://cp-algorithms.com/geometry/vertical_decomposition.html)
- **Problems (2):**
  - `[E]` ★ [Darts](https://codeforces.com/contest/107/problem/E)
  - `[M]` ★ [Inquisition](https://codeforces.com/contest/62/problem/C)

### 10.9 Planar Geometry

**Subcategory ID:** `planar_geometry` · **Topics:** 2

#### 10.9.1 Faces in Planar Graph

- **ID:** `planar_graph_faces` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/planar_graph_faces
- **Templates (1):**
  - [planar.html](https://cp-algorithms.com/geometry/planar.html)
- **Resources (1):**
  - ★ [Finding faces of a planar graph and Building planar graph from line segments | CP Algorithms](https://cp-algorithms.com/geometry/planar.html)
- **Problems (5):**
  - `[M]` [Pipeline Transportation](https://acm.timus.ru/problem.aspx?space=1&num=1664)
  - `[M]` [Brother Bear's Garden](https://acm.timus.ru/problem.aspx?space=1&num=1681)
  - `[M]` ★ [Isolated Island](https://codeforces.com/gym/105112/problem/I)
  - `[H]` ★ [Farmers' Tale](https://lightoj.com/problem/farmers-tale)
  - `[H]` ★ [LL’s cake](https://vjudge.net/problem/POJ-3743)

#### 10.9.2 Point Location

- **ID:** `point_location` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/point_location
- **Templates (1):**
  - [Point Location.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Point%20Location.cpp)
- **Resources (1):**
  - [Point location | CP Algorithms](https://cp-algorithms.com/geometry/point-location.html)
- **Problems (2):**
  - `[E]` ★ [Point Location](https://vjudge.net/problem/UVA-12310)
  - `[M]` [Football Goal](https://acm.timus.ru/problem.aspx?space=1&num=1874&locale=en)

### 10.10 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 6

#### 10.10.1 Hill Climbing and Simulated Annealing

- **ID:** `hill_climbing` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/hill_climbing
- **Templates (1):**
  - [Geometry 3D.cpp#L748-L766](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%203D.cpp#L748-L766)
- **Resources (3):**
  - [Hill climbing | Wiki](https://en.wikipedia.org/wiki/Hill_climbing)
  - ★ [Simple approach of Smallest Circle problem: Hill Climbing Tozan Southerpacks Redcoder](https://www.youtube.com/watch?v=WGOSX6d17TU)
  - ★ [\[Tutorial\] Simulated Annealing in Competitive Programming By PurpleCrayon](https://codeforces.com/blog/entry/94437)
- **Problems (7):**
  - `[E]` [Run Away](https://vjudge.net/problem/SPOJ-RUNAWAY)
  - `[E]` ★ [Space Rescuers](https://codeforces.com/problemset/problem/106/E)
  - `[M]` ★ [Commentator problem](https://codeforces.com/problemset/problem/2/C)
  - `[M]` [N-Ta-Gon Has a Problem](https://toph.co/p/n-ta-gon-has-a-problem)
  - `[M]` [Permutations & Primes](https://dmoj.ca/problem/dmopc21c5p5)
  - `[H]` [Subsequence Reversal](https://usaco.org/index.php?page=viewproblem2&cpid=698)
  - `[VH]` [DIY Tree](https://codeforces.com/contest/1556/problem/H)

#### 10.10.2 [Trick] Linear Combination of Vectors

- **ID:** `linear_combination_of_vectors` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/linear_combination_of_vectors
- **Resources (1):**
  - ★ [Editorial of 605C - Freelancer's Dreams](https://codeforces.com/blog/entry/22019)
- **Problems (2):**
  - `[M]` ★ [Freelancer's Dreams](https://codeforces.com/problemset/problem/605/C)
  - `[M]` ★ [Chemistry Lab](https://codeforces.com/problemset/problem/1765/F)

#### 10.10.3 Reflections on a Rectangle

- **ID:** `reflections_on_a_rectangle` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/reflections_on_a_rectangle
- **Problems (4):**
  - `[E]` [Ray Tracing](https://codeforces.com/problemset/problem/724/C)
  - `[M]` ★ [Energy Production](https://toph.co/p/energy-production)
  - `[M]` [Mirror Box](https://codeforces.com/problemset/problem/241/C)
  - `[M]` ★ [Pocket-less Billiards](https://codedrills.io/contests/icpc-kanpur-2021-regional-round/problems/pocket-less-billiards)

#### 10.10.4 [Problem] Maximum Area of a Triangle from Given Lengths

- **ID:** `maximum_area_of_a_triangle_from_given_lengths` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_area_of_a_triangle_from_given_lengths
- **Templates (1):**
  - [Maximum Area of Triangle, Given are Lengths.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Geometry/Maximum%20Area%20of%20Triangle,%20Given%20are%20Lengths.cpp)
- **Problems (1):**
  - `[M]` ★ [Triangle](https://codeforces.com/gym/100956/problem/L)

#### 10.10.5 [Problem] Maximum Area of a Polygon using Given Lengths in CCW Order

- **ID:** `maximum_area_of_a_polygon_using_given_lengths_in_ccw_order` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/maximum_area_of_a_polygon_using_given_lengths_in_ccw_order
- **Templates (1):**
  - [Geometry 2D.cpp#L1290-L1384](https://github.com/ShahjalalShohag/code-library/blob/b1d164f9fc6e9a0896370cebf43793043ee30e7b/Geometry/Geometry%202D.cpp#L1290-L1384)
- **Resources (1):**
  - ★ [Maximum area enclosure given side lengths](https://math.stackexchange.com/questions/1930607/maximum-area-enclosure-given-side-lengths)

#### 10.10.6 [Problem] Circle/Polygon Inclusion Tree

- **ID:** `circle_inclusion_hierarchy` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/circle_inclusion_hierarchy
- **Templates (1):**
  - [main.cpp](https://github.com/ar-pa/circles-hierarchy/blob/master/src/main.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] Finding inclusion hierarchy among circles — An implementation of a sweep-line algorithm By Arpa](https://codeforces.com/blog/entry/98782)
- **Problems (2):**
  - `[M]` ★ [Bomas](https://open.kattis.com/problems/bomas)
  - `[H]` ★ [Freedom from Prison](https://codeforces.com/gym/103388/problem/F)

---

## 11. Miscellaneous

**Category ID:** `miscellaneous` · **Subcategories:** 11 · **Topics:** 41

### 11.1 Greedy Algorithms

**Subcategory ID:** `greedy_algorithms` · **Topics:** 4

#### 11.1.1 Activity Selection Problem

- **ID:** `activity_selection_problem` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/activity_selection_problem
- **Resources (3):**
  - ★ [Activity Selection Problem | Greedy Algo-1 | Geeks for Geeks](https://www.geeksforgeeks.org/activity-selection-problem-greedy-algo-1/)
  - [Activity selection problem | Wiki](https://en.wikipedia.org/wiki/Activity_selection_problem)
  - ★ [Optimal schedule of jobs given their deadlines and durations | CP Algorithms](https://cp-algorithms.com/schedules/schedule-with-completion-duration.html)
- **Problems (4):**
  - `[E]` ★ [Movie Festival II](https://cses.fi/problemset/task/1632)
  - `[E]` ★ [Projects](https://cses.fi/problemset/task/1140)
  - `[E]` ★ [I AM VERY BUSY](https://www.spoj.com/problems/BUSYMAN/)
  - `[H]` ★ [Swap Space](https://vjudge.net/problem/Gym-101242L)

#### 11.1.2 Fractional Knapsack Problem

- **ID:** `fractional_knapsack_problem` · **Difficulty:** Easy · **Importance:** ★★☆ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/fractional_knapsack_problem
- **Resources (2):**
  - ★ [Fractional Knapsack Problem | Geeks for Geeks](https://www.geeksforgeeks.org/fractional-knapsack-problem/)
  - [Fractional Knapsack | avneetsng](https://leetcode.com/discuss/interview-question/1066692/fractional-knapsack)
- **Problems (1):**
  - `[E]` ★ [Fractional Knapsack Problem](https://vjudge.net/problem/Aizu-ALDS1_15_B)

#### 11.1.3 Huffman Coding

- **ID:** `huffman_coding` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/huffman_coding
- **Templates (1):**
  - [huffman-coding](https://www.programiz.com/dsa/huffman-coding)
- **Resources (2):**
  - ★ [Huffman Coding | Programiz](https://www.programiz.com/dsa/huffman-coding)
  - [Huffman Coding | Geeks for Geeks](https://www.geeksforgeeks.org/huffman-coding-greedy-algo-3/)
- **Problems (4):**
  - `[E]` ★ [Hyperhuffman](https://vjudge.net/problem/ZOJ-2339)
  - `[E]` ★ [Huffman Codes](https://vjudge.net/problem/UVA-1072)
  - `[H]` ★ [Weather Report](https://vjudge.net/problem/Kattis-weather)
  - `[H]` [Huffman Coding on Segment](https://codeforces.com/problemset/problem/700/D)

#### 11.1.4 Exchange Arguments

- **ID:** `exchange_arguments` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/exchange_arguments
- **Prerequisites:** Basic DP
- **Resources (2):**
  - ★ [Lecture #3 — Exchange arguments (sorting with dp) By Errichto](https://codeforces.com/blog/entry/63533)
  - ★ [Episode 14 - Exchange Arguments Algorithms Live!](https://www.youtube.com/watch?v=Oq1seKJvfQU)
- **Problems (14):**
  - `[E]` ★ [No Time for Dragons](https://codeforces.com/gym/101149/problem/B)
  - `[E]` ★ [Discounts](https://codeforces.com/contest/2143/problem/B)
  - `[M]` ★ [The Smallest String Concatenation](https://codeforces.com/problemset/problem/632/C)
  - `[M]` ★ [Pieces of Parentheses](https://open.kattis.com/problems/piecesofparentheses)
  - `[M]` ★ [Maximum Composition](https://atcoder.jp/contests/abc366/tasks/abc366_f)
  - `[M]` ★ [The Merry Student Life During the Term...](https://codeforces.com/gym/100113/problem/K)
  - `[M]` ★ [Annihilate the Beetles](https://codeforces.com/gym/100026/problem/J)
  - `[M]` [Altruistic Amphibians](https://open.kattis.com/problems/altruisticamphibians)
  - `[M]` [Zabuton](https://atcoder.jp/contests/cf17-final/tasks/cf17_final_d)
  - `[M]` [Velepin and Marketing](https://codeforces.com/problemset/problem/1793/E)
  - `[M]` [Gym Badges](https://oj.uz/problem/view/NOI22_gymbadges)
  - `[M]` [Tower](https://atcoder.jp/contests/dp/tasks/dp_x)
  - `[H]` [Deadline](https://codeforces.com/gym/100971/problem/I)
  - `[H]` [Fuel Finance](https://toph.co/p/fuel-finance)

### 11.2 Search Techniques

**Subcategory ID:** `search_techniques` · **Topics:** 4

#### 11.2.1 Ternary Search

- **ID:** `ternary_search` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/ternary_search
- **Templates (1):**
  - [ternary_search.html#implementation](https://cp-algorithms.com/num_methods/ternary_search.html#implementation)
- **Resources (3):**
  - ★ [Ternary Search | CP Algorithms](https://cp-algorithms.com/num_methods/ternary_search.html)
  - ★ [Ternary Search on Integers! By Deemo](https://codeforces.com/blog/entry/43440)
  - [Tutorial On Tof (Ternary Search) By Mahdi_Jfri](https://codeforces.com/blog/entry/91664)
- **Problems (21):**
  - `[E]` ★ [Race Time!](https://www.codechef.com/problems/AMCS03)
  - `[E]` ★ [Dome of Circus](https://codeforces.com/gym/101309/problem/D)
  - `[E]` ★ [Devu and his Brother](https://codeforces.com/problemset/problem/439/D)
  - `[E]` ★ [Is This JEE](https://www.codechef.com/problems/ICM2003)
  - `[E]` [Pyramid](https://lightoj.com/problem/pyramid)
  - `[E]` [Ruler (hard version)](https://codeforces.com/contest/1999/problem/G2)
  - `[M]` ★ [Weakness and Poorness](https://codeforces.com/problemset/problem/578/C)
  - `[M]` ★ [Closest Distance](https://lightoj.com/problem/closest-distance)
  - `[M]` [Galactic taxes](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4898)
  - `[M]` ★ [Chasing the Cheetahs](https://codeforces.com/gym/100829/problem/A)
  - `[M]` ★ [Vika and Bonuses](https://codeforces.com/problemset/problem/1848/D)
  - `[M]` [Trick or Treat](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3349)
  - `[M]` [Building Construction](http://www.spoj.com/problems/KOPC12A/)
  - `[M]` ★ [Nature Reserve](https://codeforces.com/problemset/problem/1059/D)
  - `[M]` ★ [Restorer Distance](https://codeforces.com/contest/1355/problem/E)
  - `[M]` [Kill the Shaitan-Boss](https://acm.timus.ru/problem.aspx?space=1&num=1719)
  - `[M]` ★ [Simple Skewness](https://codeforces.com/contest/626/problem/E)
  - `[M]` [Gift Set](https://codeforces.com/problemset/problem/1538/G)
  - `[M]` [Lonely Mountain Dungeons](https://codeforces.com/contest/1928/problem/D)
  - `[M]` [Grid Path (Hard)](https://www.codechef.com/problems/GRIDPATHHD)
  - `[H]` [Life Is Dark and Full of Error](https://toph.co/p/life-is-dark-and-full-of-error)

#### 11.2.2 Parallel Binary Search

- **ID:** `parallel_binary_search` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/parallel_binary_search
- **Templates (1):**
  - [Parallel Binary Search.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Parallel%20Binary%20Search.cpp)
- **Resources (2):**
  - ★ [Parallel Binary Search \[tutorial\] By himanshujaju](https://codeforces.com/blog/entry/45578)
  - [Parallel Binary Search Tutorial | Algorithms Conquered](https://www.youtube.com/watch?v=NGbaWEjM8MI)
- **Problems (12):**
  - `[E]` ★ [Meteors](https://www.spoj.com/problems/METEORS/)
  - `[E]` ★ [New Roads Queries](https://cses.fi/problemset/task/2101)
  - `[E]` [Make n00b land great again](https://www.hackerearth.com/challenges/competitive/may-circuits/algorithm/make-n00b_land-great-again-circuits/)
  - `[M]` ★ [Stamp Rally](https://atcoder.jp/contests/agc002/tasks/agc002_d)
  - `[M]` ★ [Pictionary](https://oj.uz/problem/view/COCI18_pictionary)
  - `[M]` [Index](https://dmoj.ca/problem/coci20c6p5)
  - `[M]` ★ [Sign on Fence](https://codeforces.com/contest/484/problem/E)
  - `[H]` [Travel in HackerLand](https://www.hackerrank.com/contests/may-world-codesprint/challenges/travel-in-hackerland)
  - `[H]` ★ [Selective Additions](https://www.hackerrank.com/contests/hourrank-23/challenges/selective-additions/problem)
  - `[H]` ★ [Frequency Mismatch (Hard Version)](https://codeforces.com/contest/1957/problem/F2)
  - `[H]` [Manhattan Christmas Tree](https://atcoder.jp/contests/abc233/tasks/abc233_h?lang=en)
  - `[H]` [AQT's Tree Game](https://dmoj.ca/problem/oly18novp11)

#### 11.2.3 Fraction Binary Search

- **ID:** `fraction_binary_search` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/fraction_binary_search
- **Templates (1):**
  - [Fraction Binary Search.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Fraction%20Binary%20Search.cpp)
- **Resources (4):**
  - [Fraction Search Algorithm | CP Algorithm](https://cp-algorithms.com/others/stern_brocot_tree_farey_sequences.html#fraction-search-algorithm)
  - [Solution by Xylofo](https://codeforces.com/gym/102354/submission/69260720)
  - [The "guess the number" game for arbitrary rational numbers?](https://stackoverflow.com/questions/5440688/the-guess-the-number-game-for-arbitrary-rational-numbers)
  - [Integer binary search and Farey series By ifsmirnov](https://codeforces.com/blog/entry/4190)
- **Problems (2):**
  - `[M]` [From Modular to Rational](https://codeforces.com/gym/102354/problem/I)
  - `[H]` [Infinite Fraction Sequence](https://oj.vnoi.info/problem/icpc23_national_i)

#### 11.2.4 Fracturing Search

- **ID:** `fracturing_search` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/fracturing_search
- **Resources (2):**
  - ★ [Fracturing Search | USACO Guide](https://usaco.guide/adv/fracturing-search?lang=cpp)
  - ★ [Episode 32 - Fracturing Search Algorithms Live!](https://www.youtube.com/watch?v=EG_HfFMM0lE)
- **Problems (4):**
  - `[E]` ★ [Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/description/)
  - `[M]` [Robotic Cow Herd](https://usaco.org/index.php?page=viewproblem2&cpid=674)
  - `[M]` ★ [Olympiads](https://vjudge.net/problem/OJUZ-BOI19_olympiads)
  - `[VH]` [Shopping Plans](https://dmoj.ca/problem/cco20p6)

### 11.3 Interactive Problems

**Subcategory ID:** `interactive_problems` · **Topics:** 2

#### 11.3.1 Interactive Problems

- **ID:** `interactive_problems` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 1
- **Topic page:** https://youkn0wwho.academy/topic-list/interactive_problems
- **Resources (1):**
  - ★ [Interactive Problems: Guide for Participants By MikeMirzayanov](https://codeforces.com/blog/entry/45307)
- **Problems (30):**
  - `[E]` ★ [Guess the Number](https://codeforces.com/gym/101021/problem/1)
  - `[E]` ★ [Interview](https://codeforces.com/problemset/problem/1807/E)
  - `[E]` ★ [Prime Factors](https://csacademy.com/contest/round-64/task/prime-factors/statement/)
  - `[E]` ★ [Guessing the Greatest (easy version)](https://codeforces.com/problemset/problem/1486/C1)
  - `[E]` ★ [Bear and Prime 100](https://codeforces.com/problemset/problem/679/A)
  - `[E]` [Hidden Permutations](https://codeforces.com/problemset/problem/1621/C)
  - `[E]` [XOR Guessing](https://codeforces.com/problemset/problem/1207/E)
  - `[E]` [Omkar and the Meaning of Life](https://codeforces.com/problemset/problem/1583/D)
  - `[E]` ★ [Bit Guessing Game](https://codeforces.com/problemset/problem/1780/D)
  - `[E]` ★ [Anya's Simultaneous Exhibition](https://codeforces.com/problemset/problem/1779/E)
  - `[E]` ★ [Decreasing Game](https://codeforces.com/problemset/problem/1839/E)
  - `[E]` [Trailing Zeros](https://csacademy.com/contest/round-64/task/trailing-zeros/statement/)
  - `[E]` [Create Tree](https://csacademy.com/contest/round-64/task/create-tree/statement/)
  - `[E]` ★ [Jump](https://codeforces.com/gym/100851/problem/J)
  - `[M]` ★ [Lost Tree](https://codeforces.com/contest/1534/problem/D)
  - `[M]` [Enchanted Artifact](https://codeforces.com/problemset/problem/1282/D)
  - `[M]` ★ [Missing String](https://toph.co/p/missing-string)
  - `[M]` ★ [Chocolate Bunny](https://codeforces.com/problemset/problem/1407/C)
  - `[M]` ★ [Bitwise Queries (Easy Version)](https://codeforces.com/problemset/problem/1451/E1)
  - `[M]` ★ [X-OR](https://codeforces.com/problemset/problem/1364/E)
  - `[M]` [Limited Moves](https://csacademy.com/contest/round-64/task/limited-moves/statement/)
  - `[M]` [Take a Guess](https://codeforces.com/problemset/problem/1556/D)
  - `[M]` [Ruler (easy version)](https://codeforces.com/contest/1999/problem/G1)
  - `[H]` ★ [Guess Divisors Count](https://codeforces.com/problemset/problem/1355/F)
  - `[H]` ★ [Lost Root](https://codeforces.com/problemset/problem/1061/F)
  - `[H]` ★ [Election Spies](https://csacademy.com/contest/round-64/task/election-spies/statement/)
  - `[H]` [Interactive Bulls and Cows (Hard)](https://codeforces.com/contest/753/problem/C)
  - `[H]` [Basin City Surveillance](https://codeforces.com/gym/100502/problem/B)
  - `[VH]` ★ [Eliminate Edges](https://csacademy.com/contest/round-64/task/eliminate-edges/statement/)
  - `[VH]` ★ [Find the Tree](https://csacademy.com/contest/round-64/task/find-the-tree/statement/)

#### 11.3.2 Interactive Problems on Centroids

- **ID:** `interactive_problems_on_centroids` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/interactive_problems_on_centroids
- **Resources (1):**
  - ★ [Editorial of 1174F - Ehab and the Big Finale](https://codeforces.com/blog/entry/67388)
- **Problems (3):**
  - `[E]` ★ [Ehab and the Big Finale](https://codeforces.com/contest/1174/problem/F?locale=en)
  - `[E]` ★ [Find the Special Node](https://www.codechef.com/START17B/problems-old/SPCNODE)
  - `[VH]` [Centroid Guess](https://codeforces.com/problemset/problem/1761/G)

### 11.4 Permutations

**Subcategory ID:** `permutations` · **Topics:** 3

#### 11.4.1 Permutations and Permutation Cycles

- **ID:** `permutation_cycles` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/permutation_cycles
- **Templates (1):**
  - [Permutation Cycles.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Permutation%20Cycles.cpp)
- **Resources (7):**
  - ★ [\[Tutorial\] A comprehensive guide to permutations for beginners By nor](https://nor-blog.pages.dev/posts/2023-01-09-permutations-for-beginners/)
  - [Permutation | Wiki](https://en.wikipedia.org/wiki/Permutation#k-permutations_of_n)
  - ★ [Linear time algorithm for parity of permutation, around 1591D By thematdev](https://codeforces.com/blog/entry/97849)
  - ★ [Minimum swaps to sort an array | Geeks for Geeks](https://www.geeksforgeeks.org/minimum-number-swaps-required-sort-array/)
  - ★ [The Riddle That Seems Impossible Even If You Know The Answer Veritasium](https://www.youtube.com/watch?v=iSNsgj1OCLA)
  - [Problem Solving Session on Cycles in Permutations by Archit Manas](https://www.youtube.com/watch?v=fDFjB3gVg0U)
  - [Cycles in Permutations by Archit Manas](https://youtu.be/eKwsCCa-uMA?si=o25_GYb95Mbxvzbp)
- **Problems (14):**
  - `[E]` ★ [Permutation Cycles](https://www.codechef.com/problems/PCYCLE)
  - `[E]` ★ [Sorting by Swapping](https://vjudge.net/problem/POJ-1674)
  - `[E]` [Permutations](https://vjudge.net/problem/CodeForces-48D)
  - `[E]` ★ [Sakurako, Kosuke, and the Permutation](https://codeforces.com/contest/2033/problem/E)
  - `[M]` ★ [Permutations](http://acm.timus.ru/problem.aspx?space=1&num=1024)
  - `[M]` ★ [Lucky Permutation](https://codeforces.com/contest/1768/problem/D)
  - `[M]` ★ [Infinite Path](https://codeforces.com/problemset/problem/1327/D)
  - `[M]` ★ [Square Root of Permutation](https://codeforces.com/contest/612/problem/E)
  - `[M]` ★ [Yet Another Sorting Problem](https://codeforces.com/contest/1591/problem/D)
  - `[M]` ★ [Inversion Counting](https://codeforces.com/contest/911/problem/D)
  - `[M]` ★ [Petr and Permutations](https://codeforces.com/contest/987/problem/E)
  - `[M]` ★ [The Cabins in the Woods](https://codedrills.io/contests/icpc-asia-west-continent-final-contest-2023/problems/the-cabins-in-the-woods)
  - `[M]` [Permutation Cost Sum](https://www.codechef.com/problems/P_COST_SUM)
  - `[H]` ★ [D-Power Permutations](https://www.codechef.com/problems/DPOWPERM/)

#### 11.4.2 [Problem] K-th Root of a Permutation

- **ID:** `kth_root_of_a_permutation` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/kth_root_of_a_permutation
- **Templates (1):**
  - [K-th Root of a Permutation.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/K-th%20Root%20of%20a%20Permutation.cpp)
- **Resources (1):**
  - ★ [Editorial of Sasha and Swaps by adamant](https://www.hackerrank.com/contests/infinitum14/challenges/sasha-and-swaps/editorial)
- **Problems (2):**
  - `[M]` ★ [Square Root of Permutation](https://codeforces.com/contest/612/problem/E)
  - `[M]` ★ [Sasha and Swaps](https://www.hackerrank.com/contests/infinitum14/challenges/sasha-and-swaps/problem)

#### 11.4.3 Schreier–Sims Algorithm

- **ID:** `schreier_sims_algorithm` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/schreier_sims_algorithm
- **Templates (1):**
  - [Schreier–Sims algorithm.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Schreier%E2%80%93Sims%20algorithm.cpp)
- **Resources (3):**
  - ★ [Permutation group basis construction (Schreier–Sims algorithm) By adamant](https://codeforces.com/blog/entry/111290?locale=en)
  - ★ [Schraer-Sims algorithm for dummies | Zlobober](https://codeforces.com/blog/entry/21335?locale=ru#comment-260437)
  - [Another Problem using this Algorithm, but not sure if you can access it](http://opencup.ru/files/ocg/gp5/problems1-e.pdf)
- **Problems (1):**
  - `[E]` ★ [Permutations](https://codeforces.com/gym/421334/problem/A)

### 11.5 Matroids

**Subcategory ID:** `matroids` · **Topics:** 1

#### 11.5.1 Matroid Intersection

- **ID:** `matroid_intersection` · **Difficulty:** Very Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/matroid_intersection
- **Templates (3):**
  - [Matroid Intersection Color Linear Matroid.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Matroid%20Intersection%20Color%20Linear%20Matroid.cpp)
  - [Matroid Intersection Color Graphic Matroid.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Matroid%20Intersection%20Color%20Graphic%20Matroid.cpp)
  - [graphicGraphicMatroid.cpp](https://github.com/AnikSarker/ACM-Library/blob/master/Matroid/graphicGraphicMatroid.cpp)
- **Resources (2):**
  - ★ [\[Tutorial\] Matroid intersection in simple words By ATSTNG](https://codeforces.com/blog/entry/69287)
  - [Matroid | Wiki](https://en.wikipedia.org/wiki/Matroid)
- **Problems (14):**
  - `[E]` ★ [Pick Your Own Nim](https://codeforces.com/gym/102156/problem/D)
  - `[E]` ★ [Coin Collecting](https://www.spoj.com/problems/COIN/)
  - `[E]` [Demonstration of Honesty!](https://www.urionlinejudge.com.br/judge/en/problems/view/2128)
  - `[E]` [Communicating Servers](https://www.codechef.com/problems/SERVERS)
  - `[M]` ★ [Faulty System](https://www.codechef.com/problems/CNNCT2)
  - `[M]` ★ [MEXimum Spanning Tree](https://qoj.ac/contest/1221/problem/6402)
  - `[M]` [ICPC Kingdom](https://codeforces.com/gym/103373/problem/I)
  - `[M]` ★ [Rainbow Graph](https://naipc18.kattis.com/problems/rainbowgraph)
  - `[M]` [Ambiguous Forests](https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3080)
  - `[M]` ★ [Colorful Spanning Tree](https://atcoder.jp/contests/abc399/tasks/abc399_g)
  - `[H]` [Seollal](https://codeforces.com/contest/1284/problem/G)
  - `[H]` ★ [Hamel Paths](https://www.codechef.com/problems/HAMEL)
  - `[VH]` [DIY Tree](https://codeforces.com/contest/1556/problem/H)
  - `[VH]` [TST](https://dmoj.ca/problem/dmopc19c3p6)

### 11.6 Chess

**Subcategory ID:** `chess` · **Topics:** 3

#### 11.6.1 [Problem] Knight Moves in Infinity Grid

- **ID:** `knight_moves_in_infinity_grid` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/knight_moves_in_infinity_grid
- **Templates (1):**
  - [Knight Moves in Infinity Grid.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Knight%20Moves%20in%20Infinity%20Grid.cpp)
- **Resources (1):**
  - ★ [Knight’s move on infinite chess board with constant time and space | Adem Atalay](https://medium.com/@adematalay/knights-move-on-infinite-chess-board-with-constant-time-and-space-98c1c0748aa6)

#### 11.6.2 [Problem] Knight's Tour Problem

- **ID:** `knights_tour_problem` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/knights_tour_problem
- **Resources (3):**
  - ★ [19.4 Knight’s tours | CPH](https://usaco.guide/CPH.pdf#page=189)
  - ★ [Warnsdorff’s algorithm for Knight’s tour problem | Geeks for Geeks](https://www.geeksforgeeks.org/warnsdorffs-algorithm-knights-tour-problem/)
  - [Knight's Tour Problem | Backtracking | Code Dope](https://www.codesdope.com/course/algorithms-knights-tour-problem/)
- **Problems (1):**
  - `[E]` [Knight's Tour](https://cses.fi/problemset/task/1689)

#### 11.6.3 [Problem] Bishop Placement

- **ID:** `bishop_placement` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bishop_placement
- **Templates (1):**
  - [bishops-on-chessboard.html#implementation](https://cp-algorithms.com/combinatorics/bishops-on-chessboard.html#implementation)
- **Resources (1):**
  - [Placing Bishops on a Chessboard | CP Algorithms](https://cp-algorithms.com/combinatorics/bishops-on-chessboard.html)
- **Problems (1):**
  - `[E]` ★ [Counting Bishops](https://cses.fi/problemset/task/2176)

### 11.7 Techniques

**Subcategory ID:** `techniques` · **Topics:** 9

#### 11.7.1 Coordinate Compression

- **ID:** `coordinate_compression` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/coordinate_compression
- **Resources (5):**
  - ★ [Coordinate Compression | A small but an useful trick to have in the armoury | take U forward](https://www.youtube.com/watch?v=s9oXy-fZUzg)
  - [What is coordinate compression?](https://codeforces.com/blog/entry/23180)
  - [Coordinate Compression | Geeks for Geeks](https://www.geeksforgeeks.org/coordinate-compression/)
  - ★ [Coordinate Compression | Algorithms Digest](https://medium.com/algorithms-digest/coordinate-compression-2fff95326fb)
  - ★ [My code for coordinate compression By rembocoder](https://codeforces.com/blog/entry/84164)
- **Problems (11):**
  - `[E]` ★ [Covered Points Count](https://codeforces.com/problemset/problem/1000/C)
  - `[E]` ★ [Restaurant Customers](https://cses.fi/problemset/task/1619)
  - `[E]` ★ [Salary Queries](https://cses.fi/problemset/task/1144/)
  - `[E]` [Shuffling Songs](https://codeforces.com/contest/1950/problem/G)
  - `[E]` ★ [K-query](https://www.spoj.com/problems/KQUERY/)
  - `[M]` ★ [Increasing subsequence II](https://cses.fi/problemset/task/1748)
  - `[M]` ★ [Distinct Values Queries](https://cses.fi/problemset/task/1734)
  - `[M]` [Infinite Inversions](https://codeforces.com/contest/540/problem/E)
  - `[M]` [Turn Off The TV](https://codeforces.com/contest/863/problem/E)
  - `[M]` [Crazy Fences](https://usaco.org/index.php?cpid=207&page=viewproblem2)
  - `[M]` ★ [Rectangular Pasture](https://usaco.org/index.php?page=viewproblem2&cpid=1063)

#### 11.7.2 Direction Array

- **ID:** `direction_array` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/direction_array
- **Prerequisites:** DFS/BFS
- **Resources (2):**
  - ★ [An Efficient (and quite common) Way to Navigate Grid Problems \[C++\] By Jellyman102](https://codeforces.com/blog/entry/78827)
  - [ডিরেকশন অ্যারে | শাফায়েতের ব্লগ](https://www.shafaetsplanet.com/?p=1448)
- **Problems (9):**
  - `[E]` ★ [Counting Rooms](https://cses.fi/problemset/task/1192)
  - `[E]` ★ [King's Path](https://codeforces.com/contest/242/problem/C)
  - `[E]` ★ [Maze](https://codeforces.com/contest/378/problem/C)
  - `[E]` [Ice Cave](https://codeforces.com/contest/540/problem/C)
  - `[E]` [Igor In the Museum](https://codeforces.com/contest/598/problem/D)
  - `[E]` [Solve The Maze](https://codeforces.com/contest/1365/problem/D)
  - `[E]` [Fox And Two Dots](https://codeforces.com/contest/510/problem/B)
  - `[E]` [Statues](https://codeforces.com/contest/129/problem/C)
  - `[E]` [Set of Strangers](https://codeforces.com/contest/2069/problem/B)

#### 11.7.3 Meet in the Middle

- **ID:** `meet_in_the_middle` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 4
- **Topic page:** https://youkn0wwho.academy/topic-list/meet_in_the_middle
- **Templates (1):**
  - [meet-in-the-middle?lang=cpp#meet-in-the-middle-solution](https://usaco.guide/gold/meet-in-the-middle?lang=cpp#meet-in-the-middle-solution)
- **Resources (3):**
  - ★ [Meet in the Middle | Tutorial & Problems | Errichto Hard Algorithms](https://www.youtube.com/watch?v=18sJ3mK173s)
  - ★ [5.5 Meet in the middle | CPH](https://usaco.guide/CPH.pdf#page=64)
  - [Meet In The Middle | USACO Guide](https://usaco.guide/gold/meet-in-the-middle?lang=cpp)
- **Problems (17):**
  - `[E]` ★ [Meet in the Middle](https://cses.fi/problemset/task/1628/)
  - `[E]` ★ [Subset Sums](https://www.spoj.com/problems/SUBSUMS/)
  - `[E]` ★ [Maximum Subsequence](https://codeforces.com/contest/888/problem/E)
  - `[E]` [Robot Instructions](https://usaco.org/index.php?page=viewproblem2&cpid=1207)
  - `[E]` ★ [Sum of Four Values](https://cses.fi/problemset/task/1642)
  - `[E]` ★ [Подарок](https://codeforces.com/group/NOwIbqv33y/contest/307527/problem/J)
  - `[E]` ★ [Maximum Independent Set](https://judge.yosupo.jp/problem/maximum_independent_set)
  - `[M]` ★ [Xor-Paths](https://codeforces.com/contest/1006/problem/F)
  - `[M]` ★ [Prime Gift](https://codeforces.com/contest/912/problem/E)
  - `[M]` ★ [Algebra Flash](https://codeforces.com/problemset/problem/1767/E)
  - `[M]` ★ [Make Them Similar](https://codeforces.com/problemset/problem/1257/F)
  - `[M]` ★ [Path to Integer](https://atcoder.jp/contests/abc402/tasks/abc402_f)
  - `[H]` [Lizard Era: Beginning](https://codeforces.com/problemset/problem/585/D)
  - `[H]` [Knapsack Queries on a tree](https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_d)
  - `[H]` [Playlist](https://open.kattis.com/problems/playlist)
  - `[H]` ★ [Number Clicker](https://codeforces.com/contest/995/problem/E)
  - `[H]` [actGenshinImp](https://codeforces.com/gym/105698/problem/A)

#### 11.7.4 Invariants and Monovariants

- **ID:** `invariants_and_monovariants` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/invariants_and_monovariants
- **Resources (2):**
  - ★ [\[Tutorial\] Invariants and Monovariants By TooNewbie](https://codeforces.com/blog/entry/57216)
  - ★ [Invariant List | Share Your Invariant Here! By muhammadhasan01](https://codeforces.com/blog/entry/130338)
- **Problems (14):**
  - `[E]` ★ [Coin Piles](https://cses.fi/problemset/task/1754)
  - `[E]` ★ [Chess For Three](https://codeforces.com/contest/1973/problem/A)
  - `[M]` ★ [Yet Another Sorting Problem](https://codeforces.com/contest/1591/problem/D)
  - `[M]` ★ [Contrast](https://atcoder.jp/contests/abc178/tasks/abc178_f)
  - `[M]` [The Human Equation](https://codeforces.com/problemset/problem/1775/E)
  - `[M]` [Corner Twist](https://codeforces.com/contest/1983/problem/B)
  - `[M]` ★ [Find the Maximum Sum of Node Values](https://leetcode.com/problems/find-the-maximum-sum-of-node-values/description/)
  - `[M]` ★ [Swap Dilemma](https://codeforces.com/contest/1983/problem/D)
  - `[M]` [Simultaneous Swap](https://atcoder.jp/contests/abc296/tasks/abc296_f)
  - `[M]` ★ [Magic Stones](https://codeforces.com/contest/1110/problem/E)
  - `[M]` [Button Pressing](https://codeforces.com/contest/1906/problem/B)
  - `[M]` [Operating on A](https://www.codechef.com/problems/ATBO)
  - `[H]` [Flipping Range](https://codeforces.com/contest/1630/problem/D)
  - `[H]` [Swaps Again](https://codeforces.com/contest/1365/problem/F)

#### 11.7.5 Manhattan <> Chebyshev

- **ID:** `manhattan_chebyshev` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/manhattan_chebyshev
- **Author's blog:** 
              <Text>
              For two points (x1, y1) and (x2, y2), we have the following relations between Manhattan and Chebyshev distance:
              <br/>
              - <b>Manhattan -> Chebyshev:</b> 
              <br/>
              Manhattan Distance = |x1 - x2| + |y1 - y2|
              <br/>
              Trick: Rotate 45 degrees. Let p1 = x1 + y1, p2 = x2 + y2, q1 = x1 - y1, q2 = x2 - y2, then Chebyshev Distance = max(|p1 - p2|, |q1 - q2|)
              <br/>
              - <b>Chebyshev -> Manhattan:</b> 
              <br/>
              Chebyshev Distance =max(|x1 - x2|, |y1 - y2|) 
              <br/>
              Trick: Rotate 45 degrees. Then Manhattan Distance = 1⁄2 * (|p1 - p2| + |q1 - q2|)
              </Text>
              
- **Resources (4):**
  - [Manhattan distance | Wiki](https://simple.wikipedia.org/wiki/Manhattan_distance)
  - [Chebyshev distance | Wiki](https://en.wikipedia.org/wiki/Chebyshev_distance)
  - ★ [Manhattan trick \[Tutorial\] (also I have never traveled to Manhattan) By Wandoka](https://codeforces.com/blog/entry/131907)
  - ★ [Manhattan distance trick in higher dimensions By kaldiuo](https://codeforces.com/blog/entry/57534)
- **Problems (8):**
  - `[E]` ★ [Dist Max](https://atcoder.jp/contests/abc178/tasks/abc178_e)
  - `[E]` ★ [Manhattan](https://www.spoj.com/problems/DISTANCE)
  - `[M]` [Four Coloring](https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_d)
  - `[M]` [Teleports](https://www.codechef.com/problems/TELEPORT)
  - `[M]` [Game with Tokens](https://codeforces.com/contest/944/problem/F)
  - `[H]` ★ [The Ultimate Bamboo Eater](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3226)
  - `[H]` [Manhattan Christmas Tree](https://atcoder.jp/contests/abc233/tasks/abc233_h?lang=en)
  - `[VH]` ★ [Pairs](https://oj.uz/problem/view/IOI07_pairs)

#### 11.7.6 LCM OR Technique

- **ID:** `lcm_or_technique` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lcm_or_technique
- **Resources (1):**
  - ★ [F - Subsequence LCM Editorial](https://atcoder.jp/contests/abc349/editorial/9878)
- **Problems (3):**
  - `[M]` ★ [Subsequence LCM](https://atcoder.jp/contests/abc349/tasks/abc349_f)
  - `[M]` ★ [LCM Divisible Subsequence](https://toph.co/p/lcm-divisible-subsequence)
  - `[H]` ★ [Mysterious LCM](https://codeforces.com/gym/102141/problem/B)

#### 11.7.7 [Trick] Logarithmic Subarray Aggregator (LSA Trick)

- **ID:** `logarithmic_bruteforce` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/logarithmic_bruteforce
- **Author's blog:** 
              <Text>
              Imagine a problem where you have to find sum of all subarray GCDs.
              <br/> 
              Normally you will have to use sparse table and binary search to solve this by leveraging the fact that there will be O(log(MAX)) different GCDs ending at each index.
              <br/>
              But you can do this in a better way with minimal code! You can store a vector or map v[r] which stores all GCDs of subarrays ending at r.
              <br/>
              Note that there will be O(log(MAX)) different GCDs ending at r. So, you can store their info directly in the vector.
              <br/>
              Then, you can iterate over all elements in v[r] to get the vector v[r+1].
              <br/>
              So, you are basically doing a bruteforce in log(N) time. Pretty simple and elegant!
              <br/>
              You can do the same for subarray AND, OR etc.
              <br/>
              Check the template code below for a better understanding.
              </Text>
              
- **Templates (1):**
  - [Logarithmic Subarray Aggregator.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Logarithmic%20Subarray%20Aggregator.cpp)
- **Problems (10):**
  - `[E]` ★ [Bitwise ORs of Subarrays](https://leetcode.com/problems/bitwise-ors-of-subarrays/description/)
  - `[E]` ★ [The Brand New Function](https://codeforces.com/problemset/problem/243/A)
  - `[M]` ★ [CGCDSSQ](https://codeforces.com/contest/475/problem/D)
  - `[M]` ★ [Maximum of GCDs](https://www.codechef.com/problems/KSIZEGCD)
  - `[M]` ★ [Have Some Water](https://toph.co/c/cuet-inter-university-codestorm-1-0)
  - `[M]` [Eri and Expanded Sets](https://codeforces.com/contest/2007/problem/F)
  - `[M]` ★ [Alter the GCD](https://codeforces.com/contest/2005/problem/D)
  - `[M]` ★ [GCD Counting](https://codeforces.com/problemset/problem/990/G)
  - `[H]` ★ [GCD cost on the tree](https://atcoder.jp/contests/abc248/tasks/abc248_g)
  - `[H]` ★ [Different GCD Subarray Query](https://vjudge.net/problem/HDU-5869)

#### 11.7.8 Bitwise Disjoint Partitioning

- **ID:** `bitwise_disjoint_partitioning` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bitwise_disjoint_partitioning
- **Resources (1):**
  - ★ [Disjoint partitioning with binary representation | Nafis](https://nafis277.github.io/Bit_Trick.html)
- **Problems (3):**
  - `[M]` ★ [ICC](https://oj.uz/problem/view/CEOI16_icc)
  - `[M]` ★ [The penguin's game](https://codeforces.com/problemset/problem/835/E)
  - `[M]` [Remont](https://szkopul.edu.pl/problemset/problem/xNjwUvwdHQoQTFBrmyG8vD1O/site/?key=statement)

#### 11.7.9 [Trick] Efficient Non-Increasing Sequence Recovery of Length n with a[i] <= n/i

- **ID:** `sqrt_n_sequence_recovery` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/sqrt_n_sequence_recovery
- **Templates (1):**
  - [134445](https://codeforces.com/blog/entry/134445)
- **Resources (1):**
  - ★ [Determine A Non-Increasing Integer Sequence of Length n with a\[k\]<=n/k in O(sqrt(n)) Steps By Nachia](https://codeforces.com/blog/entry/134445)
- **Problems (4):**
  - `[E]` ★ [You Are Given a Tree](https://codeforces.com/contest/1039/problem/D)
  - `[M]` ★ [Division + LCP (hard version)](https://codeforces.com/problemset/problem/1968/G2)
  - `[M]` ★ [Till I Collapse](https://codeforces.com/contest/786/problem/C)
  - `[H]` [Complex Segments (Hard Version)](https://codeforces.com/contest/2018/problem/E2)

### 11.8 Min Plus Convolution

**Subcategory ID:** `min_plus_convolution` · **Topics:** 2

#### 11.8.1 Min Plus Convolution (Convex and Convex)

- **ID:** `min_plus_convolution_convex_and_convex` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_plus_convolution_convex_and_convex
- **Templates (1):**
  - [Min Plus Convolution (Convex and Convex).cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Min%20Plus%20Convolution%20%28Convex%20and%20Convex%29.cpp)
- **Resources (2):**
  - ★ [\[Tutorial\] Knapsack, Subset Sum and the (max,+) Convolution By errorgorn](https://codeforces.com/blog/entry/98663)
  - ★ [A comment by square1001](https://codeforces.com/blog/entry/75925?#comment-602354)
- **Problems (3):**
  - `[E]` ★ [Min Plus Convolution (Convex and Convex)](https://judge.yosupo.jp/problem/min_plus_convolution_convex_convex)
  - `[M]` [Candies](https://oj.uz/problem/view/JOI18_candies)
  - `[H]` [Red and Blue Lamps](https://atcoder.jp/contests/abc218/tasks/abc218_h)

#### 11.8.2 SMAWK Algorithm and Min Plus Convolution (Convex and Arbitrary)

- **ID:** `min_plus_convolution_convex_and_arbitrary` · **Difficulty:** Very Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/min_plus_convolution_convex_and_arbitrary
- **Templates (1):**
  - [185910](https://judge.yosupo.jp/submission/185910)
- **Resources (3):**
  - ★ [The SMAWK Algorithm](https://web.cs.unlv.edu/larmore/Courses/CSC477/monge.pdf)
  - ★ [SMAWK algorithm as an alternative for D&C optimization By ko_osaga,](https://codeforces.com/blog/entry/110844)
  - ★ [\[Tutorial\] Knapsack, Subset Sum and the (max,+) Convolution By errorgorn](https://codeforces.com/blog/entry/98663)
- **Problems (4):**
  - `[E]` ★ [Min Plus Convolution (Convex and Arbitrary)](https://judge.yosupo.jp/problem/min_plus_convolution_convex_arbitrary)
  - `[M]` [Sum](https://codeforces.com/contest/1442/problem/D)
  - `[H]` [Holiday](https://oj.uz/problem/view/IOI14_holiday)
  - `[H]` [Milutin's Plums](https://codeforces.com/problemset/problem/1423/M)

### 11.9 Randomized

**Subcategory ID:** `randomized` · **Topics:** 2

#### 11.9.1 Randomized Algorithms

- **ID:** `randomized_algorithms` · **Difficulty:** Medium · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/randomized_algorithms
- **Resources (2):**
  - ★ [Randomized algorithms lecture, part 1 & 2 By Errichto](https://codeforces.com/blog/entry/71097)
  - [Randomization tasks By Radewoosh](https://codeforces.com/blog/entry/51244)
- **Problems (14):**
  - `[E]` ★ [Johnny English Strikes Again](https://codeforces.com/gym/104283/problem/C)
  - `[E]` ★ [Kuroni and the Punishment](https://codeforces.com/contest/1305/problem/F)
  - `[E]` ★ [Jump](https://codeforces.com/gym/100851/problem/J)
  - `[E]` ★ [Matrix God](https://codeforces.com/gym/101341/problem/I)
  - `[E]` ★ [Buratsuta 3](https://codeforces.com/contest/2149/problem/G)
  - `[M]` ★ [Destiny](https://codeforces.com/contest/840/problem/D)
  - `[M]` [Node Picking](https://www.codechef.com/IPC15P2B/problems/NOPI)
  - `[M]` ★ [Finding Lines](https://vjudge.net/problem/Kattis-findinglines)
  - `[M]` ★ [Turtle and Three Sequences](https://codeforces.com/contest/2003/problem/F)
  - `[M]` ★ [Ghd](https://codeforces.com/contest/364/problem/D)
  - `[M]` ★ [GCD](https://codeforces.com/gym/101741/problem/F)
  - `[H]` ★ [Lost Root](https://codeforces.com/problemset/problem/1061/F)
  - `[H]` [Interactive Bulls and Cows (Hard)](https://codeforces.com/contest/753/problem/C)
  - `[H]` [Basin City Surveillance](https://codeforces.com/gym/100502/problem/B)

#### 11.9.2 Birthday Paradox

- **ID:** `birthday_paradox` · **Difficulty:** Medium · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/birthday_paradox
- **Resources (3):**
  - ★ [Randomized algorithms lecture #2 - birthday paradox, random shuffle, hashing Errichto Algorithms](https://www.youtube.com/watch?v=GS2MxmorEzc)
  - ★ [How to blow up too weak hashing without thinking By physics0523](https://codeforces.com/blog/entry/129094)
  - ★ [Birthday problem | Wiki](https://en.wikipedia.org/wiki/Birthday_problem)
- **Problems (2):**
  - `[M]` ★ [Birthday Paradox](https://lightoj.com/problem/birthday-paradox)
  - `[H]` ★ [Number Clicker](https://codeforces.com/contest/995/problem/E)

### 11.10 Bigint

**Subcategory ID:** `bigint` · **Topics:** 2

#### 11.10.1 Big Integers

- **ID:** `bigint` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/bigint
- **Templates (1):**
  - [BigInt.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/BigInt.cpp)
- **Resources (2):**
  - ★ [BigInt (BIG INTEGERS) in C++ with Example (GFG)](https://www.geeksforgeeks.org/bigint-big-integers-in-c-with-example/)
  - [How to use BigInt?](https://codeforces.com/blog/entry/16380)
- **Problems (8):**
  - `[E]` ★ [Addition of Big Integers](https://judge.yosupo.jp/problem/addition_of_big_integers)
  - `[E]` [Simple Multiplication](https://vjudge.net/problem/CodeChef-MULTISRM)
  - `[E]` ★ [Fast Multiplication](https://www.spoj.com/problems/MUL/)
  - `[E]` ★ [Very Fast Multiplication](https://www.spoj.com/problems/VFMUL/)
  - `[E]` ★ [Multiplication of Big Integers](https://judge.yosupo.jp/problem/multiplication_of_big_integers)
  - `[M]` ★ [Division of Big Integers](https://judge.yosupo.jp/problem/division_of_big_integers)
  - `[M]` ★ [Perfect Encoding](https://codeforces.com/problemset/problem/986/D)
  - `[M]` [Help King](https://codeforces.com/contest/98/problem/B)

#### 11.10.2 Trygub Numbers

- **ID:** `trygub_numbers` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/trygub_numbers
- **Templates (1):**
  - [Trygub Num.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Trygub%20Num.cpp)
- **Resources (1):**
  - ★ [Big integers with negative digits: The Trygub numbers By adamant](https://codeforces.com/blog/entry/115626)
- **Problems (4):**
  - `[E]` [Powers of Two](https://tlx.toki.id/problems/inc-2022/C/)
  - `[M]` [整数](https://loj.ac/p/2302)
  - `[VH]` [Half-sum](https://codeforces.com/contest/1817/problem/E)
  - `[VH]` [M-tree](https://codeforces.com/contest/1810/problem/F)

### 11.11 Miscellaneous

**Subcategory ID:** `miscellaneous` · **Topics:** 9

#### 11.11.1 Inversions

- **ID:** `inversions` · **Difficulty:** Easy · **Importance:** ★★★ · **Phase:** 2
- **Topic page:** https://youkn0wwho.academy/topic-list/inversions
- **Prerequisites:** Segment Tree or Fenwick Tree
- **Templates (1):**
  - [Inversions.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Inversions.cpp)
- **Resources (1):**
  - ★ [\[Tutorial\] Problems about swapping adjacent elements By TheScrasse](https://codeforces.com/blog/entry/92130)
- **Problems (20):**
  - `[E]` ★ [Inversion Count](https://vjudge.net/problem/SPOJ-INVCNT)
  - `[E]` ★ [Swapping numbers](https://www.hackerearth.com/practice/data-structures/advanced-data-structures/fenwick-binary-indexed-trees/practice-problems/algorithm/move-minimization-8a9d3991/)
  - `[E]` ★ [Minimize Inversions](https://codeforces.com/problemset/problem/1918/B)
  - `[E]` ★ [Make the strings equal](https://www.hackerearth.com/practice/algorithms/string-algorithm/string-searching/practice-problems/algorithm/make-them-equal-too-89585e71/)
  - `[E]` [Mega Inversions](https://vjudge.net/problem/Kattis-megainversions)
  - `[E]` [Greetings](https://codeforces.com/problemset/problem/1915/F)
  - `[M]` ★ [String Reversal](https://codeforces.com/contest/1430/problem/E)
  - `[M]` ★ [Swaps 2](https://atcoder.jp/contests/arc120/tasks/arc120_c)
  - `[M]` [Luna Likes Love](https://codeforces.com/gym/103148/problem/B)
  - `[M]` ★ [Papple Sort](https://atcoder.jp/contests/arc088/tasks/arc088_c)
  - `[M]` [Sorted and Sorted](https://atcoder.jp/contests/arc097/tasks/arc097_c)
  - `[M]` [Arranging Shoes](https://oj.uz/problem/view/IOI19_shoes)
  - `[M]` ★ [Inversion Counting](https://codeforces.com/contest/911/problem/D)
  - `[M]` [Kill Anton](https://codeforces.com/contest/1526/problem/D)
  - `[M]` [Inversions problem](https://vjudge.net/problem/CodeForces-513G1)
  - `[M]` ★ [K-inversions](https://acm.timus.ru/problem.aspx?space=1&num=1523)
  - `[M]` ★ [Sherlock and Inversions](https://www.codechef.com/problems/IITI15)
  - `[M]` ★ [Static Range Inversions Query](https://judge.yosupo.jp/problem/static_range_inversions_query)
  - `[H]` [Group Photo](https://atcoder.jp/contests/joi2021ho/tasks/joi2021ho_c)
  - `[H]` ★ [Counting inversions](https://vjudge.net/problem/SPOJ-SWAPS)

#### 11.11.2 Josephus Problem

- **ID:** `josephus_problem` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/josephus_problem
- **Templates (1):**
  - [Josephus Problem.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Josephus%20Problem.cpp)
- **Resources (3):**
  - ★ [Josephus Problem | CP Algorithms](https://cp-algorithms.com/others/josephus_problem.html)
  - [Multiple people Josephus problem By ad_red](https://codeforces.com/blog/entry/118764)
  - ★ [The Josephus Problem - Numberphile](https://www.youtube.com/watch?v=uCsD3ZGzMgE)
- **Problems (5):**
  - `[E]` ★ [Josephus Problem I](https://cses.fi/problemset/task/2162)
  - `[E]` ★ [Josephus Problem II](https://cses.fi/problemset/task/2163)
  - `[E]` [Lucky Number](https://www.codechef.com/IGNU2015/problems/IGNUS15B)
  - `[E]` ★ [Josephus Queries](https://cses.fi/problemset/task/2164)
  - `[E]` ★ [Josephus Again](https://www.codechef.com/problems/JOSEPHUS)

#### 11.11.3 Gray Code

- **ID:** `gray_code` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/gray_code
- **Templates (1):**
  - [Gray Code.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/Gray%20Code.cpp)
- **Resources (1):**
  - ★ [Gray code | CP Algorithms](https://cp-algorithms.com/algebra/gray-code.html)
- **Problems (4):**
  - `[E]` ★ [Gray Code](https://cses.fi/problemset/task/2205)
  - `[E]` ★ [Grey Codes](https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=2114)
  - `[E]` ★ [Тест](https://codeforces.com/gym/100209/problem/D)
  - `[M]` [Matrix](https://codeforces.com/problemsets/acmsguru/problem/99999/249)

#### 11.11.4 Backtracking

- **ID:** `backtracking` · **Difficulty:** Easy · **Importance:** ★★★
- **Topic page:** https://youkn0wwho.academy/topic-list/backtracking
- **Resources (12):**
  - ★ [What is Backtracking Algorithm? Types, Examples & its Application By Soni Upadhyay](https://www.simplilearn.com/tutorials/data-structure-tutorial/backtracking-algorithm)
  - ★ [Backtracking tutorial: power set WilliamFiset](https://www.youtube.com/watch?v=RnlHPR0lyOE)
  - ★ [Recursion and Backtracking | HackerEarth](https://www.hackerearth.com/practice/basic-programming/recursion/recursion-and-backtracking/tutorial/)
  - ★ [Introduction to Backtracking – Data Structure and Algorithm Tutorials | Geeks for Geeks](https://www.geeksforgeeks.org/introduction-to-backtracking-data-structure-and-algorithm-tutorials/)
  - [Backtracking Algorithm | Programiz](https://www.programiz.com/dsa/backtracking-algorithm)
  - [N Queens Problem | Geeks for Geeks](https://www.geeksforgeeks.org/printing-solutions-n-queen-problem/)
  - [Sudoku | Geeks for Geeks](https://www.geeksforgeeks.org/sudoku-backtracking-7/)
  - [M coloring problem | Geeks for Geeks](https://www.geeksforgeeks.org/m-coloring-problem/)
  - [Hamiltonian path problem | Wiki](https://en.wikipedia.org/wiki/Hamiltonian_path_problem)
  - [Eight queens puzzle | Wiki](https://en.wikipedia.org/wiki/Eight_queens_puzzle)
  - [Knight's tour | Wiki](https://en.wikipedia.org/wiki/Knight%27s_tour)
  - [15 Puzzle Game: Existence Of The Solution | CP Algorithms](https://cp-algorithms.com/others/15-puzzle.html)
- **Problems (25):**
  - `[E]` ★ [Dreamoon and WiFi](https://codeforces.com/problemset/problem/476/B)
  - `[E]` ★ [Tower of Hanoi](https://vjudge.net/problem/CSES-2165)
  - `[E]` ★ [Passwords](https://onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=569)
  - `[E]` ★ [Red and Black](https://vjudge.net/problem/POJ-1979)
  - `[E]` ★ [8 Queens Chess Problem](https://vjudge.net/problem/UVA-750)
  - `[E]` [The Sultan's Successors](https://vjudge.net/problem/UVA-167)
  - `[E]` [Don't Get Rooked](https://vjudge.net/problem/POJ-1315)
  - `[E]` ★ [Map Colouring](https://vjudge.net/problem/Kattis-mapcolouring)
  - `[E]` [Prime Ring Problem](https://vjudge.net/problem/UVA-524)
  - `[E]` ★ [Hamiltonian Cycle](https://vjudge.net/problem/UVA-775)
  - `[E]` [Jugs](https://vjudge.net/problem/UVA-571)
  - `[E]` [Back to the 8-Queens](https://vjudge.net/problem/UVA-11085)
  - `[E]` ★ [23 out of 5](https://vjudge.net/problem/UVA-10344)
  - `[E]` ★ [All Walks of length "n" from the first node](https://vjudge.net/problem/UVA-677)
  - `[E]` [Knight's Tour](https://cses.fi/problemset/task/1689)
  - `[E]` ★ [Creating Strings](https://cses.fi/problemset/task/1622)
  - `[E]` ★ [Chessboard and Queens](https://cses.fi/problemset/task/1624)
  - `[M]` ★ [Random Digital Exponentiation](https://open.kattis.com/problems/randomdigitalexponentiation)
  - `[M]` [Codovid Virus](https://lightoj.com/problem/c-icpc-dhk-2021)
  - `[M]` ★ [A problem of Backtracking](https://vjudge.net/problem/SPOJ-BTCK)
  - `[M]` [Sum It Up](https://vjudge.net/problem/UVA-574)
  - `[H]` [Smallest Inverse Euler Totient Function](https://www.spoj.com/problems/INVPHI/)
  - `[H]` ★ [N Queen Again](https://vjudge.net/problem/LightOJ-1061)
  - `[VH]` ★ [Faketorial Hashing](https://codeforces.com/gym/102040/problem/D)
  - `[VH]` ★ [Enumerate Cliques](https://judge.yosupo.jp/problem/enumerate_cliques)

#### 11.11.5 [Problem] MEX of all Subarrays

- **ID:** `mex_of_all_subarrays` · **Difficulty:** Hard · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/mex_of_all_subarrays
- **Templates (1):**
  - [MEX of all Subarrays.cpp](https://github.com/ShahjalalShohag/code-library/blob/main/Miscellaneous/MEX%20of%20all%20Subarrays.cpp)
- **Resources (3):**
  - ★ [Editorial of 1148H - Holy Diver](https://codeforces.com/blog/entry/67366)
  - ★ [Editorial of F | DSAAcademy — Shahjalal Shohag](https://toph.co/p/f/editorial)
  - [Offline Range MEX queries in O(log n) By one_autum_leaf](https://codeforces.com/blog/entry/117688)
- **Problems (3):**
  - `[E]` ★ [Complicated Computations](https://codeforces.com/contest/1436/problem/E)
  - `[H]` ★ [F](https://toph.co/p/f)
  - `[H]` ★ [Holy Diver](https://codeforces.com/contest/1148/problem/H)

#### 11.11.6 Lindstrom Gessel Viennot(LGV) Lemma

- **ID:** `lindstrom_gessel_viennot_lemma` · **Difficulty:** Hard · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/lindstrom_gessel_viennot_lemma
- **Resources (2):**
  - ★ [Lattice paths and Lindström–Gessel–Viennot lemma By miaowtin](https://codeforces.com/blog/entry/108395)
  - ★ [Lindström–Gessel–Viennot lemma | Wiki](https://en.wikipedia.org/wiki/Lindstr%C3%B6m%E2%80%93Gessel%E2%80%93Viennot_lemma)
- **Problems (1):**
  - `[E]` ★ [Turtles](https://codeforces.com/problemset/problem/348/D)

#### 11.11.7 Dynamic Bitsets

- **ID:** `dynamic_bitsets` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/dynamic_bitsets
- **Resources (1):**
  - ★ [Dynamic Bitsets in GCC By bitset](https://codeforces.com/blog/entry/129454)
- **Problems (2):**
  - `[E]` [Triangle](https://atcoder.jp/contests/abc258/tasks/abc258_g)
  - `[M]` ★ [PermuTree (hard version)](https://codeforces.com/contest/1856/problem/E2)

#### 11.11.8 Pragmas

- **ID:** `pragmas` · **Difficulty:** Medium · **Importance:** ★★☆
- **Topic page:** https://youkn0wwho.academy/topic-list/pragmas
- **Resources (6):**
  - ★ [#pragma Directive in C | Geeks for Geeks](https://www.geeksforgeeks.org/pragma-directive-in-c-c/)
  - ★ [Speeding Up for Naive Algorithm By E869120](https://codeforces.com/blog/entry/66279)
  - ★ [Speed up Code executions with help of Pragma in C/C++ | Geeks for Geeks](https://www.geeksforgeeks.org/speed-up-naive-algorithms-in-competitive-coding-in-c-cpp/)
  - ★ [Tree queries for O(nq) By Golovanov399](https://codeforces.com/blog/entry/67001)
  - [Using pragmas efficiently in C++](https://stackoverflow.com/questions/76598335/using-pragmas-efficiently-in-c)
  - ★ [Vectorization in C++ | USACO Guide](https://usaco.guide/adv/vectorization?lang=cpp)
- **Problems (6):**
  - `[E]` ★ [Mass Change Queries](https://codeforces.com/contest/911/problem/G)
  - `[E]` ★ [Awesome Substrings](https://codeforces.com/contest/1270/problem/F)
  - `[M]` [Nagini](https://codeforces.com/contest/855/problem/F)
  - `[M]` ★ [Sonya and Gifts](https://www.codechef.com/MAY19A/problems/SONGIF)
  - `[M]` [May Holidays](https://codeforces.com/contest/925/problem/E)
  - `[H]` ★ [Welcome home, Chtholly](https://codeforces.com/contest/896/problem/E)

#### 11.11.9 Boyer–Moore Voting Algorithm and Misra–Gries Algorithm

- **ID:** `boyer_moore_voting_algorithm_and_misra_gries_algorithm` · **Difficulty:** Easy · **Importance:** ★☆☆
- **Topic page:** https://youkn0wwho.academy/topic-list/boyer_moore_voting_algorithm_and_misra_gries_algorithm
- **Resources (7):**
  - ★ [Boyer–Moore majority vote algorithm | Wikipedia](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm)
  - [Boyer-Moore Majority Voting Algorithm | GeeksForFeeks](https://www.geeksforgeeks.org/theory-of-computation/boyer-moore-majority-voting-algorithm/)
  - [Boyer-Moore Majority Voting Algorithm by Anil Goyal](https://medium.com/@anil.goyal0057/boyer-moore-majority-voting-algorithm-d3e6b4601ba7)
  - ★ [Boyer Moore majority vote algorithm | TopCoder](https://www.topcoder.com/thrive/articles/boyer-moore-majority-vote-algorithm)
  - ★ [Misra–Gries heavy hitters algorithm | Wikipedia](https://en.wikipedia.org/wiki/Misra%E2%80%93Gries_heavy_hitters_algorithm)
  - ★ [The streaming model, and how to estimate the most frequent elements with the Misra-Gries algorithm by Stéphane Guichard](https://medium.com/nerd-for-tech/the-streaming-model-and-how-to-estimate-the-most-frequent-elements-with-the-misra-gries-algorithm-c880bbe7218b)
  - [Dominant Path Queries discussion By ExtraStageLover](https://codeforces.com/blog/entry/121038)
- **Problems (4):**
  - `[E]` ★ [Buratsuta 3](https://codeforces.com/contest/2149/problem/G)
  - `[E]` ★ [Majority Element](https://leetcode.com/problems/majority-element/description/)
  - `[E]` ★ [Majority Element II](https://leetcode.com/problems/majority-element-ii/description/)
  - `[M]` ★ [Destiny](https://codeforces.com/contest/840/problem/D)

---

## Useful Links (from the topic-list page)

- [Codeforces](https://codeforces.com)
- [AtCoder](https://atcoder.jp)
- [CodeChef](https://www.codechef.com)
- [Codeforces Catalog](https://codeforces.com/catalog)
- [A list of almost all useful blogs ever published on Codeforces (parveen1981)](https://codeforces.com/blog/entry/91363)
- [(Plenty of) useful blogs in Codeforces (tallnut_liu)](https://codeforces.com/blog/entry/125623)
- [Helpful Codeforces Extensions (MohamedAboOkail)](https://codeforces.com/blog/entry/82884)
- [Stress Testing (C137)](https://ali-ibrahim137.github.io/competitive/programming/2020/08/23/Stress-Testing.html)
- [AtCoder Problems](https://kenkoooo.com/atcoder/#/table/)
- [CSES Problem Set](https://cses.fi/problemset/)
- [Library Checker](https://judge.yosupo.jp/)
- [VJudge](https://vjudge.net/)
- [StopStalk](https://www.stopstalk.com/)
- [CP Algorithms](https://cp-algorithms.com/index.html)
- [USACO Guide](https://usaco.guide/)
- [VisuAlgo](https://visualgo.net/en)
- [Graph Editor (CSAcademy)](https://csacademy.com/app/graph_editor/)
- [A List of Useful Equations in Competitive Programming (DSAAcademy — Shahjalal Shohag)](https://blog.shahjalalshohag.com/equation-list/)
- [Common Mistakes in Competitive Programming and How to Avoid Them (DSAAcademy — Shahjalal Shohag)](https://codeforces.com/blog/entry/111217)
- [CP Trainer (Michal Opala)](https://codeforces.com/blog/entry/146823)

---

**Totals:** 11 categories · 126 subcategories · 570 topics · 1542 resource links · 451 template links · 4437 topic→problem links (3888 unique problems).
