Repository: luctivud/All-Of-Competitive-Programming Branch: master Commit: 0a8926089af6 Files: 37 Total size: 115.4 KB Directory structure: gitextract_peww_frl/ ├── 00-Setting-up-local-environment/ │ └── README.md ├── 01-Material/ │ └── README.md ├── 02-Codes/ │ ├── Editorials/ │ │ ├── ConvertToStrictlyIncreasing/ │ │ │ ├── ConevertToStrictlyIncreasing.md │ │ │ ├── convertToIncreasing.cpp │ │ │ └── convertToIncreasing.py │ │ └── Random/ │ │ └── TransposeColorsWork.cpp │ ├── README.md │ └── Snippets/ │ ├── Raw/ │ │ └── 166_e_MatMul_w_Ashishgup.cpp │ ├── Sublime/ │ │ ├── FastReadWrite.sublime-snippet │ │ ├── addundirectededge.sublime-snippet │ │ ├── basic-template.sublime-snippet │ │ ├── check execution time.sublime-snippet │ │ ├── checkvalid.sublime-snippet │ │ ├── cmp-priority.sublime-snippet │ │ ├── common-completions.sublime-completions │ │ ├── dsu-array.sublime-snippet │ │ ├── dsu.sublime-snippet │ │ ├── errorWatch.sublime-snippet │ │ ├── eulerTotientFunc.sublime-snippet │ │ ├── leetcode-solution-class.sublime-snippet │ │ ├── manipulated-sieve-of-eratosthene.sublime-snippet │ │ ├── matrix-expo.sublime-snippet │ │ ├── max-biparite-matching.sublime-snippet │ │ ├── modop.sublime-snippet │ │ ├── myReadTemplate.sublime-snippet │ │ ├── ncr-on-demand.sublime-snippet │ │ ├── pbds.sublime-snippet │ │ ├── power-expo.sublime-snippet │ │ ├── sieve-of-eratosthene.sublime-snippet │ │ └── topcoder-template.sublime-snippet │ └── mydebug.h ├── 03-Interview Preparation/ │ ├── Docs/ │ │ ├── .gitkeep │ │ ├── 0x01_Interview_Preparation_in_C_v1.0.docx │ │ └── System Design Guide.docx │ ├── PDF/ │ │ └── .gitkeep │ └── README.md └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: 00-Setting-up-local-environment/README.md ================================================ # Setting up Competitive Programming on Local Machine : #### Content - [Benefits](#Benefits) - [SetUp](#Setting-up-env) - [Snippets](#Snippets)


## Benefits #### It is always a good practice to set up your coding environment right on your pc as : * It helps in faster code execution. * Independent of the load on IDE's during the contest. * Various Code Snippets can be used. * Interaction with command line and terminal. * Less chances of your code getting leaked.


## Setting up env: So below are some good setups which you may like and may modify as well as per your choice. Also, you can set up your environment as you like if you have basic knowledge and read any of the blogs below. Just set up the compiler and a text editor or ide. Remember to add the path of your compiler to environment variable. p.s. Should read about precompiling the headers if you use C++ for faster build. [Codeforces blog for some editor preferences](https://codeforces.com/blog/entry/356)
### VSCode and C++ : * [Setting up VS Code for CP - Rachit Jain - Youtube](https://www.youtube.com/watch?v=Y-_3rXgrRAY)
### Sublime and C++ : * [Codingblocks Blog](https://blog.codingblocks.com/2019/setting-up-a-c-competitive-programming-environment/) * [Codingblocks - Youtube](https://www.youtube.com/watch?v=Mt6Jb8u9XBk) * [Blog - the-hyp0cr1t3](https://github.com/the-hyp0cr1t3/CC/blob/master/Setting%20up%20Sublime.md)
### C++ in Ubuntu : * [GeeksforGeeks Blog](https://www.geeksforgeeks.org/setting-up-a-c-competitive-programming-environment/)
### Linux Setup with Geany : * [Linux Setup with Geany - Errichto - Youtube](https://www.youtube.com/watch?v=ePZEkbbf3fc)
### Precompiling C++ headers : It is always important to precompile the C++ header files to save your precious time in compilation. You can search for the same on the internet if you run into error. All you have to do is to find your stdc++.h file in your compiler path and then compile it like normal file with the flags you use to run. `g++ [your-flags] stdc++.h` * [Codeforces blog for windows](https://codeforces.com/blog/entry/66809) * [Codeforces blog for linux distro](https://codeforces.com/blog/entry/53909?) * [Another Codeforces blog](https://codeforces.com/blog/entry/79026)
### VSCode and Python3 : I prefer Python and VSCode setup. Here's how you can set it up : * Download and install Python3 and VSCode. * Add path to environment variable. * Install CodeRunner Extension on VSCode. * Open your settings.json file on VSCode and modify the coderunner command for any python file as `python -u output.txt` to take input from input.txt and write to output.txt. Then you can easily run your file with ctrl + alt + n
### Bonus [CP Editor](https://cpeditor.org/) This editor is purposely designed for CP and Codeforces. Easy to use and many interesting features. It greatly improves typing speed as one of my friends who is a big fan of this editor suggests.


## Snippets Snippets are the cool features offered by the text editors through which you can add a bunch of code just by a few taps. - [CP Snippets by Atom.io](https://atom.io/packages/cpp-competitive-programming-snippets)
You can add your own snippets as for loading your template, adding a bfs code or for anything you want. Just look for how to add custom snippets in your text editor. - [VSCode Guide - Blog](https://code.visualstudio.com/docs/editor/userdefinedsnippets) - [Sublime Text 3 - Video & Blog](https://devdojo.com/episode/how-to-create-sublime-text-snippets)

> Now you're all set to solve the [problems](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/01-Material). > I've mentioned all the popular setups. If you're facing an error in setting up it is easy to google it and find solution on stackoverflow. ================================================ FILE: 01-Material/README.md ================================================ # CP Material Many of the seniors as well good competitive coders advice to not waste any money on the courses which are designed for beginners. It is always easy to start cp on your own and be good at it. However you can choose to have a good certification on Data Structures and ALgorithms offered by [Codechef](https://www.codechef.com/certification/data-structures-and-algorithms/about) or choose a course which aims at advanced data structures and algorithms.
#### Content * [Books](#books) * [Informative Blogs](#some-good-and-informative-blogs-) * [Problemset](#Problemset)


## Books:
* Check out [this](https://github.com/lnishan/awesome-competitive-programming#books-for-algorithms) section for a long list of books. * I prefer to have [Competitive Programmers Handbook by Antti Laaksonen](https://cses.fi/book/book.pdf) and [Introduction To Algorithms by CLRS](https://web.iiit.ac.in/~pratik.kamble/storage/Algorithms/Cormen_Algorithms_3rd.pdf) as mandatory. > Note: The best time to read the topics in any book is either in the morning or in the evening to grasp everything.


## Some good and informative blogs :
Below is the encyclopedia of all that one needs to set up the schedule of cp and start away asap. * [ACM-ICPC Preparation Repository by BedirT](https://github.com/BedirT/ACM-ICPC-Preparation) : The curriculum and schedule one needs to follow to learn data structures and algorithms for ICPC. * [Getting into Competitive Coding by hyp0cr1t3](https://github.com/the-hyp0cr1t3/CC) : This repo is best for starting cp. It contains everything you need to master cp from basic setup to data structures along with decent problemset. Make sure to check the tips and tricks section. * [Awesome Competitive Programming by lnishan](https://github.com/lnishan/awesome-competitive-programming) : The encyclopedia of cp. It contains in-depth analysis as well as topic wise practice problems. Probably more than one can ask for. * [Competitive Coding Implementation (C++) by Ashishgup](https://github.com/Ashishgup1/Competitive-Coding) : Whenever you run into any problem, just check the implementation of Ashish Sir. His codes are easy to understand and beautifully formatted. * [Competitive Coding Implementation (Python) by cheran-senthil](https://github.com/cheran-senthil/PyRival) : Python Oriented Library for Competitive Programming. * [OEIS](https://oeis.org/) : who doesn't love integer sequences? Well everyone should.
[Back To Top](#cp-material)

## Problemset
The problemset is divided into two broad categories based on beginner or intermediate level of knowledge. * [Beginners](#Beginners) * [Intermediate](#intermediate)
[Back To Top](#cp-material)

### Beginners
* **Start :** :page_facing_up: [TopCoder-Introduction to Competitive Programming](https://www.topcoder.com/community/competitive-programming/tutorials) :movie_camera: [Starting CP - Errichto - Youtube](https://www.youtube.com/watch?v=xAeiXy8-9Y8) :page_facing_up: [Codingblocks](https://blog.codingblocks.com/2019/start-with-competitive-programming/) :page_facing_up: [How to start CC - cf](https://codeforces.com/blog/entry/49157)
* **Train :** :page_facing_up: [Must do Maths in CP - Gfg](https://www.geeksforgeeks.org/math-in-competitive-programming/?ref=leftbar-rightbar) :page_facing_up: [Hackerearth - Codemonk](https://www.hackerearth.com/blog/developers/hackerearth-codemonk-v2-0/) :page_facing_up: [Training Roadmap for newcomers - cf](https://codeforces.com/blog/entry/65133) - [ ] [Arabic CP](https://github.com/mostafa-saad/ArabicCompetitiveProgramming/) and the [Junior Training Sheet](https://docs.google.com/spreadsheets/d/1iJZWP2nS_OB3kCTjq8L6TrJJ4o-5lhxDOyTaocSYc-k/edit#gid=1160016643) as well as [Supervision Template](https://docs.google.com/spreadsheets/d/1QUegTqKnVtdejCwttYFXHeOQs6Q5nmAT77sxWh3qYMc/edit#gid=2139527441). - [ ] [20+ leetcode problems on Sliding Window](https://leetcode.com/discuss/general-discussion/657507/Sliding-Window-for-Beginners-Problems-or-Template-or-Sample-Solutions)
* **Solve :** It is adviced to solve beginner level problems with lower rating first and then jump to higher ratings when you start feeling comfortable. Do not copy paste solutions directly from editorial without implementing on your own. - [ ] [CSES Problemset](https://cses.fi/problemset/) - [ ] [A2OJ Ladders](https://a2oj.com/ladders) - [ ] [Another A2OJ ladder](https://earthshakira.github.io/a2oj-clientside/server/Categories.html) : Mirror - [ ] [CodeForces-Ladders with updated problemset](https://github.com/karansinghgit/CodeForces-Ladders)
* **Bonus :** :page_facing_up: [Simple Trick to detect integer overflow - codechef discuss](https://discuss.codechef.com/t/simple-trick-to-detect-integer-overflow-c-c/54373) :page_facing_up: [Catching silly mistakes with GCC](https://codeforces.com/blog/entry/15547)
[Back To Problemset](#problemset)

### Intermediate
Solving the beginner level problems from the above resources will be enough to get a sound knowledge of basic Maths, Greedy, AdHoc and other constructive problems and their approach. For Data Structures and Algorithms, consider: - [ ] [Codechef Blog on Data Structures and Algorithms with 100+ Problems and Tutorial](https://discuss.codechef.com/t/data-structures-and-algorithms/6599) : This blog has tutorials and practice problems for most of the data structures and algorithms that one can come across. :page_facing_up: [CP Algorithm](https://cp-algorithms.com/) : This online project is the English translation of a popular [russian site](http://e-maxx.ru/algo) containing descriptions of many algorithms and data structures especially popular in field of competitive programming and practice problems. :page_facing_up: [Important Algorithms for Competitive Programming - Code of Geeks](https://codeofgeeks.com/important-algorithms-for-competitive-programming/) :page_facing_up: [vplanetcoding](https://www.vplanetcoding.com/course2) : Check out all the free courses. - [ ] [Junior Training Sheet](https://docs.google.com/spreadsheets/d/1iJZWP2nS_OB3kCTjq8L6TrJJ4o-5lhxDOyTaocSYc-k/edit#gid=1160016643) & [CSES Prolemset](https://cses.fi/problemset/) - (Again!)
>The problems are majorly categorized into following topics for now:
**Content**
* [Graphs](#Graphs) * [Dynamic Programming](#Dynamic-Programming) * [Trees](#Trees) * [Other](#Other)
[Back To Problemset](#problemset)

## Graphs
* #### Tutorial : :page_facing_up: [CF-Center of graph](https://codeforces.com/blog/entry/17974) :page_facing_up: [Longest Path Problem - Wikipedia](https://en.wikipedia.org/wiki/Longest_path_problem) :page_facing_up: [Graph Diameter - Mathworld](https://mathworld.wolfram.com/GraphDiameter.html) * #### Problemset : - [ ] [Codeforces comment with 100+ graph problems](https://codeforces.com/blog/entry/55219?#comment-390897) - [ ] [international-open-olympiad-kpiopen-2013-round-1](https://codeforces.com/gym/100279/attachments/download/2025/20122013-international-open-olympiad-kpiopen-2013-round-1-en.pdf) - [ ] [LeetCode Graph Related Problems](https://leetcode.com/list/x1vj23fh/) - [ ] [500+ Problems on BFS/DFS/Dijkshtra - A2OJ](https://a2oj.com/category?ID=13) **IARCS** - [ ] [Graphs](https://www.iarcs.org.in/inoi/online-study-material/topics/graphs.php) - [ ] [Advanced Graph Algo](https://www.iarcs.org.in/inoi/online-study-material/topics/advanced-graph-algorithms.php) **Union Find** - [ ] [leetcode : friend-circle](https://leetcode.com/problems/friend-circles/) - [ ] [leetcode : redundant-connection](https://leetcode.com/problems/redundant-connection/) - [ ] [leetcode : most-stones-removed-with-same-row-or-column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/) - [ ] [leetcode : number-of-operations-to-make-network-connected](https://leetcode.com/problems/number-of-operations-to-make-network-connected/) - [ ] [leetcode : satisfiability-of-equality-equation](https://leetcode.com/problems/satisfiability-of-equality-equations/) - [ ] [leetcode : accounts-merge](https://leetcode.com/problems/accounts-merge/) **DFS - Basic** - [ ] [leetcode : surrounded-region](https://leetcode.com/problems/surrounded-regions/) - [ ] [leetcode : number-of-enclave](https://leetcode.com/problems/number-of-enclaves/) - [ ] [leetcode : time-needed-to-inform-all-employee](https://leetcode.com/problems/time-needed-to-inform-all-employees/) - [ ] [leetcode : find-eventual-safe-state](https://leetcode.com/problems/find-eventual-safe-states/) **Island Problems** - [ ] [leetcode : number-of-closed-island](https://leetcode.com/problems/number-of-closed-islands/) - [ ] [leetcode : number-of-island](https://leetcode.com/problems/number-of-islands/) - [ ] [leetcode : keys-and-room](https://leetcode.com/problems/keys-and-rooms/) - [ ] [leetcode : max-area-of-island](https://leetcode.com/problems/max-area-of-island/) - [ ] [leetcode : flood-fill](https://leetcode.com/problems/flood-fill/) **BFS** - [ ] [http://codeforces.com/contest/653/problem/E](http://codeforces.com/contest/653/problem/E) - [ ] [https://codeforces.com/contest/769/problem/C](https://codeforces.com/contest/769/problem/C) - [ ] [https://codeforces.com/contest/796/problem/D](https://codeforces.com/contest/796/problem/D) - [ ] [https://codeforces.com/contest/821/problem/D](https://codeforces.com/contest/821/problem/D) - [ ] [http://www.spoj.com/problems/DIGOKEYS/](http://www.spoj.com/problems/DIGOKEYS/) - [ ] [http://www.spoj.com/problems/SPIKES/](http://www.spoj.com/problems/SPIKES/) - [ ] [http://www.spoj.com/problems/MULTII/](http://www.spoj.com/problems/MULTII/) - [ ] [http://www.spoj.com/problems/ADV04F1/](http://www.spoj.com/problems/ADV04F1/) - [ ] [http://www.spoj.com/problems/ADV04F1/](http://www.spoj.com/problems/ADV04F1/) - [ ] [leetcode : 01-matrix](https://leetcode.com/problems/01-matrix/) - [ ] [leetcode : as-far-from-land-as-possible](https://leetcode.com/problems/as-far-from-land-as-possible/) - [ ] [leetcode : rotting-orange](https://leetcode.com/problems/rotting-oranges/) - [ ] [leetcode : shortest-path-in-binary-matrix](https://leetcode.com/problems/shortest-path-in-binary-matrix/) **Graph Coloring** - [ ] [leetcode : possible-bipartition](https://leetcode.com/problems/possible-bipartition/) - [ ] [leetcode : is-graph-bipartite](https://leetcode.com/problems/is-graph-bipartite/) **Topological Sort** - [ ] [leetcode : course-schedule](https://leetcode.com/problems/course-schedule/) - [ ] [leetcode : course-schedule-ii](https://leetcode.com/problems/course-schedule-ii/) - [ ] [codeforces : 510C-Fox and names](https://codeforces.com/contest/510/problem/C) **Other** - [ ] [https://dmoj.ca/problem/tle16c4p4](https://dmoj.ca/problem/tle16c4p4) - [ ] [https://codeforces.com/problemset/problem/322/E](https://codeforces.com/problemset/problem/322/E) - [ ] [https://codeforces.com/problemset/problem/592/D](https://codeforces.com/problemset/problem/592/D) - [ ] [https://codeforces.com/contest/456/problem/E](https://codeforces.com/contest/456/problem/E) The above problems were extracted from [this leetcode article](https://leetcode.com/discuss/general-discussion/655708/graph-for-beginners-problems-pattern-sample-solutions). Thanks to the work of [wh0ami sir](https://leetcode.com/wh0ami/).
[Back To Problemset](#problemset)

## Dynamic Programming
* #### Tutorial : :page_facing_up: [Hackerearth](https://www.hackerearth.com/practice/algorithms/dynamic-programming/introduction-to-dynamic-programming-1/tutorial/) :page_facing_up: [Codechef Tutorial and few problems](https://www.codechef.com/wiki/tutorial-dynamic-programming) :page_facing_up: [TutorialsPoint Blog](https://www.tutorialspoint.com/data_structures_algorithms/dynamic_programming.htm) :movie_camera: [CS Dojo - Youtube](https://www.youtube.com/watch?v=vYquumk4nWw) :movie_camera: [Aditya Verma - Youtube](https://www.youtube.com/watch?v=nqowUJzG-iM&list=PL_z_8CaSLPWekqhdCPmFohncHwz8TY2Go) Check this one out. :movie_camera: [CodeN Code - youtube](https://www.youtube.com/watch?v=AfE1nZjG5ZM&list=PL2q4fbVm1Ik71hmKyay-GkU6J9GTXCe5g) :page_facing_up: [Dynamic Programming Beginner's Course](https://discuss.codechef.com/t/dynamic-programming-beginners-course/70936) contains problems and video tutorials. * #### Problemset : - [ ] [100+ LeetCode problems - wh0ami](https://leetcode.com/discuss/general-discussion/662866/Dynamic-Programming-for-Practice-Problems-Patterns-and-Sample-Solutions) - [ ] [100+ codeforces problems - karansinghgit](https://github.com/karansinghgit/CodeForces-Ladders/blob/master/dynamicProgramming.md) - [ ] [1000+ problems on DP - A2OJ](http://a2oj.com/category?ID=33) - [ ] [Few other DP problems - A2OJ](https://a2oj.com/category?ID=758) - [ ] [AtCoder DP Contest](https://atcoder.jp/contests/dp/tasks) - [ ] [30+ Non-Classical Dynamic Programming problems - A2OJ](https://a2oj.com/category?ID=126)
[Back To Problemset](#problemset)

## Trees
* #### Tutorial : :page_facing_up: [Trees - hackerearth](https://www.hackerearth.com/practice/notes/trees/) :page_facing_up: [Fenwick Tree - gfg](https://www.geeksforgeeks.org/binary-indexed-tree-or-fenwick-tree-2/) :page_facing_up: [Dynamic Programming on Trees - gfg](https://www.geeksforgeeks.org/dynamic-programming-trees-set-1/) :movie_camera: [Dynamic Programming on Trees - Aditya Verma - Youtube](https://www.youtube.com/playlist?list=PL_z_8CaSLPWfxJPz2-YKqL9gXWdgrhvdn) * #### Problemset : - [ ] [Vplanet](https://www.vplanetcoding.com/course3) - [ ] [Binary and n-ary trees - Hackerearth](https://www.hackerearth.com/practice/data-structures/trees/binary-and-nary-trees/practice-problems/) - [ ] [BST - hackerearth](https://www.hackerearth.com/practice/data-structures/trees/binary-search-tree/practice-problems/) - [ ] [Heaps - hackerearth](https://www.hackerearth.com/practice/data-structures/trees/heapspriority-queues/practice-problems/) - [ ] [GERALD2 - codechef](http://www.codechef.com/NOV13/problems/GERALD2) - [ ] [GERALD07 - codechef](http://www.codechef.com/MARCH14/problems/GERALD07) - [ ] [FBCHEF - codechef](http://www.codechef.com/APRIL14/problems/FBCHEF) - [ ] [GERALD08 - codechef](http://www.codechef.com/APRIL14/problems/GERALD08) - [ ] [MLCHEF - codechef](https://www.codechef.com/SEPT13/problems/MLCHEF) - [ ] [200+ Problems on Trees - A2OJ](https://a2oj.com/category?ID=89) - [ ] [150+ Problems on Segment Trees - A2OJ](https://a2oj.com/category?ID=25) - [ ] [20+ problems on Balanced BST - A2OJ](https://a2oj.com/category?ID=14) - [ ] [20+ problems on suffix array A2OJ](https://a2oj.com/category?ID=44)
[Back To Problemset](#problemset)

## Other
:movie_camera: [Algorithm - SecondThread - Youtube](https://www.youtube.com/watch?v=cVBzMXYc4ss&list=PLZU0kmvryb_HZpDW2yfn-H-RxAu_ts6xq) :page_facing_up: [Matrix Exponentiation cf Blog](https://codeforces.com/blog/entry/67776) :page_facing_up: [Matrix Expo - gfg](https://www.geeksforgeeks.org/matrix-exponentiation/) :movie_camera: [Matrix Expo - Errichto - Youtube](https://www.youtube.com/watch?v=eMXNWcbw75E) - [ ] [Matrix Expo - Problems - Mashup](https://codeforces.com/gym/102644) - [ ] [90+ problems on matrix expo - A2OJ](https://a2oj.com/category?ID=32)
[Back To Problemset](#problemset)

> Note: There's a whole lot of problems still to be added. Any help will be appreciated. ================================================ FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/ConevertToStrictlyIncreasing.md ================================================

Convert an array into Strictly Increasing Array

Solution by Udit Gupta

Problem Statement

Given an array consisting of N elements namely from A1 to AN. You have to convert this array to strictly increasing array in not more than K cost. Operations allowed : 1. Increase an element by 1. 2. Decrease an element by 1. Cost of each operation is 1 unit.

Constraints

- N < 3000 - K < 5000 - |Ai| < 109 for all i from 1 to N.

Expected Time Complexity : O(N2)



Solution

Observation

1. After solving a few examples on pen and paper, we get to see that a greedy solution would fail on cases like [8, 1, 2, 3, 4] or [7, 1, 5, 2, 4, 8, 6]. 2. Another key observation is that in the transformed array which is strictly increasing, we will find that there is atleast one element which remains unchanged.

Deduction

The problem statement above can be translated into simpler terms by stating that for each i from _1_ to _N-1_,   **Ai   <   Ai+1** Now we shall work on simplifying it further and deducing a general formula for all terms, - **Ai   <   Ai+1** - **Ai   ≤   Ai+1 - 1** - Subtracting i from both sides, - **Ai-i   ≤   Ai+1-1-i** _or_ - **Ai-i   ≤   Ai+1-(i+1)** This is the general formulation which should work for all indices in range [1, N]. i.e. The sequence represented by **(Ai-i)**   ∀   i ∈ [1, N] should be a **non decreasing sequence**. To achieve this we take use of dynamic programming and brute force our way to make the subsequent array element equal to the previous one if not or leaving it as it is depending on the previous dp state. This idea, here, comes from observation 2 and we can even end up converting the whole array to a single element.

DP transition states: - **dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j]))**   ∀   i, j ∈ [1, N]. Please note that the array **A** here is the converted array represented by (Ai-i)   ∀   i ∈ [1, N] and **B** is its sorted version. Our final answer that represents the minimum cost is stored in the final index of our **dp** array which represents the optimal array till last index of **A**.

If our minimum cost is not more than **K** then we can certainly achieve the optimal solution. Note : This dp solution can be made more state verbose by storing the brute forced optimal substructure into their respective states in dp[i][j] but I prefer it this way.
Python Code

```python N = int(input()) K = int(input()) A = [0] + list(map(int, input().split())) # Convert A[i] = A[i] - i for i in range(1, N+1): A[i] = A[i] - i # store sorted A in B to stay working # with best possible element already B = [0] + sorted(A[1:]) # dp array dp = [0 for x in range(N+1)] # unreachable state dp[0] = float('inf') for i in range(1, N+1): for j in range(1, N+1): dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j])) # dp[N] represent the ans print("YES "+str(dp[N]) if dp[N] <= K else "NO") ```

C++ Code

```cpp #include #include #include signed main() { long long N, K; std::cin >> N >> K; std::vector A(N+1, 0ll); for (long long i = 1ll; i <= N; i++) { std::cin >> A.at(i); A.at(i) -= i; } // sorted version of A std::vector B{A}; std::sort(B.begin() + 1ll, B.end()); // dp array std::vector dp(N+1, 0ll); dp.at(0) = (long long) 1e9; for (long long i = 1ll; i <= N; i++) { for (long long j = 1ll; j <= N; j++) { dp.at(j) = std::min(dp.at(j-1), dp.at(j) + llabs(A.at(i) - B.at(j))); } } if (dp.at(N) <= K) { std::cout << "YES " << dp.at(N); } else { std::cout << "NO"; } return 0; } ```

Time Complexity : O(N2) Space Complexity : O (N) ================================================ FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.cpp ================================================ #include using namespace std; signed main() { long long N, K; cin >> N >> K; vector A(N+1, 0ll); for (long long i = 1ll; i <= N; i++) { cin >> A.at(i); A.at(i) -= i; } // sorted version of A vector B{A}; sort(B.begin() + 1ll, B.end()); // dp array vector dp(N+1, 0ll); dp.at(0) = (long long) 1e9; for (long long i = 1ll; i <= N; i++) { for (long long j = 1ll; j <= N; j++) { dp.at(j) = min(dp.at(j-1), dp.at(j) + llabs(A.at(i) - B.at(j))); } } if (dp.at(N) <= K) { cout << "YES " << dp.at(N); } else { cout << "NO"; } return 0; } ================================================ FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.py ================================================ N = int(input()) K = int(input()) A = [0] + list(map(int, input().split())) # Convert A[i] = A[i] - i for i in range(1, N+1): A[i] = A[i] - i # store sorted A in B to stay working # with best possible element already B = [0] + sorted(A[1:]) # dp array dp = [0 for x in range(N+1)] # unreachable state dp[0] = float('inf') for i in range(1, N+1): for j in range(1, N+1): dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j])) # dp[N] represent the ans print("YES "+str(dp[N]) if dp[N] <= K else "NO") ================================================ FILE: 02-Codes/Editorials/Random/TransposeColorsWork.cpp ================================================ // J A I S H R E E R A M // #include #pragma GCC optimize "trapv" // #pragma GCC optimize ("Ofast") // // #pragma GCC target ("fpmath=sse,sse2") // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") // #pragma GCC optimize ("-ffloat-store") using namespace std; typedef long long int lld; typedef unsigned long long int llu; #define forn(I7, E4) for(lld I7=0ll; I7 < E4; (I7)+=1ll) #define forn1(I7, E4) for(lld I7=1ll; I7 < E4+1; (I7)+=1ll) #define len(v) ((int)((v).size())) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define f1 first #define s2 second template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << "\n"; } template void dbg_out(Head H, Tail... T) { cout << H << ", "; dbg_out(T...);} #define _____error_____(...) cout << #__VA_ARGS__ << " : ", dbg_out(__VA_ARGS__) const lld d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const lld d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; const long double EPS = 1e-6; lld TempVar, mod, MOD; /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ void solveEachTest(int _TestCase) { // cout << "Case #" << _TestCase << ": "; vectormoves; while(cin >> TempVar) { moves.push_back((int)TempVar); } int n = (int)sqrt(moves.back()); vector> matr(n+1, vector(n, '-')); forn(i, n) { forn(j, n) { matr[i][j] = char('A' + i); } } matr[n][0] = '.'; // for (auto row : matr) { // cout << row << "\n"; // } cout << "\n"; int sz = (int)moves.size(); int tempX = n, tempY = 0; forn(i, sz-1) { int posX = moves[i] / n, posY = moves[i] % n; swap(matr[posX][posY], matr[tempX][tempY]); tempX = posX, tempY = posY; // for (auto row : matr) { // cout << row << "\n"; // } cout << "\n"; } bool ok = true; forn(i, n) { set cnt; forn(j, n) { cnt.insert(matr[i][j]); } ok &= ((int)cnt.size() == n); } cout << "Checker Verdict:\n"; cout << (ok ? "Accepted" : "Wrong Answer") << "\n"; cout << "Moves : " << moves.size(); return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); // cout.precision(10); cout << fixed; #ifdef LUCTIVUD // const auto start_time = std::chrono::high_resolution_clock::now(); freopen("/home/luctivud/CPPractice/Zinput.txt", "r", stdin); freopen("/home/luctivud/CPPractice/Zoutput.txt", "w", stdout); #endif MOD = mod = lld(1e9) + 7ll; lld _T0T4 = 1; // cin >> _T0T4; for (int _TestCase = 1; _TestCase <= _T0T4; _TestCase++) { solveEachTest(_TestCase); cout << "\n"; } #ifdef LUCTIVUD // auto end_time = std::chrono::high_resolution_clock::now(); // std::chrono::duration diff = end_time - start_time; // cerr << "Finished in : " << diff.count() << "\n"; #endif return 0; } /* ~~ Author : Udit "luctivud" Gupta linkedin : https://www.linkedin.com/in/udit-gupta-1b7863135/ */ ================================================ FILE: 02-Codes/README.md ================================================

Containing codes of some problems

Check the subfolders for contents, it has some snippets and editorials

================================================ FILE: 02-Codes/Snippets/Raw/166_e_MatMul_w_Ashishgup.cpp ================================================ // J A I S H R E E R A M // #include #pragma GCC optimize "trapv" // #pragma GCC optimize ("Ofast") // // #pragma GCC target ("fpmath=sse,sse2") // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") // #pragma GCC optimize ("-ffloat-store") using namespace std; typedef long long int lld; typedef unsigned long long int llu; #define forn(I7, E4) for(lld I7=0ll; I7 < E4; (I7)+=1ll) #define forn1(I7, E4) for(lld I7=1ll; I7 < E4+1; (I7)+=1ll) #define len(v) ((int)((v).size())) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define f1 first #define s2 second template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << "\n"; } template void dbg_out(Head H, Tail... T) { cout << H << ", "; dbg_out(T...);} #define _____error_____(...) cout << #__VA_ARGS__ << " : ", dbg_out(__VA_ARGS__) const lld d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const lld d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; const long double EPS = 1e-6; lld TempVar, mod, MOD; /* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */ // matrix exponentiation snippet:: // // courtesy Ashishgup3 via Github lld add(lld a, lld b) { lld res = a + b; if(res >= MOD) return res - MOD; return res; } lld mult(lld a, lld b) { long long res = a; res *= b; if(res >= MOD) return res % MOD; return res; } const lld SZ = 2; // size of MaGiC struct matrix { lld MaGiC[SZ][SZ]; void reset() { memset(MaGiC, 0, sizeof(MaGiC)); } void makeiden() { reset(); for(lld i=0;i>= 1; } return res; } // // GUIDE : // // matrix m; // m.makeiden(); // // m.MaGiC[0][0] = 0, m.MaGiC[0][1] = 1; // m.MaGiC[1][0] = 3, m.MaGiC[1][1] = 2; // // m = power(m, n); // // cout << m.MaGiC[0][0]; void solveEachTest(int _TestCase) { // cout << "Case #" << _TestCase << ": "; lld n; cin >> n; matrix m; m.makeiden(); m.MaGiC[0][0] = 0, m.MaGiC[0][1] = 1; m.MaGiC[1][0] = 3, m.MaGiC[1][1] = 2; m = power(m, n); cout << m.MaGiC[0][0]; return; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); // cout.precision(10); cout << fixed; #ifdef LUCTIVUD // const auto start_time = std::chrono::high_resolution_clock::now(); freopen("/home/luctivud/CPPractice/Zinput.txt", "r", stdin); freopen("/home/luctivud/CPPractice/Zoutput.txt", "w", stdout); #endif MOD = mod = lld(1e9) + 7ll; lld _T0T4 = 1; // cin >> _T0T4; for (int _TestCase = 1; _TestCase <= _T0T4; _TestCase++) { solveEachTest(_TestCase); cout << "\n"; } #ifdef LUCTIVUD // auto end_time = std::chrono::high_resolution_clock::now(); // std::chrono::duration diff = end_time - start_time; // cerr << "Finished in : " << diff.count() << "\n"; #endif return 0; } /* ~~ Author : Udit "luctivud" Gupta linkedin : https://www.linkedin.com/in/udit-gupta-1b7863135/ */ ================================================ FILE: 02-Codes/Snippets/Sublime/FastReadWrite.sublime-snippet ================================================ 57) && c != '-'); c = gc()); if (c == '-') {neg = 1; c = gc();} for (; c > 47 && c < 58; c = gc()) {x = (x << 1) + (x << 3) + c - 48;} if (neg) x = -x; } void scanLong(lld &x) { register lld c = gc(); x = 0; bool neg = 0; for (; ((c < 48 || c > 57) && c != '-'); c = gc()); if (c == '-') {neg = 1; c = gc();} for (; c > 47 && c < 58; c = gc()) {x = (x << 1) + (x << 3) + c - 48;} if (neg) x = -x; } #define pc(x) putchar_unlocked(x); inline void writeInt (int n) { int N = n, rev, count = 0; rev = N; if (N == 0) { pc('0'); pc('\n'); return ;} while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s rev = 0; while (N != 0) { rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;} //store reverse of N in rev while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;} while (count--) pc('0'); pc ('\n'); } inline void writeLong (lld n) { lld N = n, rev, count = 0; rev = N; if (N == 0) { pc('0'); pc('\n'); return ;} while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s rev = 0; while (N != 0) { rev = (rev << 3) + (rev << 1) + N % 10; N /= 10;} //store reverse of N in rev while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;} while (count--) pc('0'); pc ('\n'); } ]]> snip-read-write-fast FastIo source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/addundirectededge.sublime-snippet ================================================ adj[]) { adj[a].push_back(b); adj[b].push_back(a); return; } ]]> snip-add-undirected-edge Add Undirected Edge source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/basic-template.sublime-snippet ================================================ #pragma GCC optimize "trapv" using namespace std; typedef long long int lld; signed main() { // Input - Output and optimization ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; #ifdef LUCTIVUD freopen("/home/luctivud/CPPractice/Zinput.txt", "r", stdin); freopen("/home/luctivud/CPPractice/Zoutput.txt", "w", stdout); #endif $0 return 0; } ]]> snip-basic-template Basic Template for c++ source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/check execution time.sublime-snippet ================================================ (S34p - S34t); cout << "Time Elapsed: " << D34n.count() / (long double) 1e6 << " seconds" << endl; ]]> snip-debug CP Template source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/checkvalid.sublime-snippet ================================================ = 0 and i < n; } ]]> snip-checkvalid source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/cmp-priority.sublime-snippet ================================================ > class ${1:cmp} { public: bool operator() (${2:const pair } &a, ${2:const pair } &b) { return ${3:a.s2 > b.s2}; } }; ]]> snip-cmp-pq cmp for priority queue source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/common-completions.sublime-completions ================================================ { "scope": "source.c++, meta.block.c++, meta.function.c++", "completions": [ {"trigger": "vectorlld", "contents": "vector ${1:arr}"}, {"trigger": "vectorpalld", "contents": "vector> ${1:arr}"}, {"trigger": "vectorvelldp2", "contents": "vector> ${1:dp}(${2:n}, vector(${3:m}, ${4:-1})) $0"}, {"trigger": "vectorstr", "contents": "vector ${1:arr}"}, {"trigger": "vectorcha", "contents": "vector ${1:arr}"}, {"trigger": "vectorboo", "contents": "vector ${1:visited}"}, {"trigger": "setlld", "contents": "set ${1:visited}"}, {"trigger": "setpall", "contents": "set> ${1:arr}"}, {"trigger": "setstr", "contents": "set ${1:arr}"}, {"trigger": "setchar", "contents": "set ${1:arr}"}, {"trigger": "setbool", "contents": "set ${1:arr}"}, {"trigger": "maplld", "contents": "map ${1:arr}"}, {"trigger": "mapstr", "contents": "map ${1:arr}"}, {"trigger": "front", "contents": "front()"}, {"trigger": "first", "contents": "first"}, {"trigger": "second", "contents": "second"}, {"trigger": "make_pair", "contents": "make_pair(${1:fir}, ${2:sec})"}, {"trigger": "make_tuple", "contents": "make_tuple"}, {"trigger": "push_back", "contents": "push_back(${1:el})"}, {"trigger": "max_element", "contents": "max_element(all(${1:arr}))"}, {"trigger": "min_element", "contents": "min_element(all(${1:arr}))"}, {"trigger": "accumulate", "contents": "accumulate(all(${1:arr}), ${2:0ll})"}, {"trigger": "sortarr", "contents": "sort(${1:r}all(${2:arr}))"}, {"trigger": "emplace_back", "contents": "emplace_back()"}, {"trigger": "insert", "contents": "insert()"}, {"trigger": "push", "contents": "push()"}, {"trigger": "for4", "contents": "for4(${1: i}, ${2:0ll}, ${3:n}, ${4:1ll}) {${0}}"}, {"trigger": "EACH", "contents": "EACH(${1:it}, ${2:arr}) {${0}}"}, {"trigger": "find", "contents": "find(all(${1:arr}), ${2:val}) != ${1:arr}.end()"}, {"trigger": "lower_bound", "contents": "lower_bound(all(${1:arr}), ${2:val})"}, {"trigger": "upper_bound", "contents": "upper_bound(all(${1:arr}), ${2:val})"}, {"trigger": "reverse", "contents": "reverse(all(${1:arr}))"}, {"trigger": "len", "contents": "len(${1:arr})"}, // {"trigger": "debspace", "contents": "debspace(${1})"}, // {"trigger": "debline", "contents": "debline(${1})"}, {"trigger": "error", "contents": "_____error_____(${1})"}, {"trigger": "cin", "contents": "cin >> "}, {"trigger": "cout", "contents": "cout << "}, {"trigger": "d4dir", "contents": "const lld d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};"}, {"trigger": "d8dir", "contents": "const lld d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};"}, // {"trigger": "read", "contents": "Read(${1})"}, // {"trigger": "println", "contents": "Println(${1})"}, // {"trigger": "NOYES", "contents": "Println(\"NO\\0YES\" + 3 * (${1:condition}));"}, {"trigger": "transform", "contents": "transform(all(${1:str}), ${1:str}.begin(), ::to${2:low}er);"}, ] } // "vector ${1:arr}", // "vector> ${1:arr}", // "vector> ${1:dp}(${2:n}, vector(${3:m}, ${4:-1})) $0", // "vector ${1:arr}", // "vector ${1:arr}", // "vector ${1:visited}", // "set ${1:visited}", // "set> ${1:arr}", // "set ${1:arr}", // "set ${1:arr}", // "set ${1:arr}", // "map ${1:arr}", // "map ${1:arr}", // "map ${1:arr}", // "front()", // "first", // "second", // "make_pair(${1:fir}, ${2:sec})", // "make_tuple", // "push_back(${1:el})", // "max_element(all(${1:arr}))", // "min_element(all(${1:arr}))", // "accumulate(all(${1:arr}), ${2:0ll})", // "emplace_back()", // "insert()", // "push()", // "input(${0})", // "for4(${1: i}, ${2:0ll}, ${3:n}, ${4:1ll}) {${0}}", // "EACH(${1:it}, ${2:arr}) {${0}}", // "find(all(${1:arr}), ${2:val}) != ${1:arr}.end()", // "lower_bound(all(${1:arr}), ${2:val})", // "upper_bound(all(${1:arr}), ${2:val})", // "reverse(all(${1:arr}))", // "len(${1:arr})", // "debspace(${1})", // "debline(${1})", // "error(${1})", // "read(${1})", // "println(${1})", ================================================ FILE: 02-Codes/Snippets/Sublime/dsu-array.sublime-snippet ================================================ struct DSU { lld par3t[SZ], ran4k[SZ]; DSU() { forn(i,SZ) par3t[i] = i, ran4k[i] = 1; } lld find_repr(lld x) { // path compression if (par3t[x] != x) par3t[x] = find_repr(par3t[x]); return par3t[x]; } bool Union(lld x, lld y) { // union-by-ran4k x = find_repr(x), y = find_repr(y); if (x == y) return 0; if (ran4k[x] < ran4k[y]) swap(x,y); ran4k[x] += ran4k[y], par3t[y] = x; return 1; } }; DSU<100001> D; ]]> snip-dsu-array dsu using path compression source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/dsu.sublime-snippet ================================================ &par3t, vector &ran4k) { iota(all(par3t), 0ll); } lld find_repr(lld x, vector &par3t, vector &ran4k) { if (x != par3t[x]) par3t[x] = find_repr(par3t[x], par3t, ran4k); return par3t[x]; } void Union(lld x, lld y, vector &par3t, vector &ran4k) { x = find_repr(x, par3t, ran4k); y = find_repr(y, par3t, ran4k); if (x == y) return; if (ran4k[x] < ran4k[y]) { par3t[x] = y; } else if (ran4k[x] > ran4k[y]) { par3t[y] = x; } else { par3t[y] = x; ran4k[x] = ran4k[x] + 1; } return; } // create par3t and ran4k at the place. vector par3t(n, 0); vector ran4k(n, 0); makeSet(n, par3t, ran4k); ]]> snip-dsu dsu using path compression source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/errorWatch.sublime-snippet ================================================ _it(_ss); huehue(_it, args); cout << "\n";} void huehue(istream_iterator it) {} template void huehue(istream_iterator it, T a, Args... args) { cout << *it << " = " << a << ", "; huehue(++it, args...); } ]]> snip-error-watch Error Watch source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/eulerTotientFunc.sublime-snippet ================================================ 1) result -= result / n0n; return result; } vector phiVal; // precompute_phiVal complexity O(N.log(log(N))) void precompute_phiVal(lld n0n) { phiVal.resize(n0n+1); phiVal[0] = 0; phiVal[1] = 1; for (lld i = 2; i <= n0n; i++) phiVal[i] = i; for (lld i = 2; i <= n0n; i++) { if (phiVal[i] == i) { for (lld j = i; j <= n0n; j += i) phiVal[j] -= phiVal[j] / i; } } } // precompute_phiVal(n); ]]> snip-totient-euler-phi Euler totient Phi source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/leetcode-solution-class.sublime-snippet ================================================ #pragma GCC optimize "trapv" using namespace std; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // Solution class to work with class Solution { }; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(10); Solution Obj; // read input vars here and pass it to solve. int ans = Obj.solve(); cout << ans; return 0; } // Random Thought : null ]]> snip-leetcode-solution Solution class implementation source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/manipulated-sieve-of-eratosthene.sublime-snippet ================================================ isPrime(MAXN , true); // checkIfPrime vectorprime_numbers; // List of prime numbers vectorsmallest_prime_factor(MAXN); // smallest_prime_factor of a number void manipulated_seive() { isPrime[0] = isPrime[1] = false ; prime_numbers.push_back(2); smallest_prime_factor[2] = 2ll; for (long long int i=4; i < MAXN ; i+=2) { isPrime[i] = false; smallest_prime_factor[i] = 2ll; } for (long long int i = 3; i < MAXN ; i+=2) { if (isPrime[i]) { prime_numbers.push_back(i); smallest_prime_factor[i] = i; } for (long long int j = 0; j < (int)prime_numbers.size() && i * prime_numbers[j] < MAXN && prime_numbers[j] <= smallest_prime_factor[i]; j++) { isPrime[i * prime_numbers[j]] = false; smallest_prime_factor[i * prime_numbers[j]] = prime_numbers[j] ; } } } /* This should be called inside main. */ manipulated_seive(); ]]> snip-fast-sieve sieve-manipulated source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/matrix-expo.sublime-snippet ================================================ = MOD) return res - MOD; return res; } lld mult(lld a, lld b) { long long res = a; res *= b; if(res >= MOD) return res % MOD; return res; } const lld SZ = 2; // size of MaGiC struct matrix { lld MaGiC[SZ][SZ]; void reset() { memset(MaGiC, 0, sizeof(MaGiC)); } void makeiden() { reset(); for(lld i=0;i>= 1; } return res; } // // GUIDE : // // matrix m; // m.makeiden(); // // m.MaGiC[0][0] = 0, m.MaGiC[0][1] = 1; // m.MaGiC[1][0] = 3, m.MaGiC[1][1] = 2; // // m = power(m, n); // // cout << m.MaGiC[0][0]; ]]> snip-matrix-expo Matrix Expo on recurrence formula source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/max-biparite-matching.sublime-snippet ================================================ > graph, lld u, vector &visited, vector &matchR) { for (lld v = 0; v < n; v++) { if (graph[u][v] and !visited[v]) { visited[v] = true; if (matchR[v] < 0 || bpm(graph, matchR[v], visited, matchR)) { matchR[v] = u; return true; } } } return false; } lld maxBPM(vector> graph, vector &matchR) { lld result = 0; for (lld u = 0; u < m; u++) { vector visited(n, 0); if (bpm(graph, u, visited, matchR)) result++; } return result; } // This should be in main // 0.indexed n = 6, m = 6; // for i -> m then for j -> n vector> graph(m, vector(n, false)); vector matchR(n, -1); maxBPM(graph, matchR); ]]> snip-bipartite-matching Max B M source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/modop.sublime-snippet ================================================ >= 1; base = (base * base) % mod; } return res; } lld minv(lld base) { return mpow(base, mod - 2); } lld mdiv(lld a, lld b) { return mmul(a, minv(b)); } } lld nck(lld n, lld k) { if (n < k) return 0; lld r = 1; for (lld i = n; i > n - k; i--) { r = (r * i) % mod; } for (lld i = 1; i <= k; i++) { r = (r * minv(i)) % mod; } return r; } ]]> snip-namespace-modop modops and ncr on demand source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/myReadTemplate.sublime-snippet ================================================ T Read(T& x) { cin >> x; return x; } template void Print(T a) { cout << a; } template void Println(T a) { cout << a << "\n"; } template void Read(vector &arr) { EACH(i, arr) cin >> (i); } template void Print(vector arr) { EACH(i, arr) {cout << i << " ";} } template void Println(vector arr) { EACH(i, arr) {cout << i << " ";} cout << "\n"; } template void Read(vector> &arr) { EACH(i, arr) Read(i); } template void Print(vector> arr) { EACH(i, arr) Println(i); } template void Println(vector> arr) { EACH(i, arr) Println(i); } template void Read(vector &arr, Args &... args) { Read(arr); Read(args...);} template void Read(vector> &arr, Args &... args) { Read(arr); Read(args...);} template void Read(T &a, Args &... args) { cin >> (a); Read(args...); } template void Print(vector &arr, Args &... args) { Print(arr); Print(args...);} template void Print(T a, Args... args) { cout << a << " "; Print(args...); }; template void Println(vector &arr, Args &... args) { Print(arr); Println(args...);} template void Println(T a, Args... args) { cout << a << " "; Println(args...); }; ]]> snip-read-template Read-Print-Template source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/ncr-on-demand.sublime-snippet ================================================ snip-ncr-binomial NCR on demand source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/pbds.sublime-snippet ================================================ #include using namespace __gnu_pbds; template using PBSET = tree, rb_tree_tag, tree_order_statistics_node_update>; /* .insert(el) - set hai! .find_by_order(3) - returns an iterator to the k-th largest element (counting from zero) .order_of_key(6) - the number of items in a set that are strictly smaller than our item */ ]]> snip-pbds pbds source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/power-expo.sublime-snippet ================================================ 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1; x = (x * x) % MOD; } return res; } ]]> snip-power power exponentiation source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/sieve-of-eratosthene.sublime-snippet ================================================ isPrime(MAXN, true); // Temp vector for sieve result vector prime_numbers; // vector of primes void sieve() { isPrime[0] = isPrime[1] = false; prime_numbers.push_back(2); for (lld i=4; i< MAXN; i+=2) isPrime[i] = false; for (lld i = 3; i < MAXN; i+=2) { if (isPrime[i]) { prime_numbers.push_back(i); // remove if not necessary for (lld j = 2 * i; j < MAXN; j += i) { isPrime[j] = false; } } } } /* This should be called inside main. */ sieve(); // function call in main ]]> snip-sieve sieve source.c++ ================================================ FILE: 02-Codes/Snippets/Sublime/topcoder-template.sublime-snippet ================================================ using namespace std; typedef long long int lld; typedef unsigned long long int llu; #define forn(I7, E4) for(lld I7=0ll; I7 < E4; (I7)+=1ll) #define forn1(I7, E4) for(lld I7=1ll; I7 < E4+1; (I7)+=1ll) #define len(v) ((int)((v).size())) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define f1 first #define s2 second template ostream& operator<<(ostream &os, const pair &p) { return os << '(' << p.first << ", " << p.second << ')'; } template < typename T_container, typename T = typename enable_if < !is_same::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cout << "\n"; } template void dbg_out(Head H, Tail... T) { cout << H << ", "; dbg_out(T...);} #define _____error_____(...) cout << #__VA_ARGS__ << " : ", dbg_out(__VA_ARGS__) const lld d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const lld d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; const long double EPS = 1e-6; lld TempVar, mod, MOD; class ${1:} { public: ${0:} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* signed main() { ios_base::sync_with_stdio(false); cin.tie(0); // cout.precision(10); cout << fixed; #ifdef LUCTIVUD // const auto start_time = std::chrono::high_resolution_clock::now(); freopen("/home/luctivud/CPPractice/Zinput.txt", "r", stdin); freopen("/home/luctivud/CPPractice/Zoutput.txt", "w", stdout); #endif ${1:} obj; return 0; } */ ]]> snip-topcoder-template Topcoder class template source.c++ ================================================ FILE: 02-Codes/Snippets/mydebug.h ================================================ // C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2021 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . /** @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers // C #ifndef _GLIBCXX_NO_ASSERT #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if __cplusplus >= 201103L #include #include #include #include #include #include #include #include #endif // C++ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // for prettyprint #if __cplusplus >= 201103L #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #endif #if __cplusplus >= 201402L #include #endif #if __cplusplus >= 201703L #include #include // #include #include #include #include #include #include #endif #if __cplusplus > 201703L #include #include #include #include #if __cpp_impl_coroutine # include #endif #include #include #include #include #include #include #include #include #include #endif /* stdc++.h end */ using namespace std; template ostream &operator<<(ostream &os, const pair &p) { return os << '{' << p.first << ", " << p.second << '}'; } template ()))>, class = enable_if_t::value>> ostream &operator<<(ostream &os, const T &c) { os << '['; for (auto it = c.begin(); it != c.end(); ++it) os << &", "[2 * (it == c.begin())] << *it; return os << ']'; } //support up to 5 args #define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N #define _FE_0(_CALL, ...) #define _FE_1(_CALL, x) _CALL(x) #define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__) #define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__) #define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__) #define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__) #define FOR_EACH_MACRO(MACRO, ...) \ _NTH_ARG(dummy, ##__VA_ARGS__, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1, _FE_0) \ (MACRO, ##__VA_ARGS__) //Change output format here #define out(x) #x " = " << x << "; " #define _____error_____(...) \ cerr << "(Line " << __LINE__ << "): " FOR_EACH_MACRO(out, __VA_ARGS__) << "\n" /* _______ _______ ______ ___ __ _ _______ | || || _ | | | | | | || | | _ || _ || | || | | | |_| ||_ _| | |_| || |_| || |_||_ | | | | | | | ___|| ___|| __ || | | _ | | | | | | | | | | || | | | | | | | |___| |___| |___| |_||___| |_| |__| |___| Pretty Printer for Modern C++ https://github.com/p-ranav/pprint Licensed under the MIT License . SPDX-License-Identifier: MIT Copyright (c) 2019 Pranav Srinivas Kumar . Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma once // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include // #include #ifdef __GNUG__ // #include // #include // #include #endif // Check if a type is stream writable, i.e., std::cout << foo; template struct is_to_stream_writable: std::false_type {}; template struct is_to_stream_writable()<() ) >> : std::true_type {}; // Printing std::tuple // The indices trick: http://loungecpp.wikidot.com/tips-and-tricks:indices namespace pprint { template struct seq{}; template struct gen_seq : gen_seq{}; template struct gen_seq<0, Is...> : seq{}; template inline T to_string(T value) { return value; } inline std::string to_string(char value) { return "'" + std::string(1, value) + "'"; } inline std::string to_string(const char * value) { return "\"" + std::string(value) + "\""; } inline std::string to_string(const std::string& value) { return "\"" + value + "\""; } template void print_tuple(std::basic_ostream& os, Tuple const& t, seq){ using swallow = int[]; (void)swallow{0, (void(os << (Is == 0? "" : ", ") << to_string(std::get(t))), 0)...}; } } template auto operator<<(std::basic_ostream& os, std::tuple const& t) -> std::basic_ostream& { os << "("; pprint::print_tuple(os, t, pprint::gen_seq()); return os << ")"; } // Enum value must be greater or equals than MAGIC_ENUM_RANGE_MIN. By default MAGIC_ENUM_RANGE_MIN = -128. // If need another min range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MIN. #if !defined(MAGIC_ENUM_RANGE_MIN) # define MAGIC_ENUM_RANGE_MIN -128 #endif // Enum value must be less or equals than MAGIC_ENUM_RANGE_MAX. By default MAGIC_ENUM_RANGE_MAX = 128. // If need another max range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MAX. #if !defined(MAGIC_ENUM_RANGE_MAX) # define MAGIC_ENUM_RANGE_MAX 128 #endif namespace magic_enum { // Enum value must be in range [-MAGIC_ENUM_RANGE_MAX, MAGIC_ENUM_RANGE_MIN]. By default MAGIC_ENUM_RANGE_MIN = -128, MAGIC_ENUM_RANGE_MAX = 128. // If need another range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MAX and MAGIC_ENUM_RANGE_MIN. // If need another range for specific enum type, add specialization enum_range for necessary enum type. template struct enum_range final { static_assert(std::is_enum_v, "magic_enum::enum_range requires enum type."); static constexpr int min = std::is_signed_v> ? MAGIC_ENUM_RANGE_MIN : 0; static constexpr int max = MAGIC_ENUM_RANGE_MAX; }; static_assert(MAGIC_ENUM_RANGE_MAX > 0, "MAGIC_ENUM_RANGE_MAX must be greater than 0."); static_assert(MAGIC_ENUM_RANGE_MAX < std::numeric_limits::max(), "MAGIC_ENUM_RANGE_MAX must be less than INT_MAX."); static_assert(MAGIC_ENUM_RANGE_MIN <= 0, "MAGIC_ENUM_RANGE_MIN must be less or equals than 0."); static_assert(MAGIC_ENUM_RANGE_MIN > std::numeric_limits::min(), "MAGIC_ENUM_RANGE_MIN must be greater than INT_MIN."); namespace detail { template > [[nodiscard]] constexpr int min_impl() { static_assert(std::is_enum_v, "magic_enum::detail::min_impl requires enum type."); constexpr int min = enum_range::min > (std::numeric_limits::min)() ? enum_range::min : (std::numeric_limits::min)(); return min; } template > [[nodiscard]] constexpr decltype(auto) range_impl() { static_assert(std::is_enum_v, "magic_enum::detail::range_impl requires enum type."); static_assert(enum_range::max > enum_range::min, "magic_enum::enum_range requires max > min."); constexpr int max = enum_range::max < (std::numeric_limits::max)() ? enum_range::max : (std::numeric_limits::max)(); constexpr auto range = std::make_integer_sequence() + 1>{}; return range; } [[nodiscard]] constexpr bool is_name_char(char c, bool front) noexcept { return (!front && c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; } template [[nodiscard]] constexpr std::string_view name_impl() noexcept { static_assert(std::is_enum_v, "magic_enum::detail::name_impl requires enum type."); #if defined(__clang__) std::string_view name{__PRETTY_FUNCTION__}; constexpr auto suffix = sizeof("]") - 1; #elif defined(__GNUC__) && __GNUC__ >= 9 std::string_view name{__PRETTY_FUNCTION__}; constexpr auto suffix = sizeof("; std::string_view = std::basic_string_view]") - 1; #elif defined(_MSC_VER) std::string_view name{__FUNCSIG__}; constexpr auto suffix = sizeof(">(void) noexcept") - 1; #else return {}; // Unsupported compiler. #endif #if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER) name.remove_suffix(suffix); for (std::size_t i = name.size(); i > 0; --i) { if (!is_name_char(name[i - 1], false)) { name.remove_prefix(i); break; } } if (name.length() > 0 && is_name_char(name.front(), true)) { return name; } else { return {}; // Value does not have name. } #endif } template [[nodiscard]] constexpr decltype(auto) strings_impl(std::integer_sequence) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::strings_impl requires enum type."); constexpr std::array names{{name_impl(I + min_impl())>()...}}; return names; } template [[nodiscard]] constexpr std::string_view name_impl(int value) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::name_impl requires enum type."); constexpr auto names = strings_impl(range_impl()); const int i = value - min_impl(); if (i >= 0 && static_cast(i) < names.size()) { return names[i]; } else { return {}; // Value out of range. } } template [[nodiscard]] constexpr decltype(auto) values_impl(std::integer_sequence) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::values_impl requires enum type."); constexpr int n = sizeof...(I); constexpr std::array valid{{!name_impl(I + min_impl())>().empty()...}}; constexpr int num_valid = ((valid[I] ? 1 : 0) + ...); std::array enums{}; for (int i = 0, v = 0; i < n && v < num_valid; ++i) { if (valid[i]) { enums[v++] = static_cast(i + min_impl()); } } return enums; } template [[nodiscard]] constexpr decltype(auto) names_impl(std::integer_sequence) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::names_impl requires enum type."); constexpr auto enums = values_impl(range_impl()); constexpr std::array names{{name_impl()...}}; return names; } template [[nodiscard]] constexpr std::optional enum_cast_impl(std::string_view value) noexcept { static_assert(std::is_enum_v, "magic_enum::detail::enum_cast_impl requires enum type."); constexpr auto values = values_impl(range_impl()); constexpr auto count = values.size(); constexpr auto names = names_impl(std::make_index_sequence{}); for (std::size_t i = 0; i < count; ++i) { if (names[i] == value) { return values[i]; } } return std::nullopt; // Invalid value or out of range. } template using enable_if_enum_t = typename std::enable_if>::type; template> struct is_scoped_enum_impl : std::false_type {}; template struct is_scoped_enum_impl : std::bool_constant>> {}; template> struct is_unscoped_enum_impl : std::false_type {}; template struct is_unscoped_enum_impl : std::bool_constant>> {}; } // namespace magic_enum::detail // Checks whether T is an Unscoped enumeration type. // Provides the member constant value which is equal to true, if T is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration) type. // Otherwise, value is equal to false. template struct is_unscoped_enum : detail::is_unscoped_enum_impl {}; template inline constexpr bool is_unscoped_enum_v = is_unscoped_enum::value; // Checks whether T is an Scoped enumeration type. // Provides the member constant value which is equal to true, if T is an [Scoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations) type. // Otherwise, value is equal to false. template struct is_scoped_enum : detail::is_scoped_enum_impl {}; template inline constexpr bool is_scoped_enum_v = is_scoped_enum::value; // Obtains enum value from enum string name. template > [[nodiscard]] constexpr std::optional enum_cast(std::string_view value) noexcept { static_assert(std::is_enum_v, "magic_enum::enum_cast requires enum type."); return detail::enum_cast_impl(value); } // Obtains enum value from integer value. template > [[nodiscard]] constexpr std::optional enum_cast(std::underlying_type_t value) noexcept { static_assert(std::is_enum_v, "magic_enum::enum_cast requires enum type."); if (detail::name_impl(static_cast(value)).empty()) { return std::nullopt; // Invalid value or out of range. } else { return static_cast(value); } } // Returns enum value at specified index. // No bounds checking is performed: the behavior is undefined if index >= number of enum values. template> [[nodiscard]] constexpr E enum_value(std::size_t index) { static_assert(std::is_enum_v, "magic_enum::enum_value requires enum type."); constexpr auto values = detail::values_impl(detail::range_impl()); return assert(index < values.size()), values[index]; } // Obtains value enum sequence. template > [[nodiscard]] constexpr decltype(auto) enum_values() noexcept { static_assert(std::is_enum_v, "magic_enum::enum_values requires enum type."); constexpr auto values = detail::values_impl(detail::range_impl()); return values; } // Returns number of enum values. template > [[nodiscard]] constexpr std::size_t enum_count() noexcept { static_assert(std::is_enum_v, "magic_enum::enum_count requires enum type."); constexpr auto count = detail::values_impl(detail::range_impl()).size(); return count; } // Obtains string enum name from enum value. template , typename = detail::enable_if_enum_t> [[nodiscard]] constexpr std::optional enum_name(E value) noexcept { static_assert(std::is_enum_v, "magic_enum::enum_name requires enum type."); const auto name = detail::name_impl(static_cast(value)); if (name.empty()) { return std::nullopt; // Invalid value or out of range. } else { return name; } } // Obtains string enum name sequence. template > [[nodiscard]] constexpr decltype(auto) enum_names() noexcept { static_assert(std::is_enum_v, "magic_enum::enum_names requires enum type."); constexpr auto count = detail::values_impl(detail::range_impl()).size(); constexpr auto names = detail::names_impl(std::make_index_sequence{}); return names; } namespace ops { template , typename = detail::enable_if_enum_t> std::ostream& operator<<(std::ostream& os, E value) { static_assert(std::is_enum_v, "magic_enum::ops::operator<< requires enum type."); const auto name = detail::name_impl(static_cast(value)); if (!name.empty()) { os << name; } return os; } template > std::ostream& operator<<(std::ostream& os, std::optional value) { static_assert(std::is_enum_v, "magic_enum::ops::operator<< requires enum type."); if (value.has_value()) { const auto name = detail::name_impl(static_cast(value.value())); if (!name.empty()) { os << name; } } return os; } } // namespace magic_enum::ops } // namespace magic_enum namespace pprint { // Some utility structs to check template specialization template class Ref> struct is_specialization : std::false_type {}; template class Ref, typename... Args> struct is_specialization, Ref> : std::true_type {}; template using to_void = void; template struct is_container : std::false_type {}; template struct is_container().begin()), decltype(std::declval().end()), typename T::value_type >> : std::true_type // will be enabled for iterable objects {}; class PrettyPrinter { private: std::ostream& stream_; std::string line_terminator_; size_t indent_; bool quotes_; bool compact_; public: PrettyPrinter(std::ostream& stream = std::cout) : stream_(stream), line_terminator_("\n"), indent_(2), quotes_(false), compact_(false) {} PrettyPrinter& line_terminator(const std::string& value) { line_terminator_ = value; return *this; } PrettyPrinter& indent(size_t indent) { indent_ = indent; return *this; } PrettyPrinter& compact(bool value) { compact_ = value; return *this; } PrettyPrinter& quotes(bool value) { quotes_ = value; return *this; } template void print(T value) { print_internal(value, 0, line_terminator_, 0); } template void print(std::initializer_list value) { print_internal(value, 0, line_terminator_, 0); } template void print(T value, Targs... Fargs) { print_internal(value, 0, "", 0); auto current_quotes = quotes_; quotes_ = false; print_internal(" ", 0, "", 0); quotes_ = current_quotes; print(Fargs...); } template void print_inline(T value) { print_internal(value, indent_, "", 0); } template void print_inline(std::initializer_list value) { print_internal(value, indent_, "", 0); } template void print_inline(T value, Targs... Fargs) { print_internal(value, indent_, "", 0); auto current_quotes = quotes_; quotes_ = false; print_internal(" ", 0, "", 0); quotes_ = current_quotes; print_inline(Fargs...); } private: template typename std::enable_if::value == true, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } template typename std::enable_if::value == true, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << "nullptr" << line_terminator; } void print_internal(float value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << 'f' << line_terminator; } void print_internal(double value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } void print_internal(const std::string& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (!quotes_) print_internal_without_quotes(value, indent, line_terminator, level); else stream_ << std::string(indent, ' ') << "\"" << value << "\"" << line_terminator; } void print_internal(const char * value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (!quotes_) print_internal_without_quotes(value, indent, line_terminator, level); else stream_ << std::string(indent, ' ') << "\"" << value << "\"" << line_terminator; } void print_internal(char value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (!quotes_) print_internal_without_quotes(value, indent, line_terminator, level); else stream_ << std::string(indent, ' ') << "'" << value << "'" << line_terminator; } void print_internal_without_quotes(const std::string& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } void print_internal_without_quotes(const char * value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } void print_internal_without_quotes(char value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } void print_internal(bool value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << (value ? "true" : "false") << line_terminator; } template typename std::enable_if::value == true, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (value == nullptr) { return print_internal(nullptr, indent, line_terminator, level); } stream_ << std::string(indent, ' ') << "<" << type(value) << " at " << value << ">" << line_terminator; } std::string demangle(const char* name) { #ifdef __GNUG__ int status = -4; std::unique_ptr res { abi::__cxa_demangle(name, NULL, NULL, &status), std::free }; return (status==0) ? res.get() : name; #else return name; #endif } template std::string type(const T& t) { return demangle(typeid(t).name()); } template typename std::enable_if::value == true, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { auto enum_string = magic_enum::enum_name(value); if (enum_string.has_value()) { stream_ << std::string(indent, ' ') << enum_string.value() << line_terminator; } else { stream_ << std::string(indent, ' ') << static_cast>(value) << line_terminator; } } template typename std::enable_if::value == true && is_to_stream_writable::value == true && std::is_enum::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } template typename std::enable_if::value == true && is_to_stream_writable::value == false && std::is_enum::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false && is_specialization::value == false, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << "" << line_terminator; } template typename std::enable_if::value == true, void>::type print_internal(T value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << "" << line_terminator; } template typename std::enable_if::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { typedef typename Container::value_type T; if (level == 0 && !compact_) { if (value.size() == 0) { print_internal_without_quotes("[", 0, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", 0, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", 0, "\n"); print_internal(value.front(), indent + indent_, "", level + 1); if (value.size() > 1 && is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else if (is_container::value) print_internal_without_quotes(", ", 0, "\n"); for (size_t i = 1; i < value.size() - 1; i++) { print_internal(value[i], indent + indent_, "", level + 1); if (is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else print_internal_without_quotes(", ", 0, "\n"); } if (value.size() > 1) { print_internal(value.back(), indent + indent_, "\n", level + 1); } } if (value.size() == 0) print_internal_without_quotes("]", indent, ""); else if (is_container::value == false) print_internal_without_quotes("]", indent, ""); else print_internal_without_quotes(line_terminator_ + "]", indent, ""); print_internal_without_quotes(line_terminator_, 0, ""); } else { if (value.size() == 0) { print_internal_without_quotes("[", indent, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); if (value.size() > 1) print_internal_without_quotes(", ", 0, ""); for (size_t i = 1; i < value.size() - 1; i++) { print_internal(value[i], 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } if (value.size() > 1) { print_internal(value.back(), 0, "", level + 1); } } print_internal_without_quotes("]", 0, ""); if (level == 0 && compact_) print_internal_without_quotes(line_terminator_, 0, ""); } } template void print_internal(const std::array& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (level == 0 && !compact_) { if (value.size() == 0) { print_internal_without_quotes("[", 0, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", 0, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", 0, "\n"); print_internal(value.front(), indent + indent_, "", level + 1); if (value.size() > 1 && is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else if (is_container::value) print_internal_without_quotes(", ", 0, "\n"); for (size_t i = 1; i < value.size() - 1; i++) { print_internal(value[i], indent + indent_, "", level + 1); if (is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else print_internal_without_quotes(", ", 0, "\n"); } if (value.size() > 1) { print_internal(value.back(), indent + indent_, "\n", level + 1); } } if (value.size() == 0) print_internal_without_quotes("]", indent, ""); else if (is_container::value == false) print_internal_without_quotes("]", indent, ""); else print_internal_without_quotes(line_terminator_ + "]", indent, ""); print_internal_without_quotes(line_terminator_, 0, ""); } else { if (value.size() == 0) { print_internal_without_quotes("[", indent, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); if (value.size() > 1) print_internal_without_quotes(", ", 0, ""); for (size_t i = 1; i < value.size() - 1; i++) { print_internal(value[i], 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } if (value.size() > 1) { print_internal(value.back(), 0, "", level + 1); } } print_internal_without_quotes("]", 0, ""); if (level == 0 && compact_) print_internal_without_quotes(line_terminator_, 0, ""); } } template typename std::enable_if::value || is_specialization::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { typedef typename Container::value_type T; if (level == 0 && !compact_) { if (value.size() == 0) { print_internal_without_quotes("[", 0, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", 0, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", 0, "\n"); print_internal(value.front(), indent + indent_, "", level + 1); if (value.size() > 1 && is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else if (is_container::value) print_internal_without_quotes(", ", 0, "\n"); typename Container::const_iterator iterator; for (iterator = std::next(value.begin()); iterator != std::prev(value.end()); ++iterator) { print_internal(*iterator, indent + indent_, "", level + 1); if (is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else print_internal_without_quotes(", ", 0, "\n"); } if (value.size() > 1) { print_internal(value.back(), indent + indent_, "\n", level + 1); } } if (value.size() == 0) print_internal_without_quotes("]", indent, ""); else if (is_container::value == false) print_internal_without_quotes("]", indent, ""); else print_internal_without_quotes(line_terminator_ + "]", indent, ""); print_internal_without_quotes(line_terminator_, 0, ""); } else { if (value.size() == 0) { print_internal_without_quotes("[", indent, ""); } else if (value.size() == 1) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); } else if (value.size() > 0) { print_internal_without_quotes("[", indent, ""); print_internal(value.front(), 0, "", level + 1); if (value.size() > 1) print_internal_without_quotes(", ", 0, ""); typename Container::const_iterator iterator; for (iterator = std::next(value.begin()); iterator != std::prev(value.end()); ++iterator) { print_internal(*iterator, 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } if (value.size() > 1) { print_internal(value.back(), 0, "", level + 1); } } print_internal_without_quotes("]", 0, ""); if (level == 0 && compact_) print_internal_without_quotes(line_terminator_, 0, ""); } } template typename std::enable_if::value || is_specialization::value || is_specialization::value || is_specialization::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { typedef typename Container::value_type T; if (level == 0 && !compact_) { if (value.size() == 0) { print_internal_without_quotes("{", 0, ""); } else if (value.size() == 1) { print_internal_without_quotes("{", 0, ""); print_internal(*(value.begin()), 0, "", level + 1); } else { print_internal_without_quotes("{", 0, "\n"); print_internal(*(value.begin()), indent + indent_, "", level + 1); if (value.size() > 1 && is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else if (is_container::value) print_internal_without_quotes(", ", 0, "\n"); typename Container::const_iterator iterator; for (iterator = std::next(value.begin()); (iterator != value.end()) && (std::next(iterator) != value.end()); ++iterator) { print_internal(*iterator, indent + indent_, "", level + 1); if (is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else print_internal_without_quotes(", ", 0, "\n"); } if (value.size() > 1) { print_internal(*iterator, indent + indent_, "\n", level + 1); } } if (value.size() == 0) print_internal_without_quotes("}", indent, ""); else if (is_container::value == false) print_internal_without_quotes("}", indent, ""); else print_internal_without_quotes(line_terminator_ + "}", indent, ""); print_internal_without_quotes(line_terminator_, 0, ""); } else { if (value.size() == 0) { print_internal_without_quotes("{", indent, ""); } else if (value.size() == 1) { print_internal_without_quotes("{", indent, ""); print_internal(*(value.begin()), 0, "", level + 1); } else { print_internal_without_quotes("{", indent, ""); print_internal(*(value.begin()), 0, "", level + 1); if (value.size() > 1) print_internal_without_quotes(", ", 0, ""); typename Container::const_iterator iterator; for (iterator = std::next(value.begin()); (iterator != value.end()) && (std::next(iterator) != value.end()); ++iterator) { print_internal(*iterator, 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } if (value.size() > 1) { print_internal(*iterator, 0, "", level + 1); } } print_internal_without_quotes("}", 0, ""); if (level == 0 && compact_) print_internal_without_quotes(line_terminator_, 0, ""); } } template typename std::enable_if::value == true || is_specialization::value == true || is_specialization::value == true || is_specialization::value == true, void>::type print_internal(const T& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { typedef typename T::mapped_type Value; if (level == 0 && !compact_) { if (value.size() == 0) { print_internal_without_quotes("{", 0, ""); } else if (value.size() == 1) { print_internal_without_quotes("{", 0, ""); for (auto& kvpair : value) { print_internal(kvpair.first, 0, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); } } else if (value.size() > 0) { size_t count = 0; for (auto& kvpair : value) { if (count == 0) { print_internal_without_quotes("{", 0, "\n"); print_internal(kvpair.first, indent + indent_, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); if (value.size() > 1 && is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else if (is_container::value) print_internal_without_quotes(", ", 0, "\n"); } else if (count + 1 < value.size()) { print_internal(kvpair.first, indent + indent_, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); if (is_container::value == false) print_internal_without_quotes(", ", 0, "\n"); else print_internal_without_quotes(", ", 0, "\n"); } else { print_internal(kvpair.first, indent + indent_, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "\n", level + 1); } count += 1; } } if (value.size() == 0) print_internal_without_quotes("}", indent, ""); else if (is_container::value == false) print_internal_without_quotes("}", indent, ""); else print_internal_without_quotes(line_terminator_ + "}", indent, ""); print_internal_without_quotes(line_terminator_, 0, ""); } else { if (value.size() == 0) { print_internal_without_quotes("{", indent, ""); } else if (value.size() == 1) { print_internal_without_quotes("{", indent, ""); for (auto& kvpair : value) { print_internal(kvpair.first, 0, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); } } else if (value.size() > 0) { size_t count = 0; for (auto& kvpair : value) { if (count == 0) { print_internal_without_quotes("{", indent, ""); print_internal(kvpair.first, 0, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } else if (count + 1 < value.size()) { print_internal(kvpair.first, indent + indent_, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); print_internal_without_quotes(", ", 0, ""); } else { print_internal(kvpair.first, 0, "", level + 1); print_internal_without_quotes(" : ", 0, ""); print_internal(kvpair.second, 0, "", level + 1); } count += 1; } } print_internal_without_quotes("}", 0, ""); if (level == 0 && compact_) print_internal_without_quotes(line_terminator_, 0, ""); } } template void print_internal(std::pair value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { print_internal_without_quotes("(", indent, ""); print_internal(value.first, 0, ""); print_internal_without_quotes(", ", 0, ""); print_internal(value.second, 0, ""); print_internal_without_quotes(")", 0, line_terminator, level); } template void print_internal(std::variant value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { std::visit([=](const auto& value) { print_internal(value, indent, line_terminator, level); }, value); } template void print_internal(std::optional value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { if (value) { print_internal(value.value(), indent, line_terminator, level); } else { print_internal_without_quotes("nullopt", indent, line_terminator, level); } } template typename std::enable_if::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { auto current_compact = compact_; compact_ = true; typedef typename Container::value_type T; auto local = value; std::vector local_vector; while (!local.empty()) { local_vector.push_back(local.front()); local.pop(); } print_internal(local_vector, indent, line_terminator, level); compact_ = current_compact; } template typename std::enable_if::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { auto current_compact = compact_; compact_ = true; typedef typename Container::value_type T; auto local = value; std::vector local_vector; while (!local.empty()) { local_vector.push_back(local.top()); local.pop(); } print_internal(local_vector, indent, line_terminator, level); compact_ = current_compact; } template void print_internal(std::initializer_list value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { std::multiset local; for(const T& x : value) { local.insert(x); } print_internal(local, indent, line_terminator_, level); } template typename std::enable_if::value, void>::type print_internal(const Container& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { bool current_compact = compact_; compact_ = false; // Need to print a stack like its a stack, i.e., vertical typedef typename Container::value_type T; auto local = value; std::vector local_vector; while (!local.empty()) { local_vector.push_back(local.top()); local.pop(); } print_internal(local_vector, indent, line_terminator, level); compact_ = current_compact; } template void print_internal(const std::tuple& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << value << line_terminator; } template void print_internal(const std::complex& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << "(" << value.real() << " + " << value.imag() << "i)" << line_terminator; } template typename std::enable_if::value || is_specialization::value || is_specialization::value, void>::type print_internal(const Pointer& value, size_t indent = 0, const std::string& line_terminator = "\n", size_t level = 0) { stream_ << std::string(indent, ' ') << "<" << type(value) << " at " << &value << ">" << line_terminator; } }; } ================================================ FILE: 03-Interview Preparation/Docs/.gitkeep ================================================ ================================================ FILE: 03-Interview Preparation/PDF/.gitkeep ================================================ ================================================ FILE: 03-Interview Preparation/README.md ================================================ ⚙️ Under construction ⚙️ Aiming to help my fellow coders to clear Technical Interviews. I have compiled the resources yet again to simplify the work and save time. ================================================ FILE: README.md ================================================ # All-Of-Competitive-Programming This repo contains all the resources a beginner needs to start competitive programming and an intermediate to excel in it. It is a curated blog of all other blogs that I've found informative while going through several posts for the past some time. #### Contents * [CP - Essentials](#The-essentials-that-every-competitive-programmer-should-have) * [Technique](#Technique) * [Tools](#Tools-for-Competitive-Programming) * [Speed](#Speed)
> Skip to [setting-up your working environment on your pc](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/00-Setting-up-local-environment) or [CP Materials](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/01-Material).

### The essentials that every competitive programmer should have:
1. Competitive Programming environment set up on their local machine. 2. CP Books to keep them on track. 3. Habit of reading blogs. 4. Practice! Practice! Practice! 5. Should NOT have a complaining nature.


### Technique
The everyday schedule that one follows should be very balanced and should not leave a person exhausted in the end. The most appropriate time of reading is said to be in the morning itself and a practice which involves heavy mental exercise should be done at night. The following schedule is optimal to be followed by a beginner to make it a second nature. However, it is not mandatory and one can follow a plan in which they feel most comfortable. * Morning : Read blogs / books / texts. * Noon : Implement the concepts and solve related problems. * Evening : Read blogs or watch video tutorials. * Night : Solve problems based on the concepts learnt.
The following practices should be kept in mind as these are also helpful : * Implementing the concepts after reading it. * Reading Editorial even if you have solved the problem. * Reading and understanding other users' solution and implementing the same. * Elaborating the concepts on your own and thinking about the different ways any concept can be modified and then implementing the same. * Helping others in understanding the concepts you have learnt so far: This might seem like a waste of time but solving others' doubts and making someone understand a concept will make your concept crystal clear. * Having a Good Sleep is always necessary to start the next day with zeal.
* **How much time should we spend on a problem ?** The answer depends from person to person and from problem to problem. Solving a problem on your own without taking any help from editorial is always a confidence booster but spending a lot of time on probably something you are not aware of yet is not upto the mark. In my opinion, you should never take help of any editorial if the problem is simply an implementation as editorials are useless in this case. The problem should be solved by yourself. Consider the editorial only if you're stuck at it and can't bear it anymore. However, this should not be made into habit. > Side Note: One should take competitive programming as a sport or hobby. If you really want to improve in cp then you should remove all the unnecessary burden of *placements, etc* from your mind. It will take some time and practice to master cp which can only be achieved when you start to enjoy solving the problems rather than treating them as a task. It is not necessary to extensively keep on solving the problems to improve your skills. Instead you can take a break, relax, and then get to the problem. > Tip for implementation: To write a good and bug-free code in one-go, you should write your code following the same steps as you would if you were teaching a newbie to do something. (Atleast that's how I've managed a good accuracy so far even in contests.) Your speed will tend to increase once it becomes an habit.
[Back to top](#All-Of-Competitive-Programming)

### Tools for Competitive Programming
Check out the following tools, these may turn out to be of great use: * [CP Tracker](http://cptracker.herokuapp.com/) : The current and future cp contests listed from various sites. * [C List](https://clist.by/) : Similar to CP Tracker but it contains them all in a single list. - [StopStalk](https://www.stopstalk.com/) : A goto for analysing your daily performance and finding problems based on tags. * [Codeforces Visualiser](https://cfviz.netlify.app/) : You can track your progress on codeforces and can see the ratings of problems you have currently solved and a complete package for your codeforces profile. - [Kenkooo Atcoder](https://kenkoooo.com/atcoder) : A visualisation tool for AtCoder, here you can solve problems from different contests, see its ratings and many more. It is basically a problemset for AtCoder. - [CodeDigger](http://codedigger.tech/practice/topicwise) : Solve codeforces problems based on tags and ladders. * [Contest Mania](https://contestmania.web.app/) : Past as well as Upcoming contests in a list. * [Lockout bot for discord](https://codeforces.com/blog/entry/78546) : You can try this tool for competiting with your friend in a one on one contest simulation on a discord server. * [TLE - Discord Bot](https://github.com/cheran-senthil/TLE) : Another Discord bot centred around CP. * [Graph Visualizer](https://csacademy.com/app/graph_editor/) : Easily visualize graphs. * Chrome extensions : There are a variety of extensions available on Chrome as well as Firefox which can be of great use inculcating the start of competitive programming.
[Back to top](#All-Of-Competitive-Programming)

### Speed
Speed plays a very important role in perfoming well during the live contests. For improving the speed, [AtCoder](https://atcoder.jp/) is a great platform. Try attempting the problems and solving them in alloted time which is: * 1-2 minute for A & B. * Approx 5 minutes for C * Approx 10 - 15 minutes for D & E. This will greatly boost the confidence and enhance the logic building and typing speed, in general. Virtual Contests can also help in speed as these are simulation of real contest. You can give virtual contests by : - Giving a virtual contest on codeforces. - Creating a mashup on codeforces. - Using [VJudge](https://vjudge.net/) to create a contest of your own from past problems of different OJs. - Using [Light OJ](http://lightoj.com/login_main.php?url=index.php) to simulate the same.
[Back to top](#All-Of-Competitive-Programming)

> You can now [set-up your working environment on your pc](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/00-Setting-up-local-environment) or move directly to the [CP Materials](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/01-Material). > This repo will keep on updating as new resources are found. > Note : I don't claim any of the works to be mine. I have just curated them all at one place.