using
System;
using
System.Collections.Generic;
class
GFG{
static
int
maximumMatchingPairs(
int
[]perm1,
int
[]perm2,
int
n)
{
int
[]left =
new
int
[n];
int
[]right =
new
int
[n];
Dictionary<
int
,
int
> mp1=
new
Dictionary<
int
,
int
>();
Dictionary<
int
,
int
> mp2=
new
Dictionary<
int
,
int
>();
for
(
int
i = 0; i < n; i++)
{
mp1[perm1[i]] = i;
}
for
(
int
j = 0; j < n; j++)
{
mp2[perm2[j]] = j;
}
for
(
int
i = 0; i < n; i++)
{
int
idx2 = mp2[perm1[i]];
int
idx1 = i;
if
(idx1 == idx2)
{
left[i] = 0;
right[i] = 0;
}
else
if
(idx1 < idx2)
{
left[i] = (n - (idx2 - idx1));
right[i] = (idx2 - idx1);
}
else
{
left[i] = (idx1 - idx2);
right[i] = (n - (idx1 - idx2));
}
}
Dictionary<
int
,
int
> freq1=
new
Dictionary <
int
,
int
>();
Dictionary<
int
,
int
> freq2=
new
Dictionary <
int
,
int
>();
for
(
int
i = 0; i < n; i++)
{
if
(freq1.ContainsKey(left[i]))
freq1[left[i]]++;
else
freq1[left[i]] = 1;
if
(freq2.ContainsKey(right[i]))
freq2[right[i]]++;
else
freq2[right[i]] = 1;
}
int
ans = 0;
for
(
int
i = 0; i < n; i++)
{
ans = Math.Max(ans,
Math.Max(freq1[left[i]],
freq2[right[i]]));
}
return
ans;
}
public
static
void
Main(
string
[] args)
{
int
[]P1 = {5, 4, 3, 2, 1};
int
[]P2 = {1, 2, 3, 4, 5};
int
n = P1.Length;
Console.Write(maximumMatchingPairs(P1, P2, n));
}
}