constint N = 1000005, M = 1005; constlonglong mod = 1000000007;
int n, m, l[M], a[N], vis[M], cnt; longlong f[M][M][5], inv[M];
inlinevoidRead(){ n = qread(); m = qread(); for (int i = 1;i <= n;i++) { int x = qread(); if (!vis[x]) { l[cnt] = i - 1; vis[x] = ++cnt; } a[i] = vis[x]; } l[cnt] = n; }
inlinevoidAdd(longlong &x, longlong y){ x = (x + y >= mod ? x + y - mod : x + y); }
inlinevoidSolve(){ inv[1] = 1; for (int i = 2;i <= m + 1;i++) inv[i] = (mod - mod / i) * inv[mod % i] % mod; for (int i = cnt - 1;i >= 0;i--) { for (int j = m - i;j >= 0;j--) { if (m - i - j) { Add(f[i][j][4], (f[i + 1][j][3] + l[i + 1] - l[i]) * inv[m - i - j] % mod); Add(f[i][j][4], (f[i][j + 1][4] + 2) * inv[m - i - j] % mod * (m - i - j - 1) % mod); } if (j) Add(f[i][j][3], (f[i + 1][j - 1][3] + l[i + 1] - l[i]) * inv[m - i] % mod * j % mod); Add(f[i][j][3], f[i][j][4] * (m - i - j) % mod * inv[m - i] % mod); Add(f[i][j][2], f[i][j][4] * (m - i - j) % mod * inv[m - i - 1] % mod * inv[m - i - j + 1] % mod); if (j) Add(f[i][j][2], (f[i + 1][j - 1][3] + l[i + 1] - l[i]) * (j - 1) % mod * inv[m - i - 1] % mod * inv[m - i - j + 1] % mod); Add(f[i][j][2], (f[i][j + 1][2] + 2) * (m - i - j) % mod * inv[m - i - j + 1] % mod); if (j == 0) { Add(f[i][0][1], (f[i + 1][0][1] + l[i + 1] - l[i]) * inv[m - i + 1] % mod); Add(f[i][0][1], (f[i][0][3] + 1 + (i != 0)) * inv[m - i + 1] % mod); Add(f[i][0][1], (f[i][1][2] + 2) * (m - i - 1) % mod * inv[m - i + 1] % mod); } } } cout << f[0][0][1] << endl; }