criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int X, Y, n;

struct Memo
{
	int b;
	int k;
};

struct Point
{
	int x;
	int y;
};

struct Node
{
	int idx;
	int a[10][10];
};

class memo_greater
{
public:
	bool operator() (const Memo m1, const Memo m2)
	{
		return m1.k > m2.k;
	}
};

Point P[15];
Memo M[15];
int A[10][10];

bool is_able(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			if(i<0 || j<0 || i>=X || j>=Y) return false;
			if(a[j][i]!=0 && a[j][i]!=idx) return false;
		}
	}

	return true;
}

void set(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			a[j][i] = idx;
		}
	}
}

bool is_ans()
{
	for(int y=0; y<Y; y++)
	{
		for(int x=0; x<X; x++)
		{
			if(A[y][x]==0)
			{
				return false;	
			}
		}
	}

	return true;
}

bool solve()
{
	queue<Node> que;
	int b, k, i, j, mem_size;
	Point p;

	bool is_ok;
	mem_size = sizeof(int) * 100;
	sort(&M[0], &M[n-1], memo_greater());
	Node nn;
	nn.idx = 0;
	memcpy(nn.a, A, mem_size);

	que.push(nn);

	is_ok = false;
	while(!que.empty())
	{
		nn = que.front();
		que.pop();

		if(nn.idx==n)
		{
			if(!is_ok)
			{
				memcpy(A, nn.a, mem_size);
				is_ok = true;
			}
			else{
				return false;
			}
		}

		b = M[nn.idx].b;
		k = M[nn.idx].k;
		p = P[b-1];

		for(i=1; i<=k; i++)
		{
			if(k%i!=0) continue;

			j = k / i;
			for(int dy=0; dy<j; dy++)
			{
				for(int dx=0; dx<i; dx++)
				{
					if(is_able(nn.a, p.x-dx, p.y-dy, i, j, b))
					{
						Node node;
						memcpy(node.a, nn.a, mem_size);
						set(node.a, p.x-dx, p.y-dy, i, j, b);
						node.idx = nn.idx+1;
						que.push(node);
					}
				}
			}
		}
	}

	return true;
}

int main(int argc, char** argv)
{
	while( 1 )
	{
		cin >> X >> Y >> n;
		if(!(X || Y || n)) break;

		for(int i=0; i<n; i++)
		{
			cin >> M[i].b >> M[i].k;
		}

		for(int y=0; y<Y; y++)
		{
			for(int x=0; x<X; x++)
			{
				cin >> A[y][x];
				if(A[y][x] != 0)
				{
					P[A[y][x]-1].x = x;
					P[A[y][x]-1].y = y;
				}
			}
		}

		if(solve())
		{	
			for(int y=0; y<Y; y++)
			{
				for(int x=0; x<X; x++)
				{
					cout << A[y][x];
					if(x!=X-1) cout << " ";
				}
				cout << endl;
			}
		}
		else
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Compiler output:
a.cc: In function 'bool solve()':
a.cc:92:9: error: 'memcpy' was not declared in this scope
   92 |         memcpy(nn.a, A, mem_size);
      |         ^~~~~~
a.cc:4:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <queue>
  +++ |+#include <cstring>
    4 |
Language: C++

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <queue>

using namespace std;

int X, Y, n;

struct Memo
{
	int b;
	int k;
};

struct Point
{
	int x;
	int y;
};

struct Node
{
	int idx;
	int a[10][10];
};

class memo_greater
{
public:
	bool operator() (const Memo m1, const Memo m2)
	{
		return m1.k > m2.k;
	}
};

Point P[15];
Memo M[15];
int A[10][10];

bool is_able(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			if(i<0 || j<0 || i>=X || j>=Y) return false;
			if(a[j][i]!=0 && a[j][i]!=idx) return false;
		}
	}

	return true;
}

void set(int a[10][10], int x, int y, int w, int h, int idx)
{
	for(int j=y; j<y+h; j++)
	{
		for(int i=x; i<x+w; i++)
		{
			a[j][i] = idx;
		}
	}
}

bool is_ans()
{
	for(int y=0; y<Y; y++)
	{
		for(int x=0; x<X; x++)
		{
			if(A[y][x]==0)
			{
				return false;	
			}
		}
	}

	return true;
}

bool solve()
{
	queue<Node> que;
	int b, k, i, j, mem_size;
	Point p;

	bool is_ok;
	mem_size = sizeof(int) * 100;
	sort(&M[0], &M[n-1], memo_greater());
	Node nn;
	nn.idx = 0;
	memcpy(nn.a, A, mem_size);

	que.push(nn);

	is_ok = false;
	while(!que.empty())
	{
		nn = que.front();
		que.pop();

		if(nn.idx==n)
		{
			if(!is_ok)
			{
				memcpy(A, nn.a, mem_size);
				is_ok = true;
			}
			else{
				return false;
			}
		}

		b = M[nn.idx].b;
		k = M[nn.idx].k;
		p = P[b-1];

		for(i=1; i<=k; i++)
		{
			if(k%i!=0) continue;

			j = k / i;
			for(int dy=0; dy<j; dy++)
			{
				for(int dx=0; dx<i; dx++)
				{
					if(is_able(nn.a, p.x-dx, p.y-dy, i, j, b))
					{
						Node node;
						memcpy(node.a, nn.a, mem_size);
						set(node.a, p.x-dx, p.y-dy, i, j, b);
						node.idx = nn.idx+1;
						que.push(node);
					}
				}
			}
		}
	}

	return true;
}

int main(int argc, char** argv)
{
	while( 1 )
	{
		cin >> X >> Y >> n;
		if(!(X || Y || n)) break;

		for(int i=0; i<n; i++)
		{
			cin >> M[i].b >> M[i].k;
		}

		for(int y=0; y<Y; y++)
		{
			for(int x=0; x<X; x++)
			{
				cin >> A[y][x];
				if(A[y][x] != 0)
				{
					P[A[y][x]-1].x = x;
					P[A[y][x]-1].y = y;
				}
			}
		}

		if(solve())
		{	
			for(int y=0; y<Y; y++)
			{
				for(int x=0; x<X; x++)
				{
					cout << A[y][x];
					if(x!=X-1) cout << " ";
				}
				cout << endl;
			}
		}
		else
		{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Compiler output:
a.cc: In function 'bool solve()':
a.cc:93:9: error: 'memcpy' was not declared in this scope
   93 |         memcpy(nn.a, A, mem_size);
      |         ^~~~~~
a.cc:5:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include <queue>
  +++ |+#include <cstring>
    5 |
Language: C

def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end
def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end
def x a,b
(0..3).any?{|k|
(0..3).map{|m|z a[m*2-2,2],a[m*2,2],a[m*2-2,2],b[k*2,2]}.all?{|m|m<=0}||
(0..3).map{|m|z b[m*2-2,2],b[m*2,2],b[m*2-2,2],a[k*2,2]}.all?{|m|m<=0}||
(0..3).any?{|m|xx a[k*2-2,2],a[k*2,2],b[m*2-2,2],b[m*2,2]}
}end
while(n=gets.to_i)>0
n.times{a=[*0..gets.to_i-1]
l=a.map{gets.split.map &:to_i}
a.map{|i|(i+1..a[-1]).map{|j|x(l[i],l[j])&&(b=[]
i=a[i]while(b<< i;a[i]!=i)
j=a[j]while(b<< j;a[j]!=j)
b.map{|k|a[k]=[i,j].min})}}
a.map!{|i|i=a[i]while a[i]!=i;i}
p a.uniq.size}end

Compiler output:
main.c:1:1: error: unknown type name 'def'
    1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end
      | ^~~
main.c:1:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a'
    1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end
      |       ^
main.c:1:20: error: expected ')' before '-' token
    1 | def z a,b,c,d;(b[0]-a[0])*(d[1]-c[1])-(d[0]-c[0])*(b[1]-a[1])end
      |                    ^
      |                    )
main.c:2:18: error: expected ')' before '=' token
    2 | def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end
      |                  ^
      |                  )
main.c:2:67: error: unknown type name 'end'
    2 | def xx a,b,c,d;(v=z a,b,c,d)!=0&&z(a,c,a,b)/v==0&&z(a,c,c,d)/v==0;end
      |                                                                   ^~~
main.c:3:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'x'
    3 | def x a,b
      |     ^
main.c:3:5: error: unknown type name 'x'
main.c:4:2: error: too many decimal points in number
    4 | (0..3).any?{|k|
      |  ^~~~
main.c:5:2: error: too many decimal points in number
    5 | (0..3).map{|m|z a[m*2-2,2],a[m*2,2],a[m*2-2,2],b[k*2,2]}.all?{|m|m<=0}||
      |  ^~~~
main.c:6:2: error: too many decimal points in number
    6 | (0..3).map{|m|z b[m*2-2,2],b[m*2,2],b[m*2-2,2],a[k*2,2]}.all?{|m|m<=0}||
      |  ^~~~
main.c:7:2: error: too many decimal points in number
    7 | (0..3).any?{|m|xx a[k*2-2,2],a[k*2,2],b[m*2-2,2],b[m*2,2]}
      |  ^~~~
main.c:9:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'while'
    9 | while(n=gets.to_i)>0
      | ^~~~~
main.c:10:13: error: too many decimal points in number
   10 | n.times{a=[*0..gets.to_i-1]
      |             ^~~~~~~~~~~~
main.c:12:13: error: too many decimal points in number
   12 | a.map{|i|(i+1..a[-1]).map{|j|x(l[i],l[j])&&(b=[]
      |             ^~~~
main.c:17:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
   17 | p a.uniq.size}end
      | ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef complex < double > P;
typedef vector< P > G;
vector< G > g;
const double EPS = 1e-8;
const double INF = 1e12;
double cross(const P& a,const P& b){ //??????
  return imag(conj(a) * b);
}
double dot(const P& a,const P& b){ // ??????
  return real(conj(a) * b);
}
struct L: vector < P >{
  L(const P& a,const P& b){
    push_back(a);
    push_back(b);
  }
};
int ccw(P a,P b,P c){
  b -= a; c -= a;
  if(cross(b,c) > 0) return 1;
  if(cross(b,c) < 0) return -1;
  if(dot(b,c) < 0) return 2; // c--a--b
  if(norm(b) < norm(c)) return -2; // a--b--c
  return 0; // a--c--b
}
bool intersectSS(const L& s,const L& t){ //???????????? ??????:??????
  return ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0;
}
#define curr(P,i) P

Compiler output:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
Language: C++

#include <set>
#include <cstdio>
#include <queue>
#include <iostream>
#include <complex>
#include <vector>
#include <climits>
#include <cfloat>

#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef complex<double> P;
typedef vector<P> Polygon;
const double EPS = 1e-10;

class UnionFind{
private:
  vector<int> id;

  int getId(int i){
    if(i == id[i]) return i;
    return id[i] = getId(id[i]);
  }
public:
  UnionFind(int size = 0){ init(size); }
  ~UnionFind(){}
  void init(int size){
    id = vector<int>(size);
    for(int i = 0; i < size; i++)
      id[i] = i;
  }
  void unite(int i, int j){
    int next = min( getId(i), getId(j) );
    id[getId(i)] = id[getId(j)] = next;
  }
  int operator [](int i){ return getId(i); }
  int count(){
    set<int> s;
    for(int i = 0; i < (int)id.size(); i++)
      s.insert(getId(i));
    return s.size();
  }
};

struct S{
  P p1;
  P p2;
  S(P p,P q) : p1(p), p2(q) {}
};

bool intersect(const S &s, const P &p){
  return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs
}

bool contain(const Polygon &g, const P &p){
  double sum = 0.0;
  int n = g.size();
  for(int i = 0; i < n; i++){
    int j = (i + 1) % n;
    if(intersect(S(g[i], g[j]), p))
      return true;
    sum += arg((g[j] - p) / (g[i] - p));
  }
  return std::abs(sum) > 1.0; // 0 or 2 PI
}

bool intersect(const Polygon &p1, const Polygon &p2){
  int n = p2.size();
  int m = p1.size();
  for(int i = 0; i < n; i++)
    if(contain(p1, p2[i])) return true;
  for(int i = 0; i < m; i++)
    if(contain(p2, p1[i])) return true;
  return false;
}

int main(){
  int t;
  while(scanf("%d", &t), t){
    while(t --> 0){
      int n; scanf("%d", &n);
      UnionFind uf(n);
      vector<Polygon> ps(n);

      REP(i,n){
        vector<P> pos(4);
        REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos
        ps[i] = pos;

        REP(j,i) if(intersect(ps[i], ps[j])){
          //printf("cross: %d %d\n", i, j);
          uf.unite(i, j);
        }
      }

      printf("%d\n", uf.count());
    }
  }
  return 0;
}

Compiler output:
a.cc: In function 'bool intersect(const S&, const P&)':
a.cc:54:49: error: invalid operands of types 'double' and '<unresolved overloaded function type>' to binary 'operator-'
   54 |   return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:54:54: error: expected ';' before '}' token
   54 |   return std::abs(abs(s.p1 - p) + abs(s.p2 - p) - abs
      |                                                      ^
      |                                                      ;
   55 | }
      | ~                                                     
a.cc: In function 'int main()':
a.cc:89:46: error: lvalue required as unary '&' operand
   89 |         REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos
      |                                   ~~~~~~~~~~~^~
a.cc:89:54: error: expected ')' before 'ps'
   89 |         REP(j,4) scanf("%lf%lf", &pos[j].real(), &pos
      |                       ~                              ^
      |                                                      )
   90 |         ps[i] = pos;
      |         ~~
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>

const double EPS = 1e-24;

struct P{
	double x, y;
	P operator-(const P& rp);
	bool operator==(const P& rp);
};

P P::operator-(const P& rp){
	return {x-rp.x, y-rp.y};
}

bool P::operator==(const P& rp){
	return abs(x-rp.x) < EPS && abs(y-rp.y) < EPS;
}

typedef P Vector;

double dotProduct(Vector v1, Vector v2){
	return v1.x * v1.y + v2.x * v2.y;
}

double crossProduct(Vector v1, Vector v2){
	return v1.x * v2.y - v2.x * v1.y;
}

double abs(P p){
	return sqrt(p.x * p.x + p.y * p.y);
}

struct Rectangle{
	P ps[4];
};

class UnionFind{
public:
	int size;
	std::vector<int> par, rank;
	UnionFind(int _size);
	int find(int x);
	void unite(int x, int y);
};

UnionFind::UnionFind(int _size)
	:par(_size), rank(_size), size(_size){
	for(int i=0;i<size;i++){
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x){
	if(par[x] == x){
		return x;
	}
	return par[x] = find(par[x]);
}

void UnionFind::unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y)return;//もう併合している

	if(rank[x] < rank[y]){
		par[x] = par[y];
	}else{
		par[y] = par[x];
		if(rank[x] == rank[y]){
			rank[x]++;
		}
	}
}

bool kousa(Rectangle r1, Rectangle r2){
	for(int k=2;k;k--){
		for(int i=0;i<4;i++){
			P c = r1.ps[i];
			int count = 0;
			for(int j=0;j<4;j++){
				P a = r2.ps[j], b = r2.ps[(j+1)%4];

				if(a == c || b == c || (abs(crossProduct(b-a, c-a)) < EPS) && dotProduct(b-a, c-a) > -EPS && abs(b-a) < abs(c-a) + EPS){//四角形の線分上
					return true;
				}

				if(crossProduct(b-a, c-a) > -EPS){
					count++;
				}else{
					count--;
				}
			}
			if(abs(count) == 4){
				return true;
			}
		}
		std::swap(r1, r2);
	}

	return false;
}

int main(){
	int n;
	while(std::cin >> n, n){
		int res[100];
		for(int k=0;k<n;k++){
			int m;
			std::cin >> m;

			Rectangle rs[100];
			for(int i=0;i<m;i++){
				P (&ps)[4] = rs[i].ps;
				for(int j=0;j<4;j++){
					std::cin >> ps[j].x >> ps[j].y;
				}
			}

			UnionFind uf(100);
			for(int i=0;i<m;i++){
				for(int j=i+1;j<m;j++){
					if(kousa(rs[i], rs[j])){//片方灯せばいいかなー
						uf.unite(i, j);//併合
					}
				}
			}

			std::set<int> s;//大元さん
			for(int i=0;i<m;i++){
				s.insert(uf.find(i));
			}

			std::cout << s.size() << std::endl;
		}
	}
}

Compiler output:
a.cc: In function 'double abs(P)':
a.cc:33:16: error: 'sqrt' was not declared in this scope
   33 |         return sqrt(p.x * p.x + p.y * p.y);
      |                ^~~~
Language: Java

### constant

MAX_INT = (1 << 31) - 1

### subroutines

def dist(nd0, nd1)
  (nd0[0] - nd1[0]).abs + (nd0[1] - nd1[1]).abs
end

### main

while true
  w, h = gets.strip.split(' ').map{|s| s.to_i}
  break if w == 0 && h == 0

  nodes = 7.times.map{[]}
  start = nil
  goal = nil

  for y in (0...h)
    hl = gets.strip.split('')
    for x in (0...w)
      case hl[x]
      when 'S'
        start = [x, y, 0]
        nodes[5] << start
      when 'G'
        goal = [x, y, MAX_INT]
        nodes[6] << goal
      when '1'..'5'
        attr = hl[x].to_i - 1
        nodes[attr] << [x, y, MAX_INT]
      end
    end
  end

  min_dist = MAX_INT
  min_attr = nil

  for sattr in (0..4)
    attrs = [5] + (1..4).map{|k| (sattr + k) % 5} + [6]

    start[2] = 0
    goal[2] = MAX_INT

    for k in (1..5)
      prev_attr = attrs[k - 1]
      attr0 = attrs[k]

      for nd0 in nodes[attr0]
        min_dist0 = MAX_INT
        for p_nd in nodes[prev_attr]
          d = p_nd[2] + dist(p_nd, nd0)
          min_dist0 = d if min_dist0 > d
        end

        nd0[2] = min_dist0
      end
    end

    if goal[2] < MAX_INT && min_dist > goal[2]
      min_dist = goal[2]
      min_attr = sattr
    end
  end

  if min_attr.nil?
    puts 'NA'
  else
    puts [min_attr + 1, min_dist].join(' ')
  end
end

Compiler output:
Main.java:1: error: illegal character: '#'
### constant
^
Main.java:1: error: illegal character: '#'
### constant
 ^
Main.java:1: error: illegal character: '#'
### constant
  ^
Main.java:3: error: class, interface, enum, or record expected
MAX_INT = (1 << 31) - 1
^
Main.java:5: error: illegal character: '#'
### subroutines
^
Main.java:5: error: illegal character: '#'
### subroutines
 ^
Main.java:5: error: illegal character: '#'
### subroutines
  ^
Main.java:11: error: illegal character: '#'
### main
^
Main.java:11: error: illegal character: '#'
### main
 ^
Main.java:11: error: illegal character: '#'
### main
  ^
Main.java:21: error: illegal '.'
  for y in (0...h)
               ^
Main.java:22: error: empty character literal
    hl = gets.strip.split('')
                          ^
Main.java:23: error: illegal '.'
    for x in (0...w)
                 ^
Main.java:31: error: illegal '.'
      when '1'..'5'
               ^
Main.java:69: error: unclosed character literal
    puts 'NA'
         ^
Main.java:69: error: illegal line end in character literal
    puts 'NA'
            ^
16 errors
Language: Java

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Dijkstra {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	}
}

Compiler output:
Main.java:10: error: class Dijkstra is public, should be declared in a file named Dijkstra.java
public class Dijkstra {
       ^
1 error
Language: Java

import java.awt.Point;
import java.util.Scanner;

public class Dijkstra {

	/** ????§??????? */
	static final String WHITE_SPACE = " ";

	/** ??????????????????_X */
	static int mapSizeX = 0;

	/** ??????????????????_Y */
	static int mapSizeY = 0;

	/** ??????????????° */
	static int maxNode = 0;

	/** ????????? */
	static String[] map = new String[1000 * 1000];

	/** ????????¢??????????????? */
	/** ????????? */
	//	static List<Point> pachimonList = new ArrayList<Point>();
	static Point[] pachimonList = new Point[1000 * 1000];

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextLine()) {
			readMap(scanner);
		}

	}

	/**
	 * ?????????????????????????????????
	 * @param scanner ????????£??????
	 */
	private static void readMap(Scanner scanner) {
		String[] mapSizeLine = scanner.nextLine().split(WHITE_SPACE);
		if (mapSizeLine.length < 2) {
			return;
		}

		// ??????????????±????????????
		//		pachimonList.removeAll(pachimonList);
		maxNode = 0;
		mapSizeX = Integer.parseInt(mapSizeLine[0]);
		mapSizeY = Integer.parseInt(mapSizeLine[1]);
		//		initializeMap(mapSizeX, mapSizeY);

		while (scanner.hasNextLine()) {
			for (int i = 0; i < mapSizeY; i++) {
				String mapInfoLine = scanner.nextLine();
				mapInfoLine = mapInfoLine.replaceAll(".", "9");
				mapInfoLine = mapInfoLine.replaceAll("S", "0");
				mapInfoLine = mapInfoLine.replaceAll("G", "6");
				for (int j = 0; j < mapSizeX; j++) {
					int val = Integer.valueOf(mapInfoLine.charAt(j));
					if (val < 9) {
						// ???????????¢????????°????¨????
						pachimonList[maxNode] = createPos(Integer.valueOf(val), calcIndex(j, i));
						maxNode++;
					}
				}
			}
		}

		//		Collections.sort(pachimonList, new Comparator<Point>() {
		//			@Override
		//			public int compare(Point o1, Point o2) {
		//				return o1.x - o2.x;
		//			}
		//		});
	}

	/**
	 * ??????????????¨??????????´???????????????§?????????
	 */
	private static void initializeMap(int sizeX, int sizeY) {
		for (int i = 0; i < sizeX * sizeY; i++) {
			map[i] = "";
		}
	}

	/**
	 * X????????????????????´?????????????????¢???????±???§????¨????<br>
	 * ????????????:0?????´??????:6???????????¢???????±???§:1???5<br>
	 * Y????????????????????????????????????????´?
	 * @param type ?????????????????´?????????????????¢???????±???§
	 * @param index ??????????????????????????????
	 * @return
	 */
	private static Point createPos(int type, int index) {
		return new Point(type, index);
	}

	/**
	 * X??§?¨???¨Y??§?¨???????????????£?????????????????????????????????????????´?????????
	 *
	 * @param x X??§?¨?
	 * @param y Y??§?¨?
	 * @return
	 */
	private static int calcIndex(int x, int y) {
		return x * mapSizeY + y;
	}
}

Compiler output:
Main.java:4: error: class Dijkstra is public, should be declared in a file named Dijkstra.java
public class Dijkstra {
       ^
1 error
Language: Java


import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class P0215 {

	int INF = 1 << 28;
	int[][] map;
	P s, g;
	int w, h, node;
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			LinkedList<P>[] d = new LinkedList[5];
			for(int i=0;i<5;i++) d[i] = new LinkedList<P>();
			
			node = 0;
			for(int i=0;i<h;i++) {
				String str = sc.next();
				for(int j=0;j<str.length();j++) {
					switch(str.charAt(j)) {
					case 'S': s = new P(j, i, node); break;
					case 'G': g = new P(j, i, node); break;
					case '.': continue;
					default : d[str.charAt(j)-'1'].add(new P(j, i, node));
					}
					node++;
				}
			}
			map = new int[node][node];
			for(int[] a: map) fill(a, INF);
			for(LinkedList<P> list: d) {
				for(P p: list) {
					map[s.ind][p.ind] = abs(s.x-p.x) + abs(s.y-p.y);
					map[p.ind][g.ind] = abs(p.x-g.x) + abs(p.y-g.y);
				}
			}
			for(int i=0;i<5;i++) {
				for(P p1: d[i]) for(P p2: d[(i+1)%5]) {
					map[p1.ind][p2.ind] = abs(p1.x-p2.x) + abs(p1.y-p2.y);
				}
			}
			int min = dijkstra();
			if(min == INF) System.out.println("NA");
			else {
				int p = g.ind;
				while(visit[p] != s.ind) {
					p = visit[p];
				}
				for(int i=0;i<5;i++) {
					boolean f = false;
					for(P p1: d[i]) {
						if(p1.ind == p) {
							f = true;
							break;
						}
					}
					if(f) {
						System.out.println(i + " " +  min);
						break;
					}
				}
			}
		}
	}
	int visit[];
	int dijkstra() {
		int[] d = new int[node];
		boolean visited[] = new boolean[node];
		visit = new int[node];
		fill(visited, false);
		fill(d, INF);
		d[s.ind] = 0;
		for(;;) {
			int v = -1;
			int min = INF;
			for(int i=0;i<node;i++) {
				if( min > d[i] && !visited[i] ) {
					v = i;
					min = d[i];
				}
			}
			if(v < 0) break;
			if(v == g.ind) break;
			visited[v] = true;
			for(int u=0;u<node;u++) {
				if(d[u] > d[v] + map[v][u]) {
					d[u] = d[v] + map[v][u];
					visit[u] = v;
				}
			}
		}
		return d[g.ind];
	}

	public static void main(String[] args) {
		new P0215().run();
	}
	
	class P {
		int x, y, ind;
		P(int x, int y, int ind) {
			this.x = x;
			this.y = y;
			this.ind = ind;
		}
	}
}

Compiler output:
Main.java:7: error: class P0215 is public, should be declared in a file named P0215.java
public class P0215 {
       ^
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
Language: C

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

struct State{
	int i,j,cost,bit;
	State(){}
	State(int i,int j,int c,int b):i(i),j(j),cost(c),bit(b){}
};

int solve(vs& grid,pii start,pii goal,int firstbit)
{
	int h=grid.size(),w=grid[0].size();
	vector<vvi> vis(h,vvi(w,vi(1<<5)));
	queue<State> q;
	q.push(State(start.first,start.second,0,firstbit));
	while(q.size()){
		State cur=q.front(); q.pop();
		
		if(cur.bit==31 && mp(cur.i,cur.j)==goal)
			return cur.cost;
		if(vis[cur.i][cur.j][cur.bit])
			continue;
		vis[cur.i][cur.j][cur.bit]=1;
		
		int di[]={-1,1,0,0},dj[]={0,0,-1,1};
		rep(k,4){
			int ni=cur.i+di[k],nj=cur.j+dj[k];
			if(ni<0 || h<=ni || nj<0 || w<=nj)
				continue;
			if(grid[ni][nj]=='.')
				q.push(State(ni,nj,cur.cost+1,cur.bit));
			else{
				int m=grid[ni][nj]-'1';
				if(cur.bit&(1<<(m+4)%5))
					q.push(State(ni,nj,cur.cost+1,cur.bit|1<<m));
				else
					q.push(State(ni,nj,cur.cost+1,cur.bit));
			}
		}
	}
	return INFTY;
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		
		pii start,goal;
		rep(i,h) rep(j,w){
			if(grid[i][j]=='S'){
				start=mp(i,j);
				grid[i][j]='.';
			}
			if(grid[i][j]=='G'){
				goal=mp(i,j);
				grid[i][j]='.';
			}
		}
		
		pii res(INFTY,-1);
		rep(i,5){
			int tmp=solve(grid,start,goal,1<<i);
			res=min(res,mp(tmp,i));
		}
		
		if(res.second==-1)
			cout<<"NA"<<endl;
		else
			cout<<res.second+1<<' '<<res.first<<endl;
	}
	
	return 0;
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.
Language: C++

import java.util.*;

@SuppressWarnings("unchecked")
class Main{

    int w, h;
    //char[][] map;
    ArrayList[] list;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt(); h = sc.nextInt();
            if(w==0 && h==0) break;

            list = new ArrayList[5];
            for(int i=0; i<5; i++) list[i] = new ArrayList<int[]>();

            int sx = 0, sy = 0;
            int gx = 0, gy = 0;
            for(int i=0; i<h; i++){
                char[] line = sc.next().toCharArray();
                for(int j=0; j<w; j++){
                    if(line[j]=='S'){ sx = j; sy = i;}
                    if(line[j]=='G'){ gx = j; gy = i;}
                    if(Character.isDigit(line[j])) list[line[j]-'1'].add(new int[]{j, i});
                }
            }

            int idx = 0, min = Integer.MAX_VALUE;
            for(int i=0; i<5; i++){
                int num = bfs(sx, sy, gx, gy, i);
                if(num==-1) continue;
                if(num<min){
                    min = num;
                    idx = i;
                }
            }
            idx++;
            if(min==Integer.MAX_VALUE) System.out.println("NA");
            else System.out.println(idx+" "+min);
        }
    }

    int bfs(int sx, int sy, int gx, int gy, int pati){
        //pos, nextpati, dist
        PriorityQueue<int[]> q = new PriorityQueue<int[]>(10, new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    return a[3] - b[3];
                }
            });
        q.add(new int[]{sx, sy, (pati+1)%5, 0});

        while(q.size()>0){
            int[] qq = q.poll();
            int x = qq[0], y = qq[1], nextpati = qq[2], dist = qq[3];

            if(nextpati==pati) return dist;

            for(int i=0; i<list[nextpati].size(); i++){
                int[] qqq = (int[])list[nextpati].get(i);
                int nx = qqq[0], ny = qqq[1];
                int ndist = dist+Math.abs(x-nx)+Math.abs(y-ny);
                if((nextpati+1)%5==pati) ndist += Math.abs(nx-gx)+Math.abs(ny-gy);
                q.add(new int[]{nx, ny, (nextpati+1)%5, ndist});
            }
        }
        return -1;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Compiler output:
a.cc:3:1: error: stray '@' in program
    3 | @SuppressWarnings("unchecked")
      | ^
a.cc:1:1: error: 'import' does not name a type
    1 | import java.util.*;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:18: error: expected constructor, destructor, or type conversion before '(' token
    3 | @SuppressWarnings("unchecked")
      |                  ^
Language: C++

#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
#define F first
#define S second
using namespace std;
 
int sx, sy, gx, gy;
typedef pair < int, int > P;
vector < P > v[5];
int memo[5][5][1111];

int dist(P a, P b){
  return abs(a.F - b.F) + abs(a.S - b.S);
}


int solve(int cnt, int now, int p){
 
  if(cnt == 4) return dist(v[now][p], P(gx, gy));
  if(memo[cnt][now][p]) return memo[cnt][now][p];
 
  int ans = INF, next = (now+1)%5, cost;
  for(int i=0;i<v[next].size();i++){
    if(!cnt) cost = dist(P(sx, sy), v[next][i]);
    else cost = dist(v[now][p], v[next][i]);
    ans = min(ans, solve(cnt+1, next, i) + cost);
  }
 
  return memo[cnt][now][p] = ans;
}
 
int main(){
 
  int w, h;
  char c;
 
  while(scanf("%d %d", &w, &h), w){
    
    for(int i=0;i<5;i++) v[i].clear();
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == '.') continue;
	else if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else v[c-'1'].push_back( P(j,i) );
      }
    }
    
    int a, b = INF;
    for(int i=0;i<5;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i+1, b = solve(0,i,0);
    }
 
    b == INF:puts("NA"):printf("%d %d\n", a, b);
 
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:61:13: error: expected ';' before ':' token
   61 |     b == INF:puts("NA"):printf("%d %d\n", a, b);
      |             ^
Language: C++

#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int L = 5;
const int MAX_H = 1010;
const int MAX_W = 1010;
const int INF = 1e9 + 7;

class C{
  public:
    int y, x, cnt, fir, bit;
    C(){}
    C(int yy, int xx, int cc, int ff, int bb) { y = yy; x = xx; cnt = cc; fir = ff; bit = bb; }
};

int W, H;
int my[] = {0, 0, 1, -1};
int mx[] = {1, -1, 0, 0};
int closed[MAX_H][MAX_W][(1 << L)];

bool check(int bit, int m){
  int tar = (m == 0 ? 4 : m - 1);
  if(bit & (1 << tar)) return true;
  return false;
}

P solve(int sy, int sx, int gy, int gx, vector< vector<int> > &v){
  queue<C> open;
  REP(i, MAX_H) REP(j, MAX_W) REP(k, L) REP(l, (1 << L)) closed[i][j][k][l] = INF;
  //REP(i, L){
  //  open.push(C(sy, sx, 0, i, (1 << i)));
  //  closed[sy][sx][i][(1 << i)] = 0;
  //}
  //while(!open.empty()){
  //  C c = open.front(); open.pop();
  //  REP(i, 4){
  //    int ny = c.y + my[i], nx = c.x + mx[i];
  //    if(ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
  //    int nb = c.bit;
  //    if(v[ny][nx] != -1 && check(c.bit, v[ny][nx])) nb |= (1 << v[ny][nx]);
  //    if(closed[ny][nx][c.fir][nb] <= c.cnt + 1) continue;
  //    closed[ny][nx][c.fir][nb] = c.cnt + 1;
  //    open.push(C(ny, nx, c.cnt + 1, c.fir, nb));
  //  }
  //}
  P res = P(INF, INF);
  //REP(i, L) if(closed[gy][gx][i][(1 << L) - 1] < res.second) res = P(i + 1, closed[gy][gx][i][(1 << L) - 1]);
  return res;
}

int main() {
  while(cin >>W >>H && W && H){
    int sy, sx, gy, gx;
    vector< vector<int> > v(H, vector<int>(W));
    REP(i, H){
      REP(j, W){
        char c; cin >>c;
        if(c == 'S') { sy = i; sx = j; v[i][j] = -1; }
        else if(c == 'G') { gy = i; gx = j; v[i][j] = -1; }
        else if(c == '.') { v[i][j] = -1; }
        else { v[i][j] = c - '0' - 1; }
      }
    }
    P res = solve(sy, sx, gy, gx, v);
    if(res.first == INF) cout <<"NA" <<endl;
    else cout <<res.first <<" " <<res.second <<endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'P solve(int, int, int, int, std::vector<std::vector<int> >&)':
a.cc:51:73: error: invalid types 'int[int]' for array subscript
   51 |   REP(i, MAX_H) REP(j, MAX_W) REP(k, L) REP(l, (1 << L)) closed[i][j][k][l] = INF;
      |                                                                         ^
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>

using namespace std;

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

struct Data
{
	int x, y, dist, state;
	Data() {}
	Data(int _x, int _y, int _dist, int _state)
	{
		x = _x;
		y = _y;
		dist = _dist;
		state = _state;
	}
};

struct MockQueue
{
	Data *data;
	int head, tail;
	MockQueue(int size)
	{
		data = new Data[size];
		head = tail = 0;
	}
	
	void Enqueue(Data &d)
	{
		data[tail++] = d;
	}

	Data Dequeue()
	{
		return data[head++];
	}
};

char fld[1000][1000];
bool isUsed[5][1000][1000];

inline int GetNext(int n)
{
	return (n == 4) ? 0 : n + 1;
}

inline int GetPrev(int n)
{
	return (n == 0) ? 4 : n - 1;
}

signed main()
{
	int W, H;
	while (cin >> W >> H, W || H)
	{
		int sx, sy, gx, gy;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				scanf(" %c", &fld[i][j]);
				if (fld[i][j] == 'S')
				{
					sx = j;
					sy = i;
				}
				else if (fld[i][j] == 'G')
				{
					gx = j;
					gy = i;
				}
			}
		}
		
		int mi = INT_MAX / 2, ans;
		for (int i = 0; i < 5; i++)
		{
			MockQueue q(20 * W * H);
			Data qf;
			
			q.Enqueue(Data(sx, sy, 0, i));
			fill_n((bool*)isUsed, 5 * 1000 * 1000, false);
			isUsed[i][sy][sx] = true;
			while (q.head != q.tail)
			{
				qf = q.Dequeue();
				if (qf.x == gx && qf.y == gy && qf.state == GetPrev(i))
				{
					if (mi > qf.dist)
					{
						mi = qf.dist;
						ans = i;
						break;
					}
				}
				for (int j = 0; j < 4; j++)
				{
					int nx = qf.x + dx[j];
					int ny = qf.y + dy[j];
					if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
					int state = qf.state;
					if (isUsed[state][ny][nx]) continue;
					isUsed[state][ny][nx] = true;
					if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state))
					{
						state = GetNext(state);
					}
					q.Enqueue(Data(nx, ny, qf.dist + 1, state));
				}
			}
		}
		if (mi == INT_MAX / 2) puts("NA");
		else printf("%d %d\n", ans, mi);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:93:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data'
   93 |                         q.Enqueue(Data(sx, sy, 0, i));
      |                                   ^~~~~~~~~~~~~~~~~~
a.cc:39:28: note:   initializing argument 1 of 'void MockQueue::Enqueue(Data&)'
   39 |         void Enqueue(Data &d)
      |                      ~~~~~~^
a.cc:120:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data'
  120 |                                         q.Enqueue(Data(nx, ny, qf.dist + 1, state));
      |                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:39:28: note:   initializing argument 1 of 'void MockQueue::Enqueue(Data&)'
   39 |         void Enqueue(Data &d)
      |                      ~~~~~~^
Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>

using namespace std;

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

struct Data
{
	int x, y, dist, state;
	Data() {}
	Data(int _x, int _y, int _dist, int _state)
	{
		x = _x;
		y = _y;
		dist = _dist;
		state = _state;
	}
};

class MockQueue
{
public:
	Data *data;
	int head, tail;
	MockQueue(int size)
	{
		data = new Data[size];
		head = tail = 0;
	}
	
	void Enqueue(Data &d)
	{
		data[tail++] = d;
	}

	Data Dequeue()
	{
		return data[head++];
	}
};

char fld[1000][1000];
bool isUsed[5][1000][1000];

inline int GetNext(int n)
{
	return (n == 4) ? 0 : n + 1;
}

inline int GetPrev(int n)
{
	return (n == 0) ? 4 : n - 1;
}

signed main()
{
	int W, H;
	while (cin >> W >> H, W || H)
	{
		int sx, sy, gx, gy;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				scanf(" %c", &fld[i][j]);
				if (fld[i][j] == 'S')
				{
					sx = j;
					sy = i;
				}
				else if (fld[i][j] == 'G')
				{
					gx = j;
					gy = i;
				}
			}
		}
		
		int mi = INT_MAX / 2, ans;
		for (int i = 0; i < 5; i++)
		{
			MockQueue q(20 * W * H);
			Data qf;
			
			q.Enqueue(Data(sx, sy, 0, i));
			fill_n((bool*)isUsed, 5 * 1000 * 1000, false);
			isUsed[i][sy][sx] = true;
			while (q.head != q.tail)
			{
				qf = q.Dequeue();
				if (qf.x == gx && qf.y == gy && qf.state == GetPrev(i))
				{
					if (mi > qf.dist)
					{
						mi = qf.dist;
						ans = i;
						break;
					}
				}
				for (int j = 0; j < 4; j++)
				{
					int nx = qf.x + dx[j];
					int ny = qf.y + dy[j];
					if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
					int state = qf.state;
					if (isUsed[state][ny][nx]) continue;
					isUsed[state][ny][nx] = true;
					if (isdigit(fld[ny][nx]) && fld[ny][nx] - '1' != i && fld[ny][nx] - '1' == GetNext(state))
					{
						state = GetNext(state);
					}
					q.Enqueue(Data(nx, ny, qf.dist + 1, state));
				}
			}
		}
		if (mi == INT_MAX / 2) puts("NA");
		else printf("%d %d\n", ans, mi);
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:94:35: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data'
   94 |                         q.Enqueue(Data(sx, sy, 0, i));
      |                                   ^~~~~~~~~~~~~~~~~~
a.cc:40:28: note:   initializing argument 1 of 'void MockQueue::Enqueue(Data&)'
   40 |         void Enqueue(Data &d)
      |                      ~~~~~~^
a.cc:121:51: error: cannot bind non-const lvalue reference of type 'Data&' to an rvalue of type 'Data'
  121 |                                         q.Enqueue(Data(nx, ny, qf.dist + 1, state));
      |                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:40:28: note:   initializing argument 1 of 'void MockQueue::Enqueue(Data&)'
   40 |         void Enqueue(Data &d)
      |                      ~~~~~~^
Language: C++

#include <iostream>
#include <vector>
#include <cctype>
#include <queue>
#include <functional>
#include <cmath>
#include <algorithm>

constexpr int MAX = 1000, INF = INT_MAX;

struct edge {
	int toX_, toY_;
	edge() = default;
	edge(int x, int y) : toX_(x), toY_(y) {}
};

struct Node {
	int cost_, x_, y_, num_, cnt_;
	Node() = default;
	Node(int cost, int x, int y, int num, int cnt) : cost_(cost), x_(x), y_(y), num_(num), cnt_(cnt) {}
	
	bool operator<(const Node& rhs) const {
		return (cost_ == rhs.cost_) ? cnt_ < rhs.cnt_ : cost_ < rhs.cost_;
	}

	bool operator > (const Node& rhs) const {
		return (cost_ == rhs.cost_ ? cnt_ > rhs.cnt_ : cost_ > rhs.cost_);
	}
};

int w, h;
int sx, sy, gx, gy;
std::vector<edge> G[5];
int d[MAX][MAX];

int dijkstra(int num) {
	for (int j = 0; j < h; ++j) {
		for (int k = 0; k < w; ++k)
			d[j][k] = INF;
	}

	std::priority_queue<Node, std::vector<Node>,std::greater<Node>> que;

	d[sy][sx] = 0;
	que.emplace(0, sx, sy, num, 1);

	while (!que.empty()) {
		Node node = que.top(); que.pop();
		if (node.cost_ > d[node.y_][node.x_])
			continue;
		if (node.cnt_ == 5)
			return d[node.y_][node.x_] + abs(gx - node.x_) + abs(gy - node.y_);
		edge e;
		for (int i = 0; i < G[node.num_].size(); ++i) {
			e = G[node.num_][i];
			if (d[e.toY_][e.toX_] > d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_)) {
				d[e.toY_][e.toX_] = d[node.y_][node.x_] + abs(e.toX_ - node.x_) + abs(e.toY_ - node.y_);
				que.emplace(d[e.toY_][e.toX_], e.toX_, e.toY_, (node.num_ + 1) % 5, node.cnt_ + 1);
			}
		}
	}
	return -1;
}

int main() {
	while (1) {
		std::cin >> w >> h;
		if (w + h == 0)
			break;
		for (int i = 0; i < 5; ++i)
			G[i].clear();
		char ch;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				std::cin >> ch;
				if (ch == 'S') {
					sx = j;
					sy = i;
				}
				else if (ch == 'G') {
					gx = j;
					gy = i;
				}
				if (std::isdigit(ch)) {
					int num = atoi(&ch);
					--num;
					G[(num + 4) % 5].emplace_back(j, i);
				}
			}
		}
		int ans = INF, v, res;
		for (int i = 0; i < 5; ++i) {
			res = dijkstra(i);
			if (res != -1 && ans > res) {
				ans = res;
				v = i;
			}
		}
		
		if (ans == INF)
			std::cout << "NA" << std::endl;
		else
			std::cout << v + 1 << ' ' << ans << std::endl;
	}
	return 0;
}

Compiler output:
a.cc:9:33: error: 'INT_MAX' was not declared in this scope
    9 | constexpr int MAX = 1000, INF = INT_MAX;
      |                                 ^~~~~~~
a.cc:8:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    7 | #include <algorithm>
  +++ |+#include <climits>
    8 |
Language: C++

#include <iostream>
#include <math.h>

char map[1000 + 2][1000 + 2];

int gx, gy;
int size_x, size_y;
int ans;
int ans_el;

using namespace std;

int calc(int x, int y, int get, int have, int dist)
{
	if (have == get){
		if (dist + abs(x - gx) + abs(y - gy) < ans){
			ans = dist + abs(x - gx) + abs(y - gy);
			ans_el = have;
		}
		return (1);
	}
	if (dist >= ans){
		return (0);
	}
	for (int mx = 1; mx <= size_x; mx++){
		for (int my = 1; my <= size_y; my++){
			if (map[mx][my] - '0' - 1 == get){
				calc(mx, my, (get + 1) % 5, have, dist + abs(x - mx) + abs(y - my));
			}
		}
	}
	
	return (0);
}
 
int main(void)
{
	int sx, sy;
	int have;
	int get;
	
	while (1){
	
	cin >> size_x >> size_y;
	if (size_x == 0 && size_y == 0)break;
	memset(map, -1, size_x * size_y);
	for (int y = 1; y <= size_y; y++){
		ans = 10000000;
		ans_el = -1;
		char str[1001];
		cin >> str;
		for (int x = 1; x <= size_x; x++){
			if (str[x - 1] == 'S'){
				sx = x;
				sy = y;
			}
			if (str[x - 1] == 'G'){
				gx = x;
				gy = y;
			}
			map[x][y] = str[x - 1];
		}
	}
	
	for (int i = 0; i < 5; i++){
		have = i;
		get = (i + 1) % 5;
		calc(sx, sy, get, have, 0);
	}
	
	if (ans_el == -1){
		cout << "NA" << endl;
	}
	else {
		cout << ans_el + 1 << ' ' << ans << endl;
	}
	}
	return (0);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:9: error: 'memset' was not declared in this scope
   46 |         memset(map, -1, size_x * size_y);
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <math.h>
  +++ |+#include <cstring>
    3 |
Language: C++

#include<cstdio>
#include<vector>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;

char field[1000][1001];
int memo[1000][5];

int dis(const pii &a,const pii &b){
	return abs(a.first-b.first)+abs(a.second-b.second);
}

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		pii s,g;
		vector<pii> pach[5];
		for(int i=0;i<h;i++){
			static char field[1001];
			scanf("%s",field);
			for(int j=0;j<w;j++){
				if     (field[j]=='S')	s=mp(i,j);
				else if(field[j]=='G')	g=mp(i,j);
				else if(field[j]=='1')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='2')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='3')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='4')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='5')	pach[field[j]-'1'].pb(mp(i,j));
			}
		}

		int ans=1<<30,bestpartner;
		for(int partner=0;partner<5;partner++){
			int bef=partner,next=(partner+1)%5;
			for(int i=0;i<pach[next].size();i++){
				memo[i][next]=dis(s,pach[next][i]);
			}
			bef=next; next=(next+1)%5;
			for(int k=1;k<4;k++){
				for(int i=0;i<pach[next].size();i++){
					memo[i][next]=1<<30;
					for(int j=0;j<pach[bef].size();j++){
						memo[i][next]=min(memo[i][next],
							memo[j][bef]+dis(pach[bef][j],pach[next][i]));
					}
				}
				bef=next; next=(next+1)%5;
			}
			for(int j=0;j<pach[bef].size();j++){
				int tmp=memo[j][bef]+dis(pach[bef][j],g);
				if(tmp<ans){
					ans=tmp;
					bestpartner=partner;
				}
			}
		}

		if(ans==(1<<30))	puts("NA");
		else	printf("%d %d\n",bestpartner+1,ans);
	}

	return 0;
}

Compiler output:
a.cc: In function 'int dis(const pii&, const pii&)':
a.cc:15:16: error: 'abs' was not declared in this scope
   15 |         return abs(a.first-b.first)+abs(a.second-b.second);
      |                ^~~
Language: C++

#include<cstdio>
#include<vector>

#define	mp	make_pair
#define	pb	push_back

using namespace std;

typedef	pair<int,int>	pii;

int memo[1000][5];

int dis(const pii &a,const pii &b){
	return abs(a.first-b.first)+abs(a.second-b.second);
}

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		pii s,g;
		vector<pii> pach[5];
		for(int i=0;i<h;i++){
			static char field[1001];
			scanf("%s",field);
			for(int j=0;j<w;j++){
				if     (field[j]=='S')	s=mp(i,j);
				else if(field[j]=='G')	g=mp(i,j);
				else if(field[j]=='1')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='2')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='3')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='4')	pach[field[j]-'1'].pb(mp(i,j));
				else if(field[j]=='5')	pach[field[j]-'1'].pb(mp(i,j));
			}
		}

		int ans=1<<30,bestpartner;
		for(int partner=0;partner<5;partner++){
			int bef=partner,next=(partner+1)%5;
			for(int i=0;i<pach[next].size();i++){
				memo[i][next]=dis(s,pach[next][i]);
			}
			bef=next; next=(next+1)%5;
			for(int k=1;k<4;k++){
				for(int i=0;i<pach[next].size();i++){
					memo[i][next]=1<<30;
					for(int j=0;j<pach[bef].size();j++){
						memo[i][next]=min(memo[i][next],
							memo[j][bef]+dis(pach[bef][j],pach[next][i]));
					}
				}
				bef=next; next=(next+1)%5;
			}
			for(int j=0;j<pach[bef].size();j++){
				int tmp=memo[j][bef]+dis(pach[bef][j],g);
				if(tmp<ans){
					ans=tmp;
					bestpartner=partner;
				}
			}
		}

		if(ans==(1<<30))	puts("NA");
		else	printf("%d %d\n",bestpartner+1,ans);
	}

	return 0;
}

Compiler output:
a.cc: In function 'int dis(const pii&, const pii&)':
a.cc:14:16: error: 'abs' was not declared in this scope
   14 |         return abs(a.first-b.first)+abs(a.second-b.second);
      |                ^~~
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
struct P{int x,y,cost;};
#define INF (1<<25)
#define rep(i,n) for(int i=0; i<n ;i++)

int dist(P a,P b){
	return abs(a.x-b.x) + abs(a.y-b.y);
}
int main(){
	int w,h;
	
	while(cin >> w >> h , w) {
		vector<P> data[5];
		P start , goal ;
		
		start.cost = 0 , goal.cost = 0;
		
		rep(i,h)rep(j,w){
			char c;	cin >> c;
			if(c != '.'){
				if(c == 'S')start.x = j , start.y = i;	
				else if(c == 'G')goal.x = j , goal.y = i;
				else P t = {j,i,0} , data[c-'1'].push_back(t);
			}
		}
		int ret = INF , num ;
		
		P dp[5][1000];
		
		rep(lp,5){ // start
			rep(i,5)rep(j,1000){dp[i][j].cost = INF;}
			
			int so = (lp+1)%5;
			rep(i,data[so].size()){
				dp[so][i] = data[so][i];
				dp[so][i].cost = dist(data[so][i],start);
			}
			
			rep(Z,3){ // remain 
				int z = (lp+Z+2)%5;
				int prev = (z+4)%5;
				rep(i,data[prev].size()){ // prev
					rep(j,data[z].size()){ //cur
						int cost = dp[prev][i].cost + dist(dp[prev][i],data[z][j]);
						if(dp[z][j].cost > cost){
							dp[z][j] = data[z][j] , dp[z][j].cost = cost;
						}
					}
				}
			}
			rep(i,data[(lp+4)%5].size() ){
				int kCost = dp[(lp+4)%5][i].cost + dist(dp[(lp+4)%5][i],goal);
				if( kCost < ret){
					ret = kCost , num = lp+1; 
				}
			}
		}
		
		if(ret == INF)cout << "NA" << endl; 
		else cout << num << " " << ret << endl; 
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:65: error: expected initializer before '.' token
   26 |                                 else P t = {j,i,0} , data[c-'1'].push_back(t);
      |                                                                 ^