Language: C++

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#define M 15
using namespace std;

struct node {
    int x, y, bottom, east;
    __int64 value;
} Q[M*M*M*M*M*M], s, p;
int mark[M][M][M][M];
__int64 dis[M][M][M][M];
int value[M][M];
int n, m;
int sx, sy, ex, ey;
__int64 oo = 100000000000000LL;
int add[7][7] = {
    {0},
    {5, 4, 2, 3},
    {3, 1, 4, 6},
    {2, 6, 5, 1},
    {5, 6, 2, 1},
    {6, 4, 1, 3},
    {3, 2, 4, 5}
};

void checkIn(int &H) {
    if (dis[s.x][s.y][s.bottom][s.east] > s.value) {
        dis[s.x][s.y][s.bottom][s.east] = s.value;
        if (!mark[s.x][s.y][s.bottom][s.east]) {
            mark[s.x][s.y][s.bottom][s.east] = 1;
            Q[H++] = s;
        }
        //printf("s %d %d %d %d\n", s.x, s.y, s.bottom, s.east);
    }
}

int find(int e, int b, int k) {
    int i;
    for (i = 0; i < 4; i++)
        if (add[e][i] == b) {
            return add[e][(i + k + 4) % 4];
        }
}

void SPFA() {
    int i, j, k, x, y, bottom, east;
    int L, H;
    for (x = 0; x < n; x++)
        for (y = 0; y < m; y++)
            for (i = 1; i <= 6; i++)
                for (j = 1; j <= 6; j++) {
                    dis[x][y][i][j] = oo;
                    mark[x][y][i][j] = 0;
                }
    dis[sx][sy][6][3] = 0;
    s.x = sx, s.y = sy, s.bottom = 6, s.east = 3, s.value = 0;
    mark[s.x][s.y][s.bottom][s.east] = 1;
    L = H = 0;
    Q[H++] = s;
    while (L < H) {
        p = Q[L++];
        mark[p.x][p.y][p.bottom][p.east] = 0;
        x = p.x, y = p.y;
        if (x > 0) {//up
            s.x = p.x - 1;
            s.y = p.y;
            s.bottom = find(p.east, p.bottom, 1);
            s.east = p.east;
            s.value = p.value + value[s.x][s.y] * s.bottom;
            checkIn(H);
        }
        if (x < n - 1) {//down
            s.x = p.x + 1;
            s.y = p.y;
            s.bottom = find(p.east, p.bottom, -1);
            s.east = p.east;
            s.value = p.value + value[s.x][s.y] * s.bottom;
            checkIn(H);
        }
        if (y > 0) {//left
            s.x = p.x;
            s.y = p.y - 1;
            s.bottom = 7 - p.east;
            s.east = p.bottom;
            s.value = p.value + value[s.x][s.y] * s.bottom;
            checkIn(H);
        }
        if (y < m - 1) {//right
            //puts("yes");
            s.x = p.x;
            s.y = p.y + 1;
            s.bottom = p.east;
            s.east = 7 - p.bottom;
            s.value = p.value + value[s.x][s.y] * s.bottom;
            checkIn(H);
        }
    }
}

int main(int argc, char** argv) {
    int i, j, k;
    while (scanf("%d %d", &n, &m), n | m) {
        for (i = 0; i < n; i++)
            for (j = 0; j < m; j++)
                scanf("%d", &value[i][j]);
        scanf("%d %d %d %d", &sx, &sy, &ex, &ey);
        SPFA();
        __int64 ans = oo;
        for (i = 1; i <= 6; i++)
            for (j = 1; j <= 6; j++)
                if (dis[ex][ey][i][j] < ans)
                    ans = dis[ex][ey][i][j];
        printf("%I64d\n", ans);
    }
    return 0;
}

Compiler output:
a.cc:15:5: error: '__int64' does not name a type; did you mean '__int64_t'?
   15 |     __int64 value;
      |     ^~~~~~~
      |     __int64_t
a.cc:18:1: error: '__int64' does not name a type; did you mean '__int64_t'?
   18 | __int64 dis[M][M][M][M];
      | ^~~~~~~
      | __int64_t
a.cc:22:1: error: '__int64' does not name a type; did you mean '__int64_t'?
   22 | __int64 oo = 100000000000000LL;
      | ^~~~~~~
      | __int64_t
a.cc: In function 'void checkIn(int&)':
a.cc:34:9: error: 'dis' was not declared in this scope; did you mean 'div'?
   34 |     if (dis[s.x][s.y][s.bottom][s.east] > s.value) {
      |         ^~~
      |         div
a.cc:34:45: error: 'struct node' has no member named 'value'
   34 |     if (dis[s.x][s.y][s.bottom][s.east] > s.value) {
      |                                             ^~~~~
a.cc:35:45: error: 'struct node' has no member named 'value'
   35 |         dis[s.x][s.y][s.bottom][s.east] = s.value;
      |                                             ^~~~~
a.cc: In function 'void SPFA()':
a.cc:59:21: error: 'dis' was not declared in this scope; did you mean 'div'?
   59 |                     dis[x][y][i][j] = oo;
      |                     ^~~
      |                     div
a.cc:59:39: error: 'oo' was not declared in this scope
   59 |                     dis[x][y][i][j] = oo;
      |                                       ^~
a.cc:62:5: error: 'dis' was not declared in this scope; did you mean 'div'?
   62 |     dis[sx][sy][6][3] = 0;
      |     ^~~
      |     div
a.cc:63:53: error: 'struct node' has no member named 'value'
   63 |     s.x = sx, s.y = sy, s.bottom = 6, s.east = 3, s.value = 0;
      |                                                     ^~~~~
a.cc:76:15: error: 'struct node' has no member named 'value'
   76 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |               ^~~~~
a.cc:76:25: error: 'struct node' has no member named 'value'
   76 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |                         ^~~~~
a.cc:84:15: error: 'struct node' has no member named 'value'
   84 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |               ^~~~~
a.cc:84:25: error: 'struct node' has no member named 'value'
   84 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |                         ^~~~~
a.cc:92:15: error: 'struct node' has no member named 'value'
   92 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |               ^~~~~
a.cc:92:25: error: 'struct node' has no member named 'value'
   92 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |                         ^~~~~
a.cc:101:15: error: 'struct node' has no member named 'value'
  101 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |               ^~~~~
a.cc:101:25: error: 'struct node' has no member named 'value'
  101 |             s.value = p.value + value[s.x][s.y] * s.bottom;
      |                         ^~~~~
a.cc: In function 'int main(int, char**)':
a.cc:115:9: error: '__int64' was not declared in this scope; did you mean '__ynf64'?
  115 |         __int64 ans = oo;
      |         ^~~~~~~
      |         __ynf64
a.cc:118:21: error: 'dis' was not declared in this scope; did you mean 'div'?
  118 |                 if (dis[ex][ey][i][j] < ans)
      |                     ^~~
      |                     div
a.cc:118:41: error: 'ans' was not declared in this scope; did you mean 'abs'?
  118 |                 if (dis[ex][ey][i][j] < ans)
      |                                         ^~~
      |                                         abs
a.cc:120:27: error: 'ans' was not declared in this scope; did you mean 'abs'?
  120 |         printf("%I64d\n", ans);
      |                           ^~~
      |                           abs
a.cc: In function 'int find(int, int, int)':
a.cc:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^