Code templates
A template is the starter code that drops into the editor the first time you open a problem in a given language. cf-mirror ships with sensible defaults; this page shows how to write your own.
Where do I edit them?
Open Settings → Templates. Pick a language from the dropdown, edit the body, hit Save (or Ctrl+S). The next time you open a problem of that language for the first time, your template will be used.
Already-opened problems keep whatever code they have — to apply a new template retroactively, use the new ⟲ Reset button on the problem-page editor.
Variables you can use
Each variable is wrapped in $DOLLAR$ markers. They're expanded once, at the moment the file is scaffolded.
| Variable | Example expansion |
|---|---|
| $NAME$ | Watermelon |
| $URL$ | https://codeforces.com/contest/4/problem/A |
| $ID$ | 4A |
| $DATE$ | 2026-06-26 |
| $TIME$ | 14:03:21 |
| $LANG$ | cpp |
| $CURSOR$ | (the editor cursor lands here after open) |
Example — pragmatic C++ template
/**
* $NAME$ · $ID$
* $URL$
* solved on $DATE$ at $TIME$
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
$CURSOR$
}
return 0;
}The $CURSOR$ marker is consumed during expansion — it's where the cursor lands the first time you open the file. Useful for jumping straight intowhile (t--) { }.
Example — Python template
# $NAME$ · $ID$ · $URL$
import sys
input = sys.stdin.readline
def solve():
$CURSOR$
t = 1
# t = int(input())
for _ in range(t):
solve()What templates DON'T do
- They don't re-apply to problems you've already opened. Hit ⟲ Reset on the problem page to force a re-expansion of the current template.
- They don't affect submitted code. Whatever's in the editor at submit time is what gets sent (with the template scaffolding intact unless you've edited it).
- They don't auto-update across already-open tabs. New tabs get the new template; old ones stay on the old saved code.
Snippets vs Templates — what's the difference?
A template is the WHOLE file you start with. A snippet is a chunk you summon mid-file by typing a trigger and hitting Tab. Both live under Settings; snippets get their own tab.
Example: keep your template minimal (headers + main + cursor), then use snippets to drop in DSU, segtree, modint, etc. when you actually need them. See the stress test docs for a worked example that uses snippets.