Search is not available for this dataset
name stringlengths 2 112 | description stringlengths 29 13k | source int64 1 7 | difficulty int64 0 25 | solution stringlengths 7 983k | language stringclasses 4
values |
|---|---|---|---|---|---|
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 |
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import javafx.util.Pair;
public class Main
{
public static void main(String args[])
{
FastScanner input = new ... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | # key not available "" :
from collections import defaultdict
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
dp = [0]*n
Dict = defaultdict(int)
for i in range(n):
Dict[a[i]] = i
for i in range(n):
x = b[i]
ind = Dict[x]
dp[i] =... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | def help():
n = int(input())
arr1 = list(map(int,input().split(" ")))
arr2 = list(map(int,input().split(" ")))
indices = [[0,0] for i in range(n)]
dist = [0]*n
for i in range(n):
indices[arr1[i]-1][0] = i
indices[arr2[i]-1][1] = i
for i in range(n):
dist[i] = indices[i][0]-indices[i][1]
if(dist[i]<0):
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] d = new int[n];
int[] c = new int[n];
for ( int i=0; i<n; i++ ) {
int a = sc.nextInt()-1;
d[a] = i;
}
for ( int i=0; i<n; i++ ) {
int b = sc.nextInt... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import Counter
n = int(input())
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
pos = dict()
for i in range(n):
pos[arr[i]]=i
rotations = [0]*(n)
for i in range(n):
rotations[i] = (pos[brr[i]]-i+n)%n
#print(rotations)
print(Counter(rotations).most_common()[0][1])
| PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
mt19937 rng(229);
const int N = 2e5 + 7;
const int inf = INT_MAX / 2;
const long long INF = LLONG_MAX / 3;
const int MOD = 1e9 + 7;
const long double eps = 1e-6;
int a[N], b[N], c[N], n;
int dist(int x, int y) {
if (x < y) {
return y - x;
} else {
return y - x +... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
a_t = [0] * (n + 1)
for idx, val in enumerate(a):
if idx == 0:
continue
a_t[val] = idx
res = 0
d = {}
for idx, val in enumerate(b):
if idx == 0:
continue
t = a_t[val] - idx
if t < 0... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ad = {}; dd = {}; M = 0
for c, el in enumerate(a):
ad[el] = c
for c, el in enumerate(b):
target = ad[el]
if target >= c:
dist = target - c
else:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))
visited = {k : 0 for k in range(n)}
scores = [0 for k in range(n)]
maxscore = 0
position = 0
for i in range(n):
visited[alist[i]] = i
for i in range(n):
if i <= visited[blist[i]]:
position = visited[bli... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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[bi... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public final class CodeForces648C {
public static void main(String args[]){
FastReader sc=new FastReader();
PrintWrite... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
result = 0
position = [0 for _ in range(N)]
for i, a in enumerate(A):
position[a - 1] = i
shift = [0 for _ in range(N)]
for i in range(N):
shift[position[B[i] - 1] - i] += 1
print(max(shift))
# for t_itr in range(T):
#... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, b = 0, c = 0, i, j, k, p;
scanf("%lld", &n);
long long a[n + 1];
memset(a, 0, sizeof(a));
map<long long, long long> is, hr;
map<long long, long long>::iterator t, it;
for (i = 1; i < n + 1; i++) {
scanf("%lld", &k);
is[k] = i;... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | """609C"""
# import math
# import sys
def main():
# n ,m= map(int,input().split())
# a = list(map(int,input().split()))
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dp = [0 for _ in range(n+1)]
for i in range(n):
dp[a[i]] = i
offset = [0 for _ in range(n)]
for i in r... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | # https://codeforces.com/contest/1365/problem/C
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
# do magic here
n = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
posA = {A[x]:x+1 for x in range(n)}
posB = {B[x]:x+1 for x in range(n)}
# print(posA)
#... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class C{
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[n];
int max = 1;
HashMap<Integer, Integer> pos = new HashMap<>();
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import math as mt
def m(arr, n):
# Insert all elements in Hash.
Hash = dict()
for i in range(n):
if arr[i] in Hash.keys():
Hash[arr[i]] += 1
else:
Hash[arr[i]] = 1
# find the max frequency
max_count = 0
res = -1
for i in Hash:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
from collections import Counter
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number)... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import defaultdict, Counter
from math import log, ceil
import sys
#sys.stdin = open("third.txt", "r")
raw_input = sys.stdin.readline
def rotateL(arr, d, n):
tmp = [0 for n_itr in xrange(n)]
for n_itr in xrange(n):
tmp[(n_itr + d) % n] = arr[n_itr]
return tmp
def rotateR(arr, d, n):
tmp = [0... | PYTHON |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> second(n);
map<int, int> mymap;
vector<int> temp;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
mymap[x] = i;
}
for (int i = 0; i < n; i++) {
cin >> second[i];
int idx = mymap[second[i]];
if... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #https://codeforces.com/problemset/problem/1365/C
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=a... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from sys import stdin
#t = int(stdin.readline())
t=1
fir = [0] * (2*10**5 +5)
sec = [0] * (2*10**5 + 5)
ans = [0] * (2 * 10**5 + 5)
for _ in xrange(t):
#a,b= map(int,stdin.readline().split())
n = int(stdin.readline())
a = map(int,stdin.readline().split())
b = map(int,stdin.readline().split())
for i ... | PYTHON |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from sys import stdin
input = stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
pos_mapping = {}
for idx, val in enumerate(brr):
pos_mapping[val] = idx
ans = {}
mx = 0
for idx,val in enumerate(arr):
j = pos_mapping[val]
if j <= idx:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d={}
p={}
for i in range(n):
d[a[i]]=i
for i in range(n):
x=(d[b[i]]-i+n)%n
if x not in p:
p[x]=1
else:
p[x]+=1
print(max(list(p.values()))) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
double pai = 3.14159265359;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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
ans = [0]*(n+1)
for j in range(n):
temp = d[b[j]]-j
if temp < 0:
temp = n+temp
ans[temp] +=1
print(max(ans))
| PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;
public class C1365 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int[] nums = new int[length + 1];
HashMap<Integer, Integer> differences = new HashMap<Integer... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
rotations = [0] * n
answers = [0] * n
for i in range(len(a)):
rotations[a[i] - 1] += i
rotations[b[i] - 1] -= i
for i in range(len(a)):
rotations[i] = (rotations[i] + n) % n
answers[rotations[i] - 1] += 1
pr... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import collections
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
d=dict.fromkeys(list(range(1,n+1)),0)
ind=[-1]*(n+1)
for i in range(n):
ind[b[i]]=i
#lets shift right
#n-()
for i in range(n):
r=ind[a[i]]
if r>i:
d[a[i]]=r-i
elif r<i:
d[a[i]]=n-(... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class Main{
static class InputReader {
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
d = {}
for i in range(n):
d[a[i]] = i
ans = [0]*n
for i in range(n):
j = d[b[i]]
ans[(j-i)%n] += 1
print(max(ans)) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
aa={}
bb={}
for i in range(n):
aa[a[i]]=i
bb[b[i]]=i
ans=1
dic={}
# par=1
for i in range(n):
ind=bb[a[i]]
temp=0
if (ind<i):
temp=n+ind-i
else:
temp=ind-i
if (temp in dic):
dic[temp]+=1
else:
dic[temp]=1
ans=max(ans, dic... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 |
# Author : raj1307 - Raj Singh
# Date : 07.06.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())... | PYTHON |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.*;
import java.util.*;
public class C { //
static long[] a, b;
static int[] cnt;
static int mask = 0xfffff;
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new B... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import os
import sys
import time
import math as mt
import pprint
import itertools as it
import operator as op
import bisect as bs
import functools as fn
from collections import deque, defaultdict , OrderedDict, Counter, ChainMap
maxx, localsys, mod = 1 << 60, 0, int(1e9 + 7)
def nCr(n, r): return reduce(mul, range(n - ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import javafx.util.Pair;
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Contest {
public static class pair implements Comparable<pair> {
long l;
long r;
public pair(long lef, long ri) {
l = lef;
r = ri;
}
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
int a[n + 1], b[n + 1];
for (long long int i = 1; i <= n; i += 1) cin >> a[i];
for (long long int i = 1; i <= n; i += 1) cin >> b[i];
map<int, int> mp;
for (long long int i = 1; i <= n; i += 1) mp[b[i]] = i;
int mx = 0... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class aaaaaaaaaaaaaaaa {
public void run() throws Exception {
FastReader file = new FastReader();
int times = file.nextInt();
ArrayList<Integer> a = new ArrayList(), b = new ArrayList();
int[] c = new int[times + 1];
for (int i = 0; i < times; i++) a.add(file.nex... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {
private static void solver(InputReader sc, PrintWriter out) throws Exception {
int test = 1;
for(int ii=0; ii<test; ii++){
int n = sc.nextInt();
int a... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long n, x;
cin >> n;
vector<int> m(n + 1, 0), v1(n + 1, 0);
for (int i = 0; i < n; ++i) {
cin >> x;
v1[x - 1] = i;
}
for (int i = 0; i < n; ++i) {
cin >> x;
m[((v1[x - 1] - i) + n) % n]++;
}
cout ... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 |
import java.io.*;
import java.util.*;
public class Main {
private static final boolean N_CASE = false;
private void solve() {
int n = sc.nextInt();
int[] a = sc.nextArray(n);
int[] b = sc.nextArray(n);
int[] pa = new int[n + 1];
int[] pb = new int[n + 1];
for... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
public class C {
static HashMap<Long, Long> combos = new HashMap<>();
public static v... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
lst1 = [int(i) for i in input().split()]
lst2 = [int(i) for i in input().split()]
res = [0]*(n+1)
d = {}
for i in range(n):
d[lst1[i]]=i
for i in range(n):
k=(d[lst2[i]]-i)
if k>0:
res[k]+=1
else:
res[n+k]+=1
print(max(res)) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class TestTask {
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc = new FastReader();
PrintWriter out = new ... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
input = sys.stdin.readline
def intInput():
return(int(input()))
def intListInput():
return(list(map(int,input().split())))
def strInput():
return input()
def brute(n, a, b):
result = 0
for k in range(n):
curr = 0
for i in range(n):
if a[i] == b[(i + k) % n]:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import Counter
def solve(list1, list2,n):
inverse_index = { element: index for index, element in enumerate(list1) }
return [inverse_index[element]-index if inverse_index[element]-index>=0 else n+inverse_index[element]-index
for index, element in enumerate(list2) if element in inverse_in... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class C1365 {
public static int getDiff(int i, int j, int n) {
int ans = i - j;
if(ans <= 0)
ans += n;
return ans;
}
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.ou... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
n=int(input())
q=list(map(int,input().split()))
w=list(map(int,input().split()))
e=[0]*(n+1)
for i in range(n):
e[q[i]]=i
t=[0]*n
for i in range(n):
t[(i-e[w[i]])%n]+=1
print(max(t)) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0 for i in range(n+1)]
count=[0 for i in range(n)]
maxx=0
for i in range(n):
c[a[i]]=i
for i in range(n):
pos=c[b[i]]
if i>=pos:
k=i-pos
else:
k=n+i-pos
count[k]+=1
maxx=max(maxx,count[k])
print(m... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238463;
long long int modfun(long long int a, long long int b) {
long long int result = 1;
while (b > 0) {
if (b & 1) {
a = a % 1000000007;
result = (result * a) % 1000000007;
result = result % 1000000007;
}
... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
import string
input = sys.stdin.readline
import math
#import stdout
#import numpy
#letters = list(string.ascii_lowercase)
#from decimal import Decimal
from operator import xor
#d = pow(a, b, p)
p = 10**9 + 7
n = int(input())
a_ind = {}
b_ind = {}
counter = [0 for i in range(2*n)]
a = list(map(int,input().... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
# from collections import Counter
# sys.setrecursionlimit(200010)
def input():
return sys.stdin.readline()[:-1]
def main():
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
A = [(a[k],k) for k in range(n)]
B = [(b[k],k) for k in range(n)]
A = ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #from __future__ import print_function
mod=int(1e9+7)
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.stack_size(2**25)
#import sys
#sys.setrecursionlimit(10**5)
#fact=[1]
#for i in range(1,100001):
# fact.append((fact[-1]*i)%mod)
#ifact... | PYTHON |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
A=list(map(int,input("").split()))
B=list(map(int,input("").split()))
#print(A)
#print(B)
ans=0
indexA=dict()
indexB=dict()
for i in range(n):
indexB[B[i]]=i
count=dict()
for i in range(n):
x=indexB[A[i]]-i
if x<0:
x+=n
count[x]=count.get(x,0)+1
print(max(count.values()))
| PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.Scanner;
public class _C_ {
public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
final int n = in.nextInt();
final int[] arr1 = new int[n + 1], arr2 = new int[n + 1], offset = new int[n];
for (int i = 1; i <= n; i++)
arr1[in.nextInt()] = i;
for (int i = 1;... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
def main():
n=int(stdin.readline())
a=[int(x)-1 for x in stdin.readline().split()]
b=[int(x)-1 for x in stdin.readline().split()]
posa=[0]*n
posb=[0]*n
for i in range(n):
posa[a[i]]=i... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | z,zz=input,lambda:list(map(int,z().split()))
n,a,b=int(z()),zz(),zz();h=[0]*n;l=[0]*n
for i in range(n):l[a[i]-1]+=i;l[b[i]-1]-= i
for i in range(n):h[l[i]%n]+=1
print(max(h)) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = ... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
posA = {}
for i in range(n):
posA[a[i]] = i
ans = {}
for i in range(n):
moves = (posA[b[i]] - i) if posA[b[i]] >= i else (n - i + posA[b[i]])
if moves in ans:
ans[moves] += 1
else:
ans[moves] = 1
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from sys import stdin
def readline():
return stdin.readline()
#tests = int(readline())
def solve(n, a, b):
shifts = []
pos = [0] * n
for i in range(0, n):
pos[b[i]] = i
for i in range(0, n):
shift = i - pos[a[i]]
if shift < 0:
shift += n
shifts.append(... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.awt.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
public class Abc {
public static void main(String[] args) throws Exception {
InputReader sc=new InputReader(System.in);
int n=sc.nextInt();
int a[]=new int[n+1];
int... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import defaultdict
n = int(input())
a = [x for x in map(int, input().split(' '))]
b = [x for x in map(int, input().split(' '))]
a_pos = dict()
diff = defaultdict(lambda: 0)
for i, v in enumerate(a):
a_pos[v] = i
for i, v in enumerate(b):
p = a_pos[v]
dist = p - i
if dist < 0:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 |
import java.io.*;
import java.math.*;
import java.util.*;
// @author : Dinosparton
public class test {
static class Pair{
int x;
int y;
Pair(int x,int y){
this.x = x;
this.y = y;
}
}
static class Compare {
void compare(Pair arr[], int... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import queue
import math
n = int(input())
a = input().split()
a = [int(x) for x in a]
b = input().split()
b = [int(x) for x in b]
pos = [0 for i in range(n+1)]
for i in range(n):
pos[b[i]] = i
cnt = {}
for i in range(n):
k = pos[a[i]]-i
if (k < 0):
k += n
if (k not in cnt):
cnt[k] = 0
cnt[k] += 1
ans ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
// int t = scn.nextInt();
// for(int p=0;p<t;p++){
int n = scn.nextInt();
int a[] = new int[n];
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ia = [0]*n
ib = [0]*n
for i in range(n):
ia[a[i]-1] = i
ib[b[i]-1] = i
ans = dict()
for i in range(n):
switch = (ia[i]-ib[i])%n
res = 0
ans[switch] = ans.get(switch, 0) + 1
print(max(ans.values()))
| PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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,in... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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)... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [0]*n
for i in range(n):
arr[a[i]-1]+=i
arr[b[i]-1]-=i
for i in range(n):
arr.append(arr[i]-n)
freq = {}
for i in arr:
freq[i] = freq.get(i,0)+1
max = 0
for i in freq:
if freq[i]>max:
max = freq[i... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | # -*- coding: utf-8 -*-
"""
Created on Wed Jun 10 12:17:51 2020
@author: wpj
"""
number = int(input())
col_a = list(map(int, input().split()))
col_b = list(map(int, input().split()))
mark = [0 for i in range(number)]
dic_b = [0 for i in range(number)]
for i in range(number):
dic_b[col_b[i]-1] = i
match = [0 ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n = int(input())
l = [int(j) for j in input().split()]
m = [int(j) for j in input().split()]
# d = [(i,0) for i in range(1,n+1)]
d = dict()
for i in range(n):
d[m[i]]=i
ans = dict()
for i in range(n):
tmp = (i-d[l[i]])
if tmp<0:
tmp = n+tmp
if tmp in ans:
ans[tmp]+=1
else:
ans[tmp]=1
# print(tmp, l[i], d)... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int a, b, c, d, i, j, k;
vector<long long int> v, ve;
cin >> a;
long long int vp[a + 1][2];
for (i = 0; i < a; i++) {
cin >> c;
v.push_back(c);
vp[c][0] = i + 1;
}
for (i = 0; i < a; i... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | t = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
g = {}
g2 = {}
for x in range(t):
if g.get(a[x], None) != None:
g2[x - g[a[x]]] = g2.get(x - g[a[x]], 0) + 1
else:
g[a[x]] = x
if g.get(b[x], None) != None:... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import defaultdict
n =int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pos = [0]*n
for i in range(n):
pos[a[i]-1] = i
store = defaultdict(int)
for i in range(n):
cur = pos[b[i]-1] - i
if cur < 0: cur += n
store[cur] += 1
mx = 0
for k in store:
if ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
dct={}
for i in range(n):
dct[a[i]]=i
lst=[]
for j in range(n):
if(b[j] in dct.keys()):
if(dct[b[j]]<j):
x=n-j+dct[b[j]]
else:
x=dct[b[j]]-j
lst.appen... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import math
from collections import Counter,defaultdict,deque
from sys import stdin, stdout
input = stdin.readline
I =lambda:int(input())
M =lambda:map(int,input().split())
LI=lambda:list(map(int,input().split()))
n=I()
a=LI()
b=LI()
c=[]
d={};e={}
for i in range(n):
d[a[i]]=i+1
for i in range(n):
e[b[i]]=i+1
f... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
import collections as cc
import bisect as bi
I=lambda:list(map(int,input().split()))
for tc in range(1):
n,=I()
a=I()
b=I()
if a==b:
print(n)
break
x=cc.defaultdict(int)
y=cc.defaultdict(int)
for i in range(n):
x[a[i]]=i
y[b[i]]=i
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(1,n+1):
tem=y[i]-x... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | # for fast pow :- use math.pow(x,y) O(1) return value in float
#input=sys.stdin.readline
from collections import defaultdict as dft
import sys
import math
def ml():return list(map(int,input().split()))
def mp(): return map(int,input().split())
def debug(name,val):print(name,':',val)
def solve():
n=int(input())
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import math
from collections import Counter
def i() : return int(input())
def lii(): return list(map(int,input().split()))
def lis(): return list(input())
n = i()
a,b = lii(),lii()
c= []
d_a = {}
d_b = {}
for i in range(n):
d_a[a[i]],d_b[b[i]] = i,i
for i in range(n):
c.append((d_b[a[i]]-d_a[a[i]]+n)%n)
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | def main():
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
off = {}
pos = [0 for _ in range(n)]
for i in range(n):
pos[a[i]-1] = i
for i in range(n):
cur = pos[b[i]-1] - i
if cur < 0 :
cur += n
if cur in off:... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | a = [0 for y in range(200001)]
b = [0 for y in range(200001)]
n = int(input())
m=-1
temp = input().split()
for i in range(0, n):
a[int(temp[i])] = i
temp = input().split()
for i in range(0, n):
l = (n + a[int(temp[i])] - i) % n
b[l] += 1
m = max(m, b[l])
print(m) | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class C {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(in.readLine());
int[] A = new int[n];
int[] B = new int[n];
StringTokenizer token = new String... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import sys
input = lambda:sys.stdin.readline().strip()
n = int(input())
a = list(map(int,input().split()))
am = [0]*n
for i in range(n):
am[a[i]-1] = i
b = list(map(int,input().split()))
bm = [0]*n
for i in range(n):
bm[b[i]-1] = i
ans = 0
cm = [0]*n
for i in range(n):
if bm[i]>am[i]:
cm[n-bm[i]+am... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.*;
import java.io.*;
public class c
{
static boolean multiple_testcases = false;
static void solve() {
int n = in.nextInt();
int[] arr = new int[n];
int[] a = new int[n];
int[] b = new int[n];
HashMap<Integer,Integer> map = new HashMap<>();
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, x;
cin >> n;
vector<long long> f(n), p(n + 1, 0);
for (long long i = 0; i < n; i++) cin >> x, p[x] = i;
for (long long i = 0; i < n; i++) {
cin >> x;
f[(p[x] - i + n) % n]++;
... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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
#print(d1)
ma=0
for i in d1:
if ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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:
... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 |
#------------------------------warmup----------------------------
# *******************************
# * AUTHOR: RAJDEEP GHOSH *
# * NICK : Rajdeep2k *
# * INSTITUTION: IIEST, SHIBPUR *
# *******************************
import os
import sys
from io import BytesIO, IOBase
import math
from fraction... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int NMAX = 200005;
int N, a[NMAX], b[NMAX];
int posa[NMAX], posb[NMAX];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N;
for (int i = 1; i <= N; ++i) {
cin >> a[i];
posa[a[i]] = i;
}
for (int i = 1; i <= N; ++i) {
cin ... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.util.Scanner;
public class D5PC {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] ish = new int[n];
int[] hri = new int[n];
for (int i=0; i<n; ++i) {
int x = s.nextInt();
... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Task3 {
public static void main(String[] args) throws IOException {
new Task3().solve();
}
public void solve() throws IOException ... | JAVA |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | from sys import stdin,stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I=lambda: map(int,stdin.readline().split())
I1=lambda: stdin.readline()
#(a/b)%m =((a%m)*pow(b,m-2)%m)%m
# for odered set :)
def unique(sequence):
seen = set()
return [x for x in sequence ... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const long long int N = 3 * 1e6 + 2;
long long int n, k;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<long long int> a(n), b(n), pos1(n + 1), pos2(n + 1);
long long int res = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
inline int add(int a, int b) {
a += b;
return a >= 1000000007 ? a - 1... | CPP |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | __multitest = False
## =====================
def solve():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
##
da = {}
db = {}
for i in range(n):
da[a[i]] = i
db[b[i]] = i
##
dv = {}
for x in range(n):
dv[x + 1] = (da... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ind=[0 for i in range(n)]
for i in range(n):
ind[a[i]-1]+=i
for i in range(n):
ind[b[i]-1]-=i
for i in range(n):
if ind[i]<0:
ind[i]+=n
from collections import Counter
c=Counter(ind)
ans=1
for i in c:
ans=max(ans,c[... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | 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... | PYTHON3 |
1365_C. Rotation Matching | 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, β¦, a_n, in ... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<int> v(n);
vector<int> v2(n);
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i++) cin >> v2[i];
unordered_map<int, vector<int>> mp;
unordered_map<int, int> freq;
for (int i = 0; i < n; i++) {
... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.