Language: C++

using System;
using System.Linq;

class C2
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Read();
		var b = Read();

		int i = 0, j = 0, c = 0;
		new Perm<int>(Enumerable.Range(1, n).ToArray(), n, p =>
		{
			++c;
			if (p.SequenceEqual(a)) i = c;
			if (p.SequenceEqual(b)) j = c;
		}).Find();
		Console.WriteLine(Math.Abs(i - j));
	}
}

class Perm<T>
{
	T[] v, p;
	bool[] u;
	Action<T[]> act;
	public Perm(T[] _v, int r, Action<T[]> _act) { v = _v; p = new T[r]; u = new bool[v.Length]; act = _act; }

	public void Find() { if (p.Length > 0) Dfs(0); else act(p); }
	void Dfs(int i)
	{
		for (int j = 0; j < v.Length; ++j)
		{
			if (u[j]) continue;
			p[i] = v[j];
			u[j] = true;
			if (i + 1 < p.Length) Dfs(i + 1); else act(p);
			u[j] = false;
		}
	}
}


Compiler output:
a.cc:1:7: error: expected nested-name-specifier before 'System'
    1 | using System;
      |       ^~~~~~
a.cc:2:7: error: expected nested-name-specifier before 'System'
    2 | using System.Linq;
      |       ^~~~~~
a.cc:6:19: error: expected unqualified-id before '[' token
    6 |         static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
      |                   ^
a.cc:22:2: error: expected ';' after class definition
   22 | }
      |  ^
      |  ;
a.cc: In static member function 'static void C2::Main()':
a.cc:9:17: error: 'var' was not declared in this scope
    9 |                 var n = int.Parse(Console.ReadLine());
      |                 ^~~
a.cc:10:21: error: expected ';' before 'a'
   10 |                 var a = Read();
      |                     ^
a.cc:11:21: error: expected ';' before 'b'
   11 |                 var b = Read();
      |                     ^
a.cc:14:21: error: 'Perm' does not name a type
   14 |                 new Perm<int>(Enumerable.Range(1, n).ToArray(), n, p =>
      |                     ^~~~
a.cc:14:26: error: expected primary-expression before 'int'
   14 |                 new Perm<int>(Enumerable.Range(1, n).ToArray(), n, p =>
      |                          ^~~
a.cc:19:18: error: expected primary-expression before ')' token
   19 |                 }).Find();
      |                  ^
a.cc:20:17: error: 'Console' was not declared in this scope
   20 |                 Console.WriteLine(Math.Abs(i - j));
      |                 ^~~~~~~
a.cc:20:35: error: 'Math' was not declared in this scope
   20 |                 Console.WriteLine(Math.Abs(i - j));
      |                                   ^~~~
a.cc: At global scope:
a.cc:24:7: error: 'Perm' is not a class template
   24 | class Perm<T>
      |       ^~~~
a.cc:24:12: error: 'T' was not declared in this scope
   24 | class Perm<T>
      |            ^
a.cc:26:9: error: 'T' does not name a type
   26 |         T[] v, p;
      |         ^
a.cc:27:13: error: expected unqualified-id before '[' token
   27 |         bool[] u;
      |             ^
a.cc:28:9: error: 'Action' does not name a type
   28 |         Action<T[]> act;
      |         ^~~~~~
a.cc:29:15: error: expected ':' before 'Perm'
   29 |         public Perm(T[] _v, int r, Action<T[]> _act) { v = _v; p = new T[r]; u = new bool[v.Length]; act = _act; }
      |               ^~~~~
      |               :
a.cc:29:24: error: expected ')' before '_v'
   29 |         public Perm(T[] _v, int r, Action<T[]> _act) { v = _v; p = new T[r]; u = new bool[v.Length]; act = _act; }
      |                    ~   ^~~
      |                        )
a.cc:31:15: error: expected ':' before 'void'
   31 |         public void Find() { if (p.Length > 0) Dfs(0); else act(p); }
      |               ^~~~~
      |               :
a.cc:43:2: error: expected ';' after class definition
   43 | }
      |  ^
      |  ;
a.cc: In member function 'void Perm::Find()':
a.cc:31:34: error: 'p' was not declared in this scope
   31 |         public void Find() { if (p.Length > 0) Dfs(0); else act(p); }
      |                                  ^
a.cc:31:61: error: 'act' was not declared in this scope
   31 |         public void Find() { if (p.Length > 0) Dfs(0); else act(p); }
      |                                                             ^~~
a.cc: In member function 'void Perm::Dfs(int)':
a.cc:34:37: error: 'v' was not declared in this scope
   34 |                 for (int j = 0; j < v.Length; ++j)
      |                                     ^
a.cc:36:29: error: 'u' was not declared in this scope
   36 |                         if (u[j]) continue;
      |                             ^
a.cc:37:25: error: 'p' was not declared in this scope
   37 |                         p[i] = v[j];
      |                         ^
a.cc:38:25: error: 'u' was not declared in this scope
   38 |                         u[j] = true;
      |                         ^
a.cc:39:64: error: 'act' was not declared in this scope
   39 |                         if (i + 1 < p.Length) Dfs(i + 1); else act(p);
      |                                                                ^~~