Language: C++

//
//  respect the past, embrace the future
//

#include  <algorithm>
#include  <iostream>
#include  <climits>
#include  <cstdlib>
#include  <cstring>
#include  <cmath>
#include  <cstdio>
#include  <unordered_map>
#include  <map>
#include  <set>
#include  <stack>
#include  <string>
#include  <vector>
#include  <queue>

using namespace :: std;

using vpll = vector <pair <long long, long long> >;
using pll = pair <long long, long long>;
using vll = vector <long long>;
using ll = long long;

#define W (long long) (5e3 + 7)
#define N (long long) (2e6 + 7)
#define M (long long) (1e16 + 3)
#define INF (long long) (2e18)
#define F first
#define S second
#define P 53
#define str[i] (str[i] - 'a' + 1)

inline void fastInputOutput () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
}

inline void ReadWriteFromFile () {
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
}

ll n, p[N];
char str[N];
set <pll> s;

int32_t main (int argc, char *argv[]) {
  fastInputOutput();
  // ReadWriteFromFile();
  
  cin >> n >> str + 1;
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = (p[i - 1] * P) % M;
  for (int len = n / 2; len >= 1; len--) {
    ll hash = 0;
    for (int i = 1; i <= len; i++)
      hash = (hash + (str[i] * p[len - i + 1]) % M) % M;
    s.insert({hash, 1});
    for (int i = 2; i <= n - len + 1; i++) {
      hash = (hash - (str[i - 1] * p[len]) % M) % M;
      hash = (hash * P) % M;
      hash = (hash + (str[i + len - 1] * P) % M) % M;
      s.insert({hash, i});
    }
    for (auto cur : s) {
      auto it = s.lower_bound({cur.first, cur.second + len});
      if (it != s.end() && (*it).first == cur.first) {
        cout << len;
        return 0;
      }
    }
    s.clear();
  }
  cout << 0;
}

Compiler output:
a.cc:34:9: warning: ISO C++11 requires whitespace after the macro name
   34 | #define str[i] (str[i] - 'a' + 1)
      |         ^~~
a.cc:34:12: error: structured binding declaration cannot have type 'char'
   34 | #define str[i] (str[i] - 'a' + 1)
      |            ^~~
a.cc:47:6: note: in expansion of macro 'str'
   47 | char str[N];
      |      ^~~
a.cc:34:12: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
   34 | #define str[i] (str[i] - 'a' + 1)
      |            ^~~
a.cc:47:6: note: in expansion of macro 'str'
   47 | char str[N];
      |      ^~~
a.cc:34:17: error: 'str' was not declared in this scope
   34 | #define str[i] (str[i] - 'a' + 1)
      |                 ^~~
a.cc:47:6: note: in expansion of macro 'str'
   47 | char str[N];
      |      ^~~
a.cc:34:21: error: use of 'i' before deduction of 'auto'
   34 | #define str[i] (str[i] - 'a' + 1)
      |                     ^
a.cc:47:6: note: in expansion of macro 'str'
   47 | char str[N];
      |      ^~~
a.cc:47:9: error: expected ';' before '[' token
   47 | char str[N];
      |         ^
a.cc: In function 'int32_t main(int, char**)':
a.cc:34:13: warning: capture of variable 'i' with non-automatic storage duration
   34 | #define str[i] (str[i] - 'a' + 1)
      |             ^
a.cc:54:15: note: in expansion of macro 'str'
   54 |   cin >> n >> str + 1;
      |               ^~~
a.cc:34:13: note: '<typeprefixerror>i' declared here
   34 | #define str[i] (str[i] - 'a' + 1)
      |             ^
a.cc:47:6: note: in expansion of macro 'str'
   47 | char str[N];
      |      ^~~
a.cc:34:17: error: 'str' has not been declared
   34 | #define str[i] (str[i] - 'a' + 1)
      |                 ^~~
a.cc:54:15: note: in expansion of macro 'str'
   54 |   cin >> n >> str + 1;
      |               ^~~
a.cc:34:24: error: expected ',' or '...' before '-' token
   34 | #define str[i] (str[i] - 'a' + 1)
      |                        ^
a.cc:54:15: note: in expansion of macro 'str'
   54 |   cin >> n >> str + 1;
      |               ^~~
a.cc: In lambda function:
a.cc:54:19: error: expected '{' before '+' token
   54 |   cin >> n >> str + 1;
      |                   ^
a.cc: In function 'int32_t main(int, char**)':
a.cc:54:19: error: no match for 'operator+' (operand types are 'main(int, char**)::<lambda(...)>' and 'int')
   54 |   cin >> n >> str + 1;
      |                   ^ ~
      |                     |
      |                     int
In file included from /usr/include/c++/14/bits/stl_algobase.h:67,
                 from /usr/include/c++/14/algorithm:60,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'int'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   mismatched types 'const std::move_iterator<_IteratorL>' and 'int'
   54 |   cin >> n >> str + 1;
      |                     ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:6:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   mismatched types 'const _CharT*' and 'main(int, char**)::<lambda(...)>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   'main(int, char**)::<lambda(...)>' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:54:21: note:   mismatched types 'const _CharT*' and 'main(int, char**)::<lambda(...)>'
   54 |   cin >> n >> str + 1;
      |                     ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_s