> ## Documentation Index
> Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Codeforces Survival Guide

> Everything LeetCode users need to know about Codeforces—ratings, contests, and how to not get destroyed

# Codeforces Survival Guide

## From LeetCode to Codeforces

You've grinded LeetCode. You understand algorithms. But Codeforces? It's a different beast. This guide will help you survive and thrive.

***

## Understanding the Rating System

### Rating Colors & Titles

| Rating    | Title                     | Color     | What It Means         |
| --------- | ------------------------- | --------- | --------------------- |
| 0-1199    | Newbie                    | Gray      | Just starting out     |
| 1200-1399 | Pupil                     | Green     | Understand basics     |
| 1400-1599 | Specialist                | Cyan      | Solid fundamentals    |
| 1600-1899 | Expert                    | Blue      | Strong problem solver |
| 1900-2099 | Candidate Master          | Violet    | Very strong           |
| 2100-2299 | Master                    | Orange    | Top competitor        |
| 2300-2399 | International Master      | Orange    | Elite                 |
| 2400-2599 | Grandmaster               | Red       | World class           |
| 2600-2999 | International Grandmaster | Red       | Legend                |
| 3000+     | Legendary Grandmaster     | Black/Red | Mythical              |

### Rating Changes

```
Rating Change = K × (Actual Score - Expected Score)

Where:
- K depends on your rating and contest participation
- New accounts have higher K (faster rating changes)
- Expected score based on your current rating vs opponents
```

**Pro Tip**: Your first 6 contests have inflated K values. Focus on performing well early!

***

## Contest Types

### Division 4 (Div 4)

* **Who**: Rated \< 1400
* **Difficulty**: A (800) to G (1400)
* **Duration**: 2 hours, 7-8 problems
* **Strategy**: Solve A-E quickly, attempt F-G
* **Best for**: Complete beginners, first-time CF users, building confidence
* **Frequency**: Every 4-6 months (less frequent than Div 2/3)

### Division 3 (Div 3)

* **Who**: Rated \< 1600
* **Difficulty**: A (800) to F (1600)
* **Duration**: 2 hours, 6-7 problems
* **Strategy**: Solve A-D quickly, attempt E-F
* **Best for**: Beginners who are comfortable with basics

### Division 2 (Div 2)

* **Who**: Rated \< 2100
* **Difficulty**: A (800-1000) to E/F (2000+)
* **Duration**: 2 hours, 5-6 problems
* **Strategy**: Solve A-C, attempt D
* **Best for**: Reaching Specialist/Expert

### Division 1+2 (Combined)

* **Who**: Everyone is rated (no rating cutoff)
* **Difficulty**: A (1000-1200) to F/G (2400+)
* **Duration**: 2-2.5 hours, 6-7 problems
* **Strategy**: Same problems for all participants
* **Best for**: Intermediate difficulty between Div 2 and Div 1
* **Note**: A-B problems are harder than typical Div 2 A-B

### Division 1 (Div 1)

* **Who**: Rated ≥ 1900
* **Difficulty**: Starts at \~1700
* **Best for**: Expert+ grinders

### Educational Rounds

* **Rated**: For all \< 2100
* **Special**: 12-hour hacking phase after
* **Format**: Similar to Div 2

### Global Rounds

* **Who**: Everyone rated
* **Difficulty**: Wide range
* **Duration**: Usually 2.5-3 hours

***

## The Contest Interface

### Before Contest

```
┌─────────────────────────────────────────────┐
│  1. Register for the contest                │
│  2. Check your template compiles            │
│  3. Have input.txt ready                    │
│  4. Close distracting tabs                  │
│  5. Get water/snacks ready                  │
└─────────────────────────────────────────────┘
```

### During Contest

```
Problems     → List of all problems
Standings    → Real-time leaderboard
Submit       → Submit your solution
My Submissions → Check verdicts
```

### Verdict Meanings

| Verdict | Meaning               | What to Do                     |
| ------- | --------------------- | ------------------------------ |
| **AC**  | Accepted (pretests)   | Wait for system test           |
| **WA**  | Wrong Answer          | Check logic, edge cases        |
| **TLE** | Time Limit Exceeded   | Optimize algorithm             |
| **MLE** | Memory Limit Exceeded | Use less memory                |
| **RE**  | Runtime Error         | Array bounds, division by zero |
| **CE**  | Compilation Error     | Syntax error                   |

<Warning>
  **PRETESTS ≠ ACCEPTED**

  During contest, you only pass pretests. After contest ends, your solution runs on the full test set (system test). Many solutions fail system tests!
</Warning>

***

## Reading CF Problems

### Anatomy of a CF Problem

```
┌─────────────────────────────────────────────────────┐
│  PROBLEM TITLE                                      │
├─────────────────────────────────────────────────────┤
│  Time limit: 1 second                               │
│  Memory limit: 256 megabytes                        │
├─────────────────────────────────────────────────────┤
│  [Story/Context - often skip-able]                  │
│                                                     │
│  [Actual problem statement - READ CAREFULLY]        │
│                                                     │
│  [Constraints - VERY IMPORTANT]                     │
├─────────────────────────────────────────────────────┤
│  Input                                              │
│  [Input format description]                         │
│                                                     │
│  Output                                             │
│  [Output format description]                        │
├─────────────────────────────────────────────────────┤
│  Examples                                           │
│  Input:         Output:                             │
│  3              6                                   │
│  1 2 3                                              │
├─────────────────────────────────────────────────────┤
│  Note                                               │
│  [Explanation of examples - very helpful!]          │
└─────────────────────────────────────────────────────┘
```

### How to Read (The Right Way)

<Steps>
  <Step title="Skim the Story (10 seconds)">
    Most CF problems have elaborate stories. Skim for keywords.
  </Step>

  <Step title="Read Constraints FIRST (30 seconds)">
    This tells you what complexity is acceptable.

    * n ≤ 100 → O(n³) OK
    * n ≤ 10⁵ → Need O(n log n) or O(n)
    * n ≤ 10⁶ → Must be O(n)
  </Step>

  <Step title="Read Problem Statement (1-2 minutes)">
    Understand what you need to compute/output.
  </Step>

  <Step title="Study Examples (1 minute)">
    Trace through by hand. Read the Note section!
  </Step>

  <Step title="Check Edge Cases">
    What if n=1? What if all elements are same?
  </Step>
</Steps>

***

## Input/Output Differences from LeetCode

### LeetCode Style

```python theme={null}
class Solution:
    def solve(self, nums: List[int]) -> int:
        return sum(nums)
```

### Codeforces Style

```cpp theme={null}
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    
    long long sum = 0;
    for (int x : nums) sum += x;
    
    cout << sum << "\n";
    
    return 0;
}
```

### Multiple Test Cases

**Most CF problems have multiple test cases!**

```cpp theme={null}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    
    while (t--) {
        // Solve one test case
        int n;
        cin >> n;
        // ... solution ...
        cout << answer << "\n";
    }
    
    return 0;
}
```

<Warning>
  **Common Mistake**: Forgetting to reset variables between test cases!

  ```cpp theme={null}
  // WRONG - 'seen' accumulates across test cases
  set<int> seen;  // Global

  void solve() {
      // seen still has data from previous test case!
  }

  // CORRECT - reset or declare inside
  void solve() {
      set<int> seen;  // Fresh each time
      // ...
  }
  ```
</Warning>

***

## Common CF Input Patterns

### Pattern 1: Single Line of Numbers

```
Input:
5
1 2 3 4 5
```

```cpp theme={null}
int n;
cin >> n;
vector<int> a(n);
for (int& x : a) cin >> x;
```

### Pattern 2: Matrix/Grid

```
Input:
3 4
1 2 3 4
5 6 7 8
9 10 11 12
```

```cpp theme={null}
int n, m;
cin >> n >> m;
vector<vector<int>> grid(n, vector<int>(m));
for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
        cin >> grid[i][j];
```

### Pattern 3: String Grid

```
Input:
3 3
...
.#.
...
```

```cpp theme={null}
int n, m;
cin >> n >> m;
vector<string> grid(n);
for (int i = 0; i < n; i++) cin >> grid[i];
// Access: grid[i][j]
```

### Pattern 4: Graph Edges

```
Input:
4 5
1 2
2 3
3 4
4 1
1 3
```

```cpp theme={null}
int n, m;
cin >> n >> m;
vector<vector<int>> adj(n + 1);
for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);  // If undirected
}
```

### Pattern 5: Queries

```
Input:
5 3
1 2 3 4 5
1 3
2 4
1 5
```

```cpp theme={null}
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int& x : a) cin >> x;

while (q--) {
    int l, r;
    cin >> l >> r;
    // Process query [l, r]
}
```

***

## Output Patterns

### YES/NO Questions

```cpp theme={null}
// Always check problem for exact format
cout << (condition ? "YES" : "NO") << "\n";
// Some problems want "Yes"/"No" or "yes"/"no"
```

### Impossible Cases

```cpp theme={null}
if (impossible) {
    cout << -1 << "\n";  // or "NO" or "Impossible"
    return;
}
```

### Floating Point

```cpp theme={null}
cout << fixed << setprecision(9) << answer << "\n";
```

### Multiple Values

```cpp theme={null}
cout << a << " " << b << " " << c << "\n";

// Array output
for (int i = 0; i < n; i++) {
    cout << arr[i] << " \n"[i == n - 1];
}
```

***

## Debugging on Codeforces

### Using Custom Test

1. After submitting (or before), go to problem page
2. Scroll down to "Custom Test"
3. Enter your test case
4. Run and see output

### Creating Test Cases

When you get WA, try:

1. **Edge cases**: n=1, n=2, all same, all different
2. **Boundary values**: Maximum n, minimum values
3. **Special patterns**: Sorted, reverse sorted, alternating

### Stress Testing

Compare your solution with a brute force on random inputs:

```cpp theme={null}
// Generate random test
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n = rng() % 10 + 1;
vector<int> a(n);
for (int& x : a) x = rng() % 100;
```

***

## Your First Week Checklist

<Steps>
  <Step title="Create Account">
    Register at [codeforces.com](https://codeforces.com)
  </Step>

  <Step title="Set Up Environment">
    Install VS Code + extensions + template
  </Step>

  <Step title="Solve 10 Problems Rated 800">
    Get comfortable with the format
  </Step>

  <Step title="Do a Virtual Contest">
    Go to Contests → Pick a past contest → Click "Virtual Participation" on the right sidebar
  </Step>

  <Step title="Participate in Live Contest">
    Register for next Div 3 or Div 4
  </Step>

  <Step title="Upsolve">
    Solve problems you couldn't during contest
  </Step>
</Steps>

***

## Essential Links

| Resource                                          | Purpose                 |
| ------------------------------------------------- | ----------------------- |
| [Problemset](https://codeforces.com/problemset)   | Filter by rating/tags   |
| [Gym](https://codeforces.com/gyms)                | Practice contests       |
| [EDU Section](https://codeforces.com/edu/courses) | Interactive courses     |
| [Blog](https://codeforces.com/blog)               | Editorials, discussions |
| [CSES](https://cses.fi/problemset/)               | Structured problem set  |

***

## Key Takeaways

<CardGroup cols={2}>
  <Card title="Read Constraints First" icon="ruler">
    Constraints tell you what algorithm to use.
  </Card>

  <Card title="Handle Test Cases" icon="repeat">
    Most problems have multiple test cases.
  </Card>

  <Card title="Use Fast I/O" icon="bolt">
    Always use sync\_with\_stdio(false).
  </Card>

  <Card title="Upsolve Everything" icon="graduation-cap">
    Learning happens after the contest.
  </Card>
</CardGroup>

***

## Next Up

<Card title="Fast I/O & Templates" icon="arrow-right" href="/courses/competitive-programming/02-fast-io">
  Set up your competitive programming template.
</Card>
