TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
n=int(input())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
seq=range(n)
l=list(itertools.permutations(seq))
#print(l[0])
a_num=0
b_num=0
for i in range(len(l)):
  if l[i]==a:
    a_num=i
  elif l[i]==b:
    b_num=i
print(abs(a_num-b_num))

import itertools
n=int(input()
a=map(int,input().split())
b=map(int,input().split())
seq=range(n)
list(itertools.permutations(seq))
print(a)
print(list[0])

import itertools
n=int(input())
a=tuple(map(int,input().split()))
b=tuple(map(int,input().split()))
seq=range(1,n+1)
l=list(itertools.permutations(seq))
#print(l[0])

a_num=0
b_num=0
for i in range(len(l)):
  if l[i]==a:
    a_num=i
  if l[i]==b:
    b_num=i

print(abs(a_num-b_num))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

lis = [i for i in range(1, N+1)]
m = []

for i in itertools.permutations(lis, len(lis)):
    m.append(i)

print(m)
print(abs(m.index(P) - m.index(Q)))

import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

lis = [i for i in range(1, N+1)]
m = []

for i in itertools.permutations(lis, len(lis)):
    m.append(i)

print(abs(m.index(P) - m.index(Q)))

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

n = int(input())
p = input().replace(" ", "")
q = input().replace(" ", "")
m = ""
for i in range(1, n + 1):
    m += str(i)
anagram_list = ["".join(v) for v in itertools.permutations(m)]

pa = 0
qa = 0

for i in range(len(anagram_list)):
    if anagram_list[i] == p:
        pa = i+1
    if anagram_list[i] == q:
        qa = i+1a
print(abs(pa-qa))


import itertools

n = int(input())
p = input().replace(" ", "")
q = input().replace(" ", "")
m = ""
for i in range(1, n + 1):
    m += str(i)
anagram_list = ["".join(v) for v in itertools.permutations(m)]

pa = 0
qa = 0

for i in range(len(anagram_list)):
    if anagram_list[i] == p:
        pa = i+1
    if anagram_list[i] == q:
        qa = i+1
print(abs(pa-qa))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
permutations=list(itertools.permutations(range(1,N+1)))
p=permutations.index(P)
q=permutations.index(Q)
ans=abs(p-q)
print(ans)

import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
permutations=list(itertools.permutations(range(1,N+1)))
p=permutations.index(P)
q=permutations.index(Q)
ans=abs(p-q)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
from itertools import permutations

N = int(input())
P = list(map(int, input().split()))
S = list(map(int, input().split()))
J = list(permutations(sorted(S) , N))

print(J.index(tuple(P)) - J.index(tuple(S)))

from itertools import permutations

N = int(input())
P = list(map(int, input().split()))
S = list(map(int, input().split()))
J = list(permutations(sorted(S) , N))

print(abs(J.index(tuple(P)) - J.index(tuple(S))))

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n=int(input())
#s=list(input().split())
#s,t=list(input().split())
#a=list(map(int,input().split()))
#k,x=map(int,input().split())
p=list(map(int,input()))
q=list(map(int,input()))
import itertools
import math
fulllist=list(itertools.permutations([i for i in range(1,n+1)]))
for i in range(math.factorial(n)):
    if p==fulllist[i]:
        p_index=i+1
    elif q==fulllist[i]:
        q_index=i+1
print(abs(p_index-q_index))

n=int(input())
#s=list(input().split())
#s,t=list(input().split())
#a=list(map(int,input().split()))
#k,x=map(int,input().split())
p=list(input().split())
q=list(input().split())
p=[int(i) for i in p]
q=[int(i) for i in q]
import itertools
import math
p_index,q_index=0,0
fulllist=list(itertools.permutations([i for i in range(1,n+1)]))
for i in range(math.factorial(n)):
    if p==list(fulllist[i]):
        p_index=i+1
    if q==list(fulllist[i]):
        q_index=i+1
print(abs(p_index-q_index))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

pi = 0
count = 1
for i in itertools.permutations(range(1, n+1), n):
    if list(i) == p:
        pi = count
        break
    else:
        count += 1

qi = 0
count = 1
for i in itertools.permutations(range(1, n+1), n):
    if list(i) == q:
        qi = count
        break
    else:
        count += 1


print(pi, qi)
ans = abs(pi - qi)
print(ans)

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

pi = 0
count = 1
for i in itertools.permutations(range(1, n+1), n):
    if list(i) == p:
        pi = count
        break
    else:
        count += 1

qi = 0
count = 1
for i in itertools.permutations(range(1, n+1), n):
    if list(i) == q:
        qi = count
        break
    else:
        count += 1

ans = abs(pi - qi)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

l = [i for i in range(1, n+1)]

zyu = itertools.permutations(l, n)

for t, child in enumerate(zyu):
    p_flag = True
    q_flag = True
    print(t,child)
    for check_idx in range(0, n):
        if list(child)[check_idx] == p[check_idx]:
            pass
        else:
            p_flag = False
            break

    for check_idx in range(0, n): 
        print(check_idx)
   
        if list(child)[check_idx] == q[check_idx]:
            pass
        else:
            q_flag = False
            break

    if p_flag:
        p_idx = t+1

    if q_flag:
        q_idx = t+1



print(abs(q_idx-p_idx))



n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

import itertools

l = [i for i in range(1, n+1)]

zyu = itertools.permutations(l, n)

for t, child in enumerate(zyu):
    p_flag = True
    q_flag = True
    for check_idx in range(0, n):
        if list(child)[check_idx] == p[check_idx]:
            pass
        else:
            p_flag = False
            break

    for check_idx in range(0, n):    
        if list(child)[check_idx] == q[check_idx]:
            pass
        else:
            q_flag = False
            break

    if p_flag:
        p_idx = t+1

    if q_flag:
        q_idx = t+1



print(abs(q_idx-p_idx))



Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
def fact(n):
  ret=1
  for i in range(2.n+1):
    ret=ret*i
  return ret

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
checked1=[0]*(n+1)
checked2=[0]*(n+1)
for i in range(n):
  checked1[arr1[i]]=1
  checked2[arr2[i]]=1
  cnt1+=(arr1[i]-1-sum(checked1[:arr1[i]]))*fact(n-i-1)
  cnt2+=(arr2[i]-1-sum(checked1[:arr2[i]]))*fact(n-i-1)
print(abs(cnt1-cnt2))

def fact(n):
  ret=1
  for i in range(2.n+1):
    ret=ret*i
  return ret

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
checked1=[0]*(n+1)
checked2=[0]*(n+1)
for i in range(n):
  checked1[arr1[i]]=1
  checked2[arr2[i]]=1
  cnt1+=(arr1[i]-1-sum(checked1[:arr1[i]]))*fact(n-i-1)
  cnt2+=(arr2[i]-1-sum(checked2[:arr2[i]]))*fact(n-i-1)
print(abs(cnt1-cnt2))

def fact(n):
  ret=1
  for i in range(2,n+1):
    ret=ret*i
  return ret

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(n):
  cnt1+=(arr1[i]-1)*fact(n-i-1)
  cnt2+=(arr2[i]-1)*fact(n-i-1)
print(abs(cnt1-cnt2))

def fact(n):
  ret=1
  for i in range(2.n+1):
    ret=ret*i
  return ret

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
checked1=[0]*(n+1)
checked2=[0]*(n+1)
for i in range(n):
  checked1[arr1[i]]=1
  checked2[arr2[i]]=1
  cnt1+=(arr1[i]-1-sum(checked1[:arr1[i]]))*fact(n-i-1)
  cnt2+=(arr2[i]-1-sum(checked2[:arr2[i]]))*fact(n-i-1)
print(abs(cnt1-cnt2))

def fact(n):
  ret=1
  for i in range(2.n+1):
    ret=ret*i
  return ret

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=0
cnt2=0
for i in range(n):
  cnt1+=(arr1[i]-1)*fact(n-i-1)
  cnt2+=(arr2[i]-1)*fact(n-i-1)
print(abs(cnt1-cnt2))

import itertools

n=int(input())
p=''.join(list(map(str,input().split())))
q=''.join(list(map(str,input().split())))
arr=[]
for pairs in itertools.permutations([str(i) for i in range(1,n+1)]):
  arr.append(''.join(list(pairs)))
arr=sorted(arr)
print(abs(arr.index(q)-arr.index(p)))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
from itertools import permutations
n = 8
a = map(str, range(1, n+1))
a = "".join(a)
l = list(permutations(a, n))

p = tuple(input().split())
q = tuple(input().split())

print(abs(l.index(p)-l.index(q)))


from itertools import permutations
n = int(input())
a = map(str, range(1, n+1))
a = "".join(a)
l = list(permutations(a, n))

p = tuple(input().split())
q = tuple(input().split())

print(abs(l.index(p)-l.index(q)))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import math
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
diff = 0
for i in range(n-1):
  diff += (p[i] - q[i] ) * math.factorial(n-i-1)

print(abs(diff))

import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
nums = [i for i in range(1,n+1)]
fac = [words for words in itertools.permutations(nums)]
ans = abs(fac.index(p) - fac.index(q))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

lst = itertools.permutations(range(1,N+1))

for i, L in enumerate(lst):
    print(i,L)
    if L == tuple(P):
        a = i + 1
    if L == tuple(Q):
        b = i + 1

print(abs(a-b))


import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

lst = itertools.permutations(range(1,N+1))

for i, L in enumerate(lst):
    #print(i,L)
    if L == tuple(P):
        a = i + 1
    if L == tuple(Q):
        b = i + 1

print(abs(a-b))


Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):




#       S


N = input()


S = input()

print(S.count('ABC'))






#       N M
#       a1 a2 ... aN



def min_hankobaisu(A, M):
    result = 1
    for a in A:
        result = result * a / 2
        if result > M:
            print(0)
            exit(0)
    return int(result)


N, M = map(int, input().split())


A = list(set(list(map(int, input().split()))))
A.sort(reverse=True)




for i in range(0, len(A) - 1):
    if (A[i] / 2 % 2) != (A[i + 1] / 2 % 2):
        print(0)
        exit(0)


if (A[0] / 2) % 2 == 0:
    print(0)
    exit(0)


min_hankobaisu = min_hankobaisu(A, M)

print(int(M/min_hankobaisu+1)/2)








import math


def junban(N, str):
    int_list = str.split() 
    int_list = [int(i) for i in int_list]
    yet_list = str.split() 
    yet_list = [int(i) for i in yet_list]

    num = 1 
    keta = 0 

    while keta < N:
        
        now_int = int_list[keta]

        
        yet_list.remove(now_int)

        
        
        num += math.factorial(len(yet_list)) * len([i for i in yet_list if i < now_int])
        keta += 1


    return num


N = int(input())


P = input()


Q = input()


p_int = junban(N, P)
q_int = junban(N, Q)

print(abs(p_int - q_int))

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import sys

import math
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
p = na()
q = na()
l = list(itertools.permutations(list(range(1, n+1))))
print(abs(l.index(tuple(p))) - abs(l.index(tuple(q))))

import sys

import math
import itertools

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
p = na()
q = na()
l = list(itertools.permutations(list(range(1, n+1))))
print(abs(l.index(tuple(p)) - l.index(tuple(q))))

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

nlist = list(itertools.permutations(i for i in range(1,n+1)))

ans = abs(index(nlist,p) - index(nlist,q))


import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

nlist = list(itertools.permutations(i for i in range(1,n+1)))

ans = abs(nlist.index(p) - nlist.index(q))
print(ans)

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

n = int(input())
pl = tuple([int(i) for i in input().split()])
ql = tuple([int(i) for i in input().split()])

all_list = list(itertools.permutations(range(1,n+1)))

print(all_list.index(pl) - all_list.index(ql))


n = int(input())
l = sorted(list(itertools.permutations([i for i in range(1,n+1)])))

al = tuple([int(i) for i in input().split()])
bl = tuple([int(i) for i in input().split()])


a,b = 0,0


if al == bl:
    print(0)
else:
    for idx,i in enumerate(l):
        if i == al:
            a = idx
        elif i == bl:
            b = idx
        else:
            pass
        
    print(abs(a-b))

import itertools

n = int(input())
pl = tuple([int(i) for i in input().split()])
ql = tuple([int(i) for i in input().split()])

all_list = list(itertools.permutations(range(1,n+1)))

print(abs(all_list.index(pl) - all_list.index(ql)))


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n = int(input())
l = list(input())
pi = int(input())
qi = int(input())
 
for i in range(n):
	l[i] = i+1
 
p = list(map(int, input().split()))
q = list(map(int, input().split()))
 
m = itertools.permutations(l, n)
 
for i in range(n):
	if l[i] == p
  	pi = i
    
    if l[i] == q
    qi = i
 
print(abs(pi-qi))

import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
 
l = [i for i in range(1,n+1)] 
 
pi = 0
qi = 0
 
m = list(itertools.permutations(l))
 
for i in range(len(m)):
	if m[i] == p:
  		pi = i+1
	if m[i] == q:
    	qi = i+1
        
print(abs(pi-qi))

n = int(input())
l = list(input())
pi = int(input())
qi = int(input())

for i in range(n):
	l[i] = i+1

p = list(map(int, input().split()))
q = list(map(int, input().split()))

m = itertools.permutations(l, n)

for i in range(n):
	if l[i] = p
  	pi = i
    
    if l[i] = q
    qi = i

print(abs(pi-qi))    

import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

l = [i for i in range(1,N+1)] 

pi = 0
qi = 0
 
m = list(itertools.permutations(l))



#	if m[i] == p:
#  		pi = i+1

#    	qi = i+1
 
#print(abs(pi-qi))

print(m[1])

import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
 
l = [i for i in range(1,n+1)] 
 
x = 0
y = 0
 
m = list(itertools.permutations(l))
 
for i in range(len(m)):
	if m[i] == p:
  		x = i+1
	if m[i] == q:
    	y = i+1
        
print(abs(x-y))

import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

l = [i for i in range(1,N+1)] 

pi = 0
qi = 0
 
m = list(itertools.permutations(l))
 
for i in range(len(m)):
	if m[i] == p:
  		pi = i+1
	if m[i] == q:
    	qi = i+1
 
print(abs(pi-qi))

import math
import itertools

n = int(input())
l = list(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))

pi = 0
qi = 0

for i in range(n):
	l[i] = i+1
  
m = itertools.permutations(l, n)
 
for i in range(n):
	if m[i] == p:
  		pi = i+1
	if m[i] == q:
    	qi = i+1

print(abs(pi-qi))

import itertools
 
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
 
l = [i for i in range(1,n+1)] 
 
x = 0
y = 0
 
m = list(itertools.permutations(l))
 
for i in range(len(m)):
	if m[i] == p:
  		x = i+1
	if m[i] == q:
 		y = i+1
        
print(abs(x-y))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))





import itertools
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

l = list(itertools.permutations(range(1,n+1)))

A, B = 0, 0
for i, p in enumerate(l):
    if p == a:
        A = i
    if p == b:
        B = i

print(abs(A-B))





import itertools
n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])

l = list(itertools.permutations(range(1,n+1)))

print(abs(l.index(a) - l.index(b)))





Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
    N=int(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)))

N=int(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)))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


pos = 0
pos_p = 0
pos_q = 0
for i in itertools.permutations(range(1,N)):
    pos += 1
    if i == P:
        pos_p = pos
    if i == Q:
        pos_q = pos

print(abs(pos_p - pos_q))



import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


pos = 0
pos_p = 0
pos_q = 0
for i in itertools.permutations(range(1,4)):
    pos += 1
    print(type(i), i)
    if i == P:
        pos_p = pos
    if i == Q:
        pos_q = pos

print(abs(pos_p - pos_q))



import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))


pos = 0
pos_p = 0
pos_q = 0
for i in itertools.permutations(range(1,N + 1)):
    pos += 1
    if i == P:
        pos_p = pos
    if i == Q:
        pos_q = pos

print(abs(pos_p - pos_q))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

all_pattern = list(itertools.permutations([i for i in range(1,N+1)]))
print(all_pattern)

for i, node in enumerate(all_pattern):
  print(node)
  if node == P:
    p = i
  if node ==  Q:
    q = i
    
    
print(abs(p-q))


import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

all_pattern = list(itertools.permutations([i for i in range(1,N+1)]))
#print(all_pattern)

for i, node in enumerate(all_pattern):
  #print(node)
  if node == P:
    p = i
  if node ==  Q:
    q = i
    
    
print(abs(p-q))


Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl =[]
for i in range(N):
    Nl.append(i+1)

P_answer = 0
Q_answer = 0
for i, permu in enumerate(itertools.permutations(Nl)):
    if list(permu) == P:
        P_answer = i+1
    if list(permu) == Q:
        Q_answer = i+1

print(abs(P_answer-Q_answer))

import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl =[]
for i in range(N):
    Nl.append(i+1)

P_answer = 0
Q_answer = 0
for i, permu in enumerate(itertools.permutations(Nl)):
    if list(permu) == P:
        P_answer = i+1
    if list(permu) == Q:
        Q_answer = i+1

print(abs(P_answer-Q_answer))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

n = input()
p = map(int, input().split())
q = map(int, input().split())

x = itertools.permutations(list(range(n)), n)
pnum = 0
qnum = 0
for index, xx in enumerate(x):
  if(xx == p):
    pnum = index
  if(xx == q):
    qnum = index
    
print(abs(pnum - qnum))

import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())

x = itertools.permutations(list(range(1, n+1)), n)
pnum = 0
qnum = 0
for index, xx in enumerate(x):
  if(xx == p):
    pnum = index + 1
  if(xx == q):
    qnum = index + 1
    
print(abs(pnum - qnum))


import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())

x = itertools.permutations(list(range(1, n+1)), n)
pnum = 0
qnum = 0
for index, xx in enumerate(x):
  if(list(xx) == p):
    pnum = index + 1
  if(list(xx) == q):
    qnum = index + 1
    
print(abs(pnum - qnum))


import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())

x = itertools.permutations(list(range(n)), n)
pnum = 0
qnum = 0
for index, xx in enumerate(x):
  if(xx == p):
    pnum = index
  if(xx == q):
    qnum = index
    
print(abs(pnum - qnum))


import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

x = itertools.permutations(list(range(1, n+1)), n)
pnum = 0
qnum = 0
for index, xx in enumerate(x):
  if(list(xx) == p):
    pnum = index
  if(list(xx) == q):
    qnum = index
    
print(abs(pnum - qnum))


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
from math import *
from itertools import permutations
n = int(input())
p = list(permutations(list(range(1,n+1))))
a = (int(i) for i in input().split())
b = (int(i)for i in input().split())
print(abs(p.index(a) - p.index(b)))

from math import *
from itertools import permutations
n = int(input())
a = tuple([int(i) for i in input().split()])
b = tuple([int(i) for i in input().split()])
p = list(permutations(list(range(1,n+1))))
print(abs(p.index(a)-p.index(b)))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n = int(input())
def pos_num(l):
    l_sort = l.copy()
    l_len = len(l)
    l_sort.sort()
    if l_len == 1:
        an = 0
    else:
        #print(l_sort.index(l[0])+1)
        an = (l_sort.index(l[0]))*math.factorial(l_len-1)
    #print(an)
    return an 

    

ls = list(map(int, input().split()))
an = 0
for i in range(n-1):
    b = pos_num(ls[i:])
    an += b
    #print(an)
    
print()
ll = list(map(int, input().split()))
bn = 0
for i in range(n-1):
    b = pos_num(ll[i:])
    bn += b
    #print(bn)

print(abs(an-bn))

import math
n = int(input())
def pos_num(l):
    l_sort = l.copy()
    l_len = len(l)
    l_sort.sort()
    if l_len == 1:
        an = 0
    else:
        #print(l_sort.index(l[0])+1)
        an = (l_sort.index(l[0]))*math.factorial(l_len-1)
    #print(an)
    return an 

    

ls = list(map(int, input().split()))
an = 0
for i in range(n-1):
    b = pos_num(ls[i:])
    an += b
    #print(an)
    

ll = list(map(int, input().split()))
bn = 0
for i in range(n-1):
    b = pos_num(ll[i:])
    bn += b
    #print(bn)

print(abs(an-bn))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

n = int(input())
p = tuple(map(int,readline().split()))
q = tuple(map(int,readline().split()))

a = 0

permutations = list(itertools.permutations(range(1, n+1)))
p = permutations.index(p)
q = permutations.index(q)

print(abs(p-q))

import sys

import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

permutations = list(itertools.permutations(range(1, n+1)))
p = permutations.index(p)
q = permutations.index(q)

print(abs(p-q))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import copy

n = int(input())
p = int(input().replace(" ", ""))
q = int(input().replace(" ", ""))

def hoge(numbers, s, n_list):

    for i in range(len(numbers)):
        copy_numbers = copy.deepcopy(numbers)
        ss = s+copy_numbers.pop(i)
        if len(copy_numbers) > 0:
            hoge(copy_numbers, ss, n_list)
        else:
            n_list.append(ss)

n_list = []
for i in range(n):
    number_list = [str(i) for i in range(1, n+1)]
    s = number_list.pop(i)
    hoge(number_list, s, n_list)

n_list.sort()

ans = abs((n_list.index(p) + 1) - (n_list.index(q) + 1))
print(ans)


import copy

n = int(input())
p = int(input().replace(" ", ""))
q = int(input().replace(" ", ""))

def hoge(numbers, s, n_list):

    for i in range(len(numbers)):
        copy_numbers = copy.deepcopy(numbers)
        ss = s+copy_numbers.pop(i)
        if len(copy_numbers) > 0:
            hoge(copy_numbers, ss, n_list)
        else:
            n_list.append(int(ss))

n_list = []
for i in range(n):
    number_list = [str(i) for i in range(1, n+1)]
    s = number_list.pop(i)
    hoge(number_list, s, n_list)

n_list.sort()

ans = abs((n_list.index(p) + 1) - (n_list.index(q) + 1))
print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
length = [i+1 for i in range(n)]
permut = list(itertools.permutations(length))
print(max((permut.index(p)) - (permut.index(q)) , (mm.index(q)) - mm.index(p)))


import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
length = [i+1 for i in range(n)]
permut = list(itertools.permutations(length))
print(max((permut.index(p)) - (permut.index(q)) , (permut.index(q)) - permut.index(p)))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n=int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
import math
r=sorted(p)
t=0
l=0
s=0
for i in range(n):
    if p[i]>q[i]:
        l=p
        s=q
        break
    elif q[i]>p[i]:
        l=q
        s=p
        break
else:
    l=p
    s=q
for i in range(n):
    if l[i]>=s[i]:
        t=t+(r.index(l[i])-r.index(s[i])-1)*math.factorial(n-i-1)
    else:
        t=t+(n-r.index(s[i])-1+r.index(l[i])-1)*math.factrial(n-i-1)

print(t)

import itertools
n=int(input())
p=list(input().split())
q=list(input().split())
h=[]
p1=[]
q1=[]
for i in range(n):
    h+=str(i+1)
    p1+=p[i]
    q1+=q[i]
k=list(itertools.permutations(h))
p2=-1
q2=-1
for i in range(len(k)):
    if p1==k[i]:
        p2=i
    if q1==k[i]:
        q2=i
    if p1 != -1 and q1 !=-1:
        break
print(abs(q2-p2))

import itertools
n=int(input())
p=tuple(input().split())
q=tuple(input().split())
h=[]
for i in range(n):
    h+=str(i+1)
k=list(itertools.permutations(h))
p2=-1
q2=-1
for i in range(len(k)):
    if p==k[i]:
        p2=i
    if q==k[i]:
        q2=i
    if p2 != -1 and q2 !=-1:
        break
print(abs(p2-q2))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N = int(input())
P = inpl()
Q = inpl()
ls = P.copy()
ls.sort()
cnt = 0
for l in it.permutations(ls):
    cnt += 1
    if P == l:
        a = cnt
    if Q == l:
        b = cnt
print(abs(a-b))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N = int(input())
P = inpl()
Q = inpl()
ls = P.copy()
ls.sort()
cnt = 0
a = 0
b = 0
for l in it.permutations(ls):
    cnt += 1
    l = list(l)
    if P == l:
        a = cnt
    if Q == l:
        b = cnt
print(abs(a - b))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
from itertools import permutations
n=int(input())
p,q = = tuple(map(int, input().split())), tuple(map(int, input().split()))
l = list(range(1,n+1))
x = [i for i in permutations(l,n)]
print(abs(x.index(p) - x.index(q)))

from itertools import permutations
n=int(input())
p,q = tuple(map(int, input().split())), tuple(map(int, input().split()))
l = list(range(1,n+1))
x = [i for i in permutations(l,n)]
print(abs(x.index(p) - x.index(q)))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
print(abs(A.index(map(int,input().split()))-A.index(map(int,input().split())))


import itertool
A=itertool.permutation(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))


import itertool
A=itertool.permutations(range(1,int(input())+1))
print(abs(A.index(list(map(int,input().split())))-A.index(list(map(int,input().split()))))


import itertools
A=list(itertools.permutations(range(1,int(input())+1)))
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
print(abs(A.index(P)-A.index(Q)))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
N = int(input())
P = (int(i) for i in input().split())
Q = (int(i) for i in input().split())

seq = tuple(range(N))
import itertools
p_list = list(itertools.permutations(seq))
for i,p in enumerate(p_list):
  if p_list == P:
    p_idx = i
  elif p_list == Q:
    q_idx = i
print(abs(p_idx-q_idx))

N = int(input())
P = tuple(int(i) for i in input().split())
Q = tuple(int(i) for i in input().split())

seq = tuple(range(1,N+1))
import itertools
p_list = list(itertools.permutations(seq))
for i,p in enumerate(p_list):
  if p == P:
    p_idx = i
  if p == Q:
    q_idx = i
print(abs(p_idx-q_idx))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
import sys

N = int(input())

T = []
T.append(tuple(map(int, input().split())))
T.append(tuple(map(int, input().split())))

if T[0] == T[1]:
    print(0)
    sys.exit(0)

M = [0]*N
for i in range(N):
    M[i] = i+1

ans = []
for i, v in enumerate(itertools.permutations(M, N)):
    if v in T:
        ans.append(i)

print(abs(ans[0] - ans[1])

import itertools
import sys

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

if P == Q:
    print(0)
else:
    M = [0]*N
    for i in range(N):
        M[i] = i+1

    ans = []
    for i, v in enumerate(itertools.permutations(M, N)):
        if v in [P, Q]:
            ans.append(i)

    print(abs(ans[0] - ans[1]))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
from fractions import gcd
A, B = map(int, input().split())

def lcm(x,y):
    return (x*y) // gcd(x,y)

ans = lcm(A, B)
print(ans)

from fractions import gcd
A, B = map(int, input().split())

def lcm(x,y):
    return (x*y) // gcd(x,y)

ans = lcm(A, B)
print(ans)

import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

l = 0
r = 0

for i, j in enumerate(itertools.permutations(range(1,N+1)), start=1):
    if j == P and j == Q:
        l, r = i, i
    elif j == P:
        l = i
    elif j == Q:
        r = i
    else:
        pass

print(abs(l-r))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]
R = [itertools.permutations(range(1,N+1))]
print(abs(r.idex(P)-r.index(Q)))

from itertools import permutations
N = int(input())
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())
L = list(range(1,N+1))
R = list(permutations(L))
print(abs(R.index(P)-R.index(Q)))

Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools

N = int(input())
P = list(map(int, (input().split())))
Q = list(map(int, (input().split())))

a = 0
b = 0
cnt = 0

tmp = sorted(P)

print(P)

for x in itertools.permutations(tmp):
    cnt += 1

    if P == list(x):
        a = cnt

    if Q == list(x):
        b = cnt

print(abs(a - b))


from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

a = 0
b = 0
ans = 0

for i in permutations(range(1, N + 1)):
    a += 1
    b += 1

    if i == P:
        ans = abs(ans - a)

    if i == Q:
        ans = abs(ans - b)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
num = int(input())
array1 = list(map(int, input().split()))
array2 = list(map(int, input().split()))
all_list = list(itertools.permutations(range(num)))

array1_index = all_list.index(array1) + 1
array2_index = all_list.index(array2) + 1

if array1 > array2:
  print(array1-array2)
else:
  print(array2-array1)

import itertools
num = int(input())
array1 = tuple(map(int, input().split()))
array2 = tuple(map(int, input().split()))
all_list = list(itertools.permutations(range(1, num + 1)))
 
array1_index = all_list.index(array1) + 1
array2_index = all_list.index(array2) + 1
 
if array1_index > array2_index:
  print(array1_index-array2_index)
else:
  print(array2_index-array1_index)ar

import itertools
num = int(input())
array1 = tuple(map(int, input().split()))
array2 = tuple(map(int, input().split()))
all_list = list(itertools.permutations(range(1, num + 1)))
 
array1_index = all_list.index(array1) + 1
array2_index = all_list.index(array2) + 1
 
if array1 > array2:
  print(array1-array2)
else:
  print(array2-array1)


import itertools
num = int(input())
array1 = tuple(map(int, input().split()))
array2 = tuple(map(int, input().split()))
all_list = list(itertools.permutations(range(num)))
 
array1_index = all_list.index(array1) + 1
array2_index = all_list.index(array2) + 1
 
if array1 > array2:
  print(array1-array2)
else:
  print(array2-array1)

import itertools
num = int(input())
array1 = tuple(map(int, input().split()))
array2 = tuple(map(int, input().split()))
all_list = list(itertools.permutations(range(1, num + 1)))
 
array1_index = all_list.index(array1) + 1
array2_index = all_list.index(array2) + 1
 
if array1_index > array2_index:
  print(array1_index-array2_index)
else:
  print(array2_index-array1_index)
  

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
n = int(input())
s = "".join(list(map(str,input().split())))
q = "".join(list(map(str,input().split())))
a=0
b=0
for i in range(n):
  a += 1+(n-(i+1))*(int(s[i])-1)
for i in range(n):
  b += 1+(n-(i+1))*(int(q[i])-1)
print(abs(a-b))


import itertools 
n = int(input())
s = list(map(int,input().split()))
q = list(map(int,input().split()))
z = 0
l = [i for i in  range(1,n+1)]
l1 = itertools.permutations(l)
for i in l1:
  z += 1
  if list(i)==s:
    a =z
  if list(i)==q:
    c = z
print(abs(c-a))

Verdicts: Wrong Answer

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
if __name__ == '__main__':
    n = int(input())
    s1 = [int(i) for i in input().split()]
    s2 = [int(i) for i in input().split()]
    l = []
    for i in range(n):
        l.append(i+1)
    g = []

    for v in itertools.permutations(l, n):
        h = ""
        for i in v:
            h=h+str(i)
        g.append(h)
    g.sort()

    index1 = ""
    index2 = ""
    for i in s1:
        index1 = index1 +str(i)
    for i in s2:
        index2 = index2 +str(i)

    print(abs(g.index(index1) - g.index(index2)))



import itertools

if __name__ == '__main__':
    n = int(input())
    s1 = [int(i) for i in input().split()]
    s2 = [int(i) for i in input().split()]
    l = []
    for i in range(n):
        l.append(i+1)
    g = []

    for v in itertools.permutations(l, n):
        h = ""
        for i in v:
            h=h+str(i)
        g.append(h)
    g.sort()

    index1 = ""
    index2 = ""
    for i in s1:
        index1 = index1 +str(i)
    for i in s2:
        index2 = index2 +str(i)

    print(abs(g.index(index1) - g.index(index2)))


Verdicts: Runtime Error

Accepted
Problem: We have two permutations P and Q of size N (that is, P and Q are both rearrangements of (1,~2,~...,~N)).  There are N! possible permutations of size N. Among them, let P and Q be the a-th and b-th lexicographically smallest permutations, respectively. Find |a - b|.

Submission attempts (in order):
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

l=list(range(1,n+1))
ll=itertools.permutations(l,n)
pp=ll.index(p)
qq=ll.index(q)
a=pp-qq
if a<0:
  a=a*(-1)
print(str(a))

import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

l=list(range(1,n+1))
ll=list(itertools.permutations(l,n))
pp=ll.index(p)
qq=ll.index(q)
a=pp-qq
if a<0:
  a=a*(-1)
print(str(a))

Verdicts: Runtime Error

Accepted