input
stringlengths 20
127k
| target
stringlengths 20
119k
| problem_id
stringlengths 6
6
|
---|---|---|
import itertools
n = int(eval(input()))
p = input().replace(' ', '')
q = input().replace(' ', '')
for i, num in enumerate(itertools.permutations(list(range(1,n+1)))):
num = ''.join(map(str, list(num)))
if num == p:
break
for j, num in enumerate(itertools.permutations(list(range(1,n+1)))):
num = ''.join(map(str, list(num)))
if num == q:
break
print((abs(i-j)))
|
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
N = list(itertools.permutations(list(range(1, n+1))))
def f(val):
for i, x in enumerate(N):
if x == val:
return i+1
print((abs(f(p) - f(q))))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
# Nが10程度で小さい
# 階乗の全探索をしても間に合う
# Pythonならitertoolsが使える
# permutations(関数)にlistを渡すと、順列を生成!
l = [i for i in range(1, N+1)]
permutations_l = list(itertools.permutations(l))
a, b = 0, 0
for i, R in enumerate(permutations_l):
if R == P: a = i
for i, R in enumerate(permutations_l):
if R == Q: b = i
print((abs(a-b)))
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
# Nが10程度で小さい
# 階乗の全探索をしても間に合う
# Pythonならitertoolsで順列を生成できる!
l = [i for i in range(1, N+1)]
permutations_l = list(itertools.permutations(l))
a, b = 0, 0
for i, R in enumerate(permutations_l):
if R == P: a = i
if R == Q: b = i
print((abs(a-b)))
|
p02813
|
import sys
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
last = [n-1 for i in range(n)]
a,b = 0,0
l = [i+1 for i in range(n)]
if l == p:
a = 1
if l == q:
b = 1
if a == b == 1:
print((0))
sys.exit()
cnt = 1
while True:
cnt += 1
for i in range(n-1,-1,-1):
if l[i] < l[i-1]:
continue
else:
obj = l[i-1]
tmp = sorted(l[i-1:])
switch = tmp.pop(tmp.index(obj)+1)
l = l[:i-1] + [switch] + sorted(tmp)
#print(l)
break
if l == p:
a = cnt
if l == q:
b = cnt
if a != 0 and b != 0:
break
print((abs(a-b)))
|
import itertools
n = int(eval(input()))
p = "".join(list(map(str, input().split())))
q = "".join(list(map(str, input().split())))
l = "".join([str(i+1) for i in range(n)])
cnt = 0
a,b = 0,0
for x in itertools.permutations(l):
y = "".join(x)
cnt += 1
if y == p:
a = cnt
if y == q:
b = cnt
if a != 0 and b != 0:
break
print((abs(a-b)))
|
p02813
|
def main():
n=int(eval(input()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
fact = [1]
for i in range(1,9):
fact.append(i*fact[i-1])
tmp = []
for i in range(n):
tmp.append(i+1)
i=0
ansp = caldict(fact,i,p,tmp)
tmp = []
for i in range(n):
tmp.append(i+1)
i=0
ansq = caldict(fact,i,q,tmp)
print((abs(ansp-ansq)))
def caldict(f,i,p,tmp):
if i < len(p)-1:
nowi = tmp.index(p[i])
now = tmp.pop(nowi)
i+=1
return nowi * f[len(tmp)] + caldict(f,i,p,tmp)
else:
return 1
if __name__=='__main__':
main()
|
import itertools
def main():
n=int(eval(input()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
perm = list(itertools.permutations(list(range(1,n+1))) )
ansp = perm.index(tuple(p))
# qq = list(itertools.permutations(q) )
ansq = perm.index(tuple(q))
print((abs(ansp-ansq)))
if __name__=='__main__':
main()
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
A = [i for i in range(1,N+1)]
count = 1
for i in itertools.permutations(A):
flg = True
for k in range(N):
if i[k] != P[k]:
flg = False
break
if flg:
a = count
flg = True
for k in range(N):
if i[k] != Q[k]:
flg = False
break
if flg:
b = count
count += 1
print((abs(a-b)))
|
import itertools
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
a = [i for i in range(1,N+1)]
cnt = 0
ans_a, ans_b = 0, 0
for target in itertools.permutations(a):
cnt += 1
if list(target) == P:
ans_a = cnt
if list(target) == Q:
ans_b = cnt
print((abs(ans_a-ans_b)))
|
p02813
|
import itertools
n = int(eval(input()))
a = tuple(i for i in range(1, n+1))
x = tuple(map(int, input().split()))
y = tuple(map(int, input().split()))
for i, z in enumerate(tuple(itertools.permutations(a))):
if z == x:
x_count = i
if z == y:
y_count = i
print((abs(x_count - y_count)))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
comb = sorted(list(permutations([i for i in range(1, N+1)], N)))
print((abs((comb.index(P) + 1) - (comb.index(Q) + 1))))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(itertools.permutations(list(range(1, N + 1))))
Pi, Qi = -1, -1
for i in range(len(LUT)):
if LUT[i] == P:
Pi = i
if LUT[i] == Q:
Qi = i
print((abs(Qi - Pi)))
|
from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
LUT = list(permutations(list(range(1, N + 1)))).index
print((abs(LUT(P) - LUT(Q))))
|
p02813
|
import itertools
N=int(eval(input()))
P,Q=[tuple(map(int,input().split())) for i in range(2)]
dictionary=sorted(itertools.permutations(P,N))
print((abs(dictionary.index(P)-dictionary.index(Q))))
|
import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
count=0
a=0
b=0
for i in itertools.permutations(list(range(1,n+1))):
count+=1
if i == p:
a=count
if i==q:
b=count
print((abs((count-a)-(count-b))))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a = b = cnt = 0
R = []
for i in range(1,N+1):
R.append(i)
for permutation in itertools.permutations(R):
cnt += 1
if permutation == P:
a = cnt
if permutation == Q:
b = cnt
ans = abs(a-b)
print(ans)
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
L = list(itertools.permutations(list(range(1, N+1))))
ans = abs(L.index(P)-L.index(Q))
print(ans)
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
seq = [x for x in range(1,N+1)]
L = list(itertools.permutations(seq))
for i in range(len(L)):
X = list(L[i])
if X == P:
a = i + 1
if X == Q:
b = i + 1
ans = abs(a-b)
print(ans)
|
import itertools
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
A = list(itertools.permutations(list(range(1,N+1))))
ans = abs(A.index(P) - A.index(Q))
print(ans)
|
p02813
|
from itertools import permutations
from collections import defaultdict
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
res = 0
loop = 0
d = defaultdict(int)
for perm in permutations(list(range(1,N+1))):
d[perm] = loop
loop += 1
res = abs(d[P] - d[Q])
print(res)
|
from itertools import *
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
dic = dict()
i = 0
for a in permutations(list(range(1,N+1)),N):
dic[a] = i
i += 1
print((abs(dic[P]-dic[Q])))
|
p02813
|
import itertools
N = int(eval(input()))
P = int(input().replace(' ', ''))
Q = int(input().replace(' ', ''))
s = [i for i in range(1, N + 1)]
l = list(itertools.permutations(s))
j = []
for i in range(len(l)):
t = list(map(str,l[i]))
j.append(int(''.join(t)))
nl = sorted(j)
a = 0
b = 0
for i in range(len(nl)):
if nl[i] == P:
a = i + 1
if nl[i] == Q:
b = i + 1
print((abs(a -b)))
|
import itertools
N = int(eval(input()))
P = int(input().replace(' ', ''))
Q = int(input().replace(' ', ''))
l = [i for i in range(1, N+1)]
pl = itertools.permutations(l)
lis = []
for oc in pl:
lis.append(int(''.join(map(str, list(oc)))))
lis.sort()
a = lis.index(P)
b = lis.index(Q)
print((abs(a - b)))
|
p02813
|
import itertools
N = int(eval(input()))
a = list(itertools.permutations(list(range(1, N+1))))
s = []
for i in a:
ans = ""
for j in i:
ans+=str(j)
s.append(ans)
P = "".join(list(input().split()))
Q = "".join(list(input().split()))
ans = abs((s.index(P)+1)-(s.index(Q)+1))
print(ans)
|
# abc150_c.py
'''
全パターン作ってソートで順番みる
'''
import itertools
N = int(eval(input()))
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
l = [i+1 for i in range(N)]
target = itertools.permutations(l)
cnt=0
pcnt = 0
qcnt = 0
for i in target:
cnt += 1
if i == P:
pcnt=cnt
if i == Q:
qcnt=cnt
print((abs(pcnt-qcnt)))
|
p02813
|
import math
def number(plist):
a = 1
memo = []
while len(plist) > 0:
p = plist.pop(0)
memo.append(p)
num = len(set(range(1, p)) - set(memo))
a += math.factorial(len(plist)) * num
return a
n = int(eval(input()))
plist = list(map(int, input().split()))
qlist = list(map(int, input().split()))
a = number(plist)
b = number(qlist)
print((int(math.fabs(a - b))))
|
import math
from itertools import permutations
def generate_permutations(n):
perms = permutations(list(range(1, n+1)), n)
return [perm for perm in perms]
n = int(eval(input()))
ptuple = tuple(map(int, input().split()))
qtuple = tuple(map(int, input().split()))
perms = generate_permutations(n)
a = perms.index(ptuple)
b = perms.index(qtuple)
print((int(math.fabs(a - b))))
|
p02813
|
from itertools import permutations
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
P = []
for perm in permutations(list(range(1, N + 1)), r=N):
P.append(tuple(perm))
P.sort()
print((abs(P.index(A) - P.index(B))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
X = [tuple(p) for p in permutations(list(range(1, N + 1)), r=N)]
X.sort()
print((abs(X.index(P) - X.index(Q))))
|
p02813
|
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools
# 標準入力を取得
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
# 求解処理
p = 0
q = 0
order = 1
for t in itertools.permutations(list(range(1, N + 1)), N):
if t == P:
p = order
if t == Q:
q = order
order += 1
ans = abs(p - q)
# 結果出力
print(ans)
|
# -*- coding: utf-8 -*-
# モジュールのインポート
import itertools
def get_input() -> tuple:
"""
標準入力を取得する.
Returns:\n
tuple: 標準入力
"""
# 標準入力を取得
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
return N, P, Q
def main(N: int, P: tuple, Q: tuple) -> None:
"""
メイン処理.
Args:\n
N (int): 数列の大きさ
P (tuple): 順列
Q (tuple): 順列
"""
# 求解処理
p = 0
q = 0
order = 1
for t in itertools.permutations(list(range(1, N + 1)), N):
if t == P:
p = order
if t == Q:
q = order
order += 1
ans = abs(p - q)
# 結果出力
print(ans)
if __name__ == "__main__":
# 標準入力を取得
N, P, Q = get_input()
# メイン処理
main(N, P, Q)
|
p02813
|
import itertools, sys
N = int(eval(input()))
N_list = [i for i in range(1, N+1)]
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A == B:
print('0')
sys.exit()
for v, i in enumerate(list(itertools.permutations(N_list))):
i = list(i)
if A == i:
a = v
elif B == i:
b = v
print((abs(a-b)))
|
import itertools
N = int(eval(input()))
N_list = [i for i in range(1, N+1)]
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
N_pattern = list(itertools.permutations(N_list))
print((abs(N_pattern.index(A) - N_pattern.index(B))))
|
p02813
|
import itertools
N = int(eval(input()))
N_list = [i for i in range(1, N+1)]
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
N_pattern = list(itertools.permutations(N_list))
print((abs(N_pattern.index(A) - N_pattern.index(B))))
|
import itertools
n = int(eval(input()))
ans = list(itertools.permutations(list(range(1,n+1))))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a = ans.index(P)
b = ans.index(Q)
print((abs(a-b)))
|
p02813
|
import itertools
n = int(eval(input()))
order = list(itertools.permutations([int(x)for x in range(1,n+1)]))
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
for i in range(len(order)):
if P == list(order[i]):
P_num = i
if Q == list(order[i]):
Q_num = i
print((abs(P_num-Q_num)))
|
import sys
import itertools
input = sys.stdin.readline
def slove():
n = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
"""
print(P)
print(Q)
"""
count = 0
for item in itertools.permutations(list(range(1,1+n))):
if P == item:
a = count
if Q == item:
b = count
count += 1
print((abs(a-b)))
if __name__ == "__main__":
slove()
|
p02813
|
import itertools
N=int(eval(input()))
candi=[str(i) for i in range(1,N+1)]
P="".join(input().split())
Q="".join(input().split())
count=0
#候補列挙
for j in itertools.permutations(candi,N):
k="".join(list(j))
count+=1
if k==P:
a=count
if k==Q:
b=count
print((abs(a-b)))
|
#Favorite Answers
from itertools import permutations
n=int(eval(input()))
p=tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
l = list(permutations(list(range(1,n+1))))
print((abs(l.index(p)-l.index(q))))
|
p02813
|
import itertools
n = int(eval(input()))
a = [ str(x) for x in range(1,n+1)]
jun = list(itertools.permutations(a))
p = list(map(str, input().split()))
q = list(map(str, input().split()))
p = ''.join(p)
q = ''.join(q)
a = []
for i in jun:
i = list(i)
a.append(''.join(i))
x = a.index(p)
y = a.index(q)
print((abs(x-y)))
|
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
t,h = 0,0
a = list(itertools.permutations(list(range(1,n+1))))
for i,c in enumerate(a):
if p == c:
t = i
if q == c:
h = i
print((abs(t-h)))
|
p02813
|
import itertools
N = int(eval(input()))
P = [int(x) for x in input().split()]
P = tuple(P)
Q = [int(x) for x in input().split()]
Q = tuple(Q)
N_ = list(range(1, N+1))
R = list(itertools.permutations(N_))
Pflg = Qflg = False
Pcnt = Qcnt = -1
for i, r in enumerate(R):
if P==r:
Pflg = True
Pcnt = i
if Q==r:
Qflg = True
Qcnt = i
if Pflg and Qflg:
break
print((abs(Pcnt - Qcnt)))
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
pmt = list(itertools.permutations(list(range(1, N+1))))
pmtP = pmt.index(P)
pmtQ = pmt.index(Q)
print((abs(pmtP - pmtQ)))
|
p02813
|
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = list(permutations(list(range(1, N + 1))))
ps.index(P)
print((abs(ps.index(Q) - ps.index(P))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
ps = permutations(list(range(1, N + 1)))
try:
x, y = [i for i, t in enumerate(ps) if t == P or t == Q]
except ValueError:
print((0))
else:
print((abs(x - y)))
|
p02813
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
val_list = [False for _ in range(pow(10, n))]
def make_val(suretsu):
val = 0
for index in range(n):
val += suretsu[n - index - 1] * pow(10, index)
return val
p_val = make_val(p)
q_val = make_val(q)
min_val = min(p_val, q_val)
max_val = max(p_val, q_val)
count = 0
counting = False
if min_val == max_val:
print((0))
else:
for suretsu in itertools.permutations(list(range(1, n+1))):
val = make_val(suretsu)
if val == min_val:
counting = True
if val == max_val:
break
if counting:
count += 1
print(count)
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
def make_val(suretsu):
val = 0
for index in range(n):
val += suretsu[n - index - 1] * pow(10, index)
return val
p_val = make_val(p)
q_val = make_val(q)
min_val = min(p_val, q_val)
max_val = max(p_val, q_val)
count = 0
counting = False
p_rank = 0
q_rank = 0
for suretsu in itertools.permutations(list(range(1, n+1))):
val = make_val(suretsu)
if val < p_val:
p_rank += 1
if val < q_val:
q_rank += 1
p_rank += 1
q_rank += 1
print((abs(p_rank-q_rank)))
|
p02813
|
import math
import itertools
n=int(eval(input()))
a=list(map(str,input().split()))
b=list(map(str,input().split()))
p=str(math.factorial(n))
a_list = [''.join(v) for v in itertools.permutations(a)]
a_int = [int(i) for i in a_list]
a_int.sort()
a_=[int(i) for i in a]
b_=[int(j) for j in b]
x="".join(a)
y="".join(b)
p_=a_int.index(int(x))+1
q_=a_int.index(int(y))+1
sum=abs(p_-q_)
print(sum)
|
import math
import itertools
n=int(eval(input()))
a=list(map(str,input().split()))
b=list(map(str,input().split()))
a_str = [''.join(v) for v in itertools.permutations(a)]
a_int = [int(i) for i in a_str]
a_int.sort()
x="".join(a)
y="".join(b)
p=a_int.index(int(x))+1
q=a_int.index(int(y))+1
print((abs(p-q)))
|
p02813
|
import itertools
N = int(eval(input()))
T = list(range(1,N+1))
S = list(itertools.permutations(T, N))
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
for i in range(len(S)):
if tuple(P) == S[i]:
A = i
if tuple(Q) == S[i]:
B = i
print((abs(A-B)))
|
import itertools
N = int(eval(input()))
T = list(range(1,N+1))
S = list(itertools.permutations(T, N))
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
A = S.index(tuple(P))
B = S.index(tuple(Q))
print((abs(A-B)))
|
p02813
|
import itertools
N = int(eval(input()))
PER = []
for i in range(N):
PER.append(i+1)
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
tmp = 1
for x in itertools.permutations(PER):
flag_a = 0
flag_b = 0
for i in range(N):
if x[i] == P[i]:
flag_a += 1
if x[i] == Q[i]:
flag_b += 1
if flag_b == N:
b = tmp
if flag_a == N:
a = tmp
tmp += 1
ans = a - b
if ans < 0:
ans = - ans
print(ans)
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
p = list(permutations(list(range(1,N+1))))
print((abs(p.index(P)-p.index(Q))))
|
p02813
|
import itertools
N=int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
a=0
b=0
index=0
for i in itertools.permutations(list(range(1,N+1)), N):
if P==list(i):
a=index
if Q==list(i):
b=index
index+=1
print((abs(b-a)))
|
import sys
input = sys.stdin.readline
def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))
def main():
mod=10**9+7
N=I()
P=LI()
Q=LI()
import itertools
cnt=0
p=0
q=0
for ite in itertools.permutations(list(range(1,N+1))):
if P==list(ite):
p=cnt
if Q==list(ite):
q=cnt
cnt+=1
print((abs(p-q)))
main()
|
p02813
|
def abc150_c_count_order():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
def solve(items, current):
if items == []:
permutations.append(current)
return
for item in items:
next = current + [item]
new_items = [i for i in items if i != item]
solve(new_items, next)
permutations = []
items = list(range(1, N+1))
current = []
solve(items, current)
a = permutations.index(P)
b = permutations.index(Q)
print((abs(a - b)))
##########
if __name__ == "__main__":
abc150_c_count_order()
|
def abc150_c_count_order_2():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
factorial = [1]
for i in range(1, N+1):
factorial.append(factorial[i-1] * i)
def find_index(permutation, lst):
indices = []
for p in permutation:
i = lst.index(p)
indices.append(i)
lst.pop(i)
# print(indices)
idx = 0
for i in range(N):
idx += factorial[N - i - 1] * (indices[i])
# print(idx)
return idx
a = find_index(P, list(range(1, N+1)))
b = find_index(Q, list(range(1, N+1)))
print((abs(a-b)))
##########
if __name__ == "__main__":
abc150_c_count_order_2()
|
p02813
|
N=int(eval(input()))
P=list(input().split())
Q=list(input().split())
P=int(''.join(P))
Q=int(''.join(Q))
n=[i for i in range(1,N+1)]
A=[]
def dps(n,A,me):
if len(n)==0:
A.append(me)
return
else:
for i in range(0, len(n)):
t=n.pop(i)
dps(n, A, me*10+t)
n.insert(i, t)
dps(n,A,0)
print((abs(A.index(P)-A.index(Q))))
|
N=int(eval(input()))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
import itertools
l=list(itertools.permutations([i for i in range(1, N+1)]))
print((abs(l.index(P)-l.index(Q))))
|
p02813
|
import itertools
N = int(eval(input()))
P_list = list(map(int, input().split()))
Q_list = list(map(int, input().split()))
for i, v in enumerate(itertools.permutations(list(range(1,N+1)))):
if list(v) == P_list:
a = i + 1
if list(v) == Q_list:
b = i + 1
print((abs(a-b)))
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
count = 1
for p in itertools.permutations(list(range(1, N+1))):
if p == P:
count_P = count
if p == Q:
count_Q = count
count += 1
ans = abs(count_P - count_Q)
print(ans)
|
p02813
|
# -*- coding: utf-8 -*-
from itertools import permutations
N = int(input().strip())
pat_P = [ "".join( input().rstrip().split() )][0]
pat_Q = [ "".join( input().rstrip().split() )][0]
#-----
perm_list = [ "".join( map(str, pat) ) for pat in permutations(list(range(1,N+1)))]
perm_list.sort()
a = perm_list.index(pat_P) + 1
b = perm_list.index(pat_Q) + 1
print((abs(a-b)))
|
# -*- coding: utf-8 -*-
from itertools import permutations
N = int(input().strip())
pat_P = tuple(map(int, input().rstrip().split()))
pat_Q = tuple(map(int, input().rstrip().split()))
#-----
perm_list = [ pat for pat in permutations(list(range(1,N+1)))]
a = perm_list.index(pat_P) + 1
b = perm_list.index(pat_Q) + 1
print((abs(a-b)))
|
p02813
|
import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
ls = list(itertools.permutations(list(range(1,n+1))))
print((abs(ls.index(p)-ls.index(q))))
|
import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
dict=list(itertools.permutations(list(range(1,n+1))))
print((abs(dict.index(p)-dict.index(q))))
|
p02813
|
import itertools
n=int(eval(input()))
p=tuple([int(i) for i in input().split()])
q=tuple([int(i) for i in input().split()])
x=list(itertools.permutations(list(range(1,n+1))))
nc=len(x)
for i in range(nc):
if x[i]==p:
pn=i
for j in range(nc):
if x[j]==q:
qn=j
print((abs(pn-qn)))
|
def main():
from itertools import permutations
import sys
input=sys.stdin.readline
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
cnt=1
for i in permutations(list(range(1,n+1))):
if i==p:
pi=cnt
if i==q:
qi=cnt
cnt+=1
print((abs(pi-qi)))
if __name__=='__main__':
main()
|
p02813
|
from collections import deque
n = int(eval(input()))
p_que = deque(list(map(int, input().split())))
q_que = deque(list(map(int, input().split())))
que = deque(i for i in range(1, n+1))
cnt = 0
a = 0
b = 0
def dfs(d, q):
# print('-'*10, q)
# sorted(q)
for i in list(q):
# print(i, d, q)
d.append(i)
q.remove(i)
# print('>', d, q)
if q == deque([]):
global cnt
cnt += 1
# print('>>>', cnt, d, q)
if d == p_que:
global a
a = cnt
if d == q_que:
global b
b = cnt
# print('return')
d.remove(i)
q.appendleft(i)
return
# print('tansaku')
dfs(d, q)
# print('>returned')
# print('---', i, d, q)
d.remove(i)
if i > q[0]:
q.append(i)
else:
q.appendleft(i)
q = deque(sorted(q))
dfs(deque(), que)
# print(a, b)
print((abs(a-b)))
|
from itertools import permutations
n = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
n_list = [x for x in range(1, n+1)]
# print(list(permutations(n_list, n)))
a = b = 0
for n, i in enumerate(permutations(n_list, n)):
# print(n, i)
if i == P:
a = n
if i == Q:
b = n
print((abs(a-b)))
|
p02813
|
from itertools import permutations
n=int(eval(input()))
P=list(map(str,input().split()))
Q=list(map(str,input().split()))
S=sorted(P)
S=list(permutations(S))
A=[]
for i in S:
A.append(int("".join(i)))
A.sort()
for i in range(len(A)):
if A[i]==int("".join(P)):
pp=i
if A[i]==int("".join(Q)):
qq=i
print((abs(pp-qq)))
|
from itertools import permutations
n=int(eval(input()))
P=list(input().split())
Q=list(input().split())
A=[]
for i in list(permutations(P)):
A.append(int("".join(i)))
A.sort()
print((abs(A.index(int("".join(P)))-A.index(int("".join(Q))))))
|
p02813
|
import itertools
import math
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
L = list(map(list,list(itertools.permutations(list(i for i in range(1,N+1)),N))))
a = L.index(P)
b = L.index(Q)
print((abs(a-b)))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
perm = list(permutations(list(range(1, N+1)), N))
print((abs(perm.index(P) - perm.index(Q))))
|
p02813
|
import sys
import itertools
import math
#import numpy as np
stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip() # ignore trailing spaces
N = ri()
P = rl()
Q = rl()
L = []
for x in itertools.permutations(list(range(1, N+1))):
L.append(list(x))
a = 0
b = 0
for i in range(math.factorial(N)):
if L[i] == P:
a = i
if L[i] == Q:
b = i
print((abs(a-b)))
|
import sys
import itertools
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
P = tuple(lr())
Q = tuple(lr())
a = -1; b = -1
for i, x in enumerate(itertools.permutations(list(range(1, N+1)), N)):
if x == P:
a = i
if x == Q:
b = i
answer = abs(a-b)
print(answer)
|
p02813
|
import itertools
n = int(eval(input()))
ls = []
for i in range(1,n+1):
ls.append(i)
p = list(map(int,input().split()))
q = list(map(int,input().split()))
a = 0
b = 0
c = 1
for v in itertools.permutations(ls, n):
if list(v) == p:
a = c
if list(v) == q:
b = c
c += 1
print((abs(a-b)))
|
#ABC150C
import itertools
n = int(eval(input()))
ls = [i+1 for i in range(n)]
p = list(map(int,input().split()))
q = list(map(int,input().split()))
v = [ list(v) for v in itertools.permutations(ls, n)]
a, b = v.index(p), v.index(q)
print((abs(a-b)))
|
p02813
|
N = int(eval(input()))
P = [int(i) for i in input().split(' ')]
Q = [int(i) for i in input().split(' ')]
fact = [1] * 8
for i in range(1,8):
fact[i] = fact[i-1] * i
a = 0
remain = list(range(1,N+1))
for i , v in enumerate(P):
num = remain.index(v)
remain.remove(v)
a += num * fact[(N - i - 1)]
b = 0
remain = list(range(1,N+1))
for i , v in enumerate(Q):
num = remain.index(v)
remain.remove(v)
b += num * fact[(N - i - 1)]
print((abs(b-a)))
|
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
fact = [1] *(N+1)
for i in range(1,N+1):
fact[i] = fact[i-1] *i
a = 1
b = 1
P2 = sorted(P)
Q2 = sorted(Q)
for i,(p,q) in enumerate(zip(P,Q)):
a += P2.index(p)*fact[N-i-1]
b += Q2.index(q)*fact[N-i-1]
P2.remove(p)
Q2.remove(q)
print((abs(b-a)))
|
p02813
|
import itertools as i
eval(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
x=sorted(list(i.permutations(P)))
print((abs(-~x.index(P)--~x.index(Q))))
|
import itertools as i
eval(input())
f=lambda:tuple(map(int,input().split()))
P=f()
Q=f()
x=sorted(list(i.permutations(P)))
print((abs(-~x.index(P)--~x.index(Q))))
|
p02813
|
import itertools as i
eval(input())
f=lambda:tuple(map(int,input().split()))
P=f()
Q=f()
x=sorted(list(i.permutations(P)))
print((abs(-~x.index(P)--~x.index(Q))))
|
import itertools as i
f=lambda:tuple(map(int,input().split()))
x=list(i.permutations(list(range(1,int(eval(input()))+1))))
print((abs(-~x.index(f())--~x.index(f()))))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(int(i) for i in input().split())
Q = tuple(int(i) for i in input().split())
for i, n in enumerate(itertools.permutations(list(range(1, N+1)), N)):
if n == P:
a = i
if n == Q:
b = i
ans = abs(b - a)
print(ans)
|
import itertools
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
c = 0
for s in itertools.permutations(list(range(1, n+1)), n):
c += 1
if s == p:
a = c
if s == q:
b = c
ans = abs(a - b)
print(ans)
|
p02813
|
import itertools
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
li = [i+1 for i in range(n)]
# print(p)
# print(q)
i = 0
for elm in itertools.permutations(li):
#print(list(elm))
if list(elm) == p:
mm1 = i
if list(elm) == q:
mm2 = i
i+=1
print((abs(mm1-mm2)))
|
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
li = [i+1 for i in range(N)]
cnt = 0
for i in itertools.permutations(li):
if list(i) == P:
a = cnt
if list(i) == Q:
b = cnt
cnt += 1
print((abs(a-b)))
|
p02813
|
import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
l = [i+1 for i in range(n)]
r = list(itertools.permutations(l))
j = 0
flagp = True
flagq = True
while flagp:
if r[j] == p:
x = j+1
flagp = False
j += 1
j = 0
while flagq:
if r[j] == q:
y = j+1
flagq = False
j += 1
print((abs(y-x)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(input().split())
q = tuple(input().split())
# print(p)
# print(q)
l = [str(i+1) for i in range(n)]
cnt = 1
for v in permutations(l,n):
if p == v:
a = cnt
if q == v:
b = cnt
cnt += 1
print((abs(a-b)))
|
p02813
|
from itertools import permutations
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = sorted(P)
cnt = 0
for x in permutations(A,N):
x = list(x)
if x==P:
a = cnt
if x==Q:
b = cnt
cnt += 1
print((abs(a-b)))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(list(map(int,input().split())))
Q = tuple(list(map(int,input().split())))
cnt = 0
for x in permutations(list(range(1,N+1)),N):
if P==x:
indP = cnt
if Q==x:
indQ = cnt
cnt += 1
print((abs(indP-indQ)))
|
p02813
|
import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
o=0
h=0
u=list(itertools.permutations(list(range(1,n+1))))
for i in range(len(u)):
if u[i]==p:
h=i
for i in range(len(u)):
if u[i]==q:
o=i
print((abs(h-o)))
|
import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
o=0
h=0
u=list(itertools.permutations(list(range(1,n+1))))
for i in range(len(u)):
if u[i]==p:
h=i
if u[i]==q:
o=i
print((abs(h-o)))
|
p02813
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
def main():
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = sorted(list(itertools.permutations(list(range(1,n+1)), n)))
ans = []
for i in range(len(l)):
if l[i] == p:
ans.append(i)
elif l[i] == q:
ans.append(i)
if len(ans) == 1:
print((0))
else:
print((abs(ans[0]-ans[1])))
if __name__=="__main__":
main()
|
import math
from math import gcd
INF = float("inf")
import sys
input=sys.stdin.readline
import itertools
def main():
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = list(itertools.permutations(list(range(1,n+1))))
print((abs(l.index(p) - l.index(q))))
if __name__=="__main__":
main()
|
p02813
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
if per == p:
x = i
if per == q:
y = i
print((abs(x-y)))
|
from itertools import *
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
a = [i+1 for i in range(n)]
for i,per in enumerate(list(permutations(a))):
if per == p:
x = i
if per == q:
y = i
print((abs(x-y)))
|
p02813
|
from collections import deque
def solve(N, P, Q):
stack = deque()
vals = [i for i in range(1, N + 1)]
for idx, next_val in enumerate(vals):
stack.append([[next_val], vals[: idx] + vals[idx + 1:]])
a, b = -1, -1
counter = 0
while stack:
cur_list, rest = stack.popleft()
if not rest:
counter += 1
a = counter if cur_list == P else a
b = counter if cur_list == Q else b
if 0 < a and 0 < b:
print((abs(a - b)))
return
for idx, next_val in enumerate(rest):
stack.append([cur_list + [next_val], rest[: idx] + rest[idx + 1:]])
if __name__ == "__main__":
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
solve(N, P, Q)
|
from itertools import permutations
def solve(N, P, Q):
vals = [i for i in range(1, N + 1)]
perms = list(permutations(vals))
print((abs(perms.index(P) - perms.index(Q))))
if __name__ == "__main__":
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
solve(N, P, Q)
|
p02813
|
# -*- coding: utf-8 -*-
"""
Created on Thu May 7 03:09:14 2020
@author: Kanaru Sato
"""
import itertools as it
n = int(eval(input()))
l = []
for i in range(1,n+1):
l.append(i)
p = list(map(int, input().split()))
q = list(map(int, input().split()))
count = 0
for sequence in it.permutations(l,n):
if list(sequence) == p:
pnum = count
if list(sequence) == q:
qnum = count
count += 1
print((abs(pnum-qnum)))
|
# -*- coding: utf-8 -*-
"""
Created on Sun May 17 19:16:09 2020
@author: Kanaru Sato
"""
import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
nums = [i+1 for i in range(n)]
count = 0
for perm in itertools.permutations(nums):
count += 1
if p == perm:
pcount = count
if q == perm:
qcount = count
print((abs(pcount-qcount)))
|
p02813
|
from itertools import permutations
n = int(eval(input()))
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
a = 0
b = 0
cnt = 0
st = 0
for i in permutations(list(range(1,n+1))):
cnt += 1
if list(i) == p:
a = cnt
st += 1
if list(i) == q:
b = cnt
st += 1
if st == 2:
break
print((abs(a-b)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
a = 0
b = 0
cnt = 0
st = 0
for i in permutations(list(range(1,n+1))):
cnt += 1
if i == p:
a = cnt
st += 1
if i == q:
b = cnt
st += 1
if st == 2:
break
print((abs(a-b)))
|
p02813
|
# -*- coding:utf-8 -*-
import copy
def solve():
N = int(eval(input()))
Ps = tuple(map(int, input().split()))
Qs = tuple(map(int, input().split()))
available_list = [i for i in range(1, N+1)]
permutations = [] # 順列
def _dfs(rest_list, p):
if len(rest_list) == 0:
permutations.append(tuple(p))
return
for i in range(1, N+1):
if i in rest_list:
tmp_rest_list = copy.deepcopy(rest_list)
tmp_rest_list.remove(i)
tmp_p = copy.deepcopy(p)
tmp_p.append(i)
_dfs(tmp_rest_list, tmp_p)
_dfs(available_list, [])
permutations.sort()
for i, p in enumerate(permutations):
if p == Ps:
a = i+1
if p == Qs:
b = i+1
print((abs(a-b)))
if __name__ == "__main__":
solve()
|
# -*- coding:utf-8 -*-
# https://atcoder.jp/contests/abc150/tasks/abc150_c
def solve():
import itertools
import bisect
N = int(eval(input()))
Ps = tuple(map(int, input().split()))
Qs = tuple(map(int, input().split()))
lst = [i for i in range(1, N+1)]
origins = list(itertools.permutations(lst, r=N))
origins.sort()
for i, p in enumerate(origins):
if p == Ps:
a = i
if p == Qs:
b = i
print((abs(a-b)))
if __name__ == "__main__":
solve()
|
p02813
|
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
from collections import deque
tuples=[]
def f(que):
if len(que)==n:
tuples.append(tuple(que))
return
for v in range(1,n+1):
if v not in que:
que.append(v)
f(que)
que.pop()
f(deque([]))
#print(tuples)
#print(tuples.index(p))
#print(tuples.index(q))
print((abs(tuples.index(p)-tuples.index(q))))
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a,b = 0,0
for i, perm in enumerate(itertools.permutations(list(range(1, N+1))), 1):
if P==perm:
a = i
if Q==perm:
b = i
if a > 0 and b > 0:
print((abs(a-b)))
exit()
|
p02813
|
import itertools
N = int(eval(input()))
P = "".join(input().split())
Q = "".join(input().split())
# print(P)
p_index = -1
q_index = -1
permutation_list = list(itertools.permutations([x + 1 for x in range(N)]))
# print(permutation_list)
for i in range(len(permutation_list)):
# print(permutation_list[i])
param = "".join(map(str, permutation_list[i]))
if P == param:
p_index = i
if Q == param:
q_index = i
if p_index != -1 and q_index != -1:
result = p_index - q_index
if result < 0:
result = -result
print(result)
exit(0)
|
import itertools
N = int(eval(input()))
P = "".join(input().split())
Q = "".join(input().split())
p_index = -1
q_index = -1
permutation_list = list(itertools.permutations([x + 1 for x in range(N)]))
for i in range(len(permutation_list)):
param = "".join(map(str, permutation_list[i]))
if P == param:
p_index = i
if Q == param:
q_index = i
if p_index != -1 and q_index != -1:
print((abs(p_index - q_index)))
exit(0)
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = [i for i in range(1, N+1)]
a = 0
b = 0
#順列作成
L_list = list(itertools.permutations(L))
for i in range(len(L_list)):
if list(L_list[i]) == P:
a = i+1
for i in range(len(L_list)):
if list(L_list[i]) == Q:
b = i+1
# else:
# continue
print((abs(a-b)))
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = [i for i in range(1, N+1)]
a = 0
b = 0
#順列作成
L_list = list(itertools.permutations(L))
for i in range(len(L_list)):
if list(L_list[i]) == P:
a = i+1
if list(L_list[i]) == Q:
b = i+1
print((abs(a-b)))
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
L = [i for i in range(1, N+1)]
a = 0
b = 0
#順列作成
L_list = list(itertools.permutations(L))
for i in range(len(L_list)):
if list(L_list[i]) == P:
a = i+1
if list(L_list[i]) == Q:
b = i+1
print((abs(a-b)))
|
#パクリ
import itertools
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
lis=list(itertools.permutations(P))
lis.sort()
#indexで要素の何番目か取得
print((abs(lis.index(P)-lis.index(Q))))
|
p02813
|
import itertools
import math
n = int(eval(input()))
p = list(map(int, input().split()))
d = list(map(int, input().split()))
a = list(itertools.permutations(list(range(1,n+1))))
b = []
for i in range(1,len(a)+1):
b.append(i)
it = itertools.zip_longest(b, a)
for i in it:
if p != d:
if p == list(i[1]):
pcount = int(i[0])
elif d == list(i[1]):
dcount = int(i[0])
else:
pcount = 0
dcount = 0
print((abs(pcount-dcount)))
|
import itertools
import math
n = int(eval(input()))
p = list(map(int, input().split()))
d = list(map(int, input().split()))
a = list(itertools.permutations(list(range(1,n+1))))
b = []
for i in range(1,len(a)+1):
b.append(i)
it = itertools.zip_longest(b, a)
pcount = 0
dcount = 0
for i in it:
if p != d:
if p == list(i[1]):
pcount = int(i[0])
if d == list(i[1]):
dcount = int(i[0])
print((abs(pcount-dcount)))
|
p02813
|
#!/usr/bin/env python3
import sys
import itertools
import bisect
def solve(N: int, P: "List[int]", Q: "List[int]"):
nums = [i for i in range(1, N + 1)]
perm = list(itertools.permutations(nums, N))
perm.sort()
p_at = 0
for i, pr in enumerate(perm):
if pr == tuple(P):
p_at = i + 1
if pr == tuple(Q):
q_at = i + 1
print((abs(p_at - q_at)))
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == "__main__":
main()
|
#!/usr/bin/env python3
import sys
import itertools
import bisect
def solve(N: int, P: "List[int]", Q: "List[int]"):
nums = [i for i in range(1, N + 1)]
perm = list(itertools.permutations(nums, N))
print((abs(perm.index(tuple(P)) - perm.index(tuple(Q)))))
return
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
Q = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
solve(N, P, Q)
if __name__ == "__main__":
main()
|
p02813
|
from itertools import permutations
n = int(eval(input()))
p = list(map(str, input().split()))
q = list(map(str, input().split()))
s = "".join(map(str, list(range(1, (n+1)))))
x = list(permutations(s))
x = [list(i) for i in x]
print((abs(x.index(p)-x.index(q))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
for i, X in enumerate(permutations(list(range(1, N + 1)), N)):
if P == X:
a = i
if Q == X:
b = i
print((abs(a - b)))
|
p02813
|
import itertools
s = 1
a = 0
b = 0
N = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == p:
a = s
s += 1
s = 1
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
for i in ite:
if list(i) == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
|
import itertools
N = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
ite = [x for x in range(1, N + 1)]
ite = itertools.permutations(ite)
a = 0
b = 0
s = 1
for i in ite:
if i == p:
a = s
if i == q:
b = s
s += 1
if a > b:
total = a - b
else:
total = b - a
print(total)
|
p02813
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
list_ = list(range(1, n + 1))
for num ,v in enumerate(itertools.permutations(list_, n)):
if p == list(v):
res_p = num + 1
for num ,v in enumerate(itertools.permutations(list_, n)):
if q == list(v):
res_q = num + 1
ans = abs(res_p - res_q)
print(ans)
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
list_ = list(range(1, n + 1))
for num ,v in enumerate(itertools.permutations(list_, n)):
if p == list(v):
res_p = num + 1
break
for num ,v in enumerate(itertools.permutations(list_, n)):
if q == list(v):
res_q = num + 1
break
ans = abs(res_p - res_q)
print(ans)
|
p02813
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
list_ = list(range(1, n + 1))
for num ,v in enumerate(itertools.permutations(list_, n)):
if p == list(v):
res_p = num + 1
break
for num ,v in enumerate(itertools.permutations(list_, n)):
if q == list(v):
res_q = num + 1
break
ans = abs(res_p - res_q)
print(ans)
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
list_ = list(range(1, n + 1))
def turn_num(list_num, arr, m):
for num ,v in enumerate(itertools.permutations(list_num, m)):
if arr == list(v):
res = num + 1
break
return res
ans = abs(turn_num(list_, p, n) - turn_num(list_, q, n))
print(ans)
|
p02813
|
N = int(eval(input()))
p1 = tuple(map(int,input().split()))
p2 = tuple(map(int,input().split()))
def dfs(pair=[]):
global lst
if len(pair) == N:
lst.append(tuple(pair))
else:
for j in range(1,N+1):
if j not in pair:
pair.append(j)
dfs(pair)
pair.pop()
lst = []
dfs()
lst.sort()
print((abs(lst.index(p1) - lst.index(p2))))
|
def LI():
return list(map(int, input().split()))
N = int(eval(input()))
P = LI()
Q = LI()
result = []
def permutations(N, cur):
if len(cur) == N:
result.append(cur)
return
for i in range(1, N+1):
if i not in cur:
permutations(N, cur+[i])
permutations(N,[])
result.sort()
print((abs(result.index(P) - result.index(Q))))
|
p02813
|
from itertools import permutations
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
a=sorted(list(permutations(p)))
print((abs(a.index(p)-a.index(q))))
|
from itertools import permutations
n=int(eval(input()))
p=tuple(input().split())
q=tuple(input().split())
a=sorted(list(permutations(p)))
print((abs(a.index(p)-a.index(q))))
|
p02813
|
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
import itertools
L = list(itertools.permutations([i for i in range(1, N + 1)]))
a = b = 1
for l in L:
if l == P:
break
a += 1
for l in L:
if l == Q:
break
b += 1
print((abs(a-b)))
|
n = int(eval(input()))
from itertools import *
l = list(permutations(list(range(1, n + 1)), n))
l.sort()
p = l.index(tuple(map(int, input().split())))
q = l.index(tuple(map(int, input().split())))
print((abs(p - q)))
|
p02813
|
import itertools,math
n = int(eval(input()))
a = sorted(list(itertools.permutations([ i for i in range(1,n+1)])))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
print((abs(a.index(p) - a.index(q))))
|
import itertools
n = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
L = list(itertools.permutations([i for i in range(1,n+1)]))
print((
abs((L.index(P)+1)-((L.index(Q)+1)))
))
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
num = 0
for v in list(itertools.permutations(list(range(1,N+1)))):
num += 1
if list(v) == P:
A = num
elif list(v) == Q:
B = num
else:
pass
try:
print((abs(A-B)))
except:
print((0))
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = B = 0
for i,v in enumerate(list(itertools.permutations(list(range(1,N+1)))), 1):
if list(v) == P:
A = i
elif list(v) == Q:
B = i
else:
pass
print((abs(A-B) if A != 0 and B != 0 else 0))
|
p02813
|
import bisect
N = int(eval(input()))
L = int(''.join([str(n) for n in range(1, N+1)]))
R = int(''.join([str(n) for n in range(1, N+1)][::-1]))
P = int(''.join(input().split()))
Q = int(''.join(input().split()))
C = [str(c) for c in range(1, N+1)]
A = []
for i in range(L, R+1):
flg = True
for c in C:
if c not in str(i):
flg = False
break
if flg:
A.append(i)
print((abs(bisect.bisect(A, P)-bisect.bisect(A, Q))))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(int(n) for n in input().split())
Q = tuple(int(n) for n in input().split())
a = [x for x in permutations(list(range(1,N+1)), N)]
print((abs(a.index(P)-a.index(Q))))
|
p02813
|
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
i = 1
for ptn in itertools.permutations(list(range(1,n+1))):
if list(ptn)==p:
a = i
if list(ptn)==q:
b = i
i += 1
print((abs(a-b)))
|
N = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
from itertools import permutations
l = list(permutations(list(range(1,N+1))))
print((abs(l.index(P) - l.index(Q))))
|
p02813
|
#python3
from itertools import permutations
n=int(eval(input()))
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
def f(lis):
cnt=0
for i in permutations(list(range(1,n+1))):
cnt+=1
if i == tuple(lis):
return cnt
print((abs(f(p)-f(q))))
|
def main():
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
from itertools import permutations
a = [i for i in range(1, n+1)]
o1 = -1
o2 = -1
cnt = 0
for i in permutations(a):
cnt += 1
if i == p:
o1 = cnt
if i == q:
o2 = cnt
ans = abs(o1-o2)
print(ans)
main()
|
p02813
|
def main():
n = int(eval(input()))
p = tuple(int(i) for i in input().split())
q = tuple(int(i) for i in input().split())
from itertools import permutations
a = [i for i in range(1, n+1)]
o1 = -1
o2 = -1
cnt = 0
for i in permutations(a):
cnt += 1
if i == p:
o1 = cnt
if i == q:
o2 = cnt
ans = abs(o1-o2)
print(ans)
main()
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import permutations
def main():
n = int(readline())
p = tuple([int(i) for i in readline().split()])
q = tuple([int(i) for i in readline().split()])
num = [i for i in range(1, n+1)]
c1 = 0
c2 = 0
cnt = 0
for perm in permutations(num):
cnt += 1
if perm == p:
c1 = cnt
if perm == q:
c2 = cnt
print((abs(c1-c2)))
if __name__ == '__main__':
main()
|
p02813
|
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import permutations as perm
n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
lst = list(perm(list(range(1, n+1)),n))
lst.sort()
pn=qn=0
for i,j in enumerate(lst, 1):
if p == j:
pn = i
if q == j:
qn = i
if pn*qn!=0:
break
print((abs(pn-qn)))
|
from itertools import permutations as perm
import sys
readline = sys.stdin.buffer.readline
n = int(readline())
p = tuple(map(int, readline().split()))
q = tuple(map(int, readline().split()))
p_lst = list(perm(list(range(1, n + 1)), n)) # 排列
pn = qn = 0
for i,j in enumerate(p_lst, 1):
if p == j:
pn = i
if q == j:
qn = i
if pn * qn != 0:
break
print((abs(pn - qn)))
|
p02813
|
N = int(eval(input()))
def factorial(num):
if num == 1:
return 1
return num * factorial(num - 1)
def count_order(group):
numbers = [i for i in range(1, N + 1)]
res = 1
for i in range(len(group) - 1):
num = group[i]
res += numbers.index(num) * pattern[-(i + 1)]
numbers.pop(numbers.index(num))
return res
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
pattern = [factorial(i) for i in range(1, N)]
res_p = count_order(P)
res_q = count_order(Q)
print((abs(res_p - res_q)))
|
from itertools import permutations
n = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
comb = list(permutations([i for i in range(1, n + 1)]))
comb.sort()
a = 0
b = 0
for i in range(len(comb)):
if list(comb[i]) == P:
a = i
if list(comb[i]) == Q:
b = i
ans = abs(a - b)
print(ans)
|
p02813
|
from itertools import permutations
N = int(eval(input()))
P, Q = input().replace(' ', ''), input().replace(' ', '')
a = b = x = 0
for d in permutations(''.join(map(str, list(range(1, N+1)))), N):
x += 1
s = ''.join(d)
if s == P:
a = x
if s == Q:
b = x
print((abs(a - b)))
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
i = a = b = 0
for x in permutations(list(range(1, N+1)), N):
i += 1
if x == P:
a = i
if x == Q:
b = i
print((abs(a - b)))
|
p02813
|
import itertools
n = int(eval(input()))
p = tuple(list(map(int, input().split())))
q = tuple(list(map(int, input().split())))
po = 0
qo = 0
l = sorted(list(itertools.permutations(list(range(1,n+1)))))
for i in range(len(l)):
if l[i] == p:
po = i
if l[i]== q:
qo = i
print((abs(po-qo)))
|
import itertools
n = int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
l = sorted(itertools.permutations([i for i in range(1,n+1)]))
print((abs(l.index(tuple(p))-l.index(tuple(q)))))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
Nlist = []
for i in range(N):
Nlist.append(i+1)
J = list(itertools.permutations(Nlist, N))
count = 0
for i in range(len(J)):
if J[i] == P:
a = i+1
count += 1
if count == 2:
break
if J[i] == Q:
b = i+1
count += 1
if count == 2:
break
print((abs(a-b)))
|
import itertools
def LI():
return tuple(map(int, input().split()))
N = int(eval(input()))
P = LI()
Q = LI()
Nlist = list(range(1, N+1))
count = 1
for v in itertools.permutations(Nlist, N):
if P == v:
p = count
if Q == v:
q = count
count += 1
print((abs(p-q)))
|
p02813
|
import math
def calc_order(A, N):
l = [i + 1 for i in range(N)]
order = 1
for i in range(N):
a = A[i]
len_l = len(l)
index = l.index(a)
# print(a, index, math.factorial(len_l - 1), order)
order += index * math.factorial(len_l - 1)
del l[index]
return order
def main():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
ord_p = calc_order(P, N)
ord_q = calc_order(Q, N)
ans = abs(ord_p - ord_q)
# print(ord_p, ord_q)
print(ans)
if __name__ == '__main__':
main()
|
def factorial(n):
ret = 1
for i in range(n):
ret *= (i + 1)
return ret
def calc_order(A, N):
l = [i + 1 for i in range(N)]
order = 1
for i in range(N):
a = A[i]
len_l = N - i
index = l.index(a)
# print(a, index, factorial(len_l - 1), order)
order += index * factorial(len_l - 1)
del l[index]
return order
def main():
N = int(eval(input()))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
ord_p = calc_order(P, N)
ord_q = calc_order(Q, N)
ans = abs(ord_p - ord_q)
# print(ord_p, ord_q)
print(ans)
if __name__ == '__main__':
main()
|
p02813
|
import itertools
N = int(eval(input()))
P = [int(a)-1 for a in input().split()]
Q = [int(a)-1 for a in input().split()]
i = 0
ans = 0
for a in itertools.permutations(list(range(N)), N):
a = [b for b in a]
if a == P:
ans -= i
if a == Q:
ans += i
i += 1
print((abs(ans)))
|
fact = [1]
for i in range(20):
fact.append(fact[-1] * (i+1))
def calc(L):
n = len(L)
if n == 1: return 0
a = len([l for l in L if l < L[0]])
return a * fact[n-1] + calc(L[1:])
N = int(eval(input()))
P = [int(a)-1 for a in input().split()]
Q = [int(a)-1 for a in input().split()]
print((abs(calc(P) - calc(Q))))
|
p02813
|
import itertools
N=int(eval(input()))
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
K=list(itertools.permutations(list(range(1,N+1))))
print((abs(K.index(a)-K.index(b))))
|
import itertools as it
N=int(eval(input()))
W=list(range(1,N+1))
c1=-1
c2=-1
c=0
L=tuple(map(int,input().split()))
M=tuple(map(int,input().split()))
if L==M:
print((0))
exit()
for i in it.permutations(W,N):
c+=1
if i==L:
c1=c
elif i==M:
c2=c
print((abs(c1-c2)))
|
p02813
|
import collections
n = int(input())
p = list(map(int,input().split(' ')))
q = list(map(int,input().split(' ')))
elems = list(range(1, n+1))
res = []
c = [0]
def perms(i, elems,res):
if i == len(elems):
res.append(tuple(elems))
return
for j in range(i, len(elems)):
elems[j], elems[i] = elems[i], elems[j]
perms(i+1, elems, res)
elems[j], elems[i] = elems[i], elems[j]
perms(0, elems, res)
tp = tuple(p)
tq = tuple(q)
res.sort()
for i in range(len(res)):
if res[i] == tp:
ii = i
if res[i] == tq:
jj = i
print(abs(jj - ii))
|
import collections
n = int(input())
p,q = list(map(int,input().split(' '))), list(map(int,input().split(' ')))
res = []
def perms(i, elems,res):
if i == len(elems):
res.append(tuple(elems))
return
for j in range(i, len(elems)):
elems[j], elems[i] = elems[i], elems[j]
perms(i+1, elems, res)
elems[j], elems[i] = elems[i], elems[j]
perms(0, list(range(1, n+1)), res)
tp,tq = tuple(p),tuple(q)
res.sort()
for i in range(len(res)):
if res[i] == tp: ii = i
if res[i] == tq: jj = i
print(abs(jj - ii))
|
p02813
|
#<C>
import math
import itertools
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
ans1=n
ans2=n
x = [i for i in range(1, n+1)]
for i in itertools.permutations(x,n):
if p < list(i):
ans1 -= 1
if q < list(i):
ans2 -= 1
print((abs(ans1-ans2)))
|
#<順列全探索>
#n!通りの順列の組み合わせを全探索する方法。
#pythonにはitertoolsが存在するからそれを利用
#<ex.1(ABC150-C)>
import itertools
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
ls = list(itertools.permutations(list(range(1, n + 1)))) #順列作成
print((abs(ls.index(p) - ls.index(q))))
|
p02813
|
#abc150c
from itertools import *
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=list(permutations(list(range(1,n+1))))
print((abs(l.index(p)-l.index(q))))
|
#abc150c
from itertools import *
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=list(permutations(list(range(1,n+1))))
print(abs(l.index(p)-l.index(q)))
|
p02813
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
for i, pat in enumerate(permutations(list(range(1, n + 1)), n)):
if pat == p:
a = i + 1
if pat == q:
b = i + 1
print((abs(a - b)))
|
from itertools import permutations
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
for i, pat in enumerate(permutations(list(range(1, n + 1)), n)):
if pat == p:
a = i
if pat == q:
b = i
ans = abs(a - b)
print(ans)
|
p02813
|
from itertools import permutations
stdin = open(0).read().split('\n')
N = int(stdin[0])
P=int("".join(list(stdin[1].split())))
Q=int("".join(list(stdin[2].split())))
l = []
for pp in permutations(list(range(1, N+1))):
ll = []
for _p in pp:
ll.append(str(_p))
l.append(int("".join(ll)))
a = l.index(P)
b = l.index(Q)
print((abs(a - b)))
|
def perm(N):
if N==0:return 0
a=1
for i in range(1,N+1):
a*=i
return a
def getposi(P):
N=len(P)
l=list(range(1,N+1))
a = 0
for i,num in enumerate(P):
a+=perm(N-i-1)*l.index(num)
l.remove(num)
return a
stdin = open(0).read().split('\n')
N = int(stdin[0])
P = list(map(int,stdin[1].split()))
Q = list(map(int,stdin[2].split()))
a=getposi(P)
b=getposi(Q)
print((abs(a-b)))
|
p02813
|
from itertools import permutations
n = int(eval(input()))
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
dict = {}
d = [i for i in range(1,n+1)]
i = 1
for x in permutations(d,n):
dict[x] = i
i += 1
print((abs(dict[P]-dict[Q])))
|
from itertools import permutations
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
a,b = -1,-1
for i,x in enumerate(permutations([i+1 for i in range(n)])):
c,d = True,True
for j in range(n):
if x[j] != p[j]:
c = False
if x[j] != q[j]:
d = False
if c:a = i+1
if d:b = i+1
print((abs(a-b)))
|
p02813
|
N=int(eval(input()))
P=list(map(int,input().split()))
ps=""
for i in range(N):
ps+=str(P[i])
Q=list(map(int,input().split()))
qs=""
for i in range(N):
qs+=str(Q[i])
stack=[]
stack.append("")
res=[]
while stack:
d=stack.pop()
if len(d)==N:
res.append(d)
continue
for i in range(1,N+1):
if str(i) not in d:
stack.append(d+str(i))
res=res[::-1]
a=0
b=0
for i in range(len(res)):
if res[i]==ps:
a=i+1
if res[i]==qs:
b=i+1
print((abs(a-b)))
|
import sys
readline = sys.stdin.readline
N = int(readline())
P = tuple(map(int,readline().split()))
Q = tuple(map(int,readline().split()))
import itertools
a = 0
b = 0
cnt = 0
for perm in itertools.permutations(list(range(1, N + 1))):
cnt += 1
if perm == P:
a = cnt
if perm == Q:
b = cnt
print((abs(a - b)))
|
p02813
|
import itertools
N = int(eval(input()))
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
n_list = [i for i in range(1,N+1)]
n_perm = sorted(list(itertools.permutations(n_list, N)))
a = 0
b = 0
for i in range(len(n_perm)):
if list(n_perm[i]) == P:
a = i
break
for k in range(len(n_perm)):
if list(n_perm[k]) == Q:
b = k
break
print((abs(a-b)))
|
import itertools
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=sorted(list(itertools.permutations(list(range(1,n+1)))))
print((abs(l.index(p)-l.index(q))))
|
p02813
|
from itertools import permutations
n=int(eval(input()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
c=sorted(list(permutations(list(range(1,n+1)))))
a,b,=0,0
for i,c in enumerate(c):
if p==list(c):
a=i
if q==list(c):
b=i
print((abs(a-b)))
|
from itertools import permutations
n=int(eval(input()))
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
P=sorted(list(permutations(list(range(1,n+1)),n)))
print((abs(P.index(p)-P.index(q))))
|
p02813
|
n = int(eval(input()))
p = list(map(int,input().split()))
q = list(map(int,input().split()))
import itertools
lst = [i+1 for i in range(n)]
l = [0]*len(lst)
for i in itertools.permutations(lst):
l.append(list(i))
for i in range(len(l)):
if p == l[i]:
a = i
if q == l[i]:
b = i
print((abs(b-a)))
|
from itertools import permutations as pm
n = int(eval(input()))
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
i = 0
for l in pm([i+1 for i in range(n)],n):
if l == p:
a = i
if l == q:
b = i
i += 1
print((abs(a-b)))
|
p02813
|
from itertools import permutations
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
perm = list(permutations(list(range(1, N + 1))))
print((abs(perm.index(P) - perm.index(Q))))
|
import sys
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
N = int(readline())
P = tuple(map(int, readline().split()))
Q = tuple(map(int, readline().split()))
perms = list(permutations(list(range(1, N + 1))))
print((abs(perms.index(P) - perms.index(Q))))
return
if __name__ == '__main__':
main()
|
p02813
|
import math
n=int(eval(input()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a=0
b=0
x=[i+1 for i in range(n)]
y=[i+1 for i in range(n)]
for i in range(n-1):
a+=x.index(p[i])*math.factorial(n-1-i)
b+=y.index(q[i])*math.factorial(n-1-i)
x.remove(p[i])
y.remove(q[i])
print((abs(a-b)))
|
import itertools
n=int(eval(input()))
p= list(map(int, input().split()))
q= list(map(int, input().split()))
x=[i+1 for i in range(n)]
x=list(itertools.permutations(x))
a=0
b=0
for i in range(len(x)):
if list(x[i])==p:
a=i
if list(x[i])==q:
b=i
print((abs(a-b)))
|
p02813
|
import itertools
n = int(eval(input()))
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))
num_list = []
num = 0
a = 0
b = 0
for i in itertools.permutations(list(range(1,n+1))):
num_list = list(i)
num += 1
if num_list == p_list:
a = num
if num_list == q_list:
b = num
print((abs(a-b)))
|
import itertools
n = int(eval(input()))
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
num_list = list(itertools.permutations(list(range(1,n+1))))
print((abs(num_list.index(p)-num_list.index(q))))
|
p02813
|
import itertools
def checkArrays(arr1, arr2):
if len(arr1) != len(arr2):
return False
for i in range(len(arr1)):
if arr1[i] != arr2[i]:
return False
return True
n = int(eval(input()))
arrays = list(itertools.permutations([i for i in range(1, n + 1)]))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
a = b = 1
for i in range(len(arrays)):
ar = list(arrays[i])
if checkArrays(ar, p):
a = i + 1
if checkArrays(ar, q):
b = i + 1
print((abs(a - b)))
|
import itertools
n = int(eval(input()))
array = [i for i in range(1, n + 1)]
gen_array = itertools.permutations(array, n)
a = list(map(int, input().split()))
b = list(map(int, input().split()))
idx = 1
for lis in gen_array:
if list(lis) == a:
num_a = idx
if list(lis) == b:
num_b = idx
idx += 1
print((abs(num_a - num_b)))
|
p02813
|
from sys import stdin
import math
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = list(map(int,stdin.readline().rstrip().split()))
from itertools import permutations
lis = permutations(li)
liv = []
for i in lis:
liv.append(list(i))
liv.sort()
a = liv.index(li)
b = liv.index(lin)
print((abs(a-b)))
|
from itertools import permutations
n = int(eval(input()))
li = [i for i in range(1,n+1)]
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
for i,j in enumerate(permutations(li)):
if j == p:
num_p = i
if j == q:
num_q = i
print((abs(num_p-num_q)))
|
p02813
|
import itertools
N = int(eval(input()))
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
A = [i for i in range(1, N+1)]
B = list(itertools.permutations(A))
ans = abs(B.index(P)-B.index(Q))
print(ans)
|
import itertools
N = int(eval(input()))
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
X = list(itertools.permutations(list(range(1, N+1))))
a = X.index(A)
b = X.index(B)
print((abs(a-b)))
|
p02813
|
n = int(input())
mxs, minm = 0, 1000
for i in range(n):
m, s = list(map(int, input().split()))
if s > mxs:
mxs = s
minm = m
elif s == mxs:
if m < minm:
minm = m
print(minm, mxs)
|
n = int(input())
mxs, minm = 0, 21
for i in range(n):
m, s = list(map(int, input().split()))
if s > mxs:
mxs = s
minm = m
elif s == mxs:
if m < minm:
minm = m
print(minm, mxs)
|
p00095
|
import bisect
n,m = list(map(int,input().split()))
xy = sorted([list(map(int,input().split())) + [i] for i in range(n)])
yx = sorted(xy, key = lambda x:x[1])
X = [i[0] for i in xy]
Y = [i[1] for i in yx]
xy = [str(i[0]) + "," + str(i[1]) + "_" + str(i[2]) for i in xy]
yx = [str(i[0]) + "," + str(i[1]) + "_" + str(i[2]) for i in yx]
ans = {}
for xi in range(n):
for xj in range(xi,n+1):
for yi in range(n):
for yj in range(yi,n+1):
ans[str(xi) + "_" + str(xj) + "_" + str(yi) + "_" + str(yj)] = len(set(xy[xi:xj])&set(yx[yi:yj]))
for i in range(m):
x1,y1,x2,y2 = list(map(int,input().split()))
x1 = bisect.bisect_left(X,x1)
y1 = bisect.bisect_left(Y,y1)
x2 = bisect.bisect_right(X,x2)
y2 = bisect.bisect_right(Y,y2)
try: print(ans[str(x1) + "_" + str(x2) + "_" + str(y1) + "_" + str(y2)])
except: print(0)
|
import bisect
inf = 1e10
n,m = list(map(int,input().split()))
xy = [list(map(int,input().split())) for i in range(n)]
X = sorted([i[0] for i in xy] + [-inf-1] + [inf+1])
Y = sorted([i[1] for i in xy] + [-inf-1] + [inf+1])
s = [[0]*(n+10) for i in range(n+10)]
for i in range(n):
a = bisect.bisect_left(X,xy[i][0])
b = bisect.bisect_left(Y,xy[i][1])
s[a][b] += 1
for i in range(n+2):
for j in range(n+2):
s[i+1][j+1] += s[i+1][j] + s[i][j+1] - s[i][j]
for i in range(m):
x1,y1,x2,y2 = list(map(int,input().split()))
x1 = bisect.bisect_left(X,x1) - 1
y1 = bisect.bisect_left(Y,y1) - 1
x2 = bisect.bisect_left(X,x2+1) - 1
y2 = bisect.bisect_left(Y,y2+1) - 1
print(s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1])
|
p01540
|
import sys
c=["light fly", "fly", "bantam", "feather", "light", "light welter",
"welter", "light middle", "middle", "light heavy", "heavy"]
w=[48,51,54,57,60,64,69,75,81,91]
for s in map(float,sys.stdin):
i=0
while i<len(w) and w[i]<s:
i+=1
print(c[i])
|
import sys
c=["light fly", "fly", "bantam", "feather", "light", "light welter",
"welter", "light middle", "middle", "light heavy", "heavy"]
w=[48,51,54,57,60,64,69,75,81,91]
for s in map(float,sys.stdin):
i=0
for e in w:
if e<s: i+=1
print(c[i])
|
p00048
|
import statistics
n=int(eval(input()))
a=list(map(int,input().split()))
num=round(statistics.mean(a))
print((sum([(num-i)**2 for i in a])))
|
eval(input());a=list(map(int,input().split()));r=float('inf')
for i in range(min(a),max(a)+1):
n=0
for j in a:
n+=(j-i)**2
r=min(n,r)
print(r)
|
p04031
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.