Overview
Templates provide starting points for your competitive programming solutions. Each template is optimized for specific contest formats and includes essential utilities.Available Templates
Standard Template
Trigger:template_std
The most comprehensive template for general competitive programming.
- Clean, minimal starting point
- Fast I/O optimization
- Date and author placeholders
- Compatible with all contest formats
- Codeforces rounds
- AtCoder contests
- General practice problems
Header Template
Trigger:template_header
Comprehensive header with optimizations and utility macros.
- Compiler optimization pragmas
- Common macros and shortcuts
- Direction arrays for grid problems
- Min/max utility functions
- Vector I/O operators
- Type aliases
- Complex problems requiring many utilities
- When you need grid navigation
- Problems with lots of container operations
Optimization pragmas only activate on online judges to avoid local debugging issues.
Test Case Template
Trigger:template_cases
Optimized for problems with multiple test cases.
- Clean separation of solve logic
- Handles multiple test cases automatically
- Fast I/O enabled
- Codeforces Division 2/3 problems
- Most AtCoder contests
- Any problem starting with “T test cases”
Google Template
Trigger:template_google
Specialized for Google Code Jam and Kick Start.
- Automatic case numbering
- Proper output format:
Case #X: answer - One-indexed test cases
- Google Code Jam
- Google Kick Start
- Facebook Hacker Cup
USACO Template
Trigger:template_usaco
Optimized for USA Computing Olympiad format.
- File I/O setup
- Reads from
.infile - Writes to
.outfile - Automatic file handling
- USACO contests
- Any competition requiring file I/O
LeetCode Template
Trigger:template_std_leetcode
Class-based structure for LeetCode problems.
- Class-based structure matching LeetCode format
- Easy local testing setup
- Compatible with LeetCode copy-paste
- LeetCode practice
- Interview preparation
- Class-based problem formats
Random Test Template
Trigger:template_random
Generate random test cases for stress testing.
- Proper random number generation
- Utility functions for common random data
- Stress testing helpers
- Finding edge cases
- Comparing brute force vs optimized solutions
- Validating correctness
Use with
random_init, random_vector, and random_permutation snippets for more functionality.Template Selection Guide
Decision Tree
Identify Contest Type
General Contests
Codeforces, AtCoder, etc.→
template_std or template_headerGoogle Competitions
Code Jam, Kick Start→
template_googleUSACO
USA Computing Olympiad→
template_usacoLeetCode
Interview practice→
template_std_leetcodeConsider Problem Format
Single test case:
- Use
template_std
- Use
template_cases
- Use
template_usaco
- Use
template_random
Combining Templates with Snippets
Common Combinations
Graph Problem
Graph Problem
Dynamic Programming
Dynamic Programming
String Problem
String Problem
Geometry Problem
Geometry Problem
Interactive Problem
Interactive Problem
Template Customization
Modifying Templates
You can customize templates for your preferences:Add Your Handle
Custom Macros
Add frequently used macros:Favorite Utilities
Add your most-used functions:Template Best Practices
DO:
- ✅ Always start with a template
- ✅ Use
template_casesfor multiple test cases - ✅ Enable fast I/O for large inputs
- ✅ Use appropriate template for contest format
- ✅ Add
misc_debugduring development - ✅ Remove debug code before submission
DON’T:
- ❌ Disable fast I/O for interactive problems
- ❌ Use Google template for non-Google contests
- ❌ Forget to change USACO filename
- ❌ Submit with debug statements enabled
- ❌ Use unnecessary includes or snippets
- ❌ Modify template structure unless needed
Interactive Problems
For interactive problems, modify the template:Template Cheat Sheet
| Template | Trigger | Use Case | Key Features |
|---|---|---|---|
| Standard | template_std | General purpose | Clean, minimal |
| Header | template_header | Complex problems | Macros, optimizations |
| Cases | template_cases | Multiple test cases | Auto T handling |
template_google | Code Jam, Kick Start | Case numbering | |
| USACO | template_usaco | USACO contests | File I/O |
| LeetCode | template_std_leetcode | Interview prep | Class structure |
| Random | template_random | Stress testing | Random generation |
Common Mistakes
Using Wrong Template for Contest
Using Wrong Template for Contest
Problem: Using
template_std for Google Code JamSolution: Use template_google for proper case numbering:Forgetting to Change USACO Filename
Forgetting to Change USACO Filename
Problem: Submitting with
problemname.in/outSolution: Always update filenames:Fast I/O in Interactive Problems
Fast I/O in Interactive Problems
Problem: Solution hangs or gets wrong answerSolution: Disable fast I/O and use flush:
Including Unnecessary Code
Including Unnecessary Code
Problem: Large template with unused codeSolution: Remove what you don’t need:
- Don’t need direction arrays? Remove them
- Don’t need vector I/O? Remove those operators
- Keep templates minimal for compilation speed
Advanced Usage
Creating Problem-Specific Templates
For recurring problem types, create specialized templates:my_dp_template.cpp
Template Inheritance
Build on existing templates:Next Steps
Snippet Usage
Learn how to efficiently trigger and combine snippets
Competitive Programming
Master contest strategies and best practices
API Reference
Explore all available algorithms and data structures
Quick Start
Build your first solution with snippets