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

#include<iostream>
#include<list>
using namespace std;

class Chain
{
    public:
    int tail;
    int length;
    
    Chain(int b)
    {
        tail = b;
        length = 2;
    };
};

int main(){
    
    while(1)
    {
        int num;
        cin>>num;
        
        if(num==0)
        {
            break;
        }
        
        int chainB;
        int length;
        list< Chain > clist;
        
        for(int i=0;i<num;++i)
        {
            int a, b;
            cin>>a;
            cin>>b;
            
            if(clist.empty())
            {
                clist.push_back(Chain(b));
                continue;
            }
            
            list< Chain >::iterator it = clist.begin();
            bool added = false;
            while(it != clist.end())
            {
                if((*it).tail == a)
                {
                    (*it).length += 1;
                    (*it).tail = b;
                    added = true;
                }
                ++it;
            }
            if(!added)
            {
                clist.push_back(Chain(b));
            }
        }
        
        int maxLength = 0;
        list< Chain >::iterator it = clist.begin();
        while(it != clist.end())
        {
            if((*it).length>maxLength)
            {
                macLength = (*it).length;
            }
        }
        cout<<macLength<<endl;
        
    }
    
    return 0;
};

Compiler output:
a.cc: In function 'int main()':
a.cc:70:17: error: 'macLength' was not declared in this scope; did you mean 'maxLength'?
   70 |                 macLength = (*it).length;
      |                 ^~~~~~~~~
      |                 maxLength
a.cc:73:15: error: 'macLength' was not declared in this scope; did you mean 'maxLength'?
   73 |         cout<<macLength<<endl;
      |               ^~~~~~~~~
      |               maxLength
Language: C++

#include<iostream>
#include<list>
using namespace std;

class Chain
{
    public:
    int tail;
    int length;
    
    Chain(int b)
    {
        tail = b;
        length = 2;
    };
};

int main(){
    
    ifstream ifs("input.txt");
    ofstream ofs("output.txt");
    
    while(1)
    {
        int num;
        ifs>>num;
        
        if(num==0)
        {
            break;
        }
        
        int chainB;
        int length;
        list< Chain > clist;
        
        for(int i=0;i<num;++i)
        {
            int a, b;
            ifs>>a;
            ifs>>b;
            
            if(clist.empty())
            {
                clist.push_back(Chain(b));
                continue;
            }
            
            list< Chain >::iterator it = clist.begin();
            bool added = false;
            while(it != clist.end())
            {
                if((*it).tail == a)
                {
                    (*it).length += 1;
                    (*it).tail = b;
                    added = true;
                }
                ++it;
            }
            if(!added)
            {
                clist.push_back(Chain(b));
            }
        }
        
        int maxLength = 0;
        list< Chain >::iterator it = clist.begin();
        while(it != clist.end())
        {
            if((*it).length>maxLength)
            {
                maxLength = (*it).length;
            }
            ++it;
        }
        ofs<<maxLength<<endl;
        
    }
    ofs<<endl;
    
    return 0;
};

Compiler output:
a.cc: In function 'int main()':
a.cc:20:17: error: variable 'std::ifstream ifs' has initializer but incomplete type
   20 |     ifstream ifs("input.txt");
      |                 ^
a.cc:3:1: note: 'std::ifstream' is defined in header '<fstream>'; this is probably fixable by adding '#include <fstream>'
    2 | #include<list>
  +++ |+#include <fstream>
    3 | using namespace std;
a.cc:21:17: error: variable 'std::ofstream ofs' has initializer but incomplete type
   21 |     ofstream ofs("output.txt");
      |                 ^
a.cc:21:17: note: 'std::ofstream' is defined in header '<fstream>'; this is probably fixable by adding '#include <fstream>'
Language: C++

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int n,G[100][100],L[100],D[100];

int solve(int m)
{
    int r=0;
    D[m]=1;
    for(int i=0;i<L[m];i++){
        int k=G[m][i];
        if(!D[k]){
            r=max(r,solve(k));
        }
    }
    D[m]=0
    return r+1;
}

int main()
{
    while(scanf("%d",&n),n){
        int r=0;
        memset(L,0,sizeof(L));
        while(n--){
            int a,b;
            scanf("%d%d",&a,&b);
            G[a][L[a]++]=b;
            G[b][L[b]++]=a;
        }
        for(int i=0;i<100;i++){
            r=max(r,solve(i));
        } 
        printf("%d\n",r+1);
    }
}

Compiler output:
a.cc: In function 'int solve(int)':
a.cc:18:11: error: expected ';' before 'return'
   18 |     D[m]=0
      |           ^
      |           ;
   19 |     return r+1;
      |     ~~~~~~ 
a.cc:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
   20 | }
      | ^
Language: C++

#include <stdio.h>
#include <stdbool.h>

#define MAX_VERTEX_NUM 100

typedef struct {
    char linked_num;
    char linked[MAX_VERTEX_NUM-1];
} vertex;

vertex vertex_list[MAX_VERTEX_NUM];
bool has_arrived[MAX_VERTEX_NUM];
char count_max;

void vertex_init() {
    int i;
    for (i=0;i < MAX_VERTEX_NUM;i++) {
        vertex_list[i].linked_num = 0;
    }

    return ;
}

void link(int id1, int id2) {
    vertex *obj1 = &vertex_list[id1];
    vertex *obj2 = &vertex_list[id2];

    int num1 = obj1->linked_num;
    int num2 = obj2->linked_num;
    obj1->linked[num1] = id2;
    obj2->linked[num2] = id1;

    obj1->linked_num += 1;
    obj2->linked_num += 1;

    return ;
}

void rec(int id, int now_count) {
    int i;

    if (has_arrived[id]) {
        return ;
    }

    has_arrived[id] = 1;
    if (count_max < now_count+1)count_max = now_count+1;

    for (i=0;i < vertex_list[id].linked_num;i++) {
        rec(vertex_list[id].linked[i], now_count + 1);
    }

    has_arrived[id] = 0;

    return ;
}

int main() {
    while (1) {
        int i,n;
        scanf("%d", &n);
        if (n == 0) return;

        vertex_init();

        for (i=0;i<n;i++) {
            int id1, id2;
            scanf("%d %d", &id1, &id2);
            link(id1-1, id2-1);
        }

        count_max = 0;

        for (i=0;i<n;i++) {
            rec(i, 0);
        }

        printf("%d\n", count_max);
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:21: error: return-statement with no value, in function returning 'int' [-fpermissive]
   62 |         if (n == 0) return;
      |                     ^~~~~~
Language: C++

#include<iostream>
#include<set>
#include<bitset>
#include<algorithm>
using namespace std;

set<int> vertex;
vector< vector<int> > edge;

int dfs(int v, bitset<101> visited) {
    int result = visited.count() + 1;
    visited.set(v);
    for(vector<int>::iterator i=edge[v].begin(); i!=edge[v].end(); i++) {
        if(visited.test(*i)) continue;
        result = max(result, dfs(*i, visited));
    }
    return result;
}

int solve() {
    int result = 0;
    for(set<int>::iterator i=vertex.begin(); i!=vertex.end(); i++) {
        result = max(result, dfs(*i, bitset<101>(0)));
    }
    return result;
}

int main() {
    int n;
    while(cin>>n, n) {
        edge = vector< vector<int> >(101);
        for(int i=0; i<n; i++) {
            int u, v;
            cin>>u>>v;
            vertex.insert(--u);
            vertex.insert(--v);
            edge[u].push_back(v);
            edge[v].push_back(u);
        }
        cout<<solve()<<endl;
    }
}

Compiler output:
a.cc:8:1: error: 'vector' does not name a type
    8 | vector< vector<int> > edge;
      | ^~~~~~
a.cc: In function 'int dfs(int, std::bitset<101>)':
a.cc:13:9: error: 'vector' was not declared in this scope
   13 |     for(vector<int>::iterator i=edge[v].begin(); i!=edge[v].end(); i++) {
      |         ^~~~~~
a.cc:5:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    4 | #include<algorithm>
  +++ |+#include <vector>
    5 | using namespace std;
a.cc:13:16: error: expected primary-expression before 'int'
   13 |     for(vector<int>::iterator i=edge[v].begin(); i!=edge[v].end(); i++) {
      |                ^~~
a.cc:13:50: error: 'i' was not declared in this scope
   13 |     for(vector<int>::iterator i=edge[v].begin(); i!=edge[v].end(); i++) {
      |                                                  ^
a.cc:13:53: error: 'edge' was not declared in this scope
   13 |     for(vector<int>::iterator i=edge[v].begin(); i!=edge[v].end(); i++) {
      |                                                     ^~~~
a.cc: In function 'int main()':
a.cc:31:9: error: 'edge' was not declared in this scope
   31 |         edge = vector< vector<int> >(101);
      |         ^~~~
a.cc:31:16: error: 'vector' was not declared in this scope
   31 |         edge = vector< vector<int> >(101);
      |                ^~~~~~
a.cc:31:16: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
a.cc:31:31: error: expected primary-expression before 'int'
   31 |         edge = vector< vector<int> >(101);
      |                               ^~~
Language: Java

import java.util.Arrays;
import java.util.Scanner;


public class Sheets{
	
	public static void main(String[] args){
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int kindOfProblem = sc.nextInt();
	
		Sheet s = new Sheet(10001);
		for(int i = 0; i < n; i++) {
			s.addSheet(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
		}
		sc.close();
		switch(kindOfProblem) {
			case 1:
				System.out.println(s.countTrue());
				break;
			case 2:
				System.out.println(s.countTrue());
				System.out.println(s.calcLength());
		}
	}
	
}

class Sheet{
	boolean[][] grid;
	
	Sheet(int size){
		this.grid = new boolean[size][size];
		for(boolean[] row: grid) {
			Arrays.fill(row, false);
		}
	}
	
	void addSheet(int x1, int y1, int x2, int y2) {
		for(int i = y1; i < y2; i++){
			for(int j = x1; j < x2; j++) {
				this.grid[i][j] = true;
			}
		}
	}
	
	int countTrue() {
		int result = 0;
		for(int i = 0; i < grid.length; i++) {
			for(int j = 0; j < grid[i].length; j++) {
				if(grid[i][j]) result++;
			}
		}
		return result;
	}
	
	int calcLength() {
		int result = 0;
		for(int i = 0; i < grid.length; i++) {
			for(int j = 0; j < grid[i].length; j++) {
				if(grid[i][j]) {
					if(!check(i, j-1)) result++;
					if(!check(i-1, j)) result++;
					if(!check(i+1, j)) result++;
					if(!check(i, j+1)) result++;
				}
			}
		}
		return result;
	}
	
	boolean check(int x, int y) {
		if(0 <= x && x < grid[0].length && 0 <= y && y < grid.length) return grid[x][y];
		else return false;
	}
}

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

import java.util.Scanner;

public class Sheet {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		
		
		int numOfSheet = in.nextInt();
		int probNum = in.nextInt();
		int[][] matrix;
		while(!(numOfSheet==0 && probNum==0)) {
			int maxX = 0, maxY = 0;
			int[][] data = new int[numOfSheet][4];
			for(int i=0; i<numOfSheet; i++) {
				data[i][0] = in.nextInt();//x1
				data[i][1] = in.nextInt();//y1
				data[i][2] = in.nextInt();//x2
				data[i][3] = in.nextInt();//y2
				
				if(data[i][0]>maxX) maxX=data[i][0];
				if(data[i][2]>maxX) maxX=data[i][2];
				if(data[i][1]>maxY) maxY=data[i][1];
				if(data[i][3]>maxY) maxY=data[i][3];
			}
			
			matrix = new int[maxX+1][maxY+1];
			
			for(int i=0; i<data.length; i++) {
				for(int j=data[i][0]; j<data[i][2]; j++) {
					for(int k=data[i][1]; k<data[i][3]; k++) {
						matrix[k][j] = 1;
					}
				}
			}
			
			if(probNum==1 || probNum==2) {
				int area = 0;
				for(int i=0; i<matrix.length; i++) {
					for(int j=0; j<matrix[i].length; j++) {
						area+= matrix[i][j];
					}
				}
				System.out.println(area);
			}
			if(probNum==2) {
				int length = 0;
				for(int i=0; i<matrix.length; i++) {
					for(int j=0; j<matrix[i].length; j++) {
						if(matrix[i][j] == 1) length += getLength(i, j, matrix);
						
					}
				}
				System.out.println(length);
			}
			numOfSheet = in.nextInt();
			probNum = in.nextInt();
		}
	}
	
	public static int getLength(int x, int y, int[][] matrix) {
		int ret = 0;
		int n = 0;
		if(x==0&&y==0) n = matrix[x][y+1] + matrix[x+1][y];
		else if(x==0&&y==matrix[0].length-1) n = matrix[x][y-1] + matrix[x+1][y];
		else if(x==matrix.length-1&&y==0) n = matrix[x-1][y] + matrix[x][y+1];
		else if(x==matrix.length-1&&y==matrix[x].length-1) n = matrix[x][y-1] + matrix[x-1][y];
		else if(x==0) n = matrix[x][y+1] + matrix[x][y-1] + matrix[x+1][y];
		else if(x==matrix.length-1) n = matrix[x][y+1] + matrix[x][y-1] + matrix[x-1][y];
		else if(y==0) n = matrix[x-1][y] + matrix[x+1][y] + matrix[x][y+1];
		else if(y==matrix[x].length-1) n = matrix[x-1][y] + matrix[x+1][y] + matrix[x][y-1];
		else n = matrix[x-1][y] + matrix[x+1][y] + matrix[x][y-1] + matrix[x][y+1];
		
		switch(n){
		case 1:
			ret = 3;
			break;
		case 2:
			ret = 2;
			break;
		case 3:
			ret = 1;
			break;
		default:
			break;
		}
		
		return ret;
	}
}

Compiler output:
Main.java:3: error: class Sheet is public, should be declared in a file named Sheet.java
public class Sheet {
       ^
1 error
Language: C

#include<stdio.h>
main(){
  int n,r;
  int i,j,k;
  int Mx,My;
  int p[10000][4];
  while(scanf("%d %d",&n,&r)!=EOF){
    Mx = My = 100;
    for(k=0,k<n,k++){
      scanf("%d %d %d %d",&p[k][0],&p[k][1],&p[k][2],&p[k][3]);
      if(p[k][2]>Mx){
        Mx = p[k][2];
      }
      if(p[k][3]>My){
        My = p[k][3];
      }      
    }
    sl(p,Mx,My,n,r);
  }
}

void sl(int p[][4],int Mx,int My,int n,int r){
  int f[Mx][My];
  int i,j,k;
  int s,l;
  s = 0
  for(i=0;i<Mx;i++){
    for(j=0;j<My;j++){
      f[i][j] = 0;
    }
  }
  for(k=0;k<n;k++){
    for(i=p[k][0];i<p[k][2];i++){
      for(j=p[k][1];j<p[k][3];j++){
        if(f[i][j]==0){
          s++;
        }
        f[i][j] = 1;
      }
    }
  } 
  printf("%d\n",s);
  if(r==2){
    l = 0
    for(i=0;i<Mx-1;i++){
      l+=(f[i][0]+f[i][Mx-1]);
      for(j=0;j<My-1;j++){
        l+=(f[i][j]^f[i][j+1]);
      }
    }
    for(j=0;j<My-1;j++){
      l+=(f[0][j]+f[My-1][j]);
      for(i=0;<Mx-1;i++){
        l+=(f[i+1][j]^f[i][j]);
      }
    }
    printf("%d\n",l);
  }
}

Compiler output:
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
    2 | main(){
      | ^~~~
main.c: In function 'main':
main.c:9:20: error: expected ';' before ')' token
    9 |     for(k=0,k<n,k++){
      |                    ^
      |                    ;
main.c:9:20: error: expected expression before ')' token
main.c:18:5: error: implicit declaration of function 'sl' [-Wimplicit-function-declaration]
   18 |     sl(p,Mx,My,n,r);
      |     ^~
main.c: At top level:
main.c:22:6: warning: conflicting types for 'sl'; have 'void(int (*)[4], int,  int,  int,  int)'
   22 | void sl(int p[][4],int Mx,int My,int n,int r){
      |      ^~
main.c:18:5: note: previous implicit declaration of 'sl' with type 'void(int (*)[4], int,  int,  int,  int)'
   18 |     sl(p,Mx,My,n,r);
      |     ^~
main.c: In function 'sl':
main.c:26:8: error: expected ';' before 'for'
   26 |   s = 0
      |        ^
      |        ;
   27 |   for(i=0;i<Mx;i++){
      |   ~~~   
main.c:44:10: error: expected ';' before 'for'
   44 |     l = 0
      |          ^
      |          ;
   45 |     for(i=0;i<Mx-1;i++){
      |     ~~~
Language: C

#include<stdio.h>
main(){
  int n,r;
  int i,j,k;
  int Mx,My;
  int p[10000][4];
  while(scanf("%d %d",&n,&r)!=EOF){
    Mx = My = 100;
    for(k=0,k<n,k++){
      scanf("%d %d %d %d",&p[k][0],&p[k][1],&p[k][2],&p[k][3]);
      if(p[k][2]>Mx){
        Mx = p[k][2];
      }
      if(p[k][3]>My){
        My = p[k][3];
      }      
    }
    sl(p,Mx,My,n,r);
  }
}

void sl(int p[][4],int Mx,int My,int n,int r){
  int f[Mx][My];
  int i,j,k;
  int s,l;
  s = 0;
  for(i=0;i<Mx;i++){
    for(j=0;j<My;j++){
      f[i][j] = 0;
    }
  }
  for(k=0;k<n;k++){
    for(i=p[k][0];i<p[k][2];i++){
      for(j=p[k][1];j<p[k][3];j++){
        if(f[i][j]==0){
          s++;
        }
        f[i][j] = 1;
      }
    }
  } 
  printf("%d\n",s);
  if(r==2){
    l = 0;
    for(i=0;i<Mx-1;i++){
      l+=(f[i][0]+f[i][Mx-1]);
      for(j=0;j<My-1;j++){
        l+=(f[i][j]^f[i][j+1]);
      }
    }
    for(j=0;j<My-1;j++){
      l+=(f[0][j]+f[My-1][j]);
      for(i=0;<Mx-1;i++){
        l+=(f[i+1][j]^f[i][j]);
      }
    }
    printf("%d\n",l);
  }
}

Compiler output:
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
    2 | main(){
      | ^~~~
main.c: In function 'main':
main.c:9:20: error: expected ';' before ')' token
    9 |     for(k=0,k<n,k++){
      |                    ^
      |                    ;
main.c:9:20: error: expected expression before ')' token
main.c:18:5: error: implicit declaration of function 'sl' [-Wimplicit-function-declaration]
   18 |     sl(p,Mx,My,n,r);
      |     ^~
main.c: At top level:
main.c:22:6: warning: conflicting types for 'sl'; have 'void(int (*)[4], int,  int,  int,  int)'
   22 | void sl(int p[][4],int Mx,int My,int n,int r){
      |      ^~
main.c:18:5: note: previous implicit declaration of 'sl' with type 'void(int (*)[4], int,  int,  int,  int)'
   18 |     sl(p,Mx,My,n,r);
      |     ^~
main.c: In function 'sl':
main.c:53:15: error: expected expression before '<' token
   53 |       for(i=0;<Mx-1;i++){
      |               ^
Language: C

#include<stdio.h>
#include<string.h>
bool m[10005][10005];
int main(){
	int i,j,x1,y1,x2,y2,n,r;
	int sx,sy,bx,by,a,b;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	while(1){
		fscanf(fp,"%d%d",&n,&r);
		if(n==0 && r==0)break;
		sx=sy=10000;
		bx=by=0;
		memset(m,0,sizeof(m));
		while(n--){
			fscanf(fp,"%d%d%d%d",&x1,&y1,&x2,&y2);
			if(x1<sx)sx=x1;
			if(y1<sy)sy=y1;
			if(x2+1>bx)bx=x2+1;
			if(y2+1>by)by=y2+1;
			for(i=y1+1;i<=y2;i++){
				for(j=x1+1;j<=x2;j++){
					m[i][j]=true;
				}
			}
		}
		a=b=0;
		for(i=sy;i<=by;i++){
			for(j=sx;j<=bx;j++){
				if(m[i][j])a++;
				else{
					if(m[i+1][j])b++;
					if(m[i][j+1])b++;
					if(i-1>=sy && m[i-1][j])b++;
					if(j-1>=sx && m[i][j-1])b++;
				}
				//printf("%d",m[i][j]);
			}
			//printf("\n");
		}
		printf("%d\n",a);
		if(r==2)printf("%d\n",b);
	}
	fclose(fp);
	return 0;
}

Compiler output:
main.c:3:1: error: unknown type name 'bool'
    3 | bool m[10005][10005];
      | ^~~~
main.c:3:1: note: 'bool' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
    2 | #include<string.h>
  +++ |+#include <stdbool.h>
    3 | bool m[10005][10005];
main.c: In function 'main':
main.c:24:49: error: 'true' undeclared (first use in this function)
   24 |                                         m[i][j]=true;
      |                                                 ^~~~
main.c:24:49: note: 'true' is defined in header '<stdbool.h>'; this is probably fixable by adding '#include <stdbool.h>'
main.c:24:49: note: each undeclared identifier is reported only once for each function it appears in
Language: C

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

typedef struct {
    int sx, sy;
    int ex, ey;
} RECT;

int area;
int length;

RECT calc[10000];
RECT before[10000];
RECT grid[10000];
int bsize;

bool comp(const RECT& rLeft, const RECT& rRight){
    return (rLeft.sx < rRight.sx);
}

void mergeArea(int n, int *sq)
{
    int i, j;
    int num;
    int start, end;
    
    if (n == 0){
        return;
    }
    
    sort(grid, grid + n, comp);
    
    num = 0;
    start = grid[0].sx;
    end = grid[0].ex;
    for (i = 1; i < n; i++){
        if (grid[i].sx <= end){
            end = max(end, grid[i].ex);
        }
        else {
            calc[num].sx = start;
            calc[num++].ex = end;
            start = grid[i].sx;
            end = grid[i].ex;
        }
    }
    calc[num].sx = start;
    calc[num++].ex = end;
    for (i = 0; i < num; i++){
        area += calc[i].ex - calc[i].sx;
    }
    
    *sq = num;
}

void mergeLength(int n)
{
    vector<int> total;
    int i;
    int res;
    
    for (i = 0; i < n; i++){
        total.push_back(calc[i].sx);
        total.push_back(calc[i].ex);
    }
    for (i = 0; i < bsize; i++){
        total.push_back(before[i].sx);
        total.push_back(before[i].ex);
    }
    
    sort(total.begin(), total.end());
    res = 0;
    for (i = 0; i < total.size(); i += 2){
        res += total[i + 1] - total[i];
    }
    length += res + 2 * n;
}

int main(void)
{
    int n, query;
    static RECT p[10000];
    int num;
    int i, j;
    int sq;
    int miny, maxy;
    
    while (1){
        scanf("%d%d", &n, &query);
        
        if (n + query == 0){
            break;
        }
        area = length = 0;
        miny = 1000000;
        maxy = -100000;
        for (i = 0; i < n; i++){
            scanf("%d%d%d%d", &p[i].sx, &p[i].sy, &p[i].ex, &p[i].ey);
            miny = min(miny, p[i].sy);
            maxy = max(maxy, p[i].ey);
        }
        if (query == 1){
            continue;
        }
        bsize = 0;
        memset(before, 0, sizeof(before));
        area = length = 0;
        for (i = miny; i <= maxy; i++){
            memset(grid, 0, sizeof(grid));
            num = sq = 0;
            for (j = 0; j < n; j++){
                if (p[j].sy <= i && i < p[j].ey){
                    grid[num++] = p[j];
                }
            }
            mergeArea(num, &sq);
            if (query == 2 && (bsize != 0 || num != 0)){
                mergeLength(sq);
            }
            memcpy(before, calc, sizeof(calc));
            bsize = sq;
        }
        printf("%d\n", area);
        if (query == 1){
            continue;
        }
        printf("%d\n", length);
    }
    
    return (0);
}

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

#include<string.h>
#include<stdio.h>
#define max(x,y) ((x>y)?x:y)
#define min(x,y) ((x<y)?x:y)
using namespace std;

int g[10003][10003];
int n,r;

int main(){
	while(1){
		int ans=0,ans2=0,minx=10001,miny=10001,maxx=1,maxy=1;
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(g,0,sizeof(g));
		for(int i=0;i<n;i++){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++,y1++,x2++,y2++;
			minx=min(min(x1,x2),minx);
			miny=min(min(y1,y2),miny);
			maxx=max(max(x1,x2),maxx);
			maxy=max(max(y1,y2),maxy);
			g[x1][y1]+=1;
			g[x2][y1]-=1;
			g[x1][y2]-=1;
			g[x2][y2]+=1;
		}
		for(int i=miny;i<=maxy;i++){
			int t=0;
			for(int j=minx;j<=maxx;j++){
				t+=g[j][i];
				g[j][i]=t;
			}
		}
		for(int i=minx;i<=maxx;i++){
			int t=0;
			for(int j=miny;j<=maxy;j++){
				t+=g[i][j];
				g[i][j]=t;
				if(g[i][j]>0){
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		if(r==2){
			for(int i=minx;i<=maxx;i++){
				for(int j=miny;j<=maxy;j++){
					if(g[i][j]>=1){
						if(g[i-1][j]<=0)ans2++;
						if(g[i+1][j]<=0)ans2++;
						if(g[i][j-1]<=0)ans2++;
						if(g[i][j+1]<=0)ans2++;
					}
				}
			}
			printf("%d\n",ans2);
		}
	}
    return 0;
}

Compiler output:
main.c:5:1: error: unknown type name 'using'
    5 | using namespace std;
      | ^~~~~
main.c:5:17: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'std'
    5 | using namespace std;
      |                 ^~~
Language: C

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;

int g[10003][10003];
int n,r;

int main(){
	while(1){
		int ans=0,ans2=0,minx=10001,miny=10001,maxx=1,maxy=1;
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(g,0,sizeof(g));
		for(int i=0;i<n;i++){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++,y1++,x2++,y2++;
			minx=min(x1,minx);
			miny=min(y1,miny);
			maxx=max(x2,maxx);
			maxy=max(y2,maxy);
			g[x1][y1]++;
			g[x2][y1]--;
			g[x1][y2]--;
			g[x2][y2]++;
		}
		/*for(int i=miny;i<=maxy;i++){
			int t=0;
			for(int j=minx;j<=maxx;j++){
				t+=g[j][i];
				g[j][i]=t;
			}
		}
		for(int i=minx;i<=maxx;i++){
			int t=0;
			for(int j=miny;j<=maxy;j++){
				t+=g[i][j];
				g[i][j]=t;
				if(g[i][j]>0){
					ans++;
				}
			}
		}*/
		printf("%d\n",ans);
		/*if(r==2){
			for(int i=minx;i<=maxx;i++){
				for(int j=miny;j<=maxy;j++){
					if(g[i][j]>=1){
						if(g[i-1][j]<=0)ans2++;
						if(g[i+1][j]<=0)ans2++;
						if(g[i][j-1]<=0)ans2++;
						if(g[i][j+1]<=0)ans2++;
					}
				}
			}
			printf("%d\n",ans2);
		}*/
	}
    return 0;
}

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

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int g[10003][10003];
int n,r;

int main(){
	while(scanf("%d%d",&n,&r),n){
		memset(g,0,sizeof(g));
		int mx = 10001,Mx = 1,my = 10001,My = 1;
		for(int i = 0; i < n; i++){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			a++;b++;c++;d++;
			g[a][b]++; g[a][d]--;
			g[c][b]--; g[c][d]++;
			mx = min(mx,a);
			Mx = max(Mx,c);
			my = min(my,b);
			My = max(My,d);
		}
		
		for(int i = mx; i <= Mx; i++){
			int t = 0;
			for(int j = my; j <= My; j++){
				t += g[i][j];
				g[i][j] = t;
			}
		}
		
		int s = 0;
		for(int j = my; j <= My; j++){
			int t = 0;
			for(int i = mx; i <= Mx; i++){
				t += g[i][j];
				if(g[i][j] = t)s++;
			}
		}
		printf("%d\n",s);
		
		if(r==2){
			int l = 0;
			for(int i = mx; i <= Mx; i++){
				for(int j = my; j <= My; j++){
					if(g[i][j]){
						l += !g[i-1][j]+!g[i+1][j]+!g[i][j-1]+!g[i][j+1];
					}
				}
			}
			printf("%d\n",l);
		}
	}
	return 0;
}

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;

#define INF 2000000000
#define LLINF 4000000000000000000
#define SIZE 10004

int mm[SIZE][SIZE];
int mo[5] = {0,1,0,-1,0};

void calc(int n,int r){
    int x_1,x_2,y_1,y_2,minx=SIZE-1,maxx=0,miny=SIZE-1,maxy=0;
    int ansV=0,ansL=0;
    
    memset(mm,0,sizeof(mm));
    
    for(int i=0;i<n;i++){
        scanf("%d%d%d%d",&x_1,&y_1,&x_2,&y_2);
        
        x_1++;
        y_1++;
        x_2++;
        y_2++;
        
        mm[x_1][y_1]++;
        mm[x_2][y_1]--;
        mm[x_1][y_2]--;
        mm[x_2][y_2]++;
        
        minx = min(minx,x_1);
        miny = min(miny,y_1);
        maxx = max(maxx,x_2);
        maxy = max(maxy,y_2);
    }
    
    for(int i=miny;i<=maxy;i++){
        for(int j=minx+1;j<=maxx;j++){
            mm[j][i]+=mm[j-1][i];
        }
    }
    
    for(int i=minx;i<=maxx;i++){
        for(int j=miny+1;j<=maxy;j++){
            mm[i][j]+=mm[i][j-1];
        }
    }
    
    for(int i=minx;i<maxx;i++){
        for(int j=miny;j<maxy;j++){
            if(mm[i][j]>0){
                ansV++;
                
                for(int k=0;k<4;k++){
                    if(mm[i+mo[k]][j+mo[k+1]]==0){
                        ansL++;
                    }
                }
                
            }
        }
    }
    
    printf("%d\n",ansV);
    
    if(r==2)
        printf("%d\n",ansL);
    
    return;
}

int main(){
    int n,r;
    
    while(1){
        scanf("%d%d",&n,&r);
        if(n==0) break;
        calc(n,r);
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'void calc(int, int)':
a.cc:26:5: error: 'memset' was not declared in this scope
   26 |     memset(mm,0,sizeof(mm));
      |     ^~~~~~
a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   10 | #include <map>
  +++ |+#include <cstring>
   11 |
Language: C++

#include<iostream>
#include<stdio.h>
#include<list>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int short[10001][10001];

int main(){
    
    int n,r;
    
        int S=0;
        int L=0;
        int state;
  

    
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;

        memset(map,0,sizeof(map));

        
        int x_min=10001,x_max=0,y_min=10001,y_max=0;
       
        int x1,y1,x2,y2;
        for(int i=0;i<n;i++){
            
            cin>>x1>>y1>>x2>>y2;
            
            map[x1][y1]+=1;
            map[x1][y2]-=1;
            map[x2][y1]-=1;
            map[x2][y2]+=1;
            
            if(x_min>x1)x_min=x1;
            if(y_min>y1)y_min=y1;
            if(x_max<x2)x_max=x2;
            if(y_max<y2)y_max=y2;
            
        }

        S=0;
        L=0;
        
        for(int h=y_min;h<=y_max;h++){
            state=0;
            for(int w=x_min;w<=x_max;w++){
                state+=map[w][h];
                map[w][h]=state;
            }
        }
        for(int w=x_min;w<=x_max;w++){
            state=0;
            for(int h=y_min;h<=y_max;h++){
                state+=map[w][h];
                map[w][h]=state;
                if(map[w][h]>0){
                   S++;
                   if(w==0)L+=2;
                   else if(map[w-1][h]==0)L+=2;
                   if(h==0)L+=2;
                   else if(map[w][h-1]==0)L+=2;
               }
            }
        }
        cout<<S<<endl;
        if(r==2){
            cout<<L<<endl;
        }
        
        

    }

    

}

Compiler output:
a.cc:9:11: error: expected identifier before numeric constant
    9 | int short[10001][10001];
      |           ^~~~~
a.cc:9:11: error: expected ']' before numeric constant
    9 | int short[10001][10001];
      |           ^~~~~
      |           ]
a.cc:9:10: error: structured binding declaration cannot have type 'short int'
    9 | int short[10001][10001];
      |          ^
a.cc:9:10: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:9:10: error: empty structured binding declaration
a.cc:9:17: error: expected initializer before '[' token
    9 | int short[10001][10001];
      |                 ^
a.cc: In function 'int main()':
a.cc:25:16: error: 'map' was not declared in this scope
   25 |         memset(map,0,sizeof(map));
      |                ^~~
a.cc:7:1: note: 'std::map' is defined in header '<map>'; this is probably fixable by adding '#include <map>'
    6 | #include<algorithm>
  +++ |+#include <map>
    7 | using namespace std;
Language: C++

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

const static int MAX = 10000;
bool Sheets[MAX+2][MAX+2];

int count(int x,int y) {
  int dx[4] = {-1,0,0,1};
  int dy[4] = {0,1,-1,0};
  int cnt = 0;
  for(int d=0;d<4;d++) {
    if(!Sheets[x+dx[d]][y+dy[d]])
      cnt++;
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n,r;
  while(cin >> n >> r) {
    if(n+r == 0) break;
    memset(Sheets,0,sizeof(Sheets));

    int x[2],y[2];
    for(int i=0;i<n;i++) {
      cin >> x[0] >> y[0] >> x[1] >> y[1];
      for(int w=x[0]+1;w<=x[1];w++) {
        for(int h=y[0]+1;h<=y[1];h++) {
          Sheets[h][w] = true;
        }
      }
    }

    // calc
    int length = 0;
    int surface = 0;
    for(int i=1;i<=MAX;i++) {
      for(int j=1;j<=MAX;j++) {
        if(Sheets[i][j]) {
          surface++;
          length += count(i,j);
        }
      }
    }
    cout << surface << endl;
    if(r==2) cout << length << endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:26:5: error: 'memset' was not declared in this scope
   26 |     memset(Sheets,0,sizeof(Sheets));
      |     ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include <vector>
  +++ |+#include <cstring>
    3 | using namespace std;
Language: C++

#include<stdio.h>
main(){
  printf(" ")
}

Compiler output:
a.cc:2:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    2 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:3:14: error: expected ';' before '}' token
    3 |   printf(" ")
      |              ^
      |              ;
    4 | }
      | ~
Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define mp         make_pair
#define pb         push_back

const int N = 30000;

class st{
public:
  int height;
  int out;//1 or -1
  bool operator<(const st & a)const{
    if (height != a.height)return height < a.height;
    return out > a.out;
  }
};

int x[N];
vector<st> inx[N];

int y[N];
vector<st> iny[N];

/*
29
29

80

45



*/

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int &py){
  vector<int> xd,yd;
  rep(i,n){
    xd.pb(x1[i]);
    xd.pb(x2[i]);
    yd.pb(y1[i]);
    yd.pb(y2[i]);
  }
  sort(ALL(xd));
  sort(ALL(yd));
  xd.erase(unique(ALL(xd)),xd.end());
  yd.erase(unique(ALL(yd)),yd.end());
  rep(i,xd.size())x[px++]=xd[i],inx[i].clear();
  rep(i,yd.size())y[py++]=yd[i],iny[i].clear();

  //cout <<"allx ";rep(i,px)cout << x[i]<<" ";cout << endl;
  rep(i,n){
    int j=lower_bound(xd.begin(),xd.end(),x1[i])-xd.begin();
    while(j < px && x[j] < x2[i]){
      inx[j].pb((st){y1[i],1});
      inx[j].pb((st){y2[i],-1});
      j++;
    }
    j = lower_bound(ALL(yd),y1[i])-yd.begin();
    while(j < py && y[j] < y2[i]){
      iny[j].pb((st){x1[i],1});
      iny[j].pb((st){x2[i],-1});
      j++;
    }
  }
}

pair<int,int> solve(int n,vector<st> *in,int *c){
  int area=0;
  int len=0;
  rep(i,n-1){
    if (in[i].size() == 0)continue;
    sort(in[i].begin(),in[i].end());
    int cnt=0,prev=-100;
    int width;
    width=c[i+1]-c[i];
    rep(j,in[i].size()){
      if (cnt > 0){
	area+=(in[i][j].height-prev)*width;
      }
      //if (cnt == 0 && in[i][j].height != prev){
      if (cnt == 0){
	len+=width;
      }
      cnt+=in[i][j].out;
      //if (cnt == 0 && in[i][j].height != prev){
      if (cnt == 0){
	len+=width;
      }
      prev=in[i][j].height;
    }
  }
  return mp(area,len);
}

main(){
  int n,q;
  static int x1[N],y1[N],x2[N],y2[N];
  while(cin>>n>>q && n){
    rep(i,n){
      cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    }
    int px=0,py=0;
    makedata(n,x1,x2,y1,y2,px,py);
    pair<int,int> ansx=solve(px,inx,x);
    pair<int,int> ansy= solve(py,iny,y);
    cout << ansx.first << endl;
    if (q == 2)cout << ansx.second+ansy.second << endl;
  }
  return false;
}

Compiler output:
a.cc: In function 'void makedata(int, int*, int*, int*, int*, int&, int&)':
a.cc:53:3: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   53 |   sort(ALL(xd));
      |   ^~~~
      |   sqrt
a.cc:55:12: error: 'unique' was not declared in this scope
   55 |   xd.erase(unique(ALL(xd)),xd.end());
      |            ^~~~~~
a.cc: In function 'std::pair<int, int> solve(int, std::vector<st>*, int*)':
a.cc:82:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   82 |     sort(in[i].begin(),in[i].end());
      |     ^~~~
      |     sqrt
a.cc: At global scope:
a.cc:105:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  105 | main(){
      | ^~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define mp         make_pair
#define pb         push_back

const int N = 10010;

class st{
public:
  int height;
  char out;//1 or -1
  //bool operator<(const st&)const;
bool st::operator<(const st & a)const{
  if (height != a.height)return height < a.height;
  return out > a.out;
}

};



int x[N];
vector<st> inx[N];

//int y[N];
//vector<st> iny[N];

/*
29
29
80
45
*/

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int *X,vector<st> *IN){
  //vector<int> xd;
  static int xd[N];
  int p=0;
  rep(i,n){
    //xd.pb(x1[i]);
    //xd.pb(x2[i]);
    xd[p++]=x1[i];
    xd[p++]=x2[i];
  }
  //sort(ALL(xd));
  sort(xd,xd+p);
  //xd.erase(unique(ALL(xd)),xd.end());
  p=unique(xd,xd+p)-xd;
  //rep(i,xd.size())X[px++]=xd[i],IN[i].clear();
  rep(i,p)X[px++]=xd[i],IN[i].clear();

  //cout <<"allx ";rep(i,px)cout << x[i]<<" ";cout << endl;
  rep(i,n){
    //int j=lower_bound(xd.begin(),xd.end(),x1[i])-xd.begin();
    int j=lower_bound(xd,xd+p,x1[i])-xd;
    while(j < px && x[j] < x2[i]){
      IN[j].pb((st){y1[i],1});
      IN[j].pb((st){y2[i],-1});
      j++;
    }
  }
}

pair<int,int> solve(int n,vector<st> *in,int *c){
  int area=0;
  int len=0;
  rep(i,n-1){
    if (in[i].size() == 0)continue;
    sort(in[i].begin(),in[i].end());
    int cnt=0,prev=-100;
    int width;
    width=c[i+1]-c[i];
    rep(j,in[i].size()){
      if (cnt > 0){
	area+=(in[i][j].height-prev)*width;
      }
      //if (cnt == 0 && in[i][j].height != prev){
      if (cnt == 0){
	len+=width;
      }
      cnt+=in[i][j].out;
      //if (cnt == 0 && in[i][j].height != prev){
      if (cnt == 0){
	len+=width;
      }
      prev=in[i][j].height;
    }
  }
  return mp(area,len);
}

main(){
  int n,q;
  static int x1[N],y1[N],x2[N],y2[N];
  while(cin>>n>>q && n){
    rep(i,n){
      cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    }
    int px=0,py=0;
    makedata(n,x1,x2,y1,y2,px,x,inx);
    pair<int,int> ansx=solve(px,inx,x);

    cout << ansx.first << endl;
    if (q == 2){
      px=0;
      makedata(n,y1,y2,x1,x2,px,x,inx);
      pair<int,int> ansy= solve(px,inx,x);      
      cout << ansx.second+ansy.second << endl;
    }
  }
  return false;
}

Compiler output:
a.cc:22:6: error: extra qualification 'st::' on member 'operator<' [-fpermissive]
   22 | bool st::operator<(const st & a)const{
      |      ^~
a.cc:102:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  102 | main(){
      | ^~~~
Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define mp         make_pair
#define pb         push_back

const int N = 10010;

class st{
public:
  short beg,end;
  bool operator<(const st & a)const{
    if (beg != a.beg)return beg < a.beg;
    return end < a.end;
  }
};

short  isexist[N]={0};
short testcase=0;
int x[N];
vector<st> inx[N];

int req[N];

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int *xd,vector<st> *IN){
  testcase++;
  rep(i,n){
    isexist[x1[i]]=testcase;
    isexist[x2[i]]=testcase;
  }
  rep(i,N)if (isexist[i]==testcase)x[px]=i,IN[px++].clear();

  rep(i,n){
    int j=lower_bound(xd,xd+px,x1[i])-xd;
    while(j < px && xd[j] < x2[i]){
      bool isin=false;
      rep(k,IN[j].size()){
	short Y1 = y1[i],Y2=y2[i];
	short &Y3=IN[j][k].beg;
	short &Y4=IN[j][k].end;
	if (Y4 <= Y1 || Y2 <= Y3)continue;
	isin=true;
	Y3=min(Y1,Y3);
	Y4=max(Y2,Y4);
	break;
      }
      if (!isin)IN[j].pb((st){y1[i],y2[i]});
      j++;
    }
  }
}

pair<int,int> solve(int n,vector<st> *in,int *c){
  int area=0;
  int len=0;
  rep(i,n-1){
    if (in[i].size() == 0)continue;
    sort(in[i].begin(),in[i].end());
    short l=-1,h=-1;
    short width;
    width=c[i+1]-c[i];
    rep(j,in[i].size()){
      short &nowl=in[i][j].beg,&nowh=in[i][j].end;
      if (nowl > h){
	len+=2*width;
	area+=(nowh-nowl)*width;
      }else if (nowl == h){
	area+=(nowh-nowl)*width;
      }else if (nowh > h){
	area+=(nowh-h)*width;
      }
      l=nowl;
      h=max(h,nowh);
    }
  }
  return mp(area,len);
}

main(){
  int n,q;
  static int x1[N],y1[N],x2[N],y2[N];
  while(cin>>n>>q && n){
    rep(i,n){
      cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    }
    int px=0,py=0;
    makedata(n,x1,x2,y1,y2,px,x,inx);
    pair<int,int> ansx=solve(px,inx,x);

    cout << ansx.first << endl;
    if (q == 2){
      px=0;
      makedata(n,y1,y2,x1,x2,px,x,inx);
      pair<int,int> ansy= solve(px,inx,x);      
      cout << ansx.second+ansy.second << endl;
    }
    rep(i,px)inx[i].clear();
  }
  return false;
}
!

Compiler output:
a.cc: In function 'void makedata(int, int*, int*, int*, int*, int&, int*, std::vector<st>*)':
a.cc:56:35: warning: narrowing conversion of '*(y1 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   56 |       if (!isin)IN[j].pb((st){y1[i],y2[i]});
      |                               ~~~~^
a.cc:56:41: warning: narrowing conversion of '*(y2 + ((sizetype)(((long unsigned int)i) * 4)))' from 'int' to 'short int' [-Wnarrowing]
   56 |       if (!isin)IN[j].pb((st){y1[i],y2[i]});
      |                                     ~~~~^
a.cc: At global scope:
a.cc:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main(){
      | ^~~~
a.cc:110:1: error: expected unqualified-id before '!' token
  110 | !
      | ^
Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

int map[10003][10003];

int main(){
	while(1){
		int n,r,ans=0,ans2=0,minx=10001,miny=10001,maxx=0,maxy=0;
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(map,0,sizeof(map));
		for(int i=0;i<n;i++){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++,y1++,x2++,y2++;
			minx=min(min(x1,x2),minx);
			miny=min(min(y1,y2),miny);
			maxx=max(max(x1,x2),maxx);
			maxy=max(max(y1,y2),maxy);
			map[x1][y1]-=1;
			map[x2][y1]+=1;
			map[x1][y2]+=1;
			map[x2][y2]-=1;
		}
		mx++,my++;
		for(int i=miny;i<=maxy;i++){
			int t=0;
			for(int j=minx;j<=maxy;j++){
				t+=map[j][i];
				map[j][i]=t;
			}
		}
		for(int i=minx;i<=maxx;i++){
			int t=0;
			for(int j=maxy;j>=miny;j--){
				t+=map[i][j];
				map[i][j]=t;
				if(map[i][j]>0){
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		if(r==2){
			for(int i=minx;i<=maxx;i++){
				for(int j=miny;j<=maxy;j++){
					if(map[i][j]>=1){
						if(map[i-1][j]<=0)ans2++;
						if(map[i+1][j]<=0)ans2++;
						if(map[i][j-1]<=0)ans2++;
						if(map[i][j+1]<=0)ans2++;
					}
				}
			}
			printf("%d\n",ans2);
		}
	}
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:28:17: error: 'mx' was not declared in this scope; did you mean 'maxy'?
   28 |                 mx++,my++;
      |                 ^~
      |                 maxy
a.cc:28:22: error: 'my' was not declared in this scope; did you mean 'maxy'?
   28 |                 mx++,my++;
      |                      ^~
      |                      maxy
Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

int map[100000][100000];
int n,r;

int main(){
	while(1){
		int ans=0,ans2=0,minx=10001,miny=10001,maxx=1,maxy=1;
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(map,0,sizeof(map));
		for(int i=0;i<n;i++){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++,y1++,x2++,y2++;
			minx=min(min(x1,x2),minx);
			miny=min(min(y1,y2),miny);
			maxx=max(max(x1,x2),maxx);
			maxy=max(max(y1,y2),maxy);
			map[x1][y1]-=1;
			map[x2][y1]+=1;
			map[x1][y2]+=1;
			map[x2][y2]-=1;
		}
		for(int i=miny;i<=maxy;i++){
			int t=0;
			for(int j=minx;j<=maxy;j++){
				t+=map[j][i];
				map[j][i]=t;
			}
		}
		for(int i=minx;i<=maxx;i++){
			int t=0;
			for(int j=maxy;j>=miny;j--){
				t+=map[i][j];
				map[i][j]=t;
				if(map[i][j]>0){
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		if(r==2){
			for(int i=minx;i<=maxx;i++){
				for(int j=miny;j<=maxy;j++){
					if(map[i][j]>=1){
						if(map[i-1][j]<=0)ans2++;
						if(map[i+1][j]<=0)ans2++;
						if(map[i][j-1]<=0)ans2++;
						if(map[i][j+1]<=0)ans2++;
					}
				}
			}
			printf("%d\n",ans2);
		}
	}
    return 0;
}

Compiler output:
/tmp/ccTmT0zt.o: in function `main':
a.cc:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against symbol `r' defined in .bss section in /tmp/ccTmT0zt.o
a.cc:(.text+0x3f): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccTmT0zt.o
a.cc:(.text+0x5c): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccTmT0zt.o
a.cc:(.text+0x66): relocation truncated to fit: R_X86_64_PC32 against symbol `r' defined in .bss section in /tmp/ccTmT0zt.o
a.cc:(.text+0x2e5): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccTmT0zt.o
a.cc:(.text+0x450): relocation truncated to fit: R_X86_64_PC32 against symbol `r' defined in .bss section in /tmp/ccTmT0zt.o
collect2: error: ld returned 1 exit status
Language: C++

int g[10005][10005];
int n,r;

int main(){
	while(1){
		int ans=0,ans2=0,minx=10001,miny=10001,maxx=1,maxy=1;
		scanf("%d%d",&n,&r);
		if(n==0 && r==0)break;
		memset(g,0,sizeof(g));
		for(int i=0;i<n;i++){
			int x1,y1,x2,y2;
			scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
			x1++,y1++,x2++,y2++;
			minx=min(min(x1,x2),minx);
			miny=min(min(y1,y2),miny);
			maxx=max(max(x1,x2),maxx);
			maxy=max(max(y1,y2),maxy);
			g[x1][y1]-=1;
			g[x2][y1]+=1;
			g[x1][y2]+=1;
			g[x2][y2]-=1;
		}
		for(int i=miny;i<=maxy;i++){
			int t=0;
			for(int j=minx;j<=maxy;j++){
				t+=g[j][i];
				g[j][i]=t;
			}
		}
		for(int i=minx;i<=maxx;i++){
			int t=0;
			for(int j=maxy;j>=miny;j--){
				t+=g[i][j];
				g[i][j]=t;
				if(g[i][j]>0){
					ans++;
				}
			}
		}
		printf("%d\n",ans);
		if(r==2){
			for(int i=minx;i<=maxx;i++){
				for(int j=miny;j<=maxy;j++){
					if(g[i][j]>=1){
						if(g[i-1][j]<=0)ans2++;
						if(g[i+1][j]<=0)ans2++;
						if(g[i][j-1]<=0)ans2++;
						if(g[i][j+1]<=0)ans2++;
					}
				}
			}
			printf("%d\n",ans2);
		}
	}
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:17: error: 'scanf' was not declared in this scope
    7 |                 scanf("%d%d",&n,&r);
      |                 ^~~~~
a.cc:9:17: error: 'memset' was not declared in this scope
    9 |                 memset(g,0,sizeof(g));
      |                 ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | int g[10005][10005];
a.cc:14:34: error: 'min' was not declared in this scope; did you mean 'miny'?
   14 |                         minx=min(min(x1,x2),minx);
      |                                  ^~~
      |                                  miny
a.cc:14:30: error: 'min' was not declared in this scope; did you mean 'miny'?
   14 |                         minx=min(min(x1,x2),minx);
      |                              ^~~
      |                              miny
a.cc:16:34: error: 'max' was not declared in this scope; did you mean 'maxy'?
   16 |                         maxx=max(max(x1,x2),maxx);
      |                                  ^~~
      |                                  maxy
a.cc:16:30: error: 'max' was not declared in this scope; did you mean 'maxy'?
   16 |                         maxx=max(max(x1,x2),maxx);
      |                              ^~~
      |                              maxy
a.cc:40:17: error: 'printf' was not declared in this scope
   40 |                 printf("%d\n",ans);
      |                 ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int g[10005][10005];