This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <bits/stdc++.h>
using namespace std;
// 推规律,1行j列为j,n行j列为3n-j-1,1行i列为4n-i-2,n行i列为n+i-1。
int dfs(int n, int i, int j) {
if (i == 1) return j;
if (i == n) return 3 * n - j - 1;
if (j == 1) return 4 * n - i - 2;
if (j == n) return n + i - 1;
return dfs(n - 2, i - 1, j - 1) + (n - 1) * 4;
}
int main() {
int n, a, b;
cin >> n >> a >> b;
cout << dfs(n, a, b) << endl;
return 0;