Language: C++

#include <iostream>
using namespace std;

int main(){
	long r, c;
	cin >> r >> c;
	vector< vector<long> > sp(r);
	for (long i = 0; i < r; i++){
		sp[i].resize(c);
	}
	vector<long> rsum(r, 0);
	vector<long> csum(c, 0);
	for (long i = 0; i < r; i++){
		for (long j = 0; j < c; j++){
			rsum[i] += sp[i][j];
		}
	}
	for (long i = 0; i < c; i++){
		for (long j = 0; j < r; j++){
			csum[i] += sp[j][i];
		}
	}
	long sum = 0;
	for (long i = 0; i < r; i++){
		sum += rsum[i];
	}
	vector< vector<long> > newsp(r + 1);
	for (long i = 0; i < r + 1; i++){
		newsp[i].resize(c + 1);
	}
	for (long i = 0; i < r + 1; i++){
		for (long j = 0; j < c + 1; j++){
			if (i < r && j < c) newsp[i][j] = sp[i][j];
			else if (i = r && j < c) newsp[i][j] = csum[j];
			else if (j = c && i < r) newsp[i][j] = rsum[i];
			else newsp[i][j] = sum;
		}
	}
	for (long i = 0; i < r + 1; i++){
		for (long j = 0; j < c + 1; j++){
			cout << newsp[i][j];
		}
		cout << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:7:9: error: 'vector' was not declared in this scope
    7 |         vector< vector<long> > sp(r);
      |         ^~~~~~
a.cc:2:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    1 | #include <iostream>
  +++ |+#include <vector>
    2 | using namespace std;
a.cc:7:24: error: expected primary-expression before 'long'
    7 |         vector< vector<long> > sp(r);
      |                        ^~~~
a.cc:9:17: error: 'sp' was not declared in this scope
    9 |                 sp[i].resize(c);
      |                 ^~
a.cc:11:16: error: expected primary-expression before 'long'
   11 |         vector<long> rsum(r, 0);
      |                ^~~~
a.cc:12:16: error: expected primary-expression before 'long'
   12 |         vector<long> csum(c, 0);
      |                ^~~~
a.cc:15:25: error: 'rsum' was not declared in this scope
   15 |                         rsum[i] += sp[i][j];
      |                         ^~~~
a.cc:15:36: error: 'sp' was not declared in this scope
   15 |                         rsum[i] += sp[i][j];
      |                                    ^~
a.cc:20:25: error: 'csum' was not declared in this scope
   20 |                         csum[i] += sp[j][i];
      |                         ^~~~
a.cc:20:36: error: 'sp' was not declared in this scope
   20 |                         csum[i] += sp[j][i];
      |                                    ^~
a.cc:25:24: error: 'rsum' was not declared in this scope; did you mean 'sum'?
   25 |                 sum += rsum[i];
      |                        ^~~~
      |                        sum
a.cc:27:24: error: expected primary-expression before 'long'
   27 |         vector< vector<long> > newsp(r + 1);
      |                        ^~~~
a.cc:29:17: error: 'newsp' was not declared in this scope
   29 |                 newsp[i].resize(c + 1);
      |                 ^~~~~
a.cc:33:45: error: 'newsp' was not declared in this scope
   33 |                         if (i < r && j < c) newsp[i][j] = sp[i][j];
      |                                             ^~~~~
a.cc:33:59: error: 'sp' was not declared in this scope
   33 |                         if (i < r && j < c) newsp[i][j] = sp[i][j];
      |                                                           ^~
a.cc:34:50: error: 'newsp' was not declared in this scope
   34 |                         else if (i = r && j < c) newsp[i][j] = csum[j];
      |                                                  ^~~~~
a.cc:34:64: error: 'csum' was not declared in this scope; did you mean 'sum'?
   34 |                         else if (i = r && j < c) newsp[i][j] = csum[j];
      |                                                                ^~~~
      |                                                                sum
a.cc:35:50: error: 'newsp' was not declared in this scope
   35 |                         else if (j = c && i < r) newsp[i][j] = rsum[i];
      |                                                  ^~~~~
a.cc:35:64: error: 'rsum' was not declared in this scope; did you mean 'sum'?
   35 |                         else if (j = c && i < r) newsp[i][j] = rsum[i];
      |                                                                ^~~~
      |                                                                sum
a.cc:36:30: error: 'newsp' was not declared in this scope
   36 |                         else newsp[i][j] = sum;
      |                              ^~~~~
a.cc:41:33: error: 'newsp' was not declared in this scope
   41 |                         cout << newsp[i][j];
      |                                 ^~~~~