← Getting started

C++ template

A starting file for every problem. Write your solution inside solve().

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF LLONG_MAX >> 1

void solve(){
    
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll test=1;
    cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

What each part does

  • #include <bits/stdc++.h> Pulls in the whole standard library, so you never hunt for the right header.
  • #define ll long long A shorthand for 64-bit integers, which most problems need.
  • mod and INF The usual modulus 1,000,000,007, and a large value that is safe to add to without overflowing.
  • sync_with_stdio / cin.tie Makes cin and cout fast. Without these, large inputs can time out.
  • test loop Reads the number of test cases and calls solve() once per case. For a problem with one case, delete the cin>>test line.

Make sure you know why each line is there before you rely on it.