import
java.util.*;
class
GFG{
static
int
maximumMatchingPairs(
int
perm1[],
int
perm2[],
int
n)
{
int
[]left =
new
int
[n];
int
[]right =
new
int
[n];
HashMap<Integer,
Integer> mp1 =
new
HashMap<>();
HashMap<Integer,
Integer> mp2 =
new
HashMap<>();
for
(
int
i =
0
; i < n; i++)
{
mp1.put(perm1[i], i);
}
for
(
int
j =
0
; j < n; j++)
{
mp2.put(perm2[j], j);
}
for
(
int
i =
0
; i < n; i++)
{
int
idx2 = mp2.get(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));
}
}
HashMap<Integer,
Integer> freq1 =
new
HashMap<>();
HashMap<Integer,
Integer> freq2 =
new
HashMap<>();
for
(
int
i =
0
; i < n; i++)
{
if
(freq1.containsKey(left[i]))
freq1.put(left[i],
freq1.get(left[i]) +
1
);
else
freq1.put(left[i],
1
);
if
(freq2.containsKey(right[i]))
freq2.put(right[i],
freq2.get(right[i]) +
1
);
else
freq2.put(right[i],
1
);
}
int
ans =
0
;
for
(
int
i =
0
; i < n; i++)
{
ans = Math.max(ans,
Math.max(freq1.get(left[i]),
freq2.get(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;
System.out.print(maximumMatchingPairs(P1, P2, n));
}
}