Language: C++

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception{
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNextInt()){
				Queue<State> queue = new LinkedList<>();
				Set<Integer> set = new HashSet<>();
				int[][] firstNums = new int[2][4];
				int firstZeroX = -1;
				int firstZeroY = -1;
				for(int y = 0; y < 2; y++){
					for(int x = 0; x < 4; x++){
						firstNums[y][x] = sc.nextInt();
						if(firstNums[y][x] == 0){
							firstZeroY = y;
							firstZeroX = x;
						}
					}
				}

				State firstState = new State(firstNums, firstZeroY, firstZeroX, 0);
				set.add(firstState.hashCode());
				queue.add(firstState);

				while(!queue.isEmpty()){
					State nowState = queue.poll();
					if(nowState.hashCode() == 1234567){
						System.out.println(nowState.getDepth());
						break;
					}
					for(State nextState : nowState.nextMove()){
						if(!set.contains(nextState.hashCode())){
							set.add(nextState.hashCode());
							queue.add(nextState);
						}
					}
				}
			}
		}
	}

}

class State {

	private static final int[] vy = new int[]{0, 1, 0, -1};
	private static final int[] vx = new int[]{1, 0, -1, 0};

	private int[][] nums;
	private int zeroX;
	private int zeroY;
	private int hash;
	private int depth;

	public State(int[][] nums, int zeroY, int zeroX, int depth){
		this.nums = nums;
		this.zeroY = zeroY;
		this.zeroX = zeroX;
		this.depth = depth;
		this.hash = -1;
	}

	public int getDepth(){
		return depth;
	}

	public LinkedList<State> nextMove(){
		LinkedList<State> list = new LinkedList<>();
		for(int i = 0; i < 4; i++){
			int nextZeroY = zeroY + vy[i];
			int nextZeroX = zeroX + vx[i];
			if(nextZeroY < 0 || nextZeroY >= 2) continue;
			if(nextZeroX < 0 || nextZeroX >= 4) continue;
			int[][] nextNums = new int[2][4];
			for(int y = 0; y < 2; y++){
				for(int x = 0; x < 4; x++){
					nextNums[y][x] = nums[y][x];
				}
			}
			nextNums[nextZeroY][nextZeroX] = 0;
			nextNums[zeroY][zeroX] = nums[nextZeroY][nextZeroX];
			list.add(new State(nextNums, nextZeroY, nextZeroX, depth + 1));
		}

		return list;
	}

	@Override
	public int hashCode(){
		if(hash != -1) return hash;
		hash = 0;
		for(int y = 0; y < 2; y++){
			for(int x = 0; x < 4; x++){
				hash *= 10;
				hash += nums[y][x];
			}
		}
		return hash;
	}

}

Compiler output:
a.cc:93:9: error: stray '@' in program
   93 |         @Override
      |         ^
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.HashSet;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import java.util.LinkedList;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import java.util.Queue;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import java.util.Scanner;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import java.util.Set;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: expected unqualified-id before 'public'
    7 | public class Main {
      | ^~~~~~
a.cc:51:16: error: expected ':' before 'static'
   51 |         private static final int[] vy = new int[]{0, 1, 0, -1};
      |                ^~~~~~~
      |                :
a.cc:51:24: error: 'final' does not name a type
   51 |         private static final int[] vy = new int[]{0, 1, 0, -1};
      |                        ^~~~~
a.cc:52:16: error: expected ':' before 'static'
   52 |         private static final int[] vx = new int[]{1, 0, -1, 0};
      |                ^~~~~~~
      |                :
a.cc:52:24: error: 'final' does not name a type
   52 |         private static final int[] vx = new int[]{1, 0, -1, 0};
      |                        ^~~~~
a.cc:54:16: error: expected ':' before 'int'
   54 |         private int[][] nums;
      |                ^~~~
      |                :
a.cc:54:20: error: expected unqualified-id before '[' token
   54 |         private int[][] nums;
      |                    ^
a.cc:55:16: error: expected ':' before 'int'
   55 |         private int zeroX;
      |                ^~~~
      |                :
a.cc:56:16: error: expected ':' before 'int'
   56 |         private int zeroY;
      |                ^~~~
      |                :
a.cc:57:16: error: expected ':' before 'int'
   57 |         private int hash;
      |                ^~~~
      |                :
a.cc:58:16: error: expected ':' before 'int'
   58 |         private int depth;
      |                ^~~~
      |                :
a.cc:60:15: error: expected ':' before 'State'
   60 |         public State(int[][] nums, int zeroY, int zeroX, int depth){
      |               ^~~~~~
      |               :
a.cc:60:28: error: multidimensional array must have bounds for all dimensions except the first
   60 |         public State(int[][] nums, int zeroY, int zeroX, int depth){
      |                            ^
a.cc:60:30: error: expected ',' or '...' before 'nums'
   60 |         public State(int[][] nums, int zeroY, int zeroX, int depth){
      |                              ^~~~
a.cc:68:15: error: expected ':' before 'int'
   68 |         public int getDepth(){
      |               ^~~~
      |               :
a.cc:72:15: error: expected ':' before 'LinkedList'
   72 |         public LinkedList<State> nextMove(){
      |               ^~~~~~~~~~~
      |               :
a.cc:72:16: error: 'LinkedList' does not name a type
   72 |         public LinkedList<State> nextMove(){
      |                ^~~~~~~~~~
a.cc:93:10: error: 'Override' does not name a type
   93 |         @Override
      |          ^~~~~~~~
a.cc:106:2: error: expected ';' after class definition
  106 | }
      |  ^
      |  ;
a.cc: In constructor 'State::State(...)':
a.cc:61:22: error: request for member 'nums' in '(State*)this', which is of pointer type 'State*' (maybe you meant to use '->' ?)
   61 |                 this.nums = nums;
      |                      ^~~~
a.cc:61:29: error: 'nums' was not declared in this scope
   61 |                 this.nums = nums;
      |                             ^~~~
a.cc:62:22: error: request for member 'zeroY' in '(State*)this', which is of pointer type 'State*' (maybe you meant to use '->' ?)
   62 |                 this.zeroY = zeroY;
      |                      ^~~~~
a.cc:63:22: error: request for member 'zeroX' in '(State*)this', which is of pointer type 'State*' (maybe you meant to use '->' ?)
   63 |                 this.zeroX = zeroX;
      |                      ^~~~~
a.cc:64:22: error: request for member 'depth' in '(State*)this', which is of pointer type 'State*' (maybe you meant to use '->' ?)
   64 |                 this.depth = depth;
      |                      ^~~~~
a.cc:65:22: error: request for member 'hash' in '(State*)this', which is of pointer type 'State*' (maybe you meant to use '->' ?)
   65 |                 this.hash = -1;
      |                      ^~~~