ZhenlongDai/ACPR huggingface dataset:
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

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

for i in range(1,N+1):
    order.append(i)



count = 0
print(P)
print(Q)
for vect in itertools.permutations(order):
    print(vect)
    count +=1
    if vect == P:
        a = count
    if vect ==Q:
        b = count

print(abs(a-b))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 3, 2)
(3, 1, 2)
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)
3


Fixed submission (verdict: Accepted):
import itertools

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

for i in range(1,N+1):
    order.append(i)



count = 0
for vect in itertools.permutations(order):
    
    count +=1
    if vect == P:
        a = count
    if vect ==Q:
        b = count

print(abs(a-b))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())

p = [int(s) for s in input().split()]
q = [int(s) for s in input().split()]

num_p = 1
for i in range(n):
    cnt = 0
    for j in range(i+1,n):
        if(p[i] > p[j]):
            cnt += 1
    
    num_p += math.factorial(n-i-1)*cnt

num_q = 1
for i in range(n):
    cnt = 0
    for j in range(i+1,n):
        if(q[i] > q[j]):
            cnt += 1
    
    num_q += math.factorial(n-i-1)*cnt
    


print(num_p-num_q)       


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
import math
n = int(input())

p = [int(s) for s in input().split()]
q = [int(s) for s in input().split()]

num_p = 1
for i in range(n):
    cnt = 0
    for j in range(i+1,n):
        if(p[i] > p[j]):
            cnt += 1
    
    num_p += math.factorial(n-i-1)*cnt

num_q = 1
for i in range(n):
    cnt = 0
    for j in range(i+1,n):
        if(q[i] > q[j]):
            cnt += 1
    
    num_q += math.factorial(n-i-1)*cnt
    


print(abs(num_p-num_q))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
def bub(n,l):
  tot = 0
  for _ in range(n):
    for i in range(n-1):
      if l[i+1] > l[i]:
        l[i],l[i+1] = l[i+1],l[i]
        tot += 1
  return tot
p = list(map(int, input().split()))
q = list(map(int, input().split()))
print(abs(bub(n,p)-bub(n,q)))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
def bub(x,l):
  if x == n:
    return [tuple(l)]
  ret = list()
  for i in range(1,n+1):
    if i not in l:
      ret += bub(x+1,l+[i])
  return ret
a = bub(0,list())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
print(abs(a.index(p) - a.index(q)))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()  

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))))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
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()  

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))))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

if __name__ == '__main__':
    
    
    
    n = int(input())
    p = input().split(' ')
    q = input().split(' ')

    for i in range(0, len(q)):
        p[i] = int(p[i])
        q[i] = int(q[i])

    realnums = p.copy()

    realnums.sort()

    perm = list(itertools.permutations(realnums))

    for per in perm:
        print(per)

    it = 0

    qplace = 0
    pplace = 0

    for i in perm:
        if list(i) == q:
            qplace = it
        if list(i) == p:
            pplace = it
        it += 1
    print(abs(qplace - pplace))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)
3


Fixed submission (verdict: Accepted):
import itertools

if __name__ == '__main__':
    
    
    
    n = int(input())
    p = input().split(' ')
    q = input().split(' ')

    for i in range(0, len(q)):
        p[i] = int(p[i])
        q[i] = int(q[i])

    realnums = p.copy()

    realnums.sort()

    perm = list(itertools.permutations(realnums))

    it = 0

    qplace = 0
    pplace = 0

    for i in perm:
        if list(i) == q:
            qplace = it
        if list(i) == p:
            pplace = it
        it += 1
    print(abs(qplace - pplace))

Problem: p02813
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())
d = dict()
for i, v in enumerate(itertools.permutations([x for x in range(1, n+1, 1)]), 1):
  d[str(v)] = i

print(d[str(tuple(p))] - d[str(tuple(q))])


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())
d = dict()
for i, v in enumerate(itertools.permutations([x for x in range(1, n+1, 1)]), 1):
  d[str(v)] = i

print(abs(d[str(tuple(p))] - d[str(tuple(q))]))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

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))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
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))


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))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import itertools


def main():
    N = int(input())
    *PArry, = list(map(int, input().split()))
    *QArry, = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            a = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
5


Fixed submission (verdict: Accepted):

import itertools


def main():
    N = int(input())
    PArry = list(map(int, input().split()))
    QArry = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            b = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import factorial

n = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

def f(X):
    c = 0
    a = [i+1 for i in range(n)]
    for i in range(n):
        a.sort()
        
        if X[i]!=min(a):
            c += factorial(n-i-1)*(a.index(X[i]))
        del a[a.index(X[i])]
    return c+1

print(f(P)-f(Q))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
from math import factorial

n = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

def f(X):
    c = 0
    a = [i+1 for i in range(n)]
    for i in range(n):
        a.sort()
        
        if X[i]!=min(a):
            c += factorial(n-i-1)*(a.index(X[i]))
        del a[a.index(X[i])]
    return c+1

print(abs(f(P)-f(Q)))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

def count_index(list, k):
    count = 0
    for i in range(k):
        if (list[i] < list[k]):
            count = count + 1
    return list[k]-count-1

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

a = (p[0]-1) * math.factorial(n)+1
b = (q[0]-1) * math.factorial(n)+1
print(a)
print(b)

for i in range(1,n):
    a = a + count_index(p, i) * math.factorial(n-i)
    b = b + count_index(q, i) * math.factorial(n-i)

ans = a-b
print(abs(ans))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
1
5
3


Fixed submission (verdict: Accepted):
import math

def count_index(list, k):
    count = 0
    for i in range(k):
        if (list[i] < list[k]):
            count = count + 1
    return list[k]-count-1

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

a = (p[0]-1) * math.factorial(n)+1
b = (q[0]-1) * math.factorial(n)+1

for i in range(1,n):
    a = a + count_index(p, i) * math.factorial(n-i)
    b = b + count_index(q, i) * math.factorial(n-i)

ans = a-b
print(abs(ans))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
lists=[]
listt=[]
sums=0
sumt=0

def rank(n,l):
  for i in range(len(l)):
    if n==l[i]:
      l.remove(l[i])
      return i+1
    
for i in range(n):
  lists.append(i+1)
  listt.append(i+1)
for i in range(n):
  sums+=(rank(s[i],lists)-1)*(math.factorial(7-i))
  sumt+=(rank(t[i],listt)-1)*(math.factorial(7-i))
if sums<sumt:
  tmp=sums
  sums=sumt
  sumt=tmp
print(sums-sumt)

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
9360


Fixed submission (verdict: Accepted):
import math
n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
lists=[]
listt=[]
sums=0
sumt=0

def rank(n,l):
  for i in range(len(l)):
    if n==l[i]:
      l.remove(l[i])
      return i+1
    
for i in range(n):
  lists.append(i+1)
  listt.append(i+1)
for i in range(n):
  sums+=(rank(s[i],lists)-1)*(math.factorial(n-1-i))
  sumt+=(rank(t[i],listt)-1)*(math.factorial(n-1-i))
if sums<sumt:
  tmp=sums
  sums=sumt
  sumt=tmp
print(sums-sumt)
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
N = int(input())
LN = []
for i in range(N):
  LN.append(i+1)
LLN=list(itertools.permutations(LN))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
print(LLN.index(tuple(P))-LLN.index(tuple(Q)))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
import itertools
N = int(input())
LN = []
for i in range(N):
  LN.append(i+1)
LLN=list(itertools.permutations(LN))
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
print(abs(LLN.index(tuple(P))-LLN.index(tuple(Q))))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
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))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools


def main():
    n = int(input())
    p = tuple(input().split())
    q = tuple(input().split())

    a = list(itertools.permutations([str(i+1) for i in range(n)]))
    print(a)
    print(abs(a.index(q)-a.index(p)))


if __name__ == "__main__":
    main()

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[('1', '2', '3'), ('1', '3', '2'), ('2', '1', '3'), ('2', '3', '1'), ('3', '1', '2'), ('3', '2', '1')]
3


Fixed submission (verdict: Accepted):
import itertools


def main():
    n = int(input())
    p = tuple(input().split())
    q = tuple(input().split())

    a = list(itertools.permutations([str(i+1) for i in range(n)]))
    print(abs(a.index(q)-a.index(p)))


if __name__ == "__main__":
    main()
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
import math
n = int(input())
p = input().split()
q = input().split()

p_mojiretu = ""
q_mojiretu = ""

for x in p:
    p_mojiretu += x
for x in q:
    q_mojiretu += x

print(p_mojiretu)
print(q_mojiretu)

cnt = 1
index_a = 0
index_b = 0

for i in itertools.permutations(range(1, n+1)):
    s = "".join(str(x) for x in i)
    print(s)
    if s == p_mojiretu:
        index_a = cnt
    if s == q_mojiretu:
        index_b = cnt
    cnt += 1
print(abs(index_a - index_b))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
132
312
123
132
213
231
312
321
3


Fixed submission (verdict: Accepted):
import itertools
import math
n = int(input())
p = input().split()
q = input().split()

p_mojiretu = ""
q_mojiretu = ""

for x in p:
    p_mojiretu += x
for x in q:
    q_mojiretu += x


cnt = 1
index_a = 0
index_b = 0

for i in itertools.permutations(range(1, n+1)):
    s = "".join(str(x) for x in i)
    if s == p_mojiretu:
        index_a = cnt
    if s == q_mojiretu:
        index_b = cnt
    cnt += 1
print(abs(index_a - index_b))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

N = int(input())

permu = [i+1 for i in range(N)]
s = 0
flag = False

P = tuple([int(i) for i in input().split(" ")])
Q = tuple([int(i) for i in input().split(" ")])


for i, value in enumerate(itertools.permutations(permu)):
    
    if P == Q:
        break

    if value == P or value == Q:
        
        if flag:
            s -= i
        else:
            s += i
            flag = True


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:

Fixed submission (verdict: Accepted):
import itertools

N = int(input())

permu = [i+1 for i in range(N)]
s = 0
flag = False

P = tuple([int(i) for i in input().split(" ")])
Q = tuple([int(i) for i in input().split(" ")])

if P==Q:
    print(s)
else:
    for i, value in enumerate(itertools.permutations(permu)):

        if value == P or value == Q:
            
            if flag:
                s -= i
                break
            else:
                s += i
                flag = True

    print(abs(s))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

if __name__ == '__main__':
    
    
    
    n = int(input())
    p = input().split(' ')
    q = input().split(' ')

    for i in range(0, len(q)):
        p[i] = int(p[i])
        q[i] = int(q[i])

    perm = list(itertools.permutations(p))

    it = 0

    qplace = 0
    pplace = 0

    for i in perm:
        if list(i) == q:
            qplace = it
        if list(i) == p:
            pplace = it
        it += 1
    print(abs(qplace - pplace))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
2


Fixed submission (verdict: Accepted):
import itertools

if __name__ == '__main__':
    
    
    
    n = int(input())
    p = input().split(' ')
    q = input().split(' ')

    for i in range(0, len(q)):
        p[i] = int(p[i])
        q[i] = int(q[i])

    realnums = p.copy()

    realnums.sort()

    perm = list(itertools.permutations(realnums))

    it = 0

    qplace = 0
    pplace = 0

    for i in perm:
        if list(i) == q:
            qplace = it
        if list(i) == p:
            pplace = it
        it += 1
    print(abs(qplace - pplace))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

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

A=list(itertools.permutations(range(1,N+1)))
print(A)
pindex=A.index(P)+1
qindex=A.index(Q)+1

print(abs(pindex-qindex))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
3


Fixed submission (verdict: Accepted):
import itertools

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

A=list(itertools.permutations(range(1,N+1)))

pindex=A.index(P)+1
qindex=A.index(Q)+1

print(abs(pindex-qindex))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import permutations
n = int(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

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:

Fixed submission (verdict: Accepted):
from itertools import permutations
 
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
 
i = 0
a = 0
b = 0
for s in permutations(range(1, n+1)):
    for j in range(n):
        if p[j] != s[j]:
            break
    else:
        a = i
    for j in range(n):
        if q[j] != s[j]:
            break
    else:
        b = i
    i += 1
 
print(abs(a-b))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
 
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
 
p_sort = sorted(p)
q_sort = sorted(q)
 
p_number = 1
q_number = 1
 
k = 0
for i in p:
  k += 1
  i_index = p_sort.index(i)
  p_number += i_index * math.factorial(n-k)
  p.remove(i)
  p_sort.remove(i)
k = 0
for i in q:
  k += 1
  i_index = q_sort.index(i)
  q_number += i_index * math.factorial(n-k)
  q.remove(i)
  q_sort.remove(i)
answer = abs(p_number - q_number)
print(answer)

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
5


Fixed submission (verdict: Accepted):
import math
 
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
 
p_sort = sorted(p)
q_sort = sorted(q)
 
p_number = 1
q_number = 1
 
k = 0
for i in p:
  k += 1
  i_index = p_sort.index(i)
  p_number += i_index * math.factorial(n-k)
  p_sort.remove(i)
k = 0
for i in q:
  k += 1
  i_index = q_sort.index(i)
  q_number += i_index * math.factorial(n-k)
  q_sort.remove(i)
answer = abs(p_number - q_number)
print(answer)

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()])

print(P)
print(Q)


p = list(permutations([x for x in range(1, N+1)]))

a = p.index(P)
b = p.index(Q)

if a > b:
    print(a-b)
else:
    print(b-a)

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 3, 2)
(3, 1, 2)
3


Fixed submission (verdict: Accepted):
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()])


p = list(permutations([x for x in range(1, N+1)]))

a = p.index(P)
b = p.index(Q)

if a > b:
    print(a-b)
else:
    print(b-a)

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
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))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import itertools

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

a = list(range(1,N+1))
b = itertools.permutations(a)

ans1 = 1
ans2 = 1

for i in b:
    if i == P:
        break
    ans1 += 1

b = itertools.permutations(a)

for i in b:
    if i == Q:
        break
    ans2 += 1

print(ans1, ans2)

print(abs(ans1-ans2))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
2 5
3


Fixed submission (verdict: Accepted):


import itertools

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

a = list(range(1,N+1))
b = itertools.permutations(a)

ans1 = 1
ans2 = 1

for i in b:
    if i == P:
        break
    ans1 += 1

b = itertools.permutations(a)

for i in b:
    if i == Q:
        break
    ans2 += 1

print(abs(ans1-ans2))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
n=int(input())
numbers1k=[]
numbers2k=[]
s=[]
for i in range(n):
    s.append(i+1)
p=itertools.permutations(s,n)
u=list(p)
print(u)
numbers1=input().rstrip().split(" ")
for num1 in numbers1:
    numbers1k.append(int(num1))
numbers2=input().rstrip().split(" ")
for num2 in numbers2:
    numbers2k.append(int(num2))
com1=tuple(numbers1k)
com2=tuple(numbers2k)
for i in range(len(u)):
    if u[i]==com1:
        a=i
for j in range(len(u)):
    if u[j]==com2:
        b=j


print(abs(b-a))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
3


Fixed submission (verdict: Accepted):
import itertools
n=int(input())
numbers1k=[]
numbers2k=[]
s=[]
for i in range(n):
    s.append(i+1)
p=itertools.permutations(s,n)
u=list(p)

numbers1=input().rstrip().split(" ")
for num1 in numbers1:
    numbers1k.append(int(num1))
numbers2=input().rstrip().split(" ")
for num2 in numbers2:
    numbers2k.append(int(num2))
com1=tuple(numbers1k)
com2=tuple(numbers2k)
for i in range(len(u)):
    if u[i]==com1:
        a=i+1
for j in range(len(u)):
    if u[j]==com2:
        b=j+1


print(abs(b-a))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
3


Fixed submission (verdict: Accepted):
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)))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
N = int(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(N):
    if list(n_perm[i]) == P:
        a = i
        break

for k in range(N):
    if list(n_perm[k]) == Q:
        b = k
        break
        
print(abs(a-b))    

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
1


Fixed submission (verdict: Accepted):
import itertools
N = int(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))

Problem: p02813
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
import math

n = int(input())
p = [map(int, input().split())]
q = [map(int, input().split())]
p_no, q_no = 0, 0

per = [c+1 for c in range(n)]
per_list = list(itertools.permutations(per))

for i in range(math.factorial(n)):
    if p == per_list[i]: p_no = i
    if q == per_list[i]: q_no = i

print(abs(p_no - q_no))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0


Fixed submission (verdict: Accepted):
import itertools
import math

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

per = [c+1 for c in range(n)]
per_list = list(itertools.permutations(per))

for i in range(math.factorial(n)):
    if p == per_list[i]:
        p_no = i
    if q == per_list[i]:
        q_no = i

print(abs(p_no - q_no))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools


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

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:
        result = p_index - q_index
        if result < 0:
            result = -result
        print(result)
        exit(0)


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
132
3


Fixed submission (verdict: Accepted):
import itertools


N = int(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:
        result = p_index - q_index
        if result < 0:
            result = -result
        print(result)
        exit(0)
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
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))))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
c1 = 1
c2 = 1
print(math.factorial(N))
for v in range(math.factorial(N)):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(math.factorial(N)):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
6
3


Fixed submission (verdict: Accepted):
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
Nl = list(range(1, N+1))
p = list(itertools.permutations(Nl,N))
NN = math.factorial(N)
c1 = 1
c2 = 1
for v in range(NN):
    if list(p[v]) == P:
        break
    else:
        c1 += 1
for v in range(NN):
    if list(p[v]) == Q:
        break
    else:
        c2 += 1
print(abs(c1-c2))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import permutations

n = int(input())
p = tuple(map(lambda x: int(x) - 1, input().split()))
q = tuple(map(lambda x: int(x) - 1, input().split()))

perm = list(permutations(range(n)))
print(perm.index(p) - perm.index(q))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
from itertools import permutations

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

perm = sorted(list(permutations(range(1, n + 1))))
print(abs(perm.index(p) - perm.index(q)))

Problem: p02813
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
print(P)
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 3, 2)
3


Fixed submission (verdict: Accepted):
from itertools import permutations

N=int(input())
l=[i+1 for i in range(N)]
P=tuple(map(int, input().split()))
Q=tuple(map(int, input().split()))
counter=0
for t in permutations(l):
  if P==t:
    a=counter
    
  if Q==t:
    b=counter
    
  counter+=1
  
print(abs(a-b))
Problem: p02813
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
ans=list(itertools.permutations(list(range(1,N+1))))
print(ans.index(P)-ans.index(Q))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
import itertools
N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))
ans=list(itertools.permutations(list(range(1,N+1))))
print(abs(ans.index(P)-ans.index(Q)))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
 
N = int(input())
P = map(int, input().split())
Q = map(int, input().split())
print(P)

P = tuple(P)
Q = tuple(Q)
print(P) 
dlist = range(1, N+1)
permlist = list(itertools.permutations(dlist))

a = 0
b = 0
for i, p in enumerate(permlist):
	if P == p:
		a = i
	if Q == p:
		b = i
    
print(abs(a-b))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
<map object at 0x7f162ec3d5d0>
(1, 3, 2)
3


Fixed submission (verdict: Accepted):
import itertools
 
N = int(input())
P = map(int, input().split())
Q = map(int, input().split())

P = tuple(P)
Q = tuple(Q)
dlist = range(1, N+1)
permlist = list(itertools.permutations(dlist))

a = 0
b = 0
for i, p in enumerate(permlist):
	if P == p:
		a = i
	if Q == p:
		b = i
    
print(abs(a-b))

Problem: p02813
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
ls = list(itertools.permutations(range(1,n+1)))
print(abs(ls.index(p)-ls.index(q)))
print(ls)


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
3
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]


Fixed submission (verdict: Accepted):
import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
ls = list(itertools.permutations(range(1,n+1)))
print(abs(ls.index(p)-ls.index(q)))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import itertools

INF = 1001001001

def resolve():
  n = int(input())
  p = list(map(int, input().split()))
  q = list(map(int, input().split()))
  arr = []
  for i in range(1, n+1):
    arr.append(i)

  x = itertools.permutations(arr, n)

  a = 0
  b = 0
  for i, y in enumerate(x):
    print(type(y))
    if (p == list(y)):
      a = i + 1
    if (q == list(y)):
      b = i + 1

  print(abs(a - b))
resolve()


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
<class 'tuple'>
3


Fixed submission (verdict: Accepted):
import sys
import itertools

INF = 1001001001

def resolve():
  n = int(input())
  p = list(map(int, input().split()))
  q = list(map(int, input().split()))
  arr = []
  for i in range(1, n+1):
    arr.append(i)

  x = itertools.permutations(arr, n)

  a = 0
  b = 0
  for i, y in enumerate(x):
    if (p == list(y)):
      a = i + 1
    if (q == list(y)):
      b = i + 1

  print(abs(a - b))
resolve()
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools


n = int(input())



p = input()
q = input()
print(n)
print(p)
i = 0
a = 0 
b = 0

for x in itertools.permutations(range(1,n+1), n):
	
	x = " ".join(map(str,x))
	
	i += 1
	if x == p:
		a = i
		
	elif x == q:
		b = i
		
        
print(abs(a-b))
     

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
3
1 3 2
3


Fixed submission (verdict: Accepted):
import itertools


n = int(input())




p = input()
q = input()


i = 0



for x in itertools.permutations(range(1,n+1), n):
	
	x = " ".join(map(str,x))
	
	i += 1
	if x == p:
		a = i
		
	if x == q:
		b = i
		

print(abs(a-b))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
0 (1, 2, 3)
1 (1, 3, 2)
2 (2, 1, 3)
3 (2, 3, 1)
4 (3, 1, 2)
5 (3, 2, 1)
3


Fixed submission (verdict: Accepted):
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):
    
    if L == tuple(P):
        a = i + 1
    if L == tuple(Q):
        b = i + 1

print(abs(a-b))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

N = int(input())

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

p = list(itertools.permutations(l, N))

print(p)

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

a = p.index(P)
b = p.index(Q)

print(abs(b-a))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
3


Fixed submission (verdict: Accepted):
import itertools

N = int(input())

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

p = list(itertools.permutations(l, N))

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

a = p.index(P)
b = p.index(Q)

print(abs(b-a))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
import re

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

print(p, q)

n_list = list(range(1, n + 1))

conv =[]
for v in itertools.permutations(n_list, n):
    conv.append(v)
print(conv)

p_ind = 0
q_ind = 0
for i, j in enumerate(conv):
    print(p, j)
    if p == j:
        p_ind = i + 1
        print('yes')
    elif q == j:
        q_ind = i + 1

print(abs(p_ind - q_ind))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 3, 2) (3, 1, 2)
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
(1, 3, 2) (1, 2, 3)
(1, 3, 2) (1, 3, 2)
yes
(1, 3, 2) (2, 1, 3)
(1, 3, 2) (2, 3, 1)
(1, 3, 2) (3, 1, 2)
(1, 3, 2) (3, 2, 1)
3


Fixed submission (verdict: Accepted):
import itertools
import re

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

n_list = list(range(1, n + 1))

conv =[]
for v in itertools.permutations(n_list, n):
    conv.append(v)

for i, j in enumerate(conv):
    if p == j:
        p_ind = i + 1

for i, j in enumerate(conv):
    if q == j:
        q_ind = i + 1

print(abs(p_ind - q_ind))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

n = int(input())
p = list(map(int, input().split()))
for i in range(len(p)):
	p[i] = p[i]-1
p = tuple(p)
q = list(map(int, input().split()))

a = list(itertools.permutations(range(n)))

for i in range(len(q)):
	q[i] = q[i]-1
q = tuple(q)
print(a.index(p) - a.index(q))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
-3


Fixed submission (verdict: Accepted):
import itertools

n = int(input())
p = list(map(int, input().split()))
for i in range(len(p)):
	p[i] = p[i]-1
p = tuple(p)
q = list(map(int, input().split()))

a = list(itertools.permutations(range(n)))

for i in range(len(q)):
	q[i] = q[i]-1
q = tuple(q)
print(abs(a.index(p) - a.index(q)))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import itertools


def main():
    N = int(input())
    PArry = list(map(int, input().split()))
    QArry = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            a = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
5


Fixed submission (verdict: Accepted):

import itertools


def main():
    N = int(input())
    PArry = list(map(int, input().split()))
    QArry = list(map(int, input().split()))

    a = 0
    b = 0
    comb = [i for i in range(1, N+1)]
    for i, iter in enumerate(itertools.permutations(comb)):
        listIter = list(iter)
        if PArry == listIter:
            a = i+1
        if QArry == listIter:
            b = i+1

    print(abs(a-b))


if __name__ == '__main__':
    main()
Problem: p02813
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
def main():
    n = int(input())
    p_list = list(itertools.permutations ([i+1 for i in range(n)]))
    print(type(p_list[0]))
    p = tuple(map(int, input().split(" ")))
    q = tuple(map(int, input().split(" ")))
    pn = 0
    qn = 0
    for i in range(len(p_list)):
        if p == p_list[i]:
            pn = i
        if q == p_list[i]:
            qn = i
    print(abs(pn-qn))

if __name__ == "__main__":
    main()

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
<class 'tuple'>
3


Fixed submission (verdict: Accepted):
import itertools
def main():
    n = int(input())
    p_list = list(itertools.permutations ([i+1 for i in range(n)]))
    p = tuple(map(int, input().split(" ")))
    q = tuple(map(int, input().split(" ")))
    pn = 0
    qn = 0
    for i in range(len(p_list)):
        if p == p_list[i]:
            pn = i
        if q == p_list[i]:
            qn = i
    print(abs(pn-qn))

if __name__ == "__main__":
    main()

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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()])

print(P)
print(Q)


p = list(permutations([x for x in range(1, N+1)]))

a = p.index(P)
b = p.index(Q)

if a > b:
    print(a-b)
else:
    print(b-a)


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
(1, 3, 2)
(3, 1, 2)
3


Fixed submission (verdict: Accepted):
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()])


p = list(permutations([x for x in range(1, N+1)]))

a = p.index(P)
b = p.index(Q)

if a > b:
    print(a-b)
else:
    print(b-a)

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=map(int,input().split())
import copy
import itertools
c = itertools.permutations(a, n)

b=map(int,input().split())
print(a)
print(b)
print(c)


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
<map object at 0x7f9282d31270>
<map object at 0x7f9282d312d0>
<itertools.permutations object at 0x7f9282d37c40>


Fixed submission (verdict: Accepted):
n=int(input())
a=[0]*n
b=[0]*n
a[:]=map(int,input().split())
import itertools
c=list(itertools.permutations(a, n))
c.sort()
b[:]=map(int,input().split())
a=tuple(a)
b=tuple(b)

print(abs(c.index(a)-c.index(b)))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools
N = int(input())
L1 = tuple(map(int,input().split()))
a = 0
L2 = tuple(map(int,input().split()))
b = 0
L = [i for i in range(1,N+1)]
Base = list(itertools.permutations(L))
print(Base)
for i in range(len(Base)):
    if Base[i] == L1:
        a = i+1
for i in range(len(Base)):
    if Base[i] == L2:
        b = i+1
print(abs(a-b))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)]
3


Fixed submission (verdict: Accepted):
import itertools
N = int(input())
L1 = tuple(map(int,input().split()))
a = 0
L2 = tuple(map(int,input().split()))
b = 0
L = [i for i in range(1,N+1)]
Base = list(itertools.permutations(L))
for i in range(len(Base)):
    if Base[i] == L1:
        a = i+1
for i in range(len(Base)):
    if Base[i] == L2:
        b = i+1
print(abs(a-b))

Problem: p02813
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import itertools
n=int(input())
pp=input().split()
qq=input().split()
p=[]
q=[]
p.append(pp)
q.append(qq)
a=[]
for v in itertools.permutations(pp,n):
    a.append(v)
a=sorted(a)
for j in range(len(a)):
  a[j]=list(a[j])

b=0
c=0
for i in range(len(a)):
  if a[i]==pp:
    b+=i
    
for k in range(len(a)):
  if a[k]==qq:
    c+=i

print(max(b-c,c-b))


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
4


Fixed submission (verdict: Accepted):
import itertools
n=int(input())
pp=input().split()
qq=input().split()
p=[]
q=[]
p.append(pp)
q.append(qq)
a=[]
for v in itertools.permutations(pp,n):
    a.append(v)
a=sorted(a)
for j in range(len(a)):
  a[j]=list(a[j])

b=0
c=0
for i in range(len(a)):
  if a[i]==pp:
    b+=i
    
for k in range(len(a)):
  if a[k]==qq:
    c+=k

print(max(b-c,c-b))

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import itertools

N = int(input())
P_ar = list(map(int,input().split()))
Q_ar = list(map(int,input().split()))

List = list(map(list,list(itertools.permutations(range(N)))))

for i in range(N):
  P_ar[i]-=1
  Q_ar[i]-=1

a=-1
b=-1

for i in range(len(List)):
  if List[i]==P_ar:
    a=i
    break

for i in range(len(List)):
  if List[i]==Q_ar:
    b=i
    break


Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:

Fixed submission (verdict: Accepted):
import itertools

N = int(input())
P_ar = list(map(int,input().split()))
Q_ar = list(map(int,input().split()))

List = list(map(list,list(itertools.permutations(range(N)))))

for i in range(N):
  P_ar[i]-=1
  Q_ar[i]-=1

a=-1
b=-1

for i in range(len(List)):
  if List[i]==P_ar:
    a=i
    break

for i in range(len(List)):
  if List[i]==Q_ar:
    b=i
    break

print(abs(a-b))
Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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)

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
2 5
3


Fixed submission (verdict: Accepted):
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)

Problem: p02813
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
    
def check_order(k):
    res = 0
    for _ in range(n):
        if len(k) == 1:
            break
        s = k[0]
        c = 0
        for i in k:
            if s >= i:
                 c += 1
        k.pop(0)
        res += math.factorial(c-1)
    return res

p_order = check_order(p)
q_order = check_order(q)

print(abs(p_order-q_order))

Failing test case input:
3
1 3 2
3 1 2

Expected output:
3

Actual output:
1


Fixed submission (verdict: Accepted):
import math
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

def check_order(k):
    res = 0
    for _ in range(n):
        if len(k) == 1:
            break
        s = k[0]
        c = 0
        for i in k:
            if s >= i:
                 c += 1
        k.pop(0)
        res += math.factorial(len(k)) * (c-1)
    return res

p_order = check_order(p)
q_order = check_order(q)

print(abs(p_order-q_order))