text: size(); for ((i) = (0); (i) <= (len - 2); ++(i)) if (L[i] == a && L[i + 1] == b) return 1; return 0; } int f_Before[MAX][MAX][MAX], f_After[MAX][MAX][MAX], tmp[MAX][MAX][MAX]; int Before[MAX][MAX], After[MAX][MAX]; int ans[MAX]; void work(int u, int kind, int f[MAX][MAX][MAX]) { int v; for ((v) = (1); (v) <= (n); ++(v)) if (g[u][v] == kind && !can[v][u]) { vector<int> after; after.push_back(u); after.push_back(v); if (!get(after, kind, kind != 2, 1)) continue; int Len = after.size(); f[u][after[Len - 1]][Len - 1]++; } } void add(int &a, int b) { a += b; if (a >= Mod) a -= Mod; } void work2(int a, int b) { int i, j; vector<int> &L = p[a][b]; int len = L.size(); for ((i) = (0); (i) <= (len - 2); ++(i)) if (L[i] == a && L[i + 1] == b) { vector<int> before, after; for (j = i; j >= 0; --j) before.push_back(L[j]); for (j = i + 1; j < len; ++j) after.push_back(L[j]); if (get(before, 2, 0, before.size()) && get(after, 1, 1, after.size())) { reverse(before.begin(), before.end()); int A = before[0]; int B = after[after.size() - 1]; int Len = before.size() + after.size() - 1; int k, l, o; for ((l) = (1); (l) <= (n); ++(l)) for ((o) = (0); (o) <= (2 * n); ++(o)) if (tmp[A][l][o]) for ((k) = (1); (k) <= (n); ++(k)) if (g[k][l] == 1 && p[k][l].