codeforces sex sux
3 weeks ago in Plain Text
#include <bits/stdc++.h>
#define ll long long
#define sz size_t
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define fr for(int i = 0; i < n; i++)
#define fr1 for(int i = 1; i < n; i++)
#define frx(x) for(int i = 0; i < x; i++)
#define fra(x) for(auto& it : x)
#define srt(x) sort(x.begin(), x.end())
#define vmx(x) *max_element(x.begin(), x.end())
#define vmn(x) *min_element(x.begin(), x.end())
using namespace std;
template<typename typC>
istream &operator>>(istream &cin,vector<typC> &a) {
for (auto &x:a) cin>>x;
return cin;
}
template<typename typC,typename typD>
istream &operator>>(istream &cin,pair<typC,typD> &a) {
return cin>>a.first>>a.second;
}
template<typename typC,typename typD>
ostream &operator<<(ostream &cout,const pair<typC,typD> &a) {
return cout<<a.first<<' '<<a.second;
}
template<typename typC,typename typD>
ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) {
for (auto &x:a) cout<<x<<' ';
return cout;
}
template<typename typC>
ostream &operator<<(ostream &cout,const vector<typC> &a) {
int n=a.size();
if (!n) return cout;
cout<<a[0];
for (int i=1; i<n; i++) cout<<' '<<a[i];
return cout;
}
void solve() {
int n;
cin >> n;
vvi a(n, vi(n));
fr cin >> a[i];
unordered_map<int, int> mp;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] < 0) mp[i-j] = min(mp[i-j], a[i][j]);
}
}
ll sum = 0;
fra(mp) sum += abs(it.second);
cout << sum << endl;
}
int32_t main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}