#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using mint = modint998244353; // X:= e: 6K+D // Y:= not e:D+2S // X-Y=6K-2S // (X-Y)/3=K-S/3 constexpr int M = 200010; bool used[M]; int cnt[M]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; VVI to(n); rep(_, m) { int u, v; cin >> u >> v; u--, v--; to[u].emplace_back(v); } vector ord(n); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](int i, int j) { return to[i].size() > to[j].size(); }); VI pos(n); rep(i, n) pos[ord[i]] = i; ll X = 0; rep(i, n) { int u = ord[i]; for (int w : to[u]) used[w] = true; for (int v : to[u]) if (i < pos[v]) { int cnt = 0; assert(to[u].size() >= to[v].size()); for (int w : to[v]) cnt += used[w]; X += (ll)cnt * (cnt - 1) / 2; } for (int w : to[u]) used[w] = false; } ll Y = 0; rep(i, n) { int u = ord[i]; for (int v : to[u]) if (i < pos[v]) { for (int w : to[v]) if (i < pos[w]) Y += cnt[w]++; } for (int v : to[u]) if (i < pos[v]) { for (int w : to[v]) cnt[w] = 0; } } Y = 2 * Y - X; const mint inv3 = mint(3).inv(); mint ans = (X - Y) * inv3; cout << (-inv3).val() << ' ' << ans.val() << '\n'; }