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 | def solve(n, a, b):
ixs = [None] * (n)
for i, v in enumerate(a):
ixs[v - 1] = i
shifts = [0] * n
for i, v in enumerate(b):
base = i - ixs[v - 1]
if base < 0:
base += n
shifts[base] += 1
return max(shifts)
n = int(input())
a = list(map(int, input().split(... | 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()]
places = [0] * n
placesB = [0] * n
diff = [0] * n
for i in range(n):
places[a[i]-1] = i
for i in range(n):
placesB[b[i]-1] = i
for i in range(n):
diff[i] = (n-places[i]+placesB[i])%n
# print(diff)
ats = [0] * n
fo... | 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 as cc
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n, = I()
a=I();b=I()
idx=[0]*(n+1)
x=[0]*(n+1)
for i in range(n):
idx[b[i]]=i
x[a[i]]=i
an=0
k=[0]*n
for i in range(1,n+1):
k[i-1]=(x[i]-idx[i])%n
c=cc(k)
print(max(c.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 | from sys import stdin
n= int(input())
l1 = list(map(int, stdin.readline().rstrip().split(" ")))
l2 = list(map(int, stdin.readline().rstrip().split(" ")))
d1 = {}
d2 = {}
d3 = {}
for i in range(1,n+1):
d1[l1[i-1]] = i
d2[l2[i-1]] = i
for i in range(1,n+1):
if d2[i]-d1[i]<0:
val = n + d2[i] - d1[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().split()))
b = list(map(int, input().split()))
d = dict()
for i in range(n):
d[i] = [-1, -1]
for i in range(n):
d[a[i]-1][0] = i
d[b[i]-1][1] = i
ans = dict()
answer = 0
for i in d:
x = (d[i][0]-d[i][1])%n
if x in ans:
ans[x] += 1
answer = ma... | 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 RotationMatching {
static class Pair {
int atFirst, atSecond;
}
private static final Scanner in = new Scanner(System.in, "UTF-8");
public static void main(String[] args) {
int n = in.nextInt();
Pair[] values = new Pair[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 | """
Satwik_Tiwari ;) .
16 june , 2020 - Tuesday
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IO... | 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=input()
a=[int(i) for i in raw_input().split()]
b=[int(i) for i in raw_input().split()]
d1={}
d2={}
for i in range(n):
d1[a[i]]=i
d2[b[i]]=i
l=[]
for i in range(1,n+1):
l.append((d1[i]-d2[i])%n)
l.sort()
d={}
for i in l:
d[i]=d.get(i,0)+1
print max(d.values())
| 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.util.Arrays;
import java.util.Scanner;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t;
t = 1;
while((t--) >0 ){
int n;
n = in.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 | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]*n
y=[0]*n
for i in range(n):
x[a[i]-1]=i
y[b[i]-1]=i
ans=[0]*n
for i in range(n):
m=(x[i]-y[i])%n
ans[m]+=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
def main():
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d,d1=dict(),[]
for i in range(n):
d[a[i]]=i
for i in range(n):
if(i-d[b[i]]>0):
d1.append(i-d[b[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 | #!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
accumulate, comb... | 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()))
h={}
for i in range(n):
h[a[i]]=i
cnt=[0]*(n)
for i in range(n):
if(h[b[i]]>=i):
cnt[h[b[i]]-i]+=1
else:
cnt[n+h[b[i]]-i]+=1
print(max(cnt))
| 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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import ja... | 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 math import *
def r1(t):
return t(input())
def r2(t):
return [t(i) for i in input().split()]
def r3(t):
return [t(i) for i in input()]
n = r1(int)
a = r2(int)
b = r2(int)
m1 = {}
m2 = {}
for i in range(n):
m1[i] = 0
m2[i] = 0
ia = [0] * n
ib = [0] * n
for i in range(n):
ia[a[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 | import sys;input=sys.stdin.readline
N, = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = [0]*N
d2 = dict()
for i in range(N):
d2[X[i]] = i+1
for i in range(N):
Z[i] = (d2[Y[i]]-(i+1))%N
from collections import defaultdict
d = defaultdict(int)
for z in Z:
... | 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 | # Rotation Matching
import sys
from collections import Counter
def swap(x, y, a):
temp = a[x]
a[x] = a[y]
a[y] = temp
return a
def solve():
return None
def main():
q = []
for line in sys.stdin.readlines():
q.append(line)
for i in range(len(q)):
q[i] = q[i].rstrip().split(' ')
q[i] = [int(x) for x 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())
first = {key: value for key, value in zip(map(int, input().split()), range(n))}
second = list(map(int, input().split()))
values = {}
for i in range(n):
p = second[i]
value_right = f"{abs(n - abs(i - first[p]))} {'r' if i - first[p] > 0 else 'l'}"
value_left = f"{abs(i - first[p])} {'l' if ... | 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() {
const int N = 1e5 * 2 + 1;
int m;
int c[N] = {0};
int d[N] = {0};
int r[N] = {0};
int a;
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> a;
c[a] = i;
}
for (int i = 0; i < m; ++i) {
cin >> a;
d[a] = i;
}
for (int i = 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 | #Codeforce - array bruteforce 1400 - Rotation Matching
n = int(input())
arrA = list(map(int, input().split()))
arrB = list(map(int, input().split()))
positionAdict = dict()
positionBdict = dict()
for i in range(n):
positionAdict[arrA[i]] = i
positionBdict[arrB[i]] = i
moveCount = [0]*n
for i in range(n):
if... | 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())
B=list(map(int,input().split()))
A=list(map(int,input().split()))
C=[0 for i in range(n+1)]
D=[0 for i in range(n+1)]
for i in range(n):
C[B[i]]=i
D[A[i]]=i
CD=[0 for i in range(n+1)]
for i in range(1,n+1):
if ((D[i]-C[i])<=0):
CD[D[i]-C[i]+n]=CD[D[i]-C[i]+n]+1
else:
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 |
if(__name__ == '__main__'):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
id = [dict(), dict()]
for i in range(n):
id[0][a[i]] = i
id[1][b[i]] = i
ans = dict()
for i in range(1, n + 1):
d = (n + id[0][i] - id[1][i]) % n
... | 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 division, print_function
def main():
# Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, floor
from heapq import heappush, heappop, heapify, nlargest, nsmal... | 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())
ai = list(map(int,input().split()))
bi = list(map(int,input().split()))
sub = [0 for k in range(n)]
distancia = [0 for k in range(n)]
for k in range(n):
sub[ai[k]-1] -= k
sub[bi[k]-1] += k
for k in range(n):
if(sub[k] < 0):
distancia[n + sub[k]] += 1
else:
distancia... | 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+1)
d=[0]*(n+1)
left=[0]*(n+1)
right=[0]*(n+1)
for i in range(n):
c[a[i]]=i
d[b[i]]=i
for i in range(1,n+1):
if c[i]<d[i]:
left[n-d[i]+c[i]]+=1
right[d[i]-c[i]]+=1
else:
left[c[i]-d[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
input = stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
z = [0]*(n+1)
for i in range(n):
z[a[i]] = i
c = [0]*(n+1)
ans = 0
for i in range(n):
x = z[b[i]] - i
if x < 0:
x += n
c[x] += 1
ans = max(ans, c[x])
pri... | 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 os import path
import sys,time
# mod = int(1e9 + 7)
# import re
from math import ceil, floor,gcd,log,log2 ,factorial
from collections import defaultdict ,Counter , OrderedDict , deque
from itertools import combinations,accumulate
# from string import ascii_lowercase ,ascii_uppercase
# from bisect import *
from hea... | 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 | public class Main {
public static void main(String[] args) {
var s = new java.util.Scanner(System.in);
int n = s.nextInt();
int[] offset = new int[n];
int[] a = new int[n];
int[] pos = new int[n];
for (int i = 0; i < n; i++) a[i] = s.nextInt();
for (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 | import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n=int(input())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
index=defaultdict(lambda:0)
for i in range(n):
index[a[i]]=i
ans=0
shift=defau... | 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()))
dp = defaultdict(lambda : 0) ; temp = [0]*(n+1)
for i in range(n):
temp[a[i]] = i
for i,v in enumerate(b):
cur = temp[v] - i
if(cur < 0): cur+=n
dp[cur]+=1
ans = 0
for i , j in dp... | 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.math.BigInteger;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
impor... | 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())
arr=list(map(int,input().split()))
brr=list(map(int,input().split()))
arr=list(zip(arr,range(0,n)))
arr.sort()
brr=list(zip(brr,range(0,n)))
brr.sort()
cnt=[0]*n
for i in range(n):
cnt[(arr[i][1]-brr[i][1])%n]+=1
print(max(cnt)) | 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.HashMap;
import java.util.StringTokenizer;
public class _648_C implements Runnable{
public static void main(String[] args) {
new Thread(null, new _648_C(),"Main",1<<27).st... | 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 | # we must perform a rotation in a first array A in order to obtain the most
# number of elements pairing (in the same position) on an array B.
# For that matter, we compute how much we need to rotate the array for each
# elemnt to match arrays A and B. After that, get the number of rotation that
# which will lead to mo... | 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 diff(a, b, num):
n = a[num]
d = num - c[n] % len(a)
if(d < 0):
d = len(a)+d
return d
n = int(input())
a = [int(i)-1 for i in input().split(" ")]
b = [int(i)-1 for i in input().split(" ")]
c = [None for i in range(n)]
for p, e in enumerate(b):
c[e] = p
diffs = [diff(a,c,i) for i in ... | 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()))
pos = {}
for i in range(n):
pos[a[i]]=i
dic = {}
for i in range(n):
cur = pos[b[i]]-i
if cur<0:
cur+=n
if cur in dic:
dic[cur]+=1
else:
dic[cur]=1
res = 0
for key, value in dic.items()... | 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
cin = stdin.readline
cout = stdout.write
mp = lambda: list(map(int, cin().split()))
n, = mp()
a = mp()
b = mp()
pos = [0]*(n+1)
ans = [0]*n
for i in range(n):
pos[b[i]] = i
#ans += a[i] == b[i]
k = 0
for i in range(n):
ans[(pos[a[i]]-i)%n] += 1
cout(str(sorted(ans, reverse=True)[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 | #include <bits/stdc++.h>
using namespace std;
int main() {
(ios_base::sync_with_stdio(false), cin.tie(NULL));
;
long long n;
cin >> n;
long long a[n + 5], b[n + 5], index[n + 5];
for (long long i = 0; i < n; i++) {
cin >> a[i];
index[a[i]] = i;
}
map<long long, long long> mp;
for (long long 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 = list(map(int, input().split()))
b = list(map(int, input().split()))
diff = [0] * (n + 1)
for i in range(n):
diff[a[i]] += i
diff[b[i]] -= i
del diff[0]
for i in range(n):
diff[i] %= n
from collections import *
print (max(Counter(diff).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;
long long int pows(long long int a, long long int n, long long int m) {
long long int res = 1;
while (n) {
if (n % 2 != 0) {
res = (res * a) % m;
n--;
} else {
a = (a * a) % m;
n = n / 2;
}
}
return res % m;
}
int gcd(int a, int b... | 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 | //package div2_646;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class A {
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
... | 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);
int t = 1;
while (t--) {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
vector<pair<... | 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
input = sys.stdin.readline
n = int(input())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
posix = [0] * (n+1)
for i in range(n):
posix[a[i]] = i
moveVal = [0] * (n+1)
for i in range(n):
move = posix[b[i]] - i
if move < 0:
move += n
moveVal[move] += 1
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 | # -*- coding: utf-8 -*-
"""
Created on Wed Jun 10 10:10:27 2020
@author: Harshal
"""
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
idx=[0]*n
cnt=[0]*n
for i in range(n):
idx[a[i]-1]=i
for i in range(n):
cnt[idx[b[i]-1]-i]+=1
print(max(cnt)) | 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;
int arr1[n], arr2[n];
int m2[n];
for (int i = 0; i < n; i++) {
cin >> arr1[i];
}
for (int i = 0; i < n; i++) {
cin >> arr2[i];
m2[arr2[i]] = i;
}
map<int, int> m;
for (int i = 0; i < n; i++) {
if (i >= m2[arr... | 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())
import collections
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
a1={}
b1={}
c=0
for i in range(n):
a1[a[i]]=i
b1[b[i]]=i
if a[i]==b[i]:
c+=1
d=[]
for i in a1:
e=a1[i]-b1[i]
if e<0:
e=n+e
d.append(e)
#print(d)
d1=collections.Counter(d)
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 | def main():
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
dct = dict()
for i in range(n):
if a[i] in dct:
dct[a[i]][0] = i
else:
dct[a[i]] = [i, 0]
if b[i] in dct:
dct[b[i]][1] = i
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 |
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
f = open('q1.input', 'r')
except IOError:
f = sys.stdin
if 'xrange' in dir(__builtins__):
range = xrange
# print(f.readline())
sys.setrecursionlimit(10**2)
def print_case_iterable(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 | a=int(input())
z1=list(map(int,input().split()))
z2=list(map(int,input().split()))
maxa=0
from collections import *
dl=defaultdict(int)
al=defaultdict(list)
al=defaultdict(lambda: [0,0],al)
for i in range(len(z1)):
al[z1[i]][0]=i
al[z2[i]][1]=i
for i in range(1,a+1):
if(al[i][1]>=al[i][0]):
dl[al[... | 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;
using lint = int64_t;
using uint = uint32_t;
using ulint = uint64_t;
template <class T>
using vector2d = vector<vector<T>>;
template <class T>
bool UpdateMax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
} else {
return false;
}
}
template <class T>... | 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 collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
f1 = {}; f2 = {}
for i in range(n):
f1[a[i]] = i
for i in range(n):
f2[b[i]] = i
checker = {}
for i in range(1,n+1):
if(f1[i]<=f2[i]):
checker[i] = f2[i] - f1[i]
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 | import os, sys
from collections import defaultdict
raw_input = sys.stdin.readline
n = int(raw_input())
a = map(int, raw_input().split())
b = map(int, raw_input().split())
pos_a = {}
pos_b = {}
for n_itr in xrange(n):
pos_a[a[n_itr]] = n_itr
pos_b[b[n_itr]] = n_itr
max_ppos = defaultdict(int)
for n_itr in xrange(n... | 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 sys
input = sys.stdin.buffer.readline
from collections import Counter
def I(): return(list(map(int,input().split())))
def sieve(n):
a=[1]*n
for i in range(2,n):
if a[i]:
for j in range(i*i,n,i):
a[j]=0
return a
def check(k):
a1=a[k:]+a[:k]
c=0
print(a1,b)
for i in range(n):
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 | def val(ai,bi):
final={}
lst={}
for i in range(N):
final[bi[i]]=i
for i in range(N):
if final[ai[i]]-i<0:
final[ai[i]]=N-i+final[ai[i]]
else:
final[ai[i]]-=i
for i in final:
if final[i] not in lst:
lst[final[i]]=1
else:
... | 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 copy import *
import math as mt
def mostFrequent(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 ... | 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(n,seqA,seqB) :
table = {x:index for index,x in enumerate(seqA,0)}
diff = {}
for indexB in range(n) :
res = table[seqB[indexB]] - indexB
if res < 0 :
if (res*-1) > (n//2) :
res = n - (res*-1)
else :
if 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 | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dif = [0]*n
a = list(enumerate(a))
b = list(enumerate(b))
a.sort(key = lambda x:x[1])
b.sort(key = lambda x:x[1])
for i in range(n):
q1 = a[i][0]
q2 = b[i][0]
if q2-q1<0:
dif[i]=(n+(q2-q1))
else:
dif[i... | 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()]
pos=[0]*(n+1)
for i in range(0,n):
val=b[i]
pos[val]=i
d=dict()
for i in range(0,n):
val=a[i]
posn=pos[val]
diff=posn-i
if diff<0:
diff=n+diff
if diff not in d:
d[diff]=1
else:
... | 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(ele) for ele in input().split()]
b = [int(ele) for ele in input().split()]
mem = {}
diff = []
for i in range(1,n+1):
mem[i] = []
for i in range(n):
mem[a[i]].append(i)
for i in range(n):
mem[b[i]].append(i)
for i in range(n):
diff.append(0)
for key in mem.keys():
if mem[... | 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 double PI = 3.14159265;
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
fast();
int n;
cin >> n;
int a[200005], b[200005];
map<int, int> mp;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[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 |
import java.util.*;
import java.io.*;
public class Template {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
HashMap<Integer,Integer> m1 = new HashMap<>();
HashMap<Integer,Integer> m2 = new HashMap<>();
HashMap<Integer,Integer> map = new HashMap<>();
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 | // Working program with FastReader
import java.io.*;
import java.util.*;
public class ll
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
... | 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.Scanner;
public class Problem1365c {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[n];
int[] b = new int[n];
for(int i = 0; i < n; i++) {
int x = sc.nextInt();
a[x... | 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 codeforces._648;
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;
public class _648_C {
public static void main (String[] args) throws Exception {
String s = "7\n" +
"1 7 3 2 6 4 5\n" +
"2 4 7 6 1 5 3";
// br = new BufferedRe... | 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 | num = int(input());
ft=list(map(int,input().split()))
st=list(map(int,input().split()))
ans=[0]*(num+1)
for i in range(num):
ans[ft[i]]=i
mx=[0]*(num+1)
#print(ans)
for i in range(num):
j=ans[st[i]]
if(i-j)>0:
mx[i-j]+=1
else:
mx[num+(i-j)]+=1
#print(mx)
print(max(mx)) | 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 | #int(x) for x in input().split()
#map(int,input().split())
import copy
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
d={}
for i in range(len(b)):
d[b[i]]=i
c={}
for i in range(len(a)):
p=(i-d[a[i]]+n)%n
if p in c:
c[p]+=1
else:
c[p]=1
print(max(list(c.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 N;
int df[200001];
int sp[200000] = {0};
int main() {
int elem;
cin >> N;
for (int i = 1; i <= N; i++) cin >> elem, df[elem] = i;
for (int i = 1; i <= N; i++) {
cin >> elem;
int shiftsReq = (df[elem] - i + N) % N;
sp[shiftsReq] += 1;
}
int max = ... | 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;
int main() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
int d;
cin >> d;
a[d - 1] = i + 1;
}
for (int i = 0; i < n; i++) {
int d;
cin >> d;
b[d - 1] = i + 1;
}
unordered_map<int, int> m;
for (int i = 0; i < n; 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 | R = lambda : map(int, input().split())
n = int(input())
a = R()
b = R()
from collections import defaultdict
max_match = -1
ind = {}
dis = defaultdict(int)
for i, el in enumerate(a):
ind[el] = i
for i, el in enumerate(b):
if(i - ind[el] < 0):
d = -(i - ind[el])
else:
d = (n - i) + ind[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 | import sys
import collections
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_loc, b_loc = [0] * (n + 1), [0] * (n + 1)
for i in range(n):
a_loc[a[i] - 1] = i
b_loc[b[i] - 1] = i
c = [(a_loc[i] - b_loc[i]) for i in range(n)]
res = 0
cnt = collecti... | 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()))
revA = []
b = list(map(int,input().split()))
revB = []
diffCount = []
for i in range(n):
revA.append(-1)
revB.append(-1)
diffCount.append(0)
for i in range(n):
revA[a[i] - 1] = i
revB[b[i] - 1] = i
for i in range(n):
diffCount[(revA[i] - rev... | 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()))
# Get locations of a & b
#declare location lists
a_loc = [-1 for i in range(n)]
b_loc = [-1 for i in range(n)]
# insert locations
for i in range(n):
a_loc[a[i]-1] = i
b_loc[b[i]-1] = 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;
int n, m, cases, t, ans, sz;
string s, s2, s3;
int ar[(int)(1e6 + 10)], ar2[(int)(1e6 + 10)];
int aa[(int)(1e6 + 10)], bb[(int)(1e6 + 10)];
void brainfuck();
void checker() {
map<int, int> mp;
map<int, int>::iterator it;
cin >> n;
for (int i = 1; i <= n; 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 | import java.io.*;
import java.math.*;
import java.util.*;
public class test {
/*
* array list
*
* ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
*
* BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
*
* hash map
*
* HashMap<Integer,Integer> hm=new HashMap<Integer,Integ... | 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.io.*;
public class Main {
public static void main(String[] args) throws IOException,InterruptedException{
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
int[] b=new int[n];
int[] pos1=new int[n];
int[] po... | 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
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits
def read_line():
return stdin.readline().strip()
def read_int():
return int(read_line())
def read_arr():
retu... | 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.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharF... | 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 | """
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __|
| |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \
\____\___/ \__,_|\___|_| \___/|_| \___\___||___/
"""
"""
βββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
βββββββββ... | 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_i = [int(a) for a in input().split()]
b_i = [int(b) for b in input().split()]
list = [0 for num in range(n+1)]
for index in range(n):
list[a_i[index]] = index
for index in range(n):
list[b_i[index]] -= index
if list[b_i[index]] < 0:
list[b_i[index]] += n
list.sort()
maximum = 0
co... | 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()))
ga={}
gb={}
for i in range(n):ga[a[i]]=i;gb[b[i]]=i
g={}
for i in range(1,n+1):o=(gb[i]-ga[i])%n;g[o]=g[o]+1if g.get(o)else 1
print(max(g[i]for i in g)) | 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 | #------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUF... | 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 | # cook your dish here
ind=[-1 for i in range(200005)]
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
ind[a[i]]=i
d=dict()
for i in range(n):
x=ind[b[i]]
z=0
if x>=i:
z=x-i
else:
z=n-i+x
d[z]=d.get(z,0)+1
l=d.values()
print(max... | 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 = lambda: sys.stdin.readline().strip("\r\n")
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
al = [0]*n
bl = [0]*n
for i in range(n):
al[a[i]-1] = i+1
bl[b[i]-1] = i+1
# print(al)
# print(bl)
ans = [0]*n
for i in range(n):
ans[(al[i] - bl[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 = input()
a = map(int,raw_input().split())
b = map(int,raw_input().split())
m = {a[n]:n for n in range(N)}
dists1 = {}
dists2 = {}
for n in range(N) :
loc = m[b[n]]
p1 = (loc-n) % N
p2 = N-p1
dists1[p1] = dists1.get(p1, 0) + 1
dists2[p2] = dists2.get(p2, 0) + 1
#print dists1
#print dists2
best = 0
for ... | 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_trans = [0] * (n + 1)
for i, ai in enumerate(input().split()):
a_trans[int(ai)] = i
matches = [0] * n
for i, bi in enumerate(input().split()):
matches[(i - a_trans[int(bi)]) % n] += 1
print(max(matches))
| 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={}
for i,e in enumerate(a):
d[e]=i
for i,e in enumerate(b):
d[e]-=i
if d[e]<0:
d[e]+=n
v=d.values()
# print(d,v)
from collections import Counter
c=Counter(v)
print(max(c.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.*;
public class Codeforces{
static int gcd(Integer a,Integer b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
//int t=sc.nextInt();
//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 | from collections import Counter
def f(n,a,b):
d={}
for i in xrange(n): d[a[i]]=i
b2=[d[x] for x in b]
c=[(b2[i]-i)%n for i in xrange(n)]
return Counter(c).most_common()[0][1]
n=int(raw_input())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
print f(n,a,b)
| 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;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 2e5 + 10;
const int M = (1 << 20) + 10;
const int maxn = 1e6 + 10;
const int mod = 1000000007;
const double eps = 1e-10;
const double pi = acos(-1.0);
int n;
int a[N];
int p[N];
int cnt[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 |
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n= scan.nextInt();
Map<Integer, Integer> a = new HashMap<>();
for(int i=0;i<n;i++) {
a.pu... | 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>
#pragma GCC optimize("Ofast")
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n], b[n];
for (auto &it : a) cin >> it;
for (auto &it : b) cin >> it;
map<long long, long long> m1, m2;
for (long long i = 0; i < n; i++) {
m1[a[i]] = i + 1;
}
for (long lo... | 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 *
input = stdin.readline
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = [0]*(n+1)
for i in range(n):
d[b[i]] = i
# print(d)
e = [0]*(n+1)
for i in range(n):
ind = d[a[i]]
if(ind>=i):
e[i] = ind - i
else:
e[i] = ind +... | 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()))
l1=[0]*n
l2=[0]*n
diff=[0]*n
m={}
for w in range(n):
l1[a[w]-1]=w
for w in range(n):
l2[b[w]-1]=w
for w in range(n):
if l2[w]>=l1[w]:
diff[w]=l2[w]-l1[w]
else:
diff[w]=n-(l1[w]-l2[w])
for w in diff:
if w... | 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 | #!/usr/bin/env python
from __future__ import division, print_function
import os
import 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
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
... | 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) for i in input().split()]
b = [int(i) for i in input().split()]
da = {}
db = {}
for i in range(N):
da[a[i]] = i
db[b[i]] = i
counts = {}
for i in range(1,N+1):
if(db[i]>da[i]):
count = da[i] + N-db[i]
else:
count = da[i]-db[i]
if(count in counts.keys... | 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())
aa = map(int, input().split())
aid = [0] * (n + 1)
for i, a in enumerate(aa):
aid[a] = i
bb = map(int, input().split())
dcount = [0] * n
for i, b in enumerate(bb):
dcount[(i - aid[b]) % n] += 1
print(max(dcount))
| 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()))
aIndex = {}
for i in range(n):
aIndex[a[i]] = i
cnt = [0]*n
for i in range(n):
tmp = aIndex[b[i]] - i
cnt[tmp if tmp >= 0 else tmp + n] += 1
print(max(cnt)) | 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;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t, n;
t = 1;
while (t--) {
cin >> n;
long long a[n], b[n];
map<long long, long long> mp1, mp2, mp3;
for (long long i = 0; i < n; i++) {
cin >> a[i];
mp1[... | 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
input=sys.stdin.readline
t=1
while t>0:
t-=1
n=int(input())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
d=[0 for i in range(n+1)]
for i in range(n):
d[a[i]]=i
for i in range(n):
b[i]=d[b[i]]
d={}
for i in range(n):
if (b[... | 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 functools
def A():
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
a = [[]] * n
for j in range(n):
a[j] = list(map(int, input().split()))
free_str_state = [1] * n
free_col_state = [1] * m
for i in range(n):
... | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.