{"id":26520024,"url":"https://github.com/thesobersobber/cp-snippets","last_synced_at":"2026-02-13T12:43:26.804Z","repository":{"id":155419118,"uuid":"602967661","full_name":"theSoberSobber/CP-Snippets","owner":"theSoberSobber","description":"CP-Snippets, will write good doc someday","archived":false,"fork":false,"pushed_at":"2024-12-26T15:45:13.000Z","size":8091,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-26T16:32:00.146Z","etag":null,"topics":["atcoder","codechef","codeforces","competitive-programming","competitive-programming-contests","cpp17","hackerank","hackerearth","pdf","programming","snippets"],"latest_commit_sha":null,"homepage":"https://bit.ly/cpsnippets","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theSoberSobber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-17T10:31:48.000Z","updated_at":"2024-12-26T15:45:16.000Z","dependencies_parsed_at":"2024-02-10T17:30:59.796Z","dependency_job_id":"c9c380e7-116a-41ed-876f-d4599f837574","html_url":"https://github.com/theSoberSobber/CP-Snippets","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoberSobber%2FCP-Snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoberSobber%2FCP-Snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoberSobber%2FCP-Snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theSoberSobber%2FCP-Snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theSoberSobber","download_url":"https://codeload.github.com/theSoberSobber/CP-Snippets/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244794718,"owners_count":20511516,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atcoder","codechef","codeforces","competitive-programming","competitive-programming-contests","cpp17","hackerank","hackerearth","pdf","programming","snippets"],"created_at":"2025-03-21T11:38:34.462Z","updated_at":"2026-02-13T12:43:21.785Z","avatar_url":"https://github.com/theSoberSobber.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"```bash\ncurl -L \"https://raw.githubusercontent.com/theSoberSobber/CP-Snippets/main/snippets.json\" \u003e snippets.json\n```\n---\n# Index - \n\n\n- **[BIT-general](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2)** : easy BIT general with range updates by diff array too \n- **[DSU](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L74)** : DSU \n- **[Efficient-Divsibility-Trick-7-and-13](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L109)** :  used here: https://codeforces.com/contest/2043/problem/B \n- **[ExtendedGcdDiophantine](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L117)** : Diophantine any and all soln \n- **[General-Hash](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L239)** : General Hash functions that returns two hashes, takes in 0 indexed arr or string, allows hash query on range, beware that this uses the decreasing power convention \n- **[Inline-break](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L314)** : Inline Break by defining break to a function that basically breaks but returns value and hence can be used as a expression with comma operator \n- **[LCA-RMQ](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L334)** : LCA using Range Min Query(Sparse) on ETT ([Reference](https://codeforces.com/contest/1975/submission/262585070)) \n- **[PrefSum2D](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L400)** : 2D Prefix Sum \n- **[Segtree-General](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L423)** : General segree, needs node struct (with members def and epsilon(default) for all of them) and operation lambda (merge) \n- **[Simpler-Segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L500)** : Init with an array simply using the build fn, customize operation and epslion in the struct itself, supports point updates and range queries \n- **[Sparse-General](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L554)** : General Implementation of Sparse table with the template\u003cclass T\u003e structure \n- **[Weird_Lazy_Segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L605)** : A lazy segtree taken from a abc340 E mridulahi submission, it's supposed to be able to do range updates and point queries \n- **[Xor-Of-First-N-Natural-Numbers](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L754)** : based on the fact that if n%4==3 then xor till n from 1 is 0 \n- **[arr-inp](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L777)** : arr-inp \n- **[arr-pref](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L785)** : arr-pref \n- **[bfs-dist](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L793)** : bfs that measures levels/dist \n- **[binpow](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L812)** : binpow \n- **[binsearch](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L827)** : binsearch \n- **[bp-small](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L848)** : bp-small \n- **[bp](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L893)** : bp \n- **[clock_for_TL](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L971)** : clock \n- **[combi-mint](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L983)** : combi template with mint \n- **[combi-struct](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1059)** : combi-struct \n- **[combination-non-mod](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1110)** : combination-non-mod \n- **[combination-small](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1127)** : combination-small \n- **[combination](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1143)** : combination \n- **[crt](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1156)** : crt \n- **[cute-lcm](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1180)** : [a,b,c]=abc(a,b,c)/(a,b)(b,c)(c,a), where []=lcm adn ()=gcd or [a,b,c]=abc/gcd(ab,bc,ca) \n- **[derangments](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1190)** : derangments \n- **[dfs-full](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1203)** : dfs with lots of stuff implemented \n- **[dfs](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1233)** : weird ass dfs \n- **[diophantine](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1253)** : linear diophantine \n- **[dsu-rr](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1329)** : dsu-rr \n- **[easy_seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1368)** : easy_seive \n- **[euclid](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1387)** : euclid \n- **[explanation_binsearch](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1412)** : explanation_binsearch \n- **[fac](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1447)** : fac \n- **[factorization](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1461)** : factorization \n- **[fenwick](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1491)** : binary indexed tree \n- **[file_io](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1531)** : for coding competetions \n- **[freq-map](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1541)** : freq-map \n- **[gr-inp-Fwt](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1552)** : graph input weight \n- **[gr-inp](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1565)** : graph input \n- **[highest_exponent](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1578)** : power_in_fac \n- **[interactive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1593)** : essential measures for interactive problems \n- **[ip-overloads](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1618)** : I/O Overloads that I don't use \n- **[kadane](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1635)** : max subarray sum O(n) \n- **[kahn's algo](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1651)** : toposort using bfs (kahn's algo) \n- **[kosaraju](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1673)** : kosaraju \n- **[kruskal](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1753)** : kruskal \n- **[lambda_function](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1774)** : lambda_function \n- **[lca-isAncestor](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1783)** : lca that uses isAncestor instead of level jumping, sets a level upper limit of 25 itself since 2^25 is bigger than any N give anyways \n- **[lca](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1834)** : LCA path satisfying some condition \n- **[log](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1895)** : log \n- **[matrix](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1926)** : matrix \n- **[mint](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L1977)** : modular integer \n- **[modpow](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2036)** : modpow \n- **[pbds](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2052)** : pbds \n- **[pq](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2067)** : pq \n- **[prime-related-stuff](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2075)** : implements prime fac, fac list and is_prime in both space optimized and time optimized ways \n- **[re-write](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2266)** : a bunch of re and write functions based on template meta programming heklpful in cp. \n- **[recur-binsearch](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2288)** : recursive binary search implementation to make intution easier ig \n- **[recur-modpow](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2305)** : recur-modpow \n- **[rng](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2321)** : rng \n- **[rr-segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2330)** : best segtree \n- **[segtree](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2474)** : sextree \n- **[seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2588)** : seive \n- **[splay-tree-rr-sir](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2606)** : used here by rr sir, I have no idea how to use it or what it's used in mostly, [RR Sir ABC F Submission](https://atcoder.jp/contests/abc350/submissions/52600529) \n- **[tokenizer](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2801)** : tokenizer that has no use \n- **[totient-seive](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2808)** : totient-seive \n- **[totient](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2822)** : totient \n- **[trie](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2842)** : trie \n- **[troll](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2878)** : troll \n- **[two-sat (kosaraju)](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L2888)** : two-sat (kosaraju) \n- **[variadic](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L3025)** : variadic lambdas with 1 and 2 arguments \n- **[xor-basis](https://github.com/theSoberSobber/CP-Snippets/blob/main/snippets.json#L3034)** : xor-basis ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesobersobber%2Fcp-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesobersobber%2Fcp-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesobersobber%2Fcp-snippets/lists"}