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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
public class hello2{
public static class InputReader {
private InputSt... | 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
def ai(): return list(map(int, stdin.readline().split()))
def ei(): return map(int, stdin.readline().split())
def ip(): return int(stdin.readline().strip())
def op(ans): return stdout.write(str(ans) + '\n')
n = ip()
a = ai()
b = ai()
a_ = [-1]*n
b_ = [-1]*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 sys import stdin as f
n = int(f.readline().strip())
A = [int(i) for i in f.readline().strip().split()]
B = [int(i) for i in f.readline().strip().split()]
a_map = [0 for i in range(n+1)]
b_map = [0 for i in range(n+1)]
for i in range(n):
a_map[A[i]] = i
b_map[B[i]] = i
#print(a_map[1:])
#print(b_map[1:])
s... | 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 | #!/usr/bin/python3
import sys
input = sys.stdin.buffer.readline
n = int(input())
arr1 = [int(x) for x in input().split()]
arr2 = [int(x) for x in input().split()]
out = [0]*n
dif = [0]*n
for i in range(n):
dif[arr1[i]-1] += i
for i in range(n):
dif[arr2[i]-1] -= i
for v in dif:
out[v] += 1
print(max(out)... | 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 N = 1e6 + 100;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
while (tc--) {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
x--;
a[x] = i;
}
for (int 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 | n = int(input())
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
da = dict()
db = dict()
i = 0
for el in a:
da[el] = i
i += 1
i = 0
for el in b:
db[el] = i
i += 1
delta = dict()
for i in range(1, n + 1):
if db[i] - da[i] not in delta:
delta[db[i] - da[i]] = 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, stdout, setrecursionlimit
#import threading
# tail-recursion optimization
# In case of tail-recusion optimized code, have to use python compiler.
# Otherwise, memory limit may exceed.
# declare the class Tail_Recursion_Optimization
class Tail_Recursion_Optimization:
def __init__(self, RECURS... | 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 MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n+1];
int b[] = new int[n+1];
int pos1[] = new int[n+1];
int diff[] = new int[n+1];
for(int i=0;i<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 | import java.util.*;
public class Solution{
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n+1];
int b[]=new int[n+1];
int posa[]=new int[n+1];
int posb[]=new int[n+1];
int c[]=new int[n+1];
for(int i=1;i<=n;i++){
... | 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 | """
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
import sys
input = sys.stdin.buffer.readline
from collections import Counter
def solution():
# This is the main code
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[0]*(n+1)
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 | from sys import stdin
import copy
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
d = dict()
dd = dict()
for x in range(n):
dd[a[x]] = x
for x in range(n):
t = x - dd[b[x]]
if t < 0:
t += n
if t in d.keys():
d[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 | //package CodeForces.RoadMap.Diff1400;
import java.util.*;
/**
* @author Syed Ali.
* @createdAt 11/05/2021, Tuesday, 23:35
*/
public class RotationMatching {
private static Scanner fs = new Scanner(System.in);
public static void main(String[] args) {
int n = fs.nextInt();
int[] a = new int[n+1];
int[] r... | 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.util.*;
public class HelloWorld{
public static void main(String []args){
Scanner s=new Scanner(System.in);
int n=s.nextInt();
HashMap<Integer,Integer> map=new HashMap<>();
HashMap<Integer,Integer> c=new HashMap<>();
for(int i=0;i<n;i++)
{
map.put(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 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=dict()
dd=dict()
for i in range(n):
d[a[i]]=i
dd[b[i]]=i
l=[]
from collections import defaultdict
l=defaultdict(int)
maxc=0
for i in range(1,n+1):
l[(n+d[i]-dd[i])%n]+=1
maxc=max(maxc,l[(n+d[i]-dd[i])%n])
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 | 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 _ ... | 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(x) for x in input().split()]
b=[int(x) for x in input().split()]
right={}
aindex={}
bindex={}
for i in range(n):
aindex[a[i]]=i
for i in range(n):
bindex[b[i]]=i
for i in range(1,n+1):
if bindex[i]>aindex[i]:
right[i]=bindex[i]-aindex[i]
else:
right[i]=(n-aindex[i])... | 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 mN = 200200;
int a[mN], b[mN], p1[mN], p2[mN];
int cnt[mN];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], p1[a[i]] = i;
for (int i = 1; i <= n; i++) cin >> b[i], p2[b[i]] = i;
f... | 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 | from statistics import mode
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[0]*n
l1=[0]*n
l2=[0]*n
for i in range(n):
l1[a[i]-1]=i
l2[b[i]-1]=i
for i in range(n):
l[(l1[i]-l2[i])%n]+=1
print(max(l))
| 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())
ar=list(map(int,input().split()))
br=list(map(int,input().split()))
li=[0]*(n+1)
for i in range(n):
li[ar[i]]=(i)
ans=[0]*(n+1)
for i in range(n):
ind=li[br[i]]
if(ind>i):
ans[br[i]]=(ind-i)
elif(ind<i):
ans[br[i]]=n-i+ind
else:
ans[br[i]]=0
dic={}
for i in ran... | 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())
arr = [0 for i in range(n)]
brr = [0 for i in range(n)]
temp = list(map(int,input().split()))
for i in range(n):
arr[temp[i]-1] = i
temp = list(map(int,input().split()))
for i in range(n):
brr[temp[i]-1] = i
d = defaultdict(int)
for i in range(n):
if brr[i]<=arr[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 | 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))
| 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 Q3 {
static int m = 1000000007;
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] a = new int[n+1];
int[] b = new int[n+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 | import java.util.*;
public class Rotation
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int max1 = 0,max2=0;
int[] B = new int[N];
HashMap<Integer,Integer> A = new HashMap<Integer,Integer>();
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 | 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) | 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()]
ia=[-1 for i in range(n)]
ib=[-1 for i in range(n)]
for i in range(n):
ia[a[i]]=i
ib[b[i]]=i
d=[0 for i in range(n)]
for i in range(n):
d[i]=ia[i]-ib[i] if ia[i]>ib[i] else ia[i]-ib[i]+n
f={i:0 for i in set(d)}
for i in d:
... | 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()))
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]
... | 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.*;
import java.text.*;
public class C1265 {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int[] a = sc.nextIntArr(n);
int[] b = sc.nextIntArr(n);
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 | n=int(input())
o=[-1 for i in range(n+1)]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d={}
for i in range(n):
o[a[i]]=i
for i in range(n):
x=o[b[i]]
if x-i>=0:
if x-i in d:
d[x-i]+=1
else:
d[x-i]=1
else:
if n+x-i in d:
d[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 | #: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"
input = sys.stdin.readline
######... | 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()))
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... | 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]*n
d=[0]*n
for i in range(n):
c[a[i]-1]=i
for i in range(n):
d[b[i]-1]=i
left=[]
right=[]
for i in range(n):
left.append((c[i]-d[i])%n)
right.append((d[i]-c[i])%n)
c={}
d={}
for i in range(n):
if left[i] not in c.k... | 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 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 | 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)
#print(pa,pb)
d=[]
for i in range(0,n):
d.append((pa[i]-pb[i])%n)
#print(d)
f=[0]*n
for i in d:
f[i]+=1
print(max(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 math
# t = int(input())
t = 1
for _ in range(t):
n = int(input())
a = [int(var) for var in input().split()]
b = [int(var) for var in input().split()]
bMap, deltaMap, maxMatch = {}, {}, 0
for i in range(n):
bMap[b[i]] = i
# print(bMap)
for i in range(n):
delta = bMa... | 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
am = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
am = len(a)
swap = [0]*am
swapSec = [0]*am
for i in range(am):
swap[a[i]-1] = i
swapSec[a[i]-1] = i
for i in range(am):
swap[b[i]-1]-=i
if swap[b[i]-1] < 0:
swap[b[i]-1] = abs(... | 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 | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
P... | 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()]
order_a = sorted(range(len(a)), key=lambda k: a[k])
order_b = sorted(range(len(b)), key=lambda k: b[k])
left = [0]*n
rigth = [0]*n
for i in range(n):
aux = order_a[i] - order_b[i]
if aux == 0:
left[0] += 1... | 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_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
map<int, int> m;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]] = i;
}
long long int b[n];
map<int, int> freq;
for (int i = 0; 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 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long binpow(long long a, long long b) {
a %= mod;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % mod;
res = res * res % mod;
b >>= 1;
}
return res;
}
int gcd(int a, int b) {
while (b) {
a %= b;
swa... | 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 | from math import *
from sys import stdin,stdout
input=stdin.buffer.readline
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
posa=[]
posb=[]
ans=[]
for i in range(n):
posa.append(-1)
posb.append(-1)
ans.append(0)
for i in range(n):
posa[a[i]-1]=i
posb[b[i]-1]=i
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 | /*Radhe Krishna*/
import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Prin... | 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 | 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] ... | 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
input=sys.stdin.buffer.readline
n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
if arr1==arr2:
print(n)
else:
da=dict()
db=dict()
for i in range(n):
da.update({arr1[i]:i})
db.update({arr2[i]:i})
ans=[]
#print(da)
#print(db)
for i in range(1,n+1):
ans.appe... | 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()))
dicA={i:e for e,i in enumerate(a)}
dicB={i:e for e,i in enumerate(b)}
rdata=[0]*N
for i in range(1,N+1):
A=dicA[i]
B=dicB[i]
if B>A:
rdata[B-A]+=1
else:
rdata[(N-(A-B))%N]+=1
ans=max(rdata)
print(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 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dica = dict()
dicb = dict()
ks = dict()
for i in range(n):
dica[a[i]] = i
dicb[b[i]] = i
#print(dica,dicb)
for i in dica.keys():
t = dicb[i] - dica[i]
if t>0:
if t not in ks... | 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 -*-
import sys
from collections import defaultdict, deque
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]
def solve():
n = int(input())
a = [int(x) for x in input().split()]
p = {}
for i in range(n):
p[... | 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 = [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
... | 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 operator import eq
n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
dic = {}
for i in range(n):
dic[arr2[i]] = i
for i in range(n):
dic[arr1[i]] -= i
if (dic[arr1[i]]<0):
dic[arr1[i]]+=n
ans = [0]*n
for i in dic:
ans[dic[i]]+=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 | from collections import Counter
import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)
def main():
n = next(ints)
A = [0]*n
for i in range(n): A[next(ints)-1]=i
b = [next(ints) for i in range(n)]
ans = max(Counter((i-A[b[i]-1])%n for i in range(n)).values())
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 math
#import math
#------------------------------warmup----------------------------
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.writab... | 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
# Initialize dictionary
e = defaultdict(int)
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c={}
d={}
for i in range(n):
c[a[i]]=i
d[b[i]]=i
for i in range(n):
s=d[a[i]]
if s>i:
e[i+n-s]+=1
else:
e[i-s]+=1
re... | 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
def solve(n,a,b):
ind_a = [0] * (n)
ind_b = [0] * (n)
diff = [0] * (n)
for i in range(0,n):
a[i] -= 1
b[i] -= 1
ind_a[a[i]] = i
ind_b[b[i]] = i
for i in range(n):
x = ind_a[i] - ind_b[i]
if x < 0: x += n
diff[x] += 1
prin... | 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
from sys import stdin
input = stdin.readline
if __name__ == '__main__':
n = int(input())
arr = list(map(int, input().split()))
brr = list(map(int, input().split()))
narr = [-1 for _ in range(n + 1)]
parr = []
for i, x in enumerate(arr):
narr[x] = 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 | n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
h = [0 for a in range(0, n + 1)]
for i in range(0, n) :
h[a[i]] = i
r = []
# print(h)
for i in range(0, n):
i2 = h[b[i]]
if i2 > i:
if ( i2-i) < (n-(i2-i)):
res = "r" + str(i2-i)
else:
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 | from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
l1,l2 = {},{}
for i in range(n):
l1[a[i]] = i
l2[b[i]] = i
v = []
for i in range(1,n+1):
if l2[i]-l1[i]<0:
v.append(l2[i]-l1[i]+n)
continue
v.append(l2[i]-l1[i])
c = Counter(v)
m = 0
for i in 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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class First {
public static void main(String[] args) ... | 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, = 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()))
| 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() {
int n;
cin >> n;
map<int, int> mp;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
mp[a[i]] = i;
}
map<int, int> gap, pag;
set<int> st;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
int dif, diff;
if (mp[x] > 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 | from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda: input()
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
I = lambda:list(map(int,input().split()))
chrIdx = lambda x: ord(x)-96
idxChr = la... | 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 | /*-----------------------------*/
/* Vora Mahammadasim */
/*-----------------------------*/
import java.util.*;
import java.lang.*;
import java.math.*;
public class Solution{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
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 java.io.*;
import java.util.*;
/**
* Created by gouthamvidyapradhan on 29/07/2020
*/
public class RotationMatching {
private static PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 500000));
static class MyScanner {
/**
* Buffered reader
*/
privat... | 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 | #t=int(input())
t=1
for ab in range(t):
n=int(input())
ind=[0]*(n+1)
index=[0]*(n+1)
m=list(map(int,input().split()))
x=list(map(int,input().split()))
for ab in range(n):
ind[m[ab]]=ab+1
index[x[ab]]=ab+1
tl=[0 for ac in range(1,n+1... | 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.util.HashMap;
import java.util.StringTokenizer;
public class C {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader file = new BufferedReader(new InputStreamReader... | 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.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
// HashMap<> map=new HashMap<>();
// TreeMap<> map=new TreeMap<>();
// map.put(p,map.getOrDefault(p,0)+1);
// for(Map.Entry<> mx:map.entrySet()){
// int v=mx.getValue(),k=mx.getKey();
// }
// ArrayList<Pai... | 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;
template <class t1, class t2>
using pi = pair<t1, t2>;
template <class t>
using vi = vector<t>;
template <class t>
using vvi = vi<vi<t>>;
template <class t1, class t2>
using um = unordered_map<t1, t2>;
template <class t1, class t2>
using om = map<t1, t2>;
void hinataVSsakur... | 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.*;
import java.math.*;
public class Main {
static long sx = 0, sy = 0, mod = (long) (998244353);
static ArrayList<Integer>[] a;
// static ArrayList<Long> p;
// static HashMap<Integer, Integer> hm = new HashMap<>();
static Integer[][][] dp;
static long[] far;
static int[] f... | 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 | def solve():
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
da,db={},{}
for i in range(n):
da[a[i]]=i
db[b[i]]=i
d1,d2={},{}
for ele in da:
x,y=da[ele],db[ele]
if y<x:
k1=(y+n)-x
k2=x-y
el... | 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
import operator
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arrA = [0]*n
arrB = [0]*n
arr = [0]*n
for i in range(n):
currA = a[i]
currB = b[i]
arrA[currA-1] = i+1
arrB[currB-1] = i+1
for i in range(n):
diff = arrA[i] - 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 java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] A = new int[n+1];
int[] B = new int[n+1];
for(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 | #include <bits/stdc++.h>
using namespace std;
bool desc(long long int a, long long int b) { return (a > b); }
bool pairone(pair<long long int, long long int> &a,
pair<long long int, long long int> &b) {
return (a.first < b.first);
}
void show(vector<int> vec) {
for (auto x : vec) cout << x << " ";
co... | 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 | from sys import stdin,stdout
from collections import defaultdict as dd
from collections import Counter as ctr
n = int(stdin.readline().strip())
a = list(map(int,stdin.readline().strip().split()))
b = list(map(int, stdin.readline().strip().split()))
d = dd(int)
ans = []
for i in range(n):
d[a[i]]=i
for i in 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 | from math import *
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = dict()
for i in range(n):
d[a[i]] = i
dif = dict()
for i in range(n):
x = (i - d[b[i]])%n
if(x in dif):
dif[x] += 1
else:
dif[x] = 1
print(max(dif.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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader ... | 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.math.BigDecimal;
import java.util.*;
public class Main {
Scanner sc = new Scanner(System.in);
int[] dx = {1, 0, -1, 0};
int[] dy = {0, 1, 0, -1};
public static void main(String[] args) {
new Main().run();
}
void run() {
int n = sc.nextInt();
Pair[] a = 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 | import java.util.*;
import javax.security.auth.kerberos.KerberosKey;
import javax.swing.plaf.basic.BasicScrollPaneUI.HSBChangeListener;
import java.awt.font.GraphicAttribute;
import java.io.*;
import java.nio.channels.AcceptPendingException;
import java.time.Period;
public class Main {
public static void main(... | 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
n = int(sys.stdin.readline())
a = [int(i) for i in sys.stdin.readline().split()]
b = [int(i) for i in sys.stdin.readline().split()]
d = {}
for i,ai in enumerate(a):
d[ai] = i
offsets = {}
for i,bi in enumerate(b):
aloc = d[bi]
offsets[(i - aloc + n) %n] = offsets.get((i - aloc + n) %n,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.BigInteger;
import java.util.*;
public class n1{
static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out=new PrintWriter(System.out);
public static void main(String[] args) throws Exception{
int n=Integer.parseInt(in.readLine());
... | 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())
r=lambda :list(map(int,input().split()))
pos,ans,a,b=[0]*(n+1),dict(),r(),r()
for i in range(1,n+1):pos[a[i-1]]=i
for i in range(1,n+1):
ps=pos[b[i-1]]-i
if ps<0:ps+=n
ans[ps]=ans.get(ps,0)+1
print(max(ans.values())) | 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 | if __name__ == '__main__':
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d1 = [0]*n
d2 = [0]*n
for i in range (n):
d1[a[i]-1]+=i
for i in range (n):
d1[b[i]-1]-=i
for a in d1:
d2[a]+=1
print(max(d2)) | 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()))
a1 = [-1]*(n+1)
a2 = [-1]*(n+1)
for i in range(n):
a1[a[i]] = i
a2[b[i]] = i
l1 = []
l2 = []
for i in range(1, 1+n):
l1.append((a1[i]-a2[i])%n)
l2.append((a2[i]-a1[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 | n=int(input())
a=[int(x)-1 for x in input().split()]
b=[int(x)-1 for x in input().split()]
#n=2*10**5
#a=list(range(n))
#b=list(range(n))
aindex=[0]*n
bindex=[0]*n
for i in range(n):
aindex[a[i]]=i
bindex[b[i]]=i
ans=[0]*n
for i in range(n):
x=aindex[i]-bindex[i]
if x<0:
x=n+x
ans[x]+=1
#print(ainde... | 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(x) for x in input().split(' ')]
B=[int(x) for x in input().split(' ')]
C=[0 for x in range (0,n)]
D=C.copy()
E=C.copy()
E.append(0)
X=[]
if len(A)<=1:
print (1)
else:
for i in range (0,n):
C[A[i]-1]=i
D[B[i]-1]=i
for i in range (0,n):
e=(C[i]-D[i])%n
E[... | 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
length = int(input())
x = list(map(int,input().split()))
x_dict = defaultdict(lambda : -1)
for index in range(length):
x_dict[x[index]] = index
y = list(map(int,input().split()))
shifts = [0]*length
for index in range(length):
temp = index-x_dict[y[index]]
if temp>=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 math
from collections import Counter,defaultdict
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
d1=defaultdict(lambda :0)
d2=defaultdict(lambda :0)
d3=defaultdict(lambda :0)
for i in range(n):
d1[b[i]]=i
for i in range(n):
j=d1[a[i]]
if(j>i):
d2[i+n-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 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
index = [[0,0] for _ in range(n+1)]
for i in range(1,n+1):
index[a[i-1]][0]=i
index[b[i-1]][1]=i
hashmap = defaultdict(int)
for i in range(1,n+1):
x,y = index[i]
dist = y-x
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, n, t;
t = 1;
while (t--) {
cin >> n;
long long int ar[n], b[n];
map<long long int, long long int> mp, mp2;
for (i = 0; i < n; i++) {
cin >> ar[i];
mp[ar[i]] = i;
}
long long int o = 0, z = 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 | def inp():
return map(int, input().split())
def solve():
n = int(input())
a = list(inp())
b = list(inp())
aa = [-1] + [0] * n
bb = [-1] + [0] * n
for i in range(n):
aa[a[i]] = i + 1
bb[b[i]] = i + 1
d = dict()
for i in range(1, n + 1):
k = (n + aa[i] - bb[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 | import sys
sys.setrecursionlimit(10**8)
try:
FILE_POINTER = open('input.inpt')
input = FILE_POINTER.readline
except:
FILE_POINTER = None
input = sys.stdin.readline
# ********************* Write your code from here ********************
from collections import defaultdict
n = int(input())
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 | from math import sqrt
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [0] * n
d = [0] * n
for i in range(n):
c[a[i] - 1] = i
for i in range(n):
k = c[b[i] - 1] - i
if k < 0:
k += n
d[k] += 1
m = 0
for i in d:
m = max(i, m)
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 | from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = {a[i]:i for i in range(n)}
for i in range(n):
v = i - d[b[i]]
if v >= 0:
d[b[i]] = v
else:
d[b[i]] = n+v
print(max(Counter(d.values()).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.*;
import java.io.*;
import java.text.*;
import java.math.*;
import java.lang.Math.*;
public class C {
public static void main(String[] args) throws Exception {new C().run();}
public FastIO file = new FastIO();
public int ntc, ctc;
public final long MOD = 1000000007L; //998244353L;
public fina... | 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 | #created by nit1n
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] +=... | 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 MyClass {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n =s.nextInt();
int map[] = new int[n];
int cnt[] = new int[n];
int [] arr = new int[n];
int [] arr1 = new int[n];
for(int i... | 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 | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Solution
{
// Complete the maximumSum function below.
public static class InputReader {
private InputStream s... | 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 dc
input = sys.stdin.readline
N = int(input())
L1 = list(map(int,input().split()))
L2 = list(map(int,input().split()))
d = dc(lambda:0)
d2=dc(lambda:0)
for i in range(N):
d[L2[i]]=i
for i in range(N):
DIFFERENCE = d[L1[i]]-i
if DIFFERENCE < 0:
DIF... | 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/problemset/problem/1365/C
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
shifts = {}
ans = 1
alpha = {}
for i in range(n):
alpha[b[i]]=[i]
for i in range(n):
alpha[a[i]].append(i)
for i in range(n):
index = alpha[b[i]][1]
shift = 0
if 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 | #from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
#from __future__ import print_function, division #while using python2
def modinv(n,p):
return pow(n,p-2,p)
def main():
#sys.stdin = ... | 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(x) for x in input().split()]
b = [int(x) for x in input().split()]
indices = [0] * n
for i, x in enumerate(b):
indices[x-1] = i
offsets = [0] * n
for i in range(n):
offsets[(indices[a[i]-1] - i) % n] += 1
print(max(offsets)) | 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 a[200100], b[200100], c[200100];
int main() {
int n;
int ans;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) scanf("%d", a + i);
for (int i = 0; i < n; i++) scanf("%d", b + i);
memset(c, 0, sizeof(c));
for (int i = 0; i < n; i++) {
c[... | 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 | from sys import stdin, stdout
from sys import maxsize
input = stdin.readline
# def print(n):
# stdout.write(str(n)+'\n')
def solve():
pass
test = 1
# test = int(input().strip())
for t in range(0, test):
n = int(input().strip())
# s = list(input().strip()) ... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.