description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [(int(x) - 1) for x in input().split()]
b = [(int(x) - 1) for x in input().split()]
aindex = [0] * n
bindex = [0] * n
for i in range(n):
aindex[a[i]] = i
bindex[b[i]] = i
ans = [0] * n
for i in range(n):
x = aindex[i] - bindex[i]
if x < 0:
x = n + x
ans[x] += 1
print(max(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Left = [(0) for i in range(n + 1)]
Right = [(0) for i in range(n + 1)]
Pos = [[-1, -1] for i in range(n + 1)]
for i in range(n):
Pos[A[i]][0] = i
Pos[B[i]][1] = i
for i in range(1, n + 1):
a, b = Pos[i][0], Pos[i][1]
if a > b:
Left[n + (b - a)] += 1
Right[a - b] += 1
elif a == b:
Left[0] += 1
else:
Left[b - a] += 1
Right[n + (a - b)] += 1
l = max(Left)
r = max(Right)
print(max(l, r)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
check_a = [0] * (n + 10)
check_b = [0] * (n + 10)
correct = [0] * (n + 10)
for i in range(n):
check_a[a[i]] = i + 1
for i in range(n):
if check_a[b[i]] > i + 1:
correct[b[i]] = check_a[b[i]] - i - 1
else:
correct[b[i]] = n - i - 1 + check_a[b[i]]
answer = 0
d = dict()
for i in range(n):
if correct[b[i]] not in d.keys():
d[correct[b[i]]] = 1
else:
d[correct[b[i]]] += 1
answer = max(answer, d[correct[b[i]]])
print(answer) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
a[i] = [a[i], i]
b[i] = [b[i], i]
a.sort(key=lambda x: x[0])
b.sort(key=lambda x: x[0])
ans = [0] * n
mx = 0
for i in range(n):
ans[(n + b[i][1] - a[i][1]) % n] += 1
mx = max(ans[(n + b[i][1] - a[i][1]) % n], mx)
print(mx)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def main():
n = int(input())
shifts = [0] * n
for i, j in zip(
*[
sorted(range(n), key=list(map(int, input().split())).__getitem__)
for _ in "ab"
]
):
shifts[i - j] += 1
print(max(shifts))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))
dict1 = {}
dict2 = {}
for i in range(n):
a = list1[i]
b = list2[i]
if a not in dict1:
dict1[a] = i
else:
x = dict1[a] + i
if x not in dict2:
dict2[x] = 1
else:
dict2[x] += 1
if b not in dict1:
dict1[b] = -i
else:
y = dict1[b] - i + n
if y not in dict2:
dict2[y] = 1
else:
dict2[y] += 1
print(max(dict2.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
li = []
d = {}
di = {}
maxi = 0
k = 0
for i in range(n):
if a[i] in di.keys():
di[a[i]][0] = i
else:
di[a[i]] = [0, 0]
di[a[i]][0] = i
if b[i] in di.keys():
di[b[i]][1] = i
else:
di[b[i]] = [0, 0]
di[b[i]][1] = i
for i in di.keys():
if di[i][0] - di[i][1] < 0:
value = n - (di[i][1] - di[i][0])
else:
value = di[i][0] - di[i][1]
if value in d.keys():
d[value] = d[value] + 1
if maxi < d[value]:
maxi = d[value]
else:
d[value] = 1
if maxi < d[value]:
maxi = d[value]
print(maxi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR ASSIGN VAR VAR VAR LIST NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def read_int():
return int(input())
def read_ints():
return map(int, input().split(" "))
n = read_int()
a = list(read_ints())
b = list(read_ints())
cnt = dict()
ad = dict()
bd = dict()
for i in range(n):
ad[a[i]] = i
bd[b[i]] = i
for i in range(1, n + 1):
delta = (bd[i] - ad[i] + n) % n
if not delta in cnt:
cnt[delta] = 0
cnt[delta] += 1
ans = 0
for key in cnt:
ans = max(ans, cnt[key])
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
aa = map(int, input().split())
aid = [0] * (n + 1)
bb = map(int, input().split())
dcount = [0] * n
for i, a in enumerate(aa):
aid[a] = i
for i, b in enumerate(bb):
dcount[(i - aid[b]) % n] += 1
print(max(dcount)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import *
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [0] * (n + 1)
for i in range(n):
d[b[i]] = i
e = [0] * (n + 1)
for i in range(n):
ind = d[a[i]]
if ind >= i:
e[i] = ind - i
else:
e[i] = ind + 1 + (n - 1 - i)
d = [0] * n
for i in range(n):
d[e[i]] += 1
mx = -1
for i in range(n):
mx = max(mx, d[i])
stdout.write(str(mx) + "\n") | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
M = [(0) for i in range(n)]
a = input().split()
b = input().split()
for i in range(n):
M[int(a[i]) - 1] = i
for i in range(n):
t = i - M[int(b[i]) - 1]
if t < 0:
M[int(b[i]) - 1] = n + t
else:
M[int(b[i]) - 1] = t
R = [(0) for i in range(n)]
for i in range(n):
R[M[i]] += 1
print(max(R)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def solve(a, b):
d = {}
for i in range(len(b)):
d[b[i]] = i
arr = []
for i in range(len(a)):
val = d[a[i]]
if val >= i:
arr.append(val - i)
else:
arr.append(len(a) - i + val)
d = {}
for i in arr:
d[i] = d.get(i, 0) + 1
ans = 0
for key in d:
ans = max(ans, d[key])
return ans
n = input()
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
print(solve(a, b)) | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
diff = [(0) for i in range(n)]
for i in range(n):
a_el = a[i]
diff[a_el - 1] += i + n
b_el = b[i]
diff[b_el - 1] += -i + n
diff[a_el - 1] = diff[a_el - 1] % n
diff[b_el - 1] = diff[b_el - 1] % n
frequency = [(0) for i in range(n)]
for i in range(n):
el = diff[i]
frequency[el] += 1
print(max(frequency)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
arr = [0] + list(map(int, input().split()))
bbs = [0] + list(map(int, input().split()))
d = {}
for i in range(1, n + 1):
d[arr[i]] = i
count = {}
for i in range(1, n + 1):
curr = d[bbs[i]] - i
if curr < 0:
curr += n
count[curr] = count.get(curr, 0) + 1
res = max(count.values())
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
def ii():
return sys.stdin.readline().strip()
def idata():
return [int(x) for x in ii().split()]
def solve_of_problem():
n = int(ii())
a = idata()
b = idata()
a1, b1 = [0] * n, [0] * n
for i in range(n):
a1[a[i] - 1] = i
b1[b[i] - 1] = i
slov = dict()
for i in range(n):
s = (a1[i] - b1[i]) % n
if s not in slov:
slov[s] = 1
else:
slov[s] += 1
print(max(slov.values()))
return
for ______ in range(1):
solve_of_problem() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a_i = [int(a) for a in input().split()]
b_i = [int(b) for b in input().split()]
list = [(0) for num in range(n + 1)]
for index in range(n):
list[a_i[index]] = index
for index in range(n):
list[b_i[index]] -= index
if list[b_i[index]] < 0:
list[b_i[index]] += n
list.sort()
maximum = 0
count = 0
K_check = 0
for index in range(1, n + 1):
if index == 1:
K_check = list[index]
count = 1
elif list[index] == K_check:
count += 1
else:
maximum = max(maximum, count)
count = 1
K_check = list[index]
maximum = max(maximum, count)
print(maximum) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
first = {key: value for key, value in zip(map(int, input().split()), range(n))}
second = list(map(int, input().split()))
values = {}
for i in range(n):
p = second[i]
value_right = f"{abs(n - abs(i - first[p]))} {'r' if i - first[p] > 0 else 'l'}"
value_left = f"{abs(i - first[p])} {'l' if i - first[p] > 0 else 'r'}"
if value_left not in values:
values[value_left] = 0
if value_right not in values:
values[value_right] = 0
values[value_left] += 1
values[value_right] += 1
print(max(values.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING BIN_OP VAR VAR VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR STRING BIN_OP VAR VAR VAR NUMBER STRING STRING IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
pos = [0] * (n + 1)
ans = dict()
a = list(map(int, input().split()))
for i in range(1, n + 1):
pos[a[i - 1]] = i
b = list(map(int, input().split()))
for i in range(1, n + 1):
ps = pos[b[i - 1]] - i
if ps < 0:
ps += n
ans[ps] = ans.get(ps, 0) + 1
print(max(ans.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def val(ai, bi):
final = {}
lst = {}
for i in range(N):
final[bi[i]] = i
for i in range(N):
if final[ai[i]] - i < 0:
final[ai[i]] = N - i + final[ai[i]]
else:
final[ai[i]] -= i
for i in final:
if final[i] not in lst:
lst[final[i]] = 1
else:
lst[final[i]] += 1
high = 1
for i in lst:
if lst[i] > high:
high = lst[i]
return high
N = int(input())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
if N < 3:
print(N)
else:
print(val(ai, bi)) | FUNC_DEF ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | a = int(input())
old = list(map(int, input().split()))
dic = {}
for i in range(a):
dic[old[i]] = i + 1
new = list(map(int, input().split()))
distance = []
for i in range(a):
distance.append((dic[new[i]] - (i + 1) + a) % a)
didi = {}
for j in distance:
if j not in didi:
didi[j] = 1
else:
didi[j] += 1
print(max(didi.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | for t in range(1):
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
ct = 0
matrix = [0] * n
diff = [0] * n
diffn = [0] * n
for i in range(n):
matrix[brr[i] - 1] = i
for i in range(n):
pos = (i - matrix[arr[i] - 1]) % n
diff[pos] += 1
print(max(diff)) | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
res = [0] * (n + 1)
for i in range(n):
d[a[i]] = [i]
for i in range(n):
d[b[i]].append(i)
for i in range(n):
l, h = d[a[i]]
if h > l:
res[h - l] += 1
else:
res[n - l + h] += 1
print(max(res)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def MI():
return map(int, sys.stdin.readline().split())
def SI():
return sys.stdin.readline().strip()
n = II()
a = LI()
b = LI()
x = [0] * (n + 1)
y = [0] * (n + 1)
d = {}
for i in range(n):
x[a[i]] = i
y[b[i]] = i
m = 0
for i in range(1, n + 1):
z = x[i] - y[i]
if z < 0:
z += n
if z not in d:
d[z] = 1
else:
d[z] += 1
m = max(m, d[z])
print(m) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def main():
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
offset = {}
pos = {}
for i in range(N):
pos[B[i]] = i
for i in range(N):
cur = pos[A[i]] - i
if cur < 0:
cur += N
if cur not in offset:
offset[cur] = 1
else:
offset[cur] += 1
print(max(offset.values()))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
A = list(map(int, input("").split()))
B = list(map(int, input("").split()))
ans = 0
indexA = dict()
indexB = dict()
for i in range(n):
indexB[B[i]] = i
count = dict()
for i in range(n):
x = indexB[A[i]] - i
if x < 0:
x += n
count[x] = count.get(x, 0) + 1
print(max(count.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def rotation(n, a, b):
dic = {}
for i in range(n):
if a[i] in dic:
dic[a[i]] = dic[a[i]] - i
if dic[a[i]] < 0:
dic[a[i]] += n
else:
dic[a[i]] = -i
if b[i] in dic:
dic[b[i]] = dic[b[i]] + i
if dic[b[i]] < 0:
dic[b[i]] += n
else:
dic[b[i]] = i
answerdic = {}
for x in dic:
x = dic[x]
if x in answerdic:
answerdic[x] += 1
else:
answerdic[x] = 1
ans = 1
for y in answerdic:
if answerdic[y] > ans:
ans = answerdic[y]
return ans
n = int(input())
a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
print(rotation(n, a, b)) | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import maxsize, stdin, stdout
input = stdin.readline
def solve():
pass
test = 1
for t in range(0, test):
n = int(input().strip())
a = [int(x) for x in input().strip().split()]
b = [int(x) for x in input().strip().split()]
da = {}
db = {}
ind = a.index(1)
rel = 0
for i in range(ind, n):
da[a[i]] = rel
rel += 1
for i in range(ind):
da[a[i]] = rel
rel += 1
ind = b.index(1)
rel = 0
for i in range(ind, n):
db[b[i]] = rel
rel += 1
for i in range(ind):
db[b[i]] = rel
rel += 1
ans = {}
for i in range(1, n + 1):
temp = (da[i] - db[i] + n) % n
ans[temp] = ans.get(temp, 0) + 1
print(max(ans.values()))
ans = solve() | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def solve(t, d, e):
arr1 = [0] * (3 * 10**5)
arr2 = [0] * (3 * 10**5)
for i in range(t):
arr1[d[i]] = i
arr2[e[i]] = i
shifts = {}
for i in range(t):
dind = arr1[e[i]]
if dind >= i:
shift = dind - i
else:
shift = dind - i + t
if shift in shifts:
shifts[shift] += 1
else:
shifts[shift] = 1
maxer = 0
for i in shifts:
maxer = max(maxer, shifts[i])
return maxer
def main():
t = int(input())
d = input()
d = [int(i) for i in d.split()]
e = input()
e = [int(i) for i in e.split()]
ans = solve(t, d, e)
print(ans)
main() | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [0] * n
for i in range(n):
ind[a[i] - 1] = i
h = [0] * n
g = [0] * n
for i in range(n):
h[ind[b[i] - 1] - i] += 1
g[i - ind[b[i] - 1]] += 1
print(max(h + g)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(ele) for ele in input().split()]
b = [int(ele) for ele in input().split()]
mem = {}
diff = []
for i in range(1, n + 1):
mem[i] = []
for i in range(n):
mem[a[i]].append(i)
for i in range(n):
mem[b[i]].append(i)
for i in range(n):
diff.append(0)
for key in mem.keys():
if mem[key][0] <= mem[key][1]:
differ = mem[key][1] - mem[key][0]
diff[differ] += 1
else:
differ = n - mem[key][0] + mem[key][1]
diff[differ] += 1
print(max(diff)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
j = [(0) for x in range(n)]
ans = j.copy()
for i in range(n):
j[a[i] - 1] = i
for i in range(n):
if j[b[i] - 1] < i:
ans[b[i] - 1] = n - i + j[b[i] - 1]
else:
ans[b[i] - 1] = j[b[i] - 1] - i
ans.sort()
now = 1
res = 0
for i in range(1, n):
if ans[i] != ans[i - 1]:
if now > res:
res = now
now = 1
else:
now += 1
if now > res:
res = now
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | t = int(input())
code_a = list(map(int, input().split(" ")))
code_b = list(map(int, input().split(" ")))
def from_list_to_dict(perm):
pos = dict()
length = len(perm)
for i in range(length):
pos[perm[i]] = i
return pos
pos_a = from_list_to_dict(code_a)
pos_b = from_list_to_dict(code_b)
shift = [0] * t
for i in range(1, t + 1):
shift[(pos_a[i] - pos_b[i]) % t] += 1
print(max(shift)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
ai = [-1] * n
for i in range(n):
ai[a[i] - 1] = i
c = [0] * n
for i in range(n):
ia = ai[b[i] - 1]
if ia == i:
c[0] += 1
elif ia > i:
c[ia - i] += 1
else:
c[n + ia - i] += 1
print(max(c)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
db = {b[i]: i for i in range(n)}
l = {}
for i in range(n):
try:
l[(i - db[a[i]] + n) % n] += 1
except KeyError:
l[(i - db[a[i]] + n) % n] = 1
ans = max(l.values())
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [0] * (n + 1)
for i, x in enumerate(map(int, input().split())):
a[x] = i
b = [0] * (n + 1)
for i, x in enumerate(map(int, input().split())):
y = ((i - a[x]) % n + n) % n
b[y] += 1
print(max(b)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
right = {}
aindex = {}
bindex = {}
for i in range(n):
aindex[a[i]] = i
for i in range(n):
bindex[b[i]] = i
for i in range(1, n + 1):
if bindex[i] > aindex[i]:
right[i] = bindex[i] - aindex[i]
else:
right[i] = n - aindex[i] + bindex[i]
left = {}
for i in range(1, n + 1):
if bindex[i] > aindex[i]:
left[i] = aindex[i] + (n - bindex[i])
else:
left[i] = aindex[i] - bindex[i]
aindexcount = {}
bindexcount = {}
for i in left:
if left[i] in aindexcount:
aindexcount[left[i]] += 1
else:
aindexcount[left[i]] = 1
for i in right:
if right[i] in bindexcount:
bindexcount[right[i]] += 1
else:
bindexcount[right[i]] = 1
firstmax, secondmax = 0, 0
for i in aindexcount:
firstmax = max(firstmax, aindexcount[i])
for i in bindexcount:
secondmax = max(secondmax, bindexcount[i])
print(max(firstmax, secondmax)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(p) for p in input().split()]
b = [int(p) for p in input().split()]
index = {}
for i in range(len(a)):
index[a[i]] = i
diff = {}
for i in range(len(b)):
d = index[b[i]] - i
if d < 0:
d = n + d
try:
diff[d] += 1
except KeyError:
diff[d] = 1
print(max(diff.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dif = [0] * n
a = list(enumerate(a))
b = list(enumerate(b))
a.sort(key=lambda x: x[1])
b.sort(key=lambda x: x[1])
for i in range(n):
q1 = a[i][0]
q2 = b[i][0]
if q2 - q1 < 0:
dif[i] = n + (q2 - q1)
else:
dif[i] = q2 - q1
maxi = 0
difmax = [0] * n
for s in dif:
difmax[s] += 1
if difmax[s] > maxi:
maxi = difmax[s]
print(maxi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
seq1 = {}
seq2 = {}
for i in range(n):
seq1[a[i]] = i
seq2[b[i]] = i
arr = [0] * n
for i in range(n):
e = a[i]
index1 = seq1[e]
index2 = seq2[e]
arr[(index1 - index2) % n] += 1
print(max(arr)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
mpa = dict()
mpb = dict()
for i in range(n):
mpa[a[i]] = i
mpb[b[i]] = i
mp1 = dict()
for i in range(n):
j = mpb[a[i]]
try:
if j > i:
mp1[i + n - j] += 1
else:
mp1[i - j] += 1
except KeyError:
if j > i:
mp1[i + n - j] = 1
else:
mp1[i - j] = 1
mp2 = dict()
for i in range(n):
j = mpb[a[i]]
try:
if j >= i:
mp2[j - i] += 1
else:
mp2[j + n - i] += 1
except KeyError:
if j >= i:
mp2[j - i] = 1
else:
mp2[j + n - i] = 1
res = 0
for i in mp1.values():
res = max(res, i)
for i in mp2.values():
res = max(res, i)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
m = []
for i in range(n):
m.append(0)
pos = []
for i in range(n + 1):
pos.append(0)
for i in range(n):
pos[a[i]] = i
for i in range(n):
cur = pos[b[i]] - i
if cur < 0:
cur += n
m[cur] += 1
max = 0
for i in range(n):
if m[i] > max:
max = m[i]
print(max) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
rotations = [0] * n
answers = [0] * n
for i in range(len(a)):
rotations[a[i] - 1] += i
rotations[b[i] - 1] -= i
for i in range(len(a)):
rotations[i] = (rotations[i] + n) % n
answers[rotations[i] - 1] += 1
print(max(answers)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
A1 = input()
B1 = input()
A = A1.split()
B = B1.split()
for i in range(n):
A[i] = int(A[i]) - 1
B[i] = int(B[i]) - 1
D = []
AA = [None] * n
BB = [None] * n
for i in range(n):
AA[A[i]] = i
BB[B[i]] = i
for i in range(n):
D.append((AA[i] - BB[i]) % n)
D.sort()
DD = [0]
last = D[0]
for i in range(n):
if last == D[i]:
DD[-1] += 1
else:
last = D[i]
DD.append(1)
print(max(DD)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NONE VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
Ri = lambda: [int(x) for x in sys.stdin.readline().split()]
ri = lambda: sys.stdin.readline().strip()
n = int(ri())
a = Ri()
b = Ri()
dic1 = {}
dic2 = {}
for i in range(len(a)):
dic1[a[i]] = i
for i in range(len(b)):
dic2[b[i]] = i
dic = {}
for i in range(1, n + 1):
if (dic2[i] - dic1[i]) % n in dic:
dic[(dic2[i] - dic1[i]) % n] += 1
else:
dic[(dic2[i] - dic1[i]) % n] = 1
maxx = max([dic[i] for i in dic])
print(maxx) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia = [0] * (n + 1)
ib = [0] * (n + 1)
i = 0
while i < len(b):
x = b[i]
ib[x] = i
i = i + 1
i = 0
da = {}
while i < n:
x = a[i]
y = ib[x]
if i == y:
r = n
h = -1 * n
elif i < y:
r = y - i
h = -1 * (n - y + i)
else:
r = n - i + y
h = y - i
if r in da:
da[r] = da[r] + 1
else:
da[r] = 1
if h in da:
da[h] = da[h] + 1
else:
da[h] = 1
i = i + 1
m = -1
for i in da:
if da[i] > m:
m = da[i]
print(m) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
def input():
return sys.stdin.readline().rstrip()
n = int(input())
a = [(int(i) - 1) for i in input().split()]
b = [(int(i) - 1) for i in input().split()]
initial = [None for i in range(n)]
final = [None for i in range(n)]
for i, el in enumerate(a):
initial[el] = i
for i, el in enumerate(b):
final[el] = i
count = [(0) for i in range(n)]
for el in range(n):
count[(initial[el] - final[el]) % n] += 1
print(max(count)) | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = dict()
d2 = dict()
for i in range(n):
d1[a[i]] = i
d2[b[i]] = i
ans = dict()
for i in range(n):
id1 = d1[b[i]]
id2 = d2[b[i]]
if id1 > id2:
if ans.get(id1 - id2) is None:
ans[id1 - id2] = 1
else:
ans[id1 - id2] += 1
elif ans.get(n + id1 - id2) is None:
ans[n + id1 - id2] = 1
else:
ans[n + id1 - id2] += 1
print(max(ans.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NONE ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NONE ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a_trans = [0] * (n + 1)
for i, ai in enumerate(input().split()):
a_trans[int(ai)] = i
matches = [0] * n
for i, bi in enumerate(input().split()):
matches[(i - a_trans[int(bi)]) % n] += 1
print(max(matches)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import stdin, stdout
for _ in range(1):
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
d = {}
ib = {}
for i in range(n):
ib[b[i]] = i
for i in range(n):
shift = (i - ib[a[i]] + n) % n
d[shift] = d.get(shift, 0) + 1
print(max(v for k, v in d.items())) | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def solve():
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
da, db = {}, {}
for i in range(n):
da[a[i]] = i
db[b[i]] = i
d1, d2 = {}, {}
for ele in da:
x, y = da[ele], db[ele]
if y < x:
k1 = y + n - x
k2 = x - y
else:
k1 = y - x
k2 = x + n - y
d1[k1] = d1.get(k1, 0) + 1
d2[k2] = d2.get(k2, 0) + 1
mx = -100000000
for ele in d1:
if d1[ele] > mx:
note = ele
mx = d1[ele]
for ele in d2:
if d2[ele] > mx:
note = ele
mx = d1[ele]
print(mx)
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR DICT DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
input = sys.stdin.buffer.readline
n = int(input())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
out = [0] * n
dif = [0] * n
for i in range(n):
dif[arr1[i] - 1] += i
for i in range(n):
dif[arr2[i] - 1] -= i
for v in dif:
out[v] += 1
print(max(out)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | elem = int(input())
ar = []
for i in input().split(" "):
ar.append(int(i))
ar2 = []
for i in input().split(" "):
ar2.append(int(i))
diff = {}
m = 0
t = []
acc = {}
for i in range(len(ar)):
acc[ar[i]] = i + 1
for i in range(len(ar)):
temp = (i - acc[ar2[i]]) % elem
if temp in diff:
diff[temp] = diff[temp] + 1
else:
diff[temp] = 1
if diff[temp] > m:
m = diff[temp]
print(m) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
seg = []
dic = {}
for i in range(n):
dic[arr1[i]] = [i]
for j in range(n):
if dic[arr2[j]][0] > j:
dic[arr2[j]].append(n + j)
else:
dic[arr2[j]].append(j)
dic2 = {}
for key in dic:
if dic[key][1] - dic[key][0] not in dic2:
dic2[dic[key][1] - dic[key][0]] = 1
else:
dic2[dic[key][1] - dic[key][0]] += 1
print(dic2[max(dic2.keys(), key=lambda k: dic2[k])]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = input()
n = int(n)
a = input()
b = input()
a = a.split(" ")
b = b.split(" ")
for k in range(n):
a[k] = int(a[k])
b[k] = int(b[k])
c = [0] * n
d = [0] * n
e = [0] * n
for k in range(n):
c[a[k] - 1] = k
d[b[k] - 1] = k
for k in range(n):
e[k] = d[k] - c[k]
if e[k] < 0:
e[k] = n + e[k]
f = [0] * n
for k in range(n):
f[e[k]] += 1
print(max(f)) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | ind = [(-1) for i in range(200005)]
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
ind[a[i]] = i
d = dict()
for i in range(n):
x = ind[b[i]]
z = 0
if x >= i:
z = x - i
else:
z = n - i + x
d[z] = d.get(z, 0) + 1
l = d.values()
print(max(l)) | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
d = {}
for i in range(n):
d[b[i]] = i
jump_needed = []
for i in range(n):
map_idx = d[a[i]]
if i <= map_idx:
jump_needed.append(map_idx - i)
else:
x = n - 1 - i + map_idx + 1
jump_needed.append(x)
di = {}
for i in jump_needed:
try:
di[i] = di[i] + 1
except KeyError:
di[i] = 1
print(max(di.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def f1(l1, l2, n):
li1, li2 = [0] * n, [0] * n
for i in range(n):
li2[l2[i] - 1] = i
li1[l1[i] - 1] = i
ldif = []
for i in range(n):
d = li2[i] - li1[i]
if d < 0:
d += n
ldif.append(d)
ldif.sort()
return ldif
def f2(ldif, n):
cmax = 1
c = 1
for i in range(1, n):
if ldif[i] == ldif[i - 1]:
c += 1
else:
if cmax < c:
cmax = c
c = 1
if cmax < c:
cmax = c
return cmax
n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ldif = f1(l1, l2, n)
cmax = f2(ldif, n)
print(cmax) | FUNC_DEF ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
B = list(map(int, input().split()))
A = list(map(int, input().split()))
C = [(0) for i in range(n + 1)]
D = [(0) for i in range(n + 1)]
for i in range(n):
C[B[i]] = i
D[A[i]] = i
CD = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
if D[i] - C[i] <= 0:
CD[D[i] - C[i] + n] = CD[D[i] - C[i] + n] + 1
else:
CD[D[i] - C[i]] = CD[D[i] - C[i]] + 1
mv = 0
for i in range(n + 1):
mv = max(mv, CD[i])
print(mv) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
input = sys.stdin.readline
def intInput():
return int(input())
def intListInput():
return list(map(int, input().split()))
def strInput():
return input()
def brute(n, a, b):
result = 0
for k in range(n):
curr = 0
for i in range(n):
if a[i] == b[(i + k) % n]:
curr += 1
result = max(result, curr)
return result
def soln(n, a, b):
table = {}
for i, num in enumerate(a):
table[num] = i
buckets = [(0) for _ in range(n)]
for j, num in enumerate(b):
i = table[num]
if j <= i:
m = i - j
else:
m = n + i - j
buckets[m] += 1
return max(buckets)
def main():
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
result = soln(n, a, b)
print(result)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import stdin
def ii():
return int(stdin.readline())
def fi():
return float(stdin.readline())
def mi():
return map(int, stdin.readline().split())
def fmi():
return map(float, stdin.readline().split())
def li():
return list(mi())
def si():
return stdin.readline().rstrip()
def lsi():
return list(si())
res = ["YES", "NO"]
test_case = 1
while test_case:
test_case -= 1
n = ii()
a = li()
p = [-1] * (n + 1)
for i in range(n):
p[a[i]] = i
a = li()
v = [0] * n
for i in range(n):
x = i - p[a[i]]
if x < 0:
x += n
v[x] += 1
print(max(v)) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().strip().split()))[:n]
b = list(map(int, input().strip().split()))[:n]
db = {}
for i in range(len(a)):
db[b[i]] = i
res = []
for i in range(len(a)):
k = db[a[i]]
if k >= i:
res.append(k - i)
else:
res.append(len(a) - (i - k))
r = [0] * len(a)
for i in range(len(res)):
r[res[i]] += 1
print(max(r)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | tam = int(input())
A = [(int(elem), i) for i, elem in enumerate(input().split())]
B = [(int(elem), i) for i, elem in enumerate(input().split())]
A.sort()
B.sort()
diff = [(0) for i in range(tam)]
desl = tam - 1
for i in range(tam):
if A[i][1] <= B[i][1]:
pos = B[i][1] - A[i][1]
diff[pos] += 1
else:
pos = tam - (A[i][1] - B[i][1])
diff[pos] += 1
print(max(diff)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
pos = [0] * (n + 1)
dp = [0] * (n + 1)
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(0, len(a)):
pos[a[i]] = i
for i in range(0, len(b)):
tt = pos[b[i]]
dp[(tt - i) % n] += 1
print(max(dp)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ind = [(0) for i in range(n + 1)]
for i in range(len(b)):
ind[b[i]] = i
diff = [(0) for i in range(n + 1)]
for i in range(n):
x = (i - ind[a[i]]) % n
diff[x] += 1
print(max(diff)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def getMatches(n, a, b):
count = 0
for i in range(n):
if a[i] == b[i]:
count += 1
return count
def rotate(arr, n):
x = arr[n - 1]
for i in range(n - 1, 0, -1):
arr[i] = arr[i - 1]
arr[0] = x
def invrotate(arr, n):
x = arr[0]
for i in range(n - 1):
arr[i] = arr[i + 1]
arr[n - 1] = x
n = int(input())
x = input()
x = x.split()
x = [int(y) for y in x]
a = x
x = input()
x = x.split()
x = [int(y) for y in x]
b = x
d = {}
for i in range(n):
d[i + 1] = 0
for i in range(n):
if i == 0:
d[a[i]] -= n
d[b[i]] += i
else:
d[a[i]] -= i
d[b[i]] += i
vals = []
for i in d:
vals.append(d[i])
x = {}
for i in vals:
x[i] = 0
for i in vals:
x[i] += 1
maxC = 0
for i in vals:
if x[i] > maxC:
maxC = x[i]
d = {}
for i in range(n):
d[i + 1] = 0
for i in range(n):
d[a[i]] -= i
d[b[i]] += i
vals = []
for i in d:
vals.append(d[i] % n)
x = {}
for i in vals:
x[i] = 0
for i in vals:
x[i] += 1
for i in vals:
if x[i] > maxC:
maxC = x[i]
print(maxC) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
input = sys.stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
(*b,) = map(int, input().split())
a += a
ia = [[] for _ in range(n)]
ib = [[] for _ in range(n)]
for i, x in enumerate(a):
ia[x - 1].append(i)
for i, x in enumerate(b):
ib[x - 1].append(i)
cnt = [0] * n
for i in range(n):
ii, jj = ia[i]
kk = ib[i][0]
if ii >= kk:
cnt[ii - kk] += 1
if jj - kk < n:
cnt[jj - kk] += 1
print(max(cnt)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | t = int(input())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
as1 = [0] * (t + 1)
as2 = [0] * (t + 1)
for j in range(t):
as1[s1[j]] = j
for k in range(t):
as2[s2[k]] = k
dic = {}
l1 = []
ma = 1
for i in range(1, t + 1):
if as2[i] < as1[i]:
ans = t + as2[i] - as1[i]
else:
ans = as2[i] - as1[i]
if ans not in dic:
dic[ans] = 1
else:
dic[ans] += 1
ma = max(dic[ans], ma)
print(ma) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | N = int(input())
a = map(int, input().strip().split())
a_positions = {elem: i for i, elem in enumerate(a)}
b = map(int, input().strip().split())
b_positions = {elem: i for i, elem in enumerate(b)}
rotation_differences = {i: (0) for i in range(N)}
max_occurance = 0
for i in range(1, N + 1):
key = (b_positions[i] - a_positions[i]) % N
rotation_differences[key] += 1
if rotation_differences[key] > max_occurance:
max_occurance = rotation_differences[key]
print(max_occurance) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a, b = [int(i) for i in input().split()], [int(i) for i in input().split()]
list = [0] * (n + 1)
for ind, el in enumerate(a):
list[el] += ind
for ind, el in enumerate(b):
list[el] -= ind
del list[0]
for ind in range(n):
list[ind] += n if list[ind] < 0 else 0
counting = [0] * (n + 1)
for ind in range(n):
counting[list[ind]] += 1
print(max(counting)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def solve(a, b, n):
map_k = [(0) for i in range(n + 1)]
offset_map = [(0) for i in range(n + 1)]
for i in range(n):
map_k[a[i]] = i
for j in range(n):
ndx = map_k[b[j]]
offset = ndx - j
if offset < 0:
offset += n
offset_map[offset] += 1
max_so_far = 0
for i in range(0, n + 1):
max_so_far = max(max_so_far, offset_map[i])
return max_so_far
def read():
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
ans = solve(a, b, n)
print(ans)
read() | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
loc = [[-1, -1] for _ in range(n)]
for i in range(n):
loc[a[i] - 1][0] = i
loc[b[i] - 1][1] = i
lefta, righta = [0] * n, [0] * n
leftb, rightb = [0] * n, [0] * n
for i in loc:
if i[0] == i[1]:
lefta[0] += 1
righta[0] += 1
leftb[0] += 1
rightb[0] += 1
elif i[0] < i[1]:
righta[i[1] - i[0]] += 1
lefta[n - i[1] + i[0]] += 1
rightb[n - i[1] + i[0]] += 1
leftb[i[1] - i[0]] += 1
else:
righta[n - i[0] + i[1]] += 1
lefta[i[0] - i[1]] += 1
rightb[i[0] - i[1]] += 1
leftb[i[1] + n - i[0]] += 1
for i in [lefta, leftb, righta, rightb]:
ans = max(ans, max(i))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
def input():
return sys.stdin.readline()[:-1]
def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
A = [(a[k], k) for k in range(n)]
B = [(b[k], k) for k in range(n)]
A = sorted(A, key=lambda x: x[0])
B = sorted(B, key=lambda x: x[0])
C = [0] * n
for k in range(n):
C[(A[k][1] - B[k][1]) % n] += 1
print(max(C))
main() | IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia = [(0) for i in range(n + 1)]
ib = [(0) for i in range(n + 1)]
for i in range(n):
ia[a[i]] = i
for i in range(n):
ib[b[i]] = i
for i in range(n + 1):
ia[i] = (ia[i] - ib[i]) % n
ans = [(0) for i in range(n)]
for i in range(1, n + 1):
ans[ia[i]] += 1
print(max(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def ans(arr1, arr2, n):
d1 = {}
for i in range(1, n + 1):
d1[i] = 0
for i in range(n):
d1[arr1[i]] = i + 1
d2 = {}
for i in range(1, n + 1):
d2[i] = 0
for i in range(n):
d2[arr2[i]] = i + 1
v1 = list(d1.values())
v2 = list(d2.values())
d3 = {}
for i in range(n):
x = (v1[i] - v2[i] + n) % n
if x not in d3:
d3[x] = 1
else:
d3[x] += 1
v3 = list(d3.values())
return max(v3)
for j in range(1):
n = int(input())
A = input().split()
B = input().split()
arr1 = []
arr2 = []
for i in A:
arr1.append(int(i))
for i in B:
arr2.append(int(i))
print(ans(arr1, arr2, n)) | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
posa = {}
posb = {}
for i in range(n):
posa[a[i]] = i
posb[b[i]] = i
diff_r = {}
diff_l = {}
for i in range(1, n + 1):
if posa[i] - posb[i] < 0:
diff_r[i] = n + posa[i] - posb[i]
else:
diff_r[i] = posa[i] - posb[i]
if posb[i] - posa[i] < 0:
diff_l[i] = n + posb[i] - posa[i]
else:
diff_l[i] = posb[i] - posa[i]
dfreq_r = {}
for item in diff_r.values():
if item in dfreq_r:
dfreq_r[item] += 1
else:
dfreq_r[item] = 1
dfreq_l = {}
for item in diff_l.values():
if item in dfreq_l:
dfreq_l[item] += 1
else:
dfreq_l[item] = 1
print(max(max(dfreq_r.values()), max(dfreq_l.values()))) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [0] * (n + 1)
for i, num in enumerate(map(int, input().split())):
a[num] = i + 1
d = {}
for i, num in enumerate(map(int, input().split())):
t = a[num] - (i + 1)
if t < 0:
t = n + t
d[t] = d.get(t, 0) + 1
ans = max(d.values())
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | t = 1
for ab in range(t):
n = int(input())
ind = [0] * (n + 1)
index = [0] * (n + 1)
m = list(map(int, input().split()))
x = list(map(int, input().split()))
for ab in range(n):
ind[m[ab]] = ab + 1
index[x[ab]] = ab + 1
tl = [(0) for ac in range(1, n + 1)]
for tr in range(n):
tl[tr] = (index[tr + 1] - ind[tr + 1]) % n
ir = [0] * n
for xy in tl:
ir[xy] += 1
print(max(ir)) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | l = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
cnt = 0
for i in a:
d[i] = cnt
cnt += 1
right = []
left = []
for i in range(l):
dif = d[b[i]] - i
if dif < 0:
left.append(abs(dif))
dif2 = l - abs(dif)
right.append(dif2)
else:
right.append(dif)
dif2 = l - dif
left.append(dif2)
ans1 = [0] * (l + 1)
ans2 = [0] * (l + 1)
for i in range(l):
ans1[right[i]] = ans1[right[i]] + 1
ans2[left[i]] = ans2[left[i]] + 1
x = max(ans1)
y = max(ans2)
print(max(x, y)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ad = {}
dd = {}
M = 0
for c, el in enumerate(a):
ad[el] = c
for c, el in enumerate(b):
target = ad[el]
if target >= c:
dist = target - c
else:
dist = n - c + target
if dist not in dd:
dd[dist] = 1
else:
dd[dist] += 1
M = max(M, dd[dist])
print(M)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
dica = {}
dicb = {}
for i in range(n):
dica[a[i]] = i
dicb[b[i]] = i
dicl = {}
dicr = {}
for i in range(1, n + 1):
x = dica[i] - dicb[i]
if x < 0:
x += n
if x in dicl.keys():
dicl[x] += 1
else:
dicl[x] = 1
x = -dica[i] + dicb[i]
if x < 0:
x += n
if x in dicr.keys():
dicr[x] += 1
else:
dicr[x] = 1
ans = 0
for i in dicr.keys():
if ans < dicr[i]:
ans = dicr[i]
for i in dicl.keys():
if ans < dicl[i]:
ans = dicl[i]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | def solve_2(D):
n = len(D)
cnts = [0] * n
for i, v in enumerate(D):
cnts[(v - i - 1 + n) % n] += 1
return max(cnts)
def solve(n, A, B):
a_d = {v: (i + 1) for i, v in enumerate(A)}
C = [a_d[v] for v in B]
C_1 = C.index(1)
D = C[C_1:] + C[:C_1]
return solve_2(D)
def main():
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(solve(n, A, B))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
d = [0] * n
e = [0] * n
for i in range(n):
c[a[i] - 1] = d[b[i] - 1] = i
for i in range(n):
e[i] = c[i] - d[i]
if e[i] < 0:
e[i] += n
m = j = 1
e.sort()
for i in range(1, n):
if e[i] == e[i - 1]:
j += 1
if j > m:
m = j
else:
j = 1
print(m) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
mp1 = [0] * (n + 2)
mp2 = [0] * (n + 2)
for i in range(n):
mp1[l1[i]] = i
for i in range(n):
mp2[l2[i]] = i
a = []
for i in range(1, n + 1):
if mp1[i] - mp2[i] < 0:
a.append(mp1[i] - mp2[i] + n)
else:
a.append(mp1[i] - mp2[i])
a.sort()
mx = 0
cnt = 1
for i in range(1, n):
if a[i] == a[i - 1]:
cnt += 1
else:
mx = max(mx, cnt)
cnt = 1
mx = max(mx, cnt)
print(mx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
input = sys.stdin.readline
n = int(input())
a = map(int, input().split())
b = map(int, input().split())
c = [[-1, -1] for _ in range(n)]
for i, (ai, bi) in enumerate(zip(a, b)):
c[ai - 1][0] = i
c[bi - 1][1] = i
s = dict()
for i, ci in enumerate(c):
if c[i][0] != -1 and c[i][1] != -1:
j = (c[i][0] - c[i][1] + n) % n
try:
s[j] += 1
except:
s[j] = 1
print(max(s.values())) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import stdin, stdout
n = int(stdin.readline())
arr = list(map(int, stdin.readline().strip().split()))
per = list(map(int, stdin.readline().strip().split()))
perr = dict()
for i in range(n):
perr[per[i]] = i
pos = [0] * 200002
for i in range(n):
x = perr.get(arr[i])
if x >= i:
pos[x - i] += 1
else:
pos[n - i + x] += 1
print(max(pos)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
l1 = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
l1[a[i]] = i
for i in range(n):
l2[b[i]] = i
t = [0] * (n + 1)
for i in range(1, n + 1):
x = l1[i] - l2[i]
if x >= 0:
y = x - n
else:
y = x + n
if abs(x) == min(abs(x), abs(y)):
t[x + n // 2] += 1
elif abs(y) == min(abs(x), abs(y)):
t[y + n // 2] += 1
print(max(t)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cnt = [0] * (n + 1)
for i in range(n):
cnt[a[i]] = i + 1
freq = []
for i in range(n):
start = i + 1
target = cnt[b[i]]
if start < target:
moves = start - 1 + 1 + n - target
else:
moves = start - target
freq.append(moves)
freq.sort()
ans = 0
cnt = 1
for i in range(1, len(freq)):
if freq[i] == freq[i - 1]:
cnt -= -1
else:
ans = max(ans, cnt)
cnt = 1
ans = max(ans, cnt)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda: int(input())
ip = lambda: [int(w) for w in input().split()]
n = inp()
a = ip()
b = ip()
d = [0] * n
at, bt = {}, {}
for i in range(n):
at[a[i]] = i
bt[b[i]] = i
for i in range(n):
d[i] = (bt[a[i]] - i + n) % n
dt = {}
for i in d:
dt[i] = dt.get(i, 0) + 1
print(max(dt.values())) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR DICT DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ram = [(0) for i in range(n + 1)]
shiv = [(0) for i in range(n + 1)]
for i in range(1, n + 1):
d = a[i - 1]
ram[d] = i
for i in range(1, n + 1):
d = b[i - 1]
shiv[d] = i
store = [(0) for i in range(n)]
for i in range(1, n + 1):
if ram[i] < shiv[i]:
ram[i] += n
e = ram[i] - shiv[i]
store[e] += 1
maxi = 0
for i in store:
maxi = max(maxi, i)
print(maxi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
best = 0
atoi = dict()
shifts_map = [(0) for i in range(0, n)]
for i in range(0, n):
atoi[a[i]] = i
for i in range(0, n):
curr = 0
off = (atoi[b[i]] - i) % n
shifts_map[off] += 1
if shifts_map[off] > best:
best = shifts_map[off]
print(best) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dic = {}
z = {}
x = {}
cnt = 1
for i in range(n):
z[a[i]] = i
for i in range(n):
x[b[i]] = i
for i in range(1, n + 1):
d = x[i] - z[i]
if d > 0:
d = d - n
try:
dic[d] += 1
except:
dic[d] = 1
print(max(dic.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | from sys import *
setrecursionlimit(100000000)
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip("\n")
ssi = lambda: input().strip("\n").split()
n = int(input())
a = lmi()
b = lmi()
a2 = [(0) for i in range(n + 1)]
for i in range(n):
a2[a[i]] = i + 1
b2 = [(0) for i in range(n + 1)]
for i in range(n):
b2[b[i]] = i + 1
mp = {}
for i in range(1, n + 1):
tmp = (b2[i] - a2[i]) % n
if tmp not in mp:
mp[tmp] = 0
mp[tmp] += 1
print(mp[max(mp, key=lambda x: mp[x])]) | EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | no = int(input())
dic = {}
for i in range(no):
dic[i] = 0
a = input()
a = str(a).split(" ")
a = [int(q) for q in a]
b = input()
b = str(b).split(" ")
b = [int(q) for q in b]
tem = {}
for i in range(len(a)):
tem[a[i]] = i
for j in range(len(b)):
k = tem[b[j]] - j
if k < 0:
k = no + k
dic[k] += 1
maxx = -1
for i in range(no):
maxx = max(dic[i], maxx)
print(maxx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
order_a = sorted(range(len(a)), key=lambda k: a[k])
order_b = sorted(range(len(b)), key=lambda k: b[k])
left = [0] * n
rigth = [0] * n
for i in range(n):
aux = order_a[i] - order_b[i]
if aux == 0:
left[0] += 1
rigth[0] += 1
elif aux > 0:
left[aux] += 1
rigth[n - aux] += 1
else:
left[n + aux] += 1
rigth[abs(aux)] += 1
a_max, b_max = max(rigth), max(left)
print(max(a_max, b_max)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | import sys
read = sys.stdin.buffer.readline
mi = lambda: map(int, read().split())
cin = lambda: int(read())
li = lambda: list(mi())
for _ in range(1):
n = cin()
a = li()
b = li()
ia = [0] * (n + 1)
d = {i: (0) for i in range(-n, n + 1, 1)}
for i in range(n):
ia[a[i]] = i
ans = 0
for i in range(n):
i1 = ia[b[i]]
d[i - i1] += 1
if i1 == i:
d[-n] += 1
d[n] += 1
elif i > i1:
d[-(n - i + i1)] += 1
else:
d[n - i1 + i] += 1
for i in range(-n, n + 1, 1):
ans = max(ans, d[i])
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = [(int(i) - 1) for i in input().split()]
b = [(int(i) - 1) for i in input().split()]
ia = [(-1) for i in range(n)]
ib = [(-1) for i in range(n)]
for i in range(n):
ia[a[i]] = i
ib[b[i]] = i
d = [(0) for i in range(n)]
for i in range(n):
d[i] = ia[i] - ib[i] if ia[i] > ib[i] else ia[i] - ib[i] + n
f = {i: (0) for i in set(d)}
for i in d:
f[i] += 1
an = max(f.values())
print(an) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
visited = {k: (0) for k in range(n)}
scores = [(0) for k in range(n)]
maxscore = 0
position = 0
for i in range(n):
visited[alist[i]] = i
for i in range(n):
if i <= visited[blist[i]]:
position = visited[blist[i]] - i
else:
position = n - (i - visited[blist[i]])
scores[position] += 1
if scores[position] > maxscore:
maxscore = scores[position]
print(maxscore) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
h = [0] * n
for i in range(n):
h[a[i] - 1] = i
l = []
for i in range(n):
x = h[b[i] - 1] - i
if x < 0:
x = n + x
l.append(x)
o = [0] * (n + 1)
for i in range(n):
o[l[i]] += 1
print(max(o)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
shifts = {}
ans = 1
alpha = {}
for i in range(n):
alpha[b[i]] = [i]
for i in range(n):
alpha[a[i]].append(i)
for i in range(n):
index = alpha[b[i]][1]
shift = 0
if index < i:
index = n + index
shift = index - i
if shift in shifts:
shifts[shift] += 1
else:
shifts[shift] = 1
for s in shifts:
if shifts[s] > ans:
ans = shifts[s]
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR LIST VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR |
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size $n$. Let's call them $a$ and $b$.
Note that a permutation of $n$ elements is a sequence of numbers $a_1, a_2, \ldots, a_n$, in which every number from $1$ to $n$ appears exactly once.
The message can be decoded by an arrangement of sequence $a$ and $b$, such that the number of matching pairs of elements between them is maximum. A pair of elements $a_i$ and $b_j$ is said to match if: $i = j$, that is, they are at the same index. $a_i = b_j$
His two disciples are allowed to perform the following operation any number of times: choose a number $k$ and cyclically shift one of the permutations to the left or right $k$ times.
A single cyclic shift to the left on any permutation $c$ is an operation that sets $c_1:=c_2, c_2:=c_3, \ldots, c_n:=c_1$ simultaneously. Likewise, a single cyclic shift to the right on any permutation $c$ is an operation that sets $c_1:=c_n, c_2:=c_1, \ldots, c_n:=c_{n-1}$ simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
-----Input-----
The first line of the input contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$Β β the size of the arrays.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le n)$ β the elements of the first permutation.
The third line contains $n$ integers $b_1$, $b_2$, ..., $b_n$ $(1 \le b_i \le n)$ β the elements of the second permutation.
-----Output-----
Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
-----Examples-----
Input
5
1 2 3 4 5
2 3 4 5 1
Output
5
Input
5
5 4 3 2 1
1 2 3 4 5
Output
1
Input
4
1 3 2 4
4 2 3 1
Output
2
-----Note-----
For the first case: $b$ can be shifted to the right by $k = 1$. The resulting permutations will be $\{1, 2, 3, 4, 5\}$ and $\{1, 2, 3, 4, 5\}$.
For the second case: The operation is not required. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $1$.
For the third case: $b$ can be shifted to the left by $k = 1$. The resulting permutations will be $\{1, 3, 2, 4\}$ and $\{2, 3, 1, 4\}$. Positions $2$ and $4$ have matching pairs of elements. For all possible rotations of $a$ and $b$, the number of matching pairs won't exceed $2$. | s = int(input())
a = input().split()
b = input().split()
a_positions = {a: i for i, a in enumerate(a)}
distances = [0] * s
for i, b in enumerate(b):
distances[(a_positions[b] - i) % s] += 1
print(max(distances)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.