fork download
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8.  
  9. int main(){
  10. int n;
  11. cin >> n;
  12. vector< vector<int> > a(n,vector<int>(n));
  13. for(int a_i = 0;a_i < n;a_i++){
  14. for(int a_j = 0;a_j < n;a_j++){
  15. cin >> a[a_i][a_j];
  16. }
  17. }
  18. int s1 = 0;
  19. for(int i = 0; i < n; i++)
  20. s1 += a[i][i];
  21. int s2 = 0;
  22. for(int i = 0; i < n; i++)
  23. s2 += a[i][i];
  24. cout << std::abs(s1 - s2) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0s 3464KB
stdin
3
11 2 4
4 5 6
10 8 -12
stdout
0