malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using std::cerr;   using std::cin;   using std::cout;   using std::endl;   using std::list;   using std::map;   using std::max;   using std::min;   using std::pair;   using std::set;   using std::sort;   using std::string;   using std::swap;   using std::vector;   const int MAXN = 100005;   const long long INF = 100000000009;   const long long MOD = (long long)1e9 + 7;   bool used[MAXN];   bool cnt[MAXN][50];   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     cin >> n;     string sec;     cin >> sec;     for (int i = 0; i < n; ++i) {       if (sec[i] !=  * ) {         used[(int)sec[i]] = true;       }     }     int m;     cin >> m;     vector<string> needed;     for (int i = 0; i < m; ++i) {       string s;       cin >> s;       bool flag = true;       for (int j = 0; j < n; ++j) {         if (sec[j] ==  * ) {           if (used[(int)s[j]]) {             flag = false;             break;           }         } else if (sec[j] != s[j]) {           flag = false;           break;         }       }       if (flag) {         needed.push_back(s);       }     }     for (int j = 0; j < needed.size(); ++j) {       for (int i = 0; i < n; ++i) {         if (sec[i] ==  * ) {           cnt[j][(int)needed[j][i] -  a ] = true;         }       }     }     int ans = 0;     for (int i = 0; i <= (int) z  - (int) a ; ++i) {       bool flag = true;       for (int j = 0; j < needed.size(); ++j) {         if (!cnt[j][i]) {           flag = false;         }       }       if (flag) {         ++ans;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, k, s = 0, m;     vector<pair<int, int> > v(110);     scanf( %d , &n);     scanf( %d , &k);     for (i = 0; i < n; ++i) {       scanf( %d , &v[i].first);       v[i].second = i + 1;     }     sort(v.begin(), v.begin() + n);     for (i = 0; s <= k && i < n; ++i) s = s + v[i].first;     m = i;     if (s > k) --m;     printf( %d n , m);     for (i = 0; i < m; ++i) printf( %d  , v[i].second);   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, f[101][101][101], g[101];   char s[101];   int main() {     scanf( %I64d%I64d%s , &n, &x, s + 1);     for (long long i = 1; i <= n; i++) f[s[i] -  0 ][i][i] = 1;     g[0] = g[1] = 2;     for (long long i = 2; i <= x; i++) g[i] = g[i - 1] * g[i - 2] % 1000000007;     for (long long i = 2; i <= x; i++)       for (long long l = 1; l <= n; l++)         for (long long r = l; r <= n; r++) {           for (long long m = l; m < r; m++)             f[i][l][r] += f[i - 1][l][m] * f[i - 2][m + 1][r] % 1000000007,                 f[i][l][r] %= 1000000007;           f[i][l][r] += f[i - 1][l][r] * (r == n ? g[i - 2] : 1) % 1000000007,               f[i][l][r] %= 1000000007;           f[i][l][r] += f[i - 2][l][r] * (l == 1 ? g[i - 1] : 1) % 1000000007,               f[i][l][r] %= 1000000007;         }     return printf( %I64d n , f[x][1][n]), 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[110];   int n, d;   int m;   int main() {     cin >> n >> d;     cin >> m;     for (int i = 0; i < m; ++i) {       int x, y;       cin >> x >> y;       bool t = false;       if (!((x - y) <= d && (x - y) >= -d)) t = true;       if (!((x + y) <= n + n - d && (x + y) >= d)) t = true;       if (t == true)         s[i] =  NO ;       else         s[i] =  YES ;     }     for (int i = 0; i < m; i++) cout << s[i] << endl;     return 0;   }
#include <bits/stdc++.h>   const int a = 1 << 18;   using namespace std;   long long odp[a], n, k, res;   vector<int> v[a];   void dfs(int x, int pop) {     for (int i = 0; i < v[x].size(); i++) {       if (v[x][i] != pop)         dfs(v[x][i], x), odp[x] += odp[v[x][i]],             res += min(odp[v[x][i]], k - odp[v[x][i]]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> k;     k *= 2;     for (int i = 0; i < k; i++) {       int b;       cin >> b;       odp[b] = 1;     }     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     dfs(1, 1);     cout << res;   }
#include <bits/stdc++.h>   char s[100], Ans[2000];   int n, m, ans, cnt, b[20], a[40][40], p[50], q[50], x[20][20];   void dfs(int c, int d) {     if (d == 15) {       memset(x, 0, sizeof(x));       for (int i = 1; i <= 28; i++) {         if (x[b[p[i]]][b[q[i]]]) return;         x[b[p[i]]][b[q[i]]] = x[b[q[i]]][b[p[i]]] = 1;       }       if (++ans == 1) {         cnt = 0;         for (int i = 0; i < n; i++) {           for (int j = 0; j < m; j++)             Ans[cnt++] = a[i][j] ? (b[a[i][j]] + 47) :  . ;           Ans[cnt++] =   n ;         }         Ans[cnt] =   0 ;       }     } else {       if (b[d]) {         dfs(c, d + 1);         return;       }       b[d] = c;       for (int j = d + 1; j <= 14; j++)         if (!b[j]) b[j] = c, dfs(c + 1, d + 1), b[j] = 0;       b[d] = 0;     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , &s);       for (int j = 0; j < m; j++) {         if (s[j] !=  .  && !a[i][j])           a[i][j] = a[i + 1][j] = a[i][j + 1] = a[i + 1][j + 1] = ++cnt;         if (s[j] !=  . ) {           int t = s[j] <=  B  ? s[j] - 64 : s[j] - 94;           if (!p[t])             p[t] = a[i][j];           else             q[t] = a[i][j];         }       }     }     dfs(1, 1);     printf( %d n%s , ans * 5040, Ans);   }
#include <bits/stdc++.h>   using namespace std;   int b[8];   string str;   int main() {     int n, i;     cin >> n >> str;     for (i = 0; i <= (n - 1); i++) switch (str[i]) {         case  2 :           b[2]++;           break;         case  3 :           b[3]++;           break;         case  4 :           b[2] += 2, b[3]++;           break;         case  5 :           b[5]++;           break;         case  6 :           b[5]++, b[3]++;           break;         case  7 :           b[7]++;           break;         case  8 :           b[7]++, b[2] += 3;           break;         case  9 : {           b[7]++;           b[2]++;           b[3] += 2;         }       }     while (b[7]--) putchar( 7 );     while (b[5]--) putchar( 5 );     while (b[3]--) putchar( 3 );     while (b[2]--) putchar( 2 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << fixed;     cout.precision(4);     int r, c;     cin >> r >> c;     int a[r][c];     for (int i = 0; i < r; ++i) {       for (int j = 0; j < c; ++j) {         cin >> a[i][j];       }     }     long long sum = 0ll;     if (a[r - 1][c - 1] <= a[r - 2][c - 1] ||         a[r - 1][c - 1] <= a[r - 1][c - 2]) {       cout << -1 <<   n ;       return 0;     }     sum += a[r - 1][c - 1];     for (int i = c - 2; i > 0; --i) {       int choose;       if (a[r - 1][i] != 0)         choose = a[r - 1][i];       else         choose = a[r - 1][i + 1] - 1;       if (choose <= a[r - 1][i - 1] || choose <= a[r - 2][i] ||           choose >= a[r - 1][i + 1]) {         cout << -1 <<   n ;         return 0;       }       a[r - 1][i] = choose;       sum += a[r - 1][i];     }     if (a[r - 1][0] <= a[r - 2][0] || a[r - 1][0] >= a[r - 1][1]) {       cout << -1 <<   n ;       return 0;     }     sum += a[r - 1][0];     for (int i = r - 2; i > 0; --i) {       if (a[i][c - 1] <= a[i - 1][c - 1] || a[i][c - 1] >= a[i + 1][c - 1] ||           a[i][c - 1] <= a[i][c - 2]) {         cout << -1 <<   n ;         return 0;       }       sum += a[i][c - 1];       for (int j = c - 2; j > 0; --j) {         int choose;         if (a[i][j] != 0)           choose = a[i][j];         else           choose = min(a[i][j + 1], a[i + 1][j]) - 1;         if (choose >= a[i][j + 1] || choose >= a[i + 1][j] ||             choose <= a[i][j - 1] || choose <= a[i - 1][j]) {           cout << -1 <<   n ;           return 0;         }         a[i][j] = choose;         sum += a[i][j];       }       if (a[i][0] >= a[i][1] || a[i][0] >= a[i + 1][0] ||           a[i][0] <= a[i - 1][0]) {         cout << -1 <<   n ;         return 0;       }       sum += a[i][0];     }     if (a[0][c - 1] <= a[0][c - 2] || a[0][c - 1] >= a[1][c - 1]) {       cout << -1 <<   n ;       return 0;     }     sum += a[0][c - 1];     for (int i = c - 2; i > 0; --i) {       int choose;       if (a[0][i] != 0)         choose = a[0][i];       else         choose = min(a[0][i + 1], a[1][i]) - 1;       if (choose >= a[0][i + 1] || choose >= a[1][i] || choose <= a[0][i - 1]) {         cout << -1 <<   n ;         return 0;       }       a[0][i] = choose;       sum += a[0][i];     }     if (a[0][0] >= a[1][0] || a[0][0] >= a[0][1]) {       cout << -1 <<   n ;       return 0;     }     sum += a[0][0];     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:102400000,102400000 )   #pragma GCC optimize( O2 )   using namespace std;   const int maxn = 1e4 + 123;   int n, k;   int a[maxn];   vector<int> ve[4];   long long sum;   int main(int argc, char const *argv[]) {     std::cin >> n;     for (int i = 0; i < n; i++) {       char s[3];       int val;       std::cin >> s >> val;       int id = 2 * (s[0] -  0 ) + (s[1] -  0 );       ve[id].push_back(val);     }     if (ve[1].size() < ve[2].size()) {       swap(ve[1], ve[2]);     }     for (int i = 0; i <= 3; i++) {       sort(ve[i].begin(), ve[i].end());     }     long long cur = (long long)ve[3].size();     while (ve[3].size() > 0) {       sum += ve[3][(long long)ve[3].size() - 1];       ve[3].pop_back();     }     while (ve[2].size() > 0) {       sum += ve[2][ve[2].size() - 1] + ve[1][(long long)ve[1].size() - 1];       ve[1].pop_back();       ve[2].pop_back();     }     for (int i = 0; i < (int)ve[1].size(); i++) {       ve[0].push_back(ve[1][i]);     }     sort(ve[0].begin(), ve[0].end());     while (cur > 0 && ve[0].size() > 0) {       sum += ve[0][ve[0].size() - 1];       ve[0].pop_back();       cur--;     }     std::cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   vector<pair<pair<int, int>, pair<int, int> > > a[300005];   vector<int> g1[300005];   vector<int> g2[300005];   string Max =   , Min =   ;   int ansMax = 0;   int ansMin = 0;   bool used[300005];   void getMax(int cur) {     ansMax++;     used[cur]++;     for (auto it : g1[cur]) {       if (!used[it]) {         getMax(it);       }     }   }   void getMin(int cur) {     ansMin++;     used[cur]++;     for (auto it : g2[cur]) {       if (!used[it]) {         getMin(it);       }     }   }   void updateMax(int s) {     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       if (used[u]) {         continue;       }       used[u]++;       for (auto it : a[u]) {         if (it.first.first == 1) {           if (!used[it.second.second]) {             q.push(it.second.second);             g1[u].push_back(it.second.second);           }         } else {           if (u == it.second.first) {             if (!used[it.second.second]) {               q.push(it.second.second);               g1[u].push_back(it.second.second);             }           } else {             if (!used[it.second.first]) {               q.push(it.second.first);               g1[u].push_back(it.second.first);               Max[it.first.second] =  - ;             }           }         }       }     }   }   void updateMin(int s) {     queue<int> q;     q.push(s);     while (!q.empty()) {       int u = q.front();       q.pop();       if (used[u]) {         continue;       }       used[u]++;       for (auto it : a[u]) {         if (it.first.first == 2) {           if (u == it.second.first) {             if (!used[it.second.second]) {               Min[it.first.second] =  - ;             }           }         }       }       for (auto it : a[u]) {         if (it.first.first == 1 && !used[it.second.second]) {           g2[u].push_back(it.second.second);           q.push(it.second.second);         }       }     }   }   int main() {     int n, m, s;     scanf( %d%d%d , &n, &m, &s);     int i, t, u, v;     int d = 0;     for (i = 0; i < m; i++) {       scanf( %d%d%d , &t, &u, &v);       if (t == 1) {         a[u].push_back({{t, i}, {u, v}});       } else {         a[u].push_back({{t, d}, {u, v}});         a[v].push_back({{t, d}, {u, v}});         d++;         Max +=  + ;         Min +=  + ;       }     }     updateMax(s);     memset(used, 0, sizeof used);     getMax(s);     printf( %d n , ansMax);     cout << Max << endl;     memset(used, 0, sizeof used);     updateMin(s);     memset(used, 0, sizeof used);     getMin(s);     printf( %d n , ansMin);     cout << Min;     return 0;   }
#include <bits/stdc++.h>   char s[520][520];   char q[520][520];   int main() {     int n, m;     scanf( %d , &n);     memset(s,   0 , sizeof(s));     memset(q,   0 , sizeof(q));     q[1][1] =  + , q[1][2] =  + , q[2][1] =  + , q[2][2] =  * ;     s[1][1] =  + , s[1][2] =  + , s[2][1] =  + , s[2][2] =  * ;     m = 2;     if (n == 0)       printf( + n );     else {       while (--n) {         for (int i = 1; i <= m; ++i)           for (int j = 1; j <= m; ++j)             s[i][j] = q[i][j], s[i + m][j] = q[i][j], s[i][j + m] = q[i][j],             s[i + m][j + m] = q[i][j] ==  +  ?  *  :  + ;         for (int i = 1; i <= m * 2; ++i)           for (int j = 1; j <= m * 2; ++j) q[i][j] = s[i][j];         m *= 2;       }       for (int i = 1; i <= m; ++i) printf( %s n , s[i] + 1);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 110000;   int t[4 * maxN], m;   int get(int k) {     int res = 0;     for (int i = k; i >= 0; i = (i & (i + 1)) - 1) {       res = max(res, t[i]);     }     return res;   }   void update(int k, int delta) {     for (int i = k; i <= m; i |= (i + 1)) {       t[i] = max(t[i], delta);     }   }   int calculate(vector<pair<int, int> > borders) {     pair<int, int> start = borders[0];     sort(borders.rbegin(), borders.rend());     for (int i = 0; i < borders.size(); ++i) {       int current = get(borders[i].second - 1);       update(borders[i].second, current + 1);       if (borders[i] == start) {         return current;       }     }   }   int a, b, c, d, n;   struct rational {     long long x, y;     rational(long long x, long long y) : x(x), y(y) {}     rational() : x(0), y(1) {}     bool operator<(const rational &other) const {       return x * other.y < other.x * y;     }   };   vector<pair<int, int> > compress(vector<rational> a, vector<rational> b) {     set<rational> S;     for (int i = 0; i < a.size(); ++i) {       S.insert(a[i]);       S.insert(b[i]);     }     map<rational, int> M;     m = 0;     for (set<rational>::iterator it = S.begin(); it != S.end(); ++it) {       M[*it] = ++m;     }     vector<pair<int, int> > borders;     for (int i = 0; i < a.size(); ++i) {       borders.push_back(make_pair(M[a[i]], M[b[i]]));     }     return borders;   }   int main() {     scanf( %d , &n);     scanf( %d/%d%d/%d , &a, &b, &c, &d);     vector<rational> u, v;     for (int i = 0; i <= n; ++i) {       long long x, y;       if (i == 0) {         x = y = 0;       } else {         cin >> x >> y;       }       u.push_back(rational(1000000LL * a + y * b - x * a, a + b));       v.push_back(rational(1000000LL * c + y * d - x * c, c + d));     }     printf( %d n , calculate(compress(u, v)));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = 300003;   int n, m, k;   vector<int> g[N], gr[N];   int to[N], from[N], mark[N], res[N], din[N], rem;   int x[N], r[N], y[N];   void out() {     cout <<  -1 n ;     exit(0);   }   void dfs(int v) {     mark[v] = 1;     for (int u : g[v])       if (mark[u] == 1)         out();       else {         if (!mark[u]) dfs(u);         from[v] = max(from[v], from[u]);       }     from[v]++;     if (r[v] > 0) {       if (from[v] > r[v]) out();       from[v] = r[v];     }     if (from[v] > k) out();     mark[v] = 2;   }   bool seen[N];   set<pair<int, int>> ss, qs;   void updateRem() {     while (rem > 0 && seen[rem]) {       rem--;       while (qs.size() && qs.rbegin()->first >= rem) {         int v = qs.rbegin()->second;         qs.erase({to[v], v});         ss.insert({from[v], v});       }     }   }   void addSource(int v) {     int x = to[v];     if (x >= rem)       ss.insert({from[v], v});     else       qs.insert({x, v});   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < n; i++) r[i] = in();     for (int i = 0; i < m; i++) {       x[i] = in() - 1;       y[i] = in() - 1;       g[x[i]].push_back(y[i]);       gr[y[i]].push_back(x[i]);       din[y[i]]++;     }     for (int i = 0; i < n; i++)       if (!mark[i]) dfs(i);     rem = k;     fill(to, to + n, k);     for (int i = 0; i < n; i++) {       if (r[i] > 0) to[i] = min(to[i], r[i]);       if (!din[i]) addSource(i);     }     for (int i = 0; i < n; i++) {       if (ss.empty()) out();       int v = ss.rbegin()->second;       ss.erase({from[v], v});       assert(to[v] >= rem);       if (r[v] > 0)         res[v] = r[v];       else         res[v] = max(rem, from[v]);       seen[res[v]] = true;       updateRem();       for (int u : g[v]) {         din[u]--;         to[u] = min(to[u], res[v] - 1);         if (to[u] < from[u]) out();         if (din[u] == 0) addSource(u);       }     }     if (rem != 0) out();     for (int i = 0; i < m; i++)       if (res[x[i]] <= res[y[i]]) out();     for (int i = 0; i < n; i++) cout << res[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 4e5 + 5;   pair<long long, long long> arr[N];   long long l[N];   long long s[N];   long long dp[N];   long long bit[N];   long long n;   void update(long long idx, long long val) {     while (idx <= n) {       bit[idx] = max(bit[idx], val);       idx += idx & -idx;     }   }   long long query(long long idx) {     long long res = 0;     while (idx) {       res = max(res, bit[idx]);       idx -= idx & -idx;     }     return res;   }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) {       long long r, h;       scanf( %lld%lld , &r, &h);       arr[i] = pair<long long, long long>(r * r * h, -i);     }     sort(arr + 1, arr + n + 1);     for (long long i = 1; i <= n; i++) {       dp[i] = max(arr[i].first, query(-arr[i].second) + arr[i].first);       update(-arr[i].second, dp[i]);     }     printf( %.7lf n , 3.14159265358979323846 * query(n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[100001];   int main() {     int n, k;     cin >> n;     int ans = 1;     int m = n;     while (n--) {       cin >> k;       cnt[k] = cnt[k - 1] + 1;       ans = max(ans, cnt[k]);     }     cout << m - ans;   }
#include <bits/stdc++.h>   char year[10];   int main() {     scanf( %s , year);     int l = strlen(year) - 1;     int num = 0, num2 = 0;     for (int i = 0; i <= l; i++) {       num = num * 10 + year[i] -  0 ;     }     for (int i = 1; i <= l; i++) num2 = num2 * 10 + year[i] -  0 ;     int x = 1;     for (int i = 1; i <= l; i++) x *= 10;     printf( %d n , x - num2);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<tuple<int, int, int, int> > v(n);     vector<int> used(n, 0);     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       v[i] = make_tuple(a, b, c, i);     }     sort(v.begin(), v.end());     map<pair<int, int>, vector<int> > m;     for (int i = 0; i < n; i++) {       pair<int, int> t = {get<0>(v[i]), get<1>(v[i])};       if (m.find(t) == m.end()) m[t] = vector<int>();       m[t].push_back(i);     }     for (auto t : m) {       for (int i = 0; i + 1 < t.second.size(); i += 2) {         cout << get<3>(v[t.second[i]]) + 1 <<                  << get<3>(v[t.second[i + 1]]) + 1 <<   n ;         used[get<3>(v[t.second[i]])] = 1;         used[get<3>(v[t.second[i + 1]])] = 1;       }     }     vector<tuple<int, int, int, int> > v1;     for (int i = 0; i < v.size(); i++) {       if (used[get<3>(v[i])] == 0) v1.push_back(v[i]);     }     map<int, vector<int> > m1;     for (int i = 0; i < v1.size(); i++) {       if (m1.find(get<0>(v1[i])) == m1.end()) {         m1[get<0>(v1[i])] = vector<int>();       }       m1[get<0>(v1[i])].push_back(i);     }     for (auto t : m1) {       for (int i = 0; i + 1 < t.second.size(); i += 2) {         cout << get<3>(v1[t.second[i]]) + 1 <<                  << get<3>(v1[t.second[i + 1]]) + 1 <<   n ;         used[get<3>(v1[t.second[i]])] = 1;         used[get<3>(v1[t.second[i + 1]])] = 1;       }     }     vector<tuple<int, int, int, int> > v2;     for (int i = 0; i < v1.size(); i++) {       if (used[get<3>(v1[i])] == 0) {         v2.push_back(v1[i]);       }     }     for (int i = 0; i < v2.size(); i += 2) {       cout << get<3>(v2[i]) + 1 <<     << get<3>(v2[i + 1]) + 1 <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int a = 26;   char c[10000], ans[10000];   int p[10000], ap[10000], perm[10000];   map<int, int> m;   int main() {     string s, st;     cin >> s;     int n = s.size(), x, t, last, y;     x = 17576;     for (int i = 0; i < 3; i++) {       x /= a;       t = 0;       last = -1;       cout <<  ?  ;       for (int j = 0; j < n; j++) {         if (j % x == 0 || last != c[j]) {           t = (t + 1) % a;         }         last = c[j];         c[j] = char(t +  a );         cout << c[j];       }       cout << endl;       cin >> st;       for (int j = 0; j < n; j++) {         y = st[j] -  a ;         p[j] = p[j] * a + y;         ap[j] = ap[j] * a + (c[j] -  a );       }     }     cout <<  !  ;     for (int i = 0; i < n; i++) m[ap[i]] = i;     for (int i = 0; i < n; i++) perm[i] = m[p[i]];     for (int i = 0; i < n; i++) ans[perm[i]] = s[i];     for (int i = 0; i < n; i++) cout << ans[i];     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int lim = 500000001;   class TMain {    private:     int n, m, f[505][505], dis[505][505], ans[505][505], now[505];       public:     int run() {       scanf( %d %d , &n, &m);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (i == j)             f[i][j] = dis[i][j] = 0;           else             f[i][j] = dis[i][j] = lim;       for (int i = 1; i <= m; i++) {         int a, b, c;         scanf( %d %d %d , &a, &b, &c);         dis[a][b] = dis[b][a] = f[a][b] = f[b][a] = min(f[a][b], c);       }       for (int k = 1; k <= n; k++)         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) now[j] = 0;         for (int j = 1; j <= n; j++)           for (int k = 1; k <= n; k++)             if (j != k && f[i][j] + dis[j][k] == f[i][k]) now[k]++;         for (int j = 1; j <= n; j++)           for (int k = 1; k <= n; k++)             if (f[i][j] + f[j][k] == f[i][k]) ans[i][k] += now[j];       }       for (int i = 1; i < n; i++)         for (int j = i + 1; j <= n; j++)           if (f[i][j] == lim)             printf( 0  );           else             printf( %d  , ans[i][j]);       printf(  n );       return 0;     }   } Main;   int main() { return Main.run(); }