Language: C++

#include <cstdio>
#include <cstring> 
#include <queue>
#include <iostream>
using namespace std;
#define N 9
#define INF 0x3fffffff
#define MOD 1000003LL

long long start, end, input[N], states[MOD];
const int step[4] = {1, -1, 3, -3};
int costs[2], mincost[MOD];
bool inque[MOD];

inline long long encode(long long nums[]){
  long long res = 0;
  for(int i = 0; i < N; i++) res |= nums[i] << (i << 2);
  return res;
}

inline void decode(long long num, long long nums[], int &idx){
  for(int i = 0; i < N; i++) nums[i] = (num >> (i << 2)) & 0xfLL;
  for(int i = 0; i < N; i++) if(nums[i] == 0){ idx = i; break; }
}

inline int find_hash(long long state){
  int hash = state % MOD;
  while(states[hash] != -1)
    if(states[hash] == state) break;
    else hash = (hash + 1) % MOD;
  if(states[hash] == -1) states[hash] = state;
  return hash;
}

inline int val(long long state){
  return mincost[find_hash(state)];
}

inline bool add(long long state, int cost){
  int hash = find_hash(state);
  
  if(cost < mincost[hash]){ mincost[hash] = cost; return true; } 
  else return false;
}

inline int solve(){
  memset(states, -1, sizeof(states));
  memset(inque, false, sizeof(inque));
  for(int i = 0; i < MOD; i++) mincost[i] = INF;
  
  int idx, tmp;
  long long nums[N];
  
  queue<long long> que;
  que.push(start); add(start, 0); inque[find_hash(start)] = true;
  
  while(!que.empty()){
    long long state = que.front(); que.pop();
    int cost = val(state);
    inque[find_hash(state)] = false;
    
    if(cost >= val(end)) continue;
    if(state == end){ system("pause"); continue; }
    
    decode(state, nums, idx);
    for(int i = 0; i < 4; i++){
      int nxt = (idx + N + step[i]) % N;
      int nxtcost = cost + costs[i >> 1];
      tmp = nums[idx]; nums[idx] = nums[nxt]; nums[nxt] = tmp;
      long long nxtstate = encode(nums);
      
      if(add(nxtstate, nxtcost) && !inque[find_hash(nxtstate)]) que.push(encode(nums));
      tmp = nums[idx]; nums[idx] = nums[nxt]; nums[nxt] = tmp;
    }
  }
  return val(end);
}

int main(){
  while(scanf("%d%d", costs, costs + 1) == 2 && (costs[0]  || costs[1])){
    for(int i = 0; i < N; i++) scanf("%d", input + i);
    start = encode(input);
    for(int i = 0; i < N; i++) scanf("%d", input + i);
    end = encode(input);
    
    printf("%d\n", solve());
  }
  return 0;
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:62:20: error: reference to 'end' is ambiguous
   62 |     if(cost >= val(end)) continue;
      |                    ^~~
In file included from /usr/include/c++/14/deque:68,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:3:
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
In file included from /usr/include/c++/14/bits/stl_deque.h:63,
                 from /usr/include/c++/14/deque:66:
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:10:18: note:                 'long long int end'
   10 | long long start, end, input[N], states[MOD];
      |                  ^~~
a.cc:63:17: error: reference to 'end' is ambiguous
   63 |     if(state == end){ system("pause"); continue; }
      |                 ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:10:18: note:                 'long long int end'
   10 | long long start, end, input[N], states[MOD];
      |                  ^~~
a.cc:76:14: error: reference to 'end' is ambiguous
   76 |   return val(end);
      |              ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:10:18: note:                 'long long int end'
   10 | long long start, end, input[N], states[MOD];
      |                  ^~~
a.cc: In function 'int main()':
a.cc:84:5: error: reference to 'end' is ambiguous
   84 |     end = encode(input);
      |     ^~~
/usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)'
  116 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
      |                                     ^~~
/usr/include/c++/14/bits/range_access.h:115:31: note:                 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)'
  115 |   template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept;
      |                               ^~~
/usr/include/c++/14/bits/range_access.h:106:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
  106 |     end(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~
/usr/include/c++/14/bits/range_access.h:85:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
   85 |     end(const _Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/bits/range_access.h:74:5: note:                 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
   74 |     end(_Container& __cont) -> decltype(__cont.end())
      |     ^~~
/usr/include/c++/14/initializer_list:99:5: note:                 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)'
   99 |     end(initializer_list<_Tp> __ils) noexcept
      |     ^~~
a.cc:10:18: note:                 'long long int end'
   10 | long long start, end, input[N], states[MOD];
      |                  ^~~