malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   inline int Get() {     char ch;     while ((ch = getchar()) <  0  || ch >  9 )       ;     int Num = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 )       Num = (Num << 3) + (Num << 1) + ch -  0 ;     return Num;   }   const int M = 3e3 + 5;   const int m = 3000;   int n, a[M][M], s[M][M], r[M][M], d[M][M];   int main() {     n = Get();     for (int i = 1; i <= n; ++i) {       int x0 = Get(), y0 = Get(), x1 = Get(), y1 = Get();       for (int x = x0 + 1; x <= x1; ++x)         for (int y = y0 + 1; y <= y1; ++y) a[x][y] = i;     }     for (int i = 1; i <= m; ++i)       for (int j = 1; j <= m; ++j)         s[i][j] = (!a[i][j]) + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];     for (int i = m; ~i; --i)       for (int j = m; ~j; --j) {         r[i][j] = a[i][j + 1] == a[i + 1][j + 1] ? 0 : r[i][j + 1] + 1;         d[i][j] = a[i + 1][j] == a[i + 1][j + 1] ? 0 : d[i + 1][j] + 1;       }     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j)         for (int k = 1; k <= r[i][j] && k <= d[i][j] &&                         !(s[i + k][j + k] - s[i][j + k] - s[i + k][j] + s[i][j]);              ++k)           if (k <= r[i + k][j] && k <= d[i][j + k]) {             std ::vector<int> ans;             for (int x = i + 1; x <= i + k; ++x)               for (int y = j + 1; y <= j + k; ++y) ans.push_back(a[x][y]);             std ::sort(ans.begin(), ans.end()),                 ans.erase(std ::unique(ans.begin(), ans.end()), ans.end());             printf( YES %d n , ans.size());             for (int k = 0, sze = ans.size(); k < sze; ++k) printf( %d  , ans[k]);             putchar(  n );             return 0;           }     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   int t1, t2, x1, x2, t0;   int main() {     scanf( %d %d %d %d %d , &t1, &t2, &x1, &x2, &t0);     long long k1 = t0 - t1, k2 = t2 - t0;     if (k1 == 0) {       printf( %d %d n , x1, t1 == t2 ? x2 : 0);     } else if (k2 == 0) {       printf( %d %d n , t1 == t2 ? x1 : 0, x2);     } else {       int y1 = 0, y2 = 0;       long long t;       double tt = 1e100;       for (int i = 0; i <= x1; i++) {         t = ((k1 * 1.0 / k2) * i);         if ((k1 * 1.0 / k2) * i - t > EPS) t++;         if (i == 0) t = x2;         if (t > x2) continue;         double tmp =             (((long long)(t1)*i + (long long)(t2)*t) * 1.0) / (i + t + 0.0);         if (tmp - tt < 0) {           y1 = i;           y2 = t;           tt = tmp;         } else if (abs(tmp - tt) <= EPS) {           if (i + t > y1 + y2) {             y1 = i;             y2 = t;           }         }       }       printf( %d %d n , y1, y2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   long long int power(long long int x, long long int y) {     long long int res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   void solve() {     long long int n;     cin >> n;     vector<string> v;     while (n--) {       string s;       cin >> s;       if (s ==  pwd ) {         cout <<  / ;         for (int i = 0; i < v.size(); i++) {           cout << v[i] <<  / ;         }         cout << endl;       } else {         string s;         cin >> s;         vector<string> temp;         string te;         if (s[0] ==  / ) v.clear();         for (int i = 0; i < s.length(); i++) {           if (s[i] !=  / )             te.push_back(s[i]);           else {             if (i != 0) {               temp.push_back(te);               te.clear();             }           }         }         temp.push_back(te);         ;         for (int i = 0; i < temp.size(); i++) {           if (temp[i] ==  .. ) {             v.pop_back();           } else             v.push_back(temp[i]);         }       }     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long int n, ans, i, j, k;     cin >> n;     if (n == 0) {       cout <<  1  << endl;       return 0;     }     ans = 2 * n * n;     ans = ans + ((n + 2) * (n + 1)) - 1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200001];   int dis[200001];   int par[200001];   void addEdge(int u, int v) {     adj[u].push_back(v);     adj[v].push_back(u);   }   void dfs(int src, int parent, int dist) {     dis[src] = dist;     par[src] = parent;     for (int child : adj[src]) {       if (child != parent) {         dfs(child, src, dist + 1);       }     }   }   int solve() {     int n;     cin >> n;     int u, v;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       addEdge(u, v);     }     dfs(1, 0, 0);     set<pair<int, int> > st;     for (int i = 1; i <= n; i++) {       if (dis[i] > 2) {         st.insert({-dis[i], i});       }     }     int ans = 0;     while (!st.empty()) {       int rmv = (*st.begin()).second;       st.erase(st.begin());       rmv = par[rmv];       auto itr = st.find({-dis[rmv], rmv});       if (itr != st.end()) st.erase(itr);       for (int c : adj[rmv]) {         if (dis[c] > 2) {           itr = st.find({-dis[c], c});           if (itr != st.end()) st.erase(itr);         }       }       ans++;     }     return ans;   }   int main() { cout << solve() <<   n ; }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e3 + 10;   vector<int> occ[maxn];   int dp[maxn][maxn], a[maxn];   void solve() {     int n;     cin >> n;     int ptr = 0;     for (int i = 1; i <= n; i++) {       cin >> a[++ptr];       if (ptr > 1 and a[ptr] == a[ptr - 1]) ptr--;     }     n = ptr;     for (int i = 1; i <= n; i++) occ[a[i]].push_back(i);     for (int len = 1; len <= n; len++) {       for (int l = 1; l + len - 1 <= n; l++) {         int r = l + len - 1;         if (len == 1) {           dp[l][r] = 0;           continue;         }         dp[l][r] = max(dp[l][r - 1], dp[l + 1][r]);         if (a[l] == a[r]) dp[l][r] = max(dp[l][r - 1], dp[l + 1][r]) + 1;         for (auto m : occ[a[l]])           if (l < m and m < r) dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);         for (auto m : occ[a[r]])           if (l < m and m < r) dp[l][r] = max(dp[l][r], dp[l][m] + dp[m][r]);       }     }     cout << n - 1 - dp[1][n] <<   n ;     for (int i = 1; i <= n; i++) occ[a[i]].clear();     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dp[i][j] = 0;   }   int main() {     ios_base::sync_with_stdio(false);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int solve(int A, int B) {     int count = 0;     for (int i = 0; i < 32; i++) {       if (((A >> i) & 1) != ((B >> i) & 1)) {         count++;       }     }     return count;   }   int main() {     int n, m, k;     cin >> n >> m >> k;     std::vector<int> arr(m + 1);     for (size_t i = 0; i < m + 1; i++) {       cin >> arr[i];     }     int count = 0;     for (size_t i = 0; i < m; i++) {       int ans;       ans = solve(arr[i], arr[m]);       if (ans <= k) {         count++;       }     }     std::cout << count <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[2001];   int main() {     int n, b, s = 0, m, s1, i;     scanf( %d%d , &n, &b);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     for (i = 0; i < n; i++) {       if (i == n - 1)         s1 = b;       else {         m = *max_element(a + i, a + n);         s1 = (b / a[i]) * m + b % a[i];       }       if (s1 > s) s = s1;     }     printf( %d , s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, sum, min = 1000000000;     cin >> n;     int k[n];     for (i = 0; i < n; i++) cin >> k[i];     for (i = 0; i < n; i++) {       sum = 0;       int m[k[i]];       for (j = 0; j < k[i]; j++) {         cin >> m[j];         sum = sum + 5 * m[j] + 15;       }       if (sum < min) min = sum;     }     cout << min;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void work(int n) {     map<int, int> v;     int ans = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= n; k++) {           for (int x = 0; x <= n; x++) {             if (i + j + k + x == n) {               int tot = i + j * 5 + k * 10 + x * 50;               if (v[tot]) continue;               v[tot] = 1;               ans++;             }           }         }       }     }     cout << ans <<   n ;   }   int main() {     scanf( %d , &n);     if (n <= 20)       work(n);     else       cout << 1LL * 733 + 1LL * 49 * (n - 20);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     cin >> n >> k;     if (k >= 2 * n) {       cout << 0;       return 0;     }     long long q = k / 2, z;     if (k <= n)       z = k - 1;     else       z = n;     if (k & 1) {       long long ans = min(q - 1, z - q - 1);       ans++;       cout << ans;     } else {       cout << min(q - 1, z - q);     }   }
#include <bits/stdc++.h>   using namespace std;   int u, v;   const int maxn = 5e3 + 10;   vector<long long> G[maxn];   bool visited[maxn];   long long dp[maxn];   vector<long long> vc[maxn];   bool mark[maxn];   long long n;   vector<long long> ans;   void dfs(int x) {     visited[x] = 1;     for (int i = 0; i != G[x].size(); i++) {       if (visited[G[x][i]] == 0) {         dfs(G[x][i]);         dp[x] += 1 + dp[G[x][i]];       }     }   }   void main_dfs(int x) {     visited[x] = 1;     memset(mark, 0, sizeof(mark));     for (int i = 0; i < G[x].size(); i++) {       if (visited[G[x][i]] == 0) {         int g = vc[x].size();         for (int j = 0; j < g; j++) {           if (vc[x][j] + dp[G[x][i]] + 1 != n - 1 &&               mark[vc[x][j] + dp[G[x][i]] + 1] == 0) {             vc[x].push_back(vc[x][j] + dp[G[x][i]] + 1);             mark[vc[x][j] + dp[G[x][i]] + 1] = 1;           }         }         if (dp[G[x][i]] + 1 != n - 1 && mark[dp[G[x][i]] + 1] == 0) {           vc[x].push_back(dp[G[x][i]] + 1);           mark[dp[G[x][i]] + 1] = 1;         }       } else {         int g = vc[x].size();         for (int j = 0; j < g; j++) {           if (mark[vc[x][j] + n - 1 - dp[x]] == 0)             if (vc[x][j] + n - 1 - dp[x] != 0 &&                 vc[x][j] + n - 1 - dp[x] != n - 1) {               vc[x].push_back(vc[x][j] + n - dp[x] - 1);               mark[vc[x][j] + n - dp[x] - 1] = 1;             }         }         if (mark[n - dp[x] - 1] == 0)           if (n - dp[x] - 1 != 0 && n - dp[x] - 1 != n - 1) {             vc[x].push_back(n - dp[x] - 1);             mark[n - dp[x] - 1] = 1;           }       }     }     for (int i = 0; i != G[x].size(); i++) {       if (visited[G[x][i]] == 0) main_dfs(G[x][i]);     }   }   bool mk[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i != n - 1; i++) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1);     fill(visited, visited + maxn, 0);     main_dfs(1);     for (int i = 1; i != n + 1; i++) {       for (int j = 0; j != vc[i].size(); j++) {         if (find(ans.begin(), ans.end(), vc[i][j]) == ans.end()) {           ans.push_back(vc[i][j]);           if (n - 1 - vc[i][j] != vc[i][j]) ans.push_back(n - 1 - vc[i][j]);         }       }     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int i = 0; i != ans.size(); i++) {       cout << ans[i] <<     << n - 1 - ans[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, m, x, y, cost, i, j;     string s;     cin >> t;     while (t--) {       cost = 0;       cin >> n >> m >> x >> y;       y = min(y, 2 * x);       for (i = 0; i < n; i++) {         cin >> s;         for (j = 0; j < m; j++) {           if (s[j] ==  . ) {             if (j + 1 < m && s[j + 1] ==  . )               cost += y, j++;             else               cost += x;           }         }       }       cout << cost << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long test;     cin >> test;     while (test--) {       long long b, p, f, h, c;       cin >> b >> p >> f >> h >> c;       long long profit = 0;       if (h > c) {         if (b - 2 * p >= 0) {           profit += p * h;           b = b - 2 * p;           if (b - 2 * f >= 0) {             profit += f * c;           } else {             profit += c * (b / 2);           }         } else {           profit += h * (b / 2);         }       } else {         if (b - 2 * f >= 0) {           profit += f * c;           b = b - 2 * f;           if (b - 2 * p >= 0) {             profit += p * h;           } else {             profit += h * (b / 2);           }         } else {           profit += c * (b / 2);         }       }       cout << profit <<   n ;     }   }
#include <bits/stdc++.h>   int n, m;   long long k;   long long pow(int n) {     if (n == 0) return 1;     long long tmp = pow(n >> 1);     tmp = tmp * tmp % 1000000009ll;     if (n & 1) tmp = tmp * 2ll % 1000000009ll;     return tmp;   }   int main() {     scanf( %d%d%I64d , &n, &m, &k);     int t = n - m;     long long ans = 0;     if (m == 0) {       puts( 0 );       return 0;     }     if (n - t * k < k) {       ans = m;     } else {       int num = (n - t * k) / k;       ans = (pow(num + 1) - 2 + 1000000009ll) * k % 1000000009ll;       ans = (ans + (n - t * k) % k) % 1000000009ll;       ans = (ans + t * (k - 1)) % 1000000009ll;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x7f7f7f7f;   char s[1005];   int dp[1005][2];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s);     if (1 == n) {       puts( 0 );       return 0;     }     memset(dp, 0x7f, sizeof(dp));     dp[0][s[0] -  0 ] = 0;     dp[0][(s[0] -  0 ) ^ 1] = 1;     for (int i = 1; i < n; ++i) {       if (s[i] ==  1 ) {         dp[i][1] = dp[i - 1][0];         dp[i][0] = dp[i - 1][1] + 1;       } else {         dp[i][0] = dp[i - 1][1];         dp[i][1] = dp[i - 1][0] + 1;       }     }     int ans = min(dp[n - 1][0], dp[n - 1][1]);     if (ans >= INF) ans = -1;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, int> > > AdjList;   priority_queue<pair<int, pair<int, int> > > Edgelist;   int n, j, k, m, l, t, i;   string s, ss;   int a[1050][1050];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         scanf( %d , &a[i][j]);       }     }     for (i = 0; i < n; i++) {       t += a[i][i] * a[i][i];     }     scanf( %d , &k);     while (k--) {       scanf( %d , &n);       if (n == 3) {         printf( %d , t % 2);       } else {         scanf( %d , &m);         t++;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100000 + 5], nxt[100000 + 5], lst[100000 + 5], fi[100000 + 5];   int cnt, root[100000 + 5];   struct node {     int sum, ls, rs;   } t[100000 * 43 + 5];   int build(int l, int r) {     int id = ++cnt;     if (l == r) {       t[id].sum = fi[l];       return id;     }     int mid = (l + r) >> 1;     t[id].ls = build(l, mid);     t[id].rs = build(mid + 1, r);     t[id].sum = t[t[id].ls].sum + t[t[id].rs].sum;     return id;   }   void upd(int l, int r, int &x, int y, int p, int v) {     t[x = ++cnt] = t[y];     if (l == r) {       t[x].sum = v;       return;     }     int mid = (l + r) >> 1;     if (p <= mid)       upd(l, mid, t[x].ls, t[y].ls, p, v);     else       upd(mid + 1, r, t[x].rs, t[y].rs, p, v);     t[x].sum = t[t[x].ls].sum + t[t[x].rs].sum;   }   int bs(int l, int r, int x, int v) {     if (v >= t[x].sum) return r + 1;     if (l == r) return l;     int mid = (l + r) >> 1;     if (t[t[x].ls].sum <= v)       return bs(mid + 1, r, t[x].rs, v - t[t[x].ls].sum);     else       return bs(l, mid, t[x].ls, v);   }   int ans[100000 + 5];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) fi[i] = 1;     for (int i = n; i >= 1; i--)       nxt[i] = lst[a[i]], lst[a[i]] = i, fi[nxt[i]] = 0;     root[1] = build(1, n);     for (int i = 1; i <= n - 1; i++) {       int tmp = 0;       upd(1, n, tmp, root[i], i, 0);       if (nxt[i])         upd(1, n, root[i + 1], tmp, nxt[i], 1);       else         root[i + 1] = tmp;     }     for (int k = 1; k <= n; k++) {       int now = 1;       while (now <= n) {         ans[k]++;         now = bs(1, n, root[now], k);       }     }     for (int i = 1; i <= n; i++) printf( %d%c , ans[i],    n [i == n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());   struct kuhn {     int n, m;     vector<vector<int>> g;     vector<int> vis, ma, mb;     kuhn(int n_, int m_) : n(n_), m(m_), g(n), vis(n + m), ma(n, -1), mb(m, -1) {}     void add(int a, int b) { g[a].push_back(b); }     bool dfs(int i) {       vis[i] = 1;       for (int j : g[i])         if (!vis[n + j]) {           vis[n + j] = 1;           if (mb[j] == -1 or dfs(mb[j])) {             ma[i] = j, mb[j] = i;             return true;           }         }       return false;     }     int matching() {       int ret = 0, aum = 1;       for (auto& i : g) shuffle(i.begin(), i.end(), rng);       while (aum) {         for (int j = 0; j < m; j++) vis[n + j] = 0;         aum = 0;         for (int i = 0; i < n; i++)           if (ma[i] == -1 and dfs(i)) ret++, aum = 1;       }       return ret;     }   };   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<string> v(n);     for (auto& i : v) cin >> i;     vector<string> v2;     kuhn k((n - 1) * m, (m - 1) * n);     int vert = 0, qt = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (v[i][j] ==  # ) {           qt++;           if (i + 1 < n and v[i + 1][j] ==  # ) {             vert++;             if (j + 1 < m and v[i][j + 1] ==  # ) k.add(m * i + j, n * j + i);             if (j + 1 < m and v[i + 1][j + 1] ==  # )               k.add(m * i + j, n * j + i + 1);             if (j and v[i][j - 1] ==  # ) k.add(m * i + j, n * (j - 1) + i);             if (j and v[i + 1][j - 1] ==  # )               k.add(m * i + j, n * (j - 1) + i + 1);           }           if (j + 1 < m and v[i][j + 1] ==  # ) vert++;         }     cout << qt - (vert - k.matching()) <<   n ;     exit(0);   }
#include <bits/stdc++.h>   const int mo = 998244353, N = 2005;   int n, a[N][N], ia[N][N], i, j, f[N][N], bi[N], mi[N], fac[N], ans;   inline void add(int x, int v = 1) {     for (; x <= n; x += x & -x) bi[x] += v;   }   inline int ask(int x) {     int ans = 0;     for (; x; x -= x & -x) ans += bi[x];     return ans;   }   int main() {     for (i = *fac = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % mo;     scanf( %d , &n);     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) scanf( %d , a[i] + j);     f[0][0] = 1;     for (i = 1; i <= n; ++i)       for (f[i][0] = fac[i], j = 1; j <= i; ++j)         f[i][j] = (1ll * f[i - 1][j - 1] * (i - j) +                    (j > 1 ? 1ll * f[i - 1][j - 2] * (j - 1) : 0)) %                   mo;     for (i = *mi = 1; i <= n; ++i) mi[i] = 1ll * mi[i - 1] * f[n][n] % mo;     for (i = n; i; --i)       ans = (ans + 1ll * fac[n - i] * ask(a[1][i])) % mo, add(a[1][i]);     ans = 1ll * ans * mi[n - 1] % mo;     for (i = 1; i <= n; ++i)       for (j = 1; j <= n; ++j) ia[i][a[i][j]] = j;     for (i = 2; i <= n; ++i) {       int tot = 0;       int cnt = 0;       memset(bi + 1, 0, n << 2);       for (j = n; j; --j) {         if (ia[i - 1][a[i][j]] > j) add(a[i][j]), ++cnt;         if (cnt) {           int w = ask(a[i][j] - 1);           tot = (tot + 1ll * w * f[n - j][cnt - 1]) % mo;         }         if (ia[i][a[i - 1][j]] > j) add(a[i - 1][j]), ++cnt;       }       cnt = 0;       memset(bi + 1, 0, n << 2);       for (j = n; j; --j) {         if (ia[i][a[i - 1][j]] > j) add(a[i - 1][j], -1);         int w = ask(a[i][j] - 1);         if (ia[i - 1][a[i][j]] > j) ++cnt;         tot = (tot + 1ll * w * f[n - j][cnt]) % mo;         if (ia[i - 1][a[i][j]] < j) add(a[i][j]);         if (ia[i][a[i - 1][j]] > j) ++cnt;       }       ans = (ans + 1ll * tot * mi[n - i]) % mo;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   ,  ;     __f(comma + 1, args...);   }   const int N = 2e5 + 10;   const int INF = 1e8;   int n;   vector<int> g[N];   vector<int> BFS(vector<int> v, int src) {     vector<int> dist = vector<int>(n, INF);     queue<int> q;     q.push(src);     dist[src] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto v : g[u])         if (dist[v] == INF) {           dist[v] = dist[u] + 1;           q.push(v);         }     }     return dist;   }   int main() {     ios::sync_with_stdio(0);     int i, j, k, m;     cin >> n >> m >> k;     vector<int> a(k);     for (i = 0; i < k; ++i) {       cin >> a[i];       a[i]--;     }     for (i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     vector<int> d1 = BFS(a, 0);     vector<int> d2 = BFS(a, n - 1);     vector<int> b = {0};     vector<int> D3 = BFS(b, n - 1);     int d3 = D3[0];     sort(a.begin(), a.end(),          [&](int x, int y) { return d1[x] - d2[x] < d1[y] - d2[y]; });     vector<int> suf(k);     suf[k - 1] = d2[a[k - 1]];     for (i = k - 2; i >= 0; --i) suf[i] = max(suf[i + 1], d2[a[i]]);     int mx = 0;     for (i = 0; i < k - 1; ++i) mx = max(d1[a[i]] + suf[i + 1] + 1, mx);     cout << min(d3, mx) <<   n ;     return 0;   }