master 0a8926089af6 cached
37 files
115.4 KB
34.4k tokens
47 symbols
1 requests
Download .txt
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)


<br> <hr> <br>


## 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.



<br> <hr> <br>



## 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)

<br>

### VSCode and C++ :
* [Setting up VS Code for CP - Rachit Jain - Youtube](https://www.youtube.com/watch?v=Y-_3rXgrRAY)

<br>

### 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)

<br>

### C++ in Ubuntu :
* [GeeksforGeeks Blog](https://www.geeksforgeeks.org/setting-up-a-c-competitive-programming-environment/)

<br>

### Linux Setup with Geany :
* [Linux Setup with Geany - Errichto - Youtube](https://www.youtube.com/watch?v=ePZEkbbf3fc)

<br>

### 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)

<br>

### 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 <input.txt> output.txt` to take input from input.txt and write to output.txt. Then you can easily run your file with <kbd> ctrl + alt + n </kbd>

<br>

### 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.

<br> <hr> <br>

## 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)

<br> 
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)

<br> <br>

> 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.



<br>



#### Content

* [Books](#books)

* [Informative Blogs](#some-good-and-informative-blogs-)

* [Problemset](#Problemset)



<br> <hr> <br>



## Books:
<br>

* 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. 




<br> <hr> <br>



## Some good and informative blogs :
<br>

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.






<br> [Back To Top](#cp-material) <hr> <br>






## Problemset
<br>

The problemset is divided into two broad categories based on beginner or intermediate level of knowledge. 

* [Beginners](#Beginners)

* [Intermediate](#intermediate)



<br> [Back To Top](#cp-material) <hr> <br>




### Beginners

<br>


* **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)  
<br>

* **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)
<br>


* **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)
<br>

* **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) 





<br> [Back To Problemset](#problemset) <hr> <br>




### Intermediate

<br>

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!)

<br> 


>The problems are majorly categorized into following topics for now:
<br>

**Content**
<br>

* [Graphs](#Graphs)

* [Dynamic Programming](#Dynamic-Programming)

* [Trees](#Trees)

* [Other](#Other)




<br> [Back To Problemset](#problemset) <hr> <br>
 


 
## Graphs
<br>

* #### 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/).






<br> [Back To Problemset](#problemset) <hr> <br>
 




 
## Dynamic Programming
<br>

* #### 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)



<br> [Back To Problemset](#problemset) <hr> <br>
 
 



## Trees
<br>

* #### 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)




<br> [Back To Problemset](#problemset) <hr> <br>
 




 
## Other
<br>

: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)



<br> [Back To Problemset](#problemset) <hr> <br>




> Note: There's a whole lot of problems still to be added. Any help will be appreciated.

================================================
FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/ConevertToStrictlyIncreasing.md
================================================
<h2> Convert an array into Strictly Increasing Array </h2>
<i> Solution by Udit Gupta </i>

</br>
<br>

<h3> Problem Statement </h3>

Given an array consisting of <b> N </b> elements namely from A<sub>1</sub> to A<sub>N</sub>. You have to convert this array to <strong>strictly increasing </strong> array in not more than <strong> K</strong> cost. 
Operations allowed :
1. Increase an element by 1.
2. Decrease an element by 1.

Cost of each operation is 1 unit.

</br>

<h3> Constraints </h3>

- <b> N < 3000 </b>
  
- <b> K < 5000 </b>
  
- <b> |A<sub>i</sub>| < 10<sup>9</sup> </b> for all i from 1 to N.
  
</br>

<h4> Expected Time Complexity : O(N<sup>2</sup>) </h4>
  
  </hr>
  </br>
  
<br>

<h3> Solution </h3>

<h4> Observation </h4>
  <p>
    
  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. 
  </p>
  
<h4> Deduction </h4>

The problem statement above can be translated into simpler terms by stating that 

for each i from _1_ to _N-1_,  &nbsp; **A<sub>i</sub> &nbsp; < &nbsp; A<sub>i+1</sub>**

Now we shall work on simplifying it further and deducing a general formula for all terms, 

- **A<sub>i</sub> &nbsp; < &nbsp; A<sub>i+1</sub>**

- **A<sub>i</sub> &nbsp; &le; &nbsp; A<sub>i+1</sub> - 1**

- Subtracting i from both sides, 

- **A<sub>i</sub>-i &nbsp; &le; &nbsp; A<sub>i+1</sub>-1-i**

_or_

- **A<sub>i</sub>-i &nbsp; &le; &nbsp; A<sub>i+1</sub>-(i+1)**

This is the general formulation which should work for all indices in range [1, N].
i.e.  

The sequence represented by **(A<sub>i</sub>-i)** &nbsp; &forall; &nbsp; i &isin; [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. 

<p style = "padding-left: 50pt;">
DP transition states:

- **dp[j] = min(dp[j-1], dp[j] + abs(A[i] - B[j]))** &nbsp; &forall; &nbsp; i, j &isin; [1, N]. 

Please note that the array **A** here is the converted array represented by (A<sub>i</sub>-i) &nbsp; &forall; &nbsp; i &isin; [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**.
</p>

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. 

<details>
  <summary>Python Code</summary>
<p>

```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")
```
  
</p>
</details>

<details>
  <summary>C++ Code</summary>
<p>

```cpp
#include<iostream>
#include<vector>
#include<algorithm>

signed main() {
	long long N, K;
	std::cin >> N >> K;

	std::vector<long long> 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<long long> B{A};
	std::sort(B.begin() + 1ll, B.end());

	// dp array
	std::vector<long long> 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;
}
```
  
</p>
</details>




Time Complexity : O(N<sup>2</sup>)

Space Complexity : O (N)




  
  


================================================
FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.cpp
================================================
#include<bits/stdc++.h>

using namespace std;

signed main() {
	long long N, K;
	cin >> N >> K;

	vector<long long> 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<long long> B{A};
	sort(B.begin() + 1ll, B.end());

	// dp array
	vector<long long> 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 <bits/stdc++.h>

#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<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::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<typename Head, typename... Tail> 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 << ": ";
    vector<int>moves;
    while(cin >> TempVar) {
    	moves.push_back((int)TempVar);
    }
    int n = (int)sqrt(moves.back());

    vector<vector<char>> matr(n+1, vector<char>(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<char> 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<double> 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
================================================
<h1> Containing codes of some problems </h1>

<p> Check the subfolders for contents, it has some snippets and editorials </p> 


================================================
FILE: 02-Codes/Snippets/Raw/166_e_MatMul_w_Ashishgup.cpp
================================================
//  J A I  S H R E E  R A M  //

#include <bits/stdc++.h>

#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<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::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<typename Head, typename... Tail> 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<SZ;i++) {
            MaGiC[i][i] = 1;
        }
    }

    matrix operator + (const matrix &o) const {
        matrix res;
        for(lld i=0;i<SZ;i++) {
            for(lld j=0;j<SZ;j++) {
                res.MaGiC[i][j] = add(MaGiC[i][j], o.MaGiC[i][j]);
            }
        }
        return res;
    }

    matrix operator * (const matrix &o) const {
        matrix res;
        for(lld i=0;i<SZ;i++) {
            for(lld j=0;j<SZ;j++) {
                res.MaGiC[i][j] = 0;
                for(lld k=0;k<SZ;k++) {
                    res.MaGiC[i][j] = add(res.MaGiC[i][j] , mult(MaGiC[i][k] , o.MaGiC[k][j]));
                }
            }
        }
        return res;
    }
};

matrix power(matrix a, lld b) {
    if (b == 0) {
        a.makeiden();
    }
    matrix res;
    res.makeiden();
    while(b) {
        if(b & 1) {
            res = res * a;
        }
        a = a * a;
        b >>= 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<double> 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
================================================
<snippet>
  <content><![CDATA[

// Fast Read Write 

#define gc getchar_unlocked
void scanint(int &x) {
    register int 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;
}

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');
}



]]></content>
  <tabTrigger>snip-read-write-fast</tabTrigger>
  <description>FastIo</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/addundirectededge.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

void add_undirected_edge(lld a, lld b, vector<lld> adj[]) {
    adj[a].push_back(b);
    adj[b].push_back(a);
    return;
}


]]></content>
  <tabTrigger>snip-add-undirected-edge</tabTrigger>
  <description>Add Undirected Edge</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/basic-template.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
#include <bits/stdc++.h>
#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;
}

]]></content>
  <tabTrigger>snip-basic-template</tabTrigger>
  <description>Basic Template for c++</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope> source.c++ </scope>
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/check execution time.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
    auto S34t = chrono:: high_resolution_clock::now(); 
    auto S34p = chrono::high_resolution_clock::now(); 
    auto D34n = chrono::duration_cast<chrono::microseconds>(S34p - S34t);
    cout << "Time Elapsed: " << D34n.count() / (long double) 1e6 << " seconds" << endl; 

]]></content>
  <tabTrigger>snip-debug</tabTrigger>
  <description>CP Template</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/checkvalid.sublime-snippet
================================================
<snippet>
	<content><![CDATA[

bool isvalid(lld i, lld n) {
	return i >= 0 and i < n;
}

]]></content>
	<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
	<tabTrigger>snip-checkvalid</tabTrigger>
	<!-- Optional: Set a scope to limit where the snippet will trigger -->
	<scope>source.c++</scope>
</snippet>


================================================
FILE: 02-Codes/Snippets/Sublime/cmp-priority.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

// sab ulta rkhna >>
class ${1:cmp} {
public:
    bool operator() (${2:const pair <lld, lld>} &a, ${2:const pair <lld, lld>} &b) {
        return ${3:a.s2 > b.s2};
    }
};
]]></content>
  <tabTrigger>snip-cmp-pq</tabTrigger>
  <description>cmp for priority queue</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++ </scope >
</snippet>


================================================
FILE: 02-Codes/Snippets/Sublime/common-completions.sublime-completions
================================================
{
    "scope": "source.c++, meta.block.c++, meta.function.c++",

    "completions":
    [
        {"trigger": "vectorlld", "contents": "vector<lld> ${1:arr}"}, 
        {"trigger": "vectorpalld", "contents": "vector<pair<lld,lld>> ${1:arr}"}, 
        {"trigger": "vectorvelldp2", "contents": "vector<vector<lld>> ${1:dp}(${2:n}, vector<lld>(${3:m}, ${4:-1})) $0"}, 
        {"trigger": "vectorstr", "contents": "vector<string> ${1:arr}"}, 
        {"trigger": "vectorcha", "contents": "vector<char> ${1:arr}"}, 
        {"trigger": "vectorboo", "contents": "vector<bool> ${1:visited}"}, 
        {"trigger": "setlld", "contents": "set<lld> ${1:visited}"}, 
        {"trigger": "setpall", "contents": "set<pair<lld,lld>> ${1:arr}"}, 
        {"trigger": "setstr", "contents": "set<string> ${1:arr}"}, 
        {"trigger": "setchar", "contents": "set<char> ${1:arr}"}, 
        {"trigger": "setbool", "contents": "set<bool> ${1:arr}"}, 
        {"trigger": "maplld", "contents": "map<lld,lld> ${1:arr}"}, 
        {"trigger": "mapstr", "contents": "map<string, lld> ${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<lld> ${1:arr}",
// "vector<pair<lld,lld>> ${1:arr}",
// "vector<vector<lld>> ${1:dp}(${2:n}, vector<lld>(${3:m}, ${4:-1})) $0",
// "vector<string> ${1:arr}",
// "vector<char> ${1:arr}",
// "vector<bool> ${1:visited}",
// "set<lld> ${1:visited}",
// "set<pair<lld,lld>> ${1:arr}",
// "set<string> ${1:arr}",
// "set<char> ${1:arr}",
// "set<bool> ${1:arr}",
// "map<lld,lld> ${1:arr}",
// "map<string, lld> ${1:arr}",
// "map<lld,string> ${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
================================================
<snippet>
  <content><![CDATA[

/*          D S U         */

template<lld SZ> 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;


]]></content>
  <tabTrigger>snip-dsu-array</tabTrigger>
  <description>dsu using path compression</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/dsu.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
/*          D S U         */

void makeSet(lld n, vector<lld> &par3t, vector<lld> &ran4k) {
    iota(all(par3t), 0ll);
}

lld find_repr(lld x, vector<lld> &par3t, vector<lld> &ran4k) {
    if (x != par3t[x])
        par3t[x] = find_repr(par3t[x], par3t, ran4k);
    return par3t[x];
}

void Union(lld x, lld y, vector<lld> &par3t, vector<lld> &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<lld> par3t(n, 0);
    vector<lld> ran4k(n, 0);
    makeSet(n, par3t, ran4k);
]]></content>
  <tabTrigger>snip-dsu</tabTrigger>
  <description>dsu using path compression</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/errorWatch.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); huehue(_it, args); cout << "\n";}

void huehue(istream_iterator<string> it) {}
template<typename T, typename... Args>
void huehue(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ", ";
    huehue(++it, args...);
}

]]></content>
  <tabTrigger>snip-error-watch</tabTrigger>
  <description>Error Watch</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/eulerTotientFunc.sublime-snippet
================================================
<snippet>
  <content><![CDATA[


// find totient Value complexity O(sqrt(N))
lld getPhiVal(lld n0n) {
    lld result = n0n;
    for (lld i = 2; i * i <= n0n; i++) {
        if (n0n % i == 0) {
            while (n0n % i == 0)
                n0n /= i;
            result -= result / i;
        }
    }
    if (n0n > 1)
        result -= result / n0n;
    return result;
}

vector<lld> 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);


]]></content>
  <tabTrigger>snip-totient-euler-phi</tabTrigger>
  <description>Euler totient Phi</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/leetcode-solution-class.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
//             Author: Udit "luctivud" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b7863135/)                  //


#include <bits/stdc++.h>
#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  
]]></content>
  <tabTrigger>snip-leetcode-solution</tabTrigger>
  <description>Solution class implementation</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>


================================================
FILE: 02-Codes/Snippets/Sublime/manipulated-sieve-of-eratosthene.sublime-snippet
================================================
<snippet>
  <content><![CDATA[


/* This part should be outside the main in global paradigm. */

const long long MAXN = (lld)(1e7) + 1ll; // MAXN Size

vector<long long >isPrime(MAXN , true); // checkIfPrime
vector<long long >prime_numbers; // List of prime numbers
vector<long long >smallest_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();



]]></content>
  <tabTrigger>snip-fast-sieve</tabTrigger>
  <description>sieve-manipulated</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope> source.c++ </scope>
</snippet>


================================================
FILE: 02-Codes/Snippets/Sublime/matrix-expo.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

// 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<SZ;i++) {
            MaGiC[i][i] = 1;
        }
    }

    matrix operator + (const matrix &o) const {
        matrix res;
        for(lld i=0;i<SZ;i++) {
            for(lld j=0;j<SZ;j++) {
                res.MaGiC[i][j] = add(MaGiC[i][j], o.MaGiC[i][j]);
            }
        }
        return res;
    }

    matrix operator * (const matrix &o) const {
        matrix res;
        for(lld i=0;i<SZ;i++) {
            for(lld j=0;j<SZ;j++) {
                res.MaGiC[i][j] = 0;
                for(lld k=0;k<SZ;k++) {
                    res.MaGiC[i][j] = add(res.MaGiC[i][j] , mult(MaGiC[i][k] , o.MaGiC[k][j]));
                }
            }
        }
        return res;
    }
};

matrix power(matrix a, lld b) {
    if (b == 0) {
        a.makeiden();
    }
    matrix res;
    res.makeiden();
    while(b) {
        if(b & 1) {
            res = res * a;
        }
        a = a * a;
        b >>= 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];


]]></content>
  <tabTrigger>snip-matrix-expo</tabTrigger>
  <description>Matrix Expo on recurrence formula</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/max-biparite-matching.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

lld n, m;

bool bpm(vector<vector<bool >> graph, lld u, vector<bool> &visited, vector<lld> &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<vector<bool >> graph, vector<lld> &matchR) {
	lld result = 0;
	for (lld u = 0; u < m; u++) {
		vector<bool> 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<vector<bool >> graph(m, vector<bool>(n, false));
	vector<lld> matchR(n, -1);
	maxBPM(graph, matchR);
]]></content>
  <tabTrigger>snip-bipartite-matching</tabTrigger>
  <description>Max B M</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/modop.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
namespace modop {
	lld madd(lld a, lld b) {
		return (a + b) % mod;
	}
	lld msub(lld a, lld b) {
		return (((a - b) % mod) + mod) % mod;
	}
	lld mmul(lld a, lld b) {
		return ((a % mod) * (b % mod)) % mod;
	}
	lld mpow(lld base, lld exp) {
		lld res = 1;
		while (exp) {
			if (exp % 2 == 1) {
				res = (res * base) % mod;
			}
			exp >>= 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;
}
]]></content>
  <tabTrigger>snip-namespace-modop</tabTrigger>
  <description>modops and ncr on demand</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/myReadTemplate.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

void Read() { return; }
void Print() { return; }
void Println() { cout << "\n"; return; }
template<class T> T Read(T& x)   { cin >> x; return x; }
template<class T> void Print(T a)   { cout << a; }
template<class T> void Println(T a) { cout << a << "\n"; }

template<class T> void Read(vector<T> &arr)   { EACH(i, arr) cin >> (i); }
template<class T> void Print(vector<T> arr)   { EACH(i, arr) {cout << i << " ";} }
template<class T> void Println(vector<T> arr) { EACH(i, arr) {cout << i << " ";} cout << "\n"; }

template<class T> void Read(vector<vector<T>> &arr)   { EACH(i, arr) Read(i); }
template<class T> void Print(vector<vector<T>> arr)   { EACH(i, arr) Println(i); }
template<class T> void Println(vector<vector<T>> arr) { EACH(i, arr) Println(i); }

template<typename T, typename... Args> void Read(vector<T> &arr, Args &... args)   { Read(arr); Read(args...);}
template<typename T, typename... Args> void Read(vector<vector<T>> &arr, Args &... args)   { Read(arr); Read(args...);}
template<typename T, typename... Args> void Read(T &a, Args &... args) { cin >> (a); Read(args...); }
template<typename T, typename... Args> void Print(vector<T> &arr, Args &... args)   { Print(arr); Print(args...);}
template<typename T, typename... Args> void Print(T a, Args... args) { cout << a << " "; Print(args...); };
template<typename T, typename... Args> void Println(vector<T> &arr, Args &... args)   { Print(arr); Println(args...);}
template<typename T, typename... Args> void Println(T a, Args... args) { cout << a << " "; Println(args...); };

]]></content>
  <tabTrigger>snip-read-template</tabTrigger>
  <description>Read-Print-Template</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
FILE: 02-Codes/Snippets/Sublime/ncr-on-demand.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

lld EE(lld a, lld b, lld *x, lld *y) {
	if (a == 0) {
		*x = 0, *y = 1;
		return b;
	}

	lld x1, y1;
	lld gcd = EE(b % a, a, &x1, &y1);

	*x = y1 - (b / a) * x1;
	*y = x1;

	return gcd;
}


lld inverse(lld a, lld m) {
	lld x, y;
	EE(a, m, &x, &y);
	if (x < 0) x += m;
	return x;
}

lld choose(lld n, lld k) {
	lld i;

	lld num = 1, den = 1;

	for (i = 2; i <= k; i++) {
		den *= i;
		den %= mod;
	}

	for (i = n - k + 1; i <= n; i++) {
		num *= i;
		num %= mod;
	}

	i = num * inverse(den, mod);
	i %= mod;
	return i;
}

]]></content>
  <tabTrigger>snip-ncr-binomial</tabTrigger>
  <description>NCR on demand</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/pbds.sublime-snippet
================================================
<snippet>
  <content><![CDATA[
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using PBSET = tree<T, null_type, less<T>, 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
*/

]]></content>
  <tabTrigger>snip-pbds</tabTrigger>
  <description>pbds</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/power-expo.sublime-snippet
================================================
<snippet>
  <content><![CDATA[


lld power(lld x, lld y) {
	lld res = 1;

	x = x % MOD;

	if (x == 0) return 0;

	while (y > 0)  {
		if (y & 1)
			res = (res * x) % MOD;

		y = y >> 1; 
		x = (x * x) % MOD;
	}
	return res;
}


]]></content>
  <tabTrigger>snip-power</tabTrigger>
  <description>power exponentiation</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/sieve-of-eratosthene.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

/* This part should be outside the main in global paradigm. */

const lld MAXN = (lld)(1e5) + 1ll; // Maximum sieve upto
vector<bool> isPrime(MAXN, true); // Temp vector for sieve result
vector<lld> 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


]]></content>
  <tabTrigger>snip-sieve</tabTrigger>
  <description>sieve</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope >source.c++</scope >
</snippet>

================================================
FILE: 02-Codes/Snippets/Sublime/topcoder-template.sublime-snippet
================================================
<snippet>
  <content><![CDATA[

#include <bits/stdc++.h>
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<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::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<typename Head, typename... Tail> 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;
}

*/

]]></content>
  <tabTrigger>snip-topcoder-template</tabTrigger>
  <description>Topcoder class template</description>
  <!-- Optional: Set a scope to limit where the snippet will trigger -->
  <scope>source.c++</scope>
</snippet>





================================================
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
// <http://www.gnu.org/licenses/>.

/** @file stdc++.h
 *  This is an implementation file for a precompiled header.
 */

// 17.4.1.2 Headers

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cuchar>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <cxxabi.h> // for prettyprint

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#if __cplusplus >= 201703L
#include <any>
#include <charconv>
// #include <execution>
#include <filesystem>
#include <optional>
#include <memory_resource>
#include <string_view>
#include <variant>
#endif

#if __cplusplus > 201703L
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_impl_coroutine
# include <coroutine>
#endif
#include <latch>
#include <numbers>
#include <ranges>
#include <span>
#include <stop_token>
#include <semaphore>
#include <source_location>
#include <syncstream>
#include <version>
#endif


/*

stdc++.h end

*/

using namespace std;




template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decay_t<decltype(*begin(declval<T>()))>,
          class = enable_if_t<!is_same<T, string>::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 <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
Copyright (c) 2019 Pranav Srinivas Kumar <pranav.srinivas.kumar@gmail.com>.
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 <iostream>
// #include <string>
// #include <typeinfo>
// #include <type_traits>
// #include <vector>
// #include <list>
// #include <deque>
// #include <set>
// #include <unordered_set>
// #include <array>
// #include <map>
// #include <unordered_map>
// #include <iomanip>
// #include <variant>
// #include <algorithm>
// #include <cassert>
// #include <cstddef>
// #include <iosfwd>
// #include <limits>
// #include <string_view>
// #include <optional>
// #include <utility>
// #include <sstream>
// #include <queue>
// #include <stack>
// #include <tuple>
// #include <initializer_list>
// #include <complex>
// #include <cmath>
// #include <memory>
#ifdef __GNUG__
// #include <cstdlib>
// #include <memory>
// #include <cxxabi.h>
#endif

// Check if a type is stream writable, i.e., std::cout << foo;
template<typename S, typename T, typename = void>
struct is_to_stream_writable: std::false_type {};

template<typename S, typename T>
struct is_to_stream_writable<S, T,
           std::void_t<  decltype( std::declval<S&>()<<std::declval<T>() ) >>
  : std::true_type {};


// Printing std::tuple
// The indices trick: http://loungecpp.wikidot.com/tips-and-tricks:indices
namespace pprint {

  template<std::size_t...> struct seq{};

  template<std::size_t N, std::size_t... Is>
  struct gen_seq : gen_seq<N-1, N-1, Is...>{};

  template<std::size_t... Is>
  struct gen_seq<0, Is...> : seq<Is...>{};

  template<typename T>
  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<class Ch, class Tr, class Tuple, std::size_t... Is>
  void print_tuple(std::basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){
    using swallow = int[];
    (void)swallow{0, (void(os << (Is == 0? "" : ", ") << to_string(std::get<Is>(t))), 0)...};
  }

}

template<class Ch, class Tr, class... Args>
auto operator<<(std::basic_ostream<Ch, Tr>& os, std::tuple<Args...> const& t)
  -> std::basic_ostream<Ch, Tr>& {
  os << "(";
  pprint::print_tuple(os, t, pprint::gen_seq<sizeof...(Args)>());
  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 <typename E>
  struct enum_range final {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_range requires enum type.");
    static constexpr int min = std::is_signed_v<std::underlying_type_t<E>> ? 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<int>::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<int>::min(),
    "MAGIC_ENUM_RANGE_MIN must be greater than INT_MIN.");

  namespace detail {

    template <typename E, typename U = std::underlying_type_t<E>>
    [[nodiscard]] constexpr int min_impl() {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::min_impl requires enum type.");
      constexpr int min = enum_range<E>::min > (std::numeric_limits<U>::min)() ? enum_range<E>::min : (std::numeric_limits<U>::min)();

      return min;
    }

    template <typename E, typename U = std::underlying_type_t<E>>
    [[nodiscard]] constexpr decltype(auto) range_impl() {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::range_impl requires enum type.");
      static_assert(enum_range<E>::max > enum_range<E>::min, "magic_enum::enum_range requires max > min.");
      constexpr int max = enum_range<E>::max < (std::numeric_limits<U>::max)() ? enum_range<E>::max : (std::numeric_limits<U>::max)();
      constexpr auto range = std::make_integer_sequence<int, max - min_impl<E>() + 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 <typename E, E V>
    [[nodiscard]] constexpr std::string_view name_impl() noexcept {
      static_assert(std::is_enum_v<E>, "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<char>]") - 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 <typename E, int... I>
    [[nodiscard]] constexpr decltype(auto) strings_impl(std::integer_sequence<int, I...>) noexcept {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::strings_impl requires enum type.");
      constexpr std::array<std::string_view, sizeof...(I)> names{{name_impl<E, static_cast<E>(I + min_impl<E>())>()...}};

      return names;
    }

    template <typename E>
    [[nodiscard]] constexpr std::string_view name_impl(int value) noexcept {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::name_impl requires enum type.");
      constexpr auto names = strings_impl<E>(range_impl<E>());
      const int i = value - min_impl<E>();

      if (i >= 0 && static_cast<std::size_t>(i) < names.size()) {
        return names[i];
      } else {
        return {}; // Value out of range.
      }
    }

    template <typename E, int... I>
    [[nodiscard]] constexpr decltype(auto) values_impl(std::integer_sequence<int, I...>) noexcept {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::values_impl requires enum type.");
      constexpr int n = sizeof...(I);
      constexpr std::array<bool, n> valid{{!name_impl<E, static_cast<E>(I + min_impl<E>())>().empty()...}};
      constexpr int num_valid = ((valid[I] ? 1 : 0) + ...);

      std::array<E, num_valid> enums{};
      for (int i = 0, v = 0; i < n && v < num_valid; ++i) {
        if (valid[i]) {
          enums[v++] = static_cast<E>(i + min_impl<E>());
        }
      }

      return enums;
    }

    template <typename E, std::size_t... I>
    [[nodiscard]] constexpr decltype(auto) names_impl(std::integer_sequence<std::size_t, I...>) noexcept {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::names_impl requires enum type.");
      constexpr auto enums = values_impl<E>(range_impl<E>());
      constexpr std::array<std::string_view, sizeof...(I)> names{{name_impl<E, enums[I]>()...}};

      return names;
    }

    template <typename E>
    [[nodiscard]] constexpr std::optional<E> enum_cast_impl(std::string_view value) noexcept {
      static_assert(std::is_enum_v<E>, "magic_enum::detail::enum_cast_impl requires enum type.");
      constexpr auto values = values_impl<E>(range_impl<E>());
      constexpr auto count = values.size();
      constexpr auto names = names_impl<E>(std::make_index_sequence<count>{});

      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<typename T>
    using enable_if_enum_t = typename std::enable_if<std::is_enum_v<T>>::type;

    template<typename T, bool = std::is_enum_v<T>>
    struct is_scoped_enum_impl : std::false_type {};

    template<typename T>
    struct is_scoped_enum_impl<T, true> : std::bool_constant<!std::is_convertible_v<T, std::underlying_type_t<T>>> {};

    template<typename T, bool = std::is_enum_v<T>>
    struct is_unscoped_enum_impl : std::false_type {};

    template<typename T>
    struct is_unscoped_enum_impl<T, true> : std::bool_constant<std::is_convertible_v<T, std::underlying_type_t<T>>> {};

  } // 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 <typename T>
  struct is_unscoped_enum : detail::is_unscoped_enum_impl<T> {};

  template <typename T>
  inline constexpr bool is_unscoped_enum_v = is_unscoped_enum<T>::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 <typename T>
  struct is_scoped_enum : detail::is_scoped_enum_impl<T> {};

  template <typename T>
  inline constexpr bool is_scoped_enum_v = is_scoped_enum<T>::value;

  // Obtains enum value from enum string name.
  template <typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr std::optional<E> enum_cast(std::string_view value) noexcept {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_cast requires enum type.");

    return detail::enum_cast_impl<E>(value);
  }

  // Obtains enum value from integer value.
  template <typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr std::optional<E> enum_cast(std::underlying_type_t<E> value) noexcept {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_cast requires enum type.");

    if (detail::name_impl<E>(static_cast<int>(value)).empty()) {
      return std::nullopt; // Invalid value or out of range.
    } else {
      return static_cast<E>(value);
    }
  }

  // Returns enum value at specified index.
  // No bounds checking is performed: the behavior is undefined if index >= number of enum values.
  template<typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr E enum_value(std::size_t index) {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_value requires enum type.");
    constexpr auto values = detail::values_impl<E>(detail::range_impl<E>());

    return assert(index < values.size()), values[index];
  }

  // Obtains value enum sequence.
  template <typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr decltype(auto) enum_values() noexcept {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_values requires enum type.");
    constexpr auto values = detail::values_impl<E>(detail::range_impl<E>());

    return values;
  }

  // Returns number of enum values.
  template <typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr std::size_t enum_count() noexcept {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_count requires enum type.");
    constexpr auto count = detail::values_impl<E>(detail::range_impl<E>()).size();

    return count;
  }

  // Obtains string enum name from enum value.
  template <typename E, typename D = std::decay_t<E>, typename = detail::enable_if_enum_t<D>>
  [[nodiscard]] constexpr std::optional<std::string_view> enum_name(E value) noexcept {
    static_assert(std::is_enum_v<D>, "magic_enum::enum_name requires enum type.");
    const auto name = detail::name_impl<D>(static_cast<int>(value));

    if (name.empty()) {
      return std::nullopt; // Invalid value or out of range.
    } else {
      return name;
    }
  }

  // Obtains string enum name sequence.
  template <typename E, typename = detail::enable_if_enum_t<E>>
  [[nodiscard]] constexpr decltype(auto) enum_names() noexcept {
    static_assert(std::is_enum_v<E>, "magic_enum::enum_names requires enum type.");
    constexpr auto count = detail::values_impl<E>(detail::range_impl<E>()).size();
    constexpr auto names = detail::names_impl<E>(std::make_index_sequence<count>{});

    return names;
  }

  namespace ops {

    template <typename E, typename D = std::decay_t<E>, typename = detail::enable_if_enum_t<E>>
    std::ostream& operator<<(std::ostream& os, E value) {
      static_assert(std::is_enum_v<D>, "magic_enum::ops::operator<< requires enum type.");
      const auto name = detail::name_impl<D>(static_cast<int>(value));

      if (!name.empty()) {
        os << name;
      }

      return os;
    }

    template <typename E, typename = detail::enable_if_enum_t<E>>
    std::ostream& operator<<(std::ostream& os, std::optional<E> value) {
      static_assert(std::is_enum_v<E>, "magic_enum::ops::operator<< requires enum type.");

      if (value.has_value()) {
        const auto name = detail::name_impl<E>(static_cast<int>(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<typename Test, template<typename...> class Ref>
  struct is_specialization : std::false_type {};

  template<template<typename...> class Ref, typename... Args>
  struct is_specialization<Ref<Args...>, Ref> : std::true_type {};

  template<typename ...>
  using to_void = void;

  template<typename T, typename = void>
  struct is_container : std::false_type
  {};

  template<typename T>
  struct is_container<T,
          to_void<decltype(std::declval<T>().begin()),
              decltype(std::declval<T>().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 <typename T>
    void print(T value) {
      print_internal(value, 0, line_terminator_, 0);
    }

    template <typename T>
    void print(std::initializer_list<T> value) {
      print_internal(value, 0, line_terminator_, 0);
    }

    template<typename T, typename... Targs>
    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 <typename T>
    void print_inline(T value) {
      print_internal(value, indent_, "", 0);
    }

    template <typename T>
    void print_inline(std::initializer_list<T> value) {
      print_internal(value, indent_, "", 0);
    }

    template<typename T, typename... Targs>
    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 T>
    typename std::enable_if<std::is_integral<T>::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 T>
    typename std::enable_if<std::is_null_pointer<T>::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 T>
    typename std::enable_if<std::is_pointer<T>::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<char, void(*)(void*)> res {
        abi::__cxa_demangle(name, NULL, NULL, &status),
        std::free
      };
      return (status==0) ? res.get() : name;
#else
      return name;
#endif
    }

    template <class T>
    std::string type(const T& t) {
      return demangle(typeid(t).name());
    }

    template <typename T>
    typename std::enable_if<std::is_enum<T>::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<std::underlying_type_t<T>>(value)
                << line_terminator;
      }
    }

    template <typename T>
    typename std::enable_if<std::is_class<T>::value == true &&
        is_to_stream_writable<std::ostream, T>::value == true &&
        std::is_enum<T>::value == false &&
        is_specialization<T, std::unique_ptr>::value == false &&
        is_specialization<T, std::shared_ptr>::value == false &&
        is_specialization<T, std::weak_ptr>::value == false &&
        is_specialization<T, std::tuple>::value == false &&
        is_specialization<T, std::variant>::value == false &&
        is_specialization<T, std::vector>::value == false &&
        is_specialization<T, std::list>::value == false &&
        is_specialization<T, std::deque>::value == false &&
        is_specialization<T, std::queue>::value == false &&
        is_specialization<T, std::priority_queue>::value == false &&
        is_specialization<T, std::stack>::value == false &&
        is_specialization<T, std::set>::value == false &&
        is_specialization<T, std::multiset>::value == false &&
        is_specialization<T, std::unordered_set>::value == false &&
        is_specialization<T, std::unordered_multiset>::value == false &&
        is_specialization<T, std::map>::value == false &&
        is_specialization<T, std::multimap>::value == false &&
        is_specialization<T, std::unordered_map>::value == false &&
        is_specialization<T, std::unordered_multimap>::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 T>
    typename std::enable_if<std::is_class<T>::value == true &&
            is_to_stream_writable<std::ostream, T>::value == false &&
            std::is_enum<T>::value == false &&
            is_specialization<T, std::unique_ptr>::value == false &&
            is_specialization<T, std::shared_ptr>::value == false &&
            is_specialization<T, std::weak_ptr>::value == false &&
            is_specialization<T, std::tuple>::value == false &&
            is_specialization<T, std::variant>::value == false &&
            is_specialization<T, std::vector>::value == false &&
            is_specialization<T, std::list>::value == false &&
            is_specialization<T, std::deque>::value == false &&
            is_specialization<T, std::queue>::value == false &&
            is_specialization<T, std::priority_queue>::value == false &&
            is_specialization<T, std::stack>::value == false &&
            is_specialization<T, std::set>::value == false &&
            is_specialization<T, std::multiset>::value == false &&
            is_specialization<T, std::unordered_set>::value == false &&
            is_specialization<T, std::unordered_multiset>::value == false &&
            is_specialization<T, std::map>::value == false &&
            is_specialization<T, std::multimap>::value == false &&
            is_specialization<T, std::unordered_map>::value == false &&
            is_specialization<T, std::unordered_multimap>::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, ' ') << "<Object " << type(value) << ">"
              << line_terminator;
    }

    template <typename T>
    typename std::enable_if<std::is_member_function_pointer<T>::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, ' ') << "<Object.method " << type(value)
              << " at " << &value << ">"
              << line_terminator;
    }

    template <typename Container>
    typename std::enable_if<is_specialization<Container, std::vector>::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<T>::value == false)
            print_internal_without_quotes(", ", 0, "\n");
          else if (is_container<T>::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<T>::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<T>::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 T, unsigned long int S>
    void print_internal(const std::array<T, S>& 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<T>::value == false)
            print_internal_without_quotes(", ", 0, "\n");
          else if (is_container<T>::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<T>::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<T>::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 Container>
    typename std::enable_if<is_specialization<Container, std::list>::value ||
            is_specialization<Container, std::deque>::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<T>::value == false)
            print_internal_without_quotes(", ", 0, "\n");
          else if (is_container<T>::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<T>::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<T>::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 Container>
    typename std::enable_if<is_specialization<Container, std::set>::value ||
            is_specialization<Container, std::multiset>::value ||
            is_specialization<Container, std::unordered_set>::value ||
            is_specialization<Container, std::unordered_multiset>::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<T>::value == false)
            print_internal_without_quotes(", ", 0, "\n");
          else if (is_container<T>::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<T>::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<T>::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 T>
    typename std::enable_if<is_specialization<T, std::map>::value == true ||
            is_specialization<T, std::multimap>::value == true ||
            is_specialization<T, std::unordered_map>::value == true ||
            is_specialization<T, std::unordered_multimap>::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>::value == false)
                print_internal_without_quotes(", ", 0, "\n");
              else if (is_container<Value>::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>::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>::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 <typename Key, typename Value>
    void print_internal(std::pair<Key, Value> 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 <class ...Ts>
    void print_internal(std::variant<Ts...> 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 <typename T>
    void print_internal(std::optional<T> 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 Container>
    typename std::enable_if<is_specialization<Container, std::queue>::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<T> 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 Container>
    typename std::enable_if<is_specialization<Container, std::priority_queue>::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<T> 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 <typename T>
    void print_internal(std::initializer_list<T> value, size_t indent = 0,
            const std::string& line_terminator = "\n", size_t level = 0) {
      std::multiset<T> local;
      for(const T& x : value) {
        local.insert(x);
      }
      print_internal(local, indent, line_terminator_, level);
    }

    template <typename Container>
    typename std::enable_if<is_specialization<Container, std::stack>::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<T> 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<class... Args>
    void print_internal(const std::tuple<Args...>& value, size_t indent = 0, const std::string& line_terminator = "\n",
            size_t level = 0) {
      stream_ << std::string(indent, ' ') << value
              << line_terminator;
    }

    template<typename T>
    void print_internal(const std::complex<T>& 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 Pointer>
    typename std::enable_if<is_specialization<Pointer, std::unique_ptr>::value ||
        is_specialization<Pointer, std::shared_ptr>::value ||
        is_specialization<Pointer, std::weak_ptr>::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)

<br> 

> <kbd>Skip</kbd> to <kbd>[setting-up your working environment on your pc](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/00-Setting-up-local-environment)</kbd> or  <kbd>[CP Materials](https://github.com/luctivud/All-Of-Competitive-Programming/tree/master/01-Material)</kbd>.

<hr> <br>


### The essentials that every competitive programmer should have:
<br>

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. 



<br> <hr> <br>



### Technique
<br>

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.

<br>

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.

<br>

* **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.




<br> [Back to top](#All-Of-Competitive-Programming) <hr> <br>




### Tools for Competitive Programming
<br>

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. 



<br> [Back to top](#All-Of-Competitive-Programming) <hr> <br>




### Speed
<br>


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.



<br> [Back to top](#All-Of-Competitive-Programming) <hr> <br>




> 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.
Download .txt
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
Download .txt
SYMBOL INDEX (47 symbols across 4 files)

FILE: 02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.cpp
  function main (line 5) | signed main() {

FILE: 02-Codes/Editorials/Random/TransposeColorsWork.cpp
  function ostream (line 25) | ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '('...
  function ostream (line 27) | ostream & operator<<(ostream &os, const T_container &v) { os << '{'; str...
  function dbg_out (line 28) | void dbg_out() { cout << "\n"; }
  function dbg_out (line 29) | void dbg_out(Head H, Tail... T) { cout << H << ", "; dbg_out(T...);}
  function solveEachTest (line 49) | void solveEachTest(int _TestCase) {
  function main (line 99) | signed main() {

FILE: 02-Codes/Snippets/Raw/166_e_MatMul_w_Ashishgup.cpp
  function ostream (line 25) | ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '('...
  function ostream (line 27) | ostream & operator<<(ostream &os, const T_container &v) { os << '{'; str...
  function dbg_out (line 28) | void dbg_out() { cout << "\n"; }
  function dbg_out (line 29) | void dbg_out(Head H, Tail... T) { cout << H << ", "; dbg_out(T...);}
  function lld (line 52) | lld add(lld a, lld b) {
  function lld (line 58) | lld mult(lld a, lld b) {
  type matrix (line 69) | struct matrix {
    method reset (line 72) | void reset() {
    method makeiden (line 76) | void makeiden() {
    method matrix (line 83) | matrix operator + (const matrix &o) const {
    method matrix (line 93) | matrix operator * (const matrix &o) const {
  function matrix (line 107) | matrix power(matrix a, lld b) {
    method reset (line 72) | void reset() {
    method makeiden (line 76) | void makeiden() {
    method matrix (line 83) | matrix operator + (const matrix &o) const {
    method matrix (line 93) | matrix operator * (const matrix &o) const {
  function solveEachTest (line 143) | void solveEachTest(int _TestCase) {
  function main (line 161) | signed main() {

FILE: 02-Codes/Snippets/mydebug.h
  function namespace (line 288) | namespace pprint {
  function enum_range (line 349) | enum_range final {
  function min_impl (line 368) | [[nodiscard]] constexpr int min_impl() {
  function range_impl (line 376) | [[nodiscard]] constexpr decltype(auto) range_impl() {
  function is_name_char (line 386) | [[nodiscard]] constexpr bool is_name_char(char c, bool front) noexcept {
  function strings_impl (line 424) | [[nodiscard]] constexpr decltype(auto) strings_impl(std::integer_sequenc...
  function std (line 432) | [[nodiscard]] constexpr std::string_view name_impl(int value) noexcept {
  function values_impl (line 445) | [[nodiscard]] constexpr decltype(auto) values_impl(std::integer_sequence...
  function names_impl (line 462) | [[nodiscard]] constexpr decltype(auto) names_impl(std::integer_sequence<...
  function std (line 471) | [[nodiscard]] constexpr std::optional<E> enum_cast_impl(std::string_view...
  function std (line 523) | [[nodiscard]] constexpr std::optional<E> enum_cast(std::string_view valu...
  function std (line 531) | [[nodiscard]] constexpr std::optional<E> enum_cast(std::underlying_type_...
  function E (line 544) | [[nodiscard]] constexpr E enum_value(std::size_t index) {
  function enum_values (line 553) | [[nodiscard]] constexpr decltype(auto) enum_values() noexcept {
  function enum_count (line 562) | [[nodiscard]] constexpr std::size_t enum_count() noexcept {
  function std (line 571) | [[nodiscard]] constexpr std::optional<std::string_view> enum_name(E valu...
  function enum_names (line 584) | [[nodiscard]] constexpr decltype(auto) enum_names() noexcept {
  function namespace (line 592) | namespace ops {
  function namespace (line 624) | namespace pprint {
  function string (line 813) | string type(const T& t) {
  type typename (line 898) | typedef typename Container::value_type T;
  type typename (line 1032) | typedef typename Container::value_type T;
  type typename (line 1108) | typedef typename Container::value_type T;
  type typename (line 1183) | typedef typename T::mapped_type Value;
  type typename (line 1310) | typedef typename Container::value_type T;
  type typename (line 1327) | typedef typename Container::value_type T;
Condensed preview — 37 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (126K chars).
[
  {
    "path": "00-Setting-up-local-environment/README.md",
    "chars": 3943,
    "preview": "# Setting up Competitive Programming on Local Machine :\n\n#### Content\n\n- [Benefits](#Benefits)\n\n- [SetUp](#Setting-up-en"
  },
  {
    "path": "01-Material/README.md",
    "chars": 16070,
    "preview": "# CP Material\n\nMany of the seniors as well good competitive coders advice to not waste any money on the courses which ar"
  },
  {
    "path": "02-Codes/Editorials/ConvertToStrictlyIncreasing/ConevertToStrictlyIncreasing.md",
    "chars": 4367,
    "preview": "<h2> Convert an array into Strictly Increasing Array </h2>\n<i> Solution by Udit Gupta </i>\n\n</br>\n<br>\n\n<h3> Problem Sta"
  },
  {
    "path": "02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.cpp",
    "chars": 617,
    "preview": "#include<bits/stdc++.h>\n\nusing namespace std;\n\nsigned main() {\n\tlong long N, K;\n\tcin >> N >> K;\n\n\tvector<long long> A(N+"
  },
  {
    "path": "02-Codes/Editorials/ConvertToStrictlyIncreasing/convertToIncreasing.py",
    "chars": 503,
    "preview": "N = int(input())\nK = int(input())\nA = [0] + list(map(int, input().split()))\n\n# Convert A[i] = A[i] - i\nfor i in range(1,"
  },
  {
    "path": "02-Codes/Editorials/Random/TransposeColorsWork.cpp",
    "chars": 3711,
    "preview": "//  J A I  S H R E E  R A M  //\n\n#include <bits/stdc++.h>\n\n#pragma GCC optimize \"trapv\"\n// #pragma GCC optimize (\"Ofast\""
  },
  {
    "path": "02-Codes/README.md",
    "chars": 127,
    "preview": "<h1> Containing codes of some problems </h1>\n\n<p> Check the subfolders for contents, it has some snippets and editorials"
  },
  {
    "path": "02-Codes/Snippets/Raw/166_e_MatMul_w_Ashishgup.cpp",
    "chars": 4573,
    "preview": "//  J A I  S H R E E  R A M  //\n\n#include <bits/stdc++.h>\n\n#pragma GCC optimize \"trapv\"\n// #pragma GCC optimize (\"Ofast\""
  },
  {
    "path": "02-Codes/Snippets/Sublime/FastReadWrite.sublime-snippet",
    "chars": 1733,
    "preview": "<snippet>\n  <content><![CDATA[\n\n// Fast Read Write \n\n#define gc getchar_unlocked\nvoid scanint(int &x) {\n    register int"
  },
  {
    "path": "02-Codes/Snippets/Sublime/addundirectededge.sublime-snippet",
    "chars": 388,
    "preview": "<snippet>\n  <content><![CDATA[\n\nvoid add_undirected_edge(lld a, lld b, vector<lld> adj[]) {\n    adj[a].push_back(b);\n   "
  },
  {
    "path": "02-Codes/Snippets/Sublime/basic-template.sublime-snippet",
    "chars": 700,
    "preview": "<snippet>\n  <content><![CDATA[\n#include <bits/stdc++.h>\n#pragma GCC optimize \"trapv\"\n\nusing namespace std;\n\ntypedef long"
  },
  {
    "path": "02-Codes/Snippets/Sublime/check execution time.sublime-snippet",
    "chars": 512,
    "preview": "<snippet>\n  <content><![CDATA[\n    auto S34t = chrono:: high_resolution_clock::now(); \n    auto S34p = chrono::high_reso"
  },
  {
    "path": "02-Codes/Snippets/Sublime/checkvalid.sublime-snippet",
    "chars": 329,
    "preview": "<snippet>\n\t<content><![CDATA[\n\nbool isvalid(lld i, lld n) {\n\treturn i >= 0 and i < n;\n}\n\n]]></content>\n\t<!-- Optional: S"
  },
  {
    "path": "02-Codes/Snippets/Sublime/cmp-priority.sublime-snippet",
    "chars": 425,
    "preview": "<snippet>\n  <content><![CDATA[\n\n// sab ulta rkhna >>\nclass ${1:cmp} {\npublic:\n    bool operator() (${2:const pair <lld, "
  },
  {
    "path": "02-Codes/Snippets/Sublime/common-completions.sublime-completions",
    "chars": 4515,
    "preview": "{\n    \"scope\": \"source.c++, meta.block.c++, meta.function.c++\",\n\n    \"completions\":\n    [\n        {\"trigger\": \"vectorlld"
  },
  {
    "path": "02-Codes/Snippets/Sublime/dsu-array.sublime-snippet",
    "chars": 816,
    "preview": "<snippet>\n  <content><![CDATA[\n\n/*          D S U         */\n\ntemplate<lld SZ> struct DSU {\n    lld par3t[SZ], ran4k[SZ]"
  },
  {
    "path": "02-Codes/Snippets/Sublime/dsu.sublime-snippet",
    "chars": 1045,
    "preview": "<snippet>\n  <content><![CDATA[\n/*          D S U         */\n\nvoid makeSet(lld n, vector<lld> &par3t, vector<lld> &ran4k)"
  },
  {
    "path": "02-Codes/Snippets/Sublime/errorWatch.sublime-snippet",
    "chars": 637,
    "preview": "<snippet>\n  <content><![CDATA[\n\n#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); str"
  },
  {
    "path": "02-Codes/Snippets/Sublime/eulerTotientFunc.sublime-snippet",
    "chars": 1028,
    "preview": "<snippet>\n  <content><![CDATA[\n\n\n// find totient Value complexity O(sqrt(N))\nlld getPhiVal(lld n0n) {\n    lld result = n"
  },
  {
    "path": "02-Codes/Snippets/Sublime/leetcode-solution-class.sublime-snippet",
    "chars": 926,
    "preview": "<snippet>\n  <content><![CDATA[\n//             Author: Udit \"luctivud\" Gupta @ (https://www.linkedin.com/in/udit-gupta-1b"
  },
  {
    "path": "02-Codes/Snippets/Sublime/manipulated-sieve-of-eratosthene.sublime-snippet",
    "chars": 1268,
    "preview": "<snippet>\n  <content><![CDATA[\n\n\n/* This part should be outside the main in global paradigm. */\n\nconst long long MAXN = "
  },
  {
    "path": "02-Codes/Snippets/Sublime/matrix-expo.sublime-snippet",
    "chars": 1902,
    "preview": "<snippet>\n  <content><![CDATA[\n\n// matrix exponentiation snippet::\n// // courtesy Ashishgup3 via Github\n\n\n\n\n\nlld add(lld"
  },
  {
    "path": "02-Codes/Snippets/Sublime/max-biparite-matching.sublime-snippet",
    "chars": 982,
    "preview": "<snippet>\n  <content><![CDATA[\n\nlld n, m;\n\nbool bpm(vector<vector<bool >> graph, lld u, vector<bool> &visited, vector<ll"
  },
  {
    "path": "02-Codes/Snippets/Sublime/modop.sublime-snippet",
    "chars": 965,
    "preview": "<snippet>\n  <content><![CDATA[\nnamespace modop {\n\tlld madd(lld a, lld b) {\n\t\treturn (a + b) % mod;\n\t}\n\tlld msub(lld a, l"
  },
  {
    "path": "02-Codes/Snippets/Sublime/myReadTemplate.sublime-snippet",
    "chars": 1806,
    "preview": "<snippet>\n  <content><![CDATA[\n\nvoid Read() { return; }\nvoid Print() { return; }\nvoid Println() { cout << \"\\n\"; return; "
  },
  {
    "path": "02-Codes/Snippets/Sublime/ncr-on-demand.sublime-snippet",
    "chars": 768,
    "preview": "<snippet>\n  <content><![CDATA[\n\nlld EE(lld a, lld b, lld *x, lld *y) {\n\tif (a == 0) {\n\t\t*x = 0, *y = 1;\n\t\treturn b;\n\t}\n\n"
  },
  {
    "path": "02-Codes/Snippets/Sublime/pbds.sublime-snippet",
    "chars": 671,
    "preview": "<snippet>\n  <content><![CDATA[\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing names"
  },
  {
    "path": "02-Codes/Snippets/Sublime/power-expo.sublime-snippet",
    "chars": 442,
    "preview": "<snippet>\n  <content><![CDATA[\n\n\nlld power(lld x, lld y) {\n\tlld res = 1;\n\n\tx = x % MOD;\n\n\tif (x == 0) return 0;\n\n\twhile "
  },
  {
    "path": "02-Codes/Snippets/Sublime/sieve-of-eratosthene.sublime-snippet",
    "chars": 869,
    "preview": "<snippet>\n  <content><![CDATA[\n\n/* This part should be outside the main in global paradigm. */\n\nconst lld MAXN = (lld)(1"
  },
  {
    "path": "02-Codes/Snippets/Sublime/topcoder-template.sublime-snippet",
    "chars": 2188,
    "preview": "<snippet>\n  <content><![CDATA[\n\n#include <bits/stdc++.h>\nusing namespace std;\n\n\ntypedef long long int lld;\ntypedef unsig"
  },
  {
    "path": "02-Codes/Snippets/mydebug.h",
    "chars": 52157,
    "preview": "// C++ includes used for precompiling -*- C++ -*-\n\n// Copyright (C) 2003-2021 Free Software Foundation, Inc.\n//\n// This "
  },
  {
    "path": "03-Interview Preparation/Docs/.gitkeep",
    "chars": 1,
    "preview": "\n"
  },
  {
    "path": "03-Interview Preparation/PDF/.gitkeep",
    "chars": 1,
    "preview": "\n"
  },
  {
    "path": "03-Interview Preparation/README.md",
    "chars": 166,
    "preview": "⚙️ Under construction ⚙️\n\nAiming to help my fellow coders to clear Technical Interviews.\n\nI have compiled the resources "
  },
  {
    "path": "README.md",
    "chars": 7062,
    "preview": "# All-Of-Competitive-Programming\n\nThis repo contains all the resources a beginner needs to start competitive programming"
  }
]

// ... and 2 more files (download for full content)

About this extraction

This page contains the full source code of the luctivud/All-Of-Competitive-Programming GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 37 files (115.4 KB), approximately 34.4k tokens, and a symbol index with 47 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!