prompt string | response string |
|---|---|
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import Counter
def solve_test_case(t):
n = int(input())
a = parse_array(int)
b = parse_array(int)
val_to_idx_a = {
e: i for i, e in enumerate(a)
}
cc = Counter()
for i, e in enumerate(b):
pos_a = val_to_idx_a[e]
distance = (pos_a + n - i) % n
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long a[n];
for (long long i = 1; i <= n; i++) {
long long t;
cin >> t;
a[t] = i;
}
long long b[n];
for (long long ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
import math
import collections
from sys import stdin,stdout,setrecursionlimit
import bisect as bs
setrecursionlimit(2**20)
M = 10**9+7
# T = int(stdin.readline())
T = 1
for _ in range(T):
n = int(stdin.readline())
# n,... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
arr=list(map(int,input().strip().split()))
brr=list(map(int,input().strip().split()))
d=dict()
e=dict()
for i in range(1,n+1):
d[i]=0
for i in range(n):
a=arr[i]
e[a]=i
for j in range(n):
b=brr[j]
t=e[b]
if(t>j):
q=t-j
d[q]=d[q]+1
elif(t<=j):
q=n-j+t
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a_pol = [-1 for _ in range(n)]
b_pol = [-1 for _ in range(n)]
for i in range(n):
a_pol[a[i] - 1] = i
b_pol[b[i] - 1] = i
ans = [0 for _ in range(n)]
for i in range(n):
k = (a_pol[i] - b_pol[i] + n) % n
ans[k] += 1
p... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
input = sys.stdin.readline
from collections import defaultdict
n=int(input())
a=[int(i) for i in input().split() if i!='\n']
b=[int(i) for i in input().split() if i!='\n']
inda=[0]*(n)
indb=[0]*(n)
for i in range(n):
inda[a[i]-1]=i
indb[b[i]-1]=i
diff=defaultdict(int)
for i in range(n):
if inda[i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
shift=[0]*(1+n)
ida,idb=[0]*(1+n),[0]*(1+n)
for i in range(n):
ida[a[i]]=i
idb[b[i]]=i
for i in range(1,1+n):
shift[(ida[i]-idb[i])%n]+=1
print(max(shift)) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* http://codeforces.com/contest/1365/problem/C
*/
public class TaskC {
public static void main(Strin... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
constexpr int R = 5e5 + 6969, INF = 2e9 + 6969;
int x;
int main() {
int n, t[2][R], cnt[R];
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
t[0][x] = i;
}
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
t[1][x] = i;
}
for (int i ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
pos = list(0 for i in range(n))
for i in range(n):
pos[arr1[i] - 1] = i
left = list(int(0) for i in range(n + 1))
right = list(int(0) for i in range(n + 1))
for i in range(n):
if i < pos[arr2[i] - 1]:
lol = i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #------------------------------------------------------------------------------------------------
#author : Shorya
#contact: shorya361@gmail.com
#Punk_GTS python Template
from sys import stdin,stdout
from collections import Counter, defaultdict
import math
def readInt(): return int(stdin.readline())
def readString():... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
input = sys.stdin.buffer.readline
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
a+=a
ia=[[] for _ in range(n)]
ib=[[] for _ in range(n)]
for i,x in enumerate(a):
ia[x-1].append(i)
for i,x in enumerate(b):
ib[x-1].append(i)
cnt=[0]*n
for i in range(n):
ii,jj=ia[i]
kk=ib[i][0]
i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n), b(n);
vector<int> apos(n), bpos(n);
for (int i = 0; i < n; i++) cin >> a[i], apos[--a[i]] = i;
for (int i = 0; i < n; i++) cin >> b[i], bpos[--b[i]] = i;
vector<int> val(n);
for (int i = 0; i < n; i++) {
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
input = sys.stdin.buffer.readline
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
_a = [0 for i in range(n+1)]
_b = [0 for i in range(n+1)]
for i in range(n):
_a[a[i]] = i
_b[b[i]] = i
ans = [0 for i in range(n+1)]
for i in range(1,n+1):
diff = _a[... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import deque
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pos = [0 for x in range(n+1)]
mmax = 0
offset = [0 for x in range(n+1)]
for i in range(n):
pos[a[i]]=i
for i in range(n):
cur = pos[b[i]] - i
if cur <0:
cur += n
offset[cur]+=1... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | for t in range(1):
n=int(input())
# n,m = map(int,input().split())
# matrix = [[] for i in range(n)]
# for i in range(n):
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))
ct=0
matrix=[0]*n
diff =[0]*n
diffn =[0]*n
for i in range(n):
matrix[brr[i]-1]=i
# print(matrix)
for i in r... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
import math
from collections import defaultdict
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
def solve(test):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
rec = {}
for i in range(n):
rec[a[i]] = i
freq = defaultdict(int)
f... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.*;
import java.util.*;
public class cp1 {
public static void main(String args[]) {
int n=II();
int a[]=IIA(n);
int b[]=IIA(n);
HashMap<Integer, Integer> hmap=new HashMap<>();
HashMap<Integer, Integer> diff=new HashMap<>();
for(int i=0;i<n;i++){
hmap.put(a[i], i);
}
for(int i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n], b[n];
map<int, pair<int, int>> m;
for (long long i = 0; i < (long long)(n); i++) {
cin >> a[i];
m[a[i]].first = i;
}
for (long long i = 0; i ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | FAST_IO = 1
if FAST_IO:
import io, sys, atexit
rr = iter(sys.stdin.read().splitlines()).next
sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().s... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;
public class C1365 {
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... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
v=[0 for i in range(n+1)]
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(n):
v[a[i]]=(v[a[i]]+i%n)%n
v[b[i]]=(v[b[i]]-i%n)%n
freq=[0 for i in range(n)]
for i in range(1,n+1):
freq[v[i]]+=1
print(max(freq))
|
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | N = int(input())
a = map(int, input().strip().split())
a_positions = {elem: i for i, elem in enumerate(a)}
b = map(int, input().strip().split())
b_positions = {elem: i for i, elem in enumerate(b)}
rotation_differences = {i:0 for i in range(N)}
max_occurance = 0
for i in range(1, N + 1):
key = (b_positions[i] - a_po... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
a=input().split()
ai=[int(i) for i in a]
b=input().split()
bi=[int(i) for i in b]
arr=[[] for i in range(n)]
for i in range(n):
arr[ai[i]-1].append(i)
for i in range(n):
arr[bi[i]-1].append(i)
fina=[0 for i in range(n)]
for i in arr:
x=i[0]
y=i[1]
if(y>=x):
fina[y-x]+=1
el... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import defaultdict
def solve(lst1, lst2):
loc = {}
for i, num in enumerate(lst1):
loc[num] = i
diff = defaultdict(int)
for i, num in enumerate(lst2):
j = loc[num]
if j - i >= 0:
diff[j - i] += 1
else:
diff[j - i + n] += 1
res... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... |
import java.io.*;
import java.util.*;
import java.lang.*;
public class RotationMatching{
public static class FastReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
publ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t, m, n, k;
cin >> n;
long long a[n], b[n], maxCount = -1, val;
map<int, int> mp, mpp;
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]] = i;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
if (i > mp[b[i]])
val = i ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def parseint():
ln = input().split()
for i in range(len(ln)):
ln[i] = int(ln[i])
return ln
def solve(n, a, b):
a_map = {}
b_map = {}
for i in range(n):
a_map[a[i]] = i
b_map[b[i]] = i
dists = {}
for i in range(1, n + 1):
dist = b_map[i] - a_map[i]
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import defaultdict as dd
from collections import Counter
n =int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
d = dd(int)
for i in range(n):
d[b[i]] = i
ans = Counter()
for i in range(n):
p = d[a[i]]
if p>=i:
ans.update({p-i:1})
else:
ans... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | //package com.company;
import java.util.*;
public class CF_1365_C {
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)
// a[i]=sc.nextInt();
// ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
inda = dict()
indb = dict()
for i, val in enumerate(a):
inda[val] = i
for i, val in enumerate(b):
indb[val] = i
from collections import defaultdict
maks = 0
cnt = defaultdict(int)
for i in range(1, n +... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
li=[]
d={}
di={}
maxi=0
k=0
for i in range(n):
if(a[i] in di.keys()):
di[a[i]][0]=i
else:
di[a[i]]=[0,0]
di[a[i]][0]=i
if(b[i] in di.keys()):
di[b[i]][1]=i
else:
di[b[i]]=[0,... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input());aa = map(int, input().split());aid = [0] * (n + 1);bb = map(int, input().split());dcount = [0] * n
for i, a in enumerate(aa):aid[a] = i
for i, b in enumerate(bb):dcount[(i - aid[b]) % n] += 1
print(max(dcount)) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = [0]*(n+1)
shifts = [0]*n
for i in range(len(a)):
pos[a[i]] = i
for i in range(len(b)):
sh = pos[b[i]] - i
if sh < 0:
sh += n
shifts[sh] += 1
print(max(shifts)) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools im... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
dic = {}
for i in range(n):
dic[a[i]] = i
dc = {}
dac = {}
for i in range(n):
x = dic[b[i]]
c = 0
ac = 0
if x>=i:
c = x-i
ac = (n-(x-i))
else:
ac = i-x
c = n-(i-x)
try:
dc[c]+=1
except:
dc[c] = 1
try:
dac[ac]+=... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | // package Div2_648;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class ProblemC {
public static void main(String[] args)throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdin
from collections import defaultdict
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split(" ")))
b = list(map(int, stdin.readline().rstrip().split(" ")))
ad = {}
bd = {}
for i in range(n):
ad[a[i]] = i
bd[b[i]] = i
diffs = defaultdict(lambda : 0)
keys = list(ad.key... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... |
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
pos_a = [-1]*(n+1)
pos_b = [-1]*(n+1)
for i in range(n):
pos_a[a[i]] = i
for i in range(n):
pos_b[b[i]] = i
# print(pos_a,pos_b)
cnt = [0]*(n)
for i in range(1,n+1):
cnt[ (pos_a[i] - pos_b[i] + n) % n ]+=1
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import defaultdict as dc
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=dc(int)
y=dc(int)
for i in range(n):
x[a[i]]=i
for j in range(n):
y[b[j]]=j
p=[0]*n
m=0
for k in x.keys():
if y[k]>=x[k]:
p[y[k]-x[k]]+=1
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOExcep... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ram=[0 for i in range(n+1)]
shiv=[0 for i in range(n+1)]
for i in range(1,n+1):
d=a[i-1]
ram[d]=i
for i in range(1,n+1):
d=b[i-1]
shiv[d]=i
store=[0 for i in range(n)]
for i in range(1,n+1):
if(ram[i]<shiv[i]):
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdin
from collections import Counter
input = stdin.readline
def main():
n = int(input())
a = [int(i) for i in input().split(" ")]
# n,k = [int(i) for i in input().split(" ")]
# a,b,c,d = [int(i) for i in input().split(" ")]
#
# l = []
b = [int(i) for i in input().split(" ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
mas1 = list(map(str, input().split()))
mas2 = list(map(str, input().split()))
s = {}
for i in range(n):
s[mas1[i]] = i
ans = {}
for i in range(n):
x = s[mas2[i]]
if i <= x:
ans[x - i] = ans.get(x - i, 0) + 1
else:
ans[n - i + x] = ans.get(n - i + x, 0) + 1
maxi = 0
for i in ans.items():
maxi ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.io.*;
import java.math.*;
public class Main7{
static public void main(String args[])throws IOException{
int tt=1;
StringBuilder sb=new StringBuilder();
for(int ttt=1;ttt<=tt;ttt++){
int n=i();
int[] a=... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
public class Rotation_Matching {
public static void main(String[] args) throws java.lang.Exception{
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[][] indices = new int[n][2];
for(int i=0;i<n;i++){
indices[input.nextInt()-1][0] =... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
import java.io.*;
import java.math.*;
public class C648{
public static void main(String args[]){
FastReader sc = new FastReader();
StringBuilder sb=new StringBuilder();
int t,i,n,j;
t=1;
while(t-->0){
n=sc.nextInt();
int a[]=new int[n+1];
int b[]=new i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
public final class cont648A
{
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];
int j=0,k=0;
int []ind1=new int[n+1];
//int []ind2=new int[n+1];... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
LI=lambda:list(map(int, sys.stdin.readline().strip('\n').split()))
MI=lambda:map(int, sys.stdin.readline().strip('\n').split())
SI=lambda:sys.stdin.readline().strip('\n')
II=lambda:int(sys.stdin.readline().strip('\n'))
n=II()
aid={v:i for i, v in enumerate(MI(), 1)}
dist={}
for i, v in enumerate(MI(), 1):
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.*;
import java.util.*;
/**
*
* @author Aaryan
* AV
*/
public class Test2 {
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Prin... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
import java.io.*;
public class q3{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int arr[] = new int[n];
int brr[] = new int[n];
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | # cook your dish here
n=int(input())
a=list(map(int,input().rstrip().split()))
b=list(map(int,input().rstrip().split()))
posa={}
posb={}
for i in range(n):
posa[a[i]]=i
posb[b[i]]=i
diff_r={}
diff_l={}
for i in range(1,n+1):
if posa[i]-posb[i]<0:
diff_r[i]=n+posa[i]-posb[i]
else:
diff_r[... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | //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);
static class Rotation{
Integer indexA;
Integer indexB;
Rotation(int a, int b){
this.indexA =... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
d1 = {}
d2 = {}
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
d3 = {}
for i in range(n):
d1[l1[i]] = i
d2[l2[i]] = i
for i in range(n):
if d1[i+1]-d2[i+1] in d3 and d1[i+1]-d2[i+1] > 0:
d3[d1[i+1]-d2[i+1]] = d3[d1[i+1]-d2[i+1]] + 1
elif n+d1[i+1]-d2[i+1] in d3:
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = input()
A = list(map(int,list(a.split())))
b = input()
B = list(map(int,list(b.split())))
f = [0]*(n)
table = [0]*(n+1)
for i in range(n):
table[A[i]] = i
for i in range(n):
k = table[B[i]]
if k-i>=0:
f[k-i] = f[k-i]+1
else:
f[n-(i-k)] = f[n-(i-k)]+1
print(max(f)) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... |
from collections import Counter
def read_ints():
return [int(i) for i in input().strip().split()]
def main():
n = int(input())
a = read_ints()
b = read_ints()
#get all the diffs then find the mode
#make dict of val to index
# lineer pass to get diff array
d = dict()
for idx, i in enumerat... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | """T = int(input())
for _ in range(T):
r,c= list(map(int,input().split()))
arr=[]
for i in range(r):
arr.append(list(map(int,input().split())))
x=y=0
for i in range(r):
flag=0
for j in range(c):
if arr[i][j]==1:
flag=1
break
if flag==0:
x+=1
for i in range(c):
flag=0
for j in range(r):
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import time,math,bisect
from sys import stdin,stdout
def I():
return int(stdin.readline())
def Is():
return str(stdin.readline())
def In():
return map(int,stdin.readline().split())
def L():
return list(map(int,stdin.readline().split()))
def Si():
return sorted(list(map(int,stdin.readline().split()))... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #!/usr/bin/env python
# https://github.com/cheran-senthil/PyRival/blob/master/templates/template_py3.py
import os
import sys,math
from io import BytesIO, IOBase
def main():
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
pos = [0 for i in range(n+1)]
for i in range(... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class c648 implements Runnable{
public static void main(String[] args) {
try{
new Thread(null, new c648(), "process", 1<<26).start();
}
catch(Exception e){
System.out.println(e);
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
int n, a[200005], b[200005], c[400005];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[x] = i;
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (a[x] < i)
c[n - (i - a[x])]++;
else
c[a[x] - i]++;
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #=int(input())
for _ in range(1):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
right=[0 for i in range(n+1)]
for i in range(n):
right[a[i]]=i+1
for i in range(n):
c=b[i]
if(right[c]>=i+1):
right[c]-=(i+1)
else:
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def find_diff(N, i, j):
if i < j:
res = j - i
else:
res = j + N - i
return res
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
Ai = {ai: i for i, ai in enumerate(A)}
Bi = {bi: i for i, bi in enumerate(B)}
maxi = [0] * (N + 1)
for i in range(1, N + ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | # All you need is love. But a little chocolate now and then doesn't hurt. Charles Schulz
# by : Blue Edge - Create some chaos
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[0]*n
d=[0]*(n+1)
for i in range(n):
d[a[i]]=i
for i in range(n):
j=d[b[i]]
c[(j-i)%n]+=1
print... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout
from itertools import repeat
import math
# sys.stdin = open('input')
def inp(force_list=False):
re = map(int, raw_input().split())
if len(re) == 1 and not force_list:
return re[0]
return re
def inst():... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
in1 = list(map(int, input().split()))
in2 = list(map(int, input().split()))
pos1 = [0] * n
out1 = [0] * n
for i in range(n):
pos1[in1[i] - 1] += i
for i in range(n):
pos1[in2[i] - 1] -= i
for v in pos1:
out1[v] += 1
print(max(out1))
|
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] a = new int[n];
int[] b = new int[n];
int[] apos = new int[n+1];
int[] bpos = new int[n+1];
for(int i =0;i<n;i++) ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def solve():
n = int(input().strip())
# a, b = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
a_ = [None for i in range(n+1)]
b_ = [None for i in range(n+1)]
for i in range(n):
a_[a[i]] = i + 1
b_[b[i]... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
import math
from collections import defaultdict,deque
import heapq
n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
b=list(map(int,sys.stdin.readline().split()))
dpa=defaultdict(int)
for i in range(n):
dpa[a[i]]=i
cnt=defaultdict(int)
for i in range(n):
x=dpa[b[i]]
if x<i:
cnt[(... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
best = 0
#from n to 0:
atoi = dict()
shifts_map = [0 for i in range(0,n)]
for i in range(0, n):
atoi[a[i]] = i
for i in range(0,n):
curr = 0
off = (atoi[b[i]] - i)%n
shifts_map[off] += 1
if shifts_map[off] > be... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
right=[0 for i in range(n+1)]
left=[0 for i in range(n+1)]
d={}
for j in range(len(b)):
d[b[j]]=j
for i in range(n):
k=d[a[i]]-i
if(k>=0):
right[k]=right[k]+1
left[(n-k)]=left[(n-k)]+1
else:
left[abs(k)]=left[abs(k)]+1
right[(n... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdout
from sys import stdin
def get():
return stdin.readline().strip()
def getf():
return [int(i) for i in get().split()]
def put(a, end = "\n"):
stdout.write(str(a) + end)
def putf(a, sep = " ", end = "\n"):
stdout.write(sep.join(map(str, a)) + end)
from collections import defaultdict... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
p = a.copy()
for i, aa in enumerate(a):
p[aa - 1] = i
for i, bb in enumerate(b):
b[i] = (p[bb - 1] + n - i) % n
# print(b)
b = Counter(b)
print(max(b.values())) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
from math import *
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def linput():
return list(input())
def rinput():
return map(int, tinput())
def fiinput():
return... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | # python3 q3.py < test.txt
n = int(input())
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
a_pos = {}
for i in range(n):
a_pos[a[i]] = i
counter = {}
for i in range(n):
diff = i - a_pos[b[i]]
if diff < 0:
diff = diff + n
if diff in counter:
counter[diff]... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def rotmatch(n, a, b):
placea = [0]*n
placeb = [0]*n
diff = [0]*n
for i in range(n):
placea[a[i]-1] = i
for i in range(n):
placeb[b[i]-1] = i
for i in range(n):
diff[i] = (n-placea[i]+placeb[i])%n
ats = [0]*n
for d in diff:
ats[d] += 1
return max(ats)
n = int(input())
a = list... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
a = Ri()
b = Ri()
dic1 = {}
dic2 = {}
for i in range(len(a)):
dic1[a[i]] = i
for i in range(len(b)):
dic2[b[i]] = i
dic = {}
for i in range(1,n+1):
if (dic2[i] - dic1[i])%n ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def f():
return list(map(int,input().split()))
n=int(input())
a=[0]*n
for i,x in enumerate( f() ):
a[x-1]=i
import collections
c=collections.Counter()
for i,x in enumerate( f() ):
c[ (a[x-1]-i+n)%n ]+=1
print(max(c.values())) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
long long powe(long long x, long long n) {
long long r = 1;
while (n > 0) {
if (n % 2) r *= x;
x *= x, n /= 2;
}
return r;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
long long powerTwo(long long n) {
int x = 1, k = -1;
while (true... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
maxcount = 0
arr1_hash = {}
arr2_hash = {}
for i in range(n):
arr1_hash[arr1[i]] = i
arr2_hash[arr2[i]] = i
subs = {}
for i in range(n):
sub = (arr1_hash[i + 1] - arr2_hash[i + 1]) % n
if sub in subs.keys():
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int, input().rstrip().split()))
b = list(map(int, input().rstrip().split()))
diff = [0 for i in range(n)]
for i in range(n):
a_el = a[i]
diff[a_el-1] += i + n
b_el = b[i]
diff[b_el-1] += - i + n
diff[a_el-1] = diff[a_el-1] % n
diff[b_el-1] = diff[b_el-1] % n
frequen... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdin
input=stdin.readline
import bisect
import math
#i = bisect.bisect_left(a, k)
#list=input().split(maxsplit=1)
for xoxo in range(1):
for _ in range (1):
n=int(input())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ls=[0]*n
rs=[0]*n
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
const int MAXM = 1e9 + 7;
const long long int mod = 1e9 + 7;
const int inf = MAXM;
long long int arr[MAXN];
const int N = 50000;
long long int abso(long long int a, long long int b) {
if (a > b) {
return a - b;
}
return b - a;
}
void solv... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import Counter
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
PosA = [0] * (N+1)
PosB = [0] * (N+1)
for i in range(N):
PosA[A[i]] = i+1
PosB[B[i]] = i+1
# print(PosA)
# print(PosB)
Change = [0] * (N+1)
for i in range(1,N+1):
Change[i] = PosA[i] ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... |
a=int(input())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
d={}
d1={}
for i in range(0,a):
d[l1[i]]=i
for i in range(0,a):
d1[l2[i]]=i
l={}
for i in d.keys():
m=(d[i]-d1[i])%a
if m in l.keys():
l[m]+=1
else:
l[m]=1
print(max(l.values())) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using bigint = int64_t;
const int MOD = 1000000007;
void io_set() {}
void solve() {
ll n, out = 0;
cin >> n;
map<ll, ll> mpp, ppm, ans;
ll a[n], b[n];
for (ll i = 0; i < n; i++) {
cin >> a[i];
mpp[a[i]] = i;
}
for (ll i = 0; i... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
loc = [ [-1,-1] for _ in range(n) ]
for i in range(n) :
loc[a[i]-1][0] = i
loc[b[i]-1][1] = i
lefta, righta = [0]*(n), [0]*(n)
leftb, rightb = [0]*(n), [0]*(n)
for i in loc :
if i[0]==i[1] :
lefta[0]+=... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdin
from collections import deque
# https://codeforces.com/contest/1354/status/D
mod = 10**9 + 7
import sys
import random
# sys.setrecursionlimit(10**6)
from queue import PriorityQueue
# def rl():
# return [int(w) for w in stdin.readline().split()]
from bisect import bisect_right
from bisect impor... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
import java.io.*;
public class B{
public static void main(String[] args)
{
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = fs.nextInt();
int[] posb = new int[n+1];
int[] a = fs.readArray(n);
for(int i=0;i<n;i++)
{
int aa = fs.nextIn... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
int ar[200004];
int main() {
int t, n, m, a, row[100], col[100];
map<int, int> mp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
mp[a] = i;
}
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a;
t = ((mp[a] + n - i) % n);
ar[t]++;
mx... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from sys import stdin,stdout
for _ in range(1):
n=int(stdin.readline())
a=list(map(int,stdin.readline().split()))
b=list(map(int,stdin.readline().split()))
d={};ib={}
for i in range(n):
ib[b[i]]=i
for i in range(n):
shift=(i-ib[a[i]]+n)%n
d[shift]=d.get(shift,0)+1
pri... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | n = int (input())
a = list(map (int, input().split()))
b = list(map (int, input().split()))
for i in range (n):
a[i] -= 1
b[i] -= 1
q = [0] * n
for i in range (n):
q[a[i]] = i
res = 0
cnt = [0] * n
for i in range (n):
cnt[(i - q[b[i]] + n) % n] += 1
print (max (cnt)) |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int INF = 1e9 + 10;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> c(n + 1, 0), d(n + 1, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
c[x]... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.io.*;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class C {
long INF = Long.MAX_VALUE; // "Бесконечность"
public static void main(String[] args) throws IOException {
new C().run();
}
... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | def result(n, a, b):
vec = [0 for _ in range(n)]
l = [0 for _ in range(n)]
for i, el in enumerate(a):
vec[el-1] = i
for i, el in enumerate(b):
l[(vec[el-1] - i)%n] += 1
return max(l)
n = int(input())
a = list(map(lambda x: int(x), input().split(' ')))
b = list(map(lambda x: int(x), ... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | #!/usr/bin/env python3
import io
import os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_str():
return input().decode().strip()
def rint():
return map(int, input().split())
def oint():
return int(input())
n = oint()
a = list(rint())
b = list(rint())
a_dict = dict()
for i, aa in e... |
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d={}
for i in range(n):
d[a[i]]=i
for i in range(n):
k=d[b[i]]-i
if k>=0:
c.append(k)
else:
c.append(k+n)
print(Counter(c).most_common(1)[0][1])
|
Problem: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b.
Note that a permutation of n elements is a sequence of numbers a_1, a_2, …,... | import java.util.*;
// scanner.nextInt();
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] array = new int[n+1];
int[] array_2 = new int[n+1];
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.