#define N 100010 #define M 200010 usingnamespace std;
typedeflonglong ll; typedef pair<int, int> PII;
vector<PII> E[N]; vector<int> G[N]; int u[N << 1], v[N << 1]; ll deg[N << 1]; ll cnt[N << 1]; ll containerP[N], containerE[M]; int tmp[N], id[N]; ll n, m;
ll countTripling(){ ll ret = 0; for (int i = 1; i <= n; i++) { for (auto j: E[i]) id[j.first] = j.second; for (auto j: E[i]) { int k = j.first; for (auto l: E[k]) { int w = l.first; if (id[w]) { containerP[i]++; containerP[k]++; containerP[w]++; containerE[j.second]++; containerE[l.second]++; containerE[id[w]]++; ret++; } } } for (auto j: E[i]) id[j.first] = 0; } return ret; }
ll countQuadrant(){ for (int i = 1; i <= m; i++) { if ((deg[u[i]] == deg[v[i]] && u[i] > v[i]) || deg[u[i]] > deg[v[i]]) swap(u[i], v[i]); E[u[i]].emplace_back(v[i], i); } ll ret = 0; int hh = 0; for (int i = 1; i <= n; i++) { for (int j: G[i]) { for (auto k: E[j]) { int w = k.first; if (deg[i] < deg[w] || (deg[i] == deg[w] && i < w)) { ret += cnt[w]; if (!cnt[w]) tmp[hh++] = w; cnt[w]++; } } } for (int j = 0; j < hh; j++) cnt[tmp[j]] = 0; hh = 0; } return ret; }