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

#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <math.h>
#include <stdio.h>

using namespace std;

char c[10001];
int p;

int solve(){

	++p;
	vector<int> v;
	if (isdigit(c[p])){
		int n = atoi(&c[p]);
		p += (int)log10((double)n) + 2;
		return n / 2 + 1;
	}
	while (c[p] == '['){
		int n = solve();
		//cout << n << endl;
		v.push_back(n);
	}
	++p;
	sort(v.begin(), v.end());
	int res = 0;
	for (int i = 0; i < (v.size() + 1) / 2; i++){
		res += v[i];
	}
	
	return res;
}


int main(void){

	int n;
	cin >> n; 
	while (n--){
		scanf("%s", &c);
		p = 0;
		cout << solve() << endl;
	}
	//system("pause");
	return  0;
}#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <string>
#include <ctype.h>
#include <math.h>
#include <stdio.h>

using namespace std;

char c[10001];
int p;

int solve(){

	++p;
	vector<int> v;
	if (isdigit(c[p])){
		int n = atoi(&c[p]);
		p += (int)log10((double)n) + 2;
		return n / 2 + 1;
	}
	while (c[p] == '['){
		int n = solve();
		//cout << n << endl;
		v.push_back(n);
	}
	++p;
	sort(v.begin(), v.end());
	int res = 0;
	for (int i = 0; i < (v.size() + 1) / 2; i++){
		res += v[i];
	}
	
	return res;
}


int main(void){

	int n;
	cin >> n; 
	while (n--){
		scanf("%s", &c);
		p = 0;
		cout << solve() << endl;
	}
	//system("pause");
	return  0;
}

Compiler output:
a.cc:51:2: error: stray '#' in program
   51 | }#include <iostream>
      |  ^
a.cc:51:3: error: 'include' does not name a type
   51 | }#include <iostream>
      |   ^~~~~~~
a.cc:62:6: error: redefinition of 'char c [10001]'
   62 | char c[10001];
      |      ^
a.cc:12:6: note: 'char c [10001]' previously declared here
   12 | char c[10001];
      |      ^
a.cc:63:5: error: redefinition of 'int p'
   63 | int p;
      |     ^
a.cc:13:5: note: 'int p' previously declared here
   13 | int p;
      |     ^
a.cc:65:5: error: redefinition of 'int solve()'
   65 | int solve(){
      |     ^~~~~
a.cc:15:5: note: 'int solve()' previously defined here
   15 | int solve(){
      |     ^~~~~
a.cc:90:5: error: redefinition of 'int main()'
   90 | int main(void){
      |     ^~~~
a.cc:40:5: note: 'int main()' previously defined here
   40 | int main(void){
      |     ^~~~
Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>

#define MAX_N 100

using namespace std;

int N;
char str[10000];

int get_num(int l){
	int res = 0;
	for (int i = l; str[i] != ']'; i++)
	{
		res += (str[i]-'0');
		res *= 10;
	}
	res /= 10;
	return res;
}

int dfs(int l, int r){// "[....]"??¨?????£???????????????(...???)????????°?????????
	if(str[l+1] >= '0' && str[l+1] <= '9') return get_num(l+1)/2+1;
	int a[1000];
	int count = 0;// ??????????????°
	int k = 0, nl = l+1;
	for (int i = l+1; i < r; i++)
	{
		if(str[i] == '['){
			k++;
		}else if(str[i] == ']'){
			k--;
		}
		if(k == 0){
			a[count] = dfs(nl, i);
			nl = i+1;
			count++;
		}
	}
	sort(a, a+count);
	int sum = 0;
	for (int i = 0; i < count/2+1; i++)
	{
		sum += a[i];
	}
	return sum;
}

void solve() {
	int res = dfs(0, strlen(str)-1);
	cout << res << endl;
	return;
}

int main(){
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> str;
		solve();
	}	
	return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:53:26: error: 'strlen' was not declared in this scope
   53 |         int res = dfs(0, strlen(str)-1);
      |                          ^~~~~~
a.cc:6:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include <cmath>
  +++ |+#include <cstring>
    6 |
Language: C++

#include <bits/stdc++.h>
テ「ツ??
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
テ「ツ??
using namespace std;
テ「ツ??
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
テ「ツ??
using ll = long long;
using ld = long double;
テ「ツ??
const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);
テ「ツ??
string s;
int p;
テ「ツ??
int number() {
  int res = 0;
  while (p < (int)s.size() && isdigit(s[p])) {
    res = res * 10 + (int)(s[p] - '0');
    ++p;
  }
  return (res + 1) / 2;
}
テ「ツ??
int expr() {
  ++p;
  int res = 0;
  if (isdigit(s[p])) res = number();
  else {
    vector<int> v;
    while (s[p] != ']') {
      v.push_back(expr());
    }
    sort(ALL(v));
    res = accumulate(begin(v), begin(v) + ((int)v.size() + 1) / 2, 0);
  }
  ++p;
  return res;
}
テ「ツ??
int main() {
  int Q;
  cin >> Q;
  while (Q--) {
    cin >> s;
    p = 0;
    cout << expr() << endl;
  }
  return 0;
}

Compiler output:
a.cc:2:1: error: extended character 「 is not valid in an identifier
    2 | テ「ツ??
      | ^
a.cc:5:1: error: extended character 「 is not valid in an identifier
    5 | テ「ツ??
      | ^
a.cc:7:1: error: extended character 「 is not valid in an identifier
    7 | テ「ツ??
      | ^
a.cc:10:1: error: extended character 「 is not valid in an identifier
   10 | テ「ツ??
      | ^
a.cc:13:1: error: extended character 「 is not valid in an identifier
   13 | テ「ツ??
      | ^
a.cc:16:1: error: extended character 「 is not valid in an identifier
   16 | テ「ツ??
      | ^
a.cc:19:1: error: extended character 「 is not valid in an identifier
   19 | テ「ツ??
      | ^
a.cc:28:1: error: extended character 「 is not valid in an identifier
   28 | テ「ツ??
      | ^
a.cc:44:1: error: extended character 「 is not valid in an identifier
   44 | テ「ツ??
      | ^
a.cc:2:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
    2 | テ「ツ??
      | ^~~~~~
a.cc:7:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
    7 | テ「ツ??
      | ^~~~~~
a.cc:10:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   10 | テ「ツ??
      | ^~~~~~
a.cc:13:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   13 | テ「ツ??
      | ^~~~~~
a.cc:16:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   16 | テ「ツ??
      | ^~~~~~
a.cc:19:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   19 | テ「ツ??
      | ^~~~~~
a.cc:28:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   28 | テ「ツ??
      | ^~~~~~
a.cc:44:1: error: '\U000030c6\U0000300c\U000030c4' does not name a type
   44 | テ「ツ??
      | ^~~~~~
Language: C++

#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

string s;

int stoit(const std::string& str, std::size_t* idx = nullptr, int base = 10) {
	const char* p = str.c_str();
	char* end;
	errno = 0;
	long x = std::strtol(p, &end, base);
	if (p == end) {
		throw std::invalid_argument("stoi");
	}
	if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
		throw std::out_of_range("stoi");
	}
	if (idx != nullptr) {
		*idx = static_cast<std::size_t>(end - p);
	}
	return static_cast<int>(x);
}

ll cal(ll l, ll r) {
	vector<ll> h;
	ll foo = 0;
	ll bar = 0;
	FOR(i, l, r) {
		if(s[i] == '[') {
			foo = 0;
			bar = 0;
			ll hoge = i + 1;
			FOR(j, i + 1, r) {
				i = j;
				if(s[j] == '[') {
					++foo;
					++bar;
				}
				if(s[j] == ']') {
					if(foo > 0) --foo;
					else {
						if(bar == 0) {
							h.pb(stoit(s.substr(hoge, j - hoge)) / 2 + 1);
						} else {
							h.pb(cal(hoge, j));
						}
						break;
					}
				}
			}
		}
	}
	sort(ALL(h));
	ll ans = 0;
	REP(i, min(h.size(), h.size() / 2 + 1)) {
		ans += h[i];
	}
	return ans;
}

int main(void) {
	ll n;
	cin>>n;
	REP(i, n) {
		cin>>s;
		cout<<cal(1, s.size() - 1)<<endl;
	}
}

Compiler output:
a.cc: In function 'int stoit(const std::string&, std::size_t*, int)':
a.cc:40:36: error: 'INT_MIN' was not declared in this scope
   40 |         if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
      |                                    ^~~~~~~
a.cc:16:1: note: 'INT_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   15 | #include<map>
  +++ |+#include <climits>
   16 | #define REP(i, N) for(ll i = 0; i < N; ++i)
a.cc:40:51: error: 'INT_MAX' was not declared in this scope
   40 |         if (errno == ERANGE || x < INT_MIN || x > INT_MAX) {
      |                                                   ^~~~~~~
a.cc:40:51: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
Language: C++

#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <functional>
#include <algorithm>
#include <string>
#include <cassert>

using namespace std;

int parse_impl(string::const_iterator &begin, string::const_iterator end) {
	assert(*begin == '[');
	begin++;
	if (*begin == '[') {
		vector<int> nodes;
		do {
			nodes.push_back(parse_impl(begin, end));
		} while (*begin != ']');
		begin++;
		std::sort(nodes.begin(), nodes.end());
		int min_win = 0;
		for (int i = 0; i < nodes.size() / 2 + 1; i++) {
			min_win += nodes[i];
		}
		return { min_win };
	}
	else {
		int value = 0;
		do {
			value *= 10;
			value += *begin - '0';
			begin++;
		} while (*begin != ']');
		begin++;
		return { value / 2 + 1 };
	}
}

int parse(string line) {
	auto it = line.begin();
	return parse_impl(it, line.end());
}

void solve() {
	string line;
	cin >> line;
	cout << parse(line) << endl;
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		solve();
	}
}

Compiler output:
a.cc: In function 'int parse(std::string)':
a.cc:42:27: error: cannot bind non-const lvalue reference of type 'std::__cxx11::basic_string<char>::const_iterator&' to an rvalue of type 'std::__cxx11::basic_string<char>::const_iterator'
   42 |         return parse_impl(it, line.end());
      |                           ^~
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:1074:9: note:   after user-defined conversion: '__gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const __gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter = char*; <template-parameter-2-2> = void; _Iterator = const char*; _Container = std::__cxx11::basic_string<char>]'
 1074 |         __normal_iterator(const __normal_iterator<_Iter, _Container>& __i)
      |         ^~~~~~~~~~~~~~~~~
a.cc:12:40: note:   initializing argument 1 of 'int parse_impl(std::__cxx11::basic_string<char>::const_iterator&, std::__cxx11::basic_string<char>::const_iterator)'
   12 | int parse_impl(string::const_iterator &begin, string::const_iterator end) {
      |                ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
Language: C++

#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct node{
  int val;
  vector<int> next;
  node(){
    val = -1;
  }
  node(int a){
    val = a;
  }
};

int n;
string s;
vector<node> tree;

int make(int p, int v)
{
  string tmp;
  for(int i = p; i < s.size(); i++){
    if(s[i] == '['){
      tree.push_back(node());
      tree[v].next.push_back(tree.size()-1);
      i = make(i+1, tree.size()-1);
    }
    else if(s[i] == ']'){
      if(tmp != ""){
        tree[v].val = atoi(tmp.c_str());
      }
      return i;
    }
    else{
      tmp += s[i];
    }
  }
}

int calc(int v)
{
  if(tree[v].val != -1){
    return (tree[v].val + 1) / 2;
  }
  vector<int> vec;
  for(int i = 0; i < tree[v].next.size(); i++){
    vec.push_back(calc(tree[v].next[i]));
  }
  sort(vec.begin(), vec.end());
  int ret = 0;
  for(int i = 0; i < ((int)vec.size()+1)/2; i++) ret += vec[i];
  return ret;
}

int main(void)
{
  cin >> n;
  for(int t = 0; t < n; t++){
    cin >> s;

    tree.clear();
    tree.push_back(node());

    make(0, 0);
    cout << calc(0) << endl;
  }

  return 0;
}



Compiler output:
a.cc: In function 'int calc(int)':
a.cc:52:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   52 |   sort(vec.begin(), vec.end());
      |   ^~~~
      |   short
a.cc: In function 'int make(int, int)':
a.cc:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>

using namespace std;

struct node{
  int val;
  vector<int> next;
  node(){
    val = -1;
  }
  node(int a){
    val = a;
  }
};

int n;
string s;
vector<node> tree;

int make(int p, int v)
{
  string tmp;
  for(int i = p; i < s.size(); i++){
    if(s[i] == '['){
      tree.push_back(node());
      tree[v].next.push_back(tree.size()-1);
      i = make(i+1, tree.size()-1);
    }
    else if(s[i] == ']'){
      if(tmp != ""){
        tree[v].val = atoi(tmp.c_str());
      }
      return i;
    }
    else{
      tmp += s[i];
    }
  }
}

int calc(int v)
{
  if(tree[v].val != -1){
    return (tree[v].val + 1) / 2;
  }
  vector<int> vec;
  for(int i = 0; i < tree[v].next.size(); i++){
    vec.push_back(calc(tree[v].next[i]));
  }
  sort(vec.begin(), vec.end());
  int ret = 0;
  for(int i = 0; i < ((int)vec.size()+1)/2; i++) ret += vec[i];
  return ret;
}

int main(void)
{
  cin >> n;
  for(int t = 0; t < n; t++){
    cin >> s;

    tree.clear();
    tree.push_back(node());

    make(0, 0);
    cout << calc(0) << endl;
  }

  return 0;
}



Compiler output:
a.cc: In function 'int calc(int)':
a.cc:53:3: error: 'sort' was not declared in this scope; did you mean 'short'?
   53 |   sort(vec.begin(), vec.end());
      |   ^~~~
      |   short
a.cc: In function 'int make(int, int)':
a.cc:42:1: warning: control reaches end of non-void function [-Wreturn-type]
   42 | }
      | ^
Language: C++

#include <iostream>
#include <vector>
#include <cstdio>
#include <utility>
#include <cstdlib>
using namespace std;

typedef pair<int, int> pii;

const char *p;

int solve() {
  int ret = 0;
  ++p;
  if(*p=='['){
    vector<int> v;
    while(*p == '['){
      v.push_back(solve());
    }
    sort(v.begin(), v.end());
    ret = 0;
    for(int i=v.size()/2; i>=0; i--) {
      ret += v[i];
    }
  }
  else {
    char *e;
    ret = strtol(p, &e, 10)/2 + 1;
    p = e;
  }
  ++p;
  return ret;
}

int main() {
  int n;
  string s;
  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>s;
    p = s.c_str();
    cout<<solve()<<endl;
  }
}

Compiler output:
a.cc: In function 'int solve()':
a.cc:20:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   20 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
#include <cassert>
using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }
  assert(*p == ']');
  ++p;
  return res;
}

int main() {
  int n;
  string str;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str[0];
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int rec()':
a.cc:16:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   16 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <cassert>
using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }
  assert(*p == ']');
  ++p;
  return res;
}

int main() {
  int n;
  string str;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str[0];
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int rec()':
a.cc:17:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   17 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }

  ++p;
  return res;
}

int main() {
  int n;
  string str;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str[0];
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int rec()':
a.cc:16:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   16 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>

using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }

  ++p;
  return res;
}

int main() {
  int n;
  char str[1000];
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str;
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int rec()':
a.cc:16:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   16 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
a.cc: In function 'int main()':
a.cc:35:9: error: cannot convert 'char (*)[1000]' to 'const char*' in assignment
   35 |     p = &str;
      |         ^~~~
      |         |
      |         char (*)[1000]
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }

  ++p;
  return res;
}

int main() {
  int n;
  char str[1000];
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str;
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:9: error: cannot convert 'char (*)[1000]' to 'const char*' in assignment
   36 |     p = &str;
      |         ^~~~
      |         |
      |         char (*)[1000]
Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

const char *p;

int rec() {
  int res = 0;
  vector<int> v;

  ++p;
  if(*p == '[') {
    while(*p == '[') v.push_back(rec());
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size()/2+1; i++) res += v[i];
  } else {
    char *e;
    res = strtol(p, &e, 10) / 2 + 1;
    p = e;
  }

  ++p;
  return res;
}

int main() {
  int n;
  char str[1000];
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> str;
    p = &str;
    cout << rec() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:9: error: cannot convert 'char (*)[1000]' to 'const char*' in assignment
   37 |     p = &str;
      |         ^~~~
      |         |
      |         char (*)[1000]
Language: C++

#include <iostream>
#include <cctype>
#include <cstdlib>
#include <vector>
using namespace std;

string str;
const char *p;

int parse() {

  p ++;
  
  switch(*p) {
  case '[':
    {
      vector<int> v;
      while(*p == '[') {
	v.push_back( parse() );
	p ++;
      }
      
      sort(v.begin(), v.end());

      int sum = 0;
      for(int i=0; i<v.size()/2+1; i++) {
	sum += v[i];
      }

      return sum;
    }

  default:
    if(isdigit(*p)) {
      char *e;
      int num = strtol(p, &e, 10);
      p = e;
      return num/2+1;
    }
  }
}

int main() {
  int n;
  
  cin >> n; cin.ignore();
  for(int i=0; i<n; i++) {
    getline(cin, str);
    p = &str[0];

    cout << parse() << endl;
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int parse()':
a.cc:23:7: error: 'sort' was not declared in this scope; did you mean 'short'?
   23 |       sort(v.begin(), v.end());
      |       ^~~~
      |       short
a.cc:41:1: warning: control reaches end of non-void function [-Wreturn-type]
   41 | }
      | ^
Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

const char *p;
string str;

int parse() {
  int num;
  char *e;
  p++;
  
  if(*p=='[') {
    vector<int> v;
    for(;;) { 
      if(*p == '[') {
	num = parse();
	v.push_back(num);
	p++;
      } else break;
    }
    p++;
    sort(v.begin(), v.end());
    
    int sum = 0;
    for(int i=0; i<v.size()/2+1; i++) sum+=v[i];
    return sum;
  }
  
  if(isdigit(*p)) {
    num = strtol(p, &e, 10);
    p = e;
    return num/2+1;
  }
}

int main() {
  int n;
  cin >> n;
  cin.ignore();
  
  for(int i=0; i<n; i++) {
    getline(cin, str);
    p = str.c_str();
    cout << parse() << endl;
  }
  
  return 0;
}

Compiler output:
a.cc: In function 'int parse()':
a.cc:26:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   26 |     sort(v.begin(), v.end());
      |     ^~~~
      |     short
a.cc:38:1: warning: control reaches end of non-void function [-Wreturn-type]
   38 | }
      | ^
Language: C++

#include<iostream>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
string s;
int now;
int rec(int now){
  if(isdigit(s[now])){
    int res = 0;
    while(now < s.size() && isdigit(s[now])) res = res * 10 + s[now++] - '0';
    return ++res / 2;
  }else{
    vector<int> dat; int res = 0;
    while(s[now] == '[') now++ , dat.push_back(rec()) , now++;
    sort(dat.begin(),dat.end());
    for(int i = 0 ; i < ( dat.size() + 1 ) / 2 ; i++ ) res += dat[i];
    return res;
  }
}
int main(){
  int q;
  cin >> q;
  while(q--){
    now = 0;
    cin >> s;
    cout << rec() << endl;
  }
}

Compiler output:
a.cc: In function 'int rec(int)':
a.cc:16:51: error: too few arguments to function 'int rec(int)'
   16 |     while(s[now] == '[') now++ , dat.push_back(rec()) , now++;
      |                                                ~~~^~
a.cc:9:5: note: declared here
    9 | int rec(int now){
      |     ^~~
a.cc: In function 'int main()':
a.cc:28:16: error: too few arguments to function 'int rec(int)'
   28 |     cout << rec() << endl;
      |             ~~~^~
a.cc:9:5: note: declared here
    9 | int rec(int now){
      |     ^~~
Language: C++

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

	int n;
	int d;
	int md;
	int inum;
	int sum;
	int cha;
	string s;
	string snum;
	vector<int> hyo[1000];

	cin>>n;

	for(int i=0;i<n;i++){
		cin>>s;
		d=0;
		md=0;
		for(int i=0;i<s.size();i++){
			if(s[i]=='[') d++,md=d;
			else if(s[i]==']') d--;
			else{
				snum=("");
				while(1){
					if(s[i]=='['||s[i]==']') break;
					snum+=s[i];
					i++;
				}
				i--;
				inum=0;
				for(int j=0;j<snum.size();j++) inum+=(snum[j]-'0')*pow(10.0,(double)snum.size()-1-j);
				hyo[d].push_back(inum);
			}
			if(d<=md-2){
				if(d==md-2) cha=2;
				else cha=1;
				sort(hyo[d+2].begin(),hyo[d+2].end());
				sum=0;
				for(int j=0;j<hyo[d+2].size()/2+1;j++){
					sum+=hyo[d+2][j]/cha;
					if(cha==2) sum++;
				}
				hyo[d+2].clear();
				hyo[d+1].push_back(sum);
			}
		}
		sum=0;
		for(int j=0;j<hyo[1].size()/2+1;j++){
			sum+=hyo[1][j];
		}
		cout<<sum<<endl;
		for(int j=0;j<1000;j++){
			if(!hyo[j].empty()) hyo[j].clear();
		}
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:84: error: 'pow' was not declared in this scope
   38 |                                 for(int j=0;j<snum.size();j++) inum+=(snum[j]-'0')*pow(10.0,(double)snum.size()-1-j);
      |                                                                                    ^~~
Language: C++


#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>
using namespace std;
string str;

int rewrite(int from, string s){

	//end位置を取得
	int end = -1;
	for (int i = from; i < (signed)s.size(); i++){
		if (i >= 1 && s[i - 1] == ']' &&s[i] == ']'){
			end = i;
			break;
		}
	}

	//右端まで来たときの処理
	if (end == -1){
		if (from == 0)
			return -1;
		else
			return rewrite(0, s);
	}

	//start位置を取得
	int start = -1;
	for (int i = end;; i--){
		if (s[i] == '[' &&s[i - 1] == '['){
			start = i;
			break;
		}
	}

	//vectorに入れる
	vector<int> v;
	int startnum = -1;
	for (int i = start; i < end; i++){
		if (s[i] == '[')
			startnum = i + 1;
		if (s[i] == ']'){
			string snum;
			for (int j = startnum; j < i; j++){
				snum = snum + s[j];
			}
			int num = atoi(snum.c_str());
			v.push_back((num + 1) / 2);
			startnum = -1;
		}
	}

	//ソート
	sort(v.begin(), v.end());

	//半分を取り出し，和を計算
	int sum = 0;
	for (int i = 0; i < ((signed)v.size() + 1) / 2; i++)
		sum += v[i];
	sum = sum * 2 - 1;
	string news = string(s.begin(), s.begin() + start);
	stringstream ss;
	ss << sum;
	news += ss.str();
	news += string(s.begin() + end, s.end());
	str = news;
	return news.size() - (s.size() - end);

}

int main()
{
	int n;
	char before = '0';
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> str;
		int from = 0;
		while (1){
			from = rewrite(from, str);
			if (from == -1)
				break;
		}
		string ans = "";
		for (int i = 1; i < (signed)str.size() - 1; i++)
			ans += str[i];
		int ansnum = atoi(ans.c_str());
		cout << (ansnum + 1) / 2 << endl;
	}
	return 0;
}

Compiler output:
a.cc:2:10: fatal error: stdafx.h: No such file or directory
    2 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: Java

import java.util.Arrays;
import java.util.Scanner;
public class Main {
	
	static boolean[] isPrime;
	static int[][] data
	
	static void prime() {
		isPrime = new boolean[1000000];
		Arrays.fill(isPrime, true);
		isPrime[0] = false;
		isPrime[1] = false;
		for(int i=2; i*i<=1000000; i++) {
			if(isPrime[i]) {
				for(int j=i+i; j<=1000000; j+=i) {
					isPrime[j] = false;
				}
			}
		}
	}
	
	static void numArray(){
        data = new int[1000][1000];
        for(int i = 0; i < 1000; i++){
            Arrays.fill(data[i], 1<<24);
        }
        int now = 1, posx = 500, posy = 500;
        for(int i = 1; now <= 1000000;i++){
            System.out.print("");
            if(i % 2 == 1){
                //right up
                for(int j = 0; j < i && now <= 1000000; j++){
                    data[posy][posx] = now;
                    posx++;
                    now++;
                }
                for(int j = 0; j < i && now <= MAX; j++){
                    data[posy][posx] = now;
                    posy--;
                    now++;
                }
            }
            else{
                //left down
                for(int j = 0; j < i && now <= 100000; j++){
                    data[posy][posx] = now;
                    posx--;
                    now++;
                }
                for(int j = 0; j < i && now <= 1000000; j++){
                    data[posy][posx] = now;
                    posy++;
                    now++;
                }
            }
        }
    }
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			prime();
			numArray();
			while(sc.hasNext()) {
				int m = sc.nextInt();
				int n = sc.nextInt();
				if(m + n == 0) break;
				
				int x = -1;
				int y = -1;
				for(int i= 0; i<1000; i++) {
					for(int j=0; j<1000; j++) {
						if(data[i][j] == n) {
							y = i;
							x = j;
						}
					}
				}
				
				int[][] dp = new int[1000][1000];
				dp[y][x] = 1;
				int max = 0;
				int num = 0;
				for(int i=y; i<1000; i++) {
					for(int j=0; j<1000; j++) {
						if(i == y && data[i][j] != n) continue;
						if(data[i][j] > m) continue;
						if(dp[i][j] == 0) continue;
						
						if(isPrime[data[i][j]]) {
							dp[i][j]++;
							if(max < dp[i][j]) {
								max = dp[i][j];
								num = data[i][j];
							}
							else if(max == dp[i][j]) {
								if(num < data[i][j]) {
									num = data[i][j];
								}
							}
						}
						
						dp[i+1][j] = Math.max(dp[i+1][j], dp[i][j]);
						if(j >= 1) {
							dp[i+1][j-1] = Math.max(dp[i+1][j-1], dp[i][j]);
						}
						if(j + 1 < 1000) {
							dp[i+1][j+1] = Math.max(dp[i+1][j+1], dp[i][j]);
						}
					}
				}
				System.out.println(max + " " + num);
			}
		}
	}
}


Compiler output:
Main.java:6: error: ';' expected
	static int[][] data
	                   ^
1 error
Language: C

#include <iostream>
#include <algorithm>
#include <string>

#define MAX 1000001
#define SIZE 2000

typedef long long ll;

using namespace std;

int m, n;
int table[SIZE][SIZE]={{0,0}};
int dp[SIZE][SIZE];
bool prime[MAX]; 
pair<int, int>coord[MAX];//座標
pair<int, int> ans;// <素数の数, 出口の番号>


void dfs(int count, int y, int x){
	int num = table[y][x];
	if(num <= 0 || m < num) return;
	if(count < dp[y][x] || (count == dp[y][x] && prime[num] == false && dp[y][x] !=0)) return;
	dp[y][x] = count;

	if(prime[num] == true){
		count++;
		dp[y][x] = count;
		if(ans.first < count || (ans.first == count && ans.second < num)){
			ans.first = count;
			ans.second = num;
		}
	}

	for(int dx=-1; dx<=1; dx++){
		dfs(count, y+1, x+dx);
	}
}


int main(void){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;
	for(int i=2; i<MAX; i++){
		if(prime[i]){
			for(int j=i+i; j<MAX; j+=i){
				prime[j] = false;
			}
		}
	}

	int d=0, x=1000, y=1000;
	int dx[4]={0, 1, 0, -1};
	int dy[4]={1, 0, -1, 0};
	for(int i=1; i<MAX; i++){
		table[y][x] = i;
		coord[i] = make_pair(y, x);
		if(table[y+dy[(d+1)%4]][x+dx[(d+1)%4]] == 0) d++;
		x += dx[d%4];
		y += dy[d%4];
	}

	while(1){
		cin >> m >> n;
		if(!m && !n) break;

		int y = coord[n].first;
		int x = coord[n].second;
		fill(dp[0], dp[2000], 0);
		ans = make_pair(0, 0);
		dfs(0, y, x);
		cout << ans.first << " " << ans.second << endl;
	}

	return 0;
}


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

#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define MAX_N 1000000
#define MAX_X 1000
#define MAX_Y 1000

int cave[MAX_Y][MAX_X];
bool sieve[MAX_N+1];
int dp[MAX_N+1];

int m, n;

struct P { int x, y; };

P search_cave(int n) {
    REP(y, MAX_Y) REP(x, MAX_X) {
        if (cave[y][x] == n) {
            return (P){x, y};
        }
    }
    return (P){0, 0}; // fail
}

int main() {
    sieve[0] = sieve[1] = true;
    FOR(i, 2, MAX_N+1) {
        if (sieve[i]) continue;
        for (int j = i + i; j < MAX_N+1; j += i) {
            sieve[j] = true;
        }
    }

    int ul = cave[0][0] = MAX_N;
    // left -> down -> right -> up ->
    int d = 0;
    int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1};
    int x = 0, y = 0;
    while (ul > 1) {
        int sx = x + dx[d];
        int sy = y + dy[d];
        if (0 <= sx && sx < MAX_X && 0 <= sy && sy < MAX_Y && cave[sy][sx] == 0) {
            x = sx;
            y = sy;
            ul--;
            cave[y][x] = ul;
        } else {
            d = (d + 1) & 3; // d % 4
        }
    }

    while (cin >> m >> n, m|n) {
        fill_n(dp, MAX_N+1, -1);
        P s = search_cave(n);
        dp[n] = 0;
        int max_primes = 0, max_cave = 0;
        FOR(y, s.y, MAX_Y) REP(x, MAX_X) {
            int c = cave[y][x];
            if (c > m || dp[c] < 0) continue;
            if (!sieve[c]) { // prime
                dp[c]++;
                if (max_primes <= dp[c]) {
                    max_primes = dp[c];
                    max_cave = c;
                }
            }
            for (int dx = -1; dx <= 1; dx++) {
                int sx = x + dx;
                int sy = y + 1;
                if (0 <= sx && sx < MAX_X && 0 <= sy && sy < MAX_Y) {
                    int c2 = cave[sy][sx];
                    if (c2 <= m) {
                        dp[c2] = max(dp[c2], dp[c]);
                    }
                }
            }
        }
        cout << max_primes << " " << max_cave << endl;
    }
}

Compiler output:
a.cc:17:20: error: expected ';' before 'typedef'
   17 | using namespace std
      |                    ^
      |                    ;
......
   28 | typedef long long ll;
      | ~~~~~~~
Language: C++

13 947
13 947
13 947
13 947
13 947
1 1069
4 1091
4 839
1 941
1 941
16 829
1 929
24 947
0 0
17 947
25 947
23 947
22 829
26 947
23 947
1 823
1 953
1 1063
1 953
1 839
0 0
0 0
0 0
0 0
0 0
19 947
20 947
20 947
19 947
20 947
13 947
17 947
22 947
0 0
14 829
19 947
11 947
11 947
5 941
20 947
18 829
9 821
574 993541

Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 13 947
      | ^~
Language: C++

#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

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

int caves[2000][2000];

bool sieve[1000001];
int SX, SY;

typedef pair<int, int> PII;

PII dp[2000][2000];
bool vis[2000][2000];

int main()
{
	int nx, ny;
	fill(sieve, sieve + 1000001, true);
	sieve[0] = sieve[1] = false;
	for(int i = 2; i * i <= 1000000; ++i) {
		if(sieve[i]) {
			for(int j = i * i; j <= 1000000; j += i) {
				sieve[j] = false;
			}
		}
	}
	
	int M, N;
	while (cin>>M>>N, M||N) {
		memset(caves, -1, sizeof(caves));
		
		for (int j=0; j<2000; j++) {
			for (int i=0; i<2000; i++) {
				dp[i][j] = PII(0, -1);
			}
		}
		
		nx = ny = 2000/2;
		int len=1, num=2;
		int d = 0;
		
		caves[nx][ny] = 1;
		
		while (num <= M) {
			for (int j=0; j<len; j++) {
				nx += dx[d];
				ny += dy[d];
				caves[nx][ny] = num++;
				if (num > M) break;
			}
			d++; d %= 4;
			if (num > M) break;
			
			for (int j=0; j<len; j++) {
				nx += dx[d];
				ny += dy[d];
				caves[nx][ny] = num++;
				if (num > M) break;
			}
			
			d++;
			d %= 4;
			len++;
		}
		
		for (int i=0; i<2000; i++) {
			for (int j=0; j<2000; j++) {
				if (caves[j][i] == N) {
					SX = j, SY = i;
					if(sieve[N]) {
						dp[i][j] = PII(1, N);
					}
					else {
						dp[i][j] = PII(0, -1);
					}
				}
			}
		}
		
		#if 0
		for (int i=1000-10; i<1000+10; i++) {
			for (int j=1000-10; j<1000+10; j++) {
				printf("%3d", caves[j][i]);
			}
			printf("\n");
		}
		#endif
		memset(vis, 0, sizeof(vis));
		vis[SY][SX] = true;
		for(int i = 0; i < 2000 - 1; ++i) {
			for(int j = 0; j < 2000; ++j) {
				if(vis[i][j] == false) continue;
				for(int k = -1; k <= 1; ++k) {
					int nx = j + k;
					if(nx < 0 || nx >= 2000) continue;
					int add = dp[i][j].first;
					int maxP = dp[i][j].second;
					if(caves[nx][i + 1] > 0 && sieve[caves[nx][i + 1]]) {
						add++;
						maxP = caves[nx][i + 1];
					}
					dp[i + 1][nx] = max(dp[i + 1][nx], PII(add, maxP));
					vis[i + 1][nx] = true;
				}
			}
		}
		PII ans(-1, -1);
		for(int j = 0; j < 2000; ++j) {
			ans = max(ans, dp[2000 - 1][j]);
		}
		cout << ans.first << ' ' << max(0, ans.second) << endl;
	}	
}

Compiler output:
a.cc: In function 'int main()':
a.cc:35:17: error: 'memset' was not declared in this scope
   35 |                 memset(caves, -1, sizeof(caves));
      |                 ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <utility>
  +++ |+#include <cstring>
    4 |
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int N = 1111111;
bool prime[N];
set<int> primes;

void hurui()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	for (int i = 2; i*i < N; i++)
	{
		for (int j = 2; i*j < N; j++)
		{
			prime[i*j] = false;
		}
	}
	REP(i, N + 1)
	{
		if (prime[i]) primes.insert(i);
	}
}

const int dx[] = { -1, 0, 0, 1 }, dy[] = { 0, -1, 1, 0 };
//[const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }


bool fld[1200][1200] = {};
int ind[1200][1200];
pii hs[1111111];

void init()
{
	REP(i, 1200)REP(j, 1200) ind[i][j] = INF;
	hurui();
	int p = 1, x = 600, y = 600;
	FOR(i, 1, 11111111)
	{
		if (i % 2)
		{
			REP(j, i)
			{
				ind[x][y] = p;
				hs[p] = pii(x, y);
				if (primes.count(p)) fld[x][y] = true;
				p++;
				y++;
			}
			REP(j, i)
			{
				ind[x][y] = p;
				hs[p] = pii(x, y);
				if (primes.count(p)) fld[x][y] = true;
				p++;
				x--;
			}
		}
		else
		{
			REP(j, i)
			{
				ind[x][y] = p;
				hs[p] = pii(x, y);
				if (primes.count(p)) fld[x][y] = true;
				p++;
				y--;
			}
			REP(j, i)
			{
				ind[x][y] = p;
				hs[p] = pii(x, y);
				if (primes.count(p)) fld[x][y] = true;
				p++;
				x++;
			}
		}
		if (p > 1000000) break;
	}
}

pii dp[1200][1200];
int n, m;

pii solve(int x, int y)
{
	if (dp[x][y] !=pii(-1,-1)) return dp[x][y];
	pii res(0, -1);
	FOR(i, -1, 2)
	{
		int nx = x + 1, ny = y + i;
		if (ind[nx][ny] > m) continue;
		pii next = solve(nx, ny);
		if (fld[nx][ny])
		{
			if (next.first == 0) chmax(res, pii(next.first + 1, ind[nx][ny]));
			else chmax(res, pii(next.first + 1, next.second));
		}
		else chmax(res, next);
	}
	return dp[x][y] = res;
}

int main()
{
	init();
	while (cin >> m >> n, n)
	{
		REP(i, 1200)REP(j, 1200) dp[i][j] = pii(-1, -1);
		pii ans = solve(hs[n].first, hs[n].second);
		if (primes.count(n))
		{
			ans.first++;
			chmax(ans.second, n);
		}
		if (ans.first == 0) cout << "0 0" << endl;
		else cout << ans.first << " " << ans.second << endl;
	}
	return 0;
}

Compiler output:
a.cc:22:12: error: size of array 'prime' is not an integral constant-expression
   22 | bool prime[N];
      |            ^
Language: C++

#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define f first
#define s second
typedef pair<int,int> P;
int a[2000][2000],ans[2000][2000],d=0,y=999,x=1001,n,m;
bool b[1000001],used[2000][2000];
int dx[]={-1,0,1,0},tx[]={-1,0,1};
int dy[]={0,1,0,-1},ty[]={1,1,1};
int main(){
  b[0]=b[1]=1;
  for(int i=2;i<1000001;i++)
    for(int j=i+i;j<1000001;j+=i)b[j]=1;
  a[1000][1000]=1;
  a[1000][1001]=2;
  a[999][1001]=3;
  for(int i=4;i<1000001;i++){
    int yy=y+dy[d],xx=x+dx[d];
    int ya=yy+dy[(d+1)%4],xa=xx+dx[(d+1)%4];
    if(!a[ya][xa])d=(d+1)%4;
    a[yy][xx]=i;
    y=yy,x=xx;
  }
  while(cin>>n>>m,n){
    memset(ans,0,sizeof(ans));
    memset(used,0,sizeof(used));
    r(i,2000)r(j,2000)if(a[i][j]==m){
      used[i][j]=1;y=i;
      break;
    }
    for(int i=y;i<2000;i++)r(j,2000)if(a[i][j]&&used[i][j]){
      if(!b[a[i][j]])ans[i][j]++;
      r(k,3){
        y=i+ty[k],x=j+tx[k];
        if(!a[y][x]||a[y][x]>=n)continue;
        ans[y][x]=max(ans[y][x],ans[i][j]);
        used[y][x]=1;
      }
    }
    int a1=0,a2;
    r(i,2000)r(j,2000)if(a[i][j]<=n)if(a1<ans[i][j]){
      a1=ans[i][j],a2=a[i][j];
    }
    if(!a1)cout<<"0 0"<<endl;
    else cout<<a1<<' '<<a2<<endl;
  }

Compiler output:
a.cc: In function 'int main()':
a.cc:47:4: error: expected '}' at end of input
   47 |   }
      |    ^
a.cc:11:11: note: to match this '{'
   11 | int main(){
      |           ^
Language: C++

#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#define t_max 10000001
int M[1001][1001];
int S[1001][1001];
int P[1001][1001];
int table[t_max];
vector<pair<int,int> >m(t_max);
map<pair<int,int>,int>m_rev;
pair<int,int> dfs(int x,int y){
	if(y==1001)return make_pair(0,0);
	if(S[x][y]>=0)return make_pair(S[x][y],P[x][y]);
	int m=0,m_place=0,i=-1;
	for(;i<2;i++){
		if(x+i<0||1000<x+i)continue;
		pair<int,int> p=dfs(x+i,y+1);
		if(m<p.first||(m==p.first&&m_place<p.second))m=p.first,m_place=p.second;
	}
	if(m==0){
		if(M[x][y])return make_pair(S[x][y]=1,P[x][y]=m_rev[make_pair(x,y)]);
		return make_pair(S[x][y]=0,P[x][y]=0);
	}else{
		return make_pair(S[x][y]=m+M[x][y],P[x][y]=m_place);
	}
}
main(){
	int k=1,z,x,y,i,n,s;
	m[k]=make_pair(x=500,y=500),m_rev[make_pair(x,y)]=k,k++;
	for(z=2;z<=1000;z+=2){
		x++,y++;
		for(i=0;i<z;i++)m[k]=make_pair(x,--y),m_rev[make_pair(x,y)]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(--x,y),m_rev[make_pair(x,y)]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(x,++y),m_rev[make_pair(x,y)]=k,k++;
		for(i=0;i<z;i++)m[k]=make_pair(++x,y),m_rev[make_pair(x,y)]=k,k++;
	}
	table[0]=table[1]=1;
	for(x=2;x<t_max;x++)if(!table[x])for(y=x*2;y<t_max;y+=x)table[y]=1;
	for(;scanf("%d%d",&n,&s),n;){
		memset(M,0,sizeof(M));
		memset(S,0xff,sizeof(S));
		memset(P,0,sizeof(P));
		for(i=1;i<=n;i++)if(!table[i])M[m[i].first][m[i].second]=1;
		pair<int,int> p=dfs(m[s].first,m[s].second);
		printf("%d %d\n",p.first,p.second);
	}
}

Compiler output:
a.cc:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:41:17: error: 'memset' was not declared in this scope
   41 |                 memset(M,0,sizeof(M));
      |                 ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <cstdio>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include <iostream>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
 
const int MAX = 1000001;
bool pri[MAX];
vector<int>v;
map<int,pair<int,int> >pos;
int field[1201][1201];
int N,M;
 
void make(){
  int cnt = 2;
  int c = 1;
  int x = 500,y=500;
  int cc = 0;
  field[500][500] = 1;
  pos[1] = make_pair(500,500);
 
  while(cnt < 1000000){
    for(int i=0; i<4; i++){
      if(cc == 2){cc = 0; c++;}
      int nx = x, ny = y;
      for(int j=0; j<c; j++){
    nx += dx[i];
    ny += dy[i];
    pos[cnt] = make_pair(ny,nx);
    field[ny][nx] = cnt++;
      }
 
      x = nx, y = ny;
      cc++;
    }
  }
}
 
void createPrime(){
  fill(pri,pri+MAX,1);
  pri[0] = pri[1] = 0;
  for(int i=2; i*i<MAX; i++){
    for(int j=2*i; j<MAX; j+=i){
      pri[j] = false;
    }
  }
 
  for(int i=2; i<MAX; i++) if(pri[i]) v.push_back(i);
}
 
bool compare(pair<int,int>p, pair<int,int>p2){
  if(p.first == p2.first){
    return p.second > p2.second;
  }
  return p.first > p2.first;
}
 
int main(){
  make();
  createPrime();
 
  while(cin >> M >> N,M|N){
    pair<int,int> p = pos[N];
    int sx = p.second, sy = p.first;
    bool F = false;
 
    static bool used[1200][1200];
    static pair<int,int> dp[1200][1200];
    memset(used,0,sizeof(used));
    memset(dp,0,sizeof(dp));
 
    if(binary_search(v.begin(),v.end(),field[sy][sx])){
      dp[sy][sx].first = 1;
      dp[sy][sx].second = field[sy][sx];
    }
    used[sy][sx] = true;
 
    for(int i=sy; i<=1000; i++){
      for(int j=0; j<=1000; j++){
    for(int k=-1; k<=1; k++){
      if(!used[i][j])continue;
      int nx = j + k;
      if(nx < 0 || nx > 1000)continue;
      if(field[i+1][nx] > M)continue;
 
      used[i+1][nx] = true;
      int value = binary_search(v.begin(),v.end(),field[i+1][nx]);
       
      if(value){
        if(dp[i+1][nx].first < dp[i][j].first + 1){
          dp[i+1][nx].first = dp[i][j].first + 1;
          dp[i+1][nx].second = field[i+1][nx];
        }
      } else {
        dp[i+1][nx] = max(dp[i+1][nx],dp[i][j]);
      }
    }
      }
    }
 
    vector<pair<int,int> >ans;
 
    for(int i=0; i<=1000; i++){
      for(int j=0; j<=1000; j++){
    if(field[i][j] > M)continue;
    if(dp[i][j].first == 0)continue;
    ans.push_back(dp[i][j]);
      }
    }
 
 
    if(ans.size() == 0){cout << "0 0" << endl;}
    else{
      sort(ans.begin(),ans.end(),compare);
      cout << ans[0].first << " " << ans[0].second << endl;
    }
 
  }
 
  return 0;
}

Compiler output:
a.cc: In function 'void make()':
a.cc:30:11: error: 'dx' was not declared in this scope; did you mean 'nx'?
   30 |     nx += dx[i];
      |           ^~
      |           nx
a.cc:31:11: error: 'dy' was not declared in this scope; did you mean 'ny'?
   31 |     ny += dy[i];
      |           ^~
      |           ny
Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
int holes[1005][1005],table[1005][1005];
bool prime[1000008];


int main(){
int m,n,g,x,y,sx,sy,i,j;
int dx[]={1,0,-1,0},dy[]={0,-1,0,1},d;

memset(prime,1,sizeof(prime));
prime[0]=prime[1]=0;
for(i=2;i<=1000003;i++){
if(prime[i])for(j=i*2;j<=1000003;j+=i){
prime[j]=0;
}
}

while(1){
scanf("%d %d",&m,&n);
if(m==0&&n==0)break;

memset(holes,0,sizeof(holes));
memset(table,-1,sizeof(table));
g=(int)ceil(sqrt(m));
y=x=g/2+1;	//縁を0でうめる
d=3;
holes[y][x]=1;
for(i=2;i<=m;i++){
if(holes[y+dy[(d+1)%4]][x+dx[(d+1)%4]]==0){
d=(d+1)%4;
}
x+=dx[d];
y+=dy[d];

holes[y][x]=i;
if(i==n){
sx=x;
sy=y;
}
}

/* for(i=0;i<=g+1;i++){
for(j=0;j<=g+1;j++)
printf("%3d ",holes[i][j]);
printf("\n");
}
*/
int maxNum=0,maxCnt=0;
table[sy][sx]=0;
for(y=sy;y<=g;y++){
for(x=1;x<=g;x++){
if(table[y][x]==-1)continue;
if(prime[holes[y][x]])table[y][x]++;
if(maxCnt<table[y][x] && holes[y][x]>0){
maxCnt=table[y][x];
maxNum=holes[y][x];
}else if(maxCnt==table[y][x]){
if(maxNum<holes[y][x])
if(prime[holes[y][x]])
maxNum=holes[y][x];
}

for(i=-1;i<=1;i++){
if(table[y+1][x+i]<table[y][x]){
table[y+1][x+i]=table[y][x];
}
}
}
}

/*cout<<endl;
for(i=0;i<=g+1;i++){
for(j=0;j<=g+1;j++)
printf("%3d ",table[i][j],holes[i][j]);
printf("\n");
}*/

parintf("%d %d\n",maxCnt,maxNum);


}

return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:83:1: error: 'parintf' was not declared in this scope; did you mean 'printf'?
   83 | parintf("%d %d\n",maxCnt,maxNum);
      | ^~~~~~~
      | printf