#include "bits/stdc++.h"
#define task "Tank"
#define endl '\n'
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using vi = vector <ll>;
bool maxi(auto &u, auto v)
{
if (u >= v) return 0;
return u = v, true;
}
bool mini(auto &u, auto v)
{
if (u <= v) return 0;
return u = v, true;
}
const int MOD = 1e9 + 7;
const int base = 311;
const int N = 1e6 + 6;
int n, k;
string s;
vi HashA, HashB, Pow;
ll Get1(int l, int r)
{
return (HashA[r] - 1ll * HashA[l - 1] * Pow[r - l + 1] + 1ll * MOD * MOD) % MOD;
}
ll Get2(int l, int r)
{
return (HashB[l] - 1ll * HashB[r + 1] * Pow[r - l + 1] + 1ll * MOD * MOD) % MOD;
}
void Solve()
{
string t = s;
n *= k;
for (int i = 1; i < k; ++i)
s += t;
HashA.assign(n + 2, 0);
HashB.assign(n + 2, 0);
Pow.assign(n + 2, 0);
Pow[0] = 1;
s = ' ' + s;
for (int i = 1; i <= n; ++i)
{
Pow[i] = 1ll * Pow[i - 1] * base % MOD;
HashA[i] = (1ll * HashA[i - 1] * base + s[i]) % MOD;
}
for (int i = n; i >= 1; --i)
HashB[i] = (1ll * HashB[i + 1] * base + s[i]) % MOD;
int ans = 1;
/// Le
for (int i = 1; i <= n; ++i)
{
int l = 1, r = min(i - 1, n - i);
while (l <= r)
{
int mid = l + r >> 1;
if (Get1(i, i + mid) == Get2(i - mid, i))
maxi(ans, 2 * mid + 1), l = mid + 1;
else r = mid - 1;
}
}
/// Chan
for (int i = 1; i <= n - 1; ++i)
{
int l = 1, r = min(i, n - i);
while (l <= r)
{
int mid = l + r >> 1;
if (Get1(i + 1, i + mid) == Get2(i - mid + 1, i))
maxi(ans, 2 * mid), l = mid + 1;
else r = mid - 1;
}
}
cout << ans;
}
signed main()
{
if (fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n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gICAgIHMgKz0gdDsKCiAgICBIYXNoQS5hc3NpZ24obiArIDIsIDApOwogICAgSGFzaEIuYXNzaWduKG4gKyAyLCAwKTsKICAgIFBvdy5hc3NpZ24obiArIDIsIDApOwogICAgUG93WzBdID0gMTsKICAgIHMgPSAnICcgKyBzOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgewogICAgICAgIFBvd1tpXSA9IDFsbCAqIFBvd1tpIC0gMV0gKiBiYXNlICUgTU9EOwogICAgICAgIEhhc2hBW2ldID0gKDFsbCAqIEhhc2hBW2kgLSAxXSAqIGJhc2UgKyBzW2ldKSAlIE1PRDsKICAgIH0KICAgIGZvciAoaW50IGkgPSBuOyBpID49IDE7IC0taSkKICAgICAgICBIYXNoQltpXSA9ICgxbGwgKiBIYXNoQltpICsgMV0gKiBiYXNlICsgc1tpXSkgJSBNT0Q7CgogICAgaW50IGFucyA9IDE7CgogICAgLy8vIExlCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpCiAgICB7CiAgICAgICAgaW50IGwgPSAxLCByID0gbWluKGkgLSAxLCBuIC0gaSk7CiAgICAgICAgd2hpbGUgKGwgPD0gcikKICAgICAgICB7CiAgICAgICAgICAgIGludCBtaWQgPSBsICsgciA+PiAxOwogICAgICAgICAgICBpZiAoR2V0MShpLCBpICsgbWlkKSA9PSBHZXQyKGkgLSBtaWQsIGkpKQogICAgICAgICAgICAgICAgbWF4aShhbnMsIDIgKiBtaWQgKyAxKSwgbCA9IG1pZCArIDE7CiAgICAgICAgICAgIGVsc2UgciA9IG1pZCAtIDE7CiAgICAgICAgfQogICAgfQoKICAgIC8vLyBDaGFuCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuIC0gMTsgKytpKQogICAgewogICAgICAgIGludCBsID0gMSwgciA9IG1pbihpLCBuIC0gaSk7CiAgICAgICAgd2hpbGUgKGwgPD0gcikKICAgICAgICB7CiAgICAgICAgICAgIGludCBtaWQgPSBsICsgciA+PiAxOwogICAgICAgICAgICBpZiAoR2V0MShpICsgMSwgaSArIG1pZCkgPT0gR2V0MihpIC0gbWlkICsgMSwgaSkpCiAgICAgICAgICAgICAgICBtYXhpKGFucywgMiAqIG1pZCksIGwgPSBtaWQgKyAxOwogICAgICAgICAgICBlbHNlIHIgPSBtaWQgLSAxOwogICAgICAgIH0KICAgIH0KCiAgICBjb3V0IDw8IGFuczsKfQoKc2lnbmVkIG1haW4oKQp7CiAgICBpZiAoZm9wZW4odGFzayIuaW5wIiwgInIiKSkKICAgIHsKICAgICAgICBmcmVvcGVuKHRhc2siLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4odGFzayIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCksIGNvdXQudGllKDApOwoKICAgIGNpbiA+PiBuID4+IGsgPj4gczsKCiAgICBTb2x2ZSgpOwoKICAgIHJldHVybiAwOwp9