/shanirez-style:shanirez-stylefrom shanirez-style
ShanireZ's personal C++14 competitive-programming / online-judge coding style. Use whenever the user wants C++ for an algorithm or online-judge problem — pasting a problem statement, asking to solve it or explain it with code, naming a judge problem id (Luogu P*/B*, CodeForces CF*, LOJ #*, PAT, AtCoder ABC*/ARC*/AGC*, SPOJ SP*, UVa UVA*), or asking to write, debug, optimize, or refactor an existing .cpp in the OJCode workspace. Read this first so the code matches the author's own hand (Allman braces, 4-space indent, no blank lines, 1-based, global state, terse names, cin/cout with endl, explicit long long). Do NOT use for general-purpose C++ engineering (GUI/Qt apps, servers/networking, embedded, build systems, library/API design, business-logic debugging) or for non-C++ tasks — those are not OJCode solutions.
Ships in shanirez-style. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A fingerprint of the author's current hand, measured on the OJCode corpus: the 313
single-file solutions added between 2025-11-08 and 2026-11-08 that still exist (309 under
Luogu/, 4 under SP UVA AT/). Every "N of 313" below counts files in that set. Habits that have
dropped out of the last year are deliberately left out of this file; when you edit an older
solution, keep whatever that file already does instead of modernizing it.
Solutions are throwaway scripts: one file, one problem, global state, terse names, no build system, no abstraction layers. Resist the instinct to "engineer" them — no OOP wrappers, no namespaces of your own, no reusable templates, no exceptions, no logging, no test scaffolding.
The dialect is C++14. The reference build is
g++ -std=c++14 -O2 -Wall -m64 -static-libgcc -fexec-charset=UTF-8 -Wl,-stack=1073741824, so don't
reach for C++17/20 library features. The 1 GB stack belongs to that environment and is why tree
algorithms stay recursive; check the target judge's stack budget before relying on deep recursion.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, m, ans, a[100005];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
cout << ans << endl;
return 0;
}
<iostream> (311 of 313) and <algorithm> (310)
are in almost every file; add <vector> (65), <queue> (33), <cstring> (15), <iomanip>
(11), <map> (10), <cmath> (8) as needed. No <bits/stdc++.h> (1 of 313) and no <cstdio>.using namespace std; in every file (313 of 313).int main(). Helpers (dfs, find, query, check…) are free functions above main.int main() (never signed main()), ending in return 0; (313 of 313). No #pragma.These are the owner's rules, not measurements; they hold even where an old file does otherwise.
cin, write with cout. Never scanf, printf, getchar, putchar, or a
hand-written read() / write().ios::sync_with_stdio(false), cin.tie(0), cout.tie(0),
cin.tie(0)->sync_with_stdio(false) or any variant.endl — never '\n' or "\n". A row of values is
cout << a[i] << " "; inside the loop and cout << endl; after it.cout << (ok ? "Yes" : "No") << endl;cout << fixed << setprecision(2) << ans << endl; with <iomanip>
(10 of 313).int T; cin >> T; while (T--) { ... } (25 files; 6 use t). Use
for (int t = 1; t <= T; t++) only when the case number is printed ("Case #" << t << ": ").while (cin >> n).The layout is what clang-format produces under the VS Code C/C++ extension's Visual Studio
fallback style: Allman braces, 4-space indent, SortIncludes on, ColumnLimit: 0.
cout chain stays on one line; never wrap to fit a ruler.The opening { goes on its own line for functions, structs, loops and conditionals, and braces
are never omitted, even for a one-statement if/for/while/else. No K&R line and no
brace-less body appears anywhere in the 313 files.
if (gu != gv)
{
g[gu] = gv, cnt++;
}
249 of 313 files use 4 spaces. The 64 tab-indented files are a burst from one editor setup — 55 of them were added between 2025-11 and 2026-01, and only 9 of the 221 files since 2026-02 use tabs. New file → 4 spaces. Editing a file → keep its existing indentation; never mix the two or reindent a whole file.
A solution is one solid block: 312 of 313 files contain no blank line — not between headers and
globals, not between functions, not inside them. The last byte is the closing } of main, with no
trailing newline (312 of 313).
int a[100005];,
long long sum[500005];. #define MX 500005 (9 of 313) is the only macro form, used when one
bound appears many times. Never const int maxn, typedef, or #define int long long (0 each).long long n, m, ans = 1, base = 233, mod = 1e9 + 7, h1[200005];mod on that line (mod = 1e9 + 7, 8 files), not a macro.
A string-hash base is base = 233 (5 files).queue or priority_queue
declares it at file scope (queue<Node> q;, priority_queue<Path> q;), and string s; is
global in 22 files against 6 local. Clear a reused global between test cases.n m k q T; loop indices i j, with k for a genuine third index such as
Floyd's middle vertex. Index names follow the array dimension (anc[i][j]), not nesting order.u v w for an edge; to for an unweighted adjacency list, es for
vector<Edge>; now for the current node and nxt for the neighbour.h[] (11 files, against 6 for dep[]); parent fa[] when it is stored.ans cnt tot sum res; state vis dis dp f pos id; intervals l r mid.int, not bool: int ok = 1; ... ok = 0; (trig occasionally) — 15 files use
an int flag and none declares a bool variable.Node (27 files), Edge (14), Path (6) — with terse fields
(x y, to w, u v w, lc rc v tag). The global array of a struct is ns
(Node ns[100005];).long long is written out (104 of 313 files). If a few variables share one short
declaration line, make the whole line long long. When many big arrays are involved, widen only
the value-carrying ones and keep indices, depths, ids and flags int.for (int i = 1; i <= n; i++) outnumbers for (int i = 0; i < n; i++) 519 to 59. Arrays are used as
a[1..n] and sorted with sort(a + 1, a + n + 1). Use 0-based indexing only for natively 0-based
data — string characters, bitmask bits, a string s[] grid — and cast .size() to int in loop
bounds.
g[gu] = gv, ans += e.w, cnt++;
vis[nx][ny] = 1, dis[nx][ny] = dis[x][y] + 1;
check(mid) ? l = mid + 1 : r = mid - 1;
cout << (ans == 1e9 ? -1 : ans) << endl;
1e9 (27 files) and 1e18 (12), assigned and compared directly. To
fill a whole array use memset(dis, 0x3f, sizeof(dis)) (9 files, <cstring>) and compare against
0x3f3f3f3f. Never INT_MAX, LLONG_MAX or #define INF (0).|| rather than a
staircase of early exits:
int l = lca(x, y);
if (a[x] == 0 || z[x] + z[y] - 2 * z[l] > 0)
{
cout << "Yes" << endl;
continue;
}
.size(), never .empty() (0 of 313): while (q.size()), if (v.size()).vector named for its payload: vector<int> to[100005]
(17 files) when the element is the neighbour, vector<Edge> es[100005] (10) when it is an edge
record, and a flat vector<Edge> es; for an edge list that gets sorted (Kruskal). Push with
push_back (60 files; emplace_back 0). Walk it with range-for:
for (int nxt : to[now]), for (Edge e : es[now]).vis[]: void dfs(int now, int from) and
if (nxt == from) continue; first thing in the loop (8 files). When the parent is needed later,
store it in fa[] and skip nxt == fa[now].ms[4][2] table and nx/ny, never dx/dy. The grid is usually a
0-based string s[1005], so bounds read nx < 0 || nx >= n.g[] plus find with path compression, merged inline:
int gu = find(u), gv = find(v); if (gu != gv) { g[gu] = gv, cnt++; }.val(x, 2) / val(x, 5), not
val2 / val5.(long long)a * b with two ints).bool operator<(const T &oth) const (17 of the 24 files that define one use exactly this
signature). A one-off order, or several orders over the same data, gets a free comparator that
takes its arguments by value: bool cmp(Edge a, Edge b), or cmpid / cmpv side by side.
Sort 1-based ranges (sort(ns + 1, ns + n + 1, cmp)) or a flat vector
(sort(es.begin(), es.end(), cmp)). No lambdas (0 of 313); auto is essentially unused (1).operator<; a min-heap of scalars is
priority_queue<int, vector<int>, greater<int>> q;.Sparse — 31 of 313 files have any. A short Chinese (UTF-8) note for a non-obvious step or a
derivation, usually trailing on the same line (52 trailing lines against 20 standalone). No
block comments (/* */, 0 files). Don't narrate the code line by line, and don't append a tag or
signature line after main.
Luogu/, CodeForces/, LOJ/, PAT/Basic/,
PAT/Advanced/, SP UVA AT/.P3372.cpp, B4339.cpp, T777250.cpp, CF1009F.cpp,
#10000.cpp, ABC403G.cpp, UVA10079.cpp, SP1043.cpp.P3367 Dfn.cpp, P3372 Zkw.cpp, P9753 90pts.cpp.For a standard structure or algorithm, use the forms in
references/templates.md — DSU and Kruskal, closed-interval binary
search, Fenwick tree, lazy segment tree, graph storage, Dijkstra, binary-lifting LCA, grid BFS,
struct sorting and the multi-test scaffold. They already follow every rule above; copy the shape,
including the density.
scanf, printf, getchar, putchar, a hand-written read()/write(), or any
sync_with_stdio / cin.tie / cout.tie line.'\n' or "\n" as a line terminator — always endl.}.#include <bits/stdc++.h> or <cstdio>.if/for/while/else.#define int long long, typedef long long ll, const int maxn, #define mid, #define MOD,
#define INF, INT_MAX/LLONG_MAX — use explicit long long, inline bounds (or #define MX),
a global mod variable and 1e9/1e18.while (!q.empty()) — write while (q.size()).emplace_back, lambdas, auto, pair-based queues, or chained-forward-star edge arrays.dx/dy — the table is ms[4][2], the target cell nx/ny.bool flags with long names (isFound, parentArray) — int ok, fa, now.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub shanirez/aptinery --plugin shanirez-style