<commit_before>/**
 * File    : E.cpp
 * Author  : <NAME>
 * Created : 2018-4-15 22:15:59
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W;
ll D[777][777][4];
ll ans[777][777];
string S[777];
typedef tuple<ll, int, int, int, ll> state; // dist, x, y, d, dist_before
priority_queue<state, vector<state>, greater<state> > Q;

bool valid(int x, int y, int d)
{
  return (0 <= x && x <= H && 0 <= y && y < W && D[x][y][d] < 0);
}

int main()
{
  fill(&D[0][0][0], &D[0][0][0] + 777 * 777 * 4, -1);
  cin >> H >> W;
  for (auto i = 0; i < H; i++)
  {
    cin >> S[i];
  }
  int goal_x = -1, goal_y = -1;
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      if (S[i][j] == 'G')
      {
        goal_x = i;
        goal_y = j;
      }
    }
  }
  assert(goal_x >= 0 && goal_y >= 0);
  Q.push(state(0, goal_x, goal_y, 0, 0));
  while (!Q.empty())
  {
    ll dist = get<0>(Q.top());
    int x = get<1>(Q.top());
    int y = get<2>(Q.top());
    int d = get<3>(Q.top());
    ll dist_b = get<4>(Q.top());
    Q.pop();
    if (D[x][y][d] < 0)
    {
      if (S[x][y] == '.')
      {
        D[x][y][d] = dist;
        cerr << "D[" << x << "][" << y << "][" << d << "] = " << D[x][y][d] << endl;
        int nx = x + dx[d];
        int ny = y + dy[d];
        if (valid(nx, ny, d))
        {
          Q.push(state(dist + 1, nx, ny, d, dist_b + 1));
        }
      }
      else
      {
        for (auto k = 0; k < 4; k++)
        {
          D[x][y][k] = dist;
          cerr << "D[" << x << "][" << y << "][" << k << "] = " << D[x][y][k] << endl;
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (valid(nx, ny, k))
          {
            Q.push(state(dist + dist_b + 1, nx, ny, k, dist_b + 1));
          }
        }
      }
    }
  }
  for (auto i = 0; i < H; i++)
  {<commit_msg>tried E.cpp to 'E'<commit_after>/**
 * File    : E.cpp
 * Author  : <NAME>
 * Created : 2018-4-15 22:15:59
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W;
ll D[777][777][4];
ll ans[777][777];
string S[777];
typedef tuple<ll, int, int, int, ll> state; // dist, x, y, d, dist_before
priority_queue<state, vector<state>, greater<state> > Q;

bool valid(int x, int y, int d)
{
  return (0 <= x && x <= H && 0 <= y && y < W && D[x][y][d] < 0);
}

int main()
{
  fill(&D[0][0][0], &D[0][0][0] + 777 * 777 * 4, -1);
  cin >> H >> W;
  for (auto i = 0; i < H; i++)
  {
    cin >> S[i];
  }
  int goal_x = -1, goal_y = -1;
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      if (S[i][j] == 'G')
      {
        goal_x = i;
        goal_y = j;
      }
    }
  }
  assert(goal_x >= 0 && goal_y >= 0);
  Q.push(state(0, goal_x, goal_y, 0, 0));
  while (!Q.empty())
  {
    ll dist = get<0>(Q.top());
    int x = get<1>(Q.top());
    int y = get<2>(Q.top());
    int d = get<3>(Q.top());
    ll dist_b = get<4>(Q.top());
    Q.pop();
    if (D[x][y][d] < 0)
    {
      if (S[x][y] == '.')
      {
        D[x][y][d] = dist;
        cerr << "D[" << x << "][" << y << "][" << d << "] = " << D[x][y][d] << endl;
        int nx = x + dx[d];
        int ny = y + dy[d];
        if (valid(nx, ny, d))
        {
          Q.push(state(dist + 1, nx, ny, d, dist_b + 1));
        }
      }
      else
      {
        for (auto k = 0; k < 4; k++)
        {
          D[x][y][k] = dist;
          if (k == 0)
          {
            cerr << "D[" << x << "][" << y << "] = " << D[x][y][k] << endl;
          }
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (valid(nx, ny, k))
          {
            Q.push(state(dist + dist_b + 1, nx, ny, k, dist_b + 1));
          }
        }
      }
    }
  }
  for (auto i = 0; i < H; i++)
  {
{'fraction_non_alphanumeric': 0.23374854028804984, 'fraction_numerical': 0.039509536784741145, 'mean_word_length': 2.0105448154657295, 'pattern_counts': {'":': 0, '<': 155, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6574433', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2174, 'n_words': 597}