Beta

Write the editorial, not the boilerplate.

CP Lang is a language for competitive programming. It compiles to one readable C++17 file you submit anywhere.

Output
Press Run (Ctrl+Enter).

The limits from the statement are the types. Change 90 to 900 in the input and run: the run stops and names the value.

Compare with the C++ (15 lines against 3)
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    assert(1 <= n && n <= 200000);
    vector<int> a(n);
    long long sum = 0;
    for (int& x : a) {
        cin >> x;
        assert(1 <= x && x <= 100);
        sum += x;
    }
    cout << sum << "\n";
}

A standard library built for contests

Segment trees, shortest paths, union-find and modular arithmetic are one line each. Browse the library (41 modules)

Output
Press Run (Ctrl+Enter).

Point updates and range minimum. You give SegTree the operation; fold takes the range as the statement writes it.

Find the bug in seconds

This solution has a bug. The brute force and the generator live in the same file, so one command finds a failing input, shrinks it, and names the first value that differs. Then you step through both runs side by side.

Output
Press Run (Ctrl+Enter).

Run it on the shrunk case: it prints 1, the answer is 2.

$ cpl stress buy.cp --cases 200 --trace --explain

  brute: buy.cp (`slow`)      checker: none
  FAIL on case 3 (seed 3): WA
  shrunk from 5 numbers to 4:
    3
    1 2 3
  expected:
    2
  got:
    1
  first difference at line 1, token 1: expected `2`, got `1`
  first differing value: `best`, its 3rd value
    solution never gives `best` a 3rd value
    brute    best = 2 at line 22
  trace buy.tests/stress-3.trace.html
  saved buy.tests/stress-3.in

Real output from today's compiler, regenerated on every build.

Time-travel trace of the shrunk casesolution and brute, step by stepOpen full screen

Whole olympiad solutions

Complete solutions to real olympiad problems, next to more of the syntax they rely on. Each carries its status: the ones the compiler does not run yet have no Run button.

let (n, m) = read<(1..=2e5, 1..=2e5)>()
domain V = 1..=n
domain Road = [m]
let roads = read<[Road](u: V, v: V, r: 0..=1e9, p: 0..=1e9)>()
let doomed = V.mask(Graph.directed(roads).transpose().peel())
let g = Graph.directed(roads).only(v => not doomed[v])
let into = g.transpose()
var left = [V] u => g.deg(u)
var need = Settle<Road, Int>(best: max)
for u in V:
    for a in g.out(u):
        need.offer(a.e, a.r)
var ans: [V]?Int = None
while let (road, x) = need.pop():
    let u = roads[road].u
    left[u] -= 1
    if left[u] == 0:
        ans[u] = x
        for a in into.out(u):
            need.offer(a.e, max(a.r, x - a.p))
print(ans, none: -1)

CCO 2021 Travelling Merchant, the whole solution. Peel dead ends off the reversed graph, keep the rest, and settle answers from a heap.

10 linesruns
let (n, m, q) = read<(1..=2e5, 1..=2e5, 1..=2e5)>()
domain V = 1..=n
domain Street = 1..=m
let street = read<[Street](V, V)>()
var deg: [V]Int = 0
for (u, v) in street:
    deg[u] += 1
    deg[v] += 1
for closed in read<[q]Range<Street>>():
    print(deg[street[closed.first!].0], closed.len)

The statement's format and limits are written once. They drive parsing, validation and the width of every value.

Learn it in 30 minutes
One page, every example runs in the browser.
Coming from C++, Python, Java or Rust
Six problems, side by side with what you know.
Look something up
Guides, the language reference and the library.
How fast is it?
Across 107 timed ports, the generated C++ takes a median 0.78x the time of matched hand-written C++ (lower is faster), and 1.98x at p95. The bar is a median of at most 1.1x, p95 at most 1.2x and max at most 1.5x; it isn't met yet. See the full distribution
100 real problems
Accepted C++ next to its CP Lang rewrite, with notes, linking to each judge's statement. Browse the gallery