# Analyzing programming contest grandmasters' styles and tools - Gennady Korotkevich (tourist) vs Andrew He (ecnerwala) (2023-03-24)

**URL:** <https://pluralist.net/t/analyzing-programming-contest-grandmasters-styles-and-tools-gennady-korotkevich-tourist-vs-andrew-he-ecnerwala-2023-03-24/121>\
**Category:** Code Reading\
**Created:** [March 24, 2024, 8:44pm UTC](https://pluralist.net/t/analyzing-programming-contest-grandmasters-styles-and-tools-gennady-korotkevich-tourist-vs-andrew-he-ecnerwala-2023-03-24/121 "2024-03-24T20:44:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![delyan](https://pluralist.net/user_avatar/pluralist.net/delyan/32/245_2.png) [@delyan](https://pluralist.net/u/delyan)\
**Post date:** [March 24, 2024, 8:44pm UTC](https://pluralist.net/t/analyzing-programming-contest-grandmasters-styles-and-tools-gennady-korotkevich-tourist-vs-andrew-he-ecnerwala-2023-03-24/121/1 "2024-03-24T20:44:24Z")

</div>

This post is a commentary and analysis based on **[this video](https://www.youtube.com/watch?v=bBNIIg8REUU)**, which shows a **[competition](https://atcoder.jp/contests/abc166/tasks/abc166_e)** between Gennady Korotkevich ([tourist](https://codeforces.com/profile/tourist)) and Andrew He ([ecnerwala](https://codeforces.com/profile/ecnerwala)):

Watch the video here: [https://www.youtube.com/watch?v=bBNIIg8REUU](https://www.youtube.com/watch?v=bBNIIg8REUU)

* * *

 ![image](https://pluralist.net/uploads/default/original/1X/8410db8445c9b9b7edbf49bc3fc1b1349c597d8e.jpeg)

* * *

# Gena’s Code

ChatGPT 4 was used to recover the first 6 characters from Gena’s code snippet.  
We see on the screen

 ![image](https://pluralist.net/uploads/default/original/1X/027cbc80e9ecb1192ab3a1d0edb40e6f258f6405.png)

So we know that "`using `" is missing in the first line of `using namespace std;` etc. (6 characters)  
We also know that tourist tends to start his solutions with [the following comment](https://github.com/draychev/competitive-programming/blob/f4b0044182f1d9280841c01e7eca4ad882875bca/codechef/alkhwarizm18/harrydh1_tourist.cpp#L1-L8):

```c++
/**
 * author: tourist
 * created: 16.03.2018 20:33:14       
**/
#include <bits/stdc++.h>
 
using namespace std;

```

Gena also has a template for his `main` function:

```c++
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  /* solution goes here */
  return 0;
}

```

 ![image](https://pluralist.net/uploads/default/original/1X/1b87099e017cf74687caaef5a3fef8ef06b82970.jpeg)

So the code from the screenshot above is most likely this:

```c++
/**
 * author: tourist
 * created: 10.05.2020 20:33:59       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    map<int, int> mp;
    long long ans = 0;
    
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        ans += mp[i - a];
        mp[i + a]++;
    }
    
    cout << ans << '\n';
    
    return 0;
}

```

* * *

# Andrew’s code

 ![image](https://pluralist.net/uploads/default/original/1X/6e93660d51c20c46b4e2f0c1c8aeccee511f3911.jpeg)

```c++
#include <bits/stdc++.h>

int main() {
    using namespace std;
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }

    int64_t ans = 0;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        // H[i] + H[j] = i - j
        ans += mp[H[i] - i];
    }

    cout << ans << '\n';
    return 0;
}

```

* * *

# Toolboxes (or Who Uses What to Compete)

## What’s in Gena’s Toolbox

Lets find out what Gennady Korotkevich uses for programming competitions.  
Here is what Gena uses and how he operates:

- OS: Windows 10
- browsers: Firefox, Chrome
- no apparent version control (VCS) system
- [MinGW](https://nuwen.net/mingw.html)
- [C++ (GCC 9.2.1)](https://gcc.gnu.org/) (what [atcoder.jp](https://atcoder.jp/contests/abc166/tasks/abc166_e) uses to evaluate)
- IDE/Editor: [Far Manager](https://www.farmanager.com/) (version 3.0.4900 x64 (as of May 2020))
- Gena does not have a shortcut for executing `sol.exe` with test input
  - he’s a fast typist
  - leverages FAR’s history  
 ![image](https://pluralist.net/uploads/default/original/1X/a60cbc0514906e5daaf65339ed801f90e17df5dd.jpeg)

### Gena’s Setup:

- has some automation to create the directories for the competition ahead of time:  
 ![image](https://pluralist.net/uploads/default/original/1X/70106e86a0e704053cb53b54685e56af6b2865d2.png)
- compiles with: `C:\MinGW\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe`
- executes the solution with: `sol.exe <in1`
- based on the May 2020 video above there is no automation to submit the code. Gena copy/pastes from Far Manager to [the competition website](https://atcoder.jp/contests/abc166/tasks/abc166_e):  
 ![image](https://pluralist.net/uploads/default/original/1X/d84e597142c8183684d4580ab5af4ea89dd1ac32.jpeg) → ![image](https://pluralist.net/uploads/default/original/1X/30063b8dd2ab73af8f31cc07fb0a71bb95aeea0f.jpeg)

* * *

## What’s in Andrew He’s toolbox

- OS: macOS
- IDE/Editor: [NVIM / NeoVIM](https://neovim.io/)
  - NeoVIM Solarized Light Theme

Andrew uses automation `download_prob.py` to speed up the setup for the contest:

 ![image](https://pluralist.net/uploads/default/original/1X/656dd50d08979a12611be42392b67999d3e0e53b.jpeg)

Andrew compiles with some iteration of:

```bash
g++ -std=c++17 -O2 -Wall -Wextra -pedantic -Wshadow -Wformat=2 \
  -Wfloat-equal -Wconversion -Wlogical-op -Wcast-qual -Wcast-align \
  -Wno-unused-result -Wno-sign-conversion \
  -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 \
  F.cpp -o F

```

What are all these flags?

- `-std=c++17` sets the C++ standard to C++17.
- `-O2` enables compiler optimizations.
- `-Wall` enables all the warnings about constructions that are easy to avoid.
- `-Wextra` enables extra warnings not covered by `-Wall`.
- `-pedantic` ensures that the code adheres strictly to the standard.
- `-Wshadow` warns whenever a local variable shadows another variable.
- `-Wformat=2` adds extra checks for `printf`/`scanf`, etc.
- `-Wfloat-equal` warns if floating-point values are compared for equality.
- `-Wconversion` warns for implicit conversions that may alter a value.
- `-Wlogical-op` warns about suspicious uses of logical operators.
- `-Wcast-qual` warns when a cast removes an attribute like `const` or `volatile`.
- `-Wcast-align` warns where pointer casts increase alignment requirements.
- `-Wno-unused-result` disables warnings for unused results.
- `-Wno-sign-conversion` turns off warnings related to sign conversions.
- `-D_GLIBCXX_DEBUG` enables macros for the debug version of the standard library.
- `-D_GLIBCXX_DEBUG_PEDANTIC` is an even more pedantic version of the above.
- `-D_FORTIFY_SOURCE=2` adds security checks to detect buffer overflows.
- `F.cpp` is the input source file to compile.
- `-o F` specifies the output file name for the compiled executable.

It is interesting that Andrew keeps his competition solutions in a Dropbox folder → ![image](https://pluralist.net/uploads/default/original/1X/40a2e697b51c0572d428dda2c51ce0e7775c244c.png)

```sh
~/Dropbox/programming/AtCoder/ABC166/D

```

Andrew’s files are under git revision control → ![image](https://pluralist.net/uploads/default/original/1X/d73caa2fa920df096e454eb10438ca74b3b3aa10.png)

 ![image](https://pluralist.net/uploads/default/original/1X/05ba786c419dfc5b0a061f56367e92d5247ac352.jpeg)

It is unclear from the video whether Andrew uses automation to submit his code to the judge or will do it manually (copy/paste from terminal?).

* * *

# Far Manager

## Configure Far Manager

- here is an excellent guide: [https://codeforces.com/blog/entry/21669](https://codeforces.com/blog/entry/21669)

1. Create file associations in Far Manager.

- Menu (`F9`) → Commands (`C`) → File associations (`A`)
- Create a new file association (`Insert`):
  - mask: `*.cc` (or however you name your C++ files)
  - execute command for Enter: `C:\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe`
  - execute command for Ctrl+PgDn: `C:\MinGW\bin\g++.exe -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 !.! -o !.exe -DDEBUG -g`

 ![image](https://pluralist.net/uploads/default/original/1X/20f17c8c7f8ea4776d9c44491a6859175b0af680.png)

Press Enter on your `sol.cc` file to execute command `g++ -O2 -Wall -Wl,--stack=268435456 -Wextra -std=c++17 sol.cpp -o sol.exe`. This will compile the C++ code from `sol.cc` to an executable `sol.exe`. This assumes that you have `C:\MinGW\bin\g++.exe`. (Get [MinGW from Nuwen.net](https://nuwen.net/mingw.html))

Alternatively you can record the keystrokes necessary to do this operation and bind them to a **hotkey** (such as `F9`). [Here are the instructions.](https://documentation.help/macroapi/documentation.pdf#page=95)

* * *

### Far Manager Shortcuts

- `Ctrl-A` - file attributes (equivalen\* t to F9, F, A)
- `Alt-F9` - maximize window
- `Alt-Shift-F9` - configure plugins
- Ctrl-Alt-Shift - hide windows while the keys are held
- F4 on a folder - edit folders attributes (ctrl-a)
- alt-left, right, home, end - scroll long names
- ctrl-ins - copy names of the selected files into clipboard (command line empty, ctrl-shift-ins if not empty)
- ctrl-alt-ins - copy network (unc) names into clipboard
- alt-shift-ins - copy full (with path) names into clipboard
- ctrl-f - full file name from the actve panel, crtl-: from passive (equiv to crtl-], ctrl-enter)
- ctrl-end - command string completion from the history (press again to go to the next matching history line)
- alt-f8 - command history
- alt-f10 - find folder
- alt-f11 - view and edit history
- alt-f12 - folder history
- shift-f1,f2,f3 - archive management commands
- shift-f10 - show the last menu command
- ctrl-\ - back to root
- shift-enter in the drive menu - show root directory in explorer
- ctrl-pgdn - enter in an archive/especially SFX
- ctrl-g - run command on selected files, like “rar32 m !.!.rar !.!” to rar each file in its own archive
- alt-ins - screen grabber
- ctrl-“gray .” - record a keyboard macro
- alt-del - wipe file, overwrite with 0, trunicate, rename to a temp name and delete.
- ctrl-w - task list
- ctrl-tab F12 - switch panes (screens) inside of far
- ctrl-f full file name into the command line
- alt shift ins full file name into clipboard for selected files
- ctrl alt ins unc names into clipboard of the selected files
- ctrl ins name into clipboard of the selected files if no cmd line
- ctrl shift ins name into clipboard of the selected files always
- ctrl m restore previous selection
- ctrl enter in quick search (alt-letter) selects file and moves to the next
- shift enter in history selects an item not changing its positions
- In the drive menu - Shift - Del to disconnect Flash, Del remove a CD.
- Ctrl-. to start recording macro. Ctrl-. again to end and assign a key
- To erase a macro do Ctrl-. twice then use the key you want to erase.

* * *

### FAR Shortcuts Printout

([source](https://cheatography.com/alexzaitzev/cheat-sheets/far-3/))

 ![image](https://pluralist.net/uploads/default/original/1X/c1d018028a3b64d913c908e84d12c51e5be46799.png)

* * *

# Links

- [E - This Message Will Self-Destruct in 5s](https://atcoder.jp/contests/abc166/tasks/abc166_e)
- [MinGW Distro - nuwen.net](https://nuwen.net/mingw.html)
- [https://www.farmanager.com/download.php](https://www.farmanager.com/download.php)
- [https://www.youtube.com/watch?v=bBNIIg8REUU](https://www.youtube.com/watch?v=bBNIIg8REUU)
- [https://codeforces.com/](https://codeforces.com/)
