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 = list(map(int, input().split()))
b = list(map(int, input().split()))
a_indices = [0] * n
for i in range(n):
a_indices[a[i] - 1] = i
counts = [0] * n
for i, num in enumerate(b):
num = num - 1
shift = (a_indices[num] - i + n) % n
counts[shift] += 1
print(max(counts)) | 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 FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP 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$. | n = int(input())
a = [0]
b = [0]
pos = [(0) for i in range(n + 1)]
offset = {}
arr = list(map(int, input().split()))
a += arr
for i in range(1, n + 1):
pos[a[i]] = i
arr1 = list(map(int, input().split()))
b += arr1
for i in range(1, n + 1):
cur = pos[b[i]] - i
if cur < 0:
cur += n
if cur in offset:
offset[cur] += 1
else:
offset[cur] = 1
ans = 0
for i in offset:
ans = max(offset[i], ans)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR 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 VAR VAR NUMBER ASSIGN 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$. | def most_frequent(arr, n):
max_count = 1
curr_count = 1
for i in range(1, n):
if arr[i] == arr[i - 1]:
curr_count += 1
else:
max_count = max(curr_count, max_count)
curr_count = 1
return max(max_count, curr_count)
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
hm = {}
for i in range(n):
hm[arr[i]] = [i]
for i in range(n):
hm[brr[i]].append(i)
count = []
for i in arr:
pos1 = hm[i][0]
pos2 = hm[i][1]
if pos1 == pos2:
count.append(0)
elif pos1 > pos2:
count.append(n - pos1 + pos2)
else:
count.append(pos2 - pos1)
count.sort()
print(most_frequent(count, n)) | 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR 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 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 ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR 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$. | for lo in range(1):
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ls = [(0) for i in range(n + 1)]
d = {}
for i in range(n):
ls[b[i]] = i
mx = 0
for i in range(n):
x = a[i]
y = ls[x]
z = (y - i + n) % n
if z in d:
d[z] += 1
else:
d[z] = 1
mx = max(d[z], mx)
print(mx) | FOR VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN 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().split())
(*b,) = map(int, input().split())
a_idx = {v: i for i, v in enumerate(a)}
diffs = {}
for i, v in enumerate(b):
diff = (a_idx[v] - i) % n
diffs.setdefault(diff, 0)
diffs[diff] += 1
print(max(diffs.values())) | 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 VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL 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()))
d = {}
a.insert(0, 0)
b.insert(0, 0)
for i in range(1, n + 1):
d[a[i]] = i
d1 = {}
for i in range(1, n + 1):
x = d[b[i]] - i
if x < 0:
x += n
if x not in d1:
d1[x] = 1
else:
d1[x] += 1
ma = 0
for i in d1:
if ma < d1[i]:
ma = d1[i]
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 DICT EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER 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 IF VAR VAR ASSIGN VAR VAR NUMBER VAR 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$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
adict = dict(zip(a, range(len(a))))
bdict = dict(zip(b, range(len(a))))
diff_map = {}
for i in adict.keys():
if bdict[i] <= adict[i]:
diff = adict[i] - bdict[i]
else:
diff = len(a) - bdict[i] + adict[i]
if diff in diff_map:
diff_map[diff] += 1
else:
diff_map[diff] = 1
print(max(diff_map.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 FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR IF 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$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dic1 = {}
dic2 = {}
dic3 = {}
for i in range(n):
dic1[a[i]] = i
dic2[b[i]] = i
for i in range(1, n + 1):
if dic1[i] - dic2[i] >= 0:
try:
dic3[dic1[i] - dic2[i]].append(1)
except:
dic3[dic1[i] - dic2[i]] = [1]
else:
try:
dic3[n - (dic2[i] - dic1[i])].append(1)
except:
dic3[n - dic2[i] + dic1[i]] = [1]
m = 0
for i in dic3:
m = max(len(dic3[i]), m)
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 DICT ASSIGN VAR DICT ASSIGN VAR DICT 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 IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL 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 = list(map(int, input().split()))
B = list(map(int, input().split()))
A = [(a - 1) for a in A]
B = [(b - 1) for b in B]
d = {}
for i, b in enumerate(B):
d[b] = i
D = {}
for i, a in enumerate(A):
j = i - d[a]
if j < 0:
j += n
if j not in D:
D[j] = 1
else:
D[j] += 1
ans = max(D.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 BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER 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$. | def rotmatch(n, a, b):
placea = [0] * n
placeb = [0] * n
diff = [0] * n
for i in range(n):
placea[a[i] - 1] = i
for i in range(n):
placeb[b[i] - 1] = i
for i in range(n):
diff[i] = (n - placea[i] + placeb[i]) % n
ats = [0] * n
for d in diff:
ats[d] += 1
return max(ats)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(rotmatch(n, a, b)) | FUNC_DEF 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 VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL 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 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$. | import sys
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = {}
for i in range(n):
d[a[i]] = [i]
for j in range(n):
d[b[j]].append(j)
right = [0] * n
left = [0] * n
for i in d:
left_ = d[i][1] - d[i][0]
right_ = d[i][0] - d[i][1]
if left_ < 0:
left_ += n
if right_ < 0:
right_ += n
right[right_] += 1
left[left_] += 1
print(max(max(left), max(right))) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER 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 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 ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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, m = int(input()), set()
s, v, d, a = input().split(), input().split(), dict(), dict()
for i in range(n):
d[s[i]] = i
for i in range(n):
if i - d[v[i]] < 0:
a[n + i - d[v[i]]] = a.get(n + i - d[v[i]], 0) + 1
else:
a[i - d[v[i]]] = a.get(i - d[v[i]], 0) + 1
for i in a:
m.add(a[i])
print(max(m)) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
bm = {}
for i in range(n):
bm[b[i]] = i
temp = []
for i in range(n):
j = bm[a[i]]
if i < j:
temp.append(j - i)
else:
temp.append(n - i + j)
freq = [0] * (n + 1)
for i in temp:
freq[i] += 1
print(max(freq)) | 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 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 EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER 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$. | from sys import stdin
def main():
n = int(stdin.readline())
b1 = [int(i) for i in stdin.readline().split()]
b2 = [int(i) for i in stdin.readline().split()]
d = [(0) for i in range(n)]
for i in range(n):
d[b1[i] - 1] = i
o = dict()
for i in range(n):
s = d[b2[i] - 1]
if s < i:
s += n
m = s - i
if s == i:
m = 0
else:
m = s - i
if m in o:
o[m] += 1
else:
o[m] = 1
print(max(o.values()))
main() | 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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN 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()))
d1 = {}
d2 = {}
c = {}
for x in range(n):
d1[a[x]] = x
d2[b[x]] = x
for x in range(1, n + 1):
if d1[x] - d2[x] < 0:
d1[x] += n
if d1[x] - d2[x] in c:
c[d1[x] - d2[x]] += 1
else:
c[d1[x] - d2[x]] = 1
print(max(c.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 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 IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR 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())
str1 = {val: id for id, val in enumerate(input().split())}
str2 = {val: id for id, val in enumerate(input().split())}
dists = {}
for key in str1:
d1, d2 = len(str1) + str1[key] - str2[key], str1[key] - str2[key]
dist = min(d1, d2) if d2 >= 0 else d1
if dist not in dists:
dists[dist] = 0
dists[dist] += 1
print(max(dists.values())) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL 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$. | size = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(size):
A[i] = A[i], i
B[i] = B[i], i
A.sort(key=lambda x: x[0])
B.sort(key=lambda x: x[0])
rotations = [0] * size
for i in range(size):
diff = A[i][1] - B[i][1]
if diff < 0:
diff = size + diff
rotations[diff] += 1
print(max(rotations)) | 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 VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER 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$. | def solve(n, a, b):
indexOfB = [0] * n
right = [(0) for _ in range(n)]
left = [(0) for _ in range(n)]
for i in range(n):
indexOfB[b[i] - 1] = i
for i in range(n):
k = i - indexOfB[a[i] - 1]
if k < 0:
right[abs(k)] += 1
left[n - abs(k)] += 1
elif k == 0:
right[0] += 1
left[0] += 1
else:
right[n - k] += 1
left[k] += 1
return max(max(right), max(left))
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER 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 BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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 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$. | def findPairs(ax, bx):
diffL = {}
for i in ax.keys():
diff = ax[i] - bx[i]
if diff < 0:
diff += len(ax)
if diff not in diffL:
diffL[diff] = 1
else:
diffL[diff] += 1
print(max(diffL.values()))
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ax = {}
bx = {}
for idx, ele in enumerate(a):
ax[ele] = idx
for idx, ele in enumerate(b):
bx[ele] = idx
findPairs(ax, bx) | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR 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
from sys import stdin
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
def neo():
return map(int, input().split())
def Neo():
return list(map(int, input().split()))
n = int(input())
A = Neo()
B = Neo()
mp1 = {}
mp2 = {}
for i in range(n):
mp1[B[i]] = i
for i in range(n):
if mp1[A[i]] >= i:
if mp2.get(mp1[A[i]] - i, 0) == 0:
mp2[mp1[A[i]] - i] = 1
else:
mp2[mp1[A[i]] - i] += 1
elif mp2.get(n - i + mp1[A[i]], 0) == 0:
mp2[n - i + mp1[A[i]]] = 1
else:
mp2[n - i + mp1[A[i]]] += 1
print(max(mp2.values())) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 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 VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR 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$. | def f(n, a, b):
smax = 0
for d in range(n):
s = 0
for i in range(n):
j = (i + d) % n
if a[i] == b[j]:
s += 1
if s > smax:
smax = s
return smax
n = int(input())
a = [(int(x) - 1) for x in input().split()]
b = [(int(x) - 1) for x in input().split()]
r = [0] * n
for i, x in enumerate(a):
r[x] = i
def recod(a):
for i in range(n):
a[i] = r[a[i]]
recod(b)
for i in range(n):
r[i] = (b[i] - i + n) % n
c = [0] * n
for i in range(n):
c[r[i]] += 1
print(max(c)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR RETURN 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 BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR 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$. | def solve():
n = int(input())
_A = list(input().split(" "))
_B = list(input().split(" "))
A = sorted([(_A[i], i) for i in range(n)])
B = sorted([(_B[i], i) for i in range(n)])
ans = [0] * n
for i in range(n):
ans[(n + A[i][1] - B[i][1]) % n] += 1
return max(ans)
print(solve()) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR VAR EXPR 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(" ")))
dis = {}
L = {}
R = {}
maxL, maxR = 0, 0
k = 0
for i in B:
dis[i] = k
k += 1
for i in range(n):
p = A[i]
ind = dis[p]
if ind - i > 0:
l = ind - i
r = n - l
elif i - ind > 0:
r = i - ind
l = n - r
elif i == ind:
l = r = 0
if l in L:
L[l] += 1
else:
L[l] = 1
if r in R:
R[r] += 1
else:
R[r] = 1
maxL = max(maxL, L[l])
maxR = max(maxR, R[r])
print(max(maxL, maxR)) | 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 DICT ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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())
orig = list(map(int, input().split()))
rot = list(map(int, input().split()))
pos = [0] * (n + 1)
rs = [0] * (n + 1)
rsMax = [0] * (n + 1)
ls = [0] * (n + 1)
lsMax = [0] * (n + 1)
for i in range(n):
pos[orig[i]] = i + 1
for i in range(n):
k = rot[i]
rs[k] = (pos[k] - i + 1 + n) % n
ls[k] = (i + 1 - pos[k] + n) % n
rsMax[rs[k]] += 1
lsMax[ls[k]] += 1
print(max(max(rsMax), max(lsMax))) | 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 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 ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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())
arrayA = [int(x) for x in input().split()]
arrayB = [int(x) for x in input().split()]
pairs = [[] for i in range(N)]
for i in range(N):
pairs[arrayA[i] - 1].append(i)
for i in range(N):
pairs[arrayB[i] - 1].append(i)
checker = []
for i in pairs:
if i[0] < i[1]:
i[0] += N
checker.append(i[0] - i[1])
def mostfrequent(x):
dictionary = {}
for i in x:
if i in dictionary:
dictionary[i] += 1
else:
dictionary[i] = 1
counter = []
for i in dictionary:
counter.append(dictionary[i])
return max(counter)
print(mostfrequent(checker)) | 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 VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR 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$. | def count_equals(arr1, arr2, x):
n = len(arr1)
ct = 0
for i in range(n):
if arr1[i] == arr2[(i + x) % n]:
ct += 1
return ct
n = int(input())
arr1 = list(map(lambda x: int(x) - 1, input().split()))
arr2 = list(map(lambda x: int(x) - 1, input().split()))
ma = 0
pos1 = [0] * n
pos2 = [0] * n
for i in range(n):
pos1[arr1[i]] = i
pos2[arr2[i]] = i
ct = [0] * n
for i in range(n):
ct[(pos1[i] - pos2[i] + n) % n] += 1
print(max(ct)) | FUNC_DEF ASSIGN 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 RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER 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 VAR BIN_OP BIN_OP BIN_OP 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 answer(n, A, B):
dp1 = [0] * (n + 1)
dp2 = [0] * (n + 1)
for i in range(n):
dp1[A[i]] = i
dp2[B[i]] = i
d = [0] * n
for i in range(1, n + 1):
if dp1[i] - dp2[i] >= 0:
d[dp1[i] - dp2[i]] += 1
else:
d[n - dp2[i] + dp1[i]] += 1
return max(d)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(answer(n, a, b)) | FUNC_DEF 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 ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL 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 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().split()))
b = list(map(int, input().split()))
la = [0] * (n + 1)
lb = [0] * (n + 1)
for i in range(n):
la[a[i]] = i
lb[b[i]] = i
dic = {}
for i in range(1, n + 1):
diff = lb[i] - la[i]
if diff < 0:
diff = n + diff
dic[diff] = dic.get(diff, 0) + 1
mx = 0
for key in dic:
if dic[key] > mx:
mx = dic[key]
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 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 ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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$. | def main():
n = int(input())
values1 = list(map(int, input().split()))
values2 = list(map(int, input().split()))
dict_1 = [(0) for i in range(n)]
for i in range(n):
dict_1[values1[i] - 1] = i
shift = [(0) for i in range(n)]
for i in range(n):
shift[i] = (n + dict_1[values2[i] - 1] - i) % n
answer = [(0) for i in range(n)]
for i in range(n):
answer[shift[i]] += 1
ans = 0
for i in answer:
ans = max(i, ans)
print(ans)
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 NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL 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
a = int(stdin.readline())
z = [0] * (a + 1)
z1 = [0] * (a + 1)
for k, i in enumerate(
zip(map(int, stdin.readline().split()), map(int, stdin.readline().split()))
):
z[i[0]] = k
z1[i[1]] = k
d = {}
for i in range(1, a + 1):
if z1[i] >= z[i]:
f = z1[i] - z[i]
d[f] = d.get(f, 0) + 1
else:
f = a - z[i] + z1[i]
d[f] = d.get(f, 0) + 1
print(max(d.values())) | 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 FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP 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 |
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 = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
c = [0] * (n + 1)
count = dict()
for i in range(1, n + 1):
c[a[i]] = i
for i in range(1, n + 1):
cur = (c[b[i]] - i + n) % n
try:
count[cur] += 1
except:
count[cur] = 1
print(max(count.values())) | IMPORT ASSIGN VAR VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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 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$. | import sys
input = sys.stdin.readline
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split())) * 2
pos = [0] * (2 * n)
u = {}
l = {}
for i in range(n):
u[arr1[i]] = i
for i in range(n):
l[arr2[i]] = i
for i in range(n):
pos[(l[arr1[i]] - u[arr1[i]]) % n] += 1
print(max(pos)) | IMPORT 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 BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER 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 VAR VAR VAR FOR VAR FUNC_CALL VAR VAR 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$. | n = int(input())
a = [(int(i) - 1) for i in input().split()]
b = [(int(i) - 1) for i in input().split()]
aindex = [0] * n
for i in range(n):
aindex[a[i]] = i
bindex = [0] * n
for i in range(n):
bindex[b[i]] = i
shifts = [0] * n
for i in range(n):
if a[i] == b[i]:
shifts[0] += 1
elif i < bindex[a[i]]:
shifts[bindex[a[i]] - i] += 1
elif i > bindex[a[i]]:
shifts[n - i + bindex[a[i]]] += 1
print(max(shifts)) | 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR 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()))
d = {}
x = {}
y = {}
for i in range(n):
d[b[i]] = i
for i in range(n):
t = i - d[a[i]]
if t > 0:
if t in x:
x[t] += 1
else:
x[t] = 1
if n - t in y:
y[n - t] += 1
else:
y[n - t] = 1
else:
t = abs(t)
if t in y:
y[t] += 1
else:
y[t] = 1
if n - t in x:
x[n - t] += 1
else:
x[n - t] = 1
print(max(max(x.values()), max(y.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 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 IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP 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$. | import sys
input = sys.stdin.readline
t = 1
while t > 0:
t -= 1
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = [(0) for i in range(n + 1)]
for i in range(n):
d[a[i]] = i
for i in range(n):
b[i] = d[b[i]]
d = {}
for i in range(n):
if (b[i] - i + n) % n not in d:
d[(b[i] - i + n) % n] = 0
d[(b[i] - i + n) % n] += 1
maxi = 0
for i in d:
maxi = max(maxi, d[i])
print(min(maxi, n)) | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER 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 ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER 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$. | arr_size = int(input())
dict_a = dict()
for i, a in enumerate(list(map(int, input().split())), start=1):
dict_a[a] = i
dict_b = dict()
for i, b in enumerate(list(map(int, input().split())), start=1):
key = (i - dict_a[b]) % arr_size
if key in dict_b:
dict_b[key] += 1
else:
dict_b[key] = 1
result = max(dict_b.values())
print(result) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN 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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d1 = {}
d2 = {}
l = [0] * n
for i in range(n):
d1[a[i]] = i
for i in range(n):
d2[b[i]] = i
for i in a:
k = d1[i] - d2[i]
if k < 0:
k += n
l[k] += 1
print(max(l)) | 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR 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$. | from sys import stdin
inp = lambda: stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
b = [int(x) for x in inp().split()]
index = [0] * (n + 1)
ans = [0] * (n + 5)
for i in range(n):
index[a[i]] = i + 1
for i in range(n):
shift = index[b[i]] - i
if shift < 0:
shift += n
ans[shift] += 1
print(max(ans)) | ASSIGN VAR FUNC_CALL FUNC_CALL 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 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 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())
arr1 = [int(c) for c in input().split()]
arr2 = [int(c) for c in input().split()]
dic1 = {}
dic2 = {}
for i in range(n):
dic1[arr1[i]] = i
dic2[arr2[i]] = i
lshift = [(0) for i in range(n)]
rshift = [(0) for i in range(n)]
lcount = {}
rcount = {}
for i in range(n):
dig = arr1[i]
ind = dic2[dig]
if ind <= i:
lsh = i - ind
else:
lsh = i + (n - ind)
if ind >= i:
rsh = ind - i
else:
rsh = ind + n - i
lshift[i] = lsh
rshift[i] = rsh
for i in range(n):
lcount[lshift[i]] = lcount.get(lshift[i], 0) + 1
rcount[rshift[i]] = rcount.get(rshift[i], 0) + 1
ans = 1
for i in lcount.keys():
ans = max(ans, lcount[i])
for i in rcount.keys():
ans = max(ans, rcount[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 NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL 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$. | from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))
(n,) = mp()
a = mp()
b = mp()
pos = [0] * (n + 1)
ans = [0] * n
for i in range(n):
pos[b[i]] = i
k = 0
for i in range(n):
ans[(pos[a[i]] - i) % n] += 1
cout(str(sorted(ans, reverse=True)[0])) | ASSIGN VAR VAR ASSIGN VAR 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER |
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()))
a = [0] + a
b = [0] + b
pos = [(0) for i in range(n + 1)]
ans = 0
d = {}
for i in range(1, n + 1):
pos[a[i]] = i
for i in range(1, n + 1):
curr = pos[b[i]] - i
if curr < 0:
curr += n
if curr not in d:
d[curr] = 1
else:
d[curr] += 1
ans = max(ans, d[curr])
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 VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER 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 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 solve():
T = int(input())
A = [int(s) for s in input().split(" ")]
B = [int(s) for s in input().split(" ")]
lst = [(0) for _ in range(len(A))]
for i in range(len(A)):
lst[A[i] - 1] += i
lst[B[i] - 1] -= i
for i in range(len(lst)):
lst[i] %= len(A)
counts = [(0) for _ in range(len(A))]
for num in lst:
counts[num] += 1
print(max(counts))
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR 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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = [(0) for i in range(n + 1)]
y = [(0) for i in range(n + 1)]
z = [(0) for i in range(2 * n + 10)]
for i in range(n):
x[a[i]] = i + 1
for i in range(n):
y[b[i]] = i + 1
for i in range(1, n + 1):
if x[i] - y[i] > 0:
z[x[i] - y[i] + 1] += 1
else:
z[x[i] - y[i] + n + 1] += 1
ans = 0
for i in z:
ans = max(ans, 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER 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()))
id = [dict(), dict()]
for i in range(n):
id[0][a[i]] = i
id[1][b[i]] = i
ans = dict()
for i in range(1, n + 1):
d = (n + id[0][i] - id[1][i]) % n
if d not in ans.keys():
ans[d] = 1
else:
ans[d] += 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 LIST FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR IF VAR FUNC_CALL 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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
pos = [0] * n
moves = [0] * n
for i in range(n):
pos[a[i] - 1] = i + 1
for i in range(n):
if pos[b[i] - 1] > i + 1:
moves[n - pos[b[i] - 1] + i + 1] += 1
else:
moves[i + 1 - pos[b[i] - 1]] += 1
print(max(moves)) | 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 ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER 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())
freq = [0] * n
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
arr1 = sorted(range(len(arr1)), key=lambda k: arr1[k])
arr2 = sorted(range(len(arr2)), key=lambda k: arr2[k])
for x in range(n):
freq[(arr1[x] - arr2[x]) % n] += 1
print(max(freq)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER 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 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$. | def maxRepeating(Arr, n, k):
arr = Arr[:]
for i in range(0, n):
arr[arr[i] % k] += k
max = arr[0]
result = 0
for i in range(1, n):
if arr[i] > max:
max = arr[i]
result = i
return result
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aindex = [0] * n
bindex = [0] * n
difarr = [0] * n
for i in range(n):
aindex[a[i] - 1] = i
bindex[b[i] - 1] = i
for i in range(n):
if aindex[i] >= bindex[i]:
difarr[i] = aindex[i] - bindex[i]
else:
difarr[i] = n - (bindex[i] - aindex[i])
print(difarr.count(maxRepeating(difarr, n, n))) | FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR 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 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 IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR 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())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
pos = [0] * (n + 1)
data = [0] * (n + 1)
for i in range(1, n + 1):
pos[arr1[i - 1]] = i
for i in range(1, n + 1):
curr = pos[arr2[i - 1]] - i
if curr < 0:
curr += n
data[curr] += 1
print(max(data)) | 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER 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 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(array1, array2):
posArr = []
offArr = []
for i in range(len(array1)):
posArr.append(0)
offArr.append(0)
for i, elem in enumerate(array1):
posArr[elem - 1] = i
maxOff = 0
for i, elem in enumerate(array2):
offArr[elem - 1] = posArr[elem - 1] - i
if offArr[elem - 1] < 0:
offArr[elem - 1] += len(offArr)
if maxOff < offArr[elem - 1]:
maxOff = offArr[elem - 1]
offCount = []
for i in range(maxOff + 1):
offCount.append(0)
for elem in offArr:
offCount[elem] += 1
return max(offCount)
input()
while True:
try:
v1 = input().split(" ")
v2 = input().split(" ")
for i in range(len(v1)):
v1[i] = int(v1[i])
v2[i] = int(v2[i])
print(solve(v1, v2))
except EOFError:
break | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR 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$. | def diff(a, b, num):
n = a[num]
d = num - c[n] % len(a)
if d < 0:
d = len(a) + d
return d
n = int(input())
a = [(int(i) - 1) for i in input().split(" ")]
b = [(int(i) - 1) for i in input().split(" ")]
c = [None for i in range(n)]
for p, e in enumerate(b):
c[e] = p
diffs = [diff(a, c, i) for i in range(n)]
distances = {}
maximum = 0
for d in diffs:
if d in distances:
distances[d] += 1
else:
distances[d] = 1
maximum = max(maximum, distances[d])
print(maximum) | FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN 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())
mas1 = list(map(str, input().split()))
mas2 = list(map(str, input().split()))
s = {}
for i in range(n):
s[mas1[i]] = i
ans = {}
for i in range(n):
x = s[mas2[i]]
if i <= x:
ans[x - i] = ans.get(x - i, 0) + 1
else:
ans[n - i + x] = ans.get(n - i + x, 0) + 1
maxi = 0
for i in ans.items():
maxi = max(maxi, i[1])
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 DICT FOR VAR FUNC_CALL 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 BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR 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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pa = [0] * (n + 1)
pb = [0] * (n + 1)
for i in range(0, n):
pa[a[i]] = i
pb[b[i]] = i
pa.pop(0)
pb.pop(0)
d = []
for i in range(0, n):
d.append((pa[i] - pb[i]) % n)
f = [0] * n
for i in d:
f[i] += 1
print(max(f)) | 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 NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR 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$. | def getMaxMatchingPairs(a, b):
mapB = {elm: index for index, elm in enumerate(b)}
maxPairs = 0
countMap = {}
n = len(a)
for i, elm in enumerate(a):
dist = mapB[elm] - i if mapB[elm] > i else n + mapB[elm] - i
countMap[dist] = countMap.get(dist, 0) + 1
if maxPairs < countMap[dist]:
maxPairs = countMap[dist]
return maxPairs
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(getMaxMatchingPairs(a, b)) | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER 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 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 = input().split()
ai = [int(i) for i in a]
b = input().split()
bi = [int(i) for i in b]
arr = [[] for i in range(n)]
for i in range(n):
arr[ai[i] - 1].append(i)
for i in range(n):
arr[bi[i] - 1].append(i)
fina = [(0) for i in range(n)]
for i in arr:
x = i[0]
y = i[1]
if y >= x:
fina[y - x] += 1
else:
fina[n + y - x] += 1
print(max(fina)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR 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$. | def solve():
n = int(input().strip())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
a_ = [None for i in range(n + 1)]
b_ = [None for i in range(n + 1)]
for i in range(n):
a_[a[i]] = i + 1
b_[b[i]] = i + 1
diff_ar = [(0) for i in range(n + 1)]
max_diff = 0
for i in range(1, n + 1):
curr_diff = (a_[i] - b_[i]) % n
diff_ar[curr_diff] += 1
max_diff = max(max_diff, diff_ar[curr_diff])
print(max_diff)
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 BIN_OP VAR NUMBER 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 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(x) for x in input().split()]
b = [int(x) for x in input().split()]
pos = [0] * (n + 1)
for i in range(0, n):
val = b[i]
pos[val] = i
d = dict()
for i in range(0, n):
val = a[i]
posn = pos[val]
diff = posn - i
if diff < 0:
diff = n + diff
if diff not in d:
d[diff] = 1
else:
d[diff] += 1
mxval = 0
for i in d:
val = d[i]
mxval = max(mxval, val)
print(mxval) | 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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR 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())
arr = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
a = dict()
right = dict()
for i in range(n):
a[arr[i]] = i
for idxB in range(n):
val = b[idxB]
idxA = a[val]
k = idxA - idxB
if k < 0:
try:
right[abs(k)] += 1
except KeyError:
right[abs(k)] = 1
else:
try:
right[n - k] += 1
except KeyError:
right[n - k] = 1
ans = 1
for k, v in right.items():
ans = max(ans, v)
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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR 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$. | import sys
input = lambda: sys.stdin.readline().strip()
li = lambda: list(map(int, input().split()))
I = lambda: int(input())
n = I()
a = li()
b = li()
ans = 0
ma = {}
mb = {}
for i in range(n):
ma[b[i]] = i
mb[a[i]] = i
dm = {}
for i in range(0, n + 1):
dm[i] = 0
for i in range(1, n + 1):
dm[(ma[i] - mb[i]) % n] += 1
print(max(dm.values())) | IMPORT ASSIGN 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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 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())
arr = list(map(int, input().strip().split()))
brr = list(map(int, input().strip().split()))
d = dict()
e = dict()
for i in range(1, n + 1):
d[i] = 0
for i in range(n):
a = arr[i]
e[a] = i
for j in range(n):
b = brr[j]
t = e[b]
if t > j:
q = t - j
d[q] = d[q] + 1
elif t <= j:
q = n - j + t
d[q] = d[q] + 1
out = 0
for i in range(1, n + 1):
if d[i] >= out:
out = d[i]
print(out) | 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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP 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()))
d = {}
for i in range(1, n + 1):
d[i] = [0, 0, 0]
for i in range(n):
d[a[i]][0] = i
d[b[i]][1] = i
for i in range(1, n + 1):
x = d[i][0] - d[i][1]
if x > 0:
d[i][2] = x
else:
d[i][2] = n + x
d2 = {}
for i in range(1, n + 1):
if d[i][2] not in d2:
d2[d[i][2]] = 1
else:
d2[d[i][2]] += 1
m = 0
for i in d2.keys():
if d2[i] > m:
m = d2[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 DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST NUMBER NUMBER 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 BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER 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$. | n = int(input())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
d1 = dict()
d2 = dict()
for i in range(n):
d1[l1[i]] = i
d2[l2[i]] = i
l = [(0) for i in range(n + 1)]
for k in d1.keys():
try:
if d1[k] <= d2[k]:
d = d2[k] - d1[k]
l[d] += 1
else:
d = n - d1[k] - 1 + d2[k] + 1
l[d] += 1
except:
pass
print(max(l)) | 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP 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()))
arr = [[] for i in range(n)]
for i in range(n):
arr[a[i] - 1].append(i + 1)
for i in range(n):
arr[b[i] - 1].append(i + 1)
ans = [[] for i in range(n)]
for i in range(n):
if arr[i][0] > arr[i][1]:
ans[i].append(arr[i][0] - arr[i][1])
elif arr[i][0] < arr[i][1]:
ans[i].append(arr[i][0] + n - arr[i][1])
else:
ans[i].append(0)
for i in range(n):
if arr[i][0] < arr[i][1]:
ans[i].append(arr[i][1] - arr[i][0])
elif arr[i][0] > arr[i][1]:
ans[i].append(arr[i][1] + n - arr[i][0])
else:
ans[i].append(0)
array = [0] * n
array2 = [0] * n
for i in range(n):
array[ans[i][0] - 1] += 1
for i in range(n):
array2[ans[i][1] - 1] += 1
x = max(array)
y = max(array2)
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 LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER 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 NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [0] * 200005
t1 = [0] * 200005
for i in range(n):
t[a[i]] = i
t1[b[i]] = i
ans = [0] * 200005
for i in range(1, n + 1):
ans[(t[i] - t1[i] + n) % n] = ans[(t[i] - t1[i] + n) % n] + 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 BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP 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 solve():
n = int(input())
posinarr = [0] * n
posinbrr = [0] * n
mp = {}
ans = 0
arr = [(int(v) - 1) for v in input().split()]
brr = [(int(v) - 1) for v in input().split()]
for i in range(n):
posinarr[arr[i]] = i
posinbrr[brr[i]] = i
j = 0
for i in range(2 * n - 1):
idx = i % n
diag = posinarr[brr[idx]] - i
mp.setdefault(diag, 0)
mp[diag] += 1
if i >= n:
diagrem = posinarr[brr[j]] - posinbrr[brr[j]]
mp[diagrem] -= 1
j += 1
ans = max(mp[diag], ans)
print(ans)
solve() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR DICT ASSIGN VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER 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(x) for x in input().split()]
b = [int(x) for x in input().split()]
pos = {}
for i in range(n):
pos[a[i]] = i + 1
freq = {}
for i in range(n):
x = i + 1
y = pos[b[i]]
dist = (y - x + n) % n
if dist not in freq:
freq[dist] = 1
else:
freq[dist] += 1
max_k, max_v = -1, -1
for k, v in freq.items():
if v > max_v:
max_v = v
max_k = k
print(max_v) | 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 BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN 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$. | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_ind = [i[0] for i in sorted(enumerate(a), key=lambda x: x[1])]
b_ind = [i[0] for i in sorted(enumerate(b), key=lambda x: x[1])]
right_shifts = n * [0]
counts = n * [0]
for i in range(n):
if b_ind[i] >= a_ind[i]:
right_shifts[i] = b_ind[i] - a_ind[i]
else:
right_shifts[i] = n - abs(b_ind[i] - a_ind[i])
counts[right_shifts[i] - 1] += 1
print(max(counts)) | 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 FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER ASSIGN VAR BIN_OP VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR 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$. | def count(arr1, arr2):
value = 0
for i in range(len(arr1)):
if arr1[i] == arr2[i]:
value += 1
return value
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos_in_a = dict()
for j in range(n):
pos_in_a[a[j]] = j
num_of_shifts = dict()
for i in range(0, n):
num_of_shifts[i] = []
for i in range(n):
difference = pos_in_a[b[i]] - i
if difference >= 0:
num_of_shifts[difference].append(b[i])
else:
num_of_shifts[n + difference].append(b[i])
final_ans = [-1, -1]
for key in num_of_shifts.keys():
if len(num_of_shifts[key]) > final_ans[1]:
final_ans[0] = key
final_ans[1] = len(num_of_shifts[key])
print(final_ans[1]) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
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 = input().split(" ")
b = input().split(" ")
mapA = [0] * (n + 1)
for i in range(n):
mapA[int(a[i])] = i
mapB = [0] * (n + 1)
for i in range(n):
ta = mapA[int(b[i])]
tb = i
k = -1
if ta < tb:
k = n - tb + ta
else:
k = ta - tb
mapB[k] += 1
print(max(mapB)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR 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 = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
da = {}
db = {}
for i in range(N):
da[a[i]] = i
db[b[i]] = i
counts = {}
for i in range(1, N + 1):
if db[i] > da[i]:
count = da[i] + N - db[i]
else:
count = da[i] - db[i]
if count in counts.keys():
counts[count] += 1
else:
counts[count] = 1
maxi = -1
for count in counts.keys():
if counts[count] > maxi:
maxi = counts[count]
print(maxi) | 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 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 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 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$. | a = int(input())
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m, n = {}, {}
for i in range(a):
m[b[i]] = i + 1
n[c[i]] = i + 1
d = {}
for j in b:
if m[j] <= n[j]:
z = n[j] - m[j]
else:
z = a - (m[j] - n[j])
if z in d:
d[z] += 1
else:
d[z] = 1
print(max(d.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 VAR DICT DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR 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 IF 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$. | n = int(input())
d1 = {}
d2 = {}
l1 = list(map(int, input().split()))
for i in range(n):
d1[l1[i]] = i
l2 = list(map(int, input().split()))
for i in range(n):
d2[l2[i]] = i
m = 0
res = [0] * (n + 1)
for i in range(1, n + 1):
m = (d2[i] - d1[i] + n) % n
res[m] += 1
ans = -1
for i in range(n):
ans = max(ans, res[i])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR 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 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 = input()
A = list(map(int, list(a.split())))
b = input()
B = list(map(int, list(b.split())))
f = [0] * n
table = [0] * (n + 1)
for i in range(n):
table[A[i]] = i
for i in range(n):
k = table[B[i]]
if k - i >= 0:
f[k - i] = f[k - i] + 1
else:
f[n - (i - k)] = f[n - (i - k)] + 1
print(max(f)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR 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 IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP 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$. | n = int(input())
ls1 = input().split()
ls2 = input().split()
mymap = dict()
for i in range(n):
mymap[ls1[i]] = i
answer = dict()
for i in range(n):
mymap[ls2[i]] -= i
x = mymap[ls2[i]] % n
if x in answer:
answer[x] = answer[x] + 1
else:
answer[x] = 1
fin = -1
for x in answer:
fin = max(fin, answer[x])
print(fin) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN 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$. | def solve():
n = int(input())
ll = list(map(int, input().split()))
mp = {}
for i in range(n):
mp[ll[i]] = i + 1
ll1 = list(map(int, input().split()))
ans = 0
mp1 = {}
for i in range(n):
temp = mp[ll1[i]] - i - 1
if temp < 0:
temp += n
if temp in mp1:
mp1[temp] += 1
else:
mp1[temp] = 1
ans = max(ans, mp1[temp])
return ans
t = 1
while t != 0:
res = solve()
print(res)
t -= 1 | 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 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 NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
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 = [x for x in input().split(" ")]
b = [x for x in input().split(" ")]
e = {}
f = {}
for i in range(n):
e[a[i]] = i
for j in range(n):
x = e[b[j]]
x = (x - j) % n
y = f.get(x, 0)
f[x] = y + 1
ans = 1
for k in f.keys():
ans = max(ans, f[k])
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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(i) for i in input().split()]
b = [int(i) for i in input().split()]
d1 = dict()
d2 = dict()
for i in range(len(a)):
d1[a[i]] = i
for i in range(len(b)):
d2[b[i]] = i
ans = []
pp = dict()
for i in range(len(a)):
r = d1[a[i]] - d2[a[i]]
if r < 0:
r += len(a)
if r in pp:
pp[r] += 1
else:
pp[r] = 1
ans.append(r)
all_values = pp.values()
max_value = max(all_values)
print(max_value) | 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 ASSIGN VAR FUNC_CALL VAR 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 LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN 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$. | n = int(input())
a = list(map(int, input().split()))
i = 0
ind = {}
for el in input().split():
ind[int(el)] = i
i += 1
count = [(0) for _ in range(n)]
for i in range(n):
j = ind[a[i]]
if j >= i:
count[j - i] += 1
else:
count[n - i + j] += 1
print(max(count)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR 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 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$. | for _ in range(1):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
right = [(0) for i in range(n + 1)]
for i in range(n):
right[a[i]] = i + 1
for i in range(n):
c = b[i]
if right[c] >= i + 1:
right[c] -= i + 1
else:
right[c] = n - (i + 1) + right[c]
left = [(0) for i in range(n + 1)]
for i in range(n):
left[a[i]] = i + 1
for i in range(n):
c = b[i]
if left[c] <= i + 1:
left[c] -= i + 1
left[c] = abs(left[c])
else:
left[c] = i + 1 + n - left[c]
c = [(0) for i in range(n + 1)]
for i in left[1:]:
c[i] += 1
ans = max(c)
c = [(0) for i in range(n + 1)]
for i in range(1, n):
c[right[i]] += 1
print(max(ans, max(c))) | 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 VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR 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())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
positionAdict = dict()
positionBdict = dict()
for i in range(n):
positionAdict[arrA[i]] = i
positionBdict[arrB[i]] = i
moveCount = [0] * n
for i in range(n):
if i < positionBdict[arrA[i]]:
moveCount[n - positionBdict[arrA[i]] + i] += 1
else:
moveCount[abs(i - positionBdict[arrA[i]])] += 1
result = 1
for i in range(n):
if moveCount[i] > result:
result = moveCount[i]
print(result) | 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
d = []
h = [0] * (n + 2)
indexArray = [0] * n
for i in range(n):
indexArray[a[i] - 1] = i
for i in range(n):
f = indexArray[b[i] - 1]
if i <= f:
d.append(f - i)
else:
d.append(n - i + f)
for i in range(n):
h[d[i]] += 1
H = 1
for i in range(n):
H = max(H, h[i])
print(H) | 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER 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 VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR 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 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()]
A = [0] * n
B = [0] * n
for i in range(n):
A[a[i] - 1] = i
B[b[i] - 1] = i
dp = [0] * n
for i in range(n):
dp[A[i] - B[i]] += 1
print(max(dp)) | 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 ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR 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$. | def solve(n, a, b):
mp = [-1] * n
for i, x in enumerate(a):
mp[x - 1] = i + 1
for i in range(n):
b[i] = mp[b[i] - 1]
bb = b + b
mdiff = {}
sol = 0
for i, x in enumerate(bb):
bbdiff = i - x
mdiff[bbdiff] = mdiff.get(bbdiff, 0) + 1
if i >= n:
ii = i - n
mdiff[ii - bb[ii]] -= 1
sol = max(sol, mdiff[bbdiff])
return sol
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b)) | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 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$. | def cast(cre, typ):
return type(typ)(map(cre, typ))
def solution():
n = int(input())
a, b = cast(int, input().split()), cast(int, input().split())
a_idx, b_idx = [(0) for i in range(n + 1)], [(0) for i in range(n + 1)]
for i in range(n):
a_idx[a[i]] = i
b_idx[b[i]] = i
amt = [(0) for i in range(n)]
for i in range(1, n + 1):
amt[(n + (a_idx[i] - b_idx[i])) % n] += 1
print(max(amt))
solution() | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR 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$. | dict1 = {}
dict2 = {}
n = int(input())
p1 = list(map(int, input().split()))
for i in range(n):
dict1[p1[i]] = i
p2 = list(map(int, input().split()))
for i in range(n):
dict2[p2[i]] = i
d = []
for i in range(1, n + 1):
d.append((dict1[i] - dict2[i]) % n)
f = [0] * n
for i in d:
f[i] += 1
print(max(f)) | ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR 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$. | n = int(input())
lis1 = list(map(int, input().split()))
lis2 = list(map(int, input().split()))
m = [(0) for i in range(n)]
for j, i in enumerate(lis2):
m[i - 1] = j
lis = [(0) for i in range(n)]
for i, k in enumerate(lis1):
ind = m[k - 1]
if ind >= i:
lis[ind - i] += 1
else:
lis[n - i + ind] += 1
print(max(lis)) | 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 FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR 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$. | import sys
input = sys.stdin.readline
def shift_left(n, ai, bi):
if ai == bi:
return n
elif ai < bi:
return bi - ai
else:
return n - (ai - bi)
def right_shift(n, ai, bi):
if ai == bi:
return n
elif ai > bi:
return ai - bi
else:
return n - (bi - ai)
def solve(n, a, b):
num_idx = {ai: i for i, ai in enumerate(a)}
zero_dist = 0
dist1 = dict()
dist2 = dict()
for i, bi in enumerate(b):
if bi in num_idx:
if num_idx[bi] == i:
zero_dist += 1
d1 = shift_left(n, num_idx[bi], i)
d2 = right_shift(n, num_idx[bi], i)
if d1 in dist1:
dist1[d1].append(bi)
else:
dist1[d1] = [bi]
if d2 in dist2:
dist2[d2].append(bi)
else:
dist2[d2] = [bi]
mx = 0
for k, lst in dist1.items():
mx = max(mx, len(lst))
for k, lst in dist2.items():
mx = max(mx, len(lst))
return max(mx, zero_dist)
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(n, a, b)) | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF IF VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR 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 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().split()))
b = list(map(int, input().split()))
temp = dict()
for i in range(n):
temp[b[i]] = i
temp2 = dict()
for i in range(n + 1):
temp2[i] = 0
for i in range(n):
j = temp[a[i]]
if j > i:
temp2[j - i] += 1
else:
temp2[n - i + j] += 1
ans = 0
for i in range(n + 1):
ans = max(ans, temp2[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 FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER 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 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$. | 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):
if a[i] not in d:
d[a[i]] = i
x = [0] * n
for i in range(n):
j = d[b[i]]
if j < i:
x[i] = n - i + j
else:
x[i] = j - i
z = [0] * (n + 1)
for i in range(n):
z[x[i]] += 1
print(max(z)) | 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 IF 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 VAR IF VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP 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()))
l = [0] * n
for i in range(n):
l[a[i] - 1] += i
l[b[i] - 1] -= i
d = dict()
ans = 0
for i in range(n):
if l[i] < 0:
l[i] += n
if l[i] not in d:
d[l[i]] = 0
d[l[i]] += 1
ans = max(ans, d[l[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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER 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()))
a1 = [0] * n
inda = a.index(1)
af = a[inda:] + a[:inda]
b = list(map(int, input().split()))
indb = b.index(1)
b1 = [0] * n
bf = b[indb:] + b[:indb]
for i in range(n):
a1[af[i] - 1] = i
for i in range(n):
b1[bf[i] - 1] = i
ans = 0
for i in range(n):
if af[i] == bf[i]:
ans += 1
l = [0] * n
for i in range(n):
l[i] = a1[i] - b1[i]
ans = [0] * n
for i in l:
ans[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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR 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 VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | first_pairs = []
second_pairs = []
lines = int(input())
words = {}
for i in range(lines):
w = input()
vow_cnt = 0
vow_last = ""
for c in w:
if c in ["a", "e", "i", "o", "u"]:
vow_cnt += 1
vow_last = c
if vow_cnt not in words:
words[vow_cnt] = {}
if vow_last not in words[vow_cnt]:
words[vow_cnt][vow_last] = w
else:
second_pairs.append((words[vow_cnt][vow_last], w))
del words[vow_cnt][vow_last]
for l in words:
first = None
second = None
for k in list(words[l].keys()):
if first is None:
first = k
continue
second = k
first_pairs.append((words[l][first], words[l][second]))
first = None
while len(first_pairs) < len(second_pairs):
first_pairs.append(second_pairs.pop())
print(len(second_pairs))
for f, s in zip(first_pairs, second_pairs):
print("{} {}".format(f[0], s[0]))
print("{} {}".format(f[1], s[1])) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR LIST STRING STRING STRING STRING STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR DICT IF VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NONE WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | n = int(input())
G = ["a", "e", "i", "o", "u"]
a = []
dic1 = dict()
for i in range(n):
s = input()
a.append(s)
last = "a"
counter = 0
for i in s:
if i in G:
last = i
counter += 1
dic1[last, counter] = dic1.get((last, counter), [])
dic1[last, counter].append(s)
end_words = []
start_word = []
dic2 = dict()
for i in dic1.keys():
while len(dic1[i]) > 1:
fir = dic1[i].pop()
sec = dic1[i].pop()
end_words.append([fir, sec])
if len(dic1[i]) > 0:
dic2[i[1]] = dic2.get(i[1], [])
dic2[i[1]].append(dic1[i].pop())
for i in dic2.keys():
while len(dic2[i]) > 1:
fir = dic2[i].pop()
sec = dic2[i].pop()
start_word.append([fir, sec])
ans = 0
ans = min(len(start_word), len(end_words))
if len(end_words) - len(start_word) > 1:
ans += (len(end_words) - len(start_word)) // 2
print(ans)
for i in range(min(len(start_word), len(end_words))):
end1 = end_words.pop()
start1 = start_word.pop()
print(start1[0], end1[0])
print(start1[1], end1[1])
if len(end_words) >= 2:
for i in range(len(end_words) // 2):
end1 = end_words.pop()
start1 = end_words.pop()
print(start1[0], end1[0])
print(start1[1], end1[1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | n = int(input())
dict_ = {}
vowel = "aeiou"
for i in range(n):
s = str(input())
cnt = 0
right = -1
for j in s:
if j in vowel:
cnt += 1
right = j
right = vowel.index(right)
try:
dict_[cnt].append((right, s))
except:
KeyError
dict_[cnt] = [(right, s)]
for i in dict_.keys():
dict_[i].sort()
first = []
second = []
for i in dict_.keys():
j = 0
prev = -1
while j < len(dict_[i]) - 1:
if dict_[i][j][0] == dict_[i][j + 1][0]:
second.append((dict_[i][j][1], dict_[i][j + 1][1]))
j += 2
elif prev != -1:
first.append((dict_[i][prev][1], dict_[i][j][1]))
j += 1
prev = -1
else:
prev = j
j += 1
if prev != -1 and j == len(dict_[i]) - 1:
first.append((dict_[i][prev][1], dict_[i][len(dict_[i]) - 1][1]))
i = 0
ans = []
while i < len(first) and i < len(second):
ans.append(first[i][0])
ans.append(second[i][0])
ans.append(first[i][1])
ans.append(second[i][1])
i += 1
while i < len(second) - 1:
ans.append(second[i][0])
ans.append(second[i + 1][0])
ans.append(second[i][1])
ans.append(second[i + 1][1])
i += 2
print(len(ans) // 4)
print(*ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR VAR ASSIGN VAR VAR LIST VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | n = int(input())
dic = {}
first_res = []
sec_res = []
for _ in range(n):
t = input()
key = t.count("e") + t.count("u") + t.count("o") + t.count("i") + t.count("a")
temp = max(t.rfind("e"), t.rfind("u"), t.rfind("o"), t.rfind("i"), t.rfind("a"))
if key not in dic.keys():
dic[key] = {}
dic[key][t[temp]] = [t]
elif t[temp] not in dic[key].keys():
dic[key][t[temp]] = [t]
else:
dic[key][t[temp]].append(t)
for key, key2 in dic.items():
temp = []
for vowel, words in key2.items():
while len(words) >= 2:
a = words.pop()
b = words.pop()
sec_res.append((a, b))
if len(words):
temp.append(words.pop())
while len(temp) >= 2:
a = temp.pop()
b = temp.pop()
first_res.append((a, b))
if len(sec_res) <= len(first_res):
print(len(sec_res))
for i in range(len(sec_res)):
print(first_res[i][0], sec_res[i][0])
print(first_res[i][1], sec_res[i][1])
else:
print(len(first_res) + (len(sec_res) - len(first_res)) // 2)
j = -1
for i in range(len(first_res)):
print(first_res[i][0], sec_res[i][0])
print(first_res[i][1], sec_res[i][1])
j = i
while j + 2 < len(sec_res):
print(sec_res[j + 1][0], sec_res[j + 2][0])
print(sec_res[j + 1][1], sec_res[j + 2][1])
j += 2 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR VAR LIST VAR IF VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | N = int(input())
words = [input() for _ in range(N)]
used = [(0) for _ in range(N)]
def last_vowel(s):
for i in range(len(s) - 1, -1, -1):
if s[i] in "aeiou":
return s[i]
raise RuntimeException("CF BAD")
def count_vowels(s):
count = 0
for c in s:
if c in "aeiou":
count += 1
return count
def key(s):
count = 0
last = ""
for c in s:
if c in "aeiou":
count += 1
last = c
return count, last
buckets = {}
finalbuckets = {}
for index, word in enumerate(words):
k = key(word)
if k not in buckets:
buckets[k] = []
if k[0] not in finalbuckets:
finalbuckets[k[0]] = []
buckets[k].append(index)
finalbuckets[k[0]].append(index)
fp = []
sp = []
for b in buckets:
if len(buckets[b]) < 2:
continue
for i in range(0, len(buckets[b]) - 1, 2):
sp.append((buckets[b][i], buckets[b][i + 1]))
used[buckets[b][i]] = 1
used[buckets[b][i + 1]] = 1
for b in finalbuckets:
pair = None
for word in finalbuckets[b]:
if used[word]:
continue
if pair is None:
pair = word
else:
fp.append((pair, word))
pair = None
move = max(0, (len(sp) - len(fp)) // 2)
z = list(zip(fp + sp[:move], sp[move:]))
print(len(z))
for (f0, f1), (s0, s1) in z:
print(words[f0], words[s0])
print(words[f1], words[s1]) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING RETURN VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR LIST IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NONE FOR VAR VAR VAR IF VAR VAR IF VAR NONE ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | import sys
class CBeautifulLyrics:
def solve(self):
n = int(input())
c = {}
for _ in range(n):
word = input().strip()
cnt = 0
last = -1
for x in word:
if x in "aoeui":
cnt += 1
last = x
if cnt in c:
c[cnt][last].append(word)
else:
c[cnt] = {key: [] for key in list("aeoiu") + [-1]}
c[cnt][last].append(word)
good = []
for last in "aeoui":
for cnt in c:
good.extend(
[
(c[cnt][last][i], c[cnt][last][i + 1])
for i in range(0, len(c[cnt][last]) - 1, 2)
]
)
semi_good = []
for cnt in c:
cur = []
for last in list("aeoui") + [-1]:
if len(c[cnt][last]) % 2 == 1:
cur.append(c[cnt][last][-1])
semi_good.extend([(cur[i], cur[i + 1]) for i in range(0, len(cur) - 1, 2)])
print(
min(len(semi_good), len(good))
+ (len(good) - min(len(semi_good), len(good))) // 2
)
gd_i = 0
nb_good = len(good)
nb_smgood = len(semi_good)
for smi_i, sm_pair in enumerate(semi_good):
if gd_i >= nb_good:
break
gd_pair = good[gd_i]
(a, c), (b, d) = sm_pair, gd_pair
print(a, b)
print(c, d)
gd_i += 1
while gd_i + 1 < nb_good:
(a, c), (b, d) = good[gd_i], good[gd_i + 1]
print(a, b)
print(c, d)
gd_i += 2
solver = CBeautifulLyrics()
input = sys.stdin.readline
solver.solve() | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR LIST VAR BIN_OP FUNC_CALL VAR STRING LIST NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR BIN_OP FUNC_CALL VAR STRING LIST NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | def p(a):
print()
for i in range(len(a)):
print(i, "-", a[i])
n = int(input())
slova = []
glas = []
for i in range(n):
s = input()
lastG = ""
k = 0
for ch in s:
if ch == "a" or ch == "e" or ch == "o" or ch == "i" or ch == "u":
k += 1
lastG = ch
if len(slova) < k:
for j in range(len(slova), k):
slova.append([])
glas.append([])
slova[k - 1].append(s)
glas[k - 1].append(lastG)
strofy1 = []
strofy2 = []
for k1 in range(len(glas)):
if len(glas[k1]) > 1:
for k2 in range(len(glas[k1]) - 1):
if glas[k1][k2] == "":
continue
k4 = k2
for k3 in range(k2 + 1, len(glas[k1])):
if glas[k1][k2] == glas[k1][k3]:
k4 = k3
break
if k4 > k2:
strofy2.append([slova[k1][k2], slova[k1][k4]])
glas[k1][k4] = ""
glas[k1][k2] = ""
slova[k1][k4] = ""
slova[k1][k2] = ""
sss = ""
while len(glas[k1]) > 0:
if slova[k1][0] != "":
if sss == "":
sss = slova[k1][0]
else:
strofy1.append([sss, slova[k1][0]])
sss = ""
del glas[k1][0]
del slova[k1][0]
minStrofy = min(len(strofy1), len(strofy2))
res = minStrofy + (len(strofy2) - minStrofy) // 2
print(res)
for i in range(minStrofy):
print(strofy1[i][0], strofy2[i][0])
print(strofy1[i][1], strofy2[i][1])
for i in range(minStrofy, len(strofy2) - 1, 2):
print(strofy2[i][0], strofy2[i + 1][0])
print(strofy2[i][1], strofy2[i + 1][1]) | FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER STRING IF VAR STRING ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER ASSIGN VAR STRING VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | voy = ["a", "e", "i", "o", "u"]
def de(a):
for i in a[::-1]:
if i in voy:
return i
di = {}
ta = set()
for k in range(int(input())):
a = input()
nb = sum(i in voy for i in a)
if not nb in ta:
for v in voy:
di[nb, v] = []
ta.add(nb)
d = de(a)
cl = nb, d
di[cl].append(a)
co1 = sum(len(di[k]) // 2 for k in di)
co2 = sum(sum(len(di[k, v]) for v in voy) // 2 for k in ta) // 2
wo = []
co = min(co1, co2)
nb = 0
for k in di:
nbl = 0
for i, j in zip(di[k][::2], di[k][1::2]):
if nb != co:
wo.append([i, j])
nb += 1
nbl += 1
di[k] = di[k][2 * nbl :]
di2 = [(di[k, "a"] + di[k, "e"] + di[k, "i"] + di[k, "o"] + di[k, "u"]) for k in ta]
p = 0
for k in di2:
for i, j in zip(k[::2], k[1::2]):
if p != len(wo):
wo[p].append(i)
wo[p].append(j)
p += 1
print(co)
for k in wo:
print(k[2], k[0])
print(k[3], k[1]) | ASSIGN VAR LIST STRING STRING STRING STRING STRING FUNC_DEF FOR VAR VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR STRING VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | vowels = ["a", "e", "i", "o", "u"]
class word:
def __init__(self, p):
o = [int(p[i] in vowels) for i in range(len(p))]
self.nov = sum(o)
o.reverse()
self.lastvow = p[len(p) - 1 - o.index(1)]
n = int(input())
ug = {}
max_keys = 0
com_duos = []
for i in range(n):
here = input()
wd = word(here)
imp = wd.nov
if imp > max_keys:
for i in range(max_keys + 1, imp + 1):
ug[i] = [[], [], [], [], []]
max_keys = imp
see = ug[imp][vowels.index(wd.lastvow)]
if see == []:
see.append(here)
else:
com_duos.append([see.pop(), here])
incom_duos = []
for key in ug:
vess = ""
for v in range(5):
if ug[key][v] != []:
if vess == "":
vess = ug[key][v][0]
else:
incom_duos += [[vess, ug[key][v][0]]]
vess = ""
x, y = len(com_duos), len(incom_duos)
m = min(x, (x + y) // 2)
print(m)
for i in range(m):
com = com_duos.pop()
if incom_duos != []:
incom = incom_duos.pop()
else:
incom = com_duos.pop()
print(incom[0], com[0])
print(incom[1], com[1]) | ASSIGN VAR LIST STRING STRING STRING STRING STRING CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST LIST LIST LIST LIST LIST ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR LIST IF VAR STRING ASSIGN VAR VAR VAR VAR NUMBER VAR LIST LIST VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
You are given $n$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.
Each lyric consists of two lines. Each line consists of two words separated by whitespace.
A lyric is beautiful if and only if it satisfies all conditions below. The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line. The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line. The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel.
Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.
For example of a beautiful lyric, "hello hellooowww"
"whatsup yowowowow" is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".
For example of a not beautiful lyric, "hey man"
"iam mcdic" is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).
How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.
-----Input-----
The first line contains single integer $n$ ($1 \le n \le 10^{5}$) — the number of words.
The $i$-th of the next $n$ lines contains string $s_{i}$ consisting lowercase alphabet letters — the $i$-th word. It is guaranteed that the sum of the total word length is equal or less than $10^{6}$. Each word contains at least one vowel.
-----Output-----
In the first line, print $m$ — the number of maximum possible beautiful lyrics.
In next $2m$ lines, print $m$ beautiful lyrics (two lines per lyric).
If there are multiple answers, print any.
-----Examples-----
Input
14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
Output
3
about proud
hooray round
wow first
this is
i that
mcdics am
Input
7
arsijo
suggested
the
idea
for
this
problem
Output
0
Input
4
same
same
same
differ
Output
1
same differ
same same
-----Note-----
In the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".
In the second example, you cannot form any beautiful lyric from given words.
In the third example, you can use the word "same" up to three times. | import sys
def key(s):
a = list(filter(lambda x: x in ("a", "e", "o", "i", "u"), s))
return len(a), a[-1]
n = int(input())
ss = map(lambda x: x.strip(), sys.stdin.readlines())
srt = sorted(ss, key=key)
pairs = []
tmp = []
i = 0
while i < n - 1:
k1 = key(srt[i])
k2 = key(srt[i + 1])
if k1 == k2:
pairs.append((srt[i], srt[i + 1]))
i += 2
else:
tmp.append(srt[i])
i += 1
while i < n:
tmp.append(srt[i])
i += 1
rest = []
i = 0
while i < len(tmp) - 1:
k1 = key(tmp[i])
k2 = key(tmp[i + 1])
if k1[0] == k2[0]:
rest.append((tmp[i], tmp[i + 1]))
i += 2
else:
i += 1
if len(pairs) <= len(rest):
result = list(zip(rest, pairs))
else:
off = (len(pairs) - len(rest)) // 2
result = list(zip(rest + pairs[len(pairs) - off :], pairs[: len(pairs) - off]))
print(len(result))
output = []
for l, r in result:
output.append("%s %s" % (l[0], r[0]))
output.append("%s %s" % (l[1], r[1]))
print("\n".join(output)) | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING STRING STRING STRING VAR RETURN FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.